forked from wormzjl/ModularMachinery
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathItemBusIOToggle.java
More file actions
70 lines (58 loc) · 2.68 KB
/
Copy pathItemBusIOToggle.java
File metadata and controls
70 lines (58 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package hellfirepvp.modularmachinery.common.item;
import hellfirepvp.modularmachinery.common.CommonProxy;
import hellfirepvp.modularmachinery.common.tiles.base.TileItemBus;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
public abstract class ItemBusIOToggle extends Item {
private final boolean disableExternalIO;
protected ItemBusIOToggle(boolean disableExternalIO) {
this.disableExternalIO = disableExternalIO;
setMaxStackSize(1);
setCreativeTab(CommonProxy.creativeTabModularMachinery);
}
@Nonnull
@Override
public EnumActionResult onItemUseFirst(@Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos,
@Nonnull EnumFacing facing, float hitX, float hitY, float hitZ,
@Nonnull EnumHand hand) {
TileEntity tileEntity = world.getTileEntity(pos);
if (!(tileEntity instanceof TileItemBus)) return EnumActionResult.PASS;
// Intercept the click before the bus GUI consumes it.
if (world.isRemote) return EnumActionResult.SUCCESS;
TileItemBus itemBus = (TileItemBus) tileEntity;
boolean changed = itemBus.setExternalIODisabled(disableExternalIO);
player.sendStatusMessage(new TextComponentTranslation(getMessageKey(changed)), true);
return EnumActionResult.SUCCESS;
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
tooltip.add(I18n.format(getTooltipKey()));
}
private String getMessageKey(boolean changed) {
String prefix = "message.itembus.external_io.";
if (disableExternalIO) {
return changed ? prefix + "disabled" : prefix + "already_disabled";
}
return changed ? prefix + "enabled" : prefix + "already_enabled";
}
private String getTooltipKey() {
String prefix = "tooltip.itembus.external_io.";
return disableExternalIO ? prefix + "disable" : prefix + "enable";
}
}