Skip to content

Commit

Permalink
Merge branch 'main' into DTs
Browse files Browse the repository at this point in the history
  • Loading branch information
bruberu authored Dec 15, 2024
2 parents c2c9b5e + 1d830e6 commit d115db1
Show file tree
Hide file tree
Showing 61 changed files with 2,220 additions and 25 deletions.
10 changes: 10 additions & 0 deletions src/main/java/supersymmetry/Supersymmetry.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package supersymmetry;

import gregtech.GTInternalTags;
import net.minecraftforge.client.model.obj.OBJLoader;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLConstructionEvent;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.relauncher.FMLLaunchHandler;
import net.minecraftforge.fml.relauncher.Side;
import org.jetbrains.annotations.NotNull;
import supersymmetry.api.capability.SuSyCapabilities;
import supersymmetry.api.sound.SusySounds;
import supersymmetry.common.CommonProxy;
import supersymmetry.common.SusyMetaEntities;
Expand Down Expand Up @@ -54,7 +58,13 @@ public void onPreInit(@NotNull FMLPreInitializationEvent event) {
SusySounds.registerSounds();

SuSyMetaTileEntities.init();
SuSyCapabilities.init();

SusyMetaEntities.init();

if (FMLLaunchHandler.side() == Side.CLIENT) {
OBJLoader.INSTANCE.addDomain(MODID);
}
}

@Mod.EventHandler
Expand Down
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 src/main/java/supersymmetry/api/capability/SuSyCapabilities.java
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);
}
}

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));
}
}
}
9 changes: 8 additions & 1 deletion src/main/java/supersymmetry/api/recipes/SuSyRecipeMaps.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class SuSyRecipeMaps {
public static final RecipeMap<CatalystRecipeBuilder> ROASTER_RECIPES = new RecipeMap<>("roaster", 3, 2, 2, 3, new CatalystRecipeBuilder(), false)
.setSound(GTSoundEvents.COMBUSTION);

public static final RecipeMap<SimpleRecipeBuilder> VACUUM_CHAMBER = new RecipeMap<>("vacuum_chamber", 4, 1, 2, 2, new SimpleRecipeBuilder(), false)
public static final RecipeMap<SimpleRecipeBuilder> VACUUM_CHAMBER = new RecipeMap<>("vacuum_chamber", 4, 2, 2, 2, new SimpleRecipeBuilder(), false)
.setProgressBar(GuiTextures.PROGRESS_BAR_COMPRESS, ProgressWidget.MoveType.HORIZONTAL)
.setSound(GTSoundEvents.CENTRIFUGE);

Expand Down Expand Up @@ -331,6 +331,13 @@ public class SuSyRecipeMaps {
.setSlotOverlay(true, false, GuiTextures.FURNACE_OVERLAY_2)
.setSound(GTSoundEvents.FURNACE);


public static final RecipeMap<NoEnergyRecipeBuilder> JET_WINGPACK_FUELS = new RecipeMap<>("jet_wingpack_fuels", 0, 0, 1, 0, new NoEnergyRecipeBuilder(), false)
.setSlotOverlay(false, false, GuiTextures.DARK_CANISTER_OVERLAY)
.setProgressBar(GuiTextures.PROGRESS_BAR_GAS_COLLECTOR, ProgressWidget.MoveType.HORIZONTAL)
.setSound(GTSoundEvents.TURBINE)
.allowEmptyOutput();

public static void init(){
RecipeMaps.SIFTER_RECIPES.setMaxFluidInputs(1);
RecipeMaps.SIFTER_RECIPES.setMaxFluidOutputs(1);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/supersymmetry/api/sound/SusySounds.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ public class SusySounds {

public static SoundEvent ROCKET_LOOP;
public static SoundEvent DRONE_TAKEOFF;
public static SoundEvent JET_ENGINE_LOOP;

public static void registerSounds() {
ROCKET_LOOP = registerSound("entity.rocket_loop");
DRONE_TAKEOFF = registerSound("entity.drone_takeoff");
JET_ENGINE_LOOP = registerSound("item.jet_wingpack_engine_active");
}

private static SoundEvent registerSound(String soundNameIn) {
Expand Down
69 changes: 69 additions & 0 deletions src/main/java/supersymmetry/api/util/ElytraFlyingUtils.java
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;
}
}
Loading

0 comments on commit d115db1

Please sign in to comment.