Skip to content

Commit b860747

Browse files
committed
Toggeable diodes
1 parent 7141fcf commit b860747

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityDiode.java

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package gregtech.common.metatileentities.electric;
22

33
import gregtech.api.GTValues;
4+
import gregtech.api.capability.GregtechTileCapabilities;
5+
import gregtech.api.capability.IControllable;
46
import gregtech.api.capability.IEnergyContainer;
57
import gregtech.api.capability.impl.EnergyContainerHandler;
8+
import gregtech.api.metatileentity.MTETrait;
69
import gregtech.api.metatileentity.MetaTileEntity;
710
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
811
import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart;
@@ -22,6 +25,7 @@
2225
import net.minecraft.util.ResourceLocation;
2326
import net.minecraft.util.text.TextComponentTranslation;
2427
import net.minecraft.world.World;
28+
import net.minecraftforge.common.capabilities.Capability;
2529

2630
import codechicken.lib.raytracer.CuboidRayTraceResult;
2731
import codechicken.lib.render.CCRenderState;
@@ -36,17 +40,20 @@
3640
import static gregtech.api.capability.GregtechDataCodes.AMP_INDEX;
3741

3842
public class MetaTileEntityDiode extends MetaTileEntityMultiblockPart
39-
implements IPassthroughHatch, IMultiblockAbilityPart<IPassthroughHatch> {
43+
implements IPassthroughHatch, IMultiblockAbilityPart<IPassthroughHatch>,
44+
IControllable {
4045

4146
protected IEnergyContainer energyContainer;
4247

4348
private static final String AMP_NBT_KEY = "amp_mode";
4449
private int amps;
50+
private boolean isWorkingEnabled;
4551

4652
public MetaTileEntityDiode(ResourceLocation metaTileEntityId, int tier) {
4753
super(metaTileEntityId, tier);
4854
amps = 1;
4955
reinitializeEnergyContainer();
56+
isWorkingEnabled = true;
5057
}
5158

5259
@Override
@@ -58,13 +65,15 @@ public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) {
5865
public NBTTagCompound writeToNBT(NBTTagCompound data) {
5966
super.writeToNBT(data);
6067
data.setInteger(AMP_NBT_KEY, amps);
68+
data.setBoolean("IsWorkingEnabled", isWorkingEnabled);
6169
return data;
6270
}
6371

6472
@Override
6573
public void readFromNBT(NBTTagCompound data) {
6674
super.readFromNBT(data);
6775
this.amps = data.getInteger(AMP_NBT_KEY);
76+
this.isWorkingEnabled = data.getBoolean("IsWorkingEnabled");
6877
reinitializeEnergyContainer();
6978
}
7079

@@ -125,8 +134,8 @@ public boolean isValidFrontFacing(EnumFacing facing) {
125134
}
126135

127136
@Override
128-
public boolean onSoftMalletClick(EntityPlayer playerIn, EnumHand hand, EnumFacing facing,
129-
CuboidRayTraceResult hitResult) {
137+
public boolean onScrewdriverClick(EntityPlayer playerIn, EnumHand hand, EnumFacing facing,
138+
CuboidRayTraceResult hitResult) {
130139
if (getWorld().isRemote) {
131140
scheduleRenderUpdate();
132141
return true;
@@ -153,9 +162,9 @@ public void addInformation(ItemStack stack, @Nullable World player, @NotNull Lis
153162

154163
@Override
155164
public void addToolUsages(ItemStack stack, @Nullable World world, List<String> tooltip, boolean advanced) {
156-
tooltip.add(I18n.format("gregtech.tool_action.screwdriver.access_covers"));
165+
tooltip.add(I18n.format("gregtech.machine.diode.tooltip_tool_usage_screwdriver"));
157166
tooltip.add(I18n.format("gregtech.tool_action.wrench.set_facing"));
158-
tooltip.add(I18n.format("gregtech.tool_action.soft_mallet.toggle_mode"));
167+
tooltip.add(I18n.format("gregtech.tool_action.soft_mallet.reset"));
159168
super.addToolUsages(stack, world, tooltip, advanced);
160169
}
161170

@@ -174,4 +183,28 @@ public void registerAbilities(@NotNull List<IPassthroughHatch> abilityList) {
174183
public Class<?> getPassthroughType() {
175184
return IEnergyContainer.class;
176185
}
186+
187+
@Override
188+
protected boolean shouldUpdate(MTETrait trait) {
189+
return !(trait instanceof EnergyContainerHandler) || isWorkingEnabled;
190+
}
191+
192+
@Override
193+
public <T> T getCapability(Capability<T> capability, EnumFacing side) {
194+
if (capability == GregtechTileCapabilities.CAPABILITY_CONTROLLABLE) {
195+
return GregtechTileCapabilities.CAPABILITY_CONTROLLABLE.cast(this);
196+
}
197+
198+
return super.getCapability(capability, side);
199+
}
200+
201+
@Override
202+
public boolean isWorkingEnabled() {
203+
return isWorkingEnabled;
204+
}
205+
206+
@Override
207+
public void setWorkingEnabled(boolean isWorkingAllowed) {
208+
this.isWorkingEnabled = isWorkingAllowed;
209+
}
177210
}

src/main/resources/assets/gregtech/lang/en_us.lang

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4240,9 +4240,9 @@ gregtech.machine.transformer.adjustable.opv.name=Overpowered Voltage Power Trans
42404240

42414241
# Diodes
42424242
gregtech.machine.diode.message=Max Amperage throughput: %s
4243-
gregtech.machine.diode.tooltip_tool_usage=Hit with a Soft Mallet to change Amperage flow.
4243+
gregtech.machine.diode.tooltip_tool_usage_screwdriver=§8Use Screwdriver to change Amperage flow or access Covers
42444244
gregtech.machine.diode.tooltip_general=Allows Energy Flow in one direction and limits Amperage
4245-
gregtech.machine.diode.tooltip_starts_at=Starts as §f1A§7, use Soft Mallet to change
4245+
gregtech.machine.diode.tooltip_starts_at=Starts as §f1A§7, use Screwdriver to change
42464246

42474247
gregtech.machine.diode.ulv.name=Ultra Low Voltage Diode
42484248
gregtech.machine.diode.lv.name=Low Voltage Diode

0 commit comments

Comments
 (0)