Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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<IPassthroughHatch> {
implements IPassthroughHatch, IMultiblockAbilityPart<IPassthroughHatch>,
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
Expand All @@ -58,33 +67,41 @@ 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;
}

@Override
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();
}

@Override
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
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();
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -153,9 +165,9 @@ public void addInformation(ItemStack stack, @Nullable World player, @NotNull Lis

@Override
public void addToolUsages(ItemStack stack, @Nullable World world, List<String> 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);
}

Expand All @@ -174,4 +186,31 @@ public void registerAbilities(@NotNull List<IPassthroughHatch> abilityList) {
public Class<?> getPassthroughType() {
return IEnergyContainer.class;
}

@Override
protected boolean shouldUpdate(MTETrait trait) {
return !(trait instanceof EnergyContainerHandler) || isWorkingEnabled;
}

@Override
public <T> T getCapability(Capability<T> 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));
}
}
}
4 changes: 2 additions & 2 deletions src/main/resources/assets/gregtech/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading