Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 22cf316
Author: DStrand1 <[email protected]>
Date:   Thu Aug 12 21:05:58 2021 -0500

    Revert "clean up duplicated code in energy hatch"

    This reverts commit 44b1b7f.

commit 44b1b7f
Author: DStrand1 <[email protected]>
Date:   Thu Aug 12 20:07:39 2021 -0500

    clean up duplicated code in energy hatch

commit 0163764
Author: Tech22 <[email protected]>
Date:   Thu Aug 12 15:51:32 2021 -0400

    adjustable energy hatches

commit 6acee86
Author: Tech22 <[email protected]>
Date:   Thu Aug 12 14:57:21 2021 -0400

    adjustable transformers
  • Loading branch information
serenibyss committed Aug 13, 2021
1 parent 45e27fa commit 3c4a9cf
Show file tree
Hide file tree
Showing 10 changed files with 513 additions and 66 deletions.
4 changes: 4 additions & 0 deletions src/main/java/gregtech/api/render/Textures.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ public class Textures {
public static final SimpleOverlayRenderer ENERGY_IN = new SimpleOverlayRenderer("overlay/machine/overlay_energy_in");
public static final SimpleOverlayRenderer ENERGY_OUT_MULTI = new SimpleOverlayRenderer("overlay/machine/overlay_energy_out_multi");
public static final SimpleOverlayRenderer ENERGY_IN_MULTI = new SimpleOverlayRenderer("overlay/machine/overlay_energy_in_multi");
public static final SimpleOverlayRenderer ENERGY_OUT_HI = new SimpleOverlayRenderer("overlay/machine/overlay_energy_out_hi");
public static final SimpleOverlayRenderer ENERGY_IN_HI = new SimpleOverlayRenderer("overlay/machine/overlay_energy_in_hi");
public static final SimpleOverlayRenderer ENERGY_OUT_ULTRA = new SimpleOverlayRenderer("overlay/machine/overlay_energy_out_ultra");
public static final SimpleOverlayRenderer ENERGY_IN_ULTRA = new SimpleOverlayRenderer("overlay/machine/overlay_energy_in_ultra");
public static final SimpleOverlayRenderer CONVEYOR_OVERLAY = new SimpleOverlayRenderer("cover/overlay_conveyor");
public static final SimpleOverlayRenderer ARM_OVERLAY = new SimpleOverlayRenderer("cover/overlay_arm");
public static final SimpleOverlayRenderer PUMP_OVERLAY = new SimpleOverlayRenderer("cover/overlay_pump");
Expand Down
120 changes: 66 additions & 54 deletions src/main/java/gregtech/common/metatileentities/MetaTileEntities.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
package gregtech.common.metatileentities.electric;

import codechicken.lib.raytracer.CuboidRayTraceResult;
import codechicken.lib.render.CCRenderState;
import codechicken.lib.render.pipeline.IVertexOperation;
import codechicken.lib.vec.Matrix4;
import gregtech.api.GTValues;
import gregtech.api.capability.GregtechCapabilities;
import gregtech.api.capability.impl.EnergyContainerHandler;
import gregtech.api.capability.tool.ISoftHammerItem;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.MetaTileEntityHolder;
import gregtech.api.render.SimpleOverlayRenderer;
import gregtech.api.render.Textures;
import gregtech.api.util.PipelineUtil;
import gregtech.common.tools.DamageValues;
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.Arrays;
import java.util.List;

public class MetaTileEntityAdjustableTransformer extends MetaTileEntityTransformer {

private static final int[] hiAmpsRange = {1, 2, 4, 16};
private static final int[] loAmpsRange = {4, 8, 16, 64};
private int ampIndex;

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

@Override
public MetaTileEntity createMetaTileEntity(MetaTileEntityHolder holder) {
return new MetaTileEntityAdjustableTransformer(metaTileEntityId, 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) % hiAmpsRange.length;
if (!getWorld().isRemote) {
reinitializeEnergyContainer();
writeCustomData(101, b -> b.writeInt(ampIndex));
getHolder().notifyBlockUpdate();
markDirty();
}
}

@Override
protected void reinitializeEnergyContainer() {
long tierVoltage = GTValues.V[getTier()];
if (isInverted()) {
//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 = 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());
}
}

@Override
public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) {
super.renderMetaTileEntity(renderState, translation, pipeline);

SimpleOverlayRenderer otherFaceTexture;
SimpleOverlayRenderer frontFaceTexture;
switch (this.ampIndex) {
case 1:
otherFaceTexture = isInverted() ? Textures.ENERGY_IN_MULTI : Textures.ENERGY_OUT_MULTI;
frontFaceTexture = isInverted() ? Textures.ENERGY_IN_HI : Textures.ENERGY_IN_HI;
break;
case 2:
otherFaceTexture = isInverted() ? Textures.ENERGY_IN_HI : Textures.ENERGY_OUT_HI;
frontFaceTexture = isInverted() ? Textures.ENERGY_OUT_ULTRA : Textures.ENERGY_IN_ULTRA;
break;
case 3:
otherFaceTexture = isInverted() ? Textures.ENERGY_IN_ULTRA : Textures.ENERGY_OUT_ULTRA;
frontFaceTexture = isInverted() ? Textures.ENERGY_OUT_ULTRA : Textures.ENERGY_IN_ULTRA;
break;
default:
otherFaceTexture = isInverted() ? Textures.ENERGY_IN : Textures.ENERGY_OUT;
frontFaceTexture = isInverted() ? Textures.ENERGY_OUT_MULTI : Textures.ENERGY_IN_MULTI;
}

frontFaceTexture.renderSided(frontFacing, renderState, translation, PipelineUtil.color(pipeline, GTValues.VC[getTier() + 1]));
Arrays.stream(EnumFacing.values()).filter(f -> f != frontFacing)
.forEach((f -> otherFaceTexture.renderSided(f, renderState, translation, PipelineUtil.color(pipeline, GTValues.VC[getTier()]))));
}

@Override
public boolean onRightClick(EntityPlayer playerIn, EnumHand hand, EnumFacing facing, CuboidRayTraceResult hitResult) {
ItemStack itemStack = playerIn.getHeldItem(hand);
if (!itemStack.isEmpty() && itemStack.hasCapability(GregtechCapabilities.CAPABILITY_MALLET, null)) {
ISoftHammerItem softHammerItem = itemStack.getCapability(GregtechCapabilities.CAPABILITY_MALLET, null);

if (getWorld().isRemote) {
scheduleRenderUpdate();
return true;
}
if (!softHammerItem.damageItem(DamageValues.DAMAGE_FOR_SOFT_HAMMER, false)) {
return false;
}

if (isInverted()) {
setTransformUp(false);
playerIn.sendMessage(new TextComponentTranslation("gregtech.machine.transformer.message_transform_down",
energyContainer.getInputVoltage(), energyContainer.getInputAmperage(), energyContainer.getOutputVoltage(), energyContainer.getOutputAmperage()));
} else {
setTransformUp(true);
playerIn.sendMessage(new TextComponentTranslation("gregtech.machine.transformer.message_transform_up",
energyContainer.getInputVoltage(), energyContainer.getInputAmperage(), energyContainer.getOutputVoltage(), energyContainer.getOutputAmperage()));
}
return true;
}
return false;
}

@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.transformer_adjustable.message_adjust",
energyContainer.getInputVoltage(), energyContainer.getInputAmperage(), energyContainer.getOutputVoltage(), energyContainer.getOutputAmperage()));

