|
1 | 1 | package ru.lionzxy.fastlogblock.ui; |
2 | 2 |
|
3 | | -import net.minecraft.creativetab.CreativeTabs; |
4 | 3 | import net.minecraft.entity.player.EntityPlayer; |
5 | | -import net.minecraft.item.Item; |
| 4 | +import net.minecraft.init.Items; |
| 5 | +import net.minecraft.item.ItemStack; |
6 | 6 | import net.minecraft.util.EnumActionResult; |
7 | 7 | import net.minecraft.util.EnumFacing; |
8 | | -import net.minecraft.util.EnumHand; |
9 | | -import net.minecraft.util.ResourceLocation; |
10 | 8 | import net.minecraft.util.math.BlockPos; |
11 | | -import net.minecraft.util.text.TextComponentTranslation; |
| 9 | +import net.minecraft.util.text.TextComponentString; |
| 10 | +import net.minecraft.util.text.translation.I18n; |
12 | 11 | import net.minecraft.world.World; |
13 | | -import ru.lionzxy.fastlogblock.FastLogBlock; |
| 12 | +import net.minecraftforge.event.entity.player.PlayerInteractEvent; |
| 13 | +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; |
14 | 14 | import ru.lionzxy.fastlogblock.handlers.EventHandlingManager; |
15 | 15 | import ru.lionzxy.fastlogblock.utils.MinecraftUtils; |
16 | 16 |
|
17 | | -import java.util.Objects; |
18 | | - |
19 | | -public class InfoItem extends Item { |
20 | | - private static final String ITEMNAME = "infoitem"; |
| 17 | +public class InfoItem { |
21 | 18 | private final EventHandlingManager eventHandlingManager; |
22 | 19 |
|
23 | 20 | public InfoItem(EventHandlingManager eventHandlingManager) { |
24 | 21 | this.eventHandlingManager = eventHandlingManager; |
25 | | - setRegistryName(FastLogBlock.MODID, ITEMNAME); |
26 | | - final ResourceLocation registryName = Objects.requireNonNull(getRegistryName()); |
27 | | - setUnlocalizedName(registryName.toString()); |
28 | | - setCreativeTab(CreativeTabs.MISC); |
29 | 22 | } |
30 | 23 |
|
| 24 | + @SubscribeEvent |
| 25 | + public void onItemRightClick(PlayerInteractEvent.RightClickBlock event) { |
| 26 | + BlockPos pos = event.getPos(); |
| 27 | + EnumFacing face = event.getFace(); |
| 28 | + if (face != null) { |
| 29 | + pos = pos.offset(face); |
| 30 | + } |
31 | 31 |
|
32 | | - @Override |
33 | | - public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { |
34 | | - if (worldIn.isRemote) { |
| 32 | + EnumActionResult result = onItemUse(event.getEntityPlayer(), event.getWorld(), pos, event.getItemStack()); |
| 33 | + if (result == EnumActionResult.SUCCESS || result == EnumActionResult.PASS) { |
| 34 | + event.setCanceled(true); |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + @SubscribeEvent |
| 39 | + public void onItemLeftClick(PlayerInteractEvent.LeftClickBlock event) { |
| 40 | + BlockPos pos = event.getPos(); |
| 41 | + EnumActionResult result = onItemUse(event.getEntityPlayer(), event.getWorld(), pos, event.getItemStack()); |
| 42 | + if (result == EnumActionResult.SUCCESS || result == EnumActionResult.PASS) { |
| 43 | + event.setCanceled(true); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, ItemStack itemStack) { |
| 48 | + if (itemStack.getItem() != Items.WOODEN_HOE) { |
35 | 49 | return EnumActionResult.FAIL; |
36 | 50 | } |
| 51 | + if (worldIn.isRemote) { |
| 52 | + return EnumActionResult.PASS; |
| 53 | + } |
37 | 54 | if (!MinecraftUtils.canShowLog(player)) { |
38 | | - player.sendMessage(new TextComponentTranslation("message.fastlogblock:blockinfo.event.permissionerror")); |
39 | | - return EnumActionResult.FAIL; |
| 55 | + player.sendMessage(new TextComponentString(String.format(I18n.translateToLocal("message.fastlogblock:blockinfo.event.permissionerror")))); |
| 56 | + return EnumActionResult.PASS; |
40 | 57 | } |
41 | | - player.sendMessage(new TextComponentTranslation("message.fastlogblock:blockinfo.start", pos.getX(), pos.getY(), pos.getZ())); |
| 58 | + player.sendMessage(new TextComponentString(String.format(I18n.translateToLocal("message.fastlogblock:blockinfo.start"), pos.getX(), pos.getY(), pos.getZ()))); |
42 | 59 | eventHandlingManager.handleLogByPos(player, pos, worldIn); |
43 | 60 | return EnumActionResult.SUCCESS; |
44 | 61 | } |
|
0 commit comments