-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #346 from MCTian-mi/extenders-and-bridges
Port over gt6 bridge/extenders
- Loading branch information
Showing
39 changed files
with
572 additions
and
22 deletions.
There are no files selected for viewing
13 changes: 0 additions & 13 deletions
13
src/main/java/supersymmetry/api/integration/theoneprobe/TheOneProbeCompatibility.java
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
src/main/java/supersymmetry/api/metatileentity/logistics/IDelegator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
169 changes: 169 additions & 0 deletions
169
src/main/java/supersymmetry/api/metatileentity/logistics/MetaTileEntityDelegator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/supersymmetry/client/renderer/textures/custom/ExtenderRender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.