Skip to content

Commit

Permalink
clean up duplicated code in energy hatch
Browse files Browse the repository at this point in the history
  • Loading branch information
serenibyss committed Aug 13, 2021
1 parent 0163764 commit 44b1b7f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@
import codechicken.lib.render.pipeline.IVertexOperation;
import codechicken.lib.vec.Matrix4;
import gregtech.api.GTValues;
import gregtech.api.capability.IEnergyContainer;
import gregtech.api.capability.impl.EnergyContainerHandler;
import gregtech.api.gui.ModularUI;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.MetaTileEntityHolder;
import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart;
import gregtech.api.metatileentity.multiblock.MultiblockAbility;
import gregtech.api.render.SimpleOverlayRenderer;
import gregtech.api.render.Textures;
import gregtech.api.util.PipelineUtil;
Expand All @@ -29,24 +25,15 @@
import javax.annotation.Nullable;
import java.util.List;

public class MetaTileEntityAdjustableEnergyHatch extends MetaTileEntityMultiblockPart implements IMultiblockAbilityPart<IEnergyContainer> {
public class MetaTileEntityAdjustableEnergyHatch extends MetaTileEntityEnergyHatch {

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

private final boolean isExportHatch;
private IEnergyContainer energyContainer;

public MetaTileEntityAdjustableEnergyHatch(ResourceLocation metaTileEntityId, int tier, boolean isExportHatch) {
super(metaTileEntityId, tier);
this.isExportHatch = isExportHatch;
super(metaTileEntityId, tier, isExportHatch);
this.ampIndex = 1;
if (isExportHatch) {
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] * 32L, GTValues.V[tier], 2);
}
reinitializeEnergyContainer();
}

@Override
Expand All @@ -55,15 +42,13 @@ public MetaTileEntity createMetaTileEntity(MetaTileEntityHolder holder) {
}

@Override
public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) {
super.renderMetaTileEntity(renderState, translation, pipeline);
protected void renderOverlay(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) {
if (shouldRenderOverlay()) {
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;
Expand All @@ -73,7 +58,6 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation,
default:
renderer = isExportHatch ? Textures.ENERGY_OUT : Textures.ENERGY_IN;
}

renderer.renderSided(getFrontFacing(), renderState, translation, PipelineUtil.color(pipeline, GTValues.VC[getTier()]));
}
}
Expand Down Expand Up @@ -125,11 +109,12 @@ protected void incrementAmpIndex() {

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

Expand All @@ -139,50 +124,15 @@ public boolean onScrewdriverClick(EntityPlayer playerIn, EnumHand hand, EnumFaci
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;
}

@Override
public void registerAbilities(List<IEnergyContainer> abilityList) {
abilityList.add(energyContainer);
}

@Override
protected boolean openGUIOnRightClick() {
return false;
}

@Override
protected ModularUI createUI(EntityPlayer entityPlayer) {
return null;
}

@Override
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.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.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()));
}
tooltip.add(I18n.format("gregtech.universal.tooltip.energy_storage_capacity", energyContainer.getEnergyCapacity()));
tooltip.add(I18n.format("gregtech.universal.enabled"));
super.addInformation(stack, player, tooltip, advanced);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

public class MetaTileEntityEnergyHatch extends MetaTileEntityMultiblockPart implements IMultiblockAbilityPart<IEnergyContainer> {

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

public MetaTileEntityEnergyHatch(ResourceLocation metaTileEntityId, int tier, boolean isExportHatch) {
super(metaTileEntityId, tier);
Expand All @@ -47,6 +47,10 @@ public MetaTileEntity createMetaTileEntity(MetaTileEntityHolder holder) {
@Override
public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) {
super.renderMetaTileEntity(renderState, translation, pipeline);
renderOverlay(renderState, translation, pipeline);
}

protected void renderOverlay(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) {
if (shouldRenderOverlay()) {
SimpleOverlayRenderer renderer = isExportHatch ? Textures.ENERGY_OUT_MULTI : Textures.ENERGY_IN_MULTI;
renderer.renderSided(getFrontFacing(), renderState, translation, PipelineUtil.color(pipeline, GTValues.VC[getTier()]));
Expand Down

0 comments on commit 44b1b7f

Please sign in to comment.