Skip to content

Commit

Permalink
Merge pull request #346 from MCTian-mi/extenders-and-bridges
Browse files Browse the repository at this point in the history
Port over gt6 bridge/extenders
  • Loading branch information
bruberu authored Dec 15, 2024
2 parents d9de827 + 08b7ba8 commit 1d830e6
Show file tree
Hide file tree
Showing 39 changed files with 572 additions and 22 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package supersymmetry.api.metatileentity.logistics;

import net.minecraft.util.EnumFacing;
import org.jetbrains.annotations.Nullable;

// Mostly a marker interface
public interface IDelegator {

/**
* @return the facing that the input facing in delegating
*/
@Nullable
EnumFacing getDelegatingFacing(EnumFacing facing);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
package supersymmetry.api.metatileentity.logistics;

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 gregtech.api.capability.GregtechCapabilities;
import gregtech.api.capability.IEnergyContainer;
import gregtech.api.gui.ModularUI;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.MetaTileEntityHolder;
import gregtech.api.util.GTUtility;
import gregtech.client.renderer.texture.Textures;
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
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.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.ItemStackHandler;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.function.Predicate;


public abstract class MetaTileEntityDelegator extends MetaTileEntity implements IDelegator {

protected final Predicate<Capability<?>> capFilter;
protected final int baseColor;

public MetaTileEntityDelegator(ResourceLocation metaTileEntityId, Predicate<Capability<?>> capFilter, int baseColor) {
super(metaTileEntityId);
this.capFilter = capFilter;
this.baseColor = baseColor;
}

@Override
public <T> T getCapability(Capability<T> capability, EnumFacing side) {
T delegatedCapability = getDelegatedCapability(capability, side);
return delegatedCapability == null ? getDefaultCapability(capability, side) : delegatedCapability;
}

protected <T> T getDefaultCapability(Capability<T> capability, EnumFacing side) {
return side != null && capFilter.test(capability) && DefaultCapabilities.hasCapability(capability) ? DefaultCapabilities.getCapability(capability) : super.getCapability(capability, side);
}

protected <T> T getDelegatedCapability(Capability<T> capability, EnumFacing side) {
if (capability == null || !capFilter.test(capability) || side == null) return null;
EnumFacing delegatingFacing = getDelegatingFacing(side);
if (delegatingFacing == null) return null;
TileEntity te = getWorld().getTileEntity(getPos().offset(delegatingFacing));
if (te == null || (te instanceof MetaTileEntityHolder holder && holder.getMetaTileEntity() instanceof IDelegator))
return null;
// TODO: make IDelegator a capability when Jet Wingsuit PR gets merged
return te.getCapability(capability, delegatingFacing.getOpposite());
}

@Override
public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) {
IVertexOperation[] colouredPipeline = ArrayUtils.add(pipeline,
new ColourMultiplier(GTUtility.convertRGBtoOpaqueRGBA_CL(this.getPaintingColorForRendering())));
for (EnumFacing facing : EnumFacing.values()) {
Textures.renderFace(renderState, translation, colouredPipeline, facing, Cuboid6.full, this.getBaseTexture(), BlockRenderLayer.CUTOUT_MIPPED);
}
}

@SideOnly(Side.CLIENT)
protected TextureAtlasSprite getBaseTexture() {
return Textures.PIPE_SIDE;
}

@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, @Nullable World world, @NotNull List<String> tooltip, boolean advanced) {
super.addInformation(stack, world, tooltip, advanced);
tooltip.add(I18n.format("gregtech.machine.delegator.tooltip.non_recursion"));
}

@SideOnly(Side.CLIENT)
public Pair<TextureAtlasSprite, Integer> getParticleTexture() {
return Pair.of(getBaseTexture(), getPaintingColorForRendering());
}

@Override
public int getDefaultPaintingColor() {
return this.baseColor;
}

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

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

public static class DefaultCapabilities {

private static final Object2ObjectArrayMap<Capability<?>, ?> DEFAULT_CAPABILITIES = new Object2ObjectArrayMap<>();

static {
// Item
addCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(new ItemStackHandler(1) {

@NotNull
@Override
public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) {
return stack;
}

@NotNull
@Override
public ItemStack extractItem(int slot, int amount, boolean simulate) {
return ItemStack.EMPTY;
}
}));

