Merge pull request #20 from 3944Realms/1.21

2024-10-23
This commit is contained in:
3944Realms 2024-10-24 23:18:37 +08:00 committed by GitHub
commit a0e2b95167
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 90 additions and 28 deletions

View File

@ -32,7 +32,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=0.0.3.9.1
mod_version=0.0.3.9.2
# 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

View File

@ -10,14 +10,11 @@ import com.r3944realms.leashedplayer.content.entities.LeashRopeArrow;
import com.r3944realms.leashedplayer.content.items.ModItemRegister;
import com.r3944realms.leashedplayer.modInterface.PlayerLeashable;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.Leashable;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.world.item.alchemy.PotionBrewing;
import net.minecraft.world.item.alchemy.Potions;
import net.minecraft.world.level.block.DispenserBlock;
@ -26,7 +23,6 @@ import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
import net.neoforged.neoforge.event.RegisterCommandsEvent;
import net.neoforged.neoforge.event.brewing.RegisterBrewingRecipesEvent;
import net.neoforged.neoforge.event.entity.living.MobEffectEvent;
import net.neoforged.neoforge.event.tick.EntityTickEvent;
@ -55,11 +51,17 @@ public class CommonEventHandler {
MobEffectInstance effect = living.getEffect(ModEffectRegister.NO_LEASH_EFFECT);
if(effect != null && effect.getDuration() > 0){
if (entity instanceof PlayerLeashable player) {
if (player.getLeashHolder() != null)
if (player.getLeashHolder() != null) {
if (player.getLeashHolder() instanceof LeashRopeArrow arrow)
arrow.setOwner(null);
player.dropLeash(true, !(player.getLeashHolder() instanceof LeashRopeArrow));
}
} else if (entity instanceof Leashable leashable) {
if (leashable.getLeashHolder() != null)
if (leashable.getLeashHolder() != null) {
if (leashable.getLeashHolder() instanceof LeashRopeArrow arrow)
arrow.setOwner(null);
leashable.dropLeash(true, !(leashable.getLeashHolder() instanceof LeashRopeArrow));
}
}
}
}

View File

