diff --git a/common/src/main/java/gripe/_90/megacells/MEGACells.java b/common/src/main/java/gripe/_90/megacells/MEGACells.java index 57cd8bfa..405304d1 100644 --- a/common/src/main/java/gripe/_90/megacells/MEGACells.java +++ b/common/src/main/java/gripe/_90/megacells/MEGACells.java @@ -40,6 +40,9 @@ private MEGACells() {} public static final Platform PLATFORM = ServiceLoader.load(Platform.class).findFirst().orElseThrow(); + public static final Platform.Client PLATFORM_CLIENT = PLATFORM.isClient() + ? ServiceLoader.load(Platform.Client.class).findFirst().orElseThrow() + : null; public static ResourceLocation makeId(String path) { return new ResourceLocation(MODID, path); @@ -56,7 +59,14 @@ public static void initCommon() { AppBotItems.init(); } - initStorageCells(); + StorageCells.addCellHandler(BulkCellItem.HANDLER); + + MEGAItems.getItemPortables() + .forEach(cell -> HotkeyActions.registerPortableCell(cell, HotkeyAction.PORTABLE_ITEM_CELL)); + MEGAItems.getFluidPortables() + .forEach(cell -> HotkeyActions.registerPortableCell(cell, HotkeyAction.PORTABLE_FLUID_CELL)); + + initStorageCellModels(); PLATFORM.initCompression(); GridServices.register(DecompressionService.class, DecompressionService.class); @@ -67,7 +77,7 @@ public static void initCommon() { PLATFORM.addVillagerTrade(MEGAItems.ACCUMULATION_PROCESSOR_PRESS, 40, 1, 50); } - private static void initStorageCells() { + private static void initStorageCellModels() { Stream.of(MEGAItems.getItemCells(), MEGAItems.getItemPortables()) .flatMap(Collection::stream) .forEach(c -> StorageCellModels.registerModel(c, makeId("block/drive/cells/mega_item_cell"))); @@ -75,14 +85,8 @@ private static void initStorageCells() { .flatMap(Collection::stream) .forEach(c -> StorageCellModels.registerModel(c, makeId("block/drive/cells/mega_fluid_cell"))); - StorageCells.addCellHandler(BulkCellItem.HANDLER); StorageCellModels.registerModel(MEGAItems.BULK_ITEM_CELL, makeId("block/drive/cells/bulk_item_cell")); - MEGAItems.getItemPortables() - .forEach(cell -> HotkeyActions.registerPortableCell(cell, HotkeyAction.PORTABLE_ITEM_CELL)); - MEGAItems.getFluidPortables() - .forEach(cell -> HotkeyActions.registerPortableCell(cell, HotkeyAction.PORTABLE_FLUID_CELL)); - if (PLATFORM.isAddonLoaded(Addons.APPBOT)) { Stream.of(AppBotItems.getCells(), AppBotItems.getPortables()) .flatMap(Collection::stream) diff --git a/common/src/main/java/gripe/_90/megacells/core/Platform.java b/common/src/main/java/gripe/_90/megacells/core/Platform.java index d00a7039..4efdfdc6 100644 --- a/common/src/main/java/gripe/_90/megacells/core/Platform.java +++ b/common/src/main/java/gripe/_90/megacells/core/Platform.java @@ -10,6 +10,8 @@ public interface Platform { Loaders getLoader(); + boolean isClient(); + CreativeModeTab.Builder getCreativeTabBuilder(); boolean isAddonLoaded(Addons addon); @@ -20,5 +22,7 @@ public interface Platform { void addVillagerTrade(ItemLike item, int cost, int quantity, int xp); - BakedModel createWrappedCellModel(Item cell, BlockOrientation orientation); + interface Client { + BakedModel createWrappedCellModel(Item cell, BlockOrientation orientation); + } } diff --git a/common/src/main/java/gripe/_90/megacells/definition/MEGABlockEntities.java b/common/src/main/java/gripe/_90/megacells/definition/MEGABlockEntities.java index 654c7a06..caf09c73 100644 --- a/common/src/main/java/gripe/_90/megacells/definition/MEGABlockEntities.java +++ b/common/src/main/java/gripe/_90/megacells/definition/MEGABlockEntities.java @@ -96,8 +96,7 @@ private static BlockEntityType create( return type; } - @FunctionalInterface - interface BlockEntityFactory { + private interface BlockEntityFactory { T create(BlockEntityType type, BlockPos pos, BlockState state); } } diff --git a/common/src/main/java/gripe/_90/megacells/item/cell/BulkCellInventory.java b/common/src/main/java/gripe/_90/megacells/item/cell/BulkCellInventory.java index 9b85a14f..fd8ad0ff 100644 --- a/common/src/main/java/gripe/_90/megacells/item/cell/BulkCellInventory.java +++ b/common/src/main/java/gripe/_90/megacells/item/cell/BulkCellInventory.java @@ -45,8 +45,7 @@ public class BulkCellInventory implements StorageCell { this.container = container; var cell = (BulkCellItem) stack.getItem(); - var filter = cell.getConfigInventory(this.stack).getKey(0); - filterItem = filter instanceof AEItemKey item ? item : null; + filterItem = (AEItemKey) cell.getConfigInventory(this.stack).getKey(0); storedItem = getTag().contains(KEY) ? AEItemKey.fromTag(getTag().getCompound(KEY)) : null; unitCount = !getTag().getString(UNIT_COUNT).isEmpty() diff --git a/common/src/main/java/gripe/_90/megacells/item/part/CellDockPart.java b/common/src/main/java/gripe/_90/megacells/item/part/CellDockPart.java index 74924c6e..57351a55 100644 --- a/common/src/main/java/gripe/_90/megacells/item/part/CellDockPart.java +++ b/common/src/main/java/gripe/_90/megacells/item/part/CellDockPart.java @@ -6,6 +6,8 @@ import org.jetbrains.annotations.Nullable; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; @@ -311,11 +313,13 @@ public IPartModel getStaticModels() { return MODEL; } + @Environment(EnvType.CLIENT) @Override public boolean requireDynamicRender() { return true; } + @Environment(EnvType.CLIENT) @Override public void renderDynamic( float partialTicks, @@ -341,7 +345,7 @@ public void renderDynamic( .getModelRenderer() .tesselateBlock( getLevel(), - MEGACells.PLATFORM.createWrappedCellModel(clientCell, orientation), + MEGACells.PLATFORM_CLIENT.createWrappedCellModel(clientCell, orientation), getBlockEntity().getBlockState(), getBlockEntity().getBlockPos(), poseStack, diff --git a/common/src/main/java/gripe/_90/megacells/misc/LavaTransformLogic.java b/common/src/main/java/gripe/_90/megacells/misc/LavaTransformLogic.java index 6556791d..137ee7f7 100644 --- a/common/src/main/java/gripe/_90/megacells/misc/LavaTransformLogic.java +++ b/common/src/main/java/gripe/_90/megacells/misc/LavaTransformLogic.java @@ -32,23 +32,17 @@ public static boolean allIngredientsPresent(ItemEntity entity) { .toList(); for (var recipe : level.getRecipeManager().getAllRecipesFor(TransformRecipe.TYPE)) { - if (!recipe.circumstance.isFluidTag(FluidTags.LAVA)) { - continue; - } - - if (recipe.ingredients.isEmpty()) { - continue; - } - - return recipe.ingredients.stream().noneMatch(ingredient -> { - for (var stack : ingredient.getItems()) { - if (items.contains(stack.getItem())) { - return false; + if (recipe.circumstance.isFluidTag(FluidTags.LAVA)) { + return recipe.ingredients.stream().noneMatch(ingredient -> { + for (var stack : ingredient.getItems()) { + if (items.contains(stack.getItem())) { + return false; + } } - } - return true; - }); + return true; + }); + } } return false; diff --git a/fabric/src/main/java/gripe/_90/megacells/fabric/FabricPlatform.java b/fabric/src/main/java/gripe/_90/megacells/fabric/FabricPlatform.java index 1a34b908..3289826f 100644 --- a/fabric/src/main/java/gripe/_90/megacells/fabric/FabricPlatform.java +++ b/fabric/src/main/java/gripe/_90/megacells/fabric/FabricPlatform.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.List; +import net.fabricmc.api.EnvType; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup; import net.fabricmc.fabric.api.object.builder.v1.trade.TradeOfferHelper; @@ -37,6 +38,11 @@ public Loaders getLoader() { return Loaders.FABRIC; } + @Override + public boolean isClient() { + return FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT; + } + @Override public CreativeModeTab.Builder getCreativeTabBuilder() { return FabricItemGroup.builder(); @@ -72,15 +78,17 @@ public void addVillagerTrade(ItemLike item, int cost, int quantity, int xp) { builder -> builder.add(new VillagerTrades.ItemsForEmeralds(item.asItem(), cost, quantity, xp))); } - @Override - public BakedModel createWrappedCellModel(Item cell, BlockOrientation orientation) { - var driveModel = Minecraft.getInstance() - .getModelManager() - .getBlockModelShaper() - .getBlockModel(AEBlocks.DRIVE.block().defaultBlockState()); - var cellModel = - BakedModelUnwrapper.unwrap(driveModel, DriveBakedModel.class).getCellChassisModel(cell); - return new WrappedCellModel(cellModel, orientation); + public static class Client implements Platform.Client { + @Override + public BakedModel createWrappedCellModel(Item cell, BlockOrientation orientation) { + var driveModel = Minecraft.getInstance() + .getModelManager() + .getBlockModelShaper() + .getBlockModel(AEBlocks.DRIVE.block().defaultBlockState()); + var cellModel = BakedModelUnwrapper.unwrap(driveModel, DriveBakedModel.class) + .getCellChassisModel(cell); + return new WrappedCellModel(cellModel, orientation); + } } private static class WrappedCellModel extends ForwardingBakedModel { diff --git a/fabric/src/main/resources/META-INF/services/gripe._90.megacells.core.Platform$Client b/fabric/src/main/resources/META-INF/services/gripe._90.megacells.core.Platform$Client new file mode 100644 index 00000000..def2031a --- /dev/null +++ b/fabric/src/main/resources/META-INF/services/gripe._90.megacells.core.Platform$Client @@ -0,0 +1 @@ +gripe._90.megacells.fabric.FabricPlatform$Client \ No newline at end of file diff --git a/forge/src/main/java/gripe/_90/megacells/forge/ForgePlatform.java b/forge/src/main/java/gripe/_90/megacells/forge/ForgePlatform.java index 5d90d20d..c45565a8 100644 --- a/forge/src/main/java/gripe/_90/megacells/forge/ForgePlatform.java +++ b/forge/src/main/java/gripe/_90/megacells/forge/ForgePlatform.java @@ -23,11 +23,13 @@ import net.minecraft.world.item.trading.MerchantOffer; import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.model.data.ModelData; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.OnDatapackSyncEvent; import net.minecraftforge.event.server.ServerStartedEvent; import net.minecraftforge.fml.ModList; +import net.minecraftforge.fml.loading.FMLEnvironment; import net.minecraftforge.fml.loading.LoadingModList; import net.minecraftforge.fml.loading.moddiscovery.ModInfo; @@ -50,6 +52,11 @@ public Loaders getLoader() { return Loaders.FORGE; } + @Override + public boolean isClient() { + return FMLEnvironment.dist == Dist.CLIENT; + } + @Override public CreativeModeTab.Builder getCreativeTabBuilder() { return CreativeModeTab.builder(); @@ -102,43 +109,45 @@ public void addVillagerTrade(ItemLike item, int cost, int quantity, int xp) { offers.put(5, masterEntries); } - @Override - public BakedModel createWrappedCellModel(Item cell, BlockOrientation orientation) { - var driveModel = Minecraft.getInstance() - .getModelManager() - .getBlockModelShaper() - .getBlockModel(AEBlocks.DRIVE.block().defaultBlockState()); - var cellModel = - BakedModelUnwrapper.unwrap(driveModel, DriveBakedModel.class).getCellChassisModel(cell); - - return new DelegateBakedModel(cellModel) { - @NotNull - @Override - public List getQuads( - @Nullable BlockState state, - @Nullable Direction side, - @NotNull RandomSource rand, - @NotNull ModelData extraData, - RenderType renderType) { - if (side != null) { - side = orientation.resultingRotate(side); // This fixes the incorrect lightmap position + public static class Client implements Platform.Client { + @Override + public BakedModel createWrappedCellModel(Item cell, BlockOrientation orientation) { + var driveModel = Minecraft.getInstance() + .getModelManager() + .getBlockModelShaper() + .getBlockModel(AEBlocks.DRIVE.block().defaultBlockState()); + var cellModel = BakedModelUnwrapper.unwrap(driveModel, DriveBakedModel.class) + .getCellChassisModel(cell); + + return new DelegateBakedModel(cellModel) { + @NotNull + @Override + public List getQuads( + @Nullable BlockState state, + @Nullable Direction side, + @NotNull RandomSource rand, + @NotNull ModelData extraData, + RenderType renderType) { + if (side != null) { + side = orientation.resultingRotate(side); // This fixes the incorrect lightmap position + } + List quads = new ArrayList<>(super.getQuads(state, side, rand, extraData, renderType)); + + for (int i = 0; i < quads.size(); i++) { + BakedQuad quad = quads.get(i); + quads.set( + i, + new BakedQuad( + quad.getVertices(), + quad.getTintIndex(), + orientation.rotate(quad.getDirection()), + quad.getSprite(), + quad.isShade())); + } + + return quads; } - List quads = new ArrayList<>(super.getQuads(state, side, rand, extraData, renderType)); - - for (int i = 0; i < quads.size(); i++) { - BakedQuad quad = quads.get(i); - quads.set( - i, - new BakedQuad( - quad.getVertices(), - quad.getTintIndex(), - orientation.rotate(quad.getDirection()), - quad.getSprite(), - quad.isShade())); - } - - return quads; - } - }; + }; + } } } diff --git a/forge/src/main/resources/META-INF/services/gripe._90.megacells.core.Platform$Client b/forge/src/main/resources/META-INF/services/gripe._90.megacells.core.Platform$Client new file mode 100644 index 00000000..261f4814 --- /dev/null +++ b/forge/src/main/resources/META-INF/services/gripe._90.megacells.core.Platform$Client @@ -0,0 +1 @@ +gripe._90.megacells.forge.ForgePlatform$Client \ No newline at end of file