// Fluid
addCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(new FluidTank(10000) {

@Override
public int fill(FluidStack resource, boolean doFill) {
return 0;
}

@Override
@Nullable
public FluidStack drainInternal(int maxDrain, boolean doDrain) {
return null;
}
}));

// GTEU
addCapability(GregtechCapabilities.CAPABILITY_ENERGY_CONTAINER, GregtechCapabilities.CAPABILITY_ENERGY_CONTAINER.cast(IEnergyContainer.DEFAULT));
}

public static boolean hasCapability(@NotNull Capability<?> capability) {
return DEFAULT_CAPABILITIES.containsKey(capability);
}

@Nullable
@SuppressWarnings("unchecked")
public static <T> T getCapability(@NotNull Capability<T> capability) {
return (T) DEFAULT_CAPABILITIES.getOrDefault(capability, null);
}

public static <T> void addCapability(@NotNull Capability<T> capability, @NotNull T value) {
DEFAULT_CAPABILITIES.put(capability, capability.cast(value));
}
}
}
2 changes: 0 additions & 2 deletions src/main/java/supersymmetry/client/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import net.minecraftforge.fml.relauncher.SideOnly;
import org.jetbrains.annotations.NotNull;
import supersymmetry.Supersymmetry;
import supersymmetry.api.integration.theoneprobe.TheOneProbeCompatibility;
import supersymmetry.api.recipes.catalysts.CatalystGroup;
import supersymmetry.api.recipes.catalysts.CatalystInfo;
import supersymmetry.common.CommonProxy;
Expand Down Expand Up @@ -49,7 +48,6 @@ public void load() {
super.load();
SuSyMetaBlocks.registerColors();
SuSyFluidTooltipLoader.registerTooltips();
TheOneProbeCompatibility.registerCompatibility();
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import gregtech.client.renderer.texture.cube.SimpleCubeRenderer;
import gregtech.client.renderer.texture.cube.SimpleOverlayRenderer;
import gregtech.client.renderer.texture.cube.SimpleSidedCubeRenderer;
import supersymmetry.client.renderer.textures.custom.ExtenderRender;
import gregtech.client.renderer.texture.custom.DrumRenderer;

public class SusyTextures {
Expand All @@ -13,6 +14,15 @@ public SusyTextures(){

public static final SimpleSidedCubeRenderer WOODEN_COAGULATION_TANK_WALL = new SimpleSidedCubeRenderer("casings/wooden_coagulation_tank_wall");
public static final SimpleSidedCubeRenderer PLASTIC_CAN_OVERLAY = new SimpleSidedCubeRenderer("storage/drums/plastic_can_top");
public static final SimpleSidedCubeRenderer INV_BRIDGE = new SimpleSidedCubeRenderer("logistics/bridges/inv");
public static final SimpleSidedCubeRenderer TANK_BRIDGE = new SimpleSidedCubeRenderer("logistics/bridges/tank");
public static final SimpleSidedCubeRenderer INV_TANK_BRIDGE = new SimpleSidedCubeRenderer("logistics/bridges/inv_tank");
public static final SimpleSidedCubeRenderer UNIVERSAL_BRIDGE = new SimpleSidedCubeRenderer("logistics/bridges/universal");

public static final ExtenderRender INV_EXTENDER = new ExtenderRender("logistics/extenders/inv");
public static final ExtenderRender TANK_EXTENDER = new ExtenderRender("logistics/extenders/tank");
public static final ExtenderRender INV_TANK_EXTENDER = new ExtenderRender("logistics/extenders/inv_tank");
public static final ExtenderRender UNIVERSAL_EXTENDER = new ExtenderRender("logistics/extenders/universal");

public static final OrientedOverlayRenderer VULCANIZING_PRESS_OVERLAY = new OrientedOverlayRenderer("machines/vulcanizing_press");
public static final OrientedOverlayRenderer LATEX_COLLECTOR_OVERLAY = new OrientedOverlayRenderer("machines/latex_collector");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package supersymmetry.client.renderer.textures.custom;

import codechicken.lib.render.CCRenderState;
import codechicken.lib.render.pipeline.IVertexOperation;
import codechicken.lib.texture.TextureUtils.IIconRegister;
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Matrix4;
import gregtech.api.GTValues;
import gregtech.client.renderer.texture.Textures;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class ExtenderRender implements IIconRegister {

private final String basePath;

@SideOnly(Side.CLIENT)
private TextureAtlasSprite[] textures;

public ExtenderRender(String basePath) {
this.basePath = basePath;
Textures.iconRegisters.add(this);
}

@Override
@SideOnly(Side.CLIENT)
public void registerIcons(TextureMap textureMap) {
String formattedBase = GTValues.MODID + ":blocks/" + basePath;
this.textures = new TextureAtlasSprite[3];
this.textures[0] = textureMap.registerSprite(new ResourceLocation(formattedBase + "/in"));
this.textures[1] = textureMap.registerSprite(new ResourceLocation(formattedBase + "/side"));
this.textures[2] = textureMap.registerSprite(new ResourceLocation(formattedBase + "/out"));
}

@SideOnly(Side.CLIENT)
public void render(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline,
EnumFacing outFace, EnumFacing inFace) {
for (EnumFacing renderSide : EnumFacing.VALUES) {
TextureAtlasSprite baseSprite = renderSide == inFace ? textures[0] :
renderSide == outFace ? textures[2] : textures[1];
Textures.renderFace(renderState, translation, pipeline, renderSide, Cuboid6.full, baseSprite,
BlockRenderLayer.CUTOUT_MIPPED);
}
}

@SideOnly(Side.CLIENT)
public TextureAtlasSprite getParticleTexture() {
return textures[0];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import gregtech.common.metatileentities.multi.multiblockpart.MetaTileEntityMultiFluidHatch;
import gregtech.common.metatileentities.storage.MetaTileEntityDrum;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.items.CapabilityItemHandler;
import org.jetbrains.annotations.NotNull;
import supersymmetry.api.SusyLog;
import supersymmetry.api.metatileentity.CatalystMachineMetaTileEntity;
Expand All @@ -27,6 +29,8 @@
import supersymmetry.api.recipes.SuSyRecipeMaps;
import supersymmetry.api.util.SuSyUtility;
import supersymmetry.client.renderer.textures.SusyTextures;
import supersymmetry.common.metatileentities.logistics.MetaTileEntityBridge;
import supersymmetry.common.metatileentities.logistics.MetaTileEntityExtender;
import supersymmetry.common.metatileentities.multi.electric.*;
import supersymmetry.common.metatileentities.multi.primitive.MetaTileEntityCoagulationTank;
import supersymmetry.common.metatileentities.multi.primitive.MetaTileEntityPrimitiveMudPump;
Expand All @@ -41,6 +45,7 @@
import supersymmetry.common.metatileentities.single.steam.SuSySimpleSteamMetaTileEntity;
import supersymmetry.common.metatileentities.storage.MetaTileEntityPlasticCan;

import java.util.ArrayList;
import java.util.function.Function;

import static gregtech.api.util.GTUtility.gregtechId;
Expand Down Expand Up @@ -164,6 +169,16 @@ public class SuSyMetaTileEntities {

public static MetaTileEntitySieveDistillationTower SIEVE_DISTILLATION_TOWER;

public static MetaTileEntityBridge INV_BRIDGE;
public static MetaTileEntityBridge TANK_BRIDGE;
public static MetaTileEntityBridge INV_TANK_BRIDGE;
public static MetaTileEntityBridge UNIVERSAL_BRIDGE;

public static MetaTileEntityExtender INV_EXTENDER;
public static MetaTileEntityExtender TANK_EXTENDER;
public static MetaTileEntityExtender INV_TANK_EXTENDER;
public static MetaTileEntityExtender UNIVERSAL_EXTENDER;

public static final MetaTileEntityMultiFluidHatch[] SUSY_QUADRUPLE_IMPORT_HATCH = new MetaTileEntityMultiFluidHatch[3]; // LV-HV
public static final MetaTileEntityMultiFluidHatch[] SUSY_NONUPLE_IMPORT_HATCH = new MetaTileEntityMultiFluidHatch[3]; // LV-HV
public static final MetaTileEntityMultiFluidHatch[] SUSY_QUADRUPLE_EXPORT_HATCH = new MetaTileEntityMultiFluidHatch[3]; // LV-HV
Expand Down Expand Up @@ -221,6 +236,16 @@ public static void init() {
ELECTROLYTIC_CELL = registerMetaTileEntity(14634, new MetaTileEntityElectrolyticCell(susyId("electrolytic_cell")));
GRAVITY_SEPARATOR = registerMetaTileEntity(15052, new MetaTileEntityGravitySeparator(susyId("gravity_separator")));

INV_BRIDGE = registerMetaTileEntity(14733, new MetaTileEntityBridge(susyId("bridge.inv"), cap -> cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, SusyTextures.INV_BRIDGE, Materials.Steel));
TANK_BRIDGE = registerMetaTileEntity(14734, new MetaTileEntityBridge(susyId("bridge.tank"), cap -> cap == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, SusyTextures.TANK_BRIDGE, Materials.Steel));
INV_TANK_BRIDGE = registerMetaTileEntity(14735, new MetaTileEntityBridge(susyId("bridge.inv_tank"), cap -> cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || cap == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, SusyTextures.INV_TANK_BRIDGE, Materials.Steel));
UNIVERSAL_BRIDGE = registerMetaTileEntity(14736, new MetaTileEntityBridge(susyId("bridge.universal"), cap -> true, SusyTextures.UNIVERSAL_BRIDGE, Materials.Aluminium));

INV_EXTENDER = registerMetaTileEntity(14737, new MetaTileEntityExtender(susyId("extender.inv"), cap -> cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, SusyTextures.INV_EXTENDER, Materials.Steel));
TANK_EXTENDER = registerMetaTileEntity(14738, new MetaTileEntityExtender(susyId("extender.tank"), cap -> cap == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, SusyTextures.TANK_EXTENDER, Materials.Steel));
INV_TANK_EXTENDER = registerMetaTileEntity(14739, new MetaTileEntityExtender(susyId("extender.inv_tank"), cap -> cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || cap == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, SusyTextures.INV_TANK_EXTENDER, Materials.Steel));
UNIVERSAL_EXTENDER = registerMetaTileEntity(14740, new MetaTileEntityExtender(susyId("extender.universal"), cap -> true, SusyTextures.UNIVERSAL_EXTENDER, Materials.Aluminium));

PRIMITIVE_SMELTER = registerMetaTileEntity(14800, new MetaTileEntityPrimitiveSmelter(susyId("primitive_smelter")));
PRIMITIVE_ITEM_IMPORT = registerMetaTileEntity(14801, new MetaTileEntityPrimitiveItemBus(susyId("primitive_item_import"), false));
PRIMITIVE_ITEM_EXPORT = registerMetaTileEntity(14802, new MetaTileEntityPrimitiveItemBus(susyId("primitive_item_export"), true));
Expand All @@ -237,9 +262,11 @@ public static void init() {
registerSimpleMTE(CVD, 12, 14653, "cvd", SuSyRecipeMaps.CVD_RECIPES, SusyTextures.CVD_OVERLAY, true, GTUtility.defaultTankSizeFunction);
registerSimpleMTE(ION_IMPLANTER, 12, 14666, "ion_implanter", SuSyRecipeMaps.ION_IMPLANTATION_RECIPES, SusyTextures.ION_IMPLANTER_OVERLAY, true, GTUtility.defaultTankSizeFunction);

int id = 14500;
while (GregTechAPI.MTE_REGISTRY.getObjectById(id) != null) id++;
SusyLog.logger.debug("The next available ID is: " + id);
ArrayList<Integer> ids = new ArrayList<>();
for (int id = 14500; id < 15000; id++) {
if (GregTechAPI.MTE_REGISTRY.getObjectById(id) == null) ids.add(id);
}
SusyLog.logger.debug("Available ID(s) are: {}", ids);

//thermodynamic stuff
registerSimpleMTE(FLUID_COMPRESSOR, 12, 15000, "fluid_compressor", SuSyRecipeMaps.FLUID_COMPRESSOR_RECIPES, SusyTextures.FLUID_COMPRESSOR_OVERLAY, true, GTUtility.defaultTankSizeFunction);
Expand Down
Loading

0 comments on commit 1d830e6

Please sign in to comment.