版本0.0.3.1 添加: 1.新的游戏规则KeepLeashNotDropTime(保持拴绳箭实体存活时间 2.新的纹理 包括弓弩材质发射拴绳箭新材质 3.新的配置文件内容 4.所有指令现在 可以同时作用多个玩家对象了 调整: 1.拾取拴绳箭的逻辑, 在落地后2s后可以通过按住Shift靠近后拾取 2.优化逻辑 3. 创造模式拴绳箭拾取逻辑修正 修复: 1.拴繩不能正常掉落的問題 2. data clear节点指令错误(笔误 具體新内容請見 README.md 介紹
58 lines
2.5 KiB
Java
58 lines
2.5 KiB
Java
package com.r3944realms.leashedplayer.mixin.item;
|
|
|
|
import com.r3944realms.leashedplayer.modInterface.PlayerLeashable;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.server.level.ServerPlayer;
|
|
import net.minecraft.world.InteractionResult;
|
|
import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.world.entity.Leashable;
|
|
import net.minecraft.world.entity.decoration.LeashFenceKnotEntity;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.item.LeadItem;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.gameevent.GameEvent;
|
|
import org.spongepowered.asm.mixin.Mixin;
|
|
import org.spongepowered.asm.mixin.injection.At;
|
|
import org.spongepowered.asm.mixin.injection.Inject;
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
|
|
import java.util.List;
|
|
|
|
@Mixin(LeadItem.class)
|
|
public class MixinLeadItem {
|
|
/**
|
|
* 拴住自己的逻辑
|
|
*/
|
|
@Inject(
|
|
method = {"bindPlayerMobs"},
|
|
at = @At("HEAD"),
|
|
cancellable = true)
|
|
private static void selfLeash(Player pPlayer, Level pLevel, BlockPos pPos, CallbackInfoReturnable<InteractionResult> cir) {
|
|
List<Leashable> list = LeadItem.leashableInArea(pLevel, pPos, p_353025_ -> p_353025_.getLeashHolder() == pPlayer);
|
|
if (list.isEmpty()) {
|
|
ItemStack mainHandItem = pPlayer.getMainHandItem();
|
|
if (!(mainHandItem.getItem() instanceof LeadItem )) {
|
|
return;
|
|
}
|
|
//非创造模式减少,防止刷物品
|
|
if(!pPlayer.isCreative()) mainHandItem.shrink(1);
|
|
//自己
|
|
Entity leashDataEntity = PlayerLeashable.getLeashDataEntity((ServerPlayer) pPlayer, (ServerLevel) pLevel);
|
|
PlayerLeashable playerLeashable = (PlayerLeashable) pPlayer;
|
|
if(leashDataEntity != null) {
|
|
playerLeashable.dropLeash(true, true);
|
|
}
|
|
//获取拴绳结实体
|
|
LeashFenceKnotEntity leashfenceknotentity = LeashFenceKnotEntity.getOrCreateKnot(pLevel, pPos);
|
|
//播放绳结被放置的声音
|
|
leashfenceknotentity.playPlacementSound();
|
|
//将自己与拴绳结绑定LeashData
|
|
playerLeashable.setLeashedTo(leashfenceknotentity, true);
|
|
pLevel.gameEvent(GameEvent.BLOCK_ATTACH, pPos, GameEvent.Context.of(pPlayer));
|
|
cir.setReturnValue(InteractionResult.SUCCESS);
|
|
}
|
|
}
|
|
}
|