@ -1,6 +1,7 @@
package com.r3944realms.leashedplayer.content.entities;
import com.r3944realms.leashedplayer.config.LeashPlayerCommonConfig;
import com.r3944realms.leashedplayer.content.effects.ModEffectRegister;
import com.r3944realms.leashedplayer.content.gamerules.GameruleRegistry;
import com.r3944realms.leashedplayer.content.gamerules.Server.KeepLeashNotDropTime;
import com.r3944realms.leashedplayer.content.items.ModItemRegister;
@ -9,8 +10,10 @@ import com.r3944realms.leashedplayer.modInterface.PlayerLeashable;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Leashable;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.decoration.LeashFenceKnotEntity;
import net.minecraft.world.entity.item.ItemEntity;
@ -59,8 +62,10 @@ public class LeashRopeArrow extends AbstractArrow {
@Override
public void setOwner(@Nullable Entity pEntity) {
super.setOwner(pEntity);
// super.setOwner(pEntity);
boolean isNull = pEntity == null;
this.ownerUUID = isNull ? null : pEntity.getUUID();
this.cachedOwner = isNull ? null : pEntity;
this.pickup = this.pickup == Pickup.CREATIVE_ONLY ? this.pickup : Pickup.DISALLOWED;
}
@ -92,7 +97,7 @@ public class LeashRopeArrow extends AbstractArrow {
}
if(life <= 240) {
if(pPlayer.isShiftKeyDown()) {
Entity leashDataEntity = PlayerLeashable.getLeashDataEntity((ServerPlayer) this.getOwner(), (ServerLevel) level());
Entity leashDataEntity = this.getOwner() instanceof PlayerLeashable ? PlayerLeashable.getLeashDataEntity((ServerPlayer) this.getOwner(), (ServerLevel) level()) : this.getOwner();
if(this.ownedBy(pPlayer)) {
this.pickup = Pickup.ALLOWED;
if(this.equals(leashDataEntity)) playerLeashable.dropLeash(true, false);
@ -100,12 +105,16 @@ public class LeashRopeArrow extends AbstractArrow {
if(life >= 120) {
Entity owner = getOwner();
if( owner != null ) {
if(this.equals(leashDataEntity)) {
((PlayerLeashable) owner).setLeashedTo(pPlayer, true);
ItemEntity itemEntity = new ItemEntity(level(), getX(), getY(), getZ(), getOrginalItemStack());
level().addFreshEntity(itemEntity);
discard();
// if(this.equals(leashDataEntity)) {
if(owner instanceof PlayerLeashable player) {
player.setLeashedTo(pPlayer, true);
} else if(owner instanceof Leashable leashable) {
leashable.setLeashedTo(pPlayer, true);
}
ItemEntity itemEntity = new ItemEntity(level(), getX(), getY(), getZ(), getOrginalItemStack());
level().addFreshEntity(itemEntity);
discard();
// }
} else return true;
} else return false;
}
@ -113,18 +122,20 @@ public class LeashRopeArrow extends AbstractArrow {
}
else {
Entity leashDataEntity = PlayerLeashable.getLeashDataEntity((ServerPlayer) this.getOwner(), (ServerLevel) level());
Entity leashDataEntity = this.getOwner() instanceof PlayerLeashable ? PlayerLeashable.getLeashDataEntity((ServerPlayer) this.getOwner(), (ServerLevel) level()) : this.getOwner();
if(this.ownedBy(pPlayer)) {
this.pickup = Pickup.ALLOWED;
if(this.equals(leashDataEntity)) playerLeashable.dropLeash(true, false);
} else {
if(this.equals(leashDataEntity)) {
Entity owner = getOwner();
((PlayerLeashable)owner).setLeashedTo(pPlayer, true);
ItemEntity itemEntity = new ItemEntity(level(), getX(), getY(), getZ(), getOrginalItemStack());
level().addFreshEntity(itemEntity);
discard();
Entity owner = getOwner();
if(owner instanceof PlayerLeashable player) {
player.setLeashedTo(pPlayer, true);
} else if(owner instanceof Leashable leashable) {
leashable.setLeashedTo(pPlayer, true);
}
ItemEntity itemEntity = new ItemEntity(level(), getX(), getY(), getZ(), getOrginalItemStack());
level().addFreshEntity(itemEntity);
discard();
}
}
@ -170,6 +181,18 @@ public class LeashRopeArrow extends AbstractArrow {
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 = 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);
@ -181,7 +204,13 @@ public class LeashRopeArrow extends AbstractArrow {
if(!level().isClientSide()){
Entity entity = pResult.getEntity();
hitOnEntityHandler(entity);
if(entity instanceof LivingEntity livingEntity){
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);
@ -201,10 +230,30 @@ public class LeashRopeArrow extends AbstractArrow {
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 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);
}
} else if (entity instanceof LeashFenceKnotEntity leashKnotFence) {
}
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);
@ -223,4 +272,5 @@ public class LeashRopeArrow extends AbstractArrow {
}
super.onHitEntity(pResult);
}
}

View File

@ -10,7 +10,6 @@ import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.world.item.alchemy.PotionContents;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.common.CommonHooks;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.registries.DeferredRegister;
import org.jetbrains.annotations.NotNull;

View File

@ -2,6 +2,7 @@ package com.r3944realms.leashedplayer.mixin.both;
import com.r3944realms.leashedplayer.LeashedPlayer;
import com.r3944realms.leashedplayer.content.commands.LeashCommand;
import com.r3944realms.leashedplayer.content.effects.ModEffectRegister;
import com.r3944realms.leashedplayer.content.entities.LeashRopeArrow;
import com.r3944realms.leashedplayer.modInterface.ILivingEntityExtension;
import com.r3944realms.leashedplayer.modInterface.PlayerLeashable;
@ -11,6 +12,7 @@ import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Leashable;
@ -188,7 +190,7 @@ public abstract class MixinPlayer extends LivingEntity implements PlayerLeashabl
@Unique
protected void Pl$tickLeash() {
if(this.Pl$LeashData == null) return;//没有Data直接退出
ILivingEntityExtension self = (ILivingEntityExtension) this;
ILivingEntityExtension self = this;
int keepLeashTick = self.getKeepLeashTick();
//info -> Holder整理
@ -198,9 +200,15 @@ public abstract class MixinPlayer extends LivingEntity implements PlayerLeashabl
Entity entity = this.Pl$LeashData.leashHolder;
//保存数据
saveLeashData(Pl$LeashData);
ILivingEntityExtension iEntityExtension = (ILivingEntityExtension) this;//获取设定值
ILivingEntityExtension iEntityExtension = this;//获取设定值
float leashLengthSelf = iEntityExtension.getLeashLength();
leashLength = leashLengthSelf > LeashCommand.MIN_VALUE ? leashLengthSelf : LeashCommand.MIN_VALUE;
MobEffectInstance effect = this.getEffect(ModEffectRegister.NO_LEASH_EFFECT);
if(effect != null && effect.getDuration() > 0) {
if (entity instanceof LeashRopeArrow arrow)
arrow.setOwner(null);
this.dropLeash(true, !(entity instanceof LeashRopeArrow));
}
if (entity != null) {
double breakDistanceTime = (entity instanceof LeashRopeArrow) ? LeashedPlayer.M1() * LeashedPlayer.M2() : LeashedPlayer.M1();
if(!isAlive() || !entity.isAlive() ||( distanceTo(entity) > Math.max(leashLength * breakDistanceTime, LeashCommand.MIN_VALUE * breakDistanceTime) && keepLeashTick == 0)){

View File

@ -15,4 +15,7 @@ public net.minecraft.world.entity.Leashable$LeashData delayedLeashHolderId # del
#private -> protect
protected net.minecraft.world.entity.projectile.AbstractArrow life # life
#protect -> public
public net.minecraft.world.effect.MobEffect <init>(Lnet/minecraft/world/effect/MobEffectCategory;I)V # MobEffect
public net.minecraft.world.effect.MobEffect <init>(Lnet/minecraft/world/effect/MobEffectCategory;I)V # MobEffect
#private -> protected
protected net.minecraft.world.entity.projectile.Projectile cachedOwner # cachedOwner
protected net.minecraft.world.entity.projectile.Projectile ownerUUID # ownerUUID