Skip to content

Commit

Permalink
port Diodes from Gregicality
Browse files Browse the repository at this point in the history
  • Loading branch information
serenibyss committed Aug 13, 2021
1 parent 3c4a9cf commit d1bceee
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class MetaTileEntities {
public static final MetaTileEntityHull[] HULL = new MetaTileEntityHull[GTValues.V.length];
public static final MetaTileEntityTransformer[] TRANSFORMER = new MetaTileEntityTransformer[GTValues.V.length - 1]; // no ULV, no MAX
public static final MetaTileEntityAdjustableTransformer[] ADJUSTABLE_TRANSFORMER = new MetaTileEntityAdjustableTransformer[GTValues.V.length - 1]; // no ULV, no MAX
public static final MetaTileEntityDiode[] DIODES = new MetaTileEntityDiode[GTValues.V.length];
public static final MetaTileEntityBatteryBuffer[][] BATTERY_BUFFER = new MetaTileEntityBatteryBuffer[GTValues.V.length][];
public static final MetaTileEntityCharger[] CHARGER = new MetaTileEntityCharger[GTValues.V.length];

Expand Down Expand Up @@ -433,15 +434,26 @@ public static void init() {
// MISC MTE's START: IDs 1285-2000


// Transformer, IDs 1285-1314
// Transformer, IDs 1270-1299
endPos = GTValues.HT ? TRANSFORMER.length - 1 : Math.min(TRANSFORMER.length - 1, GTValues.UV);
for (int i = 0; i <= endPos; i++) {
MetaTileEntityTransformer transformer = new MetaTileEntityTransformer(gregtechId("transformer." + GTValues.VN[i].toLowerCase()), i);
TRANSFORMER[i] = GregTechAPI.registerMetaTileEntity(1285 + (i), transformer);
TRANSFORMER[i] = GregTechAPI.registerMetaTileEntity(1270 + (i), transformer);
MetaTileEntityAdjustableTransformer adjustableTransformer = new MetaTileEntityAdjustableTransformer(gregtechId("transformer.adjustable." + GTValues.VN[i].toLowerCase()), i);
ADJUSTABLE_TRANSFORMER[i] = GregTechAPI.registerMetaTileEntity(1300 + (i), adjustableTransformer);
ADJUSTABLE_TRANSFORMER[i] = GregTechAPI.registerMetaTileEntity(1285 + (i), adjustableTransformer);
}

// Diode, IDs 1300-1314
endPos = GTValues.HT ? DIODES.length - 1 : Math.min(DIODES.length - 1, GTValues.UV + 1);
for (int i = 0; i < endPos; i++) {
String diodeId = "diode." + GTValues.VN[i].toLowerCase();
MetaTileEntityDiode diode = new MetaTileEntityDiode(gregtechId(diodeId), i);
DIODES[i] = GregTechAPI.registerMetaTileEntity(1300 + i, diode);
}
// MAX Diode
MetaTileEntityDiode diode = new MetaTileEntityDiode(gregtechId("diode.max"), DIODES.length - 1);
DIODES[DIODES.length - 1] = GregTechAPI.registerMetaTileEntity(1300 + DIODES.length - 1, diode);

// Battery Buffer, IDs 1315-1374
endPos = GTValues.HT ? BATTERY_BUFFER.length - 1 : Math.min(BATTERY_BUFFER.length - 1, GTValues.UV + 1);
int[] batteryBufferSlots = new int[]{1, 4, 9, 16};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
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.gui.ModularUI;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.MetaTileEntityHolder;
import gregtech.api.metatileentity.TieredMetaTileEntity;
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 MetaTileEntityDiode extends TieredMetaTileEntity {

private static final String AMP_NBT_KEY = "amp_mode";
private int amps;

public MetaTileEntityDiode(ResourceLocation metaTileEntityId, int tier) {
super(metaTileEntityId, tier);
amps = 1;
reinitializeEnergyContainer();
}

@Override
public MetaTileEntity createMetaTileEntity(MetaTileEntityHolder holder) {
return new MetaTileEntityDiode(metaTileEntityId, getTier());
}

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

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

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

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

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

private void setAmpMode() {
amps = amps == 16 ? 1 : amps << 1;
if (!getWorld().isRemote) {
reinitializeEnergyContainer();
writeCustomData(101, b -> b.writeInt(amps));
getHolder().notifyBlockUpdate();
markDirty();
}
}

@Override
protected void reinitializeEnergyContainer() {
long tierVoltage = GTValues.V[getTier()];
this.energyContainer = new EnergyContainerHandler(this, tierVoltage * 8, tierVoltage, amps, tierVoltage, amps);
((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);
Textures.ENERGY_IN_MULTI.renderSided(getFrontFacing(), renderState, translation, PipelineUtil.color(pipeline, GTValues.VC[getTier()]));
Arrays.stream(EnumFacing.values()).filter(f -> f != frontFacing).forEach(f ->
Textures.ENERGY_OUT.renderSided(f, renderState, translation, PipelineUtil.color(pipeline, GTValues.VC[getTier()])));
}

@Override
public boolean isValidFrontFacing(EnumFacing facing) {
return true;
}

@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;
}

setAmpMode();
playerIn.sendMessage(new TextComponentTranslation("gregtech.machine.diode.message", amps));
return true;
}
return false;
}

@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) {
tooltip.add(I18n.format("gregtech.machine.diode.tooltip_general"));
tooltip.add(I18n.format("gregtech.machine.diode.tooltip_tool_usage"));
tooltip.add(I18n.format("gregtech.universal.tooltip.voltage_in",
energyContainer.getInputVoltage(), GTValues.VN[getTier()]));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static void registerCompatibility() {
oneProbe.registerProvider(new ControllableInfoProvider());
oneProbe.registerProvider(new DebugPipeNetInfoProvider());
oneProbe.registerProvider(new TransformerInfoProvider());
oneProbe.registerProvider(new DiodeInfoProvider());
oneProbe.registerProvider(new MultiblockInfoProvider());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package gregtech.integration.theoneprobe.provider;

import gregtech.api.capability.IEnergyContainer;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.MetaTileEntityHolder;
import gregtech.common.metatileentities.electric.MetaTileEntityDiode;
import mcjty.theoneprobe.api.ElementAlignment;
import mcjty.theoneprobe.api.IProbeInfo;
import mcjty.theoneprobe.api.TextStyleClass;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;

public class DiodeInfoProvider extends ElectricContainerInfoProvider {

@Override
public String getID() {
return "gregtech:diode_info_provider";
}

@Override
protected void addProbeInfo(IEnergyContainer capability, IProbeInfo probeInfo, TileEntity tileEntity, EnumFacing sideHit) {
if (tileEntity instanceof MetaTileEntityHolder) {
MetaTileEntity metaTileEntity = ((MetaTileEntityHolder) tileEntity).getMetaTileEntity();
if (metaTileEntity instanceof MetaTileEntityDiode) {
long inputAmperage = capability.getInputAmperage();
long outputAmperage = capability.getOutputAmperage();
IProbeInfo horizontalPane = probeInfo.vertical(probeInfo.defaultLayoutStyle().alignment(ElementAlignment.ALIGN_CENTER));
String transformInfo;
if (capability.inputsEnergy(sideHit)) {
transformInfo = "{*gregtech.top.transform_input*} " + inputAmperage + "A";
horizontalPane.text(TextStyleClass.INFO + transformInfo);
} else if (capability.outputsEnergy(sideHit)) {
transformInfo = "{*gregtech.top.transform_output*} " + outputAmperage + "A";
horizontalPane.text(TextStyleClass.INFO + transformInfo);
}
}
}
}
}
22 changes: 21 additions & 1 deletion src/main/resources/assets/gregtech/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -2984,7 +2984,6 @@ gregtech.machine.transformer.tooltip_transform_down=Transform Down: §a%dA %dV (
gregtech.machine.transformer.message_transform_down=Transforming Down, In: %dV %dA, Out: %dV %dA
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 4 Amps)
gregtech.machine.transformer_adjustable.message_adjust=Adjusted Hi-Amp to %dV %dA, Lo-Amp to %dV %dA

Expand Down Expand Up @@ -3018,6 +3017,27 @@ gregtech.machine.transformer.adjustable.uiv.name=UIV Voltage Adjustable Transfor
gregtech.machine.transformer.adjustable.umv.name=UMV Voltage Adjustable Transformer
gregtech.machine.transformer.adjustable.uxv.name=UXV Voltage Adjustable Transformer

# Diodes
gregtech.machine.diode.message=Max Amperage throughput: %s
gregtech.machine.diode.tooltip_general=A simple Diode that will allow Energy Flow in only one direction.
gregtech.machine.diode.tooltip_tool_usage=Hit with a Soft Hammer to toggle Amperage flow.

gregtech.machine.diode.ulv.name=Ultra Low Voltage Diode
gregtech.machine.diode.lv.name=Low Voltage Diode
gregtech.machine.diode.mv.name=Medium Voltage Diode
gregtech.machine.diode.hv.name=High Voltage Diode
gregtech.machine.diode.ev.name=Extreme Voltage Diode
gregtech.machine.diode.iv.name=Insane Voltage Diode
gregtech.machine.diode.luv.name=Ludicrous Voltage Diode
gregtech.machine.diode.zpm.name=ZPM Voltage Diode
gregtech.machine.diode.uv.name=Ultimate Voltage Diode
gregtech.machine.diode.uhv.name=UHV Voltage Diode
gregtech.machine.diode.uev.name=UEV Voltage Diode
gregtech.machine.diode.uiv.name=UIV Voltage Diode
gregtech.machine.diode.umv.name=UMV Voltage Diode
gregtech.machine.diode.uxv.name=UXV Voltage Diode
gregtech.machine.diode.max.name=MAX Voltage Diode

# Chargers
gregtech.machine.charger.ulv.name=Ultra Low Voltage Battery Charger
gregtech.machine.charger.lv.name=Low Voltage Battery Charger
Expand Down

0 comments on commit d1bceee

Please sign in to comment.