Skip to content

Commit

Permalink
port the Buffer to CEu
Browse files Browse the repository at this point in the history
  • Loading branch information
serenibyss committed Aug 15, 2021
1 parent fa1b388 commit dc81fa8
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/main/java/gregtech/api/render/Textures.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public class Textures {
public static final SimpleOverlayRenderer STEAM_VENT_OVERLAY = new SimpleOverlayRenderer("overlay/machine/steam_vent");
public static final SimpleOverlayRenderer QUANTUM_TANK_OVERLAY = new SimpleOverlayRenderer("overlay/machine/overlay_qtank");
public static final SimpleOverlayRenderer QUANTUM_CHEST_OVERLAY = new SimpleOverlayRenderer("overlay/machine/overlay_qchest");
public static final SimpleOverlayRenderer BUFFER_OVERLAY = new SimpleOverlayRenderer("overlay/machine/overlay_buffer");

static {
for (int i = 0; i < VOLTAGE_CASINGS.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public class MetaTileEntities {

public static final MetaTileEntityQuantumChest[] QUANTUM_CHEST = new MetaTileEntityQuantumChest[10];
public static final MetaTileEntityQuantumTank[] QUANTUM_TANK = new MetaTileEntityQuantumTank[10];
public static final MetaTileEntityBuffer[] BUFFER = new MetaTileEntityBuffer[3];

//MISC MACHINES SECTION
public static MetaTileEntityWorkbench WORKBENCH;
Expand Down Expand Up @@ -534,7 +535,11 @@ public static void init() {
GregTechAPI.registerMetaTileEntity(1480 + ENERGY_INPUT_HATCH.length - 1, ENERGY_INPUT_HATCH[ENERGY_INPUT_HATCH.length - 1]);
GregTechAPI.registerMetaTileEntity(1495 + ENERGY_OUTPUT_HATCH_ADJUSTABLE.length - 1, ENERGY_OUTPUT_HATCH_ADJUSTABLE[ENERGY_OUTPUT_HATCH_ADJUSTABLE.length - 1]);

// Free Range: 1510-1514
BUFFER[0] = GregTechAPI.registerMetaTileEntity(1510, new MetaTileEntityBuffer(gregtechId("buffer.lv"), 1));
BUFFER[1] = GregTechAPI.registerMetaTileEntity(1511, new MetaTileEntityBuffer(gregtechId("buffer.mv"), 2));
BUFFER[2] = GregTechAPI.registerMetaTileEntity(1512, new MetaTileEntityBuffer(gregtechId("buffer.hv"), 3));

// Free Range: 1513-1514

// Fishers, IDs 1515-1529
FISHER[0] = GregTechAPI.registerMetaTileEntity(1515, new MetaTileEntityFisher(gregtechId("fisher.lv"), 1));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
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.Matrix4;
import gregtech.api.capability.impl.FilteredFluidHandler;
import gregtech.api.capability.impl.FluidTankList;
import gregtech.api.gui.GuiTextures;
import gregtech.api.gui.ModularUI;
import gregtech.api.gui.widgets.TankWidget;
import gregtech.api.metatileentity.ITieredMetaTileEntity;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.MetaTileEntityHolder;
import gregtech.api.render.Textures;
import gregtech.api.util.GTUtility;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
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.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.items.ItemStackHandler;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.tuple.Pair;

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

public class MetaTileEntityBuffer extends MetaTileEntity implements ITieredMetaTileEntity {

private final int tier;

private FluidTankList fluidTankList;
private ItemStackHandler itemStackHandler;

public MetaTileEntityBuffer(ResourceLocation metaTileEntityId, int tier) {
super(metaTileEntityId);
this.tier = tier;
initializeInventory();
}

@Override
protected void initializeInventory() {
super.initializeInventory();
FilteredFluidHandler[] fluidHandlers = new FilteredFluidHandler[tier + 2];
for (int i = 0; i < tier + 2; i++) {
fluidHandlers[i] = new FilteredFluidHandler(64000);
}
fluidInventory = fluidTankList = new FluidTankList(false, fluidHandlers);
itemInventory = itemStackHandler = new ItemStackHandler((int)Math.pow(tier + 2, 2));
}

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

@Override
public Pair<TextureAtlasSprite, Integer> getParticleTexture() {
return Pair.of(Textures.VOLTAGE_CASINGS[tier].getParticleSprite(), this.getPaintingColor());
}

@Override
protected ModularUI createUI(EntityPlayer entityPlayer) {
int invTier = tier + 2;
ModularUI.Builder builder = ModularUI.builder(GuiTextures.BACKGROUND,
176, Math.max(166, 18 + 18 * invTier + 94));//176, 166
for (int i = 0; i < this.fluidTankList.getTanks(); i++) {
builder.widget(new TankWidget(this.fluidTankList.getTankAt(i), 176 - 8 - 18, 18 + 18 * i, 18, 18)
.setAlwaysShowFull(true)
.setBackgroundTexture(GuiTextures.FLUID_SLOT)
.setContainerClicking(true, true));
}
for (int y = 0; y < invTier; y++) {
for (int x = 0; x < invTier; x++) {
int index = y * invTier + x;
builder.slot(itemStackHandler, index, 8 + x * 18, 18 + y * 18, GuiTextures.SLOT);
}
}
return builder.label(6, 6, getMetaFullName())
.bindPlayerInventory(entityPlayer.inventory, GuiTextures.SLOT, 8, 18 + 18 * invTier + 12)
.build(getHolder(), entityPlayer);
}

@Override
public int getTier() {
return tier;
}

@Override
public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) {
Textures.VOLTAGE_CASINGS[tier].render(renderState, translation, ArrayUtils.add(pipeline,
new ColourMultiplier(GTUtility.convertRGBtoOpaqueRGBA_CL(getPaintingColorForRendering()))));
for (EnumFacing facing : EnumFacing.VALUES) {
Textures.BUFFER_OVERLAY.renderSided(facing, renderState, translation, pipeline);
}
}

@Override
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);
tag.setTag("Inventory", itemStackHandler.serializeNBT());
tag.setTag("FluidInventory", fluidTankList.serializeNBT());
return tag;
}

@Override
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);
this.itemStackHandler.deserializeNBT(tag.getCompoundTag("Inventory"));
this.fluidTankList.deserializeNBT(tag.getCompoundTag("FluidInventory"));
}

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

@Override
public boolean hasFrontFacing() {
return false;
}

@Override
public void addInformation(ItemStack stack, @Nullable World player, List<String> tooltip, boolean advanced) {
super.addInformation(stack, player, tooltip, advanced);
tooltip.add(I18n.format("gregtech.machine.buffer.tooltip"));
tooltip.add(I18n.format("gregtech.machine.buffer.inventory", (int)Math.pow(tier + 2, 2)));
tooltip.add(I18n.format("gregtech.machine.buffer.tanks", tier + 2));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,10 @@ public static void init() {
ModHandler.addShapedRecipe("hermetic_casing_zpm", MetaBlocks.HERMETIC_CASING.getItemVariant(HERMETIC_ZPM), "PPP", "PFP", "PPP", 'P', new UnificationEntry(OrePrefix.plate, Materials.Iridium), 'F', new UnificationEntry(OrePrefix.pipeLargeFluid, Materials.NiobiumTitanium));
ModHandler.addShapedRecipe("hermetic_casing_uv", MetaBlocks.HERMETIC_CASING.getItemVariant(HERMETIC_UV), "PPP", "PFP", "PPP", 'P', new UnificationEntry(OrePrefix.plate, Materials.Osmium), 'F', new UnificationEntry(OrePrefix.pipeLargeFluid, Materials.Naquadah));
ModHandler.addShapedRecipe("hermetic_casing_max", MetaBlocks.HERMETIC_CASING.getItemVariant(HERMETIC_MAX), "PPP", "PFP", "PPP", 'P', new UnificationEntry(OrePrefix.plate, Materials.Neutronium), 'F', new UnificationEntry(OrePrefix.pipeLargeFluid, Materials.Ultimet));

ModHandler.addShapedRecipe("buffer_lv", MetaTileEntities.BUFFER[0].getStackForm(), "HP", "CV", 'H', MetaTileEntities.HULL[GTValues.LV].getStackForm(), 'P', MetaItems.ELECTRIC_PUMP_LV.getStackForm(), 'V', MetaItems.CONVEYOR_MODULE_LV.getStackForm(), 'C', new UnificationEntry(OrePrefix.circuit, MarkerMaterials.Tier.Basic));
ModHandler.addShapedRecipe("buffer_mv", MetaTileEntities.BUFFER[1].getStackForm(), "HP", "CV", 'H', MetaTileEntities.HULL[GTValues.MV].getStackForm(), 'P', MetaItems.ELECTRIC_PUMP_MV.getStackForm(), 'V', MetaItems.CONVEYOR_MODULE_MV.getStackForm(), 'C', new UnificationEntry(OrePrefix.circuit, MarkerMaterials.Tier.Basic));
ModHandler.addShapedRecipe("buffer_hv", MetaTileEntities.BUFFER[2].getStackForm(), "HP", "CV", 'H', MetaTileEntities.HULL[GTValues.HV].getStackForm(), 'P', MetaItems.ELECTRIC_PUMP_HV.getStackForm(), 'V', MetaItems.CONVEYOR_MODULE_HV.getStackForm(), 'C', new UnificationEntry(OrePrefix.circuit, MarkerMaterials.Tier.Basic));
}

public static <T extends MetaTileEntity & ITieredMetaTileEntity> void registerMachineRecipe(T[] metaTileEntities, Object... recipe) {
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/assets/gregtech/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -3119,6 +3119,14 @@ gregtech.machine.quantum_tank.zpm.name=Quantum Tank III
gregtech.machine.quantum_tank.uv.name=Quantum Tank IV
gregtech.machine.quantum_tank.uhv.name=Quantum Tank V

#Buffers
gregtech.machine.buffer.tooltip=A Small Buffer to store Items and Fluids
gregtech.machine.buffer.inventory=Item Capacity: %d Slots
gregtech.machine.buffer.tanks=Fluid Capacity: %d Tanks at 64,000L each
gregtech.machine.buffer.lv.name=Basic Buffer
gregtech.machine.buffer.mv.name=Advanced Buffer
gregtech.machine.buffer.hv.name=Advanced Buffer II

#Hermetic Casing
tile.hermetic_casing.hermetic_casing_lv.name=Hermetic Casing I
tile.hermetic_casing.hermetic_casing_mv.name=Hermetic Casing II
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit dc81fa8

Please sign in to comment.