diff --git a/src/main/java/gregtech/api/gui/widgets/TextFieldWidgetInfiniteEnergy.java b/src/main/java/gregtech/api/gui/widgets/TextFieldWidgetInfiniteEnergy.java deleted file mode 100644 index 74367199174..00000000000 --- a/src/main/java/gregtech/api/gui/widgets/TextFieldWidgetInfiniteEnergy.java +++ /dev/null @@ -1,61 +0,0 @@ -package gregtech.api.gui.widgets; - -import gregtech.common.metatileentities.electric.MetaTileEntityInfiniteEmitter; -import net.minecraft.client.Minecraft; -import net.minecraft.network.PacketBuffer; -import net.minecraftforge.fml.common.FMLCommonHandler; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; -import org.lwjgl.input.Keyboard; - -public class TextFieldWidgetInfiniteEnergy extends TextFieldWidget { - private final MetaTileEntityInfiniteEmitter.InfiniteEnergyUIData data; - - public TextFieldWidgetInfiniteEnergy( - int xPosition, - int yPosition, - int width, - int height, - boolean enableBackground, - MetaTileEntityInfiniteEmitter.InfiniteEnergyUIData data) { - super(xPosition, yPosition, width, height, enableBackground, data::getEnergyText, data::setEnergyText); - this.data = data; - if (FMLCommonHandler.instance().getSide().isClient()) { - this.textField.setCanLoseFocus(false); - this.textField.setFocused(true); - } - } - - @Override - public void handleClientAction(int id, PacketBuffer buffer) { - super.handleClientAction(id, buffer); - if (id == 35) { - if (buffer.readBoolean()) data.markDirty(false); - this.gui.entityPlayer.closeScreen(); - } - } - - @Override - public boolean keyTyped(char charTyped, int keyCode) { - if (!super.keyTyped(charTyped, keyCode)) { - GuiCloseAction action = GuiCloseAction.getFromKey(keyCode); - if (action == GuiCloseAction.NONE) return false; - else writeClientAction(35, buffer -> buffer.writeBoolean(action == GuiCloseAction.CLOSE_WITHOUT_SAVE)); - } - return true; - } - - @SideOnly(Side.CLIENT) - private enum GuiCloseAction { - CLOSE, - CLOSE_WITHOUT_SAVE, - NONE; - - private static GuiCloseAction getFromKey(int keyCode) { - if (keyCode == Keyboard.KEY_RETURN) return CLOSE; - else if (keyCode == 1 || Minecraft.getMinecraft().gameSettings.keyBindInventory.isActiveAndMatches(keyCode)) - return CLOSE_WITHOUT_SAVE; - else return NONE; - } - } -} diff --git a/src/main/java/gregtech/api/metatileentity/InfiniteEnergyTileEntityBase.java b/src/main/java/gregtech/api/metatileentity/InfiniteEnergyTileEntityBase.java deleted file mode 100644 index 200c28fc64d..00000000000 --- a/src/main/java/gregtech/api/metatileentity/InfiniteEnergyTileEntityBase.java +++ /dev/null @@ -1,64 +0,0 @@ -package gregtech.api.metatileentity; - -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.render.SimpleOverlayRenderer; -import gregtech.api.render.SimpleSidedCubeRenderer; -import gregtech.api.render.Textures; -import gregtech.common.metatileentities.traits.TraitInfiniteEnergy; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumHand; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; -import org.apache.commons.lang3.tuple.Pair; - -import java.text.DateFormat; -import java.text.SimpleDateFormat; - -public abstract class InfiniteEnergyTileEntityBase extends MetaTileEntity { - private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss"); - - protected final TRAIT trait; - - public InfiniteEnergyTileEntityBase(ResourceLocation metaTileEntityId) { - super(metaTileEntityId); - trait = createTrait(); - } - - protected abstract TRAIT createTrait(); - - @Override - public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) { - Textures.VOLTAGE_CASINGS[GTValues.MAX].render(renderState, translation, pipeline); - for (EnumFacing facing : EnumFacing.VALUES) - getOverlay().renderSided(facing, renderState, translation, pipeline); - } - - @Override - public boolean onWrenchClick(EntityPlayer player, EnumHand hand, EnumFacing wrenchSide, CuboidRayTraceResult hitResult) { - if (!player.isCreative() || player.isSneaking()) - return super.onWrenchClick(player, hand, wrenchSide, hitResult); - return true; - } - - @Override - public void update() { - super.update(); - } - - - @SideOnly(Side.CLIENT) - protected abstract SimpleOverlayRenderer getOverlay(); - - @Override - @SideOnly(Side.CLIENT) - public Pair getParticleTexture() { - return Pair.of(Textures.VOLTAGE_CASINGS[GTValues.MAX].getSpriteOnSide(SimpleSidedCubeRenderer.RenderSide.TOP), 0xFFFFFF); - } -} diff --git a/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java b/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java index d4af74f74d7..2f549f7c0ea 100644 --- a/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java +++ b/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java @@ -196,7 +196,7 @@ public class MetaTileEntities { public static final MetaTileEntityItemCollector[] ITEM_COLLECTOR = new MetaTileEntityItemCollector[4]; public static final MetaTileEntityFisher[] FISHER = new MetaTileEntityFisher[4]; - public static MetaTileEntityInfiniteEmitter INFINITE_EMITTER; + public static MetaTileEntityCreativeEnergy CREATIVE_ENERGY; public static void init() { GTLog.logger.info("Registering MetaTileEntities"); @@ -626,7 +626,7 @@ public static void init() { PRIMITIVE_WATER_PUMP = GregTechAPI.registerMetaTileEntity(1647, new MetaTileEntityPrimitiveWaterPump(gregtechId("primitive_water_pump"))); PUMP_OUTPUT_HATCH = GregTechAPI.registerMetaTileEntity(1648, new MetaTileEntityPumpHatch(gregtechId("pump_hatch"))); - INFINITE_EMITTER = GregTechAPI.registerMetaTileEntity(1649, new MetaTileEntityInfiniteEmitter(gregtechId("infinite_emitter"))); + CREATIVE_ENERGY = GregTechAPI.registerMetaTileEntity(1649, new MetaTileEntityCreativeEnergy()); // Steam Hatches/Buses STEAM_EXPORT_BUS = GregTechAPI.registerMetaTileEntity(1650, new MetaTileEntitySteamItemBus(gregtechId("steam_export_bus"), true)); STEAM_IMPORT_BUS = GregTechAPI.registerMetaTileEntity(1651, new MetaTileEntitySteamItemBus(gregtechId("steam_import_bus"), false)); diff --git a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityInfiniteEmitter.java b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityInfiniteEmitter.java deleted file mode 100644 index ea045d6b23f..00000000000 --- a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityInfiniteEmitter.java +++ /dev/null @@ -1,247 +0,0 @@ -package gregtech.common.metatileentities.electric; - -import gregtech.api.GTValues; -import gregtech.api.gui.IUIHolder; -import gregtech.api.gui.ModularUI; -import gregtech.api.gui.Widget; -import gregtech.api.gui.resources.EmptyTextureArea; -import gregtech.api.gui.widgets.ClickButtonWidget; -import gregtech.api.gui.widgets.CycleButtonWidget; -import gregtech.api.gui.widgets.LabelWidget; -import gregtech.api.gui.widgets.TextFieldWidgetInfiniteEnergy; -import gregtech.api.metatileentity.InfiniteEnergyTileEntityBase; -import gregtech.api.metatileentity.MetaTileEntity; -import gregtech.api.metatileentity.MetaTileEntityHolder; -import gregtech.api.render.SimpleOverlayRenderer; -import gregtech.api.render.Textures; -import gregtech.api.util.function.BooleanConsumer; -import gregtech.common.metatileentities.traits.TraitInfiniteEmitter; -import net.minecraft.client.Minecraft; -import net.minecraft.client.resources.I18n; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.fml.client.config.GuiUtils; - -import java.math.BigInteger; -import java.util.ArrayDeque; -import java.util.Collections; -import java.util.function.Consumer; -import java.util.function.IntConsumer; -import java.util.function.Predicate; -import java.util.regex.Pattern; - -public class MetaTileEntityInfiniteEmitter extends InfiniteEnergyTileEntityBase { - public MetaTileEntityInfiniteEmitter(ResourceLocation metaTileEntityId) { - super(metaTileEntityId); - } - - @Override - protected TraitInfiniteEmitter createTrait() { - return new TraitInfiniteEmitter(this); - } - - @Override - public MetaTileEntity createMetaTileEntity(MetaTileEntityHolder holder) { - return new MetaTileEntityInfiniteEmitter(metaTileEntityId); - } - - @Override - protected ModularUI createUI(EntityPlayer entityPlayer) { - InfiniteEnergyUIData d = new InfiniteEnergyUIData(); - d.setEnergy(trait.getEnergy()); - d.setInfinite(trait.isInfinite()); - d.setTier(trait.getTier()); - return d.guiBuilder() - .buttonInfinite(trait::setInfinite) - .energyInput("EU", trait::setEnergy) - .buttonTier(trait::setTier) - .buttonAcceptDecline() - .createUI(getHolder(), entityPlayer); - } - - @Override - protected SimpleOverlayRenderer getOverlay() { - return Textures.INFINITE_EMITTER_FACE; - } - - public static class InfiniteEnergyUIData { - private static final Pattern NUMBER_PATTERN = Pattern.compile("[0-9]*"); - private static final Predicate NUMBER_PATTERN_VALIDATOR = s -> NUMBER_PATTERN.matcher(s).matches(); - private static final String[] TRANSLATABLE_VOLTAGE_NAMES; - - static { - TRANSLATABLE_VOLTAGE_NAMES = new String[GTValues.V.length]; - for (int i = 0; i < GTValues.V.length; i++) - TRANSLATABLE_VOLTAGE_NAMES[i] = "info.infinite_energy." + GTValues.VN[i].toLowerCase(); - } - - private boolean isDirty; - - private String energyText; - private int tier; - private boolean isInfinite; - - public InfiniteEnergyGuiBuilder guiBuilder() { - return new InfiniteEnergyGuiBuilder(); - } - - public void markDirty(boolean isDirty) { - this.isDirty = isDirty; - } - - public boolean isDirty() { - return this.isDirty; - } - - public String getEnergyText() { - return energyText; - } - - public void setEnergyText(String energyText) { - markDirty(true); - this.energyText = energyText; - } - - public BigInteger parseEnergyFromText() { - return energyText.isEmpty() ? BigInteger.ZERO : new BigInteger(energyText); - } - - public void setEnergy(BigInteger energy) { - setEnergyText(energy.toString()); - } - - public int getTier() { - return tier; - } - - public void setTier(int tier) { - markDirty(true); - this.tier = tier; - } - - public boolean isInfinite() { - return isInfinite; - } - - public void setInfinite(boolean infinite) { - markDirty(true); - isInfinite = infinite; - } - - public final class InfiniteEnergyGuiBuilder { - private final ArrayDeque widgets = new ArrayDeque<>(); - - private int y; - private boolean infinite; - private boolean energy; - private boolean tier; - - private BooleanConsumer applyInfiniteFlagChange; - private Consumer applyEnergyChange; - private IntConsumer applyTierChange; - - public InfiniteEnergyGuiBuilder buttonInfinite(BooleanConsumer applyInfiniteFlagChange) { - this.applyInfiniteFlagChange = applyInfiniteFlagChange; - if (!widgets.isEmpty()) y += 4; - widgets.add(new CycleButtonWidget( - 0, - y, - 200, - 20, - new String[]{"info.infinite_energy.finite", "info.infinite_energy.infinite"}, - () -> isInfinite() ? 1 : 0, - i -> setInfinite(i != 0) - )); - y += 20; - infinite = true; - return this; - } - - public InfiniteEnergyGuiBuilder energyInput(String labelText, Consumer applyEnergyChange) { - this.applyEnergyChange = applyEnergyChange; - if (!widgets.isEmpty()) y += 4; - widgets.add(new TextFieldWidgetInfiniteEnergy( - 2, - y, - 180, - 12, - true, - InfiniteEnergyUIData.this - ).setValidator(NUMBER_PATTERN_VALIDATOR)); - widgets.add(new LabelWidget(188, y + 2, labelText, -1)); - y += 12; - energy = true; - return this; - } - - public InfiniteEnergyGuiBuilder buttonTier(IntConsumer applyTierChange) { - this.applyTierChange = applyTierChange; - if (!widgets.isEmpty()) y += 4; - widgets.add(new CycleButtonWidget( - 0, - y, - 200, - 20, - TRANSLATABLE_VOLTAGE_NAMES, - InfiniteEnergyUIData.this::getTier, - InfiniteEnergyUIData.this::setTier - )); - y += 20; - tier = true; - return this; - } - - public InfiniteEnergyGuiBuilder buttonAcceptDecline() { - if (!widgets.isEmpty()) y += 16; - buttonClose(true); - buttonClose(false); - y += 20; - return this; - } - - private void buttonClose(boolean setDirty) { - widgets.add(new ClickButtonWidget( - setDirty ? 0 : 200 - 98, y, - 98, - 20, - setDirty ? "info.infinite_energy.accept" : "info.infinite_energy.decline", - c -> markDirty(setDirty)) { - @Override - public void handleClientAction(int id, PacketBuffer buffer) { - super.handleClientAction(id, buffer); - this.gui.entityPlayer.closeScreen(); - } - - @Override - public void drawInForeground(int mouseX, int mouseY) { - if (isMouseOver(getPosition().x, getPosition().y, getSize().width, getSize().height, mouseX, mouseY)) { - GuiUtils.drawHoveringText( - Collections.singletonList(I18n.format(setDirty ? "info.button.accept" : "info.button.decline")), - mouseX, - mouseY, - this.gui.getScreenWidth(), - this.gui.getScreenHeight(), - -1, - Minecraft.getMinecraft().fontRenderer); - } - } - }); - } - - public ModularUI createUI(IUIHolder holder, EntityPlayer player) { - ModularUI.Builder b = new ModularUI.Builder(new EmptyTextureArea(200, y), 200, y); - for (Widget w : widgets) b.widget(w); - b.bindCloseListener(() -> { - if (!player.world.isRemote && isDirty()) { - if (infinite) applyInfiniteFlagChange.apply(isInfinite()); - if (energy) applyEnergyChange.accept(parseEnergyFromText()); - if (tier) applyTierChange.accept(getTier()); - } - }); - return b.build(holder, player); - } - } - } - -} diff --git a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityCreativeEnergy.java b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityCreativeEnergy.java new file mode 100644 index 00000000000..4a72dd72bd0 --- /dev/null +++ b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityCreativeEnergy.java @@ -0,0 +1,203 @@ +package gregtech.common.metatileentities.storage; + +import codechicken.lib.render.CCRenderState; +import codechicken.lib.render.pipeline.ColourMultiplier; +import codechicken.lib.render.pipeline.IVertexOperation; +import codechicken.lib.vec.Cuboid6; +import codechicken.lib.vec.Matrix4; +import com.google.common.collect.Lists; +import gregtech.api.GTValues; +import gregtech.api.capability.GregtechCapabilities; +import gregtech.api.capability.IEnergyContainer; +import gregtech.api.gui.ModularUI; +import gregtech.api.gui.widgets.ClickButtonWidget; +import gregtech.api.gui.widgets.CycleButtonWidget; +import gregtech.api.gui.widgets.TextFieldWidget; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.MetaTileEntityHolder; +import gregtech.api.render.Textures; +import gregtech.api.util.GTUtility; +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.tileentity.TileEntity; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; +import net.minecraftforge.common.capabilities.Capability; +import org.apache.commons.lang3.ArrayUtils; + +import javax.annotation.Nullable; +import java.util.List; + +public class MetaTileEntityCreativeEnergy extends MetaTileEntity implements IEnergyContainer { + + private long voltage = 0; + private int amps = 1; + + private int setTier = 0; + private boolean active = false; + + private final List ALLOWED_CHARS = Lists.newArrayList('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'); + + public MetaTileEntityCreativeEnergy() { + super(new ResourceLocation(GTValues.MODID, "infinite_energy")); + } + + @Override + public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) { + IVertexOperation[] renderPipeline = ArrayUtils.add(pipeline, new ColourMultiplier(GTUtility.convertRGBtoOpaqueRGBA_CL(getPaintingColorForRendering()))); + Textures.VOLTAGE_CASINGS[14].render(renderState, translation, renderPipeline, Cuboid6.full); + for (EnumFacing face : EnumFacing.VALUES) { + Textures.INFINITE_EMITTER_FACE.renderSided(face, renderState, translation, pipeline); + } + } + + @Override + public MetaTileEntity createMetaTileEntity(MetaTileEntityHolder holder) { + return new MetaTileEntityCreativeEnergy(); + } + + @Override + public T getCapability(Capability capability, EnumFacing side) { + if (capability == GregtechCapabilities.CAPABILITY_ENERGY_CONTAINER) + return GregtechCapabilities.CAPABILITY_ENERGY_CONTAINER.cast(this); + return super.getCapability(capability, side); + } + + @Override + public void addInformation(ItemStack stack, @Nullable World player, List tooltip, boolean advanced) { + tooltip.add(I18n.format("gregtech.machine.infinite_energy.tooltip")); + } + + @Override + protected ModularUI createUI(EntityPlayer entityPlayer) { + String[] V = {"NAN", "ULV", "LV", "MV", "HV", "EV", "IV", "LuV", "ZPM", "UV", "UHV", "UEV", "UIV", "UMV", "UXV", "MAX"}; + ModularUI.Builder builder = ModularUI.defaultBuilder() + .widget(new CycleButtonWidget(7, 7, 30, 20, V, () -> setTier, tier -> { + setTier = tier; + if (tier > 0) + voltage = GTValues.V[setTier - 1]; + else + voltage = 0; + })); + builder.label(7, 32, "Voltage"); + builder.widget(new TextFieldWidget(7, 44, 156, 20, true, () -> String.valueOf(voltage), value -> { + voltage = Integer.parseInt(value); + setTier = 0; + }).setValidator(value -> { + for (int i = 0; i < value.length(); i++) { + char c = value.charAt(i); + if (!ALLOWED_CHARS.contains(c)) + return false; + } + return true; + })); + builder.label(7, 74, "Amperage"); + builder.widget(new ClickButtonWidget(7, 87, 20, 20, "-", data -> amps = Math.max(0, amps+1))); + builder.widget(new TextFieldWidget(29, 87, 118, 20, true, () -> String.valueOf(amps), value -> { + amps = Integer.parseInt(value); + }).setValidator(value -> { + for (int i = 0; i < value.length(); i++) { + char c = value.charAt(i); + if (!ALLOWED_CHARS.contains(c)) + return false; + } + return true; + })); + builder.widget(new ClickButtonWidget(149, 87, 20, 20, "+", data -> amps++)); + + builder.widget(new CycleButtonWidget(7, 139, 162, 20, () -> active, value -> active = value, "Not active", "Active")); + + return builder.build(getHolder(), entityPlayer); + } + + @Override + public void update() { + super.update(); + if (!active || voltage <= 0 || amps <= 0) return; + int ampsUsed = 0; + for (EnumFacing facing : EnumFacing.values()) { + EnumFacing opposite = facing.getOpposite(); + TileEntity tile = getWorld().getTileEntity(getPos().offset(facing)); + if (tile != null) { + IEnergyContainer container = tile.getCapability(GregtechCapabilities.CAPABILITY_ENERGY_CONTAINER, opposite); + if (container == null || !container.inputsEnergy(opposite) || container.getEnergyCanBeInserted() == 0) + continue; + ampsUsed += container.acceptEnergyFromNetwork(opposite, voltage, amps - ampsUsed); + if (ampsUsed >= amps) + break; + } + } + } + + @Override + public NBTTagCompound writeToNBT(NBTTagCompound data) { + data.setLong("Voltage", voltage); + data.setInteger("Amps", amps); + data.setByte("Tier", (byte) setTier); + data.setBoolean("Active", active); + return super.writeToNBT(data); + } + + @Override + public void readFromNBT(NBTTagCompound data) { + voltage = data.getLong("Voltage"); + amps = data.getInteger("Amps"); + setTier = data.getByte("Tier"); + active = data.getBoolean("Active"); + super.readFromNBT(data); + } + + @Override + public long acceptEnergyFromNetwork(EnumFacing side, long voltage, long amperage) { + return 0; + } + + @Override + public boolean inputsEnergy(EnumFacing side) { + return false; + } + + @Override + public boolean outputsEnergy(EnumFacing side) { + return true; + } + + @Override + public long changeEnergy(long differenceAmount) { + return 0; + } + + @Override + public long getEnergyStored() { + return 69; + } + + @Override + public long getEnergyCapacity() { + return 420; + } + + @Override + public long getInputAmperage() { + return 0; + } + + @Override + public long getInputVoltage() { + return 0; + } + + @Override + public long getOutputVoltage() { + return voltage; + } + + @Override + public long getOutputAmperage() { + return amps; + } + +} diff --git a/src/main/java/gregtech/common/metatileentities/traits/TraitInfiniteEmitter.java b/src/main/java/gregtech/common/metatileentities/traits/TraitInfiniteEmitter.java deleted file mode 100644 index 7f1562f47f7..00000000000 --- a/src/main/java/gregtech/common/metatileentities/traits/TraitInfiniteEmitter.java +++ /dev/null @@ -1,141 +0,0 @@ -package gregtech.common.metatileentities.traits; - -import gregtech.api.GTValues; -import gregtech.api.capability.GregtechCapabilities; -import gregtech.api.capability.IEnergyContainer; -import gregtech.api.metatileentity.InfiniteEnergyTileEntityBase; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; -import net.minecraftforge.common.capabilities.Capability; - -import javax.annotation.Nullable; -import java.math.BigInteger; - - -public class TraitInfiniteEmitter extends TraitInfiniteEnergy implements IEnergyContainer { - private boolean isInfinite; - private int tier = GTValues.MAX; - private long voltage = GTValues.V[GTValues.MAX]; - - public TraitInfiniteEmitter(InfiniteEnergyTileEntityBase mte) { - super(mte); - } - - public boolean isInfinite() { - return isInfinite; - } - - public void setInfinite(boolean infinite) { - this.isInfinite = infinite; - } - - @Override - public void update() { - if (!metaTileEntity.getWorld().isRemote) { - if (isInfinite) for (EnumFacing facing : EnumFacing.VALUES) send(facing); - else if (energy.signum() == 1) for (EnumFacing facing : EnumFacing.VALUES) - if (send(facing) && energy.signum() != 1) break; - } - } - - - public int getTier() { - return tier; - } - - public void setTier(int tier) { - voltage = GTValues.V[this.tier = tier]; - } - - @Override - public String getName() { - return "infinite_gteu_emitter"; - } - - @Override - public int getNetworkID() { - return TraitNetworkIds.TRAIT_ID_ENERGY_CONTAINER; - } - - protected boolean send(EnumFacing facing) { - TileEntity te = metaTileEntity.getWorld().getTileEntity(this.metaTileEntity.getPos().offset(facing)); - if (te != null) { - IEnergyContainer s = te.getCapability(GregtechCapabilities.CAPABILITY_ENERGY_CONTAINER, facing.getOpposite()); - if (s != null && s.inputsEnergy(facing.getOpposite())) { - long stored = getEnergyStored(), voltage = Math.min(this.voltage, s.getInputVoltage()); - if (stored / voltage > 0) { - long accepted = s.acceptEnergyFromNetwork(facing.getOpposite(), voltage, Math.min(s.getInputAmperage(), stored / voltage)) * voltage; - if (accepted > 0) { - if (!isInfinite()) subtract(BigInteger.valueOf(accepted)); - return true; - } - } - } - } - return false; - } - - @Override - public long acceptEnergyFromNetwork(EnumFacing side, long voltage, long amperage) { - return 0; - } - - @Override - public boolean inputsEnergy(EnumFacing side) { - return false; - } - - @Override - public boolean outputsEnergy(EnumFacing side) { - return true; - } - - @Override - public long changeEnergy(long differenceAmount) { - add(BigInteger.valueOf(differenceAmount)); - return differenceAmount; - } - - @Override - public long getInputAmperage() { - return 64; - } - - @Override - public long getInputVoltage() { - return voltage; - } - - @Override - public long getEnergyStored() { - return isInfinite() || energy.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) >= 0 ? Long.MAX_VALUE : energy.longValueExact(); - } - - @Override - public long getEnergyCapacity() { - return getEnergyStored(); - } - - @Nullable - @Override - @SuppressWarnings("unchecked") - public T getCapability(Capability capability) { - return capability == GregtechCapabilities.CAPABILITY_ENERGY_CONTAINER ? (T) this : null; - } - - @Override - public NBTTagCompound serializeNBT() { - NBTTagCompound nbt = super.serializeNBT(); - if (isInfinite) nbt.setBoolean("infinite", true); - nbt.setByte("tier", (byte) tier); - return nbt; - } - - @Override - public void deserializeNBT(NBTTagCompound nbt) { - super.deserializeNBT(nbt); - setInfinite(nbt.getBoolean("infinite")); - setTier(nbt.getByte("tier")); - } -} diff --git a/src/main/java/gregtech/common/metatileentities/traits/TraitInfiniteEnergy.java b/src/main/java/gregtech/common/metatileentities/traits/TraitInfiniteEnergy.java deleted file mode 100644 index fd924599064..00000000000 --- a/src/main/java/gregtech/common/metatileentities/traits/TraitInfiniteEnergy.java +++ /dev/null @@ -1,57 +0,0 @@ -package gregtech.common.metatileentities.traits; - -import gregtech.api.metatileentity.InfiniteEnergyTileEntityBase; -import gregtech.api.metatileentity.MTETrait; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.Constants.NBT; - -import java.math.BigInteger; - -public abstract class TraitInfiniteEnergy extends MTETrait { - protected final InfiniteEnergyTileEntityBase mte; - protected BigInteger energy = BigInteger.ZERO; - - public TraitInfiniteEnergy(InfiniteEnergyTileEntityBase mte) { - super(mte); - this.mte = mte; - } - - public BigInteger getEnergy() { - return energy; - } - - public void setEnergy(BigInteger bigInteger) { - energy = bigInteger.signum() == 1 ? bigInteger : BigInteger.ZERO; - } - - protected void add(BigInteger bInt) { - switch (bInt.signum()) { - case 1: - energy = energy.add(bInt); - break; - case -1: - subtract(bInt.negate()); - } - } - - protected void subtract(BigInteger bInt) { - if (energy.compareTo(bInt) > 0) { - energy = energy.subtract(bInt); - } else energy = BigInteger.ZERO; - } - - @Override - public NBTTagCompound serializeNBT() { - NBTTagCompound nbt = new NBTTagCompound(); - if (energy.signum() > 0) nbt.setByteArray("energy", energy.toByteArray()); - return nbt; - } - - @Override - public void deserializeNBT(NBTTagCompound nbt) { - if (nbt.hasKey("energy", NBT.TAG_BYTE_ARRAY)) { - byte[] bArr = nbt.getByteArray("energy"); - energy = bArr.length > 0 ? new BigInteger(bArr) : BigInteger.ZERO; - } else energy = BigInteger.ZERO; - } -} diff --git a/src/main/resources/assets/gregtech/lang/en_us.lang b/src/main/resources/assets/gregtech/lang/en_us.lang index d035762d9d7..c834e660196 100644 --- a/src/main/resources/assets/gregtech/lang/en_us.lang +++ b/src/main/resources/assets/gregtech/lang/en_us.lang @@ -2888,8 +2888,8 @@ gregtech.machine.scanner.uiv.name=High-Tech Scanner III gregtech.machine.scanner.umv.name=High-Tech Scanner IV gregtech.machine.scanner.uxv.name=Ultimate Scanner -gregtech.machine.infinite_emitter.name=Infinite GT Energy Unit Emitter -gregtech.machine.infinite_emitter.tooltip=§fYou just need §5C§dr§4e§ca§et§ai§bv§3e §7m§1o§5d§de§f to use this +gregtech.machine.infinite_energy.name=Infinite GT Energy Unit Emitter +gregtech.machine.infinite_energy.tooltip=§8You just need §o§5C§dr§4e§ca§et§ai§bv§3e §7m§1o§5d§de§r§8 to use this # Machine hulls gregtech.machine.hull.tooltip=§fYou just need §5I§dm§4a§cg§ei§an§ba§3t§7i§1o§5n§f to use this