Skip to content

Commit

Permalink
Merge branch 'GregTechCEu:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
marisathewitch authored Nov 24, 2024
2 parents 4563b00 + 7141fcf commit 15453f7
Show file tree
Hide file tree
Showing 16 changed files with 226 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package meldexun.nothirium.api.renderer.chunk;

/**
* Adapted and minimized from <a
* href="https://github.com/Meldexun/Nothirium/blob/main/src/main/java/meldexun/nothirium/api/renderer/chunk/ChunkRenderPass.java">ChunkRenderPass.java</a>
*/
public enum ChunkRenderPass {
;

public static final ChunkRenderPass[] ALL = ChunkRenderPass.values();

}
4 changes: 2 additions & 2 deletions src/main/java/gregtech/api/recipes/RecipeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -828,15 +828,15 @@ protected static void multiplyInputsAndOutputs(List<GTRecipeInput> newRecipeInpu
if (ri.isNonConsumable()) {
newRecipeInputs.add(ri);
} else {
newRecipeInputs.add(ri.withAmount(ri.getAmount() * numberOfOperations));
newRecipeInputs.add(ri.copyWithAmount(ri.getAmount() * numberOfOperations));
}
});

recipe.getFluidInputs().forEach(fi -> {
if (fi.isNonConsumable()) {
newFluidInputs.add(fi);
} else {
newFluidInputs.add(fi.withAmount(fi.getAmount() * numberOfOperations));
newFluidInputs.add(fi.copyWithAmount(fi.getAmount() * numberOfOperations));
}
});

Expand Down
36 changes: 34 additions & 2 deletions src/main/java/gregtech/api/unification/material/Material.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,22 @@
import gregtech.api.unification.material.info.MaterialFlag;
import gregtech.api.unification.material.info.MaterialFlags;
import gregtech.api.unification.material.info.MaterialIconSet;
import gregtech.api.unification.material.properties.*;
import gregtech.api.unification.material.properties.BlastProperty;
import gregtech.api.unification.material.properties.DustProperty;
import gregtech.api.unification.material.properties.FluidPipeProperties;
import gregtech.api.unification.material.properties.FluidProperty;
import gregtech.api.unification.material.properties.GemProperty;
import gregtech.api.unification.material.properties.IMaterialProperty;
import gregtech.api.unification.material.properties.IngotProperty;
import gregtech.api.unification.material.properties.ItemPipeProperties;
import gregtech.api.unification.material.properties.MaterialProperties;
import gregtech.api.unification.material.properties.OreProperty;
import gregtech.api.unification.material.properties.PolymerProperty;
import gregtech.api.unification.material.properties.PropertyKey;
import gregtech.api.unification.material.properties.RotorProperty;
import gregtech.api.unification.material.properties.ToolProperty;
import gregtech.api.unification.material.properties.WireProperties;
import gregtech.api.unification.material.properties.WoodProperty;
import gregtech.api.unification.material.registry.MaterialRegistry;
import gregtech.api.unification.stack.MaterialStack;
import gregtech.api.util.FluidTooltipUtil;
Expand All @@ -35,7 +50,11 @@
import stanhebben.zenscript.annotations.ZenMethod;
import stanhebben.zenscript.annotations.ZenOperator;

import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.UnaryOperator;

Expand Down Expand Up @@ -110,6 +129,14 @@ public Material setFormula(String formula, boolean withFormatting) {
return this;
}

@ZenMethod
public Material setComponents(MaterialStack... components) {
this.materialInfo.setComponents(components);
this.chemicalFormula = null;
this.chemicalFormula = calculateChemicalFormula();
return this;
}

public ImmutableList<MaterialStack> getMaterialComponents() {
return materialInfo.componentList;
}
Expand Down Expand Up @@ -1172,5 +1199,10 @@ private void verifyInfo(MaterialProperties p, boolean averageRGB) {
}
}
}

