From 1daeed5f5ad18750ebba102b3519161d20768378 Mon Sep 17 00:00:00 2001 From: Juuz <6596629+Juuxel@users.noreply.github.com> Date: Fri, 2 Aug 2024 14:25:14 +0300 Subject: [PATCH] Rewrite platform bridges in Java --- .../adorn/block/AdornBlockEntities.java | 4 +-- .../java/juuxel/adorn/block/AdornBlocks.java | 2 +- .../java/juuxel/adorn/block/DrawerBlock.java | 2 +- .../adorn/block/KitchenCupboardBlock.java | 2 +- .../java/juuxel/adorn/block/ShelfBlock.java | 4 +-- .../adorn/client/ClientNetworkBridge.java | 15 +++++++++ .../adorn/client/FluidRenderingBridge.java | 33 +++++++++++++++++++ .../client/gui/screen/PalettedMenuScreen.java | 2 +- .../juuxel/adorn/entity/AdornEntities.java | 2 +- .../java/juuxel/adorn/entity/SeatEntity.java | 2 +- .../java/juuxel/adorn/item/AdornBookItem.java | 4 +-- .../java/juuxel/adorn/menu/AdornMenus.java | 8 ++--- .../java/juuxel/adorn/menu/BrewerMenu.java | 2 +- .../adorn/platform/BlockEntityBridge.java | 11 +++++++ .../juuxel/adorn/platform/BlockFactory.java | 12 +++++++ .../juuxel/adorn/platform/EntityBridge.java | 8 +++++ .../juuxel/adorn/platform/FluidBridge.java | 25 ++++++++++++++ .../juuxel/adorn/platform/MenuBridge.java | 25 ++++++++++++++ .../juuxel/adorn/platform/NetworkBridge.java | 22 +++++++++++++ .../adorn/platform/PlatformBridges.java | 19 +++++++++++ .../juuxel/adorn/platform/ResourceBridge.java | 9 +++++ .../adorn/client/ClientNetworkBridge.kt | 17 ---------- .../adorn/client/ClientPlatformBridges.kt | 14 -------- .../adorn/client/FluidRenderingBridge.kt | 26 --------------- .../adorn/platform/BlockEntityBridge.kt | 11 ------- .../juuxel/adorn/platform/BlockFactory.kt | 10 ------ .../juuxel/adorn/platform/EntityBridge.kt | 8 ----- .../juuxel/adorn/platform/FluidBridge.kt | 26 --------------- .../juuxel/adorn/platform/MenuBridge.kt | 23 ------------- .../juuxel/adorn/platform/NetworkBridge.kt | 22 ------------- .../juuxel/adorn/platform/PlatformBridges.kt | 26 --------------- .../juuxel/adorn/platform/ResourceBridge.kt | 9 ----- .../client/ClientPlatformBridgesFabric.java | 8 ----- .../adorn/platform/fabric/MenuBridgeImpl.java | 5 ++- .../platform/fabric/PlatformBridgesImpl.java | 2 +- .../juuxel.adorn.client.ClientPlatformBridges | 1 - .../juuxel.adorn.client.FluidRenderingBridge | 1 + .../adorn/platform/forge/MenuBridgeImpl.java | 7 ++-- .../platform/forge/client/AdornClient.java | 6 ++-- .../client/ClientPlatformBridgesForge.java | 11 ------- .../juuxel.adorn.client.ClientPlatformBridges | 1 - .../juuxel.adorn.client.FluidRenderingBridge | 1 + 42 files changed, 205 insertions(+), 243 deletions(-) create mode 100644 common/src/main/java/juuxel/adorn/client/ClientNetworkBridge.java create mode 100644 common/src/main/java/juuxel/adorn/client/FluidRenderingBridge.java create mode 100644 common/src/main/java/juuxel/adorn/platform/BlockEntityBridge.java create mode 100644 common/src/main/java/juuxel/adorn/platform/BlockFactory.java create mode 100644 common/src/main/java/juuxel/adorn/platform/EntityBridge.java create mode 100644 common/src/main/java/juuxel/adorn/platform/FluidBridge.java create mode 100644 common/src/main/java/juuxel/adorn/platform/MenuBridge.java create mode 100644 common/src/main/java/juuxel/adorn/platform/NetworkBridge.java create mode 100644 common/src/main/java/juuxel/adorn/platform/PlatformBridges.java create mode 100644 common/src/main/java/juuxel/adorn/platform/ResourceBridge.java delete mode 100644 common/src/main/kotlin/juuxel/adorn/client/ClientNetworkBridge.kt delete mode 100644 common/src/main/kotlin/juuxel/adorn/client/ClientPlatformBridges.kt delete mode 100644 common/src/main/kotlin/juuxel/adorn/client/FluidRenderingBridge.kt delete mode 100644 common/src/main/kotlin/juuxel/adorn/platform/BlockEntityBridge.kt delete mode 100644 common/src/main/kotlin/juuxel/adorn/platform/BlockFactory.kt delete mode 100644 common/src/main/kotlin/juuxel/adorn/platform/EntityBridge.kt delete mode 100644 common/src/main/kotlin/juuxel/adorn/platform/FluidBridge.kt delete mode 100644 common/src/main/kotlin/juuxel/adorn/platform/MenuBridge.kt delete mode 100644 common/src/main/kotlin/juuxel/adorn/platform/NetworkBridge.kt delete mode 100644 common/src/main/kotlin/juuxel/adorn/platform/PlatformBridges.kt delete mode 100644 common/src/main/kotlin/juuxel/adorn/platform/ResourceBridge.kt delete mode 100644 fabric/src/main/java/juuxel/adorn/client/ClientPlatformBridgesFabric.java delete mode 100644 fabric/src/main/resources/META-INF/services/juuxel.adorn.client.ClientPlatformBridges create mode 100644 fabric/src/main/resources/META-INF/services/juuxel.adorn.client.FluidRenderingBridge delete mode 100644 forge/src/main/java/juuxel/adorn/platform/forge/client/ClientPlatformBridgesForge.java delete mode 100644 forge/src/main/resources/META-INF/services/juuxel.adorn.client.ClientPlatformBridges create mode 100644 forge/src/main/resources/META-INF/services/juuxel.adorn.client.FluidRenderingBridge diff --git a/common/src/main/java/juuxel/adorn/block/AdornBlockEntities.java b/common/src/main/java/juuxel/adorn/block/AdornBlockEntities.java index 7230ab28d..053baf21a 100644 --- a/common/src/main/java/juuxel/adorn/block/AdornBlockEntities.java +++ b/common/src/main/java/juuxel/adorn/block/AdornBlockEntities.java @@ -27,11 +27,11 @@ public final class AdornBlockEntities { public static final Registered> KITCHEN_CUPBOARD = register("kitchen_cupboard", KitchenCupboardBlockEntity::new, KitchenCupboardBlock.class); public static final Registered> KITCHEN_SINK = - register("kitchen_sink", PlatformBridges.Companion.getBlockEntities()::createKitchenSink, KitchenSinkBlock.class); + register("kitchen_sink", PlatformBridges.get().getBlockEntities()::createKitchenSink, KitchenSinkBlock.class); public static final Registered> TRADING_STATION = register("trading_station", TradingStationBlockEntity::new, AdornBlocks.TRADING_STATION); public static final Registered> BREWER = - register("brewer", PlatformBridges.Companion.getBlockEntities()::createBrewer, AdornBlocks.BREWER); + register("brewer", PlatformBridges.get().getBlockEntities()::createBrewer, AdornBlocks.BREWER); private static Registered> register(String name, BlockEntityFactory factory, Supplier block) { return BLOCK_ENTITIES.register(name, () -> BlockEntityType.Builder.create(factory, block.get()).build(null)); diff --git a/common/src/main/java/juuxel/adorn/block/AdornBlocks.java b/common/src/main/java/juuxel/adorn/block/AdornBlocks.java index 59499d774..216d434e6 100644 --- a/common/src/main/java/juuxel/adorn/block/AdornBlocks.java +++ b/common/src/main/java/juuxel/adorn/block/AdornBlocks.java @@ -33,7 +33,7 @@ public final class AdornBlocks { DyeColor.values(), color -> HELPER.registerBlock( color.asString() + "_sofa", - () -> PlatformBridges.Companion.getBlockFactory().createSofa(BlockVariant.wool(color)) + () -> PlatformBridges.get().getBlockFactory().createSofa(BlockVariant.wool(color)) ) ); diff --git a/common/src/main/java/juuxel/adorn/block/DrawerBlock.java b/common/src/main/java/juuxel/adorn/block/DrawerBlock.java index e75fccb1a..04baf9ebd 100644 --- a/common/src/main/java/juuxel/adorn/block/DrawerBlock.java +++ b/common/src/main/java/juuxel/adorn/block/DrawerBlock.java @@ -74,7 +74,7 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt if (world.isClient) return ActionResult.SUCCESS; if (world.getBlockEntity(pos) instanceof DrawerBlockEntity drawer) { - PlatformBridges.Companion.getMenus().open(player, drawer, pos);; + PlatformBridges.get().getMenus().open(player, drawer, pos);; player.incrementStat(AdornStats.OPEN_DRAWER); } diff --git a/common/src/main/java/juuxel/adorn/block/KitchenCupboardBlock.java b/common/src/main/java/juuxel/adorn/block/KitchenCupboardBlock.java index 22d106dcf..0abd35518 100644 --- a/common/src/main/java/juuxel/adorn/block/KitchenCupboardBlock.java +++ b/common/src/main/java/juuxel/adorn/block/KitchenCupboardBlock.java @@ -40,7 +40,7 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt if (world.isClient) return ActionResult.SUCCESS; if (world.getBlockEntity(pos) instanceof KitchenCupboardBlockEntity cupboard) { - PlatformBridges.Companion.getMenus().open(player, cupboard, pos); + PlatformBridges.get().getMenus().open(player, cupboard, pos); player.incrementStat(AdornStats.OPEN_KITCHEN_CUPBOARD); } diff --git a/common/src/main/java/juuxel/adorn/block/ShelfBlock.java b/common/src/main/java/juuxel/adorn/block/ShelfBlock.java index 4f2ffeb42..edcf390fb 100644 --- a/common/src/main/java/juuxel/adorn/block/ShelfBlock.java +++ b/common/src/main/java/juuxel/adorn/block/ShelfBlock.java @@ -119,7 +119,7 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt inventory.setStack(slot, stack); be.markDirty(); if (!world.isClient) { - PlatformBridges.Companion.getNetwork().syncBlockEntity(be); + PlatformBridges.get().getNetwork().syncBlockEntity(be); player.incrementStat(AdornStats.INTERACT_WITH_SHELF); } @@ -138,7 +138,7 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt inventory.setStack(slot, ItemStack.EMPTY); be.markDirty(); if (!world.isClient) { - PlatformBridges.Companion.getNetwork().syncBlockEntity(be); + PlatformBridges.get().getNetwork().syncBlockEntity(be); player.incrementStat(AdornStats.INTERACT_WITH_SHELF); } } diff --git a/common/src/main/java/juuxel/adorn/client/ClientNetworkBridge.java b/common/src/main/java/juuxel/adorn/client/ClientNetworkBridge.java new file mode 100644 index 000000000..e95593051 --- /dev/null +++ b/common/src/main/java/juuxel/adorn/client/ClientNetworkBridge.java @@ -0,0 +1,15 @@ +package juuxel.adorn.client; + +import juuxel.adorn.util.InlineServices; +import juuxel.adorn.util.Services; +import net.minecraft.item.ItemStack; + +@InlineServices +public interface ClientNetworkBridge { + void sendSetTradeStack(int syncId, int slotId, ItemStack stack); + + @InlineServices.Getter + static ClientNetworkBridge get() { + return Services.load(ClientNetworkBridge.class); + } +} diff --git a/common/src/main/java/juuxel/adorn/client/FluidRenderingBridge.java b/common/src/main/java/juuxel/adorn/client/FluidRenderingBridge.java new file mode 100644 index 000000000..9ed3b709c --- /dev/null +++ b/common/src/main/java/juuxel/adorn/client/FluidRenderingBridge.java @@ -0,0 +1,33 @@ +package juuxel.adorn.client; + +import juuxel.adorn.fluid.FluidReference; +import juuxel.adorn.util.InlineServices; +import juuxel.adorn.util.Services; +import net.minecraft.client.item.TooltipContext; +import net.minecraft.client.texture.Sprite; +import net.minecraft.text.Text; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.BlockRenderView; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +@InlineServices +public interface FluidRenderingBridge { + @Nullable Sprite getStillSprite(FluidReference volume); + + int getColor(FluidReference volume, @Nullable BlockRenderView world, @Nullable BlockPos pos); + + default int getColor(FluidReference volume) { + return getColor(volume, null, null); + } + + boolean fillsFromTop(FluidReference volume); + + List getTooltip(FluidReference volume, TooltipContext context, @Nullable Integer maxAmountInLitres); + + @InlineServices.Getter + static FluidRenderingBridge get() { + return Services.load(FluidRenderingBridge.class); + } +} diff --git a/common/src/main/java/juuxel/adorn/client/gui/screen/PalettedMenuScreen.java b/common/src/main/java/juuxel/adorn/client/gui/screen/PalettedMenuScreen.java index 91eb0d41b..d0ecc9dbb 100644 --- a/common/src/main/java/juuxel/adorn/client/gui/screen/PalettedMenuScreen.java +++ b/common/src/main/java/juuxel/adorn/client/gui/screen/PalettedMenuScreen.java @@ -25,7 +25,7 @@ public PalettedMenuScreen(M menu, PlayerInventory playerInventory, Text title) { protected abstract Identifier getPaletteId(); private ColorManager.ColorPair getPalette() { - return PlatformBridges.Companion.getResources().getColorManager().getColors(getPaletteId()).get(blockId); + return PlatformBridges.get().getResources().getColorManager().getColors(getPaletteId()).get(blockId); } @Override diff --git a/common/src/main/java/juuxel/adorn/entity/AdornEntities.java b/common/src/main/java/juuxel/adorn/entity/AdornEntities.java index 6df025b60..32a8e43d2 100644 --- a/common/src/main/java/juuxel/adorn/entity/AdornEntities.java +++ b/common/src/main/java/juuxel/adorn/entity/AdornEntities.java @@ -11,7 +11,7 @@ public final class AdornEntities { public static final Registrar> ENTITIES = RegistrarFactory.get().create(RegistryKeys.ENTITY_TYPE); public static final Registered> SEAT = - ENTITIES.register("seat", PlatformBridges.Companion.getEntities()::createSeatType); + ENTITIES.register("seat", PlatformBridges.get().getEntities()::createSeatType); public static void init() { } diff --git a/common/src/main/java/juuxel/adorn/entity/SeatEntity.java b/common/src/main/java/juuxel/adorn/entity/SeatEntity.java index 963229eac..51f0ad165 100644 --- a/common/src/main/java/juuxel/adorn/entity/SeatEntity.java +++ b/common/src/main/java/juuxel/adorn/entity/SeatEntity.java @@ -59,7 +59,7 @@ protected void removePassenger(Entity passenger) { public void kill() { removeAllPassengers(); if (!getWorld().isClient) { - PlatformBridges.Companion.getNetwork().sendToTracking(this, new EntityPassengersSetS2CPacket(this)); + PlatformBridges.get().getNetwork().sendToTracking(this, new EntityPassengersSetS2CPacket(this)); } super.kill(); var state = getWorld().getBlockState(seatPos); diff --git a/common/src/main/java/juuxel/adorn/item/AdornBookItem.java b/common/src/main/java/juuxel/adorn/item/AdornBookItem.java index b1f0cbc21..f958d74c8 100644 --- a/common/src/main/java/juuxel/adorn/item/AdornBookItem.java +++ b/common/src/main/java/juuxel/adorn/item/AdornBookItem.java @@ -27,7 +27,7 @@ public AdornBookItem(Identifier bookId, Settings settings) { @Override public TypedActionResult use(World world, PlayerEntity user, Hand hand) { if (!world.isClient) { - PlatformBridges.Companion.getNetwork().sendOpenBookPacket(user, bookId); + PlatformBridges.get().getNetwork().sendOpenBookPacket(user, bookId); } user.incrementStat(Stats.USED.getOrCreateStat(this)); @@ -37,7 +37,7 @@ public TypedActionResult use(World world, PlayerEntity user, Hand han @Override public void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context) { super.appendTooltip(stack, world, tooltip, context); - var bookManager = PlatformBridges.Companion.getResources().getBookManager(); + var bookManager = PlatformBridges.get().getResources().getBookManager(); if (bookManager.contains(bookId)) { tooltip.add(Text.translatable("book.byAuthor", bookManager.get(bookId).author()).formatted(Formatting.GRAY)); } diff --git a/common/src/main/java/juuxel/adorn/menu/AdornMenus.java b/common/src/main/java/juuxel/adorn/menu/AdornMenus.java index 8d366c9f8..cae57b2b0 100644 --- a/common/src/main/java/juuxel/adorn/menu/AdornMenus.java +++ b/common/src/main/java/juuxel/adorn/menu/AdornMenus.java @@ -3,12 +3,10 @@ import juuxel.adorn.lib.registry.Registered; import juuxel.adorn.lib.registry.Registrar; import juuxel.adorn.lib.registry.RegistrarFactory; +import juuxel.adorn.platform.MenuBridge; import juuxel.adorn.platform.PlatformBridges; -import kotlin.jvm.functions.Function3; -import net.minecraft.entity.player.PlayerInventory; import net.minecraft.menu.Menu; import net.minecraft.menu.MenuType; -import net.minecraft.network.PacketByteBuf; import net.minecraft.registry.RegistryKeys; import net.minecraft.resource.featuretoggle.FeatureFlags; @@ -26,7 +24,7 @@ public final class AdornMenus { public static void init() { } - private static MenuType createType(Function3 factory) { - return PlatformBridges.Companion.getMenus().createType(factory); + private static MenuType createType(MenuBridge.Factory factory) { + return PlatformBridges.get().getMenus().createType(factory); } } diff --git a/common/src/main/java/juuxel/adorn/menu/BrewerMenu.java b/common/src/main/java/juuxel/adorn/menu/BrewerMenu.java index 8dc6f5064..06bc6493d 100644 --- a/common/src/main/java/juuxel/adorn/menu/BrewerMenu.java +++ b/common/src/main/java/juuxel/adorn/menu/BrewerMenu.java @@ -117,7 +117,7 @@ public void sendContentUpdates() { var last = lastFluid; if (last == null || !FluidReference.areFluidsAndAmountsEqual(fluid, last)) { lastFluid = fluid.createSnapshot(); - PlatformBridges.Companion.getNetwork().sendBrewerFluidSync(player, syncId, fluid); + PlatformBridges.get().getNetwork().sendBrewerFluidSync(player, syncId, fluid); } } diff --git a/common/src/main/java/juuxel/adorn/platform/BlockEntityBridge.java b/common/src/main/java/juuxel/adorn/platform/BlockEntityBridge.java new file mode 100644 index 000000000..f831c7419 --- /dev/null +++ b/common/src/main/java/juuxel/adorn/platform/BlockEntityBridge.java @@ -0,0 +1,11 @@ +package juuxel.adorn.platform; + +import juuxel.adorn.block.entity.BrewerBlockEntity; +import juuxel.adorn.block.entity.KitchenSinkBlockEntity; +import net.minecraft.block.BlockState; +import net.minecraft.util.math.BlockPos; + +public interface BlockEntityBridge { + BrewerBlockEntity createBrewer(BlockPos pos, BlockState state); + KitchenSinkBlockEntity createKitchenSink(BlockPos pos, BlockState state); +} diff --git a/common/src/main/java/juuxel/adorn/platform/BlockFactory.java b/common/src/main/java/juuxel/adorn/platform/BlockFactory.java new file mode 100644 index 000000000..c555549a6 --- /dev/null +++ b/common/src/main/java/juuxel/adorn/platform/BlockFactory.java @@ -0,0 +1,12 @@ +package juuxel.adorn.platform; + +import juuxel.adorn.block.SofaBlock; +import juuxel.adorn.block.variant.BlockVariant; + +public interface BlockFactory { + BlockFactory DEFAULT = new BlockFactory() {}; + + default SofaBlock createSofa(BlockVariant variant) { + return new SofaBlock(variant); + } +} diff --git a/common/src/main/java/juuxel/adorn/platform/EntityBridge.java b/common/src/main/java/juuxel/adorn/platform/EntityBridge.java new file mode 100644 index 000000000..c591ed402 --- /dev/null +++ b/common/src/main/java/juuxel/adorn/platform/EntityBridge.java @@ -0,0 +1,8 @@ +package juuxel.adorn.platform; + +import juuxel.adorn.entity.SeatEntity; +import net.minecraft.entity.EntityType; + +public interface EntityBridge { + EntityType createSeatType(); +} diff --git a/common/src/main/java/juuxel/adorn/platform/FluidBridge.java b/common/src/main/java/juuxel/adorn/platform/FluidBridge.java new file mode 100644 index 000000000..0760bd31e --- /dev/null +++ b/common/src/main/java/juuxel/adorn/platform/FluidBridge.java @@ -0,0 +1,25 @@ +package juuxel.adorn.platform; + +import juuxel.adorn.fluid.FluidAmountPredicate; +import juuxel.adorn.fluid.FluidUnit; +import juuxel.adorn.fluid.FluidVolume; +import juuxel.adorn.util.InlineServices; +import juuxel.adorn.util.Services; +import net.minecraft.block.BlockState; +import net.minecraft.fluid.Fluid; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.World; +import org.jetbrains.annotations.Nullable; + +@InlineServices +public interface FluidBridge { + FluidUnit getFluidUnit(); + + @Nullable FluidVolume drain(World world, BlockPos pos, @Nullable BlockState state, Direction side, Fluid fluid, FluidAmountPredicate amountPredicate); + + @InlineServices.Getter + static FluidBridge get() { + return Services.load(FluidBridge.class); + } +} diff --git a/common/src/main/java/juuxel/adorn/platform/MenuBridge.java b/common/src/main/java/juuxel/adorn/platform/MenuBridge.java new file mode 100644 index 000000000..6195c76e1 --- /dev/null +++ b/common/src/main/java/juuxel/adorn/platform/MenuBridge.java @@ -0,0 +1,25 @@ +package juuxel.adorn.platform; + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.menu.Menu; +import net.minecraft.menu.MenuType; +import net.minecraft.menu.NamedMenuFactory; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.util.math.BlockPos; +import org.jetbrains.annotations.Nullable; + +public interface MenuBridge { + /** + * Opens a menu with a pos with the opening NBT sent to the client. + * Does nothing on the client. + */ + void open(PlayerEntity player, @Nullable NamedMenuFactory factory, BlockPos pos); + + MenuType createType(Factory factory); + + @FunctionalInterface + interface Factory { + M create(int syncId, PlayerInventory inventory, PacketByteBuf buf); + } +} diff --git a/common/src/main/java/juuxel/adorn/platform/NetworkBridge.java b/common/src/main/java/juuxel/adorn/platform/NetworkBridge.java new file mode 100644 index 000000000..0073b26eb --- /dev/null +++ b/common/src/main/java/juuxel/adorn/platform/NetworkBridge.java @@ -0,0 +1,22 @@ +package juuxel.adorn.platform; + +import juuxel.adorn.fluid.FluidReference; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.network.packet.Packet; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.Identifier; + +public interface NetworkBridge { + void sendToTracking(Entity entity, Packet packet); + void sendOpenBookPacket(PlayerEntity player, Identifier bookId); + void sendBrewerFluidSync(PlayerEntity player, int syncId, FluidReference fluid); + + default void syncBlockEntity(BlockEntity be) { + if (!(be.getWorld() instanceof ServerWorld world)) { + throw new IllegalStateException("[Adorn] Block entities cannot be synced client->server"); + } + world.getChunkManager().markForUpdate(be.getPos()); + } +} diff --git a/common/src/main/java/juuxel/adorn/platform/PlatformBridges.java b/common/src/main/java/juuxel/adorn/platform/PlatformBridges.java new file mode 100644 index 000000000..bf1afba1e --- /dev/null +++ b/common/src/main/java/juuxel/adorn/platform/PlatformBridges.java @@ -0,0 +1,19 @@ +package juuxel.adorn.platform; + +import juuxel.adorn.util.InlineServices; +import juuxel.adorn.util.Services; + +@InlineServices +public interface PlatformBridges { + BlockEntityBridge getBlockEntities(); + BlockFactory getBlockFactory(); + EntityBridge getEntities(); + MenuBridge getMenus(); + NetworkBridge getNetwork(); + ResourceBridge getResources(); + + @InlineServices.Getter + static PlatformBridges get() { + return Services.load(PlatformBridges.class); + } +} diff --git a/common/src/main/java/juuxel/adorn/platform/ResourceBridge.java b/common/src/main/java/juuxel/adorn/platform/ResourceBridge.java new file mode 100644 index 000000000..6c8b2c787 --- /dev/null +++ b/common/src/main/java/juuxel/adorn/platform/ResourceBridge.java @@ -0,0 +1,9 @@ +package juuxel.adorn.platform; + +import juuxel.adorn.client.book.BookManager; +import juuxel.adorn.client.resources.ColorManager; + +public interface ResourceBridge { + BookManager getBookManager(); + ColorManager getColorManager(); +} diff --git a/common/src/main/kotlin/juuxel/adorn/client/ClientNetworkBridge.kt b/common/src/main/kotlin/juuxel/adorn/client/ClientNetworkBridge.kt deleted file mode 100644 index 4709e9b07..000000000 --- a/common/src/main/kotlin/juuxel/adorn/client/ClientNetworkBridge.kt +++ /dev/null @@ -1,17 +0,0 @@ -package juuxel.adorn.client - -import juuxel.adorn.util.InlineServices -import juuxel.adorn.util.loadService -import net.minecraft.item.ItemStack - -interface ClientNetworkBridge { - fun sendSetTradeStack(syncId: Int, slotId: Int, stack: ItemStack) - - @InlineServices - companion object { - private val instance: ClientNetworkBridge by lazy { loadService() } - - @JvmStatic - fun get(): ClientNetworkBridge = instance - } -} diff --git a/common/src/main/kotlin/juuxel/adorn/client/ClientPlatformBridges.kt b/common/src/main/kotlin/juuxel/adorn/client/ClientPlatformBridges.kt deleted file mode 100644 index 6361cc1a0..000000000 --- a/common/src/main/kotlin/juuxel/adorn/client/ClientPlatformBridges.kt +++ /dev/null @@ -1,14 +0,0 @@ -package juuxel.adorn.client - -import juuxel.adorn.util.InlineServices -import juuxel.adorn.util.loadService - -interface ClientPlatformBridges { - val fluidRendering: FluidRenderingBridge - - @InlineServices - companion object { - private val instance: ClientPlatformBridges by lazy { loadService() } - fun get(): ClientPlatformBridges = instance - } -} diff --git a/common/src/main/kotlin/juuxel/adorn/client/FluidRenderingBridge.kt b/common/src/main/kotlin/juuxel/adorn/client/FluidRenderingBridge.kt deleted file mode 100644 index 303ff84f5..000000000 --- a/common/src/main/kotlin/juuxel/adorn/client/FluidRenderingBridge.kt +++ /dev/null @@ -1,26 +0,0 @@ -package juuxel.adorn.client - -import juuxel.adorn.fluid.FluidReference -import net.minecraft.client.item.TooltipContext -import net.minecraft.client.texture.Sprite -import net.minecraft.text.Text -import net.minecraft.util.math.BlockPos -import net.minecraft.world.BlockRenderView - -interface FluidRenderingBridge { - fun getStillSprite(volume: FluidReference): Sprite? - - fun getColor(volume: FluidReference, world: BlockRenderView? = null, pos: BlockPos? = null): Int - - fun getColor(volume: FluidReference): Int = - getColor(volume, null, null) - - fun fillsFromTop(volume: FluidReference): Boolean - - fun getTooltip(volume: FluidReference, context: TooltipContext, maxAmountInLitres: Int?): List - - companion object { - @JvmStatic - fun get() = ClientPlatformBridges.get().fluidRendering - } -} diff --git a/common/src/main/kotlin/juuxel/adorn/platform/BlockEntityBridge.kt b/common/src/main/kotlin/juuxel/adorn/platform/BlockEntityBridge.kt deleted file mode 100644 index ccfa2ef41..000000000 --- a/common/src/main/kotlin/juuxel/adorn/platform/BlockEntityBridge.kt +++ /dev/null @@ -1,11 +0,0 @@ -package juuxel.adorn.platform - -import juuxel.adorn.block.entity.BrewerBlockEntity -import juuxel.adorn.block.entity.KitchenSinkBlockEntity -import net.minecraft.block.BlockState -import net.minecraft.util.math.BlockPos - -interface BlockEntityBridge { - fun createBrewer(pos: BlockPos, state: BlockState): BrewerBlockEntity - fun createKitchenSink(pos: BlockPos, state: BlockState): KitchenSinkBlockEntity -} diff --git a/common/src/main/kotlin/juuxel/adorn/platform/BlockFactory.kt b/common/src/main/kotlin/juuxel/adorn/platform/BlockFactory.kt deleted file mode 100644 index a956754ef..000000000 --- a/common/src/main/kotlin/juuxel/adorn/platform/BlockFactory.kt +++ /dev/null @@ -1,10 +0,0 @@ -package juuxel.adorn.platform - -import juuxel.adorn.block.SofaBlock -import juuxel.adorn.block.variant.BlockVariant - -interface BlockFactory { - fun createSofa(variant: BlockVariant): SofaBlock = SofaBlock(variant) - - companion object Default : BlockFactory -} diff --git a/common/src/main/kotlin/juuxel/adorn/platform/EntityBridge.kt b/common/src/main/kotlin/juuxel/adorn/platform/EntityBridge.kt deleted file mode 100644 index 9ec3bbb85..000000000 --- a/common/src/main/kotlin/juuxel/adorn/platform/EntityBridge.kt +++ /dev/null @@ -1,8 +0,0 @@ -package juuxel.adorn.platform - -import juuxel.adorn.entity.SeatEntity -import net.minecraft.entity.EntityType - -interface EntityBridge { - fun createSeatType(): EntityType -} diff --git a/common/src/main/kotlin/juuxel/adorn/platform/FluidBridge.kt b/common/src/main/kotlin/juuxel/adorn/platform/FluidBridge.kt deleted file mode 100644 index 702518a9e..000000000 --- a/common/src/main/kotlin/juuxel/adorn/platform/FluidBridge.kt +++ /dev/null @@ -1,26 +0,0 @@ -package juuxel.adorn.platform - -import juuxel.adorn.fluid.FluidAmountPredicate -import juuxel.adorn.fluid.FluidUnit -import juuxel.adorn.fluid.FluidVolume -import juuxel.adorn.util.InlineServices -import juuxel.adorn.util.loadService -import net.minecraft.block.BlockState -import net.minecraft.fluid.Fluid -import net.minecraft.util.math.BlockPos -import net.minecraft.util.math.Direction -import net.minecraft.world.World - -interface FluidBridge { - val fluidUnit: FluidUnit - - fun drain(world: World, pos: BlockPos, state: BlockState?, side: Direction, fluid: Fluid, amountPredicate: FluidAmountPredicate): FluidVolume? - - @InlineServices - companion object { - private val instance: FluidBridge by lazy { loadService() } - - @JvmStatic - fun get(): FluidBridge = instance - } -} diff --git a/common/src/main/kotlin/juuxel/adorn/platform/MenuBridge.kt b/common/src/main/kotlin/juuxel/adorn/platform/MenuBridge.kt deleted file mode 100644 index 4b29c125e..000000000 --- a/common/src/main/kotlin/juuxel/adorn/platform/MenuBridge.kt +++ /dev/null @@ -1,23 +0,0 @@ -package juuxel.adorn.platform - -import net.minecraft.entity.player.PlayerEntity -import net.minecraft.entity.player.PlayerInventory -import net.minecraft.menu.Menu -import net.minecraft.menu.MenuType -import net.minecraft.menu.NamedMenuFactory -import net.minecraft.network.PacketByteBuf -import net.minecraft.util.math.BlockPos - -interface MenuBridge { - // This is only needed because Forge wants to be special and have a custom opening method. - /** - * Opens a menu with a [pos] with the opening NBT sent to the client. - * Does nothing on the client. - * - * @param player the player opening the menu - * @param factory the menu factory - */ - fun open(player: PlayerEntity, factory: NamedMenuFactory?, pos: BlockPos) - - fun createType(factory: (syncId: Int, inventory: PlayerInventory, buf: PacketByteBuf) -> M): MenuType -} diff --git a/common/src/main/kotlin/juuxel/adorn/platform/NetworkBridge.kt b/common/src/main/kotlin/juuxel/adorn/platform/NetworkBridge.kt deleted file mode 100644 index 7376c234c..000000000 --- a/common/src/main/kotlin/juuxel/adorn/platform/NetworkBridge.kt +++ /dev/null @@ -1,22 +0,0 @@ -package juuxel.adorn.platform - -import juuxel.adorn.fluid.FluidReference -import net.minecraft.block.entity.BlockEntity -import net.minecraft.entity.Entity -import net.minecraft.entity.player.PlayerEntity -import net.minecraft.network.packet.Packet -import net.minecraft.server.world.ServerWorld -import net.minecraft.util.Identifier - -interface NetworkBridge { - fun sendToTracking(entity: Entity, packet: Packet<*>) - fun sendOpenBookPacket(player: PlayerEntity, bookId: Identifier) - fun sendBrewerFluidSync(player: PlayerEntity, syncId: Int, fluid: FluidReference) - - fun syncBlockEntity(be: BlockEntity) { - // Logic taken from Fabric API's BlockEntityClientSerializable.sync() - val world = be.world - if (world !is ServerWorld) throw IllegalStateException("[Adorn] Block entities cannot be synced client->server") - world.chunkManager.markForUpdate(be.pos) - } -} diff --git a/common/src/main/kotlin/juuxel/adorn/platform/PlatformBridges.kt b/common/src/main/kotlin/juuxel/adorn/platform/PlatformBridges.kt deleted file mode 100644 index 564f879be..000000000 --- a/common/src/main/kotlin/juuxel/adorn/platform/PlatformBridges.kt +++ /dev/null @@ -1,26 +0,0 @@ -package juuxel.adorn.platform - -import juuxel.adorn.util.InlineServices -import juuxel.adorn.util.loadService - -interface PlatformBridges { - val blockEntities: BlockEntityBridge - val blockFactory: BlockFactory - val entities: EntityBridge - val menus: MenuBridge - val network: NetworkBridge - val resources: ResourceBridge - - @InlineServices - companion object { - private val instance: PlatformBridges by lazy { loadService() } - fun get() = instance - - inline val blockEntities get() = get().blockEntities - inline val blockFactory get() = get().blockFactory - inline val entities get() = get().entities - inline val menus get() = get().menus - inline val network get() = get().network - inline val resources get() = get().resources - } -} diff --git a/common/src/main/kotlin/juuxel/adorn/platform/ResourceBridge.kt b/common/src/main/kotlin/juuxel/adorn/platform/ResourceBridge.kt deleted file mode 100644 index cb18cc09c..000000000 --- a/common/src/main/kotlin/juuxel/adorn/platform/ResourceBridge.kt +++ /dev/null @@ -1,9 +0,0 @@ -package juuxel.adorn.platform - -import juuxel.adorn.client.book.BookManager -import juuxel.adorn.client.resources.ColorManager - -interface ResourceBridge { - val bookManager: BookManager - val colorManager: ColorManager -} diff --git a/fabric/src/main/java/juuxel/adorn/client/ClientPlatformBridgesFabric.java b/fabric/src/main/java/juuxel/adorn/client/ClientPlatformBridgesFabric.java deleted file mode 100644 index 03b8749c8..000000000 --- a/fabric/src/main/java/juuxel/adorn/client/ClientPlatformBridgesFabric.java +++ /dev/null @@ -1,8 +0,0 @@ -package juuxel.adorn.client; - -public final class ClientPlatformBridgesFabric implements ClientPlatformBridges { - @Override - public FluidRenderingBridge getFluidRendering() { - return FluidRenderingBridgeFabric.INSTANCE; - } -} diff --git a/fabric/src/main/java/juuxel/adorn/platform/fabric/MenuBridgeImpl.java b/fabric/src/main/java/juuxel/adorn/platform/fabric/MenuBridgeImpl.java index e8af2f6e3..d9cbdfe59 100644 --- a/fabric/src/main/java/juuxel/adorn/platform/fabric/MenuBridgeImpl.java +++ b/fabric/src/main/java/juuxel/adorn/platform/fabric/MenuBridgeImpl.java @@ -2,7 +2,6 @@ import juuxel.adorn.platform.MenuBridge; import juuxel.adorn.util.Logging; -import kotlin.jvm.functions.Function3; import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory; import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerType; import net.minecraft.entity.player.PlayerEntity; @@ -52,7 +51,7 @@ public void writeScreenOpeningData(ServerPlayerEntity player, PacketByteBuf buf) } @Override - public MenuType createType(Function3 factory) { - return new ExtendedScreenHandlerType<>(factory::invoke); + public MenuType createType(Factory factory) { + return new ExtendedScreenHandlerType<>(factory::create); } } diff --git a/fabric/src/main/java/juuxel/adorn/platform/fabric/PlatformBridgesImpl.java b/fabric/src/main/java/juuxel/adorn/platform/fabric/PlatformBridgesImpl.java index 397cd9476..b29ebd3f2 100644 --- a/fabric/src/main/java/juuxel/adorn/platform/fabric/PlatformBridgesImpl.java +++ b/fabric/src/main/java/juuxel/adorn/platform/fabric/PlatformBridgesImpl.java @@ -16,7 +16,7 @@ public BlockEntityBridge getBlockEntities() { @Override public BlockFactory getBlockFactory() { - return BlockFactory.Default; + return BlockFactory.DEFAULT; } @Override diff --git a/fabric/src/main/resources/META-INF/services/juuxel.adorn.client.ClientPlatformBridges b/fabric/src/main/resources/META-INF/services/juuxel.adorn.client.ClientPlatformBridges deleted file mode 100644 index 9c8d89798..000000000 --- a/fabric/src/main/resources/META-INF/services/juuxel.adorn.client.ClientPlatformBridges +++ /dev/null @@ -1 +0,0 @@ -juuxel.adorn.client.ClientPlatformBridgesFabric diff --git a/fabric/src/main/resources/META-INF/services/juuxel.adorn.client.FluidRenderingBridge b/fabric/src/main/resources/META-INF/services/juuxel.adorn.client.FluidRenderingBridge new file mode 100644 index 000000000..c41d712c4 --- /dev/null +++ b/fabric/src/main/resources/META-INF/services/juuxel.adorn.client.FluidRenderingBridge @@ -0,0 +1 @@ +juuxel.adorn.client.FluidRenderingBridgeFabric diff --git a/forge/src/main/java/juuxel/adorn/platform/forge/MenuBridgeImpl.java b/forge/src/main/java/juuxel/adorn/platform/forge/MenuBridgeImpl.java index 8398e9e13..5a5db3466 100644 --- a/forge/src/main/java/juuxel/adorn/platform/forge/MenuBridgeImpl.java +++ b/forge/src/main/java/juuxel/adorn/platform/forge/MenuBridgeImpl.java @@ -2,13 +2,10 @@ import juuxel.adorn.platform.MenuBridge; import juuxel.adorn.util.Logging; -import kotlin.jvm.functions.Function3; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; import net.minecraft.menu.Menu; import net.minecraft.menu.MenuType; import net.minecraft.menu.NamedMenuFactory; -import net.minecraft.network.PacketByteBuf; import net.minecraft.util.math.BlockPos; import net.neoforged.neoforge.common.extensions.IMenuTypeExtension; import org.jetbrains.annotations.Nullable; @@ -29,7 +26,7 @@ public void open(PlayerEntity player, @Nullable NamedMenuFactory factory, BlockP } @Override - public MenuType createType(Function3 factory) { - return IMenuTypeExtension.create(factory::invoke); + public MenuType createType(Factory factory) { + return IMenuTypeExtension.create(factory::create); } } diff --git a/forge/src/main/java/juuxel/adorn/platform/forge/client/AdornClient.java b/forge/src/main/java/juuxel/adorn/platform/forge/client/AdornClient.java index 1e1bf5347..7c90b6eb8 100644 --- a/forge/src/main/java/juuxel/adorn/platform/forge/client/AdornClient.java +++ b/forge/src/main/java/juuxel/adorn/platform/forge/client/AdornClient.java @@ -21,8 +21,8 @@ public static void init(IEventBus modBus) { modBus.addListener(AdornRenderers::registerRenderers); modBus.addListener(AdornClient::registerTooltipComponent); var resourceManager = (ReloadableResourceManagerImpl) MinecraftClient.getInstance().getResourceManager(); - resourceManager.registerReloader(PlatformBridges.Companion.getResources().getBookManager()); - resourceManager.registerReloader(PlatformBridges.Companion.getResources().getColorManager()); + resourceManager.registerReloader(PlatformBridges.get().getResources().getBookManager()); + resourceManager.registerReloader(PlatformBridges.get().getResources().getColorManager()); ModLoadingContext.get().registerExtensionPoint( ConfigScreenHandler.ConfigScreenFactory.class, () -> new ConfigScreenHandler.ConfigScreenFactory((client, parent) -> new MainConfigScreen(parent)) @@ -38,6 +38,6 @@ private static void registerTooltipComponent(RegisterClientTooltipComponentFacto } public static void openBookScreen(Identifier bookId) { - MinecraftClient.getInstance().setScreen(new GuideBookScreen(PlatformBridges.Companion.getResources().getBookManager().get(bookId))); + MinecraftClient.getInstance().setScreen(new GuideBookScreen(PlatformBridges.get().getResources().getBookManager().get(bookId))); } } diff --git a/forge/src/main/java/juuxel/adorn/platform/forge/client/ClientPlatformBridgesForge.java b/forge/src/main/java/juuxel/adorn/platform/forge/client/ClientPlatformBridgesForge.java deleted file mode 100644 index 52c796e53..000000000 --- a/forge/src/main/java/juuxel/adorn/platform/forge/client/ClientPlatformBridgesForge.java +++ /dev/null @@ -1,11 +0,0 @@ -package juuxel.adorn.platform.forge.client; - -import juuxel.adorn.client.ClientPlatformBridges; -import juuxel.adorn.client.FluidRenderingBridge; - -public final class ClientPlatformBridgesForge implements ClientPlatformBridges { - @Override - public FluidRenderingBridge getFluidRendering() { - return FluidRenderingBridgeForge.INSTANCE; - } -} diff --git a/forge/src/main/resources/META-INF/services/juuxel.adorn.client.ClientPlatformBridges b/forge/src/main/resources/META-INF/services/juuxel.adorn.client.ClientPlatformBridges deleted file mode 100644 index a2e383ddb..000000000 --- a/forge/src/main/resources/META-INF/services/juuxel.adorn.client.ClientPlatformBridges +++ /dev/null @@ -1 +0,0 @@ -juuxel.adorn.platform.forge.client.ClientPlatformBridgesForge diff --git a/forge/src/main/resources/META-INF/services/juuxel.adorn.client.FluidRenderingBridge b/forge/src/main/resources/META-INF/services/juuxel.adorn.client.FluidRenderingBridge new file mode 100644 index 000000000..5c13a0382 --- /dev/null +++ b/forge/src/main/resources/META-INF/services/juuxel.adorn.client.FluidRenderingBridge @@ -0,0 +1 @@ +juuxel.adorn.platform.forge.client.FluidRenderingBridgeForge