diff --git a/README.md b/README.md index e9edbe7..173b95e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# 版本 1.21.3 0.0.3.9.4 提前介绍c[最终版本对于0.0.4] 【注意:本解釋簡繁混寫,因爲趕時間,所以並不怎麽規範,請諒解】 +# 版本 1.21.3 0.0.3.9.5 提前介绍c[最终版本对于0.0.4] 【注意:本解釋簡繁混寫,因爲趕時間,所以並不怎麽規範,請諒解】 ## 简介 现在开始你可以用拴绳拴住玩家,也可以拴住自己了,不如尝试拴住彼此来通关我的世界吧( diff --git a/gradle.properties b/gradle.properties index 46c5e7c..d8dafb0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -42,7 +42,7 @@ mod_name=Leashed Player # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=MIT # The mod version. See https://semver.org/ -mod_version=1.21.3 0.0.3.9.4 +mod_version=1.21.3 0.0.3.9.5 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/main/java/com/r3944realms/leashedplayer/content/entities/LeashRopeArrow.java b/src/main/java/com/r3944realms/leashedplayer/content/entities/LeashRopeArrow.java index 2013640..d613cea 100644 --- a/src/main/java/com/r3944realms/leashedplayer/content/entities/LeashRopeArrow.java +++ b/src/main/java/com/r3944realms/leashedplayer/content/entities/LeashRopeArrow.java @@ -164,113 +164,138 @@ public class LeashRopeArrow extends AbstractArrow { } - @Override - protected void onHitBlock(@NotNull BlockHitResult pResult) { - if(!level().isClientSide) { - if (getOwner() instanceof PlayerLeashable pL) { - if (this.level().getBlockState(pResult.getBlockPos()).is(BlockTags.FENCES)) { - Entity leashDataEntity = PlayerLeashable.getLeashDataEntity((ServerPlayer) getOwner(), (ServerLevel) level()); - if(leashDataEntity != null) { - pL.dropLeash(true, !(leashDataEntity instanceof LeashRopeArrow)); + @Override + protected void onHitBlock(@NotNull BlockHitResult pResult) { + if(!level().isClientSide) { + if (getOwner() instanceof PlayerLeashable pL) { + if (this.level().getBlockState(pResult.getBlockPos()).is(BlockTags.FENCES)) { + Entity leashDataEntity = PlayerLeashable.getLeashDataEntity((ServerPlayer) getOwner(), (ServerLevel) level()); + if(leashDataEntity != null) { + pL.dropLeash(true, !(leashDataEntity instanceof LeashRopeArrow)); + if(leashDataEntity instanceof LeashRopeArrow leashRopeArrow) { + leashRopeArrow.setOwner(null); } - Entity leashKnotFence = PlayerLeashable.createLeashKnotFence((ServerLevel) this.level(), pResult.getBlockPos()); - ILivingEntityExtension pLL = (ILivingEntityExtension) pL; - pLL.setKeepLeashTick(GameruleRegistry.getGameruleIntValue(level(), KeepLeashNotDropTime.ID)); - pL.setLeashedTo(leashKnotFence, true); - ItemEntity arrow = new ItemEntity(this.level(), this.position().x, this.position().y, this.position().z, getOrginalItemStack()); - this.level().addFreshEntity(arrow); - discard(); } - } else if(getOwner() instanceof Leashable L) { - if (this.level().getBlockState(pResult.getBlockPos()).is(BlockTags.FENCES)) { - Entity leashDataEntity = this.getOwner(); - if(leashDataEntity != null) { - L.dropLeash(true, false); + Entity leashKnotFence = PlayerLeashable.createLeashKnotFence((ServerLevel) this.level(), pResult.getBlockPos()); + ILivingEntityExtension pLL = (ILivingEntityExtension) pL; + pLL.setKeepLeashTick(GameruleRegistry.getGameruleIntValue(level(), KeepLeashNotDropTime.ID)); + pL.setLeashedTo(leashKnotFence, true); + ItemEntity arrow = new ItemEntity(this.level(), this.position().x, this.position().y, this.position().z, getOrginalItemStack()); + this.level().addFreshEntity(arrow); + discard(); + } + } else if(getOwner() instanceof Leashable L) { + if (this.level().getBlockState(pResult.getBlockPos()).is(BlockTags.FENCES)) { + Entity leashDataEntity = this.getOwner(); + if(leashDataEntity != null) { + L.dropLeash(true, false); + if(leashDataEntity instanceof LeashRopeArrow leashRopeArrow) { + leashRopeArrow.setOwner(null); } - Entity leashKnotFence = LeashFenceKnotEntity.getOrCreateKnot(this.level(), pResult.getBlockPos()); - L.setLeashedTo(leashKnotFence, true); - ItemEntity arrow = new ItemEntity(this.level(), this.position().x, this.position().y, this.position().z, getOrginalItemStack()); - this.level().addFreshEntity(arrow); - discard(); } + Entity leashKnotFence = LeashFenceKnotEntity.getOrCreateKnot(this.level(), pResult.getBlockPos()); + L.setLeashedTo(leashKnotFence, true); + ItemEntity arrow = new ItemEntity(this.level(), this.position().x, this.position().y, this.position().z, getOrginalItemStack()); + this.level().addFreshEntity(arrow); + discard(); } } - super.onHitBlock(pResult); - } + super.onHitBlock(pResult); - @Override - protected void onHitEntity(@NotNull EntityHitResult pResult) { - if(!level().isClientSide()){ - Entity entity = pResult.getEntity(); - hitOnEntityHandler(entity); - if(this.getOwner() instanceof LivingEntity livingEntity ) { - MobEffectInstance effect = livingEntity.getEffect(ModEffectRegister.NO_LEASH_EFFECT); - if(effect != null && effect.getDuration() > 0) { - this.setOwner(null); - } + } + + @Override + protected void onHitEntity(@NotNull EntityHitResult pResult) { + if(!level().isClientSide()){ + Entity entity = pResult.getEntity(); + hitOnEntityHandler(entity); + if(this.getOwner() instanceof LivingEntity livingEntity ) { + MobEffectInstance effect = livingEntity.getEffect(ModEffectRegister.NO_LEASH_EFFECT); + if(effect != null && effect.getDuration() > 0) { + this.setOwner(null); } - if(entity instanceof LivingEntity livingEntity) { - if(livingEntity.equals(this.getOwner())) return; - if(this.getOwner() == null && livingEntity instanceof PlayerLeashable pL) { //发射器发出或命令生成 - setOwner(livingEntity); - Entity leashDataEntity = PlayerLeashable.getLeashDataEntity((ServerPlayer) getOwner(), (ServerLevel) level()); - if(leashDataEntity != null) pL.dropLeash(true, !(leashDataEntity instanceof LeashRopeArrow)); - ILivingEntityExtension pLL = (ILivingEntityExtension) pL; - pLL.setKeepLeashTick(GameruleRegistry.getGameruleIntValue(level(), KeepLeashNotDropTime.ID)); - pL.setLeashedTo(this, true); - return; - } else if (this.getOwner() instanceof PlayerLeashable pL) { - Entity leashDataEntity = PlayerLeashable.getLeashDataEntity((ServerPlayer) getOwner(), (ServerLevel) level()); - if(leashDataEntity != null) pL.dropLeash(true, !(leashDataEntity instanceof LeashRopeArrow)); - ItemEntity arrow = new ItemEntity(this.level(), this.position().x, this.position().y, this.position().z, getOrginalItemStack()); - ILivingEntityExtension pLL = (ILivingEntityExtension) pL; - pLL.setKeepLeashTick(GameruleRegistry.getGameruleIntValue(level(), KeepLeashNotDropTime.ID)); - pL.setLeashedTo(pResult.getEntity(), true); - this.level().addFreshEntity(arrow); - discard(); - } else { - if(entity instanceof Leashable leashable) { - if (getOwner() == null) { - Entity leashDataEntity = leashable.getLeashHolder(); - if (leashDataEntity != null) - leashable.dropLeash(true, !(leashDataEntity instanceof LeashRopeArrow)); - leashable.setLeashedTo(this, true); - this.setOwner(entity); - return; - } + } + if(entity instanceof LivingEntity livingEntity) { + if(livingEntity.equals(this.getOwner())) return; + if(this.getOwner() == null && livingEntity instanceof PlayerLeashable pL) { //发射器发出或命令生成 + setOwner(livingEntity); + Entity leashDataEntity = PlayerLeashable.getLeashDataEntity((ServerPlayer) getOwner(), (ServerLevel) level()); + if(leashDataEntity != null) { + pL.dropLeash(true, !(leashDataEntity instanceof LeashRopeArrow)); + if(leashDataEntity instanceof LeashRopeArrow leashRopeArrow) { + leashRopeArrow.setOwner(null); } - if(entity instanceof LivingEntity living) { - if(this.getOwner() != null && this.getOwner()instanceof Leashable leashable) { - leashable.setLeashedTo(living, true); - ItemEntity arrow = new ItemEntity(this.level(), this.position().x, this.position().y, this.position().z, getOrginalItemStack()); - this.level().addFreshEntity(arrow); - discard(); - return; - } + } + ILivingEntityExtension pLL = (ILivingEntityExtension) pL; + pLL.setKeepLeashTick(GameruleRegistry.getGameruleIntValue(level(), KeepLeashNotDropTime.ID)); + pL.setLeashedTo(this, true); + return; + } else if (this.getOwner() instanceof PlayerLeashable pL) { + Entity leashDataEntity = PlayerLeashable.getLeashDataEntity((ServerPlayer) getOwner(), (ServerLevel) level()); + if(leashDataEntity != null) { + pL.dropLeash(true, !(leashDataEntity instanceof LeashRopeArrow)); + if(leashDataEntity instanceof LeashRopeArrow leashRopeArrow) { + leashRopeArrow.setOwner(null); } - ItemEntity lead = new ItemEntity(this.level(), this.position().x, this.position().y, this.position().z, Items.LEAD.getDefaultInstance()); - this.level().addFreshEntity(lead); - } - } - else if (entity instanceof LeashFenceKnotEntity leashKnotFence) { - if (getOwner() instanceof PlayerLeashable pL) { - Entity leashDataEntity = PlayerLeashable.getLeashDataEntity((ServerPlayer) getOwner(), (ServerLevel) level()); - if(leashDataEntity != null) pL.dropLeash(true, true); - ItemEntity arrow = new ItemEntity(this.level(), this.position().x, this.position().y, this.position().z, getOrginalItemStack()); - ILivingEntityExtension pLL = (ILivingEntityExtension) pL; - pLL.setKeepLeashTick(GameruleRegistry.getGameruleIntValue(level(), KeepLeashNotDropTime.ID)); - pL.setLeashedTo(leashKnotFence, true); - this.level().addFreshEntity(arrow); - discard(); - return; } + ItemEntity arrow = new ItemEntity(this.level(), this.position().x, this.position().y, this.position().z, getOrginalItemStack()); + ILivingEntityExtension pLL = (ILivingEntityExtension) pL; + pLL.setKeepLeashTick(GameruleRegistry.getGameruleIntValue(level(), KeepLeashNotDropTime.ID)); + pL.setLeashedTo(pResult.getEntity(), true); + this.level().addFreshEntity(arrow); + discard(); } else { + if(entity instanceof Leashable leashable) { + if (getOwner() == null) { + Entity leashDataEntity = leashable.getLeashHolder(); + if (leashDataEntity != null) { + leashable.dropLeash(true, !(leashDataEntity instanceof LeashRopeArrow)); + if(leashDataEntity instanceof LeashRopeArrow leashRopeArrow) { + leashRopeArrow.setOwner(null); + } + } + leashable.setLeashedTo(this, true); + this.setOwner(entity); + return; + } + } + if(entity instanceof LivingEntity living) { + if(this.getOwner() != null && this.getOwner()instanceof Leashable leashable) { + leashable.setLeashedTo(living, true); + ItemEntity arrow = new ItemEntity(this.level(), this.position().x, this.position().y, this.position().z, getOrginalItemStack()); + this.level().addFreshEntity(arrow); + discard(); + return; + } + } ItemEntity lead = new ItemEntity(this.level(), this.position().x, this.position().y, this.position().z, Items.LEAD.getDefaultInstance()); this.level().addFreshEntity(lead); } } - if(!level().isClientSide()) super.onHitEntity(pResult); + else if (entity instanceof LeashFenceKnotEntity leashKnotFence) { + if (getOwner() instanceof PlayerLeashable pL) { + Entity leashDataEntity = PlayerLeashable.getLeashDataEntity((ServerPlayer) getOwner(), (ServerLevel) level()); + if(leashDataEntity != null) { + pL.dropLeash(true, true); + if(leashDataEntity instanceof LeashRopeArrow leashRopeArrow) { + leashRopeArrow.setOwner(null); + } + } + ItemEntity arrow = new ItemEntity(this.level(), this.position().x, this.position().y, this.position().z, getOrginalItemStack()); + ILivingEntityExtension pLL = (ILivingEntityExtension) pL; + pLL.setKeepLeashTick(GameruleRegistry.getGameruleIntValue(level(), KeepLeashNotDropTime.ID)); + pL.setLeashedTo(leashKnotFence, true); + this.level().addFreshEntity(arrow); + discard(); + return; + } + } else { + ItemEntity lead = new ItemEntity(this.level(), this.position().x, this.position().y, this.position().z, Items.LEAD.getDefaultInstance()); + this.level().addFreshEntity(lead); + } } + if(!level().isClientSide()) super.onHitEntity(pResult); + } }