public MaterialInfo setComponents(MaterialStack... components) {
this.componentList = ImmutableList.copyOf(Arrays.asList(components));
return this;
}
}
}
3 changes: 2 additions & 1 deletion src/main/java/gregtech/api/util/OverlayedItemHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public int insertStackedItemStack(@NotNull ItemStack stack, int amountToInsert)
ItemStack slotKey = this.slots[i].getItemStack();
if (slotKey.isEmpty() || ItemStackHashStrategy.comparingAllButCount().equals(slotKey, stack)) {
// if the slot is not full
int canInsertUpTo = this.slots[i].getSlotLimit() - this.slots[i].getCount();
int canInsertUpTo = Math.min(this.slots[i].getSlotLimit() - this.slots[i].getCount(),
stack.getMaxStackSize());
if (canInsertUpTo > 0) {
int insertedAmount = Math.min(canInsertUpTo, amountToInsert);
this.slots[i].setItemStack(stack.copy()); // this copy may not be need, needs further tests
Expand Down
21 changes: 1 addition & 20 deletions src/main/java/gregtech/client/utils/BloomEffectUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,19 @@
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.shader.Framebuffer;
import net.minecraft.entity.Entity;
import net.minecraft.launchwrapper.Launch;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.world.World;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import com.github.bsideup.jabel.Desugar;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.opengl.GL11;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -336,24 +332,9 @@ public boolean test(BloomRenderTicket bloomRenderTicket) {
}, validityChecker);
}

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void init() {
bloom = EnumHelper.addEnum(BlockRenderLayer.class, "BLOOM", new Class[] { String.class }, "Bloom");
bloom = BlockRenderLayer.valueOf("BLOOM");
BLOOM = bloom;
if (Mods.Nothirium.isModLoaded()) {
try {
// Nothirium hard copies the BlockRenderLayer enum into a ChunkRenderPass enum. Add our BLOOM layer to
// that too.
Class crp = Class.forName("meldexun.nothirium.api.renderer.chunk.ChunkRenderPass", false,
Launch.classLoader);
EnumHelper.addEnum(crp, "BLOOM", new Class[] {});
Field all = FieldUtils.getField(crp, "ALL", false);
FieldUtils.removeFinalModifier(all);
FieldUtils.writeStaticField(all, crp.getEnumConstants());
} catch (ClassNotFoundException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}

// Calls injected via ASM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
@SideOnly(Side.CLIENT)
public class BloomEffectVintagiumUtil {

public static BlockRenderPass bloom;

/**
* @return {@link BlockRenderPass} instance for the bloom render layer.
*/
@NotNull
@SuppressWarnings("unused")
public static BlockRenderPass getBloomPass() {
return Objects.requireNonNull(bloom, "Bloom effect is not initialized yet");
return Objects.requireNonNull(BlockRenderPass.valueOf("BLOOM"), "Bloom effect is not initialized yet");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public abstract class MetaTileEntityAEHostablePart<T extends IAEStack<T>> extend
private int meUpdateTick;
protected boolean isOnline;
private boolean allowExtraConnections;
protected boolean meStatusChanged = false;

public MetaTileEntityAEHostablePart(ResourceLocation metaTileEntityId, int tier, boolean isExportHatch,
Class<? extends IStorageChannel<T>> storageChannel) {
Expand Down Expand Up @@ -158,6 +159,9 @@ public boolean updateMEStatus() {
if (this.isOnline != isOnline) {
writeCustomData(UPDATE_ONLINE_STATUS, buf -> buf.writeBoolean(isOnline));
this.isOnline = isOnline;
this.meStatusChanged = true;
} else {
this.meStatusChanged = false;
}
}
return this.isOnline;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,22 @@ protected ExportOnlyAEStockingItemList getAEItemHandler() {
@Override
public void update() {
super.update();
if (!getWorld().isRemote && isWorkingEnabled() && autoPull && getOffsetTimer() % 100 == 0) {
refreshList();
syncME();
if (!getWorld().isRemote) {
if (isWorkingEnabled() && autoPull && getOffsetTimer() % 100 == 0) {
refreshList();
syncME();
}

// Immediately clear cached items if the status changed, to prevent running recipes while offline
if (this.meStatusChanged && !this.isOnline) {
if (autoPull) {
clearInventory(0);
} else {
for (int i = 0; i < CONFIG_SIZE; i++) {
getAEItemHandler().getInventory()[i].setStack(null);
}
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,22 @@ protected ExportOnlyAEStockingFluidList getAEFluidHandler() {
@Override
public void update() {
super.update();
if (!getWorld().isRemote && isWorkingEnabled() && autoPull && getOffsetTimer() % 100 == 0) {
refreshList();
syncME();
if (!getWorld().isRemote) {
if (isWorkingEnabled() && autoPull && getOffsetTimer() % 100 == 0) {
refreshList();
syncME();
}

// Immediately clear cached fluids if the status changed, to prevent running recipes while offline
if (this.meStatusChanged && !this.isOnline) {
if (autoPull) {
this.getAEFluidHandler().clearConfig();
} else {
for (int i = 0; i < CONFIG_SIZE; i++) {
getAEFluidHandler().getInventory()[i].setStack(null);
}
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public List<String> getMixinConfigs() {
configs.add("mixins.gregtech.ccl.json");
configs.add("mixins.gregtech.littletiles.json");
configs.add("mixins.gregtech.vintagium.json");
configs.add("mixins.gregtech.nothirium.json");

return configs;
}
Expand All @@ -31,6 +32,7 @@ public boolean shouldMixinConfigQueue(String mixinConfig) {
case "mixin.gregtech.ctm.json" -> Mods.CTM.isModLoaded();
case "mixins.gregtech.littletiles.json" -> Mods.LittleTiles.isModLoaded();
case "mixins.gregtech.vintagium.json" -> Mods.Vintagium.isModLoaded();
case "mixins.gregtech.nothirium.json" -> Mods.Nothirium.isModLoaded();
default -> true;
};
}
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/gregtech/mixins/minecraft/BlockRenderLayerMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package gregtech.mixins.minecraft;

import net.minecraft.util.BlockRenderLayer;

import org.apache.commons.lang3.ArrayUtils;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(BlockRenderLayer.class)
public class BlockRenderLayerMixin {

@Final
@Shadow
@Mutable
private static BlockRenderLayer[] $VALUES;

@SuppressWarnings("all")
@Invoker("<init>")
private static BlockRenderLayer create(String name, int ordinal, String directoryName) {
throw new IllegalStateException("Unreachable");
}

static {
BlockRenderLayer bloom = create("BLOOM", $VALUES.length, "Bloom");

$VALUES = ArrayUtils.add($VALUES, bloom);
}
}
35 changes: 35 additions & 0 deletions src/main/java/gregtech/mixins/nothirium/ChunkRenderPassMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package gregtech.mixins.nothirium;

import meldexun.nothirium.api.renderer.chunk.ChunkRenderPass;
import org.apache.commons.lang3.ArrayUtils;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(ChunkRenderPass.class)
public class ChunkRenderPassMixin {

@Final
@Mutable
@Shadow(remap = false)
public static ChunkRenderPass[] $VALUES;

@Final
@Mutable
@Shadow(remap = false)
public static ChunkRenderPass[] ALL;

@SuppressWarnings("all")
@Invoker(value = "<init>")
private static ChunkRenderPass create(String name, int ordinal) {
throw new IllegalStateException("Unreachable");
}

static {
ChunkRenderPass bloom = create("BLOOM", $VALUES.length);
$VALUES = ArrayUtils.add($VALUES, bloom);
ALL = ChunkRenderPass.values();
}
}
31 changes: 16 additions & 15 deletions src/main/java/gregtech/mixins/vintagium/BlockRenderPassMixin.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package gregtech.mixins.vintagium;

import gregtech.client.utils.BloomEffectUtil;
import gregtech.client.utils.BloomEffectVintagiumUtil;

import net.minecraft.util.BlockRenderLayer;
import net.minecraftforge.common.util.EnumHelper;

import me.jellysquid.mods.sodium.client.render.chunk.passes.BlockRenderPass;
import me.jellysquid.mods.sodium.client.util.BufferSizeUtil;
import me.jellysquid.mods.sodium.client.util.EnumUtil;
import org.apache.commons.lang3.ArrayUtils;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(BlockRenderPass.class)
public abstract class BlockRenderPassMixin {

@Final
@Mutable
@Shadow(remap = false)
public static BlockRenderPass[] $VALUES;

@Final
@Mutable
@Shadow(remap = false)
Expand All @@ -30,17 +31,17 @@ public abstract class BlockRenderPassMixin {
@Shadow(remap = false)
public static int COUNT;

@SuppressWarnings("UnresolvedMixinReference")
@Inject(method = "<clinit>",
at = @At(value = "TAIL"),
remap = false)
private static void init(CallbackInfo ci) {
EnumUtil.LAYERS = BlockRenderLayer.values();
@SuppressWarnings("all")
@Invoker("<init>")
private static BlockRenderPass create(String name, int ordinal, BlockRenderLayer layer, boolean translucent) {
throw new IllegalStateException("Unreachable");
}

static {
BufferSizeUtil.BUFFER_SIZES.put(BloomEffectUtil.getBloomLayer(), 131072);

var params = new Class[] { BlockRenderLayer.class, boolean.class };
var values = new Object[] { BloomEffectUtil.getBloomLayer(), true };
BloomEffectVintagiumUtil.bloom = EnumHelper.addEnum(BlockRenderPass.class, "BLOOM", params, values);
BlockRenderPass bloom = create("BLOOM", $VALUES.length, BloomEffectUtil.getBloomLayer(), true);
$VALUES = ArrayUtils.add($VALUES, bloom);
VALUES = BlockRenderPass.values();
COUNT = VALUES.length;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/mixins.gregtech.minecraft.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"mixins": [
"BlockConcretePowderMixin",
"BlockRenderLayerMixin",
"DamageSourceMixin",
"EnchantmentCanApplyMixin",
"MinecraftMixin"
Expand Down
Loading

0 comments on commit 15453f7

Please sign in to comment.