版本信息
你使用的系统:win10 64
你用的JDK是: JDK8
你使用的IDE:IDEA
你使用的IDE版本:2020.2
Forge版本: 1.16.3-34.1.0
Minecraft版本: 1.16.3
错误情况简述
覆盖onItemRightClick后右键无反应
相关代码
<ToolTemplate>
public class ToolTemplate extends ToolItem{
boolean isExpansion = false;
public ToolTemplate(float attackDamageIn, float attackSpeedIn, IItemTier tier, Properties builderIn) {
super(attackDamageIn, attackSpeedIn, tier, new HashSet<>(), builderIn.addToolType(ToolType.AXE, tier.getHarvestLevel())
.addToolType(ToolType.HOE, tier.getHarvestLevel())
.addToolType(ToolType.PICKAXE, tier.getHarvestLevel())
.addToolType(ToolType.SHOVEL, tier.getHarvestLevel())
);
}
@Override
public float getDestroySpeed(ItemStack stack, BlockState state) {
if (state.isIn(Blocks.COBWEB) || state.isIn(BlockTags.LEAVES)) {
return 15.0F;
}
if (state.isIn(BlockTags.WOOL)) {
return 5.0F;
} else {
return this.efficiency;
}
}
@Override
public ActionResultType onItemUse(ItemUseContext context) {
World world = context.getWorld();
BlockPos blockpos = context.getPos();
BlockState blockstate = world.getBlockState(blockpos);
BlockState block = blockstate.getToolModifiedState(world, blockpos, context.getPlayer(), context.getItem(), net.minecraftforge.common.ToolType.AXE);
if (context.getPlayer().isSneaking()) {
return Items.IRON_SHOVEL.onItemUse(context);
}
if (block != null) {
return Items.IRON_AXE.onItemUse(context);
} else {
return Items.IRON_HOE.onItemUse(context);
}
}
@Override
public ActionResultType itemInteractionForEntity(ItemStack stack, PlayerEntity playerIn, LivingEntity target, Hand hand) {
return Items.SHEARS.itemInteractionForEntity(stack, playerIn, target, hand);
}
@Override
public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) {
return super.canApplyAtEnchantingTable(stack, enchantment) || enchantment.type.canEnchantItem(Items.DIAMOND_SWORD);
}
@OnlyIn(Dist.CLIENT)
@Override
public void addInformation(ItemStack stack, World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
if (InputMappings.isKeyDown(Minecraft.getInstance().getMainWindow().getHandle(), GLFW.GLFW_KEY_LEFT_SHIFT)){
tooltip.add(new TranslationTextComponent("information.tool.template2").mergeStyle(TextFormatting.GRAY, TextFormatting.ITALIC));
tooltip.add(new TranslationTextComponent("information.tool.template3").mergeStyle(TextFormatting.GRAY, TextFormatting.ITALIC));
tooltip.add(new TranslationTextComponent("information.tool.template4").mergeStyle(TextFormatting.GRAY, TextFormatting.ITALIC));
}else {
tooltip.add(new TranslationTextComponent("information.tool.template1").mergeStyle(TextFormatting.BLUE, TextFormatting.ITALIC));
}
}
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
if (!worldIn.isRemote && playerIn.isSneaking() && handIn == Hand.MAIN_HAND) {
if (!isExpansion){
playerIn.sendStatusMessage(new TranslationTextComponent("information.tool.template.mode1"),false);
isExpansion = true;
}else {
playerIn.sendStatusMessage(new TranslationTextComponent("information.tool.template.mode2"),false);
isExpansion = false;
}
}
return ActionResult.resultPass(playerIn.getHeldItem(handIn));
}
@Override
public boolean onBlockDestroyed(ItemStack stack, World worldIn, BlockState state, BlockPos pos, LivingEntity entityLiving) {
// if(isExpansion){
//
// }
return super.onBlockDestroyed(stack, worldIn, state, pos, entityLiving);
}
}