LeashedPlayer/src/main/java/com/r3944realms/leashedplayer/mixin/both/MixinLivingEntity.java
3944Realms 9dadf48d38 2024-09-07
版本0.0.3.1
添加:
1.新的游戏规则KeepLeashNotDropTime(保持拴绳箭实体存活时间
2.新的纹理 包括弓弩材质发射拴绳箭新材质
3.新的配置文件内容
4.所有指令现在 可以同时作用多个玩家对象了
调整:
1.拾取拴绳箭的逻辑, 在落地后2s后可以通过按住Shift靠近后拾取
2.优化逻辑
3. 创造模式拴绳箭拾取逻辑修正
修复:
1.拴繩不能正常掉落的問題
2. data clear节点指令错误(笔误

具體新内容請見 README.md 介紹
2024-09-07 18:03:02 +08:00

68 lines
2.7 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.r3944realms.leashedplayer.mixin.both;
import com.r3944realms.leashedplayer.modInterface.ILivingEntityExtension;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(LivingEntity.class)
public abstract class MixinLivingEntity extends Entity implements ILivingEntityExtension {
@Unique
protected int Pl$LeashKeepTick;//保存状态当超过断裂绳长时若LeashKeepTick大于0则不断裂
public MixinLivingEntity(EntityType<?> pEntityType, Level pLevel) {
super(pEntityType, pLevel);
}
@Unique
@SuppressWarnings("WrongEntityDataParameterClass")
private static final EntityDataAccessor<Float> DATA_ENTITY_LEASH_LENGTH = SynchedEntityData.defineId(LivingEntity.class, EntityDataSerializers.FLOAT);
@SuppressWarnings("AddedMixinMembersNamePattern")
@Override
public float getLeashLength() {
return this.entityData.get(DATA_ENTITY_LEASH_LENGTH);
}
@SuppressWarnings("AddedMixinMembersNamePattern")
@Override
public void setLeashLength(float length) {
this.entityData.set(DATA_ENTITY_LEASH_LENGTH, length);
}
@SuppressWarnings("AddedMixinMembersNamePattern")
@Override
public void setKeepLeashTick(int keepTick) {
this.Pl$LeashKeepTick = Math.max(keepTick, 0);
}
@SuppressWarnings("AddedMixinMembersNamePattern")
@Override
public int getKeepLeashTick() {
return this.Pl$LeashKeepTick;
}
@Inject(method = {"defineSynchedData"}, at = {@At("TAIL")})
//定义Client/Server实体同步数据
private void defineSyncData(SynchedEntityData.Builder pBuilder, CallbackInfo ci) {
pBuilder.define(DATA_ENTITY_LEASH_LENGTH, 5.0F);
}
@Inject(method = {"readAdditionalSaveData"}, at = {@At("RETURN")})
private void readSaveData(CompoundTag compoundTag, CallbackInfo callbackInfo) {
if(compoundTag.contains("LeashLength")) {
this.setLeashLength(compoundTag.getFloat("LeashLength"));
}
}
@Inject(method = {"addAdditionalSaveData"}, at = {@At("RETURN")})
private void addSaveData(CompoundTag compoundTag, CallbackInfo callbackInfo) {
compoundTag.putFloat("LeashLength", getLeashLength());
}
}