11package gregtech .common .metatileentities .electric ;
22
33import gregtech .api .GTValues ;
4+ import gregtech .api .capability .GregtechDataCodes ;
5+ import gregtech .api .capability .GregtechTileCapabilities ;
6+ import gregtech .api .capability .IControllable ;
47import gregtech .api .capability .IEnergyContainer ;
58import gregtech .api .capability .impl .EnergyContainerHandler ;
9+ import gregtech .api .metatileentity .MTETrait ;
610import gregtech .api .metatileentity .MetaTileEntity ;
711import gregtech .api .metatileentity .interfaces .IGregTechTileEntity ;
812import gregtech .api .metatileentity .multiblock .IMultiblockAbilityPart ;
2226import net .minecraft .util .ResourceLocation ;
2327import net .minecraft .util .text .TextComponentTranslation ;
2428import net .minecraft .world .World ;
29+ import net .minecraftforge .common .capabilities .Capability ;
2530
2631import codechicken .lib .raytracer .CuboidRayTraceResult ;
2732import codechicken .lib .render .CCRenderState ;
3439import java .util .List ;
3540
3641import static gregtech .api .capability .GregtechDataCodes .AMP_INDEX ;
42+ import static gregtech .api .capability .GregtechDataCodes .WORKING_ENABLED ;
3743
3844public 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}
0 commit comments