Skip to content

Commit

Permalink
adjustable energy hatches
Browse files Browse the repository at this point in the history
  • Loading branch information
TechLord22 committed Aug 12, 2021
1 parent 6acee86 commit 0163764
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ public static void init() {
ENERGY_INPUT_HATCH[i] = new MetaTileEntityEnergyHatch(gregtechId("energy_hatch.input." + voltageName), i, false);
ENERGY_INPUT_HATCH_ADJUSTABLE[i] = new MetaTileEntityAdjustableEnergyHatch(gregtechId("energy_hatch.adjustable.input." + voltageName), i, false);
ENERGY_OUTPUT_HATCH[i] = new MetaTileEntityEnergyHatch(gregtechId("energy_hatch.output." + voltageName), i, true);
ENERGY_OUTPUT_HATCH_ADJUSTABLE[i] = new MetaTileEntityAdjustableEnergyHatch(gregtechId("energy_hatch.adjustable.output." + voltageName), i, false);
ENERGY_OUTPUT_HATCH_ADJUSTABLE[i] = new MetaTileEntityAdjustableEnergyHatch(gregtechId("energy_hatch.adjustable.output." + voltageName), i, true);

GregTechAPI.registerMetaTileEntity(1450 + i, ENERGY_INPUT_HATCH[i]);
GregTechAPI.registerMetaTileEntity(1465 + i, ENERGY_INPUT_HATCH_ADJUSTABLE[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class MetaTileEntityAdjustableTransformer extends MetaTileEntityTransform

public MetaTileEntityAdjustableTransformer(ResourceLocation metaTileEntityId, int tier) {
super(metaTileEntityId, tier);
this.ampIndex = 0;
this.ampIndex = 2;
}

@Override
Expand All @@ -48,14 +48,14 @@ public MetaTileEntity createMetaTileEntity(MetaTileEntityHolder holder) {
@Override
public NBTTagCompound writeToNBT(NBTTagCompound data) {
super.writeToNBT(data);
data.setInteger("hiAmpIndex", ampIndex);
data.setInteger("ampIndex", ampIndex);
return data;
}

@Override
public void readFromNBT(NBTTagCompound data) {
super.readFromNBT(data);
this.ampIndex = data.getInteger("hiAmpIndex");
this.ampIndex = data.getInteger("ampIndex");
reinitializeEnergyContainer();
}

Expand Down Expand Up @@ -94,12 +94,12 @@ protected void incrementAmpIndex() {
protected void reinitializeEnergyContainer() {
long tierVoltage = GTValues.V[getTier()];
if (isInverted()) {
//storage = 1 amp high; input = tier / 4; amperage = X; output = tier; amperage = Y
//storage = 1 amp high; input = tier / 4; amperage = loAmpsRange[ampIndex]; output = tier; amperage = hiAmpsRange[ampIndex]
this.energyContainer = new EnergyContainerHandler(this, tierVoltage * 128L, tierVoltage, loAmpsRange[ampIndex], tierVoltage * 4, hiAmpsRange[ampIndex]);
((EnergyContainerHandler) this.energyContainer).setSideInputCondition(s -> s != getFrontFacing());
((EnergyContainerHandler) this.energyContainer).setSideOutputCondition(s -> s == getFrontFacing());
} else {
//storage = 1 amp high; input = tier; amperage = Y; output = tier / 4; amperage = X
//storage = 1 amp high; input = tier; amperage = hiAmpsRange[ampIndex]; output = tier / 4; amperage = loAmpsRange[ampIndex]
this.energyContainer = new EnergyContainerHandler(this, tierVoltage * 128L, tierVoltage * 4, hiAmpsRange[ampIndex], tierVoltage, loAmpsRange[ampIndex]);
((EnergyContainerHandler) this.energyContainer).setSideInputCondition(s -> s == getFrontFacing());
((EnergyContainerHandler) this.energyContainer).setSideOutputCondition(s -> s != getFrontFacing());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gregtech.common.metatileentities.electric.multiblockpart;

import codechicken.lib.raytracer.CuboidRayTraceResult;
import codechicken.lib.render.CCRenderState;
import codechicken.lib.render.pipeline.IVertexOperation;
import codechicken.lib.vec.Matrix4;
Expand All @@ -17,25 +18,34 @@
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;

import javax.annotation.Nullable;
import java.util.List;

public class MetaTileEntityAdjustableEnergyHatch extends MetaTileEntityMultiblockPart implements IMultiblockAbilityPart<IEnergyContainer> {

private static final int[] ampRange = {2, 4, 8, 16};
private int ampIndex;

private final boolean isExportHatch;
private final IEnergyContainer energyContainer;
private IEnergyContainer energyContainer;

public MetaTileEntityAdjustableEnergyHatch(ResourceLocation metaTileEntityId, int tier, boolean isExportHatch) {
super(metaTileEntityId, tier);
this.isExportHatch = isExportHatch;
this.ampIndex = 1;
if (isExportHatch) {
this.energyContainer = EnergyContainerHandler.emitterContainer(this, GTValues.V[tier] * 128L, GTValues.V[tier], 1);
this.energyContainer = EnergyContainerHandler.emitterContainer(this, GTValues.V[tier] * 32L, GTValues.V[tier], 2);
((EnergyContainerHandler) this.energyContainer).setSideOutputCondition(s -> s == getFrontFacing());
} else {
this.energyContainer = EnergyContainerHandler.receiverContainer(this, GTValues.V[tier] * 16L, GTValues.V[tier], 2);
this.energyContainer = EnergyContainerHandler.receiverContainer(this, GTValues.V[tier] * 32L, GTValues.V[tier], 2);
}
}

Expand All @@ -48,11 +58,95 @@ public MetaTileEntity createMetaTileEntity(MetaTileEntityHolder holder) {
public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) {
super.renderMetaTileEntity(renderState, translation, pipeline);
if (shouldRenderOverlay()) {
SimpleOverlayRenderer renderer = isExportHatch ? Textures.ENERGY_OUT_MULTI : Textures.ENERGY_IN_MULTI;
SimpleOverlayRenderer renderer;
switch (ampIndex) {
case 1:
renderer = isExportHatch ? Textures.ENERGY_OUT_MULTI : Textures.ENERGY_IN_MULTI;
break;

case 2:
renderer = isExportHatch ? Textures.ENERGY_OUT_HI : Textures.ENERGY_IN_HI;
break;
case 3:
renderer = isExportHatch ? Textures.ENERGY_OUT_ULTRA : Textures.ENERGY_IN_ULTRA;
break;
default:
renderer = isExportHatch ? Textures.ENERGY_OUT : Textures.ENERGY_IN;
}

renderer.renderSided(getFrontFacing(), renderState, translation, PipelineUtil.color(pipeline, GTValues.VC[getTier()]));
}
}

@Override
public NBTTagCompound writeToNBT(NBTTagCompound data) {
super.writeToNBT(data);
data.setInteger("ampIndex", ampIndex);
return data;
}

@Override
public void readFromNBT(NBTTagCompound data) {
super.readFromNBT(data);
this.ampIndex = data.getInteger("ampIndex");
reinitializeEnergyContainer();
}

@Override
public void writeInitialSyncData(PacketBuffer buf) {
super.writeInitialSyncData(buf);
buf.writeInt(ampIndex);
}

@Override
public void receiveInitialSyncData(PacketBuffer buf) {
super.receiveInitialSyncData(buf);
this.ampIndex = buf.readInt();
}

@Override
public void receiveCustomData(int dataId, PacketBuffer buf) {
super.receiveCustomData(dataId, buf);
if (dataId == 101) {
this.ampIndex = buf.readInt();
scheduleRenderUpdate();
}
}

protected void incrementAmpIndex() {
this.ampIndex = (this.ampIndex + 1) % ampRange.length;
if (!getWorld().isRemote) {
reinitializeEnergyContainer();
writeCustomData(101, b -> b.writeInt(ampIndex));
getHolder().notifyBlockUpdate();
markDirty();
}
}

protected void reinitializeEnergyContainer() {
long tierVoltage = GTValues.V[getTier()];
if (isExportHatch) {
this.energyContainer = EnergyContainerHandler.emitterContainer(this, tierVoltage * 32L, tierVoltage, ampRange[ampIndex]);
((EnergyContainerHandler) this.energyContainer).setSideOutputCondition(s -> s == getFrontFacing());
} else {
this.energyContainer = EnergyContainerHandler.receiverContainer(this, tierVoltage * 32L, tierVoltage, ampRange[ampIndex]);
}
}

@Override
public boolean onScrewdriverClick(EntityPlayer playerIn, EnumHand hand, EnumFacing facing, CuboidRayTraceResult hitResult) {
if (getWorld().isRemote) {
scheduleRenderUpdate();
return true;
}

incrementAmpIndex();
playerIn.sendMessage(new TextComponentTranslation("gregtech.machine.energy_hatch_adjustable.message_adjust",
isExportHatch ? energyContainer.getOutputAmperage() : energyContainer.getInputAmperage()));

return true;
}

@Override
public MultiblockAbility<IEnergyContainer> getAbility() {
return isExportHatch ? MultiblockAbility.OUTPUT_ENERGY : MultiblockAbility.INPUT_ENERGY;
Expand All @@ -77,12 +171,14 @@ protected ModularUI createUI(EntityPlayer entityPlayer) {
public void addInformation(ItemStack stack, @Nullable World player, List<String> tooltip, boolean advanced) {
String tierName = GTValues.VN[getTier()];

tooltip.add(I18n.format("gregtech.machine.transformer_adjustable.tooltip_tool_usage"));

if (isExportHatch) {
tooltip.add(I18n.format("gregtech.machine.energy_hatch.output.tooltip"));
tooltip.add(I18n.format("gregtech.machine.energy_hatch.adjustable.output.tooltip"));
tooltip.add(I18n.format("gregtech.universal.tooltip.voltage_out", energyContainer.getOutputVoltage(), tierName));
tooltip.add(I18n.format("gregtech.universal.tooltip.amperage_out_till", energyContainer.getOutputAmperage()));
} else {
tooltip.add(I18n.format("gregtech.machine.energy_hatch.input.tooltip"));
tooltip.add(I18n.format("gregtech.machine.energy_hatch.adjustable.input.tooltip"));
tooltip.add(I18n.format("gregtech.universal.tooltip.voltage_in", energyContainer.getInputVoltage(), tierName));
tooltip.add(I18n.format("gregtech.universal.tooltip.amperage_in_till", energyContainer.getInputAmperage()));
}
Expand Down
64 changes: 33 additions & 31 deletions src/main/resources/assets/gregtech/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -2985,7 +2985,7 @@ gregtech.machine.transformer.message_transform_down=Transforming Down, In: %dV %
gregtech.machine.transformer.tooltip_transform_up=Transform Up: §a%dA %dV (%d)§7 -> §a%dA %dV (%d)
gregtech.machine.transformer.message_transform_up=Transforming Up, In: %dV %dA, Out: %dV %dA

gregtech.machine.transformer_adjustable.tooltip_tool_usage=Use Screwdriver to cycle amperage (Starts as 1 Amp)
gregtech.machine.transformer_adjustable.tooltip_tool_usage=Use Screwdriver to cycle amperage (Starts as 4 Amps)
gregtech.machine.transformer_adjustable.message_adjust=Adjusted Hi-Amp to %dV %dA, Lo-Amp to %dV %dA

gregtech.machine.transformer.ulv.name=Ultra Low Voltage Transformer
Expand Down Expand Up @@ -3448,21 +3448,21 @@ gregtech.machine.energy_hatch.input.max.name=MAX Energy Hatch

gregtech.machine.energy_hatch.adjustable.input.tooltip=Adjustable Ampere Energy Input for Multiblocks

gregtech.machine.energy_hatch.adjustable.input.ulv.name=ULV Hi-Amp Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.lv.name=LV Hi-Amp Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.mv.name=MV Hi-Amp Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.hv.name=HV Hi-Amp Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.ev.name=EV Hi-Amp Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.iv.name=IV Hi-Amp Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.luv.name=LuV Hi-Amp Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.zpm.name=ZPM Hi-Amp Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.uv.name=UV Hi-Amp Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.uhv.name=UHV Hi-Amp Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.uev.name=UEV Hi-Amp Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.uiv.name=UIV Hi-Amp Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.umv.name=UMV Hi-Amp Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.uxv.name=UXV Hi-Amp Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.max.name=MAX Hi-Amp Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.ulv.name=ULV Adjustable Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.lv.name=LV Adjustable Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.mv.name=MV Adjustable Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.hv.name=HV Adjustable Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.ev.name=EV Adjustable Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.iv.name=IV Adjustable Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.luv.name=LuV Adjustable Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.zpm.name=ZPM Adjustable Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.uv.name=UV Adjustable Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.uhv.name=UHV Adjustable Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.uev.name=UEV Adjustable Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.uiv.name=UIV Adjustable Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.umv.name=UMV Adjustable Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.uxv.name=UXV Adjustable Energy Hatch
gregtech.machine.energy_hatch.adjustable.input.max.name=MAX Adjustable Energy Hatch

gregtech.machine.energy_hatch.output.tooltip=Energy Output for Multiblocks

Expand All @@ -3484,21 +3484,23 @@ gregtech.machine.energy_hatch.output.max.name=MAX Dynamo Hatch

gregtech.machine.energy_hatch.adjustable.output.tooltip=Adjustable Ampere Energy Output for Multiblocks

gregtech.machine.energy_hatch.adjustable.output.ulv.name=ULV Hi-Amp Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.lv.name=LV Hi-Amp Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.mv.name=MV Hi-Amp Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.hv.name=HV Hi-Amp Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.ev.name=EV Hi-Amp Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.iv.name=IV Hi-Amp Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.luv.name=LuV Hi-Amp Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.zpm.name=ZPM Hi-Amp Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.uv.name=UV Hi-Amp Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.uhv.name=UHV Hi-Amp Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.uev.name=UEV Hi-Amp Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.uiv.name=UIV Hi-Amp Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.umv.name=UMV Hi-Amp Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.uxv.name=UXV Hi-Amp Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.max.name=MAX Hi-Amp Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.ulv.name=ULV Adjustable Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.lv.name=LV Adjustable Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.mv.name=MV Adjustable Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.hv.name=HV Adjustable Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.ev.name=EV Adjustable Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.iv.name=IV Adjustable Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.luv.name=LuV Adjustable Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.zpm.name=ZPM Adjustable Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.uv.name=UV Adjustable Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.uhv.name=UHV Adjustable Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.uev.name=UEV Adjustable Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.uiv.name=UIV Adjustable Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.umv.name=UMV Adjustable Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.uxv.name=UXV Adjustable Dynamo Hatch
gregtech.machine.energy_hatch.adjustable.output.max.name=MAX Adjustable Dynamo Hatch

gregtech.machine.energy_hatch_adjustable.message_adjust=Adjusted Amperage to %dA

gregtech.machine.rotor_holder.tooltip1=Rotor Holder for Multiblocks
gregtech.machine.rotor_holder.tooltip2=Holds Rotor in place so it will not fly away
Expand Down

0 comments on commit 0163764

Please sign in to comment.