-
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.
- Loading branch information
Showing
61 changed files
with
2,220 additions
and
25 deletions.
There are no files selected for viewing
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
14 changes: 14 additions & 0 deletions
14
src/main/java/supersymmetry/api/capability/IElytraFlyingProvider.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.capability; | ||
|
||
import net.minecraft.entity.EntityLivingBase; | ||
import net.minecraft.item.ItemStack; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* Logic from EnderIO: | ||
* <a href="https://github.com/EnderIOu/EnderCore/blob/72a28bf5bc7dc8c7df067f43a7222b25ba594e32/src/main/java/com/enderio/core/common/transform/EnderCoreMethods.java#L200">...</a> | ||
*/ | ||
public interface IElytraFlyingProvider { | ||
|
||
boolean isElytraFlying(@NotNull EntityLivingBase entity, @NotNull ItemStack itemstack, boolean shouldStop); | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/supersymmetry/api/capability/SuSyCapabilities.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,18 @@ | ||
package supersymmetry.api.capability; | ||
|
||
import gregtech.api.capability.SimpleCapabilityManager; | ||
import net.minecraftforge.common.capabilities.Capability; | ||
import net.minecraftforge.common.capabilities.CapabilityInject; | ||
import net.minecraftforge.fml.common.Mod; | ||
import supersymmetry.Supersymmetry; | ||
|
||
@Mod.EventBusSubscriber(modid = Supersymmetry.MODID) | ||
public class SuSyCapabilities { | ||
|
||
@CapabilityInject(IElytraFlyingProvider.class) | ||
public static Capability<IElytraFlyingProvider> ELYTRA_FLYING_PROVIDER; | ||
|
||
public static void init() { | ||
SimpleCapabilityManager.registerCapabilityWithNoDefault(IElytraFlyingProvider.class); | ||
} | ||
} |
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
69 changes: 69 additions & 0 deletions
69
src/main/java/supersymmetry/api/util/ElytraFlyingUtils.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,69 @@ | ||
package supersymmetry.api.util; | ||
|
||
import net.minecraft.block.material.Material; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.EntityLivingBase; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.inventory.EntityEquipmentSlot; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.math.AxisAlignedBB; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.MathHelper; | ||
import net.minecraft.world.World; | ||
import org.jetbrains.annotations.NotNull; | ||
import supersymmetry.api.capability.SuSyCapabilities; | ||
|
||
public class ElytraFlyingUtils { | ||
|
||
@SuppressWarnings("DataFlowIssue") | ||
public static boolean isElytraFlying(@NotNull EntityLivingBase entity) { | ||
ItemStack itemstack = entity.getItemStackFromSlot(EntityEquipmentSlot.CHEST); | ||
if (itemstack.hasCapability(SuSyCapabilities.ELYTRA_FLYING_PROVIDER, null)) { | ||
return itemstack.getCapability(SuSyCapabilities.ELYTRA_FLYING_PROVIDER, null).isElytraFlying( | ||
entity, itemstack, | ||
entity.onGround || | ||
entity instanceof EntityPlayer && ((EntityPlayer) entity).capabilities.isFlying || | ||
entity.isRiding() || entity.isInWater() || isInLavaSafe(entity)); | ||
} | ||
return false; | ||
} | ||
|
||
public static boolean canTakeOff(EntityPlayer player, boolean ignoreOnGround) { | ||
return (ignoreOnGround || (!player.onGround && player.motionY < 0.0D)) && !player.isElytraFlying() && !player.isInWater() && !isInLavaSafe(player); | ||
} | ||
|
||
// non-chunkloading copy of Entity.isInLava() | ||
private static boolean isInLavaSafe(@NotNull Entity entity) { | ||
return isMaterialInBBSafe(entity.world, | ||
entity.getEntityBoundingBox().expand(-0.1, -0.4, -0.1), | ||
Material.LAVA); | ||
} | ||
|
||
// non-chunkloading copy of World.isMaterialInBB() | ||
private static boolean isMaterialInBBSafe(@NotNull World world, @NotNull AxisAlignedBB bb, | ||
@NotNull Material materialIn) { | ||
int i = MathHelper.floor(bb.minX); | ||
int j = MathHelper.ceil(bb.maxX); | ||
int k = MathHelper.floor(bb.minY); | ||
int l = MathHelper.ceil(bb.maxY); | ||
int i1 = MathHelper.floor(bb.minZ); | ||
int j1 = MathHelper.ceil(bb.maxZ); | ||
BlockPos.PooledMutableBlockPos pos = BlockPos.PooledMutableBlockPos.retain(); | ||
|
||
for (int k1 = i; k1 < j; ++k1) { | ||
for (int l1 = k; l1 < l; ++l1) { | ||
for (int i2 = i1; i2 < j1; ++i2) { | ||
pos.setPos(k1, l1, i2); | ||
if (world.isBlockLoaded(pos, false) && | ||
world.getBlockState(pos).getMaterial() == materialIn) { | ||
pos.release(); | ||
return true; | ||
} | ||
} | ||
} | ||
} | ||
|
||
pos.release(); | ||
return false; | ||
} | ||
} |
Oops, something went wrong.