diff --git a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityDiode.java b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityDiode.java index 2bbf645a517..c19b1797f96 100644 --- a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityDiode.java +++ b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityDiode.java @@ -1,8 +1,12 @@ package gregtech.common.metatileentities.electric; import gregtech.api.GTValues; +import gregtech.api.capability.GregtechDataCodes; +import gregtech.api.capability.GregtechTileCapabilities; +import gregtech.api.capability.IControllable; import gregtech.api.capability.IEnergyContainer; import gregtech.api.capability.impl.EnergyContainerHandler; +import gregtech.api.metatileentity.MTETrait; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; @@ -22,6 +26,7 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.World; +import net.minecraftforge.common.capabilities.Capability; import codechicken.lib.raytracer.CuboidRayTraceResult; import codechicken.lib.render.CCRenderState; @@ -34,19 +39,23 @@ import java.util.List; import static gregtech.api.capability.GregtechDataCodes.AMP_INDEX; +import static gregtech.api.capability.GregtechDataCodes.WORKING_ENABLED; public class MetaTileEntityDiode extends MetaTileEntityMultiblockPart - implements IPassthroughHatch, IMultiblockAbilityPart { + implements IPassthroughHatch, IMultiblockAbilityPart, + IControllable { protected IEnergyContainer energyContainer; private static final String AMP_NBT_KEY = "amp_mode"; private int amps; + private boolean isWorkingEnabled; public MetaTileEntityDiode(ResourceLocation metaTileEntityId, int tier) { super(metaTileEntityId, tier); amps = 1; reinitializeEnergyContainer(); + isWorkingEnabled = true; } @Override @@ -58,6 +67,7 @@ public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) { public NBTTagCompound writeToNBT(NBTTagCompound data) { super.writeToNBT(data); data.setInteger(AMP_NBT_KEY, amps); + data.setBoolean("IsWorkingEnabled", isWorkingEnabled); return data; } @@ -65,6 +75,9 @@ public NBTTagCompound writeToNBT(NBTTagCompound data) { public void readFromNBT(NBTTagCompound data) { super.readFromNBT(data); this.amps = data.getInteger(AMP_NBT_KEY); + if (data.hasKey("IsWorkingEnabled")) { + this.isWorkingEnabled = data.getBoolean("IsWorkingEnabled"); + } reinitializeEnergyContainer(); } @@ -72,12 +85,14 @@ public void readFromNBT(NBTTagCompound data) { public void writeInitialSyncData(PacketBuffer buf) { super.writeInitialSyncData(buf); buf.writeInt(amps); + buf.writeBoolean(isWorkingEnabled); } @Override public void receiveInitialSyncData(PacketBuffer buf) { super.receiveInitialSyncData(buf); this.amps = buf.readInt(); + this.isWorkingEnabled = buf.readBoolean(); } @Override @@ -85,6 +100,8 @@ public void receiveCustomData(int dataId, PacketBuffer buf) { super.receiveCustomData(dataId, buf); if (dataId == AMP_INDEX) { this.amps = buf.readInt(); + } else if (dataId == WORKING_ENABLED) { + this.isWorkingEnabled = buf.readBoolean(); } } @@ -120,13 +137,8 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, } @Override - public boolean isValidFrontFacing(EnumFacing facing) { - return true; - } - - @Override - public boolean onSoftMalletClick(EntityPlayer playerIn, EnumHand hand, EnumFacing facing, - CuboidRayTraceResult hitResult) { + public boolean onScrewdriverClick(EntityPlayer playerIn, EnumHand hand, EnumFacing facing, + CuboidRayTraceResult hitResult) { if (getWorld().isRemote) { scheduleRenderUpdate(); return true; @@ -153,9 +165,9 @@ public void addInformation(ItemStack stack, @Nullable World player, @NotNull Lis @Override public void addToolUsages(ItemStack stack, @Nullable World world, List tooltip, boolean advanced) { - tooltip.add(I18n.format("gregtech.tool_action.screwdriver.access_covers")); + tooltip.add(I18n.format("gregtech.machine.diode.tooltip_tool_usage_screwdriver")); tooltip.add(I18n.format("gregtech.tool_action.wrench.set_facing")); - tooltip.add(I18n.format("gregtech.tool_action.soft_mallet.toggle_mode")); + tooltip.add(I18n.format("gregtech.tool_action.soft_mallet.reset")); super.addToolUsages(stack, world, tooltip, advanced); } @@ -174,4 +186,31 @@ public void registerAbilities(@NotNull List abilityList) { public Class getPassthroughType() { return IEnergyContainer.class; } + + @Override + protected boolean shouldUpdate(MTETrait trait) { + return !(trait instanceof EnergyContainerHandler) || isWorkingEnabled; + } + + @Override + public T getCapability(Capability capability, EnumFacing side) { + if (capability == GregtechTileCapabilities.CAPABILITY_CONTROLLABLE) { + return GregtechTileCapabilities.CAPABILITY_CONTROLLABLE.cast(this); + } + + return super.getCapability(capability, side); + } + + @Override + public boolean isWorkingEnabled() { + return isWorkingEnabled; + } + + @Override + public void setWorkingEnabled(boolean isWorkingAllowed) { + this.isWorkingEnabled = isWorkingAllowed; + if (getWorld().isRemote) { + writeCustomData(GregtechDataCodes.WORKING_ENABLED, buf -> buf.writeBoolean(isWorkingAllowed)); + } + } } diff --git a/src/main/resources/assets/gregtech/lang/en_us.lang b/src/main/resources/assets/gregtech/lang/en_us.lang index 389d68cd3ce..6ab5189ca77 100644 --- a/src/main/resources/assets/gregtech/lang/en_us.lang +++ b/src/main/resources/assets/gregtech/lang/en_us.lang @@ -4240,9 +4240,9 @@ gregtech.machine.transformer.adjustable.opv.name=Overpowered Voltage Power Trans # Diodes gregtech.machine.diode.message=Max Amperage throughput: %s -gregtech.machine.diode.tooltip_tool_usage=Hit with a Soft Mallet to change Amperage flow. +gregtech.machine.diode.tooltip_tool_usage_screwdriver=§8Use Screwdriver to change Amperage flow or access Covers gregtech.machine.diode.tooltip_general=Allows Energy Flow in one direction and limits Amperage -gregtech.machine.diode.tooltip_starts_at=Starts as §f1A§7, use Soft Mallet to change +gregtech.machine.diode.tooltip_starts_at=Starts as §f1A§7, use Screwdriver to change gregtech.machine.diode.ulv.name=Ultra Low Voltage Diode gregtech.machine.diode.lv.name=Low Voltage Diode