Skip to content

Commit 3e35cc9

Browse files
authored
Allow diode blocks to be toggled (#2679)
1 parent c97df1c commit 3e35cc9

File tree

2 files changed

+51
-12
lines changed

2 files changed

+51
-12
lines changed

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

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

33
import gregtech.api.GTValues;
4+
import gregtech.api.capability.GregtechDataCodes;
5+
import gregtech.api.capability.GregtechTileCapabilities;
6+
import gregtech.api.capability.IControllable;
47
import gregtech.api.capability.IEnergyContainer;
58
import gregtech.api.capability.impl.EnergyContainerHandler;
9+
import gregtech.api.metatileentity.MTETrait;
610
import gregtech.api.metatileentity.MetaTileEntity;
711
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
812
import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart;
@@ -22,6 +26,7 @@
2226
import net.minecraft.util.ResourceLocation;
2327
import net.minecraft.util.text.TextComponentTranslation;
2428
import net.minecraft.world.World;
29+
import net.minecraftforge.common.capabilities.Capability;
2530

2631
import codechicken.lib.raytracer.CuboidRayTraceResult;
2732
import codechicken.lib.render.CCRenderState;
@@ -34,19 +39,23 @@
3439
import java.util.List;
3540

3641
import static gregtech.api.capability.GregtechDataCodes.AMP_INDEX;
42+
import static gregtech.api.capability.GregtechDataCodes.WORKING_ENABLED;
3743

3844
public class MetaTileEntityDiode extends MetaTileEntityMultiblockPart
39-
implements IPassthroughHatch, IMultiblockAbilityPart<IPassthroughHatch> {
45+
implements IPassthroughHatch, IMultiblockAbilityPart<IPassthroughHatch>,
46+
IControllable {
4047

4148
protected IEnergyContainer energyContainer;
4249

4350
private static final String AMP_NBT_KEY = "amp_mode";
4451
private int amps;
52+
private boolean isWorkingEnabled;
4553

4654
public MetaTileEntityDiode(ResourceLocation metaTileEntityId, int tier) {
4755
super(metaTileEntityId, tier);
4856
amps = 1;
4957
reinitializeEnergyContainer();
58+
isWorkingEnabled = true;
5059
}
5160

5261
@Override
@@ -58,33 +67,41 @@ public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) {
5867
public NBTTagCompound writeToNBT(NBTTagCompound data) {
5968
super.writeToNBT(data);
6069
data.setInteger(AMP_NBT_KEY, amps);
70+
data.setBoolean("IsWorkingEnabled", isWorkingEnabled);
6171
return data;
6272
}
6373

6474
@Override
6575
public void readFromNBT(NBTTagCompound data) {
6676
super.readFromNBT(data);
6777
this.amps = data.getInteger(AMP_NBT_KEY);
78+
if (data.hasKey("IsWorkingEnabled")) {
79+
this.isWorkingEnabled = data.getBoolean("IsWorkingEnabled");
80+
}
6881
reinitializeEnergyContainer();
6982
}
7083

7184
@Override
7285
public void writeInitialSyncData(PacketBuffer buf) {
7386
super.writeInitialSyncData(buf);
7487
buf.writeInt(amps);
88+
buf.writeBoolean(isWorkingEnabled);
7589
}
7690

7791
@Override
7892
public void receiveInitialSyncData(PacketBuffer buf) {
7993
super.receiveInitialSyncData(buf);
8094
this.amps = buf.readInt();
95+
this.isWorkingEnabled = buf.readBoolean();
8196
}
8297

8398
@Override
8499
public void receiveCustomData(int dataId, PacketBuffer buf) {
85100
super.receiveCustomData(dataId, buf);
86101
if (dataId == AMP_INDEX) {
87102
this.amps = buf.readInt();
103+
} else if (dataId == WORKING_ENABLED) {
104+
this.isWorkingEnabled = buf.readBoolean();
88105
}
89106
}
90107

@@ -120,13 +137,8 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation,
120137
}
121138

122139
@Override
123-
public boolean isValidFrontFacing(EnumFacing facing) {
124-
return true;
125-
}
126-
127-
@Override
128-
public boolean onSoftMalletClick(EntityPlayer playerIn, EnumHand hand, EnumFacing facing,
129-
CuboidRayTraceResult hitResult) {
140+
public boolean onScrewdriverClick(EntityPlayer playerIn, EnumHand hand, EnumFacing facing,
141+
CuboidRayTraceResult hitResult) {
130142
if (getWorld().isRemote) {
131143
scheduleRenderUpdate();
132144
return true;
@@ -153,9 +165,9 @@ public void addInformation(ItemStack stack, @Nullable World player, @NotNull Lis
153165

154166
@Override
155167
public void addToolUsages(ItemStack stack, @Nullable World world, List<String> tooltip, boolean advanced) {
156-
tooltip.add(I18n.format("gregtech.tool_action.screwdriver.access_covers"));
168+
tooltip.add(I18n.format("gregtech.machine.diode.tooltip_tool_usage_screwdriver"));
157169
tooltip.add(I18n.format("gregtech.tool_action.wrench.set_facing"));
158-
tooltip.add(I18n.format("gregtech.tool_action.soft_mallet.toggle_mode"));
170+
tooltip.add(I18n.format("gregtech.tool_action.soft_mallet.reset"));
159171
super.addToolUsages(stack, world, tooltip, advanced);
160172
}
161173

@@ -174,4 +186,31 @@ public void registerAbilities(@NotNull List<IPassthroughHatch> abilityList) {
174186
public Class<?> getPassthroughType() {
175187
return IEnergyContainer.class;
176188
}
189+
190+
@Override
191+
protected boolean shouldUpdate(MTETrait trait) {
192+
return !(trait instanceof EnergyContainerHandler) || isWorkingEnabled;
193+
}
194+
195+
@Override
196+
public <T> T getCapability(Capability<T> capability, EnumFacing side) {
197+
if (capability == GregtechTileCapabilities.CAPABILITY_CONTROLLABLE) {
198+
return GregtechTileCapabilities.CAPABILITY_CONTROLLABLE.cast(this);
199+
}
200+
201+
return super.getCapability(capability, side);
202+
}
203+
204+
@Override
205+
public boolean isWorkingEnabled() {
206+
return isWorkingEnabled;
207+
}
208+
209+
@Override
210+
public void setWorkingEnabled(boolean isWorkingAllowed) {
211+
this.isWorkingEnabled = isWorkingAllowed;
212+
if (getWorld().isRemote) {
213+
writeCustomData(GregtechDataCodes.WORKING_ENABLED, buf -> buf.writeBoolean(isWorkingAllowed));
214+
}
215+
}
177216
}

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

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

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

42514251
gregtech.machine.diode.ulv.name=Ultra Low Voltage Diode
42524252
gregtech.machine.diode.lv.name=Low Voltage Diode

0 commit comments

Comments
 (0)