Skip to content

Commit

Permalink
Fixes on 1.19 (#544)
Browse files Browse the repository at this point in the history
* Whoops! You Have To Put The CD In Your Computer!

* GOD WHY WON'T YOU WORK

* fix: hulls are no longer counted as energy inputs in cleanrooms (#543)

* fix: injecting packs now works on 1.19

---------

Co-authored-by: screret <[email protected]>
  • Loading branch information
mikerooni and screret authored Nov 12, 2023
1 parent e38db32 commit 682961a
Show file tree
Hide file tree
Showing 19 changed files with 132 additions and 80 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ Version: 1.0.15
* fix item pipes stopping transfer after their transfer rate per second has been reached once
* fix capability IO directions
* fix laser pipes not connecting to hatches
* fix diodes being counted as energy input in cleanrooms
* fix diodes and hulls being counted as energy input in cleanrooms
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.gregtechceu.gtceu.api.data.chemical.material.Material;
import com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey;
import com.gregtechceu.gtceu.api.data.tag.TagPrefix;
import com.lowdragmc.lowdraglib.Platform;
import com.lowdragmc.lowdraglib.client.renderer.IItemRendererProvider;
import com.lowdragmc.lowdraglib.client.renderer.IRenderer;
import dev.architectury.injectables.annotations.ExpectPlatform;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.metadata.animation.AnimationFrame;
import net.minecraft.client.resources.metadata.animation.AnimationMetadataSection;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.Registry;
import net.minecraft.data.models.BlockModelGenerators;
import net.minecraft.data.models.model.*;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -37,20 +37,20 @@ public static void create(Block block, MaterialIconType type, MaterialIconSet ic

public static void reinitModels() {
for (MaterialBlockRenderer model : MODELS) {
ResourceLocation blockId = BuiltInRegistries.BLOCK.getKey(model.block);
ResourceLocation modelId = blockId.withPrefix("block/");
ResourceLocation blockId = Registry.BLOCK.getKey(model.block);
ResourceLocation modelId = new ResourceLocation(blockId.getNamespace(), "block/" + blockId.getPath());
GTDynamicResourcePack.addBlockModel(modelId, new DelegatedModel(model.type.getBlockModelPath(model.iconSet, true)));
GTDynamicResourcePack.addBlockState(blockId, BlockModelGenerators.createSimpleBlock(model.block, modelId));
// ModelTemplates.CUBE_ALL.create(model.block,
// cubeTwoLayer(model.type.getBlockTexturePath(model.iconSet, true), model.type.getBlockTexturePath(model.iconSet, true).withSuffix(LAYER_2_SUFFIX)),
// GTDynamicResourcePack::addBlockModel)));
GTDynamicResourcePack.addItemModel(BuiltInRegistries.ITEM.getKey(model.block.asItem()), new DelegatedModel(ModelLocationUtils.getModelLocation(model.block)));
GTDynamicResourcePack.addItemModel(Registry.ITEM.getKey(model.block.asItem()), new DelegatedModel(ModelLocationUtils.getModelLocation(model.block)));
}
}

public static void initTextures() {
for (MaterialBlockRenderer model : MODELS) {
ResourceLocation blockId = BuiltInRegistries.BLOCK.getKey(model.block);
ResourceLocation blockId = Registry.BLOCK.getKey(model.block);

Resource file1 = Minecraft.getInstance().getResourceManager().getResource(GTDynamicResourcePack.getTextureLocation(null, model.type.getBlockTexturePath(model.iconSet, true)/*.withSuffix("_layer1")*/)).orElse(null);
if (file1 == null) continue;
Expand All @@ -68,7 +68,8 @@ public static void initTextures() {
}
if (materialBlock.material.getMaterialSecondaryRGB() != -1) {
int materialSecondaryRGBA = GradientUtil.argbToRgba(materialBlock.material.getMaterialSecondaryARGB());
Resource file2 = Minecraft.getInstance().getResourceManager().getResource(GTDynamicResourcePack.getTextureLocation(null, model.type.getBlockTexturePath(model.iconSet, true).withSuffix(LAYER_2_SUFFIX))).orElse(null);
ResourceLocation path = model.type.getBlockTexturePath(model.iconSet, true);
Resource file2 = Minecraft.getInstance().getResourceManager().getResource(GTDynamicResourcePack.getTextureLocation(null, new ResourceLocation(path.getNamespace(), path.getPath() + LAYER_2_SUFFIX))).orElse(null);
if (file2 != null) {
try(InputStream stream2 = file2.open()) {
NativeImage image2 = NativeImage.read(stream2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.RandomSource;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.gregtechceu.gtceu.utils.GradientUtil;
import com.mojang.blaze3d.platform.NativeImage;
import net.minecraft.client.Minecraft;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.Registry;
import net.minecraft.data.models.model.DelegatedModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.Resource;
Expand All @@ -36,15 +36,15 @@ public static void create(Item item, MaterialIconType type, MaterialIconSet icon

public static void reinitModels() {
for (TagPrefixItemRenderer model : MODELS) {
ResourceLocation itemId = BuiltInRegistries.ITEM.getKey(model.item);
ResourceLocation itemId = Registry.ITEM.getKey(model.item);
GTDynamicResourcePack.addItemModel(itemId, new DelegatedModel(model.type.getItemModelPath(model.iconSet, true)));
//ModelTemplates.FLAT_ITEM.create(GTDynamicResourcePack.getItemModelLocation(itemId), TextureMapping.layer0(itemId.withPrefix("item/")), GTDynamicResourcePack::addItemModel);
}
}

public static void initTextures() {
for (TagPrefixItemRenderer model : MODELS) {
ResourceLocation itemId = BuiltInRegistries.ITEM.getKey(model.item);
ResourceLocation itemId = Registry.ITEM.getKey(model.item);

Resource file1 = Minecraft.getInstance().getResourceManager().getResource(GTDynamicResourcePack.getTextureLocation(null, model.type.getItemTexturePath(model.iconSet, true)/*.withSuffix("_layer1")*/)).orElse(null);
if (file1 == null) continue;
Expand All @@ -62,7 +62,8 @@ public static void initTextures() {
}
}
if (prefixItem.material.getMaterialSecondaryRGB() != -1) {
Resource file2 = Minecraft.getInstance().getResourceManager().getResource(GTDynamicResourcePack.getTextureLocation(null, model.type.getItemTexturePath(model.iconSet, true).withSuffix(LAYER_2_SUFFIX))).orElse(null);
ResourceLocation path = model.type.getItemTexturePath(model.iconSet, true);
Resource file2 = Minecraft.getInstance().getResourceManager().getResource(GTDynamicResourcePack.getTextureLocation(null, new ResourceLocation(path.getNamespace(), path.getPath() + LAYER_2_SUFFIX))).orElse(null);
if (file2 != null) {
try(InputStream stream2 = file2.open()) {
NativeImage image2 = NativeImage.read(stream2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.gregtechceu.gtceu.data.pack.GTDynamicResourcePack;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.Registry;
import net.minecraft.data.models.model.DelegatedModel;
import net.minecraft.world.item.Item;

Expand All @@ -21,7 +21,7 @@ public class ToolItemRenderer {

public static void reinitModels() {
for (ToolItemRenderer model : MODELS) {
GTDynamicResourcePack.addItemModel(BuiltInRegistries.ITEM.getKey(model.item), new DelegatedModel(model.toolType.modelLocation));
GTDynamicResourcePack.addItemModel(Registry.ITEM.getKey(model.item), new DelegatedModel(model.toolType.modelLocation));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.Sheets;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.renderer.texture.MissingTextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.resources.model.BakedModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.util.Mth;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import org.jetbrains.annotations.NotNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gregtechceu.gtceu.common.data;

import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableTable;
import com.google.common.collect.Table;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import com.gregtechceu.gtceu.api.capability.GTCapabilityHelper;
import com.gregtechceu.gtceu.api.capability.ICleanroomReceiver;
import com.gregtechceu.gtceu.api.capability.IEnergyContainer;
import com.gregtechceu.gtceu.common.machine.multiblock.part.DiodePartMachine;
import com.gregtechceu.gtceu.common.machine.trait.CleanroomLogic;
import com.gregtechceu.gtceu.api.capability.recipe.EURecipeCapability;
import com.gregtechceu.gtceu.api.capability.recipe.IO;
import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity;
Expand All @@ -19,14 +17,23 @@
import com.gregtechceu.gtceu.api.machine.feature.multiblock.IMaintenanceMachine;
import com.gregtechceu.gtceu.api.machine.feature.multiblock.IMufflerMachine;
import com.gregtechceu.gtceu.api.machine.feature.multiblock.IMultiPart;
import com.gregtechceu.gtceu.api.machine.multiblock.*;
import com.gregtechceu.gtceu.api.machine.multiblock.CleanroomType;
import com.gregtechceu.gtceu.api.machine.multiblock.PartAbility;
import com.gregtechceu.gtceu.api.machine.multiblock.WorkableElectricMultiblockMachine;
import com.gregtechceu.gtceu.api.machine.multiblock.WorkableMultiblockMachine;
import com.gregtechceu.gtceu.api.machine.trait.RecipeLogic;
import com.gregtechceu.gtceu.api.misc.EnergyContainerList;
import com.gregtechceu.gtceu.api.pattern.*;
import com.gregtechceu.gtceu.api.pattern.BlockPattern;
import com.gregtechceu.gtceu.api.pattern.FactoryBlockPattern;
import com.gregtechceu.gtceu.api.pattern.Predicates;
import com.gregtechceu.gtceu.api.pattern.TraceabilityPredicate;
import com.gregtechceu.gtceu.common.data.GTBlocks;
import com.gregtechceu.gtceu.common.machine.electric.HullMachine;
import com.gregtechceu.gtceu.common.machine.multiblock.part.DiodePartMachine;
import com.gregtechceu.gtceu.common.machine.multiblock.primitive.CokeOvenMachine;
import com.gregtechceu.gtceu.common.machine.multiblock.primitive.PrimitiveBlastFurnaceMachine;
import com.gregtechceu.gtceu.common.machine.multiblock.primitive.PrimitivePumpMachine;
import com.gregtechceu.gtceu.common.machine.trait.CleanroomLogic;
import com.gregtechceu.gtceu.utils.GTUtil;
import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted;
import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder;
Expand All @@ -53,7 +60,8 @@
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.*;

import static com.gregtechceu.gtceu.api.pattern.Predicates.*;
import static com.gregtechceu.gtceu.api.pattern.Predicates.abilities;
import static com.gregtechceu.gtceu.api.pattern.Predicates.states;

@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
Expand Down Expand Up @@ -158,9 +166,9 @@ protected void initializeAbilities() {
List<IEnergyContainer> energyContainers = new ArrayList<>();
Map<Long, IO> ioMap = getMultiblockState().getMatchContext().getOrCreate("ioMap", Long2ObjectMaps::emptyMap);
for (IMultiPart part : getParts()) {
if (part instanceof DiodePartMachine) continue;
if (isPartIgnored(part)) continue;
IO io = ioMap.getOrDefault(part.self().getPos().asLong(), IO.BOTH);
if(io == IO.NONE || io == IO.OUT) continue;
if (io == IO.NONE || io == IO.OUT) continue;
for (var handler : part.getRecipeHandlers()) {
// If IO not compatible
if (io != IO.BOTH && handler.getHandlerIO() != IO.BOTH && io != handler.getHandlerIO()) continue;
Expand All @@ -176,6 +184,14 @@ protected void initializeAbilities() {
getRecipeLogic().setEnergyContainer(this.inputEnergyContainers);
}

@SuppressWarnings("RedundantIfStatement") // `return false` being a separate statement is better for readability
private static boolean isPartIgnored(IMultiPart part) {
if (part instanceof DiodePartMachine) return true;
if (part instanceof HullMachine) return true;

return false;
}

/**
* Scans for blocks around the controller to update the dimensions
*/
Expand Down Expand Up @@ -376,7 +392,7 @@ protected BlockState getGlassState() {
@Nonnull
protected static TraceabilityPredicate doorPredicate() {
return Predicates.custom(blockWorldState -> blockWorldState.getBlockState().getBlock() instanceof DoorBlock,
() -> new BlockInfo[] {new BlockInfo(Blocks.IRON_DOOR.defaultBlockState()), new BlockInfo(Blocks.IRON_DOOR.defaultBlockState().setValue(DoorBlock.HALF, DoubleBlockHalf.UPPER))});
() -> new BlockInfo[]{new BlockInfo(Blocks.IRON_DOOR.defaultBlockState()), new BlockInfo(Blocks.IRON_DOOR.defaultBlockState().setValue(DoorBlock.HALF, DoubleBlockHalf.UPPER))});
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,14 @@ public ResourceLocation type() {
}

public PipeModel createPipeModel(Material material) {
Supplier<ResourceLocation> wireSideTexturePath = () -> MaterialIconType.wire.getBlockTexturePath(material.getMaterialIconSet(), true).withSuffix("_side");
Supplier<ResourceLocation> wireEndTexturePath = () -> MaterialIconType.wire.getBlockTexturePath(material.getMaterialIconSet(), true).withSuffix("_end");
Supplier<ResourceLocation> wireSideTexturePath = () -> {
ResourceLocation location = MaterialIconType.wire.getBlockTexturePath(material.getMaterialIconSet(), true);
return new ResourceLocation(location.getNamespace(), location.getPath() + "_side");
};
Supplier<ResourceLocation> wireEndTexturePath = () -> {
ResourceLocation location = MaterialIconType.wire.getBlockTexturePath(material.getMaterialIconSet(), true);
return new ResourceLocation(location.getNamespace(), location.getPath() + "_end");
};
Supplier<@Nullable ResourceLocation> wireSideOverlayTexturePath = () -> MaterialIconType.wire.getBlockTexturePath(material.getMaterialIconSet(), "side_overlay", true);
Supplier<@Nullable ResourceLocation> wireEndOverlayTexturePath = () -> MaterialIconType.wire.getBlockTexturePath(material.getMaterialIconSet(), "end_overlay", true);
PipeModel model = new PipeModel(thickness, isCable ? () -> GTCEu.id("block/cable/insulation_5") : wireSideTexturePath, wireEndTexturePath, wireSideOverlayTexturePath, wireEndOverlayTexturePath);
Expand Down
33 changes: 31 additions & 2 deletions common/src/main/java/com/gregtechceu/gtceu/core/MixinHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,34 @@
import com.gregtechceu.gtceu.api.data.chemical.material.Material;
import com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey;
import com.gregtechceu.gtceu.api.data.tag.TagPrefix;
import com.gregtechceu.gtceu.api.fluids.GTFluid;
import com.gregtechceu.gtceu.api.fluids.store.FluidStorage;
import com.gregtechceu.gtceu.api.fluids.store.FluidStorageKey;
import com.gregtechceu.gtceu.api.registry.GTRegistries;
import com.gregtechceu.gtceu.client.renderer.block.MaterialBlockRenderer;
import com.gregtechceu.gtceu.client.renderer.item.TagPrefixItemRenderer;
import com.gregtechceu.gtceu.client.renderer.item.ToolItemRenderer;
import com.gregtechceu.gtceu.common.data.GTModels;
import com.gregtechceu.gtceu.common.data.GTRecipes;
import com.gregtechceu.gtceu.config.ConfigHolder;
import com.gregtechceu.gtceu.core.mixins.BlockBehaviourAccessor;
import com.gregtechceu.gtceu.data.pack.GTDynamicDataPack;
import com.gregtechceu.gtceu.data.pack.GTDynamicResourcePack;
import com.gregtechceu.gtceu.data.recipe.CustomTags;
import com.lowdragmc.lowdraglib.side.fluid.FluidHelper;
import com.lowdragmc.lowdraglib.side.fluid.FluidStack;
import com.tterrag.registrate.util.entry.BlockEntry;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.minecraft.core.Registry;
import net.minecraft.data.loot.BlockLoot;
import net.minecraft.data.models.model.DelegatedModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.PackResources;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.TagEntry;
import net.minecraft.tags.TagKey;
import net.minecraft.tags.TagLoader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.storage.loot.LootTable;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;

Expand Down Expand Up @@ -108,14 +115,36 @@ public static List<PackResources> addDynamicResourcePack(Collection<PackResource
MaterialBlockRenderer.reinitModels();
TagPrefixItemRenderer.reinitModels();
ToolItemRenderer.reinitModels();
GTModels.registerMaterialFluidModels();
registerMaterialFluidModels();
GTCEu.LOGGER.info("GregTech Model loading took {}ms", System.currentTimeMillis() - startTime);

// Load the data
packResources.add(new GTDynamicResourcePack("gtceu:dynamic_assets", AddonFinder.getAddons().stream().map(IGTAddon::addonModId).collect(Collectors.toSet())));
return packResources;
}

/**
* register fluid models for materials
*/
public static void registerMaterialFluidModels() {
for (var material : GTRegistries.MATERIALS) {
var fluidProperty = material.getProperty(PropertyKey.FLUID);
if (fluidProperty == null) continue;

for (FluidStorageKey key : FluidStorageKey.allKeys()) {
FluidStorage storage = fluidProperty.getStorage();
Fluid fluid = storage.get(key);
if (fluid instanceof GTFluid gtFluid) {
FluidStack testFor = FluidStack.create(gtFluid, FluidHelper.getBucket());
GTDynamicResourcePack.addItemModel(
Registry.ITEM.getKey(gtFluid.getBucket()),
new DelegatedModel(GTCEu.id("item/bucket/" + (FluidHelper.isLighterThanAir(testFor) ? "bucket_gas" : "bucket")))
);
}
}
}
}

// unused on purpose. Do not call, will destroy ram usage.
public static void initializeDynamicTextures() {
//MaterialBlockRenderer.initTextures();
Expand Down

This file was deleted.

Loading

0 comments on commit 682961a

Please sign in to comment.