return true;
}

@Override
public void addInformation(ItemStack stack, @Nullable World player, List<String> tooltip, boolean advanced) {
String lowerTierName = GTValues.VN[getTier()];
String higherTierName = GTValues.VN[getTier() + 1];
long lowerVoltage = energyContainer.getOutputVoltage();
long higherVoltage = energyContainer.getInputVoltage();
long lowerAmperage = energyContainer.getInputAmperage();
long higherAmperage = energyContainer.getOutputAmperage();

tooltip.add(I18n.format("gregtech.machine.transformer.tooltip_tool_usage"));
tooltip.add(I18n.format("gregtech.machine.transformer_adjustable.tooltip_tool_usage"));
tooltip.add(I18n.format("gregtech.universal.tooltip.energy_storage_capacity", energyContainer.getEnergyCapacity()));
tooltip.add(I18n.format("gregtech.machine.transformer.tooltip_transform_down", lowerAmperage, higherVoltage, higherTierName, higherAmperage, lowerVoltage, lowerTierName));
tooltip.add(I18n.format("gregtech.machine.transformer.tooltip_transform_up", higherAmperage, lowerVoltage, lowerTierName, lowerAmperage, higherVoltage, higherTierName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,7 @@ public void addInformation(ItemStack stack, @Nullable World player, List<String>

tooltip.add(I18n.format("gregtech.machine.transformer.tooltip_tool_usage"));
tooltip.add(I18n.format("gregtech.universal.tooltip.energy_storage_capacity", energyContainer.getEnergyCapacity()));
tooltip.add(I18n.format("gregtech.machine.transformer.tooltip_transform_down"));
tooltip.add(I18n.format("gregtech.universal.tooltip.voltage_in", higherVoltage, higherTierName));
tooltip.add(I18n.format("gregtech.universal.tooltip.voltage_out", lowerVoltage, lowerTierName));
tooltip.add(I18n.format("gregtech.universal.tooltip.amperage_in", lowerAmperage));
tooltip.add(I18n.format("gregtech.universal.tooltip.amperage_out", higherAmperage));
tooltip.add(I18n.format("gregtech.machine.transformer.tooltip_transform_up"));
tooltip.add(I18n.format("gregtech.universal.tooltip.voltage_in", lowerVoltage, lowerTierName));
tooltip.add(I18n.format("gregtech.universal.tooltip.voltage_out", higherVoltage, higherTierName));
tooltip.add(I18n.format("gregtech.universal.tooltip.amperage_in", higherAmperage));
tooltip.add(I18n.format("gregtech.universal.tooltip.amperage_out", lowerAmperage));
tooltip.add(I18n.format("gregtech.machine.transformer.tooltip_transform_down", lowerAmperage, higherVoltage, higherTierName, higherAmperage, lowerVoltage, lowerTierName));
tooltip.add(I18n.format("gregtech.machine.transformer.tooltip_transform_up", higherAmperage, lowerVoltage, lowerTierName, lowerAmperage, higherVoltage, higherTierName));
}
}
Loading

0 comments on commit 3c4a9cf

Please sign in to comment.