From 4ad1bf2b9ffeedcd19f0ee7a443fb01d2bb9ea79 Mon Sep 17 00:00:00 2001 From: DenizD Date: Thu, 22 Sep 2022 14:12:59 +0200 Subject: [PATCH 001/228] Goodbye stinky --- .../9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e | 8 +- .../armor/smart_glasses_netherite.json | 34 ++++ .../{ar_goggles.json => smart_glasses.json} | 4 +- .../armor/smart_glasses_netherite.json | 12 ++ .../{ar_goggles.json => smart_glasses.json} | 2 +- .../AdvancedPeripherals.java | 19 +- .../client/ClientRegistry.java | 4 +- .../client/HudOverlayHandler.java | 44 ----- .../peripheral/ARControllerPeripheral.java | 169 ----------------- .../peripheral/SmartGlassesPeripheral.java | 19 ++ .../common/argoggles/ARRenderAction.java | 174 ------------------ .../common/argoggles/ARRenderHelper.java | 101 ---------- .../common/argoggles/RenderActionType.java | 30 --- .../common/blocks/PlayerDetectorBlock.java | 6 +- .../blocks/RedstoneIntegratorBlock.java | 8 +- .../blockentities/ARControllerEntity.java | 159 ---------------- .../blockentities/BlockReaderEntity.java | 4 +- .../blocks/blockentities/ChatBoxEnity.java | 4 +- .../blockentities/ColonyIntegratorEntity.java | 4 +- .../blockentities/EnergyDetectorEntity.java | 4 +- .../EnvironmentDetectorEntity.java | 4 +- .../blockentities/GeoScannerEntity.java | 4 +- .../blockentities/InventoryManagerEntity.java | 4 +- .../blocks/blockentities/MeBridgeEntity.java | 14 +- .../blockentities/NBTStorageEntity.java | 4 +- .../blockentities/PlayerDetectorEntity.java | 4 +- .../RedstoneIntegratorEntity.java | 4 +- .../blocks/blockentities/RsBridgeEntity.java | 4 +- .../SmartGlassesControllerEntity.java | 22 +++ .../configuration/PeripheralsConfig.java | 4 +- .../container/InventoryManagerContainer.java | 10 +- .../common/data/BlockLootTables.java | 6 +- .../common/data/DataGenerators.java | 4 +- .../common/data/PocketUpgradesProvider.java | 12 +- .../common/data/PoiTypeProvider.java | 4 +- .../common/data/RecipesProvider.java | 90 +++++---- .../common/data/TurtleUpgradesProvider.java | 26 +-- .../common/events/Events.java | 15 -- .../common/items/ARGogglesItem.java | 115 ------------ .../common/items/SmartGlassesItem.java | 28 +++ .../common/items/WeakAutomataCore.java | 6 +- .../common/network/PacketHandler.java | 65 +++++++ .../common/network/base/IPacket.java | 20 ++ .../common/setup/APBlockEntityTypes.java | 40 ++++ .../common/setup/APBlocks.java | 54 ++++++ ...tainerTypes.java => APContainerTypes.java} | 4 +- .../common/setup/APItems.java | 40 ++++ ...{Registration.java => APRegistration.java} | 12 +- .../common/setup/APVillagers.java | 20 ++ .../common/setup/BlockEntityTypes.java | 28 --- .../common/setup/Blocks.java | 54 ------ .../common/setup/CCRegistration.java | 54 ++++-- .../common/setup/Items.java | 37 ---- .../common/setup/Villagers.java | 20 -- .../common/village/VillagerTrades.java | 32 ++-- .../advancedperipherals/network/MNetwork.java | 64 ------- .../messages/ClearHudCanvasMessage.java | 27 --- .../messages/RequestHudCanvasMessage.java | 56 ------ .../messages/UpdateHudCanvasMessage.java | 64 ------- 59 files changed, 557 insertions(+), 1327 deletions(-) create mode 100644 src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/armor/smart_glasses_netherite.json rename src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/{ar_goggles.json => smart_glasses.json} (84%) create mode 100644 src/generated/resources/data/advancedperipherals/recipes/armor/smart_glasses_netherite.json rename src/generated/resources/data/advancedperipherals/recipes/{ar_goggles.json => smart_glasses.json} (84%) delete mode 100644 src/main/java/de/srendi/advancedperipherals/client/HudOverlayHandler.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ARControllerPeripheral.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/SmartGlassesPeripheral.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/argoggles/ARRenderAction.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/argoggles/ARRenderHelper.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/argoggles/RenderActionType.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/ARControllerEntity.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/SmartGlassesControllerEntity.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/items/ARGogglesItem.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/network/PacketHandler.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/network/base/IPacket.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java rename src/main/java/de/srendi/advancedperipherals/common/setup/{ContainerTypes.java => APContainerTypes.java} (77%) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java rename src/main/java/de/srendi/advancedperipherals/common/setup/{Registration.java => APRegistration.java} (92%) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/setup/APVillagers.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/setup/BlockEntityTypes.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/setup/Blocks.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/setup/Items.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/setup/Villagers.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/network/MNetwork.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/network/messages/ClearHudCanvasMessage.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/network/messages/RequestHudCanvasMessage.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/network/messages/UpdateHudCanvasMessage.java diff --git a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e index 5875344e8..e8bb7ec6b 100644 --- a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e +++ b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e @@ -1,6 +1,6 @@ -// 1.19.2 2022-09-18T21:59:59.2591286 Recipes +// 1.19.2 2022-09-22T14:09:48.8685449 Recipes +045608027e4a5ea2d7dee7f402346b8e69f21675 data/advancedperipherals/advancements/recipes/advancedperipheralstab/armor/smart_glasses_netherite.json f472724394edd655a415d4af08c9a63509cc5098 data/advancedperipherals/advancements/recipes/advancedperipheralstab/ar_controller.json -777d312501095906ec663c4e7cca3fe3a3d1ff63 data/advancedperipherals/advancements/recipes/advancedperipheralstab/ar_goggles.json db2dada2fdf42ca1bbf47f1eb075d1f9de89dfa8 data/advancedperipherals/advancements/recipes/advancedperipheralstab/block_reader.json 77c55e8500be4a344ca563a8bf7642257cdc7b8b data/advancedperipherals/advancements/recipes/advancedperipheralstab/chat_box.json 96208b06b0c3c125762cd517506a5ffb6b1d55ac data/advancedperipherals/advancements/recipes/advancedperipheralstab/chunk_controller.json @@ -17,9 +17,10 @@ d3d8709f4fdb3d68613d751bba5b9a94b8842046 data/advancedperipherals/advancements/r d27c1267208fd9036c5c45f7f6cbd4f6f67b3845 data/advancedperipherals/advancements/recipes/advancedperipheralstab/peripheral_casing.json d8870644bb7d48c5ae33dcea2afbcfa106729d7b data/advancedperipherals/advancements/recipes/advancedperipheralstab/player_detector.json 7acff70533792bd089a655f8f24cdea6995aac0c data/advancedperipherals/advancements/recipes/advancedperipheralstab/redstone_integrator.json +c0373a4597bfbd9b005cbe0a6289779ffd4053ea data/advancedperipherals/advancements/recipes/advancedperipheralstab/smart_glasses.json fc0c3d99bec43318802f357083c7d98fde92567f data/advancedperipherals/advancements/recipes/advancedperipheralstab/weak_automata_core.json +66999fea36aa4113567753f104630f6490dda6ba data/advancedperipherals/recipes/armor/smart_glasses_netherite.json 6396232db4a526763d5b6625572677d7e8fc001e data/advancedperipherals/recipes/ar_controller.json -f344ecef134128c7835d3e9765db5b2723061797 data/advancedperipherals/recipes/ar_goggles.json b10b5cbcc668438001744d5b90d9838ab4d293cb data/advancedperipherals/recipes/block_reader.json 3c9618832fe0ac32cac0f04fbc5afad225418239 data/advancedperipherals/recipes/chat_box.json a78adfcca4c7579b143aac5648a7eca9085c0dba data/advancedperipherals/recipes/chunk_controller.json @@ -36,4 +37,5 @@ ebe70aa9fe80c5b962c13aa1fbadc32269ba81b9 data/advancedperipherals/recipes/invent a91556eb09a2a8c57b323928a76095a4b17241b7 data/advancedperipherals/recipes/peripheral_casing.json 1d476bfb11dcf490cefa9916695d91aec0cc8a19 data/advancedperipherals/recipes/player_detector.json 110983bae78f033dc8b12fd04ba3b7edcf035237 data/advancedperipherals/recipes/redstone_integrator.json +7008b3421135b3150e8c7e509166498a2b2df131 data/advancedperipherals/recipes/smart_glasses.json 7c783b341e783b22be4e40efbe3c88947e1902ec data/advancedperipherals/recipes/weak_automata_core.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/armor/smart_glasses_netherite.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/armor/smart_glasses_netherite.json new file mode 100644 index 000000000..bb6e067ec --- /dev/null +++ b/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/armor/smart_glasses_netherite.json @@ -0,0 +1,34 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_item": { + "conditions": { + "items": [ + { + "items": [ + "minecraft:netherite_ingot" + ] + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "advancedperipherals:armor/smart_glasses_netherite" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_item", + "has_the_recipe" + ] + ], + "rewards": { + "recipes": [ + "advancedperipherals:armor/smart_glasses_netherite" + ] + } +} \ No newline at end of file diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/ar_goggles.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/smart_glasses.json similarity index 84% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/ar_goggles.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/smart_glasses.json index 40db091d4..6d54b03bc 100644 --- a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/ar_goggles.json +++ b/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/smart_glasses.json @@ -15,7 +15,7 @@ }, "has_the_recipe": { "conditions": { - "recipe": "advancedperipherals:ar_goggles" + "recipe": "advancedperipherals:smart_glasses" }, "trigger": "minecraft:recipe_unlocked" } @@ -28,7 +28,7 @@ ], "rewards": { "recipes": [ - "advancedperipherals:ar_goggles" + "advancedperipherals:smart_glasses" ] } } \ No newline at end of file diff --git a/src/generated/resources/data/advancedperipherals/recipes/armor/smart_glasses_netherite.json b/src/generated/resources/data/advancedperipherals/recipes/armor/smart_glasses_netherite.json new file mode 100644 index 000000000..e46b01d51 --- /dev/null +++ b/src/generated/resources/data/advancedperipherals/recipes/armor/smart_glasses_netherite.json @@ -0,0 +1,12 @@ +{ + "type": "minecraft:smithing", + "addition": { + "item": "minecraft:netherite_ingot" + }, + "base": { + "item": "advancedperipherals:smart_glasses" + }, + "result": { + "item": "advancedperipherals:smart_glasses_netherite" + } +} \ No newline at end of file diff --git a/src/generated/resources/data/advancedperipherals/recipes/ar_goggles.json b/src/generated/resources/data/advancedperipherals/recipes/smart_glasses.json similarity index 84% rename from src/generated/resources/data/advancedperipherals/recipes/ar_goggles.json rename to src/generated/resources/data/advancedperipherals/recipes/smart_glasses.json index 369697374..c61157990 100644 --- a/src/generated/resources/data/advancedperipherals/recipes/ar_goggles.json +++ b/src/generated/resources/data/advancedperipherals/recipes/smart_glasses.json @@ -16,6 +16,6 @@ " E " ], "result": { - "item": "advancedperipherals:ar_goggles" + "item": "advancedperipherals:smart_glasses" } } \ No newline at end of file diff --git a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java index 3a3440686..06d46fbf7 100644 --- a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java +++ b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java @@ -1,12 +1,11 @@ package de.srendi.advancedperipherals; -import de.srendi.advancedperipherals.client.HudOverlayHandler; import de.srendi.advancedperipherals.common.addons.refinedstorage.RefinedStorage; import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.setup.Blocks; -import de.srendi.advancedperipherals.common.setup.Registration; +import de.srendi.advancedperipherals.common.network.PacketHandler; +import de.srendi.advancedperipherals.common.setup.APBlocks; +import de.srendi.advancedperipherals.common.setup.APRegistration; import de.srendi.advancedperipherals.common.village.VillageStructures; -import de.srendi.advancedperipherals.network.MNetwork; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.ItemStack; import net.minecraftforge.common.MinecraftForge; @@ -16,7 +15,6 @@ import net.minecraftforge.fml.ModList; import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; @@ -39,7 +37,7 @@ public class AdvancedPeripherals { @Override @NotNull public ItemStack makeIcon() { - return new ItemStack(Blocks.CHAT_BOX.get()); + return new ItemStack(APBlocks.CHAT_BOX.get()); } }; @@ -54,8 +52,7 @@ public AdvancedPeripherals() { modBus.addListener(this::commonSetup); modBus.addListener(this::interModComms); - modBus.addListener(this::clientSetup); - Registration.register(); + APRegistration.register(); MinecraftForge.EVENT_BUS.register(this); //TODO: Refactor this to a dedicated class @@ -82,14 +79,10 @@ public static boolean isCuriosLoaded() { public void commonSetup(FMLCommonSetupEvent event) { event.enqueueWork(() -> { VillageStructures.init(); - MNetwork.init(); + PacketHandler.init(); }); } - public void clientSetup(FMLClientSetupEvent event) { - HudOverlayHandler.init(); - } - @SubscribeEvent public void interModComms(InterModEnqueueEvent event) { if (!curiosLoaded) return; diff --git a/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java b/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java index 69f85ac7c..a71a51a61 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java +++ b/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java @@ -4,8 +4,8 @@ import dan200.computercraft.api.client.turtle.TurtleUpgradeModeller; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.container.InventoryManagerScreen; +import de.srendi.advancedperipherals.common.setup.APContainerTypes; import de.srendi.advancedperipherals.common.setup.CCRegistration; -import de.srendi.advancedperipherals.common.setup.ContainerTypes; import net.minecraft.client.gui.screens.MenuScreens; import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.resources.ResourceLocation; @@ -39,7 +39,7 @@ public static void registerModels(ModelEvent.RegisterAdditional event) { @SubscribeEvent public static void onClientSetup(FMLClientSetupEvent event) { - MenuScreens.register(ContainerTypes.INVENTORY_MANAGER_CONTAINER.get(), InventoryManagerScreen::new); + MenuScreens.register(APContainerTypes.INVENTORY_MANAGER_CONTAINER.get(), InventoryManagerScreen::new); ComputerCraftAPIClient.registerTurtleUpgradeModeller(CCRegistration.CHUNKY_TURTLE.get(), TurtleUpgradeModeller.flatItem()); ComputerCraftAPIClient.registerTurtleUpgradeModeller(CCRegistration.COMPASS_TURTLE.get(), TurtleUpgradeModeller.flatItem()); diff --git a/src/main/java/de/srendi/advancedperipherals/client/HudOverlayHandler.java b/src/main/java/de/srendi/advancedperipherals/client/HudOverlayHandler.java deleted file mode 100644 index ffd79ec58..000000000 --- a/src/main/java/de/srendi/advancedperipherals/client/HudOverlayHandler.java +++ /dev/null @@ -1,44 +0,0 @@ -package de.srendi.advancedperipherals.client; - -import de.srendi.advancedperipherals.common.argoggles.ARRenderAction; -import net.minecraftforge.common.MinecraftForge; - -import java.util.ArrayList; -import java.util.List; - -public class HudOverlayHandler { - private static HudOverlayHandler instance; - private final List canvas = new ArrayList<>(); - - public static void init() { - instance = new HudOverlayHandler(); - MinecraftForge.EVENT_BUS.register(instance); - } - - public static HudOverlayHandler getInstance() { - return instance; - } - - public static void updateCanvas(List actions) { - if (instance == null) return; - instance.canvas.clear(); - instance.canvas.addAll(actions); - } - - public static void clearCanvas() { - if (instance == null) return; - instance.canvas.clear(); - } - - //TODO: Use the forge Overlay System instead - /*@SubscribeEvent(priority = EventPriority.LOWEST) - public void onRender(RenderGuiEvent.Post event) { - if (event.getWindow() == null) return; - Minecraft mc = Minecraft.getInstance(); - PoseStack matrixStack = event.getMatrixStack(); - for (ARRenderAction action : canvas) { - action.draw(mc, matrixStack, event.getWindow().getScreenWidth(), event.getWindow().getScreenHeight()); - } - RenderSystem.setShaderTexture(0, GuiComponent.GUI_ICONS_LOCATION); - }*/ -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ARControllerPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ARControllerPeripheral.java deleted file mode 100644 index 25c35b484..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ARControllerPeripheral.java +++ /dev/null @@ -1,169 +0,0 @@ -package de.srendi.advancedperipherals.common.addons.computercraft.peripheral; - -import dan200.computercraft.api.lua.LuaException; -import dan200.computercraft.api.lua.LuaFunction; -import dan200.computercraft.api.lua.MethodResult; -import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner; -import de.srendi.advancedperipherals.common.argoggles.ARRenderAction; -import de.srendi.advancedperipherals.common.argoggles.RenderActionType; -import de.srendi.advancedperipherals.common.blocks.blockentities.ARControllerEntity; -import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; - -import java.util.Optional; - -public class ARControllerPeripheral extends BasePeripheral> { - public static final String TYPE = "arController"; - - public ARControllerPeripheral(ARControllerEntity tileEntity) { - super(TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); - } - - @Override - public boolean isEnabled() { - return APConfig.PERIPHERALS_CONFIG.enableARGoggles.get(); - } - - @LuaFunction(mainThread = true) - public final MethodResult isRelativeMode() { - int[] virtualScreenSize = owner.tileEntity.getVirtualScreenSize(); - if (virtualScreenSize != null) { - return MethodResult.of(owner.tileEntity.isRelativeMode(), virtualScreenSize[0], virtualScreenSize[1]); - } else { - return MethodResult.of(owner.tileEntity.isRelativeMode()); - } - } - - @LuaFunction(mainThread = true) - public final void setRelativeMode(boolean enabled, Optional virtualScreenWidth, Optional virtualScreenHeight) throws LuaException { - if (enabled) { - if (!virtualScreenWidth.isPresent() || !virtualScreenHeight.isPresent()) - throw new LuaException("You need to pass virtual screen width and height to enable relative mode."); - owner.tileEntity.setRelativeMode(virtualScreenWidth.get(), virtualScreenHeight.get()); - } else { - owner.tileEntity.disableRelativeMode(); - } - } - - @LuaFunction(mainThread = true) - public final void drawString(String text, int x, int y, int color) { - owner.tileEntity.addToCanvas(new ARRenderAction(RenderActionType.DRAW_STRING, text, x, y, color)); - } - - @LuaFunction(mainThread = true) - public final void drawStringWithId(String id, String text, int x, int y, int color) { - owner.tileEntity.addToCanvas(new ARRenderAction(id, RenderActionType.DRAW_STRING, text, x, y, color)); - } - - @LuaFunction(mainThread = true) - public final void drawCenteredString(String text, int x, int y, int color) { - owner.tileEntity.addToCanvas(new ARRenderAction(RenderActionType.DRAW_CENTERED_STRING, text, x, y, color)); - } - - @LuaFunction(mainThread = true) - public final void drawCenteredStringWithId(String id, String text, int x, int y, int color) { - owner.tileEntity.addToCanvas(new ARRenderAction(id, RenderActionType.DRAW_CENTERED_STRING, text, x, y, color)); - } - - @LuaFunction(mainThread = true) - public final void drawRightboundString(String text, int x, int y, int color) { - owner.tileEntity.addToCanvas(new ARRenderAction(RenderActionType.DRAW_RIGHTBOUND_STRING, text, x, y, color)); - } - - @LuaFunction(mainThread = true) - public final void drawRightboundStringWithId(String id, String text, int x, int y, int color) { - owner.tileEntity.addToCanvas(new ARRenderAction(id, RenderActionType.DRAW_RIGHTBOUND_STRING, text, x, y, color)); - } - - @LuaFunction(mainThread = true) - public final void horizontalLine(int minX, int maxX, int y, int color) { - owner.tileEntity.addToCanvas(new ARRenderAction(RenderActionType.HORIZONTAL_LINE, minX, maxX, y, color)); - } - - @LuaFunction(mainThread = true) - public final void horizontalLineWithId(String id, int minX, int maxX, int y, int color) { - owner.tileEntity.addToCanvas(new ARRenderAction(id, RenderActionType.HORIZONTAL_LINE, minX, maxX, y, color)); - } - - @LuaFunction(mainThread = true) - public final void verticalLine(int x, int minY, int maxY, int color) { - owner.tileEntity.addToCanvas(new ARRenderAction(RenderActionType.VERTICAL_LINE, x, minY, maxY, color)); - } - - @LuaFunction(mainThread = true) - public final void verticalLineWithId(String id, int x, int minY, int maxY, int color) { - owner.tileEntity.addToCanvas(new ARRenderAction(id, RenderActionType.VERTICAL_LINE, x, minY, maxY, color)); - } - - @LuaFunction(mainThread = true) - public final void fill(int minX, int minY, int maxX, int maxY, int color) { - owner.tileEntity.addToCanvas(new ARRenderAction(RenderActionType.FILL, minX, minY, maxX, maxY, color)); - } - - @LuaFunction(mainThread = true) - public final void fillWithId(String id, int minX, int minY, int maxX, int maxY, int color) { - owner.tileEntity.addToCanvas(new ARRenderAction(id, RenderActionType.FILL, minX, minY, maxX, maxY, color)); - } - - @LuaFunction(mainThread = true) - public final void fillGradient(int minX, int minY, int maxX, int maxY, int colorFrom, int colorTo) { - owner.tileEntity.addToCanvas(new ARRenderAction(RenderActionType.FILL_GRADIENT, minX, minY, maxX, maxY, colorFrom, colorTo)); - } - - @LuaFunction(mainThread = true) - public final void fillGradientWithId(String id, int minX, int minY, int maxX, int maxY, int colorFrom, int colorTo) { - owner.tileEntity.addToCanvas(new ARRenderAction(id, RenderActionType.FILL_GRADIENT, minX, minY, maxX, maxY, colorFrom, colorTo)); - } - - @LuaFunction(mainThread = true) - public final void drawCircle(int x, int y, int radius, int color) { - owner.tileEntity.addToCanvas(new ARRenderAction(RenderActionType.DRAW_CIRCLE, x, y, radius, color)); - } - - @LuaFunction(mainThread = true) - public final void drawCircleWithId(String id, int x, int y, int radius, int color) { - owner.tileEntity.addToCanvas(new ARRenderAction(id, RenderActionType.DRAW_CIRCLE, x, y, radius, color)); - } - - @LuaFunction(mainThread = true) - public final void fillCircle(int x, int y, int radius, int color) { - owner.tileEntity.addToCanvas(new ARRenderAction(RenderActionType.FILL_CIRCLE, x, y, radius, color)); - } - - @LuaFunction(mainThread = true) - public final void fillCircleWithId(String id, int x, int y, int radius, int color) { - owner.tileEntity.addToCanvas(new ARRenderAction(id, RenderActionType.FILL_CIRCLE, x, y, radius, color)); - } - - @LuaFunction(mainThread = true) - public final void drawItemIcon(String itemId, int x, int y) { - owner.tileEntity.addToCanvas(new ARRenderAction(RenderActionType.DRAW_ITEM_ICON, itemId, x, y)); - } - - @LuaFunction(mainThread = true) - public final void drawItemIconWithId(String id, String itemId, int x, int y) { - owner.tileEntity.addToCanvas(new ARRenderAction(id, RenderActionType.DRAW_ITEM_ICON, itemId, x, y)); - } - - @LuaFunction(mainThread = true) - public final void clear() { - owner.tileEntity.clearCanvas(); - } - - @LuaFunction(mainThread = true) - public final void clearElement(String id) { - owner.tileEntity.clearElement(id); - } - - //TODO - 0.8r: These two functions do not work. This has several reasons. https://github.com/Seniorendi/AdvancedPeripherals/issues/307 - //Returning 0 instead of crashing - @LuaFunction(mainThread = true) - public final float getPlayerRotationY() { - return 0; - } - - @LuaFunction(mainThread = true) - public final float getPlayerRotationZ() { - return 0; - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/SmartGlassesPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/SmartGlassesPeripheral.java new file mode 100644 index 000000000..73b327bea --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/SmartGlassesPeripheral.java @@ -0,0 +1,19 @@ +package de.srendi.advancedperipherals.common.addons.computercraft.peripheral; + +import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner; +import de.srendi.advancedperipherals.common.blocks.blockentities.SmartGlassesControllerEntity; +import de.srendi.advancedperipherals.common.configuration.APConfig; +import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; + +public class SmartGlassesPeripheral extends BasePeripheral> { + + public SmartGlassesPeripheral(SmartGlassesControllerEntity tileEntity) { + super("smartglasses", new BlockEntityPeripheralOwner<>(tileEntity)); + } + + @Override + public boolean isEnabled() { + return APConfig.PERIPHERALS_CONFIG.enableSmartGlasses.get(); + } + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/argoggles/ARRenderAction.java b/src/main/java/de/srendi/advancedperipherals/common/argoggles/ARRenderAction.java deleted file mode 100644 index cc4bb693e..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/argoggles/ARRenderAction.java +++ /dev/null @@ -1,174 +0,0 @@ -package de.srendi.advancedperipherals.common.argoggles; - -import net.minecraft.nbt.CompoundTag; -import net.minecraftforge.common.util.INBTSerializable; - -import java.util.Arrays; -import java.util.Objects; -import java.util.Optional; - -public final class ARRenderAction implements INBTSerializable { - - private static final String TYPE = "type"; - private static final String STRING_ARG = "string_arg"; - private static final String INT_ARGS = "int_args"; - private static final String VIRTUAL_SCREEN_SIZE = "virtualScreenSize"; - - private String id; - private RenderActionType type; - private String stringArg = ""; - private int[] intArgs = new int[0]; - private Optional virtualScreenSize = Optional.empty(); - - public ARRenderAction() { - - } - - public ARRenderAction(String id, RenderActionType type, int... intArgs) { - this(); - this.id = id; - this.type = type; - this.intArgs = intArgs; - } - - public ARRenderAction(RenderActionType type, int... intArgs) { - this(null, type, intArgs); - } - - public ARRenderAction(RenderActionType type, String stringArg, int... intArgs) { - this(null, type, stringArg, intArgs); - } - - public ARRenderAction(String id, RenderActionType type, String stringArg, int... intArgs) { - this(id, type, intArgs); - this.stringArg = stringArg; - } - - public static ARRenderAction deserialize(CompoundTag nbt) { - ARRenderAction action = new ARRenderAction(); - action.deserializeNBT(nbt); - return action; - } - - public String getId() { - return id; - } - - /*public void draw(Minecraft mc, PoseStack matrixStack, int w, int h) { - if (!type.ensureArgs(intArgs)) return; - int[] i = intArgs; - switch (type) { - case DRAW_CENTERED_STRING: - ARRenderHelper.drawCenteredString(matrixStack, mc.font, stringArg, relativeX(i[0], w), relativeY(i[1], h), i[2]); - break; - case DRAW_STRING: - ARRenderHelper.drawString(matrixStack, mc.font, stringArg, relativeX(i[0], w), relativeY(i[1], h), i[2]); - break; - case DRAW_RIGHTBOUND_STRING: - ARRenderHelper.drawRightboundString(matrixStack, mc.font, stringArg, relativeX(i[0], w), relativeY(i[1], h), i[2]); - break; - case FILL: - i[4] = ARRenderHelper.fixAlpha(i[4]); - ARRenderHelper.fill(matrixStack, relativeX(i[0], w), relativeY(i[1], h), relativeX(i[2], w), relativeY(i[3], h), i[4]); - break; - case HORIZONTAL_LINE: - ARRenderHelper.getInstance().hLine(matrixStack, relativeX(i[0], w), relativeX(i[1], w), relativeY(i[2], h), i[3]); - break; - case VERTICAL_LINE: - ARRenderHelper.getInstance().vLine(matrixStack, relativeX(i[0], w), relativeY(i[1], h), relativeY(i[2], h), i[3]); - break; - case FILL_GRADIENT: - ARRenderHelper.getInstance().fillGradient(matrixStack, relativeX(i[0], w), relativeY(i[1], h), relativeX(i[2], w), relativeY(i[3], h), i[4], i[5]); - break; - case DRAW_CIRCLE: - ARRenderHelper.getInstance().drawCircle(matrixStack, relativeX(i[0], w), relativeY(i[1], h), relativeAverage(i[2], w, h), i[3]); - break; - case FILL_CIRCLE: - ARRenderHelper.getInstance().fillCircle(matrixStack, relativeX(i[0], w), relativeY(i[1], h), relativeAverage(i[2], w, h), i[3]); - break; - case DRAW_ITEM_ICON: - ARRenderHelper.getInstance().drawItemIcon(matrixStack, mc.getItemRenderer(), stringArg, relativeX(i[0], w), relativeY(i[1], h)); - break; - default: - AdvancedPeripherals.LOGGER.warn("Failed to execute AR render action of unimplemented type " + type); - break; - } - }*/ - - private int relativeX(int x, int windowWidth) { - if (virtualScreenSize.isPresent()) { - x = x >= 0 ? x : virtualScreenSize.get()[0] + x; - return (int) Math.round((double) x / virtualScreenSize.get()[0] * windowWidth); - } else return x >= 0 ? x : windowWidth + x; - } - - private int relativeY(int y, int windowHeight) { - if (virtualScreenSize.isPresent()) { - y = y >= 0 ? y : virtualScreenSize.get()[1] + y; - return (int) Math.round((double) y / virtualScreenSize.get()[1] * windowHeight); - } else return y >= 0 ? y : windowHeight; - } - - private float relativeAverage(int i, int w, int h) { - if (virtualScreenSize.isPresent()) { - float xfactor = (float) w / virtualScreenSize.get()[0]; - float yfactor = (float) h / virtualScreenSize.get()[1]; - return i * (xfactor + yfactor) / 2; - } else return i; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof ARRenderAction renderAction) { - return type.equals(renderAction.type) && stringArg.equals(renderAction.stringArg) && Arrays.equals(intArgs, renderAction.intArgs); - } - return super.equals(obj); - } - - @Override - public int hashCode() { - int result = Objects.hash(id, type, stringArg, virtualScreenSize); - result = 31 * result + Arrays.hashCode(intArgs); - return result; - } - - @Override - public void deserializeNBT(CompoundTag nbt) { - int[] virtualScreenSizeFromNbt = nbt.getIntArray(VIRTUAL_SCREEN_SIZE); - - type = RenderActionType.valueOf(nbt.getString(TYPE)); - stringArg = nbt.getString(STRING_ARG); - intArgs = nbt.getIntArray(INT_ARGS); - virtualScreenSize = virtualScreenSizeFromNbt.length == 0 ? Optional.empty() : Optional.of(virtualScreenSizeFromNbt); - } - - @Override - public CompoundTag serializeNBT() { - CompoundTag nbt = new CompoundTag(); - nbt.putString(TYPE, type.toString()); - nbt.putString(STRING_ARG, stringArg); - nbt.putIntArray(INT_ARGS, intArgs); - nbt.putIntArray(VIRTUAL_SCREEN_SIZE, virtualScreenSize.orElse(new int[]{})); - return nbt; - } - - public int[] getVirtualScreenSize() { - if (virtualScreenSize.isPresent()) return virtualScreenSize.get(); - else return null; - } - - public void setRelativeMode(int virtualScreenWidth, int virtualScreenHeight) { - virtualScreenSize = Optional.of(new int[]{virtualScreenWidth, virtualScreenHeight}); - } - - public void disableRelativeMode() { - virtualScreenSize = Optional.empty(); - } - - public ARRenderAction copyWithVirtualScreenSize(Optional virtualScreenSize2) { - ARRenderAction action = new ARRenderAction(type, stringArg, intArgs); - if (virtualScreenSize2.isPresent()) - action.setRelativeMode(virtualScreenSize2.get()[0], virtualScreenSize2.get()[1]); - return action; - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/argoggles/ARRenderHelper.java b/src/main/java/de/srendi/advancedperipherals/common/argoggles/ARRenderHelper.java deleted file mode 100644 index 2598172b1..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/argoggles/ARRenderHelper.java +++ /dev/null @@ -1,101 +0,0 @@ -package de.srendi.advancedperipherals.common.argoggles; - -import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.client.gui.Font; -import net.minecraft.client.gui.GuiComponent; - -public class ARRenderHelper extends GuiComponent { - private static final ARRenderHelper INSTANCE = new ARRenderHelper(); - - public static void drawRightboundString(PoseStack matrixStack, Font fontRenderer, String text, int x, int y, int color) { - drawString(matrixStack, fontRenderer, text, x - fontRenderer.width(text), y, color); - } - - public static ARRenderHelper getInstance() { - return INSTANCE; - } - - /*public static int fixAlpha(int color) { - return (color & 0xFF000000) == 0 ? color | 0xFF000000 : color; - } - - @Override - public void hLine(@NotNull PoseStack matrixStack, int minX, int maxX, int y, int color) { - color = ARRenderHelper.fixAlpha(color); - super.hLine(matrixStack, minX, maxX, y, color); - } - - @Override - public void vLine(@NotNull PoseStack matrixStack, int x, int minY, int maxY, int color) { - color = ARRenderHelper.fixAlpha(color); - super.vLine(matrixStack, x, minY, maxY, color); - } - - @Override - protected void fillGradient(@NotNull PoseStack matrixStack, int x1, int y1, int x2, int y2, int colorFrom, int colorTo) { - colorFrom = ARRenderHelper.fixAlpha(colorFrom); - colorTo = ARRenderHelper.fixAlpha(colorTo); - super.fillGradient(matrixStack, x1, y1, x2, y2, colorFrom, colorTo); - } - - public void drawCircle(PoseStack matrixStack, int centerX, int centerY, float radius, int color) { - color = fixAlpha(color); - - final int nSegments = 360; - Matrix4f matrix = matrixStack.last().pose(); - - float z = this.getBlitOffset(); - float a = (float) (color >> 24 & 255) / 255.0F; - float r = (float) (color >> 16 & 255) / 255.0F; - float g = (float) (color >> 8 & 255) / 255.0F; - float b = (float) (color & 255) / 255.0F; - BufferBuilder bufferbuilder = Tesselator.getInstance().getBuilder(); - RenderSystem.enableBlend(); - RenderSystem.disableTexture(); - RenderSystem.defaultBlendFunc(); - bufferbuilder.begin(VertexFormat.Mode.LINES, DefaultVertexFormat.POSITION_COLOR); - for (int i = 0; i < nSegments; i++) { - double angle = 2 * Math.PI * i / nSegments; - float xd = (float) (radius * Math.sin(angle)); - float yd = (float) (radius * Math.cos(angle)); - bufferbuilder.vertex(matrix, centerX + xd, centerY + yd, z).color(r, g, b, a).endVertex(); - } - bufferbuilder.end(); - BufferUploader.end(bufferbuilder); - RenderSystem.enableTexture(); - RenderSystem.disableBlend(); - } - - public void fillCircle(PoseStack matrixStack, int centerX, int centerY, float radius, int color) { - color = fixAlpha(color); - - final float increment = 0.5f; - Matrix4f matrix = matrixStack.last().pose(); - - float z = this.getBlitOffset(); - float a = (float) (color >> 24 & 255) / 255.0F; - float r = (float) (color >> 16 & 255) / 255.0F; - float g = (float) (color >> 8 & 255) / 255.0F; - float b = (float) (color & 255) / 255.0F; - BufferBuilder bufferbuilder = Tesselator.getInstance().getBuilder(); - RenderSystem.enableBlend(); - RenderSystem.disableTexture(); - RenderSystem.defaultBlendFunc(); - bufferbuilder.begin(VertexFormat.Mode.LINES, DefaultVertexFormat.POSITION_COLOR); - for (float y = centerY - radius; y < centerY + radius; y += increment) { - float yd = centerY - y; - float xd = (float) Math.sqrt(Math.pow(radius, 2) - Math.pow(yd, 2)); - bufferbuilder.vertex(matrix, centerX - xd, y, z).color(r, g, b, a).endVertex(); - bufferbuilder.vertex(matrix, centerX + xd, y, z).color(r, g, b, a).endVertex(); - } - bufferbuilder.end(); - BufferUploader.end(bufferbuilder); - RenderSystem.enableTexture(); - RenderSystem.disableBlend(); - } - - public void drawItemIcon(PoseStack matrixStack, ItemRenderer itemRenderer, String item, int x, int y) { - ItemStack stack = new ItemStack(ItemUtil.getRegistryEntry(item, ForgeRegistries.ITEMS)); - itemRenderer.renderGuiItem(stack, x, y); - }*/ -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/argoggles/RenderActionType.java b/src/main/java/de/srendi/advancedperipherals/common/argoggles/RenderActionType.java deleted file mode 100644 index 28a72ed40..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/argoggles/RenderActionType.java +++ /dev/null @@ -1,30 +0,0 @@ -package de.srendi.advancedperipherals.common.argoggles; - -import de.srendi.advancedperipherals.AdvancedPeripherals; - -public enum RenderActionType { - - DRAW_CENTERED_STRING(3), - DRAW_STRING(3), - FILL(5), - HORIZONTAL_LINE(4), - VERTICAL_LINE(4), - FILL_GRADIENT(6), - DRAW_RIGHTBOUND_STRING(3), - DRAW_CIRCLE(4), - FILL_CIRCLE(4), - DRAW_ITEM_ICON(2); - - private final int intArgCount; - - RenderActionType(int intArgCount) { - this.intArgCount = intArgCount; - } - - public boolean ensureArgs(int[] args) { - boolean correct = args.length >= intArgCount; - if (!correct) - AdvancedPeripherals.LOGGER.warn("Got invalid number of arguments for AR render action {}: expected {}, got {}", this.toString(), intArgCount, args.length); - return correct; - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/PlayerDetectorBlock.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/PlayerDetectorBlock.java index a7e5ecfa6..ba798b041 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/PlayerDetectorBlock.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/PlayerDetectorBlock.java @@ -4,7 +4,7 @@ import de.srendi.advancedperipherals.common.blocks.base.APBlockEntityBlock; import de.srendi.advancedperipherals.common.blocks.blockentities.PlayerDetectorEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; +import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; import net.minecraft.core.BlockPos; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; @@ -19,13 +19,13 @@ public class PlayerDetectorBlock extends APBlockEntityBlock { public PlayerDetectorBlock() { - super(BlockEntityTypes.PLAYER_DETECTOR, false); + super(APBlockEntityTypes.PLAYER_DETECTOR, false); } @Nullable @Override public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) { - return BlockEntityTypes.PLAYER_DETECTOR.get().create(pos, state); + return APBlockEntityTypes.PLAYER_DETECTOR.get().create(pos, state); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/RedstoneIntegratorBlock.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/RedstoneIntegratorBlock.java index e9a9409ee..79552dfc8 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/RedstoneIntegratorBlock.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/RedstoneIntegratorBlock.java @@ -3,8 +3,8 @@ import de.srendi.advancedperipherals.common.blocks.base.APBlockEntityBlock; import de.srendi.advancedperipherals.common.blocks.base.BaseBlockEntityBlock; import de.srendi.advancedperipherals.common.blocks.blockentities.RedstoneIntegratorEntity; -import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; -import de.srendi.advancedperipherals.common.setup.Blocks; +import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; +import de.srendi.advancedperipherals.common.setup.APBlocks; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.item.context.BlockPlaceContext; @@ -23,13 +23,13 @@ public class RedstoneIntegratorBlock extends BaseBlockEntityBlock { public RedstoneIntegratorBlock() { - super(false, Properties.of(Material.METAL).isRedstoneConductor(Blocks::never)); + super(false, Properties.of(Material.METAL).isRedstoneConductor(APBlocks::never)); } @Nullable @Override public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) { - return BlockEntityTypes.REDSTONE_INTEGRATOR.get().create(pos, state); + return APBlockEntityTypes.REDSTONE_INTEGRATOR.get().create(pos, state); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/ARControllerEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/ARControllerEntity.java deleted file mode 100644 index 2bf2c73c6..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/ARControllerEntity.java +++ /dev/null @@ -1,159 +0,0 @@ -package de.srendi.advancedperipherals.common.blocks.blockentities; - -import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.ARControllerPeripheral; -import de.srendi.advancedperipherals.common.argoggles.ARRenderAction; -import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; -import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; -import net.minecraft.core.BlockPos; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.Tag; -import net.minecraft.network.Connection; -import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockState; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -public class ARControllerEntity extends PeripheralBlockEntity { - private static final String CANVAS = "canvas"; - private static final String VIRTUAL_SCREEN_SIZE = "virtual_screen_size"; - private final List canvas = new ArrayList<>(); - private Optional virtualScreenSize = Optional.empty(); - - public ARControllerEntity(BlockPos pos, BlockState state) { - super(BlockEntityTypes.AR_CONTROLLER.get(), pos, state); - } - - /** - * Adds a rendering action to the canvas. Won't add an action if it is already - * present with exactly the same parameters, to avoid clutter. - * - * @param action The action to add to the canvas. - */ - public void addToCanvas(ARRenderAction action) { - if (canvas.contains(action)) return; - if (action.getId() != null) { - canvas.removeIf(old -> action.getId().equals(old.getId())); - } - canvas.add(action); - blockChanged(); - } - - public void clearCanvas() { - canvas.clear(); - blockChanged(); - } - - public void clearElement(String id) { - canvas.removeIf(old -> id.equals(old.getId())); - blockChanged(); - } - - @NotNull - @Override - protected ARControllerPeripheral createPeripheral() { - return new ARControllerPeripheral(this); - } - - @Override - public void load(@NotNull CompoundTag nbt) { - super.load(nbt); - deserializeNBT(nbt); - } - - public void deserializeNBT(CompoundTag nbt) { - if (nbt.getIntArray(VIRTUAL_SCREEN_SIZE).length > 0) - virtualScreenSize = Optional.of(nbt.getIntArray(VIRTUAL_SCREEN_SIZE)); - else virtualScreenSize = Optional.empty(); - ListTag list = nbt.getList(CANVAS, Tag.TAG_COMPOUND); - canvas.clear(); - for (int i = 0; i < list.size(); i++) { - CompoundTag c = list.getCompound(i); - ARRenderAction action = new ARRenderAction(); - action.deserializeNBT(c); - canvas.add(action); - } - } - - public void saveAdditional(@NotNull CompoundTag compound) { - super.saveAdditional(compound); - if (virtualScreenSize.isPresent()) compound.putIntArray(VIRTUAL_SCREEN_SIZE, virtualScreenSize.get()); - else if (compound.contains(VIRTUAL_SCREEN_SIZE)) compound.remove(VIRTUAL_SCREEN_SIZE); - ListTag list = new ListTag(); - for (ARRenderAction action : new ArrayList<>(canvas)) { - list.add(action.serializeNBT()); - } - compound.put(CANVAS, list); - } - - @NotNull - @Override - public CompoundTag getUpdateTag() { - CompoundTag nbt = super.getUpdateTag(); - saveAdditional(nbt); - return nbt; - } - - @Override - public void handleUpdateTag(CompoundTag tag) { - deserializeNBT(tag); - super.handleUpdateTag(tag); - } - - @Override - public ClientboundBlockEntityDataPacket getUpdatePacket() { - CompoundTag nbt = new CompoundTag(); - saveAdditional(nbt); - return ClientboundBlockEntityDataPacket.create(this, BlockEntity::getUpdateTag); - } - - @Override - public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) { - CompoundTag nbt = pkt.getTag(); - deserializeNBT(nbt); - } - - public boolean isRelativeMode() { - return virtualScreenSize.isPresent(); - } - - public int[] getVirtualScreenSize() { - return virtualScreenSize.orElse(null); - } - - public void setRelativeMode(int virtualScreenWidth, int virtualScreenHeight) { - virtualScreenSize = Optional.of(new int[]{virtualScreenWidth, virtualScreenHeight}); - blockChanged(); - } - - public void disableRelativeMode() { - virtualScreenSize = Optional.empty(); - blockChanged(); - } - - private void blockChanged() { - setChanged(); - level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), 3); - } - - /** - * Returns a copy of the canvas with the virtual screen size added. - */ - public List getCanvas() { - List list = new ArrayList<>(); - for (ARRenderAction a : canvas) { - ARRenderAction action = a.copyWithVirtualScreenSize(virtualScreenSize); - list.add(action); - } - return list; - } - - @Override - public void markSettingsChanged() { - - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/BlockReaderEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/BlockReaderEntity.java index db48c0460..33e7b128f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/BlockReaderEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/BlockReaderEntity.java @@ -2,7 +2,7 @@ import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.BlockReaderPeripheral; import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; -import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; +import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; import net.minecraft.core.BlockPos; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.NotNull; @@ -10,7 +10,7 @@ public class BlockReaderEntity extends PeripheralBlockEntity { public BlockReaderEntity(BlockPos pos, BlockState state) { - super(BlockEntityTypes.BLOCK_READER.get(), pos, state); + super(APBlockEntityTypes.BLOCK_READER.get(), pos, state); } @NotNull diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/ChatBoxEnity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/ChatBoxEnity.java index 55bd49414..cb26b11e2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/ChatBoxEnity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/ChatBoxEnity.java @@ -3,7 +3,7 @@ import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.ChatBoxPeripheral; import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; import de.srendi.advancedperipherals.common.events.Events; -import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; +import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; import net.minecraft.core.BlockPos; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; @@ -16,7 +16,7 @@ public class ChatBoxEnity extends PeripheralBlockEntity { private Long lastConsumedMessage; public ChatBoxEnity(BlockPos pos, BlockState state) { - super(BlockEntityTypes.CHAT_BOX.get(), pos, state); + super(APBlockEntityTypes.CHAT_BOX.get(), pos, state); lastConsumedMessage = Events.getLastChatMessageID() - 1; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/ColonyIntegratorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/ColonyIntegratorEntity.java index 8c6504791..27e9d5e1f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/ColonyIntegratorEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/ColonyIntegratorEntity.java @@ -2,7 +2,7 @@ import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.ColonyPeripheral; import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; -import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; +import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; import net.minecraft.core.BlockPos; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.NotNull; @@ -10,7 +10,7 @@ public class ColonyIntegratorEntity extends PeripheralBlockEntity { public ColonyIntegratorEntity(BlockPos pos, BlockState state) { - super(BlockEntityTypes.COLONY_INTEGRATOR.get(), pos, state); + super(APBlockEntityTypes.COLONY_INTEGRATOR.get(), pos, state); } @NotNull diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnergyDetectorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnergyDetectorEntity.java index fea623836..38a98b4ca 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnergyDetectorEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnergyDetectorEntity.java @@ -4,7 +4,7 @@ import de.srendi.advancedperipherals.common.blocks.base.APBlockEntityBlock; import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; +import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; import de.srendi.advancedperipherals.common.util.EnergyStorageProxy; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -38,7 +38,7 @@ public class EnergyDetectorEntity extends PeripheralBlockEntity outReceivingStorage = Optional.empty(); public EnergyDetectorEntity(BlockPos pos, BlockState state) { - super(BlockEntityTypes.ENERGY_DETECTOR.get(), pos, state); + super(APBlockEntityTypes.ENERGY_DETECTOR.get(), pos, state); } @NotNull diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnvironmentDetectorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnvironmentDetectorEntity.java index 64a4527cc..681ed938e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnvironmentDetectorEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnvironmentDetectorEntity.java @@ -3,7 +3,7 @@ import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.EnvironmentDetectorPeripheral; import de.srendi.advancedperipherals.common.blocks.base.PoweredPeripheralBlockEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; +import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; import net.minecraft.core.BlockPos; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.NotNull; @@ -11,7 +11,7 @@ public class EnvironmentDetectorEntity extends PoweredPeripheralBlockEntity { public EnvironmentDetectorEntity(BlockPos pos, BlockState state) { - super(BlockEntityTypes.ENVIRONMENT_DETECTOR.get(), pos, state); + super(APBlockEntityTypes.ENVIRONMENT_DETECTOR.get(), pos, state); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/GeoScannerEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/GeoScannerEntity.java index 225541a4d..56eab8959 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/GeoScannerEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/GeoScannerEntity.java @@ -3,7 +3,7 @@ import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.GeoScannerPeripheral; import de.srendi.advancedperipherals.common.blocks.base.PoweredPeripheralBlockEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; +import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; import net.minecraft.core.BlockPos; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.NotNull; @@ -11,7 +11,7 @@ public class GeoScannerEntity extends PoweredPeripheralBlockEntity { public GeoScannerEntity(BlockPos pos, BlockState state) { - super(BlockEntityTypes.GEO_SCANNER.get(), pos, state); + super(APBlockEntityTypes.GEO_SCANNER.get(), pos, state); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java index fad6ce3d7..d92104fe1 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java @@ -5,7 +5,7 @@ import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; import de.srendi.advancedperipherals.common.container.InventoryManagerContainer; import de.srendi.advancedperipherals.common.items.MemoryCardItem; -import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; +import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.network.chat.Component; @@ -21,7 +21,7 @@ public class InventoryManagerEntity extends PeripheralBlockEntity implements IInventoryBlock { public InventoryManagerEntity(BlockPos pos, BlockState state) { - super(BlockEntityTypes.INVENTORY_MANAGER.get(), pos, state); + super(APBlockEntityTypes.INVENTORY_MANAGER.get(), pos, state); } @NotNull diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/MeBridgeEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/MeBridgeEntity.java index e8be53c0d..f7f474a94 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/MeBridgeEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/MeBridgeEntity.java @@ -1,6 +1,10 @@ package de.srendi.advancedperipherals.common.blocks.blockentities; -import appeng.api.networking.*; +import appeng.api.networking.GridFlags; +import appeng.api.networking.GridHelper; +import appeng.api.networking.IGridNode; +import appeng.api.networking.IInWorldGridNodeHost; +import appeng.api.networking.IManagedGridNode; import appeng.api.networking.crafting.ICraftingSimulationRequester; import appeng.api.networking.security.IActionHost; import appeng.api.networking.security.IActionSource; @@ -11,8 +15,8 @@ import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.MeBridgePeripheral; import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; -import de.srendi.advancedperipherals.common.setup.Blocks; +import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; +import de.srendi.advancedperipherals.common.setup.APBlocks; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.entity.player.Player; @@ -36,7 +40,7 @@ public class MeBridgeEntity extends PeripheralBlockEntity im private IManagedGridNode mainNode = GridHelper.createManagedNode(this, MeBridgeEntityListener.INSTANCE); public MeBridgeEntity(BlockPos pos, BlockState state) { - super(BlockEntityTypes.ME_BRIDGE.get(), pos, state); + super(APBlockEntityTypes.ME_BRIDGE.get(), pos, state); } @NotNull @@ -52,7 +56,7 @@ public void handleTick(Level level, BlockState state, Bl mainNode.setFlags(GridFlags.REQUIRE_CHANNEL); mainNode.setIdlePowerUsage(APConfig.PERIPHERALS_CONFIG.meConsumption.get()); - mainNode.setVisualRepresentation(new ItemStack(Blocks.ME_BRIDGE.get())); + mainNode.setVisualRepresentation(new ItemStack(APBlocks.ME_BRIDGE.get())); mainNode.setInWorldNode(true); mainNode.create(level, getBlockPos()); diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/NBTStorageEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/NBTStorageEntity.java index 707fec188..0b56fedc1 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/NBTStorageEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/NBTStorageEntity.java @@ -2,7 +2,7 @@ import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.NBTStoragePeripheral; import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; -import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; +import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.level.block.state.BlockState; @@ -13,7 +13,7 @@ public class NBTStorageEntity extends PeripheralBlockEntity { public PlayerDetectorEntity(BlockPos pos, BlockState state) { - super(BlockEntityTypes.PLAYER_DETECTOR.get(), pos, state); + super(APBlockEntityTypes.PLAYER_DETECTOR.get(), pos, state); } @NotNull diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RedstoneIntegratorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RedstoneIntegratorEntity.java index ac488d86f..c7e03e3f5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RedstoneIntegratorEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RedstoneIntegratorEntity.java @@ -3,7 +3,7 @@ import dan200.computercraft.shared.util.RedstoneUtil; import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.RedstoneIntegratorPeripheral; import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; -import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; +import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; @@ -19,7 +19,7 @@ public class RedstoneIntegratorEntity extends PeripheralBlockEntity i private static final BlockEntitySynchronizationSpec SPEC = BlockEntitySynchronizationSpec.builder().build(); public RsBridgeEntity(BlockPos pos, BlockState state) { - super(BlockEntityTypes.RS_BRIDGE.get(), pos, state, SPEC); + super(APBlockEntityTypes.RS_BRIDGE.get(), pos, state, SPEC); peripheralSettings = new CompoundTag(); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/SmartGlassesControllerEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/SmartGlassesControllerEntity.java new file mode 100644 index 000000000..458d1b633 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/SmartGlassesControllerEntity.java @@ -0,0 +1,22 @@ +package de.srendi.advancedperipherals.common.blocks.blockentities; + +import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.SmartGlassesPeripheral; +import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; +import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.NotNull; + +public class SmartGlassesControllerEntity extends PeripheralBlockEntity { + + public SmartGlassesControllerEntity(BlockPos pos, BlockState state) { + super(APBlockEntityTypes.AR_CONTROLLER.get(), pos, state); + } + + + @NotNull + @Override + protected SmartGlassesPeripheral createPeripheral() { + return null; + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java index e4faa77ae..f98abaf24 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java @@ -34,7 +34,7 @@ public class PeripheralsConfig implements IAPConfig { //Environment Detector public final ForgeConfigSpec.BooleanValue enableEnvironmentDetector; //AR Controller - public final ForgeConfigSpec.BooleanValue enableARGoggles; + public final ForgeConfigSpec.BooleanValue enableSmartGlasses; //Inventory Manager public final ForgeConfigSpec.BooleanValue enableInventoryManager; //Redstone Integrator @@ -99,7 +99,7 @@ public PeripheralsConfig() { pop("AR_Controller", builder); - enableARGoggles = builder.comment("Enable the AR goggles or not.").define("enableARGoggles", true); + enableSmartGlasses = builder.comment("Enable the smart glasses or not.").define("enableSmartGlasses", true); pop("Inventory_Manager", builder); diff --git a/src/main/java/de/srendi/advancedperipherals/common/container/InventoryManagerContainer.java b/src/main/java/de/srendi/advancedperipherals/common/container/InventoryManagerContainer.java index 17d158598..7fb9b9537 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/container/InventoryManagerContainer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/container/InventoryManagerContainer.java @@ -3,8 +3,8 @@ import de.srendi.advancedperipherals.common.container.base.BaseContainer; import de.srendi.advancedperipherals.common.container.base.SlotCondition; import de.srendi.advancedperipherals.common.container.base.SlotInputHandler; -import de.srendi.advancedperipherals.common.setup.ContainerTypes; -import de.srendi.advancedperipherals.common.setup.Items; +import de.srendi.advancedperipherals.common.setup.APContainerTypes; +import de.srendi.advancedperipherals.common.setup.APItems; import net.minecraft.core.BlockPos; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; @@ -17,11 +17,11 @@ public class InventoryManagerContainer extends BaseContainer { public InventoryManagerContainer(int id, Inventory inventory, BlockPos pos, Level level) { - super(ContainerTypes.INVENTORY_MANAGER_CONTAINER.get(), id, inventory, pos, level); + super(APContainerTypes.INVENTORY_MANAGER_CONTAINER.get(), id, inventory, pos, level); layoutPlayerInventorySlots(7, 84); if (tileEntity != null) { tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).ifPresent(handler -> { - addSlot(new SlotInputHandler(handler, 0, 79, 29, new SlotCondition().setNeededItem(Items.MEMORY_CARD.get()))); //Input + addSlot(new SlotInputHandler(handler, 0, 79, 29, new SlotCondition().setNeededItem(APItems.MEMORY_CARD.get()))); //Input }); } } @@ -44,7 +44,7 @@ public ItemStack quickMoveStack(@NotNull Player player, int index) { return ItemStack.EMPTY; } } else if (index <= 35) { - if (itemstack1.getItem().equals(Items.MEMORY_CARD.get())) { + if (itemstack1.getItem().equals(APItems.MEMORY_CARD.get())) { if (!this.moveItemStackTo(itemstack1, 36, 37, true)) { return ItemStack.EMPTY; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java b/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java index fe6799cd7..be546eda1 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java @@ -1,6 +1,6 @@ package de.srendi.advancedperipherals.common.data; -import de.srendi.advancedperipherals.common.setup.Registration; +import de.srendi.advancedperipherals.common.setup.APRegistration; import net.minecraft.world.level.block.Block; import net.minecraftforge.registries.RegistryObject; import org.jetbrains.annotations.NotNull; @@ -9,12 +9,12 @@ public class BlockLootTables extends net.minecraft.data.loot.BlockLoot { @Override protected void addTables() { - Registration.BLOCKS.getEntries().stream().map(RegistryObject::get).forEach(this::dropSelf); + APRegistration.BLOCKS.getEntries().stream().map(RegistryObject::get).forEach(this::dropSelf); } @NotNull @Override protected Iterable getKnownBlocks() { - return Registration.BLOCKS.getEntries().stream().map(RegistryObject::get)::iterator; + return APRegistration.BLOCKS.getEntries().stream().map(RegistryObject::get)::iterator; } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/DataGenerators.java b/src/main/java/de/srendi/advancedperipherals/common/data/DataGenerators.java index 5da240be8..68b2c2d2d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/DataGenerators.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/DataGenerators.java @@ -1,7 +1,7 @@ package de.srendi.advancedperipherals.common.data; import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.common.setup.Registration; +import de.srendi.advancedperipherals.common.setup.APRegistration; import net.minecraft.data.DataGenerator; import net.minecraftforge.common.data.ExistingFileHelper; import net.minecraftforge.data.event.GatherDataEvent; @@ -19,7 +19,7 @@ public static void genData(GatherDataEvent event) { DataGenerator generator = event.getGenerator(); ExistingFileHelper existingFileHelper = event.getExistingFileHelper(); - generator.addProvider(event.includeServer(), new BlockTagsProvider(generator, existingFileHelper, Registration.BLOCKS)); + generator.addProvider(event.includeServer(), new BlockTagsProvider(generator, existingFileHelper, APRegistration.BLOCKS)); generator.addProvider(event.includeServer(), new RecipesProvider(generator)); generator.addProvider(event.includeServer(), new BlockLootTablesProvider(generator)); generator.addProvider(event.includeServer(), new TurtleUpgradesProvider(generator)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/PocketUpgradesProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/PocketUpgradesProvider.java index a08dc93c5..a861dc376 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/PocketUpgradesProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/PocketUpgradesProvider.java @@ -2,7 +2,7 @@ import dan200.computercraft.api.pocket.PocketUpgradeDataProvider; import dan200.computercraft.api.pocket.PocketUpgradeSerialiser; -import de.srendi.advancedperipherals.common.setup.Blocks; +import de.srendi.advancedperipherals.common.setup.APBlocks; import de.srendi.advancedperipherals.common.setup.CCRegistration; import net.minecraft.data.DataGenerator; import org.jetbrains.annotations.NotNull; @@ -17,10 +17,10 @@ public PocketUpgradesProvider(DataGenerator generator) { @Override protected void addUpgrades(@NotNull Consumer>> addUpgrade) { - simpleWithCustomItem(CCRegistration.ID.CHATTY_POCKET, CCRegistration.CHAT_BOX_POCKET.get(), Blocks.CHAT_BOX.get().asItem()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.PLAYER_POCKET, CCRegistration.PLAYER_DETECTOR_POCKET.get(), Blocks.PLAYER_DETECTOR.get().asItem()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.ENVIRONMENT_POCKET, CCRegistration.ENVIRONMENT_POCKET.get(), Blocks.ENVIRONMENT_DETECTOR.get().asItem()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.GEOSCANNER_POCKET, CCRegistration.GEO_SCANNER_POCKET.get(), Blocks.GEO_SCANNER.get().asItem()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.COLONY_POCKET, CCRegistration.COLONY_POCKET.get(), Blocks.COLONY_INTEGRATOR.get().asItem()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.CHATTY_POCKET, CCRegistration.CHAT_BOX_POCKET.get(), APBlocks.CHAT_BOX.get().asItem()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.PLAYER_POCKET, CCRegistration.PLAYER_DETECTOR_POCKET.get(), APBlocks.PLAYER_DETECTOR.get().asItem()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.ENVIRONMENT_POCKET, CCRegistration.ENVIRONMENT_POCKET.get(), APBlocks.ENVIRONMENT_DETECTOR.get().asItem()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.GEOSCANNER_POCKET, CCRegistration.GEO_SCANNER_POCKET.get(), APBlocks.GEO_SCANNER.get().asItem()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.COLONY_POCKET, CCRegistration.COLONY_POCKET.get(), APBlocks.COLONY_INTEGRATOR.get().asItem()).add(addUpgrade); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/PoiTypeProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/PoiTypeProvider.java index e3c727865..9549f1cc3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/PoiTypeProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/PoiTypeProvider.java @@ -1,7 +1,7 @@ package de.srendi.advancedperipherals.common.data; import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.common.setup.Registration; +import de.srendi.advancedperipherals.common.setup.APRegistration; import net.minecraft.data.DataGenerator; import net.minecraft.data.tags.PoiTypeTagsProvider; import net.minecraft.data.tags.TagsProvider; @@ -21,7 +21,7 @@ public PoiTypeProvider(DataGenerator pGenerator, @Nullable ExistingFileHelper ex @Override protected void addTags() { TagsProvider.TagAppender appender = tag(PoiTypeTags.ACQUIRABLE_JOB_SITE); - Registration.POI_TYPES.getEntries().stream().map(RegistryObject::getKey).forEach(appender::add); + APRegistration.POI_TYPES.getEntries().stream().map(RegistryObject::getKey).forEach(appender::add); } @NotNull diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java index 802162b90..dd9ab48c0 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java @@ -1,17 +1,22 @@ package de.srendi.advancedperipherals.common.data; import dan200.computercraft.shared.Registry; -import de.srendi.advancedperipherals.common.setup.Blocks; +import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.common.setup.APBlocks; +import de.srendi.advancedperipherals.common.setup.APItems; import net.minecraft.data.DataGenerator; import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.data.recipes.RecipeProvider; import net.minecraft.data.recipes.ShapedRecipeBuilder; import net.minecraft.data.recipes.ShapelessRecipeBuilder; +import net.minecraft.data.recipes.UpgradeRecipeBuilder; +import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.ItemTags; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.alchemy.PotionUtils; import net.minecraft.world.item.alchemy.Potions; +import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.level.block.Block; import net.minecraftforge.common.Tags; import net.minecraftforge.common.crafting.StrictNBTIngredient; @@ -22,7 +27,7 @@ public class RecipesProvider extends RecipeProvider implements IConditionBuilder { - private static final Block CASING = Blocks.PERIPHERAL_CASING.get(); + private static final Block CASING = APBlocks.PERIPHERAL_CASING.get(); public RecipesProvider(DataGenerator generatorIn) { super(generatorIn); @@ -30,7 +35,33 @@ public RecipesProvider(DataGenerator generatorIn) { @Override protected void buildCraftingRecipes(@NotNull Consumer consumer) { - ShapedRecipeBuilder.shaped(Blocks.AR_CONTROLLER.get()) + addShapeless(consumer); + addShaped(consumer); + addSmithing(consumer); + } + + private void addShapeless(@NotNull Consumer consumer) { + ShapelessRecipeBuilder.shapeless(APItems.OVERPOWERED_WEAK_AUTOMATA_CORE.get()) + .requires(APItems.WEAK_AUTOMATA_CORE.get()) + .requires(Items.NETHER_STAR) + .unlockedBy("has_item", has(APItems.WEAK_AUTOMATA_CORE.get())) + .save(consumer); + + ShapelessRecipeBuilder.shapeless(APItems.OVERPOWERED_END_AUTOMATA_CORE.get()) + .requires(APItems.END_AUTOMATA_CORE.get()) + .requires(Items.NETHER_STAR) + .unlockedBy("has_item", has(APItems.END_AUTOMATA_CORE.get())) + .save(consumer); + + ShapelessRecipeBuilder.shapeless(APItems.OVERPOWERED_HUSBANDRY_AUTOMATA_CORE.get()) + .requires(APItems.HUSBANDRY_AUTOMATA_CORE.get()) + .requires(Items.NETHER_STAR) + .unlockedBy("has_item", has(APItems.HUSBANDRY_AUTOMATA_CORE.get())) + .save(consumer); + } + + private void addShaped(@NotNull Consumer consumer) { + ShapedRecipeBuilder.shaped(APBlocks.AR_CONTROLLER.get()) .define('E', Tags.Items.ENDER_PEARLS) .define('C', CASING) .define('G', Items.SMOOTH_STONE) @@ -40,7 +71,7 @@ protected void buildCraftingRecipes(@NotNull Consumer consumer) .unlockedBy("has_item", has(CASING)) .save(consumer); - ShapedRecipeBuilder.shaped(de.srendi.advancedperipherals.common.setup.Items.AR_GOGGLES.get()) + ShapedRecipeBuilder.shaped(APItems.SMART_GLASSES.get()) .define('E', Tags.Items.ENDER_PEARLS) .define('S', Tags.Items.RODS_WOODEN) .define('G', Tags.Items.GLASS_BLACK) @@ -49,7 +80,7 @@ protected void buildCraftingRecipes(@NotNull Consumer consumer) .unlockedBy("has_item", has(Items.STICK)) .save(consumer); - ShapedRecipeBuilder.shaped(Blocks.CHAT_BOX.get()) + ShapedRecipeBuilder.shaped(APBlocks.CHAT_BOX.get()) .define('P', ItemTags.LOGS) .define('A', CASING) .define('G', Tags.Items.INGOTS_GOLD) @@ -59,7 +90,7 @@ protected void buildCraftingRecipes(@NotNull Consumer consumer) .unlockedBy("has_item", has(CASING)) .save(consumer); - ShapedRecipeBuilder.shaped(de.srendi.advancedperipherals.common.setup.Items.CHUNK_CONTROLLER.get()) + ShapedRecipeBuilder.shaped(APItems.CHUNK_CONTROLLER.get()) .define('I', Tags.Items.INGOTS_IRON) .define('R', Tags.Items.DUSTS_REDSTONE) .define('A', Items.ENDER_EYE) @@ -69,7 +100,7 @@ protected void buildCraftingRecipes(@NotNull Consumer consumer) .unlockedBy("has_item", has(Items.RESPAWN_ANCHOR)) .save(consumer); - ShapedRecipeBuilder.shaped(de.srendi.advancedperipherals.common.setup.Items.COMPUTER_TOOL.get()) + ShapedRecipeBuilder.shaped(APItems.COMPUTER_TOOL.get()) .define('I', Tags.Items.INGOTS_IRON) .define('B', Items.BLUE_TERRACOTTA) .pattern("I I") @@ -78,7 +109,7 @@ protected void buildCraftingRecipes(@NotNull Consumer consumer) .unlockedBy("has_item", has(Items.BLUE_TERRACOTTA)) .save(consumer); - ShapedRecipeBuilder.shaped(Blocks.ENERGY_DETECTOR.get()) + ShapedRecipeBuilder.shaped(APBlocks.ENERGY_DETECTOR.get()) .define('B', Tags.Items.STORAGE_BLOCKS_REDSTONE) .define('R', Items.REDSTONE_TORCH) .define('C', Items.COMPARATOR) @@ -90,7 +121,7 @@ protected void buildCraftingRecipes(@NotNull Consumer consumer) .unlockedBy("has_item", has(CASING)) .save(consumer); - ShapedRecipeBuilder.shaped(Blocks.ENVIRONMENT_DETECTOR.get()) + ShapedRecipeBuilder.shaped(APBlocks.ENVIRONMENT_DETECTOR.get()) .define('W', ItemTags.WOOL) .define('S', ItemTags.SAPLINGS) .define('C', Tags.Items.CROPS) @@ -102,7 +133,7 @@ protected void buildCraftingRecipes(@NotNull Consumer consumer) .unlockedBy("has_item", has(CASING)) .save(consumer); - ShapedRecipeBuilder.shaped(Blocks.INVENTORY_MANAGER.get()) + ShapedRecipeBuilder.shaped(APBlocks.INVENTORY_MANAGER.get()) .define('I', Tags.Items.INGOTS_IRON) .define('C', Tags.Items.CHESTS) .define('A', CASING) @@ -112,7 +143,7 @@ protected void buildCraftingRecipes(@NotNull Consumer consumer) .unlockedBy("has_item", has(CASING)) .save(consumer); - ShapedRecipeBuilder.shaped(de.srendi.advancedperipherals.common.setup.Items.MEMORY_CARD.get()) + ShapedRecipeBuilder.shaped(APItems.MEMORY_CARD.get()) .define('I', Tags.Items.INGOTS_IRON) .define('W', Tags.Items.GLASS_WHITE) .define('O', Items.OBSERVER) @@ -123,7 +154,7 @@ protected void buildCraftingRecipes(@NotNull Consumer consumer) .unlockedBy("has_item", has(Items.OBSERVER)) .save(consumer); - ShapedRecipeBuilder.shaped(Blocks.PERIPHERAL_CASING.get()) + ShapedRecipeBuilder.shaped(APBlocks.PERIPHERAL_CASING.get()) .define('I', Tags.Items.INGOTS_IRON) .define('i', Items.IRON_BARS) .define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE) @@ -133,7 +164,7 @@ protected void buildCraftingRecipes(@NotNull Consumer consumer) .unlockedBy("has_item", has(Items.REDSTONE_BLOCK)) .save(consumer); - ShapedRecipeBuilder.shaped(Blocks.PLAYER_DETECTOR.get()) + ShapedRecipeBuilder.shaped(APBlocks.PLAYER_DETECTOR.get()) .define('S', Items.SMOOTH_STONE) .define('A', CASING) .define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE) @@ -143,7 +174,7 @@ protected void buildCraftingRecipes(@NotNull Consumer consumer) .unlockedBy("has_item", has(CASING)) .save(consumer); - ShapedRecipeBuilder.shaped(Blocks.REDSTONE_INTEGRATOR.get()) + ShapedRecipeBuilder.shaped(APBlocks.REDSTONE_INTEGRATOR.get()) .define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE) .define('A', CASING) .define('C', Items.COMPARATOR) @@ -153,7 +184,7 @@ protected void buildCraftingRecipes(@NotNull Consumer consumer) .unlockedBy("has_item", has(CASING)) .save(consumer); - ShapedRecipeBuilder.shaped(Blocks.BLOCK_READER.get()) + ShapedRecipeBuilder.shaped(APBlocks.BLOCK_READER.get()) .define('O', Items.OBSERVER) .define('I', Tags.Items.INGOTS_IRON) .define('M', Registry.ModBlocks.WIRED_MODEM_FULL.get()) @@ -165,7 +196,7 @@ protected void buildCraftingRecipes(@NotNull Consumer consumer) .unlockedBy("has_item", has(CASING)) .save(consumer); - ShapedRecipeBuilder.shaped(Blocks.GEO_SCANNER.get()) + ShapedRecipeBuilder.shaped(APBlocks.GEO_SCANNER.get()) .define('O', Items.OBSERVER) .define('D', Tags.Items.GEMS_DIAMOND) .define('C', CASING) @@ -177,7 +208,7 @@ protected void buildCraftingRecipes(@NotNull Consumer consumer) .unlockedBy("has_item", has(CASING)) .save(consumer); - ShapedRecipeBuilder.shaped(Blocks.NBT_STORAGE.get()) + ShapedRecipeBuilder.shaped(APBlocks.NBT_STORAGE.get()) .define('C', Tags.Items.CHESTS) .define('A', CASING) .define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE) @@ -188,7 +219,7 @@ protected void buildCraftingRecipes(@NotNull Consumer consumer) .unlockedBy("has_item", has(CASING)) .save(consumer); - ShapedRecipeBuilder.shaped(de.srendi.advancedperipherals.common.setup.Items.WEAK_AUTOMATA_CORE.get()) + ShapedRecipeBuilder.shaped(APItems.WEAK_AUTOMATA_CORE.get()) .define('A', CASING) .define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE) .define('S', Items.SOUL_LANTERN) @@ -199,24 +230,13 @@ protected void buildCraftingRecipes(@NotNull Consumer consumer) .pattern("RLR") .unlockedBy("has_item", has(CASING)) .save(consumer); + } - ShapelessRecipeBuilder.shapeless(de.srendi.advancedperipherals.common.setup.Items.OVERPOWERED_WEAK_AUTOMATA_CORE.get()) - .requires(de.srendi.advancedperipherals.common.setup.Items.WEAK_AUTOMATA_CORE.get()) - .requires(Items.NETHER_STAR) - .unlockedBy("has_item", has(de.srendi.advancedperipherals.common.setup.Items.WEAK_AUTOMATA_CORE.get())) - .save(consumer); - - ShapelessRecipeBuilder.shapeless(de.srendi.advancedperipherals.common.setup.Items.OVERPOWERED_END_AUTOMATA_CORE.get()) - .requires(de.srendi.advancedperipherals.common.setup.Items.END_AUTOMATA_CORE.get()) - .requires(Items.NETHER_STAR) - .unlockedBy("has_item", has(de.srendi.advancedperipherals.common.setup.Items.END_AUTOMATA_CORE.get())) - .save(consumer); - - ShapelessRecipeBuilder.shapeless(de.srendi.advancedperipherals.common.setup.Items.OVERPOWERED_HUSBANDRY_AUTOMATA_CORE.get()) - .requires(de.srendi.advancedperipherals.common.setup.Items.HUSBANDRY_AUTOMATA_CORE.get()) - .requires(Items.NETHER_STAR) - .unlockedBy("has_item", has(de.srendi.advancedperipherals.common.setup.Items.HUSBANDRY_AUTOMATA_CORE.get())) - .save(consumer); + private void addSmithing(@NotNull Consumer consumer) { + UpgradeRecipeBuilder + .smithing(Ingredient.of(APItems.SMART_GLASSES.get()), Ingredient.of(Items.NETHERITE_INGOT), APItems.SMART_GLASSES_NETHERITE.get()) + .unlocks("has_item", has(Items.NETHERITE_INGOT)) + .save(consumer, new ResourceLocation(AdvancedPeripherals.MOD_ID, "armor/" + APItems.SMART_GLASSES_NETHERITE.getKey().location().getPath())); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/TurtleUpgradesProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/TurtleUpgradesProvider.java index 4a1ec409a..70ec6c177 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/TurtleUpgradesProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/TurtleUpgradesProvider.java @@ -2,9 +2,9 @@ import dan200.computercraft.api.turtle.TurtleUpgradeDataProvider; import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser; -import de.srendi.advancedperipherals.common.setup.Blocks; +import de.srendi.advancedperipherals.common.setup.APBlocks; +import de.srendi.advancedperipherals.common.setup.APItems; import de.srendi.advancedperipherals.common.setup.CCRegistration; -import de.srendi.advancedperipherals.common.setup.Items; import net.minecraft.data.DataGenerator; import org.jetbrains.annotations.NotNull; @@ -18,18 +18,18 @@ public TurtleUpgradesProvider(DataGenerator generator) { @Override protected void addUpgrades(@NotNull Consumer>> addUpgrade) { - simpleWithCustomItem(CCRegistration.ID.CHATTY_TURTLE, CCRegistration.CHAT_BOX_TURTLE.get(), Blocks.CHAT_BOX.get().asItem()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.PLAYER_TURTLE, CCRegistration.PLAYER_DETECTOR_TURTLE.get(), Blocks.PLAYER_DETECTOR.get().asItem()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.ENVIRONMENT_TURTLE, CCRegistration.ENVIRONMENT_TURTLE.get(), Blocks.ENVIRONMENT_DETECTOR.get().asItem()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.CHUNKY_TURTLE, CCRegistration.CHUNKY_TURTLE.get(), Items.CHUNK_CONTROLLER.get()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.GEOSCANNER_TURTLE, CCRegistration.GEO_SCANNER_TURTLE.get(), Blocks.GEO_SCANNER.get().asItem()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.CHATTY_TURTLE, CCRegistration.CHAT_BOX_TURTLE.get(), APBlocks.CHAT_BOX.get().asItem()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.PLAYER_TURTLE, CCRegistration.PLAYER_DETECTOR_TURTLE.get(), APBlocks.PLAYER_DETECTOR.get().asItem()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.ENVIRONMENT_TURTLE, CCRegistration.ENVIRONMENT_TURTLE.get(), APBlocks.ENVIRONMENT_DETECTOR.get().asItem()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.CHUNKY_TURTLE, CCRegistration.CHUNKY_TURTLE.get(), APItems.CHUNK_CONTROLLER.get()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.GEOSCANNER_TURTLE, CCRegistration.GEO_SCANNER_TURTLE.get(), APBlocks.GEO_SCANNER.get().asItem()).add(addUpgrade); simpleWithCustomItem(CCRegistration.ID.COMPASS_TURTLE, CCRegistration.COMPASS_TURTLE.get(), net.minecraft.world.item.Items.COMPASS).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.WEAK_AUTOMATA, CCRegistration.WEAK_TURTLE.get(), Items.WEAK_AUTOMATA_CORE.get()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.END_AUTOMATA, CCRegistration.END_TURTLE.get(), Items.END_AUTOMATA_CORE.get()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.HUSBANDRY_AUTOMATA, CCRegistration.HUSBANDRY_TURTLE.get(), Items.HUSBANDRY_AUTOMATA_CORE.get()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.OP_WEAK_AUTOMATA, CCRegistration.OP_WEAK_TURTLE.get(), Items.OVERPOWERED_WEAK_AUTOMATA_CORE.get()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.OP_END_AUTOMATA, CCRegistration.OP_END_TURTLE.get(), Items.OVERPOWERED_END_AUTOMATA_CORE.get()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.OP_HUSBANDRY_AUTOMATA, CCRegistration.OP_HUSBANDRY_TURTLE.get(), Items.OVERPOWERED_HUSBANDRY_AUTOMATA_CORE.get()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.WEAK_AUTOMATA, CCRegistration.WEAK_TURTLE.get(), APItems.WEAK_AUTOMATA_CORE.get()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.END_AUTOMATA, CCRegistration.END_TURTLE.get(), APItems.END_AUTOMATA_CORE.get()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.HUSBANDRY_AUTOMATA, CCRegistration.HUSBANDRY_TURTLE.get(), APItems.HUSBANDRY_AUTOMATA_CORE.get()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.OP_WEAK_AUTOMATA, CCRegistration.OP_WEAK_TURTLE.get(), APItems.OVERPOWERED_WEAK_AUTOMATA_CORE.get()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.OP_END_AUTOMATA, CCRegistration.OP_END_TURTLE.get(), APItems.OVERPOWERED_END_AUTOMATA_CORE.get()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.OP_HUSBANDRY_AUTOMATA, CCRegistration.OP_HUSBANDRY_TURTLE.get(), APItems.OVERPOWERED_HUSBANDRY_AUTOMATA_CORE.get()).add(addUpgrade); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/events/Events.java b/src/main/java/de/srendi/advancedperipherals/common/events/Events.java index 41f143c43..3b1695b41 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/events/Events.java +++ b/src/main/java/de/srendi/advancedperipherals/common/events/Events.java @@ -5,21 +5,15 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.items.ARGogglesItem; import de.srendi.advancedperipherals.common.util.Pair; -import de.srendi.advancedperipherals.network.MNetwork; -import de.srendi.advancedperipherals.network.messages.ClearHudCanvasMessage; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.arguments.MessageArgument; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraftforge.event.CommandEvent; import net.minecraftforge.event.ServerChatEvent; -import net.minecraftforge.event.entity.living.LivingEquipmentChangeEvent; import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @@ -90,15 +84,6 @@ public static void onChatBox(ServerChatEvent event) { } } - @SubscribeEvent - public static void onEquipmentChange(LivingEquipmentChangeEvent event) { - LivingEntity livingEntity = event.getEntity(); - if (!(livingEntity instanceof ServerPlayer serverPlayer)) return; - if (event.getFrom().getItem() instanceof ARGogglesItem) - MNetwork.sendTo(new ClearHudCanvasMessage(), serverPlayer); - - } - public static synchronized void putChatMessage(Pair message) { messageQueue.add(message); lastChatMessageID++; diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/ARGogglesItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/ARGogglesItem.java deleted file mode 100644 index 52fb6d716..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/items/ARGogglesItem.java +++ /dev/null @@ -1,115 +0,0 @@ -package de.srendi.advancedperipherals.common.items; - -import de.srendi.advancedperipherals.AdvancedPeripherals; -import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.item.ArmorItem; -import net.minecraft.world.item.ArmorMaterials; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.TooltipFlag; -import net.minecraft.world.level.Level; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -public class ARGogglesItem extends ArmorItem { - private static final String CONTROLLER_POS = "controller_pos"; - private static final String CONTROLLER_LEVEL = "controller_level"; - - public ARGogglesItem() { - super(ArmorMaterials.LEATHER, EquipmentSlot.HEAD, new Properties().tab(AdvancedPeripherals.TAB).stacksTo(1)); - } - - @Override - public void appendHoverText(ItemStack stack, @Nullable Level levelIn, List tooltip, TooltipFlag flagIn) { - super.appendHoverText(stack, levelIn, tooltip, flagIn); - tooltip.add(Component.literal("Temporarily disabled until rewrite")); - } - - /*public static void clientTick(LocalPlayer player, ItemStack stack) { - if (stack.hasTag() && stack.getTag().contains(CONTROLLER_POS) && stack.getTag().contains(CONTROLLER_LEVEL)) { - int[] arr = stack.getTag().getIntArray(CONTROLLER_POS); - if (arr.length < 3) return; - BlockPos pos = new BlockPos(arr[0], arr[1], arr[2]); - String dimensionKey = stack.getTag().getString(CONTROLLER_LEVEL); - Level level = player.level; - if (!dimensionKey.equals(level.dimension().toString())) { - MNetwork.sendToServer(new RequestHudCanvasMessage(pos, dimensionKey)); - return; - } - BlockEntity te = level.getBlockEntity(pos); - if (!(te instanceof ARControllerEntity)) { - //If distance to ARController is larger than view distance - MNetwork.sendToServer(new RequestHudCanvasMessage(pos, dimensionKey)); - return; - } - - ARControllerEntity controller = (ARControllerEntity) te; - HudOverlayHandler.updateCanvas(controller.getCanvas()); - } - } - - public Component getDescription() { - return Component.translatable("item.advancedperipherals.tooltip.ar_goggles"); - } - - @Override - public void appendHoverText(ItemStack stack, @Nullable Level levelIn, List tooltip, TooltipFlag flagIn) { - super.appendHoverText(stack, levelIn, tooltip, flagIn); - if (!InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_KEY_LEFT_CONTROL)) { - tooltip.add(EnumColor.buildTextComponent(Component.translatable("item.advancedperipherals.tooltip.show_desc"))); - } else { - tooltip.add(EnumColor.buildTextComponent(getDescription())); - } - if (!APConfig.PERIPHERALS_CONFIG.enableARGoggles.get()) - tooltip.add(EnumColor.buildTextComponent(Component.translatable("item.advancedperipherals.tooltip.disabled"))); - if (stack.hasTag() && stack.getTag().contains(CONTROLLER_POS, CompoundTag.TAG_INT_ARRAY)) { - int[] pos = stack.getTag().getIntArray(CONTROLLER_POS); - tooltip.add(Component.translatable("item.advancedperipherals.tooltip.ar_goggles.binding", pos[0], pos[1], pos[2])); - } - } - - @Override - public ICapabilityProvider initCapabilities(ItemStack stack, CompoundTag nbt) { - if (!AdvancedPeripherals.isCuriosLoaded()) { - return null; - } - return CuriosHelper.createARGogglesProvider(stack); - } - - @Override - public String getArmorTexture(ItemStack stack, Entity entity, EquipmentSlot slot, String type) { - return AdvancedPeripherals.MOD_ID + ":textures/models/ar_goggles.png"; - } - - @Override - public void onArmorTick(ItemStack stack, Level level, Player player) { - // only need to tick client side, if client is wearing them himself - if (!SideHelper.isClientPlayer(player)) return; - clientTick((LocalPlayer) player, stack); - } - - @Override - public InteractionResult useOn(UseOnContext context) { - BlockPos blockpos = context.getClickedPos(); - Level level = context.getLevel(); - if (!level.getBlockState(blockpos).is(Blocks.AR_CONTROLLER.get())) { - return super.useOn(context); - } else { - BlockEntity entity = level.getBlockEntity(blockpos); - if (!(entity instanceof ARControllerEntity)) return super.useOn(context); - ARControllerEntity controller = (ARControllerEntity) entity; - if (!context.getLevel().isClientSide) { - ItemStack item = context.getItemInHand(); - if (!item.hasTag()) item.setTag(new CompoundTag()); - CompoundTag nbt = item.getTag(); - BlockPos pos = controller.getBlockPos(); - nbt.putIntArray(CONTROLLER_POS, new int[]{pos.getX(), pos.getY(), pos.getZ()}); - nbt.putString(CONTROLLER_LEVEL, controller.getLevel().dimension().toString()); - item.setTag(nbt); - } - context.getPlayer().displayClientMessage(Component.translatable("text.advancedperipherals.linked_goggles"), true); - return InteractionResult.SUCCESS; - } - }*/ -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java new file mode 100644 index 000000000..0a0042c65 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java @@ -0,0 +1,28 @@ +package de.srendi.advancedperipherals.common.items; + +import de.srendi.advancedperipherals.AdvancedPeripherals; +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.item.ArmorItem; +import net.minecraft.world.item.ArmorMaterials; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.level.Level; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class SmartGlassesItem extends ArmorItem { + + public SmartGlassesItem(ArmorMaterials material) { + super(material, EquipmentSlot.HEAD, new Properties().tab(AdvancedPeripherals.TAB).stacksTo(1)); + } + + @Override + public void appendHoverText(@NotNull ItemStack stack, @Nullable Level levelIn, @NotNull List tooltip, @NotNull TooltipFlag flagIn) { + super.appendHoverText(stack, levelIn, tooltip, flagIn); + tooltip.add(Component.literal("Temporarily disabled until rewrite")); + } + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/WeakAutomataCore.java b/src/main/java/de/srendi/advancedperipherals/common/items/WeakAutomataCore.java index 640161091..7975f8b1c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/WeakAutomataCore.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/WeakAutomataCore.java @@ -1,7 +1,7 @@ package de.srendi.advancedperipherals.common.items; import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.setup.Items; +import de.srendi.advancedperipherals.common.setup.APItems; import de.srendi.advancedperipherals.common.util.EnumColor; import de.srendi.advancedperipherals.lib.metaphysics.IFeedableAutomataCore; import net.minecraft.nbt.CompoundTag; @@ -37,13 +37,13 @@ public class WeakAutomataCore extends APItem implements IFeedableAutomataCore { static { Map endSouls = new HashMap<>(); endSouls.put(ForgeRegistries.ENTITY_TYPES.getKey(EntityType.ENDERMAN).toString(), 10); - WeakAutomataCoreRecord endSoulRecord = new WeakAutomataCoreRecord(endSouls, Items.END_AUTOMATA_CORE.get()); + WeakAutomataCoreRecord endSoulRecord = new WeakAutomataCoreRecord(endSouls, APItems.END_AUTOMATA_CORE.get()); Map husbandrySouls = new HashMap<>(); husbandrySouls.put(ForgeRegistries.ENTITY_TYPES.getKey(EntityType.COW).toString(), 3); husbandrySouls.put(ForgeRegistries.ENTITY_TYPES.getKey(EntityType.SHEEP).toString(), 3); husbandrySouls.put(ForgeRegistries.ENTITY_TYPES.getKey(EntityType.CHICKEN).toString(), 3); - WeakAutomataCoreRecord husbandrySoulRecord = new WeakAutomataCoreRecord(husbandrySouls, Items.HUSBANDRY_AUTOMATA_CORE.get()); + WeakAutomataCoreRecord husbandrySoulRecord = new WeakAutomataCoreRecord(husbandrySouls, APItems.HUSBANDRY_AUTOMATA_CORE.get()); endSoulRecord.ingredients.keySet().forEach(entityType -> AUTOMATA_CORE_REGISTRY.put(entityType, endSoulRecord)); husbandrySoulRecord.ingredients.keySet().forEach(entityType -> AUTOMATA_CORE_REGISTRY.put(entityType, husbandrySoulRecord)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/network/PacketHandler.java b/src/main/java/de/srendi/advancedperipherals/common/network/PacketHandler.java new file mode 100644 index 000000000..94197c83b --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/network/PacketHandler.java @@ -0,0 +1,65 @@ +package de.srendi.advancedperipherals.common.network; + +import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.common.network.base.IPacket; +import net.minecraft.core.BlockPos; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.Level; +import net.minecraftforge.common.util.FakePlayer; +import net.minecraftforge.fml.ModLoadingContext; +import net.minecraftforge.network.NetworkDirection; +import net.minecraftforge.network.NetworkRegistry; +import net.minecraftforge.network.PacketDistributor; +import net.minecraftforge.network.simple.SimpleChannel; + +import java.util.Optional; +import java.util.function.Function; + +public class PacketHandler { + + private static final String PROTOCOL_VERSION = ModLoadingContext.get().getActiveContainer().getModInfo().getVersion().toString(); + + public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel(new ResourceLocation(AdvancedPeripherals.MOD_ID, "main_channel"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals); + + private static int index = 0; + + public static void init() { + + } + + public static void registerServerToClient(Class packet, Function decode) { + CHANNEL.registerMessage(index++, packet, IPacket::encode, decode, IPacket::handle, Optional.of(NetworkDirection.PLAY_TO_CLIENT)); + } + + public static void registerClientToServer(Class packet, Function decode) { + CHANNEL.registerMessage(index++, packet, IPacket::encode, decode, IPacket::handle, Optional.of(NetworkDirection.PLAY_TO_SERVER)); + } + + public static void sendToClient(Object packet, ServerPlayer player) { + + CHANNEL.sendTo(packet, player.connection.getConnection(), NetworkDirection.PLAY_TO_CLIENT); + } + + public static void sendToServer(Object packet) { + CHANNEL.sendToServer(packet); + } + + public static void sendTo(Object packet, ServerPlayer player) { + if (!(player instanceof FakePlayer)) { + CHANNEL.sendTo(packet, player.connection.getConnection(), NetworkDirection.PLAY_TO_CLIENT); + } + } + + public static void sendToAllTracking(Object packet, Level world, BlockPos pos) { + if (world instanceof ServerLevel) { + + ((ServerLevel) world).getChunkSource().chunkMap.getPlayers(new ChunkPos(pos), false).forEach(p -> sendTo(packet, p)); + } else { + CHANNEL.send(PacketDistributor.TRACKING_CHUNK.with(() -> world.getChunk(pos.getX() >> 4, pos.getZ() >> 4)), packet); + } + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/network/base/IPacket.java b/src/main/java/de/srendi/advancedperipherals/common/network/base/IPacket.java new file mode 100644 index 000000000..1374f5bff --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/network/base/IPacket.java @@ -0,0 +1,20 @@ +package de.srendi.advancedperipherals.common.network.base; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraftforge.network.NetworkEvent; + +import java.util.function.Supplier; + +public interface IPacket { + + static void handle(MSG message, Supplier context) { + NetworkEvent.Context ctx = context.get(); + ctx.enqueueWork(() -> message.handle(ctx)); + ctx.setPacketHandled(true); + } + + void handle(NetworkEvent.Context context); + + void encode(FriendlyByteBuf buffer); + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java new file mode 100644 index 000000000..975de6300 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java @@ -0,0 +1,40 @@ +package de.srendi.advancedperipherals.common.setup; + +import com.google.common.collect.Sets; +import de.srendi.advancedperipherals.common.blocks.blockentities.BlockReaderEntity; +import de.srendi.advancedperipherals.common.blocks.blockentities.ChatBoxEnity; +import de.srendi.advancedperipherals.common.blocks.blockentities.ColonyIntegratorEntity; +import de.srendi.advancedperipherals.common.blocks.blockentities.EnergyDetectorEntity; +import de.srendi.advancedperipherals.common.blocks.blockentities.EnvironmentDetectorEntity; +import de.srendi.advancedperipherals.common.blocks.blockentities.GeoScannerEntity; +import de.srendi.advancedperipherals.common.blocks.blockentities.InventoryManagerEntity; +import de.srendi.advancedperipherals.common.blocks.blockentities.MeBridgeEntity; +import de.srendi.advancedperipherals.common.blocks.blockentities.NBTStorageEntity; +import de.srendi.advancedperipherals.common.blocks.blockentities.PlayerDetectorEntity; +import de.srendi.advancedperipherals.common.blocks.blockentities.RedstoneIntegratorEntity; +import de.srendi.advancedperipherals.common.blocks.blockentities.RsBridgeEntity; +import de.srendi.advancedperipherals.common.blocks.blockentities.SmartGlassesControllerEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraftforge.fml.ModList; +import net.minecraftforge.registries.RegistryObject; + +public class APBlockEntityTypes { + + static void register() { + } + + public static final RegistryObject> CHAT_BOX = APRegistration.TILE_ENTITIES.register("chat_box", () -> new BlockEntityType<>(ChatBoxEnity::new, Sets.newHashSet(APBlocks.CHAT_BOX.get()), null)); + public static final RegistryObject> ENVIRONMENT_DETECTOR = APRegistration.TILE_ENTITIES.register("environment_detector", () -> new BlockEntityType<>(EnvironmentDetectorEntity::new, Sets.newHashSet(APBlocks.ENVIRONMENT_DETECTOR.get()), null)); + public static final RegistryObject> PLAYER_DETECTOR = APRegistration.TILE_ENTITIES.register("player_detector", () -> new BlockEntityType<>(PlayerDetectorEntity::new, Sets.newHashSet(APBlocks.PLAYER_DETECTOR.get()), null)); + public static final RegistryObject> ME_BRIDGE = ModList.get().isLoaded("ae2") ? APRegistration.TILE_ENTITIES.register("me_bridge", () -> new BlockEntityType<>(MeBridgeEntity::new, Sets.newHashSet(APBlocks.ME_BRIDGE.get()), null)) : null; + public static final RegistryObject> RS_BRIDGE = ModList.get().isLoaded("refinedstorage") ? APRegistration.TILE_ENTITIES.register("rs_bridge", () -> new BlockEntityType<>(RsBridgeEntity::new, Sets.newHashSet(APBlocks.RS_BRIDGE.get()), null)) : null; + public static final RegistryObject> ENERGY_DETECTOR = APRegistration.TILE_ENTITIES.register("energy_detector", () -> new BlockEntityType<>(EnergyDetectorEntity::new, Sets.newHashSet(APBlocks.ENERGY_DETECTOR.get()), null)); + public static final RegistryObject> AR_CONTROLLER = APRegistration.TILE_ENTITIES.register("ar_controller", () -> new BlockEntityType<>(SmartGlassesControllerEntity::new, Sets.newHashSet(APBlocks.AR_CONTROLLER.get()), null)); + public static final RegistryObject> INVENTORY_MANAGER = APRegistration.TILE_ENTITIES.register("inventory_manager", () -> new BlockEntityType<>(InventoryManagerEntity::new, Sets.newHashSet(APBlocks.INVENTORY_MANAGER.get()), null)); + public static final RegistryObject> REDSTONE_INTEGRATOR = APRegistration.TILE_ENTITIES.register("redstone_integrator", () -> new BlockEntityType<>(RedstoneIntegratorEntity::new, Sets.newHashSet(APBlocks.REDSTONE_INTEGRATOR.get()), null)); + public static final RegistryObject> BLOCK_READER = APRegistration.TILE_ENTITIES.register("block_reader", () -> new BlockEntityType<>(BlockReaderEntity::new, Sets.newHashSet(APBlocks.BLOCK_READER.get()), null)); + public static final RegistryObject> GEO_SCANNER = APRegistration.TILE_ENTITIES.register("geo_scanner", () -> new BlockEntityType<>(GeoScannerEntity::new, Sets.newHashSet(APBlocks.GEO_SCANNER.get()), null)); + public static final RegistryObject> COLONY_INTEGRATOR = APRegistration.TILE_ENTITIES.register("colony_integrator", () -> new BlockEntityType<>(ColonyIntegratorEntity::new, Sets.newHashSet(APBlocks.COLONY_INTEGRATOR.get()), null)); + public static final RegistryObject> NBT_STORAGE = APRegistration.TILE_ENTITIES.register("nbt_storage", () -> new BlockEntityType<>(NBTStorageEntity::new, Sets.newHashSet(APBlocks.NBT_STORAGE.get()), null)); + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java new file mode 100644 index 000000000..2aaefcd61 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java @@ -0,0 +1,54 @@ +package de.srendi.advancedperipherals.common.setup; + +import de.srendi.advancedperipherals.common.blocks.PlayerDetectorBlock; +import de.srendi.advancedperipherals.common.blocks.RedstoneIntegratorBlock; +import de.srendi.advancedperipherals.common.blocks.base.APBlockEntityBlock; +import de.srendi.advancedperipherals.common.blocks.base.BaseBlock; +import de.srendi.advancedperipherals.common.configuration.APConfig; +import de.srendi.advancedperipherals.common.items.APBlockItem; +import net.minecraft.core.BlockPos; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.fml.ModList; +import net.minecraftforge.registries.RegistryObject; + +import java.util.function.Supplier; + +public class APBlocks { + + static void register() { + } + + public static final RegistryObject ENVIRONMENT_DETECTOR = register("environment_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.ENVIRONMENT_DETECTOR, false), () -> new APBlockItem(APBlocks.ENVIRONMENT_DETECTOR.get(), CCRegistration.ID.ENVIRONMENT_TURTLE, CCRegistration.ID.ENVIRONMENT_POCKET, APConfig.PERIPHERALS_CONFIG.enableEnvironmentDetector::get)); + public static final RegistryObject CHAT_BOX = register("chat_box", () -> new APBlockEntityBlock<>(APBlockEntityTypes.CHAT_BOX, true), () -> new APBlockItem(APBlocks.CHAT_BOX.get(), CCRegistration.ID.CHATTY_TURTLE, CCRegistration.ID.CHATTY_POCKET, APConfig.PERIPHERALS_CONFIG.enableChatBox::get)); + public static final RegistryObject PLAYER_DETECTOR = register("player_detector", PlayerDetectorBlock::new, () -> new APBlockItem(APBlocks.PLAYER_DETECTOR.get(), CCRegistration.ID.PLAYER_TURTLE, CCRegistration.ID.PLAYER_POCKET, APConfig.PERIPHERALS_CONFIG.enablePlayerDetector::get)); + public static final RegistryObject ME_BRIDGE = register("me_bridge", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("ae2") ? APBlockEntityTypes.ME_BRIDGE : null, ModList.get().isLoaded("ae2")), () -> new APBlockItem(APBlocks.ME_BRIDGE.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableMEBridge::get)); + public static final RegistryObject RS_BRIDGE = register("rs_bridge", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("refinedstorage") ? APBlockEntityTypes.RS_BRIDGE : null, false), () -> new APBlockItem(APBlocks.RS_BRIDGE.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableRSBridge::get)); + public static final RegistryObject ENERGY_DETECTOR = register("energy_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.ENERGY_DETECTOR, true), () -> new APBlockItem(APBlocks.ENERGY_DETECTOR.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableEnergyDetector::get)); + public static final RegistryObject PERIPHERAL_CASING = register("peripheral_casing", BaseBlock::new, () -> new APBlockItem(APBlocks.PERIPHERAL_CASING.get(), new Item.Properties().stacksTo(16), null, null, () -> true)); + public static final RegistryObject AR_CONTROLLER = register("ar_controller", () -> new APBlockEntityBlock<>(APBlockEntityTypes.AR_CONTROLLER, false), () -> new APBlockItem(APBlocks.AR_CONTROLLER.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableSmartGlasses::get)); + public static final RegistryObject INVENTORY_MANAGER = register("inventory_manager", () -> new APBlockEntityBlock<>(APBlockEntityTypes.INVENTORY_MANAGER, false), () -> new APBlockItem(APBlocks.INVENTORY_MANAGER.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableInventoryManager::get)); + public static final RegistryObject REDSTONE_INTEGRATOR = register("redstone_integrator", RedstoneIntegratorBlock::new, () -> new APBlockItem(APBlocks.REDSTONE_INTEGRATOR.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableRedstoneIntegrator::get)); + public static final RegistryObject BLOCK_READER = register("block_reader", () -> new APBlockEntityBlock<>(APBlockEntityTypes.BLOCK_READER, true), () -> new APBlockItem(APBlocks.BLOCK_READER.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableBlockReader::get)); + public static final RegistryObject GEO_SCANNER = register("geo_scanner", () -> new APBlockEntityBlock<>(APBlockEntityTypes.GEO_SCANNER, false), () -> new APBlockItem(APBlocks.GEO_SCANNER.get(), CCRegistration.ID.GEOSCANNER_TURTLE, CCRegistration.ID.GEOSCANNER_POCKET, APConfig.PERIPHERALS_CONFIG.enableGeoScanner::get)); + public static final RegistryObject COLONY_INTEGRATOR = register("colony_integrator", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("minecolonies") ? APBlockEntityTypes.COLONY_INTEGRATOR : null, false), () -> new APBlockItem(APBlocks.COLONY_INTEGRATOR.get(), null, CCRegistration.ID.COLONY_POCKET, APConfig.PERIPHERALS_CONFIG.enableColonyIntegrator::get)); + public static final RegistryObject NBT_STORAGE = register("nbt_storage", () -> new APBlockEntityBlock<>(APBlockEntityTypes.NBT_STORAGE, false), () -> new APBlockItem(APBlocks.NBT_STORAGE.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableNBTStorage::get)); + + private static RegistryObject registerNoItem(String name, Supplier block) { + return APRegistration.BLOCKS.register(name, block); + } + + private static RegistryObject register(String name, Supplier block, Supplier blockItem) { + RegistryObject registryObject = registerNoItem(name, block); + APRegistration.ITEMS.register(name, blockItem); + return registryObject; + } + + public static boolean never(BlockState state, BlockGetter level, BlockPos pos) { + return false; + } + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/ContainerTypes.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java similarity index 77% rename from src/main/java/de/srendi/advancedperipherals/common/setup/ContainerTypes.java rename to src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java index a1321805e..579a2a52d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/ContainerTypes.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java @@ -7,9 +7,9 @@ import net.minecraftforge.common.extensions.IForgeMenuType; import net.minecraftforge.registries.RegistryObject; -public class ContainerTypes { +public class APContainerTypes { - public static final RegistryObject> INVENTORY_MANAGER_CONTAINER = Registration.CONTAINER_TYPES.register("memory_card_container", () -> IForgeMenuType.create((windowId, inv, data) -> { + public static final RegistryObject> INVENTORY_MANAGER_CONTAINER = APRegistration.CONTAINER_TYPES.register("memory_card_container", () -> IForgeMenuType.create((windowId, inv, data) -> { BlockPos pos = data.readBlockPos(); Level level = inv.player.getCommandSenderWorld(); return new InventoryManagerContainer(windowId, inv, pos, level); diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java new file mode 100644 index 000000000..f53d49cc9 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java @@ -0,0 +1,40 @@ +package de.srendi.advancedperipherals.common.setup; + +import de.srendi.advancedperipherals.common.configuration.APConfig; +import de.srendi.advancedperipherals.common.items.APItem; +import de.srendi.advancedperipherals.common.items.MemoryCardItem; +import de.srendi.advancedperipherals.common.items.SmartGlassesItem; +import de.srendi.advancedperipherals.common.items.WeakAutomataCore; +import net.minecraft.world.item.ArmorMaterials; +import net.minecraft.world.item.Item; +import net.minecraftforge.registries.RegistryObject; + +public class APItems { + + public static final RegistryObject CHUNK_CONTROLLER = APRegistration.ITEMS.register("chunk_controller", () -> new APItem(new Item.Properties().stacksTo(16), CCRegistration.ID.CHUNKY_TURTLE, null, APConfig.PERIPHERALS_CONFIG.enableChunkyTurtle::get)); + + public static final RegistryObject SMART_GLASSES = APRegistration.ITEMS.register("smart_glasses", ()-> new SmartGlassesItem(ArmorMaterials.CHAIN)); + + public static final RegistryObject SMART_GLASSES_NETHERITE = APRegistration.ITEMS.register("smart_glasses_netherite", ()-> new SmartGlassesItem(ArmorMaterials.NETHERITE)); + + public static final RegistryObject COMPUTER_TOOL = APRegistration.ITEMS.register("computer_tool", () -> new APItem(new Item.Properties().stacksTo(1), null, null, () -> true)); + + public static final RegistryObject MEMORY_CARD = APRegistration.ITEMS.register("memory_card", MemoryCardItem::new); + + public static final RegistryObject END_AUTOMATA_CORE = APRegistration.ITEMS.register("end_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), CCRegistration.ID.END_AUTOMATA, null, APConfig.METAPHYSICS_CONFIG.enableEndAutomataCore)); + + public static final RegistryObject HUSBANDRY_AUTOMATA_CORE = APRegistration.ITEMS.register("husbandry_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), CCRegistration.ID.WEAK_AUTOMATA, null, APConfig.METAPHYSICS_CONFIG.enableHusbandryAutomataCore)); + + public static final RegistryObject WEAK_AUTOMATA_CORE = APRegistration.ITEMS.register("weak_automata_core", () -> new WeakAutomataCore(new Item.Properties().stacksTo(1), CCRegistration.ID.WEAK_AUTOMATA, null)); + + public static final RegistryObject OVERPOWERED_WEAK_AUTOMATA_CORE = APRegistration.ITEMS.register("overpowered_weak_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), CCRegistration.ID.OP_WEAK_AUTOMATA, null, APConfig.METAPHYSICS_CONFIG.enableWeakAutomataCore)); + + public static final RegistryObject OVERPOWERED_END_AUTOMATA_CORE = APRegistration.ITEMS.register("overpowered_end_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), CCRegistration.ID.OP_END_AUTOMATA, null, APConfig.METAPHYSICS_CONFIG.enableEndAutomataCore)); + + public static final RegistryObject OVERPOWERED_HUSBANDRY_AUTOMATA_CORE = APRegistration.ITEMS.register("overpowered_husbandry_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), CCRegistration.ID.OP_HUSBANDRY_AUTOMATA, null, APConfig.METAPHYSICS_CONFIG.enableHusbandryAutomataCore)); + + public static void register() { + } + + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/Registration.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APRegistration.java similarity index 92% rename from src/main/java/de/srendi/advancedperipherals/common/setup/Registration.java rename to src/main/java/de/srendi/advancedperipherals/common/setup/APRegistration.java index d80a33c6b..f8d25961a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/Registration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APRegistration.java @@ -14,7 +14,7 @@ import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; -public class Registration { +public class APRegistration { public static final DeferredRegister BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, AdvancedPeripherals.MOD_ID); public static final DeferredRegister ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, AdvancedPeripherals.MOD_ID); @@ -36,11 +36,11 @@ public static void register() { TURTLE_SERIALIZER.register(modEventBus); POCKET_SERIALIZER.register(modEventBus); - Blocks.register(); - BlockEntityTypes.register(); - Items.register(); - ContainerTypes.register(); - Villagers.register(); + APBlocks.register(); + APBlockEntityTypes.register(); + APItems.register(); + APContainerTypes.register(); + APVillagers.register(); CCRegistration.register(); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APVillagers.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APVillagers.java new file mode 100644 index 000000000..823d40cdc --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APVillagers.java @@ -0,0 +1,20 @@ +package de.srendi.advancedperipherals.common.setup; + +import com.google.common.collect.ImmutableSet; +import dan200.computercraft.shared.Registry; +import de.srendi.advancedperipherals.AdvancedPeripherals; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.entity.ai.village.poi.PoiType; +import net.minecraft.world.entity.npc.VillagerProfession; +import net.minecraftforge.registries.RegistryObject; + +public class APVillagers { + + public static final RegistryObject COMPUTER_SCIENTIST_POI = APRegistration.POI_TYPES.register("computer_scientist", () -> new PoiType(ImmutableSet.copyOf(Registry.ModBlocks.COMPUTER_ADVANCED.get().getStateDefinition().getPossibleStates()), 1, 1)); + + public static final RegistryObject COMPUTER_SCIENTIST = APRegistration.VILLAGER_PROFESSIONS.register("computer_scientist", () -> new VillagerProfession(AdvancedPeripherals.MOD_ID + ":computer_scientist", holder -> holder.is(COMPUTER_SCIENTIST_POI.getKey()), holder -> holder.is(COMPUTER_SCIENTIST_POI.getKey()), ImmutableSet.of(), ImmutableSet.of(Registry.ModBlocks.COMPUTER_ADVANCED.get()), SoundEvents.VILLAGER_WORK_TOOLSMITH)); + + public static void register() { + } + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/BlockEntityTypes.java b/src/main/java/de/srendi/advancedperipherals/common/setup/BlockEntityTypes.java deleted file mode 100644 index 3f15b0b0f..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/BlockEntityTypes.java +++ /dev/null @@ -1,28 +0,0 @@ -package de.srendi.advancedperipherals.common.setup; - -import com.google.common.collect.Sets; -import de.srendi.advancedperipherals.common.blocks.blockentities.*; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraftforge.fml.ModList; -import net.minecraftforge.registries.RegistryObject; - -public class BlockEntityTypes { - - static void register() { - } - - public static final RegistryObject> CHAT_BOX = Registration.TILE_ENTITIES.register("chat_box", () -> new BlockEntityType<>(ChatBoxEnity::new, Sets.newHashSet(Blocks.CHAT_BOX.get()), null)); - public static final RegistryObject> ENVIRONMENT_DETECTOR = Registration.TILE_ENTITIES.register("environment_detector", () -> new BlockEntityType<>(EnvironmentDetectorEntity::new, Sets.newHashSet(Blocks.ENVIRONMENT_DETECTOR.get()), null)); - public static final RegistryObject> PLAYER_DETECTOR = Registration.TILE_ENTITIES.register("player_detector", () -> new BlockEntityType<>(PlayerDetectorEntity::new, Sets.newHashSet(Blocks.PLAYER_DETECTOR.get()), null)); - public static final RegistryObject> ME_BRIDGE = ModList.get().isLoaded("ae2") ? Registration.TILE_ENTITIES.register("me_bridge", () -> new BlockEntityType<>(MeBridgeEntity::new, Sets.newHashSet(Blocks.ME_BRIDGE.get()), null)) : null; - public static final RegistryObject> RS_BRIDGE = ModList.get().isLoaded("refinedstorage") ? Registration.TILE_ENTITIES.register("rs_bridge", () -> new BlockEntityType<>(RsBridgeEntity::new, Sets.newHashSet(Blocks.RS_BRIDGE.get()), null)) : null; - public static final RegistryObject> ENERGY_DETECTOR = Registration.TILE_ENTITIES.register("energy_detector", () -> new BlockEntityType<>(EnergyDetectorEntity::new, Sets.newHashSet(Blocks.ENERGY_DETECTOR.get()), null)); - public static final RegistryObject> AR_CONTROLLER = Registration.TILE_ENTITIES.register("ar_controller", () -> new BlockEntityType<>(ARControllerEntity::new, Sets.newHashSet(Blocks.AR_CONTROLLER.get()), null)); - public static final RegistryObject> INVENTORY_MANAGER = Registration.TILE_ENTITIES.register("inventory_manager", () -> new BlockEntityType<>(InventoryManagerEntity::new, Sets.newHashSet(Blocks.INVENTORY_MANAGER.get()), null)); - public static final RegistryObject> REDSTONE_INTEGRATOR = Registration.TILE_ENTITIES.register("redstone_integrator", () -> new BlockEntityType<>(RedstoneIntegratorEntity::new, Sets.newHashSet(Blocks.REDSTONE_INTEGRATOR.get()), null)); - public static final RegistryObject> BLOCK_READER = Registration.TILE_ENTITIES.register("block_reader", () -> new BlockEntityType<>(BlockReaderEntity::new, Sets.newHashSet(Blocks.BLOCK_READER.get()), null)); - public static final RegistryObject> GEO_SCANNER = Registration.TILE_ENTITIES.register("geo_scanner", () -> new BlockEntityType<>(GeoScannerEntity::new, Sets.newHashSet(Blocks.GEO_SCANNER.get()), null)); - public static final RegistryObject> COLONY_INTEGRATOR = Registration.TILE_ENTITIES.register("colony_integrator", () -> new BlockEntityType<>(ColonyIntegratorEntity::new, Sets.newHashSet(Blocks.COLONY_INTEGRATOR.get()), null)); - public static final RegistryObject> NBT_STORAGE = Registration.TILE_ENTITIES.register("nbt_storage", () -> new BlockEntityType<>(NBTStorageEntity::new, Sets.newHashSet(Blocks.NBT_STORAGE.get()), null)); - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/Blocks.java b/src/main/java/de/srendi/advancedperipherals/common/setup/Blocks.java deleted file mode 100644 index aa5ea12e8..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/Blocks.java +++ /dev/null @@ -1,54 +0,0 @@ -package de.srendi.advancedperipherals.common.setup; - -import de.srendi.advancedperipherals.common.blocks.PlayerDetectorBlock; -import de.srendi.advancedperipherals.common.blocks.RedstoneIntegratorBlock; -import de.srendi.advancedperipherals.common.blocks.base.APBlockEntityBlock; -import de.srendi.advancedperipherals.common.blocks.base.BaseBlock; -import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.items.APBlockItem; -import net.minecraft.core.BlockPos; -import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.Item; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.fml.ModList; -import net.minecraftforge.registries.RegistryObject; - -import java.util.function.Supplier; - -public class Blocks { - - static void register() { - } - - public static final RegistryObject ENVIRONMENT_DETECTOR = register("environment_detector", () -> new APBlockEntityBlock<>(BlockEntityTypes.ENVIRONMENT_DETECTOR, false), () -> new APBlockItem(Blocks.ENVIRONMENT_DETECTOR.get(), CCRegistration.ID.ENVIRONMENT_TURTLE, CCRegistration.ID.ENVIRONMENT_POCKET, APConfig.PERIPHERALS_CONFIG.enableEnvironmentDetector::get)); - public static final RegistryObject CHAT_BOX = register("chat_box", () -> new APBlockEntityBlock<>(BlockEntityTypes.CHAT_BOX, true), () -> new APBlockItem(Blocks.CHAT_BOX.get(), CCRegistration.ID.CHATTY_TURTLE, CCRegistration.ID.CHATTY_POCKET, APConfig.PERIPHERALS_CONFIG.enableChatBox::get)); - public static final RegistryObject PLAYER_DETECTOR = register("player_detector", PlayerDetectorBlock::new, () -> new APBlockItem(Blocks.PLAYER_DETECTOR.get(), CCRegistration.ID.PLAYER_TURTLE, CCRegistration.ID.PLAYER_POCKET, APConfig.PERIPHERALS_CONFIG.enablePlayerDetector::get)); - public static final RegistryObject ME_BRIDGE = register("me_bridge", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("ae2") ? BlockEntityTypes.ME_BRIDGE : null, ModList.get().isLoaded("ae2")), () -> new APBlockItem(Blocks.ME_BRIDGE.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableMEBridge::get)); - public static final RegistryObject RS_BRIDGE = register("rs_bridge", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("refinedstorage") ? BlockEntityTypes.RS_BRIDGE : null, false), () -> new APBlockItem(Blocks.RS_BRIDGE.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableRSBridge::get)); - public static final RegistryObject ENERGY_DETECTOR = register("energy_detector", () -> new APBlockEntityBlock<>(BlockEntityTypes.ENERGY_DETECTOR, true), () -> new APBlockItem(Blocks.ENERGY_DETECTOR.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableEnergyDetector::get)); - public static final RegistryObject PERIPHERAL_CASING = register("peripheral_casing", BaseBlock::new, () -> new APBlockItem(Blocks.PERIPHERAL_CASING.get(), new Item.Properties().stacksTo(16), null, null, () -> true)); - public static final RegistryObject AR_CONTROLLER = register("ar_controller", () -> new APBlockEntityBlock<>(BlockEntityTypes.AR_CONTROLLER, false), () -> new APBlockItem(Blocks.AR_CONTROLLER.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableARGoggles::get)); - public static final RegistryObject INVENTORY_MANAGER = register("inventory_manager", () -> new APBlockEntityBlock<>(BlockEntityTypes.INVENTORY_MANAGER, false), () -> new APBlockItem(Blocks.INVENTORY_MANAGER.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableInventoryManager::get)); - public static final RegistryObject REDSTONE_INTEGRATOR = register("redstone_integrator", RedstoneIntegratorBlock::new, () -> new APBlockItem(Blocks.REDSTONE_INTEGRATOR.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableRedstoneIntegrator::get)); - public static final RegistryObject BLOCK_READER = register("block_reader", () -> new APBlockEntityBlock<>(BlockEntityTypes.BLOCK_READER, true), () -> new APBlockItem(Blocks.BLOCK_READER.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableBlockReader::get)); - public static final RegistryObject GEO_SCANNER = register("geo_scanner", () -> new APBlockEntityBlock<>(BlockEntityTypes.GEO_SCANNER, false), () -> new APBlockItem(Blocks.GEO_SCANNER.get(), CCRegistration.ID.GEOSCANNER_TURTLE, CCRegistration.ID.GEOSCANNER_POCKET, APConfig.PERIPHERALS_CONFIG.enableGeoScanner::get)); - public static final RegistryObject COLONY_INTEGRATOR = register("colony_integrator", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("minecolonies") ? BlockEntityTypes.COLONY_INTEGRATOR : null, false), () -> new APBlockItem(Blocks.COLONY_INTEGRATOR.get(), null, CCRegistration.ID.COLONY_POCKET, APConfig.PERIPHERALS_CONFIG.enableColonyIntegrator::get)); - public static final RegistryObject NBT_STORAGE = register("nbt_storage", () -> new APBlockEntityBlock<>(BlockEntityTypes.NBT_STORAGE, false), () -> new APBlockItem(Blocks.NBT_STORAGE.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableNBTStorage::get)); - - private static RegistryObject registerNoItem(String name, Supplier block) { - return Registration.BLOCKS.register(name, block); - } - - private static RegistryObject register(String name, Supplier block, Supplier blockItem) { - RegistryObject registryObject = registerNoItem(name, block); - Registration.ITEMS.register(name, blockItem); - return registryObject; - } - - public static boolean never(BlockState state, BlockGetter level, BlockPos pos) { - return false; - } - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/CCRegistration.java b/src/main/java/de/srendi/advancedperipherals/common/setup/CCRegistration.java index 2368a2be6..b75056291 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/CCRegistration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/CCRegistration.java @@ -5,9 +5,23 @@ import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.addons.computercraft.integrations.IntegrationPeripheralProvider; -import de.srendi.advancedperipherals.common.addons.computercraft.pocket.*; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.*; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.*; +import de.srendi.advancedperipherals.common.addons.computercraft.pocket.PocketChatBoxUpgrade; +import de.srendi.advancedperipherals.common.addons.computercraft.pocket.PocketColonyIntegratorUpgrade; +import de.srendi.advancedperipherals.common.addons.computercraft.pocket.PocketEnvironmentUpgrade; +import de.srendi.advancedperipherals.common.addons.computercraft.pocket.PocketGeoScannerUpgrade; +import de.srendi.advancedperipherals.common.addons.computercraft.pocket.PocketPlayerDetectorUpgrade; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.TurtleChatBoxUpgrade; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.TurtleChunkyUpgrade; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.TurtleCompassUpgrade; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.TurtleEnvironmentDetectorUpgrade; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.TurtleGeoScannerUpgrade; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.TurtlePlayerDetectorUpgrade; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.EndAutomata; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.HusbandryAutomata; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.OverpoweredEndAutomata; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.OverpoweredHusbandryAutomata; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.OverpoweredWeakAutomata; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.WeakAutomata; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.registries.RegistryObject; @@ -15,24 +29,24 @@ @Mod.EventBusSubscriber(modid = AdvancedPeripherals.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) public class CCRegistration { - public static final RegistryObject> CHAT_BOX_TURTLE = Registration.TURTLE_SERIALIZER.register(ID.CHATTY_TURTLE.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(TurtleChatBoxUpgrade::new)); - public static final RegistryObject> PLAYER_DETECTOR_TURTLE = Registration.TURTLE_SERIALIZER.register(ID.PLAYER_TURTLE.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(TurtlePlayerDetectorUpgrade::new)); - public static final RegistryObject> ENVIRONMENT_TURTLE = Registration.TURTLE_SERIALIZER.register(ID.ENVIRONMENT_TURTLE.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(TurtleEnvironmentDetectorUpgrade::new)); - public static final RegistryObject> CHUNKY_TURTLE = Registration.TURTLE_SERIALIZER.register(ID.CHUNKY_TURTLE.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(TurtleChunkyUpgrade::new)); - public static final RegistryObject> GEO_SCANNER_TURTLE = Registration.TURTLE_SERIALIZER.register(ID.GEOSCANNER_TURTLE.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(TurtleGeoScannerUpgrade::new)); - public static final RegistryObject> COMPASS_TURTLE = Registration.TURTLE_SERIALIZER.register(ID.COMPASS_TURTLE.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(TurtleCompassUpgrade::new)); - public static final RegistryObject> WEAK_TURTLE = Registration.TURTLE_SERIALIZER.register(ID.WEAK_AUTOMATA.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(WeakAutomata::new)); - public static final RegistryObject> END_TURTLE = Registration.TURTLE_SERIALIZER.register(ID.END_AUTOMATA.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(EndAutomata::new)); - public static final RegistryObject> HUSBANDRY_TURTLE = Registration.TURTLE_SERIALIZER.register(ID.HUSBANDRY_AUTOMATA.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(HusbandryAutomata::new)); - public static final RegistryObject> OP_WEAK_TURTLE = Registration.TURTLE_SERIALIZER.register(ID.OP_WEAK_AUTOMATA.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(OverpoweredWeakAutomata::new)); - public static final RegistryObject> OP_END_TURTLE = Registration.TURTLE_SERIALIZER.register(ID.OP_END_AUTOMATA.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(OverpoweredEndAutomata::new)); - public static final RegistryObject> OP_HUSBANDRY_TURTLE = Registration.TURTLE_SERIALIZER.register(ID.OP_HUSBANDRY_AUTOMATA.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(OverpoweredHusbandryAutomata::new)); + public static final RegistryObject> CHAT_BOX_TURTLE = APRegistration.TURTLE_SERIALIZER.register(ID.CHATTY_TURTLE.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(TurtleChatBoxUpgrade::new)); + public static final RegistryObject> PLAYER_DETECTOR_TURTLE = APRegistration.TURTLE_SERIALIZER.register(ID.PLAYER_TURTLE.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(TurtlePlayerDetectorUpgrade::new)); + public static final RegistryObject> ENVIRONMENT_TURTLE = APRegistration.TURTLE_SERIALIZER.register(ID.ENVIRONMENT_TURTLE.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(TurtleEnvironmentDetectorUpgrade::new)); + public static final RegistryObject> CHUNKY_TURTLE = APRegistration.TURTLE_SERIALIZER.register(ID.CHUNKY_TURTLE.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(TurtleChunkyUpgrade::new)); + public static final RegistryObject> GEO_SCANNER_TURTLE = APRegistration.TURTLE_SERIALIZER.register(ID.GEOSCANNER_TURTLE.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(TurtleGeoScannerUpgrade::new)); + public static final RegistryObject> COMPASS_TURTLE = APRegistration.TURTLE_SERIALIZER.register(ID.COMPASS_TURTLE.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(TurtleCompassUpgrade::new)); + public static final RegistryObject> WEAK_TURTLE = APRegistration.TURTLE_SERIALIZER.register(ID.WEAK_AUTOMATA.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(WeakAutomata::new)); + public static final RegistryObject> END_TURTLE = APRegistration.TURTLE_SERIALIZER.register(ID.END_AUTOMATA.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(EndAutomata::new)); + public static final RegistryObject> HUSBANDRY_TURTLE = APRegistration.TURTLE_SERIALIZER.register(ID.HUSBANDRY_AUTOMATA.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(HusbandryAutomata::new)); + public static final RegistryObject> OP_WEAK_TURTLE = APRegistration.TURTLE_SERIALIZER.register(ID.OP_WEAK_AUTOMATA.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(OverpoweredWeakAutomata::new)); + public static final RegistryObject> OP_END_TURTLE = APRegistration.TURTLE_SERIALIZER.register(ID.OP_END_AUTOMATA.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(OverpoweredEndAutomata::new)); + public static final RegistryObject> OP_HUSBANDRY_TURTLE = APRegistration.TURTLE_SERIALIZER.register(ID.OP_HUSBANDRY_AUTOMATA.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(OverpoweredHusbandryAutomata::new)); - public static final RegistryObject> CHAT_BOX_POCKET = Registration.POCKET_SERIALIZER.register(ID.CHATTY_POCKET.getPath(), () -> PocketUpgradeSerialiser.simpleWithCustomItem(PocketChatBoxUpgrade::new)); - public static final RegistryObject> PLAYER_DETECTOR_POCKET = Registration.POCKET_SERIALIZER.register(ID.PLAYER_POCKET.getPath(), () -> PocketUpgradeSerialiser.simpleWithCustomItem(PocketPlayerDetectorUpgrade::new)); - public static final RegistryObject> ENVIRONMENT_POCKET = Registration.POCKET_SERIALIZER.register(ID.ENVIRONMENT_POCKET.getPath(), () -> PocketUpgradeSerialiser.simpleWithCustomItem(PocketEnvironmentUpgrade::new)); - public static final RegistryObject> GEO_SCANNER_POCKET = Registration.POCKET_SERIALIZER.register(ID.GEOSCANNER_POCKET.getPath(), () -> PocketUpgradeSerialiser.simpleWithCustomItem(PocketGeoScannerUpgrade::new)); - public static final RegistryObject> COLONY_POCKET = Registration.POCKET_SERIALIZER.register(ID.COLONY_POCKET.getPath(), () -> PocketUpgradeSerialiser.simpleWithCustomItem(PocketColonyIntegratorUpgrade::new)); + public static final RegistryObject> CHAT_BOX_POCKET = APRegistration.POCKET_SERIALIZER.register(ID.CHATTY_POCKET.getPath(), () -> PocketUpgradeSerialiser.simpleWithCustomItem(PocketChatBoxUpgrade::new)); + public static final RegistryObject> PLAYER_DETECTOR_POCKET = APRegistration.POCKET_SERIALIZER.register(ID.PLAYER_POCKET.getPath(), () -> PocketUpgradeSerialiser.simpleWithCustomItem(PocketPlayerDetectorUpgrade::new)); + public static final RegistryObject> ENVIRONMENT_POCKET = APRegistration.POCKET_SERIALIZER.register(ID.ENVIRONMENT_POCKET.getPath(), () -> PocketUpgradeSerialiser.simpleWithCustomItem(PocketEnvironmentUpgrade::new)); + public static final RegistryObject> GEO_SCANNER_POCKET = APRegistration.POCKET_SERIALIZER.register(ID.GEOSCANNER_POCKET.getPath(), () -> PocketUpgradeSerialiser.simpleWithCustomItem(PocketGeoScannerUpgrade::new)); + public static final RegistryObject> COLONY_POCKET = APRegistration.POCKET_SERIALIZER.register(ID.COLONY_POCKET.getPath(), () -> PocketUpgradeSerialiser.simpleWithCustomItem(PocketColonyIntegratorUpgrade::new)); public static IntegrationPeripheralProvider integrationPeripheralProvider; diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/Items.java b/src/main/java/de/srendi/advancedperipherals/common/setup/Items.java deleted file mode 100644 index dcc4dbf2c..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/Items.java +++ /dev/null @@ -1,37 +0,0 @@ -package de.srendi.advancedperipherals.common.setup; - -import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.items.APItem; -import de.srendi.advancedperipherals.common.items.ARGogglesItem; -import de.srendi.advancedperipherals.common.items.MemoryCardItem; -import de.srendi.advancedperipherals.common.items.WeakAutomataCore; -import net.minecraft.world.item.Item; -import net.minecraftforge.registries.RegistryObject; - -public class Items { - - public static final RegistryObject CHUNK_CONTROLLER = Registration.ITEMS.register("chunk_controller", () -> new APItem(new Item.Properties().stacksTo(16), CCRegistration.ID.CHUNKY_TURTLE, null, APConfig.PERIPHERALS_CONFIG.enableChunkyTurtle::get)); - - public static final RegistryObject AR_GOGGLES = Registration.ITEMS.register("ar_goggles", ARGogglesItem::new); - - public static final RegistryObject COMPUTER_TOOL = Registration.ITEMS.register("computer_tool", () -> new APItem(new Item.Properties().stacksTo(1), null, null, () -> true)); - - public static final RegistryObject MEMORY_CARD = Registration.ITEMS.register("memory_card", MemoryCardItem::new); - - public static final RegistryObject END_AUTOMATA_CORE = Registration.ITEMS.register("end_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), CCRegistration.ID.END_AUTOMATA, null, APConfig.METAPHYSICS_CONFIG.enableEndAutomataCore)); - - public static final RegistryObject HUSBANDRY_AUTOMATA_CORE = Registration.ITEMS.register("husbandry_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), CCRegistration.ID.WEAK_AUTOMATA, null, APConfig.METAPHYSICS_CONFIG.enableHusbandryAutomataCore)); - - public static final RegistryObject WEAK_AUTOMATA_CORE = Registration.ITEMS.register("weak_automata_core", () -> new WeakAutomataCore(new Item.Properties().stacksTo(1), CCRegistration.ID.WEAK_AUTOMATA, null)); - - public static final RegistryObject OVERPOWERED_WEAK_AUTOMATA_CORE = Registration.ITEMS.register("overpowered_weak_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), CCRegistration.ID.OP_WEAK_AUTOMATA, null, APConfig.METAPHYSICS_CONFIG.enableWeakAutomataCore)); - - public static final RegistryObject OVERPOWERED_END_AUTOMATA_CORE = Registration.ITEMS.register("overpowered_end_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), CCRegistration.ID.OP_END_AUTOMATA, null, APConfig.METAPHYSICS_CONFIG.enableEndAutomataCore)); - - public static final RegistryObject OVERPOWERED_HUSBANDRY_AUTOMATA_CORE = Registration.ITEMS.register("overpowered_husbandry_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), CCRegistration.ID.OP_HUSBANDRY_AUTOMATA, null, APConfig.METAPHYSICS_CONFIG.enableHusbandryAutomataCore)); - - public static void register() { - } - - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/Villagers.java b/src/main/java/de/srendi/advancedperipherals/common/setup/Villagers.java deleted file mode 100644 index 445c5b227..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/Villagers.java +++ /dev/null @@ -1,20 +0,0 @@ -package de.srendi.advancedperipherals.common.setup; - -import com.google.common.collect.ImmutableSet; -import dan200.computercraft.shared.Registry; -import de.srendi.advancedperipherals.AdvancedPeripherals; -import net.minecraft.sounds.SoundEvents; -import net.minecraft.world.entity.ai.village.poi.PoiType; -import net.minecraft.world.entity.npc.VillagerProfession; -import net.minecraftforge.registries.RegistryObject; - -public class Villagers { - - public static final RegistryObject COMPUTER_SCIENTIST_POI = Registration.POI_TYPES.register("computer_scientist", () -> new PoiType(ImmutableSet.copyOf(Registry.ModBlocks.COMPUTER_ADVANCED.get().getStateDefinition().getPossibleStates()), 1, 1)); - - public static final RegistryObject COMPUTER_SCIENTIST = Registration.VILLAGER_PROFESSIONS.register("computer_scientist", () -> new VillagerProfession(AdvancedPeripherals.MOD_ID + ":computer_scientist", holder -> holder.is(COMPUTER_SCIENTIST_POI.getKey()), holder -> holder.is(COMPUTER_SCIENTIST_POI.getKey()), ImmutableSet.of(), ImmutableSet.of(Registry.ModBlocks.COMPUTER_ADVANCED.get()), SoundEvents.VILLAGER_WORK_TOOLSMITH)); - - public static void register() { - } - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrades.java b/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrades.java index ad18d8046..89672b9c5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrades.java +++ b/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrades.java @@ -2,10 +2,10 @@ import dan200.computercraft.shared.Registry; import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.common.setup.Blocks; +import de.srendi.advancedperipherals.common.setup.APBlocks; +import de.srendi.advancedperipherals.common.setup.APItems; +import de.srendi.advancedperipherals.common.setup.APVillagers; import de.srendi.advancedperipherals.common.setup.CCRegistration; -import de.srendi.advancedperipherals.common.setup.Items; -import de.srendi.advancedperipherals.common.setup.Villagers; import de.srendi.advancedperipherals.common.util.ItemUtil; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import net.minecraftforge.event.village.VillagerTradesEvent; @@ -20,7 +20,7 @@ public class VillagerTrades { @SubscribeEvent public static void registerWanderingTrade(WandererTradesEvent event) { - event.getGenericTrades().add(new VillagerTrade(VillagerTrade.Type.ItemForEmerald).setItem(Blocks.PERIPHERAL_CASING.get()).setEmeraldPrice(1).setMaxUses(16).setXp(3)); + event.getGenericTrades().add(new VillagerTrade(VillagerTrade.Type.ItemForEmerald).setItem(APBlocks.PERIPHERAL_CASING.get()).setEmeraldPrice(1).setMaxUses(16).setXp(3)); event.getRareTrades().add(new VillagerTrade(VillagerTrade.Type.EmeraldForItem).setItem(Registry.ModBlocks.TURTLE_ADVANCED.get()).setEmeraldPrice(2).setMaxUses(4).setXp(20).setItemAmount(1)); } @@ -28,32 +28,32 @@ public static void registerWanderingTrade(WandererTradesEvent event) { @SubscribeEvent public static void registerVillagerTrades(VillagerTradesEvent event) { Int2ObjectMap> trades = event.getTrades(); - if (event.getType() == Villagers.COMPUTER_SCIENTIST.get()) { + if (event.getType() == APVillagers.COMPUTER_SCIENTIST.get()) { - trades.get(1).add(new VillagerTrade(VillagerTrade.Type.ItemForEmerald).setItem(Blocks.PERIPHERAL_CASING.get()).setEmeraldPrice(2).setMaxUses(10).setXp(4)); - trades.get(1).add(new VillagerTrade(VillagerTrade.Type.ItemForEmerald).setItem(Blocks.CHAT_BOX.get()).setEmeraldPrice(2).setMaxUses(8).setXp(4)); + trades.get(1).add(new VillagerTrade(VillagerTrade.Type.ItemForEmerald).setItem(APBlocks.PERIPHERAL_CASING.get()).setEmeraldPrice(2).setMaxUses(10).setXp(4)); + trades.get(1).add(new VillagerTrade(VillagerTrade.Type.ItemForEmerald).setItem(APBlocks.CHAT_BOX.get()).setEmeraldPrice(2).setMaxUses(8).setXp(4)); trades.get(1).add(new VillagerTrade(VillagerTrade.Type.ItemForEmerald).setItem(Registry.ModBlocks.COMPUTER_NORMAL.get()).setEmeraldPrice(1).setMaxUses(8).setXp(4)); - trades.get(1).add(new VillagerTrade(VillagerTrade.Type.EmeraldForItem).setItem(Blocks.PERIPHERAL_CASING.get()).setEmeraldPrice(1).setMaxUses(8).setXp(2)); + trades.get(1).add(new VillagerTrade(VillagerTrade.Type.EmeraldForItem).setItem(APBlocks.PERIPHERAL_CASING.get()).setEmeraldPrice(1).setMaxUses(8).setXp(2)); - trades.get(2).add(new VillagerTrade(VillagerTrade.Type.ItemForEmerald).setItem(Blocks.INVENTORY_MANAGER.get()).setEmeraldPrice(2).setMaxUses(2).setXp(8)); - trades.get(2).add(new VillagerTrade(VillagerTrade.Type.ItemForEmerald).setItem(Blocks.REDSTONE_INTEGRATOR.get()).setEmeraldPrice(2).setMaxUses(2).setXp(8)); + trades.get(2).add(new VillagerTrade(VillagerTrade.Type.ItemForEmerald).setItem(APBlocks.INVENTORY_MANAGER.get()).setEmeraldPrice(2).setMaxUses(2).setXp(8)); + trades.get(2).add(new VillagerTrade(VillagerTrade.Type.ItemForEmerald).setItem(APBlocks.REDSTONE_INTEGRATOR.get()).setEmeraldPrice(2).setMaxUses(2).setXp(8)); trades.get(2).add(new VillagerTrade(VillagerTrade.Type.ItemForEmerald).setItem(Registry.ModBlocks.COMPUTER_ADVANCED.get()).setEmeraldPrice(2).setMaxUses(3).setXp(10)); trades.get(2).add(new VillagerTrade(VillagerTrade.Type.ItemForEmerald).setItem(Registry.ModBlocks.MONITOR_NORMAL.get()).setEmeraldPrice(1).setMaxUses(8).setXp(6).setItemAmount(8)); trades.get(3).add(new VillagerTrade(VillagerTrade.Type.ItemForEmerald).setItem(ItemUtil.makeTurtle(ItemUtil.TURTLE_NORMAL, CCRegistration.ID.ENVIRONMENT_TURTLE.toString())).setEmeraldPrice(3).setMaxUses(4).setXp(10)); trades.get(3).add(new VillagerTrade(VillagerTrade.Type.ItemForEmerald).setItem(ItemUtil.makePocket(ItemUtil.POCKET_NORMAL, CCRegistration.ID.PLAYER_POCKET.toString())).setEmeraldPrice(2).setMaxUses(4).setXp(10)); - trades.get(3).add(new VillagerTrade(VillagerTrade.Type.EmeraldForItem).setItem(Items.CHUNK_CONTROLLER.get()).setEmeraldPrice(1).setMaxUses(6).setXp(8)); - trades.get(3).add(new VillagerTrade(VillagerTrade.Type.ItemForEmerald).setItem(Items.COMPUTER_TOOL.get()).setEmeraldPrice(1).setMaxUses(4).setXp(8)); + trades.get(3).add(new VillagerTrade(VillagerTrade.Type.EmeraldForItem).setItem(APItems.CHUNK_CONTROLLER.get()).setEmeraldPrice(1).setMaxUses(6).setXp(8)); + trades.get(3).add(new VillagerTrade(VillagerTrade.Type.ItemForEmerald).setItem(APItems.COMPUTER_TOOL.get()).setEmeraldPrice(1).setMaxUses(4).setXp(8)); trades.get(3).add(new VillagerTrade(VillagerTrade.Type.ItemForEmerald).setItem(Registry.ModBlocks.MONITOR_ADVANCED.get()).setEmeraldPrice(6).setMaxUses(8).setXp(10).setItemAmount(16)); - trades.get(4).add(new VillagerTrade(VillagerTrade.Type.ItemForEmerald).setItem(Blocks.ENERGY_DETECTOR.get()).setEmeraldPrice(3).setMaxUses(8).setXp(12)); + trades.get(4).add(new VillagerTrade(VillagerTrade.Type.ItemForEmerald).setItem(APBlocks.ENERGY_DETECTOR.get()).setEmeraldPrice(3).setMaxUses(8).setXp(12)); trades.get(4).add(new VillagerTrade(VillagerTrade.Type.EmeraldForItem).setItem(Registry.ModBlocks.COMPUTER_ADVANCED.get()).setEmeraldPrice(2).setMaxUses(8).setXp(12)); - trades.get(4).add(new VillagerTrade(VillagerTrade.Type.ItemForEmerald).setItem(Items.MEMORY_CARD.get()).setEmeraldPrice(1).setMaxUses(8).setXp(18)); + trades.get(4).add(new VillagerTrade(VillagerTrade.Type.ItemForEmerald).setItem(APItems.MEMORY_CARD.get()).setEmeraldPrice(1).setMaxUses(8).setXp(18)); trades.get(4).add(new VillagerTrade(VillagerTrade.Type.EmeraldForItem).setItem(Registry.ModItems.PRINTED_PAGE.get()).setEmeraldPrice(1).setMaxUses(10).setXp(16).setItemAmount(4)); trades.get(4).add(new VillagerTrade(VillagerTrade.Type.ItemForEmerald).setItem(ItemUtil.makeTurtle(ItemUtil.TURTLE_ADVANCED, AdvancedPeripherals.MOD_ID + ":chunky_turtle")).setEmeraldPrice(8).setMaxUses(6).setXp(18)); - trades.get(5).add(new VillagerTrade(VillagerTrade.Type.ItemForEmerald).setItem(Blocks.AR_CONTROLLER.get()).setEmeraldPrice(3).setMaxUses(6).setXp(30)); - trades.get(5).add(new VillagerTrade(VillagerTrade.Type.ItemForEmerald).setItem(Items.AR_GOGGLES.get()).setEmeraldPrice(4).setMaxUses(8).setXp(30)); + trades.get(5).add(new VillagerTrade(VillagerTrade.Type.ItemForEmerald).setItem(APBlocks.AR_CONTROLLER.get()).setEmeraldPrice(3).setMaxUses(6).setXp(30)); + trades.get(5).add(new VillagerTrade(VillagerTrade.Type.ItemForEmerald).setItem(APItems.SMART_GLASSES.get()).setEmeraldPrice(4).setMaxUses(8).setXp(30)); trades.get(5).add(new VillagerTrade(VillagerTrade.Type.EmeraldForItem).setItem(Registry.ModBlocks.WIRELESS_MODEM_ADVANCED.get()).setEmeraldPrice(2).setMaxUses(14).setXp(30)); } diff --git a/src/main/java/de/srendi/advancedperipherals/network/MNetwork.java b/src/main/java/de/srendi/advancedperipherals/network/MNetwork.java deleted file mode 100644 index 11f0f16de..000000000 --- a/src/main/java/de/srendi/advancedperipherals/network/MNetwork.java +++ /dev/null @@ -1,64 +0,0 @@ -package de.srendi.advancedperipherals.network; - -import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.network.messages.ClearHudCanvasMessage; -import de.srendi.advancedperipherals.network.messages.RequestHudCanvasMessage; -import de.srendi.advancedperipherals.network.messages.UpdateHudCanvasMessage; -import net.minecraft.core.BlockPos; -import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; -import net.minecraft.resources.ResourceKey; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraftforge.common.util.FakePlayer; -import net.minecraftforge.network.NetworkRegistry; -import net.minecraftforge.network.PacketDistributor; -import net.minecraftforge.network.simple.SimpleChannel; - -public class MNetwork { - private static final String PROTOCOL_VERSION = Integer.toString(1); - private static final SimpleChannel NETWORK_CHANNEL = NetworkRegistry.newSimpleChannel(new ResourceLocation(AdvancedPeripherals.MOD_ID, "main_channel"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals); - private static int id = 0; - - public static void init() { - NETWORK_CHANNEL.registerMessage(++id, ClearHudCanvasMessage.class, ClearHudCanvasMessage::encode, ClearHudCanvasMessage::decode, ClearHudCanvasMessage::handle); - NETWORK_CHANNEL.registerMessage(++id, RequestHudCanvasMessage.class, RequestHudCanvasMessage::encode, RequestHudCanvasMessage::decode, RequestHudCanvasMessage::handle); - NETWORK_CHANNEL.registerMessage(++id, UpdateHudCanvasMessage.class, UpdateHudCanvasMessage::encode, UpdateHudCanvasMessage::decode, UpdateHudCanvasMessage::handle); - } - - /** - * Sends a packet to the server.

- * Must be called Client side. - */ - public static void sendToServer(Object msg) { - NETWORK_CHANNEL.sendToServer(msg); - } - - /** - * Send a packet to a specific player.

- * Must be called Server side. - */ - public static void sendTo(Object msg, ServerPlayer player) { - if (!(player instanceof FakePlayer)) { - NETWORK_CHANNEL.send(PacketDistributor.PLAYER.with(() -> player), msg); - } - } - - public static void sendPacketToAll(Object packet) { - NETWORK_CHANNEL.send(PacketDistributor.ALL.noArg(), packet); - } - - public static ClientboundBlockEntityDataPacket createTEUpdatePacket(BlockEntity tile) { - return ClientboundBlockEntityDataPacket.create(tile); - } - - public static void sendToAllAround(Object mes, ResourceKey dim, BlockPos pos, int radius) { - NETWORK_CHANNEL.send(PacketDistributor.NEAR.with(() -> new PacketDistributor.TargetPoint(pos.getX(), pos.getY(), pos.getZ(), radius, dim)), mes); - } - - public static void sendToAllInWorld(Object mes, ServerLevel world) { - NETWORK_CHANNEL.send(PacketDistributor.DIMENSION.with(world::dimension), mes); - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/network/messages/ClearHudCanvasMessage.java b/src/main/java/de/srendi/advancedperipherals/network/messages/ClearHudCanvasMessage.java deleted file mode 100644 index 424d47967..000000000 --- a/src/main/java/de/srendi/advancedperipherals/network/messages/ClearHudCanvasMessage.java +++ /dev/null @@ -1,27 +0,0 @@ -package de.srendi.advancedperipherals.network.messages; - -import de.srendi.advancedperipherals.client.HudOverlayHandler; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraftforge.network.NetworkEvent; - -import java.util.function.Supplier; - -public class ClearHudCanvasMessage { - - public ClearHudCanvasMessage() { - - } - - public static ClearHudCanvasMessage decode(FriendlyByteBuf buf) { - return new ClearHudCanvasMessage(); - } - - public static void encode(ClearHudCanvasMessage mes, FriendlyByteBuf buf) { - - } - - public static void handle(ClearHudCanvasMessage mes, Supplier cont) { - cont.get().enqueueWork(HudOverlayHandler::clearCanvas); - cont.get().setPacketHandled(true); - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/network/messages/RequestHudCanvasMessage.java b/src/main/java/de/srendi/advancedperipherals/network/messages/RequestHudCanvasMessage.java deleted file mode 100644 index 2aa4167ff..000000000 --- a/src/main/java/de/srendi/advancedperipherals/network/messages/RequestHudCanvasMessage.java +++ /dev/null @@ -1,56 +0,0 @@ -package de.srendi.advancedperipherals.network.messages; - -import de.srendi.advancedperipherals.common.blocks.blockentities.ARControllerEntity; -import de.srendi.advancedperipherals.network.MNetwork; -import net.minecraft.core.BlockPos; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraftforge.network.NetworkEvent; - -import java.util.function.Supplier; - -public class RequestHudCanvasMessage { - - private final BlockPos blockPos; - private final String dimensionKey; - - public RequestHudCanvasMessage(BlockPos blockPos, String dimensionKey) { - this.blockPos = blockPos; - this.dimensionKey = dimensionKey; - } - - public static RequestHudCanvasMessage decode(FriendlyByteBuf buf) { - BlockPos blockPos = buf.readBlockPos(); - String dimensionKey = buf.readUtf(Short.MAX_VALUE); - return new RequestHudCanvasMessage(blockPos, dimensionKey); - } - - public static void encode(RequestHudCanvasMessage mes, FriendlyByteBuf buf) { - buf.writeBlockPos(mes.getBlockPos()); - buf.writeUtf(mes.getDimensionKey(), Short.MAX_VALUE); - } - - public static void handle(RequestHudCanvasMessage mes, Supplier cont) { - cont.get().enqueueWork(() -> { - Iterable worlds = cont.get().getSender().getServer().getAllLevels(); - for (ServerLevel world : worlds) { - if (world.dimension().toString().equals(mes.getDimensionKey())) { - BlockEntity te = world.getBlockEntity(mes.getBlockPos()); - if (!(te instanceof ARControllerEntity controller)) return; - MNetwork.sendTo(new UpdateHudCanvasMessage(controller.getCanvas()), cont.get().getSender()); - break; - } - } - }); - cont.get().setPacketHandled(true); - } - - public BlockPos getBlockPos() { - return blockPos; - } - - public String getDimensionKey() { - return dimensionKey; - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/network/messages/UpdateHudCanvasMessage.java b/src/main/java/de/srendi/advancedperipherals/network/messages/UpdateHudCanvasMessage.java deleted file mode 100644 index d14133921..000000000 --- a/src/main/java/de/srendi/advancedperipherals/network/messages/UpdateHudCanvasMessage.java +++ /dev/null @@ -1,64 +0,0 @@ -package de.srendi.advancedperipherals.network.messages; - -import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.client.HudOverlayHandler; -import de.srendi.advancedperipherals.common.argoggles.ARRenderAction; -import io.netty.buffer.ByteBufInputStream; -import io.netty.buffer.ByteBufOutputStream; -import net.minecraft.nbt.*; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraftforge.network.NetworkEvent; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.function.Supplier; - -public class UpdateHudCanvasMessage { - private static final String LIST = "list"; - private List canvas; - - public UpdateHudCanvasMessage(List canvas) { - this.canvas = canvas; - } - - public static UpdateHudCanvasMessage decode(FriendlyByteBuf buf) { - ByteBufInputStream streamin = new ByteBufInputStream(buf); - CompoundTag nbt; - List canvas = new ArrayList(); - try { - nbt = NbtIo.read(streamin, NbtAccounter.UNLIMITED); - ListTag list = nbt.getList(LIST, Tag.TAG_COMPOUND); - list.forEach(x -> canvas.add(ARRenderAction.deserialize((CompoundTag) x))); - } catch (IOException e) { - AdvancedPeripherals.LOGGER.error("Failed to decode UpdateHudCanvasMessage: {}", e.getMessage()); - e.printStackTrace(); - } - return new UpdateHudCanvasMessage(canvas); - } - - public static void encode(UpdateHudCanvasMessage mes, FriendlyByteBuf buf) { - ByteBufOutputStream stream = new ByteBufOutputStream(buf); - CompoundTag nbt = new CompoundTag(); - ListTag list = new ListTag(); - mes.getCanvas().forEach(x -> list.add(x.serializeNBT())); - nbt.put(LIST, list); - try { - NbtIo.write(nbt, stream); - } catch (IOException e) { - AdvancedPeripherals.LOGGER.error("Failed to encode UpdateHudCanvasMessage: {}", e.getMessage()); - e.printStackTrace(); - } - } - - public static void handle(UpdateHudCanvasMessage mes, Supplier cont) { - cont.get().enqueueWork(() -> { - HudOverlayHandler.updateCanvas(mes.getCanvas()); - }); - cont.get().setPacketHandled(true); - } - - public List getCanvas() { - return canvas; - } -} From fd18e23e515b720200fadb5945b2b38de6ce0fd2 Mon Sep 17 00:00:00 2001 From: DenizD Date: Wed, 5 Oct 2022 15:50:13 +0200 Subject: [PATCH 002/228] [#250]Added Fluid Detector --- .../peripheral/FluidDetectorPeripheral.java | 42 +++++++ .../blockentities/FluidDetectorEntity.java | 105 ++++++++++++++++++ .../configuration/PeripheralsConfig.java | 10 +- .../common/setup/APBlockEntityTypes.java | 2 + .../common/setup/APBlocks.java | 27 ++--- .../common/util/FluidStorageProxy.java | 90 +++++++++++++++ 6 files changed, 262 insertions(+), 14 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/FluidDetectorPeripheral.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/FluidDetectorEntity.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/util/FluidStorageProxy.java diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/FluidDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/FluidDetectorPeripheral.java new file mode 100644 index 000000000..b4ece60af --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/FluidDetectorPeripheral.java @@ -0,0 +1,42 @@ +package de.srendi.advancedperipherals.common.addons.computercraft.peripheral; + +import dan200.computercraft.api.lua.LuaFunction; +import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner; +import de.srendi.advancedperipherals.common.blocks.blockentities.FluidDetectorEntity; +import de.srendi.advancedperipherals.common.configuration.APConfig; +import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; + +public class FluidDetectorPeripheral extends BasePeripheral> { + + public static final String TYPE = "energyDetector"; + + public FluidDetectorPeripheral(FluidDetectorEntity tileEntity) { + super(TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); + } + + @Override + public boolean isEnabled() { + return APConfig.PERIPHERALS_CONFIG.enableEnergyDetector.get(); + } + + @LuaFunction(mainThread = true) + public final int getTransferRateLimit() { + return owner.tileEntity.storageProxy.getMaxTransferRate(); + } + + @LuaFunction(mainThread = true) + public final String getTransferedFluid() { + return owner.tileEntity.lastFlowedLiquid.getFluid().toString(); + } + + @LuaFunction(mainThread = true) + public final void setTransferRateLimit(long transferRate) { + transferRate = Math.min(APConfig.PERIPHERALS_CONFIG.energyDetectorMaxFlow.get(), transferRate); + owner.tileEntity.storageProxy.setMaxTransferRate((int) transferRate); + } + + @LuaFunction(mainThread = true) + public final int getTransferRate() { + return owner.tileEntity.transferRate; + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/FluidDetectorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/FluidDetectorEntity.java new file mode 100644 index 000000000..98f99a75c --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/FluidDetectorEntity.java @@ -0,0 +1,105 @@ +package de.srendi.advancedperipherals.common.blocks.blockentities; + +import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.FluidDetectorPeripheral; +import de.srendi.advancedperipherals.common.blocks.base.APBlockEntityBlock; +import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; +import de.srendi.advancedperipherals.common.configuration.APConfig; +import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; +import de.srendi.advancedperipherals.common.util.FluidStorageProxy; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.ForgeCapabilities; +import net.minecraftforge.common.util.LazyOptional; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.IFluidHandler; +import net.minecraftforge.fluids.capability.templates.FluidTank; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Optional; + +public class FluidDetectorEntity extends PeripheralBlockEntity { + + //a zero size, zero transfer energy storage to ensure that cables connect + private final FluidTank zeroStorage = new FluidTank(0); + public int transferRate = 0; + public FluidStack lastFlowedLiquid = FluidStack.EMPTY; + //storageProxy that will forward the energy to the output but limit it to maxTransferRate + public FluidStorageProxy storageProxy = new FluidStorageProxy(this, APConfig.PERIPHERALS_CONFIG.energyDetectorMaxFlow.get()); + LazyOptional energyStorageCap = LazyOptional.of(() -> storageProxy); + Direction fluidInDetection = Direction.NORTH; + Direction fluidOutDirection = Direction.SOUTH; + LazyOptional zeroStorageCap = LazyOptional.of(() -> zeroStorage); + @NotNull + private Optional outReceivingStorage = Optional.empty(); + + public FluidDetectorEntity(BlockPos pos, BlockState state) { + super(APBlockEntityTypes.ENERGY_DETECTOR.get(), pos, state); + } + + @NotNull + @Override + protected FluidDetectorPeripheral createPeripheral() { + return new FluidDetectorPeripheral(this); + } + + @NotNull + @Override + public LazyOptional getCapability(@NotNull Capability cap, @Nullable Direction direction) { + fluidInDetection = getBlockState().getValue(APBlockEntityBlock.FACING); + fluidOutDirection = getBlockState().getValue(APBlockEntityBlock.FACING).getOpposite(); + if (cap == ForgeCapabilities.FLUID_HANDLER) { + if (direction == fluidInDetection) { + return energyStorageCap.cast(); + } else if (direction == fluidOutDirection) { + return zeroStorageCap.cast(); + } + } + return super.getCapability(cap, direction); + } + + @Override + public void saveAdditional(@NotNull CompoundTag compound) { + super.saveAdditional(compound); + compound.putInt("rateLimit", storageProxy.getMaxTransferRate()); + } + + @Override + public void handleTick(Level level, BlockState state, BlockEntityType type) { + if (!level.isClientSide) { + // this handles the rare edge case that receiveEnergy is called multiple times in one tick + transferRate = storageProxy.getTransferedInThisTick(); + storageProxy.resetTransferedInThisTick(); + } + } + + @Override + public void deserializeNBT(CompoundTag nbt) { + storageProxy.setMaxTransferRate(nbt.getInt("rateLimit")); + super.deserializeNBT(nbt); + } + + // returns the cached output storage of the receiving block or refetches it if it has been invalidated + @NotNull + public Optional getOutputStorage() { + // the documentation says that the value of the LazyOptional should be cached locally and invallidated using addListener + if (outReceivingStorage.isEmpty()) { + BlockEntity teOut = level.getBlockEntity(worldPosition.relative(fluidOutDirection)); + if (teOut == null) { + return Optional.empty(); + } + LazyOptional lazyOptionalOutStorage = teOut.getCapability(ForgeCapabilities.FLUID_HANDLER, fluidOutDirection.getOpposite()); + outReceivingStorage = lazyOptionalOutStorage.resolve(); + lazyOptionalOutStorage.addListener(l -> { + outReceivingStorage = Optional.empty(); + }); + } + return outReceivingStorage; + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java index f98abaf24..86a79f8ef 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java @@ -16,6 +16,9 @@ public class PeripheralsConfig implements IAPConfig { //Energy Detector public final ForgeConfigSpec.IntValue energyDetectorMaxFlow; public final ForgeConfigSpec.BooleanValue enableEnergyDetector; + //Energy Detector + public final ForgeConfigSpec.IntValue fluidDetectorMaxFlow; + public final ForgeConfigSpec.BooleanValue enableFluidDetector; //NBT Storage public final ForgeConfigSpec.IntValue nbtStorageMaxSize; public final ForgeConfigSpec.BooleanValue enableNBTStorage; @@ -67,7 +70,12 @@ public PeripheralsConfig() { pop("Energy_Detector", builder); enableEnergyDetector = builder.comment("Enable the Energy Detector or not.").define("enableEnergyDetector", true); - energyDetectorMaxFlow = builder.comment("Defines the maximum energy flow of the energy detector.").defineInRange("energyDetectorMaxFlow", Integer.MAX_VALUE, 1, Integer.MAX_VALUE); + energyDetectorMaxFlow = builder.comment("Defines the maximum energy flow of the energy detector.").defineInRange("energyDetectorMaxFlow", Integer.MAX_VALUE, 0, Integer.MAX_VALUE); + + pop("Fluid_Detector", builder); + + enableFluidDetector = builder.comment("Enable the Fluid Detector or not.").define("enableFluidDetector", true); + fluidDetectorMaxFlow = builder.comment("Defines the maximum fluid flow of the fluid detector.").defineInRange("energyDetectorMaxFlow", Integer.MAX_VALUE, 0, Integer.MAX_VALUE); pop("NBT_Storage", builder); diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java index 975de6300..5bf1d64d9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java @@ -6,6 +6,7 @@ import de.srendi.advancedperipherals.common.blocks.blockentities.ColonyIntegratorEntity; import de.srendi.advancedperipherals.common.blocks.blockentities.EnergyDetectorEntity; import de.srendi.advancedperipherals.common.blocks.blockentities.EnvironmentDetectorEntity; +import de.srendi.advancedperipherals.common.blocks.blockentities.FluidDetectorEntity; import de.srendi.advancedperipherals.common.blocks.blockentities.GeoScannerEntity; import de.srendi.advancedperipherals.common.blocks.blockentities.InventoryManagerEntity; import de.srendi.advancedperipherals.common.blocks.blockentities.MeBridgeEntity; @@ -29,6 +30,7 @@ static void register() { public static final RegistryObject> ME_BRIDGE = ModList.get().isLoaded("ae2") ? APRegistration.TILE_ENTITIES.register("me_bridge", () -> new BlockEntityType<>(MeBridgeEntity::new, Sets.newHashSet(APBlocks.ME_BRIDGE.get()), null)) : null; public static final RegistryObject> RS_BRIDGE = ModList.get().isLoaded("refinedstorage") ? APRegistration.TILE_ENTITIES.register("rs_bridge", () -> new BlockEntityType<>(RsBridgeEntity::new, Sets.newHashSet(APBlocks.RS_BRIDGE.get()), null)) : null; public static final RegistryObject> ENERGY_DETECTOR = APRegistration.TILE_ENTITIES.register("energy_detector", () -> new BlockEntityType<>(EnergyDetectorEntity::new, Sets.newHashSet(APBlocks.ENERGY_DETECTOR.get()), null)); + public static final RegistryObject> FLUID_DETECTOR = APRegistration.TILE_ENTITIES.register("fluid_detector", () -> new BlockEntityType<>(FluidDetectorEntity::new, Sets.newHashSet(APBlocks.FLUID_DETECTOR.get()), null)); public static final RegistryObject> AR_CONTROLLER = APRegistration.TILE_ENTITIES.register("ar_controller", () -> new BlockEntityType<>(SmartGlassesControllerEntity::new, Sets.newHashSet(APBlocks.AR_CONTROLLER.get()), null)); public static final RegistryObject> INVENTORY_MANAGER = APRegistration.TILE_ENTITIES.register("inventory_manager", () -> new BlockEntityType<>(InventoryManagerEntity::new, Sets.newHashSet(APBlocks.INVENTORY_MANAGER.get()), null)); public static final RegistryObject> REDSTONE_INTEGRATOR = APRegistration.TILE_ENTITIES.register("redstone_integrator", () -> new BlockEntityType<>(RedstoneIntegratorEntity::new, Sets.newHashSet(APBlocks.REDSTONE_INTEGRATOR.get()), null)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java index 2aaefcd61..26e98c114 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java @@ -22,20 +22,21 @@ public class APBlocks { static void register() { } - public static final RegistryObject ENVIRONMENT_DETECTOR = register("environment_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.ENVIRONMENT_DETECTOR, false), () -> new APBlockItem(APBlocks.ENVIRONMENT_DETECTOR.get(), CCRegistration.ID.ENVIRONMENT_TURTLE, CCRegistration.ID.ENVIRONMENT_POCKET, APConfig.PERIPHERALS_CONFIG.enableEnvironmentDetector::get)); - public static final RegistryObject CHAT_BOX = register("chat_box", () -> new APBlockEntityBlock<>(APBlockEntityTypes.CHAT_BOX, true), () -> new APBlockItem(APBlocks.CHAT_BOX.get(), CCRegistration.ID.CHATTY_TURTLE, CCRegistration.ID.CHATTY_POCKET, APConfig.PERIPHERALS_CONFIG.enableChatBox::get)); - public static final RegistryObject PLAYER_DETECTOR = register("player_detector", PlayerDetectorBlock::new, () -> new APBlockItem(APBlocks.PLAYER_DETECTOR.get(), CCRegistration.ID.PLAYER_TURTLE, CCRegistration.ID.PLAYER_POCKET, APConfig.PERIPHERALS_CONFIG.enablePlayerDetector::get)); - public static final RegistryObject ME_BRIDGE = register("me_bridge", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("ae2") ? APBlockEntityTypes.ME_BRIDGE : null, ModList.get().isLoaded("ae2")), () -> new APBlockItem(APBlocks.ME_BRIDGE.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableMEBridge::get)); - public static final RegistryObject RS_BRIDGE = register("rs_bridge", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("refinedstorage") ? APBlockEntityTypes.RS_BRIDGE : null, false), () -> new APBlockItem(APBlocks.RS_BRIDGE.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableRSBridge::get)); - public static final RegistryObject ENERGY_DETECTOR = register("energy_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.ENERGY_DETECTOR, true), () -> new APBlockItem(APBlocks.ENERGY_DETECTOR.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableEnergyDetector::get)); + public static final RegistryObject ENVIRONMENT_DETECTOR = register("environment_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.ENVIRONMENT_DETECTOR, false), () -> new APBlockItem(APBlocks.ENVIRONMENT_DETECTOR.get(), CCRegistration.ID.ENVIRONMENT_TURTLE, CCRegistration.ID.ENVIRONMENT_POCKET, APConfig.PERIPHERALS_CONFIG.enableEnvironmentDetector)); + public static final RegistryObject CHAT_BOX = register("chat_box", () -> new APBlockEntityBlock<>(APBlockEntityTypes.CHAT_BOX, true), () -> new APBlockItem(APBlocks.CHAT_BOX.get(), CCRegistration.ID.CHATTY_TURTLE, CCRegistration.ID.CHATTY_POCKET, APConfig.PERIPHERALS_CONFIG.enableChatBox)); + public static final RegistryObject PLAYER_DETECTOR = register("player_detector", PlayerDetectorBlock::new, () -> new APBlockItem(APBlocks.PLAYER_DETECTOR.get(), CCRegistration.ID.PLAYER_TURTLE, CCRegistration.ID.PLAYER_POCKET, APConfig.PERIPHERALS_CONFIG.enablePlayerDetector)); + public static final RegistryObject ME_BRIDGE = register("me_bridge", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("ae2") ? APBlockEntityTypes.ME_BRIDGE : null, ModList.get().isLoaded("ae2")), () -> new APBlockItem(APBlocks.ME_BRIDGE.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableMEBridge)); + public static final RegistryObject RS_BRIDGE = register("rs_bridge", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("refinedstorage") ? APBlockEntityTypes.RS_BRIDGE : null, false), () -> new APBlockItem(APBlocks.RS_BRIDGE.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableRSBridge)); + public static final RegistryObject ENERGY_DETECTOR = register("energy_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.ENERGY_DETECTOR, true), () -> new APBlockItem(APBlocks.ENERGY_DETECTOR.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableEnergyDetector)); + public static final RegistryObject FLUID_DETECTOR = register("fluid_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.FLUID_DETECTOR, true), () -> new APBlockItem(APBlocks.FLUID_DETECTOR.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableFluidDetector)); public static final RegistryObject PERIPHERAL_CASING = register("peripheral_casing", BaseBlock::new, () -> new APBlockItem(APBlocks.PERIPHERAL_CASING.get(), new Item.Properties().stacksTo(16), null, null, () -> true)); - public static final RegistryObject AR_CONTROLLER = register("ar_controller", () -> new APBlockEntityBlock<>(APBlockEntityTypes.AR_CONTROLLER, false), () -> new APBlockItem(APBlocks.AR_CONTROLLER.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableSmartGlasses::get)); - public static final RegistryObject INVENTORY_MANAGER = register("inventory_manager", () -> new APBlockEntityBlock<>(APBlockEntityTypes.INVENTORY_MANAGER, false), () -> new APBlockItem(APBlocks.INVENTORY_MANAGER.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableInventoryManager::get)); - public static final RegistryObject REDSTONE_INTEGRATOR = register("redstone_integrator", RedstoneIntegratorBlock::new, () -> new APBlockItem(APBlocks.REDSTONE_INTEGRATOR.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableRedstoneIntegrator::get)); - public static final RegistryObject BLOCK_READER = register("block_reader", () -> new APBlockEntityBlock<>(APBlockEntityTypes.BLOCK_READER, true), () -> new APBlockItem(APBlocks.BLOCK_READER.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableBlockReader::get)); - public static final RegistryObject GEO_SCANNER = register("geo_scanner", () -> new APBlockEntityBlock<>(APBlockEntityTypes.GEO_SCANNER, false), () -> new APBlockItem(APBlocks.GEO_SCANNER.get(), CCRegistration.ID.GEOSCANNER_TURTLE, CCRegistration.ID.GEOSCANNER_POCKET, APConfig.PERIPHERALS_CONFIG.enableGeoScanner::get)); - public static final RegistryObject COLONY_INTEGRATOR = register("colony_integrator", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("minecolonies") ? APBlockEntityTypes.COLONY_INTEGRATOR : null, false), () -> new APBlockItem(APBlocks.COLONY_INTEGRATOR.get(), null, CCRegistration.ID.COLONY_POCKET, APConfig.PERIPHERALS_CONFIG.enableColonyIntegrator::get)); - public static final RegistryObject NBT_STORAGE = register("nbt_storage", () -> new APBlockEntityBlock<>(APBlockEntityTypes.NBT_STORAGE, false), () -> new APBlockItem(APBlocks.NBT_STORAGE.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableNBTStorage::get)); + public static final RegistryObject AR_CONTROLLER = register("ar_controller", () -> new APBlockEntityBlock<>(APBlockEntityTypes.AR_CONTROLLER, false), () -> new APBlockItem(APBlocks.AR_CONTROLLER.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableSmartGlasses)); + public static final RegistryObject INVENTORY_MANAGER = register("inventory_manager", () -> new APBlockEntityBlock<>(APBlockEntityTypes.INVENTORY_MANAGER, false), () -> new APBlockItem(APBlocks.INVENTORY_MANAGER.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableInventoryManager)); + public static final RegistryObject REDSTONE_INTEGRATOR = register("redstone_integrator", RedstoneIntegratorBlock::new, () -> new APBlockItem(APBlocks.REDSTONE_INTEGRATOR.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableRedstoneIntegrator)); + public static final RegistryObject BLOCK_READER = register("block_reader", () -> new APBlockEntityBlock<>(APBlockEntityTypes.BLOCK_READER, true), () -> new APBlockItem(APBlocks.BLOCK_READER.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableBlockReader)); + public static final RegistryObject GEO_SCANNER = register("geo_scanner", () -> new APBlockEntityBlock<>(APBlockEntityTypes.GEO_SCANNER, false), () -> new APBlockItem(APBlocks.GEO_SCANNER.get(), CCRegistration.ID.GEOSCANNER_TURTLE, CCRegistration.ID.GEOSCANNER_POCKET, APConfig.PERIPHERALS_CONFIG.enableGeoScanner)); + public static final RegistryObject COLONY_INTEGRATOR = register("colony_integrator", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("minecolonies") ? APBlockEntityTypes.COLONY_INTEGRATOR : null, false), () -> new APBlockItem(APBlocks.COLONY_INTEGRATOR.get(), null, CCRegistration.ID.COLONY_POCKET, APConfig.PERIPHERALS_CONFIG.enableColonyIntegrator)); + public static final RegistryObject NBT_STORAGE = register("nbt_storage", () -> new APBlockEntityBlock<>(APBlockEntityTypes.NBT_STORAGE, false), () -> new APBlockItem(APBlocks.NBT_STORAGE.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableNBTStorage)); private static RegistryObject registerNoItem(String name, Supplier block) { return APRegistration.BLOCKS.register(name, block); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/FluidStorageProxy.java b/src/main/java/de/srendi/advancedperipherals/common/util/FluidStorageProxy.java new file mode 100644 index 000000000..8b5bb4311 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/util/FluidStorageProxy.java @@ -0,0 +1,90 @@ +package de.srendi.advancedperipherals.common.util; + +import de.srendi.advancedperipherals.common.blocks.blockentities.FluidDetectorEntity; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.level.material.Fluids; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.IFluidHandler; +import org.jetbrains.annotations.NotNull; + +import java.util.Optional; + +public class FluidStorageProxy implements IFluidHandler { + + private final FluidDetectorEntity fluidDetectorEntity; + private int maxTransferRate; + private int transferedInThisTick = 0; + private Fluid fluid = Fluids.EMPTY; + + public FluidStorageProxy(FluidDetectorEntity fluidDetectorEntity, int maxTransferRate) { + this.fluidDetectorEntity = fluidDetectorEntity; + this.maxTransferRate = maxTransferRate; + } + + + public int getMaxTransferRate() { + return maxTransferRate; + } + + public void setMaxTransferRate(int rate) { + maxTransferRate = rate; + } + + /** + * should be called on every tick + */ + public void resetTransferedInThisTick() { + transferedInThisTick = 0; + } + + public int getTransferedInThisTick() { + return transferedInThisTick; + } + + @Override + public int getTanks() { + return 1; + } + + @Override + public @NotNull FluidStack getFluidInTank(int tank) { + Optional out = fluidDetectorEntity.getOutputStorage(); + return out.map(outStorage -> outStorage.getFluidInTank(tank)).orElse(FluidStack.EMPTY); + } + + @Override + public int getTankCapacity(int tank) { + Optional out = fluidDetectorEntity.getOutputStorage(); + return out.map(outStorage -> outStorage.getTankCapacity(tank)).orElse(0); + } + + @Override + public boolean isFluidValid(int tank, @NotNull FluidStack stack) { + Optional out = fluidDetectorEntity.getOutputStorage(); + return out.map(outStorage -> outStorage.isFluidValid(tank, stack)).orElse(false); + } + + @Override + public int fill(FluidStack resource, IFluidHandler.FluidAction action) { + Optional out = fluidDetectorEntity.getOutputStorage(); + return out.map(outStorage -> { + int transferred = outStorage.fill(resource, action); + if (!action.simulate()) { + transferedInThisTick += transferred; + fluidDetectorEntity.lastFlowedLiquid = resource.copy(); + //transferedInThisTick = transferred; + } + return transferred; + }).orElse(0); + } + + @Override + public @NotNull FluidStack drain(int maxDrain, IFluidHandler.FluidAction action) { + return FluidStack.EMPTY; + } + + @Override + public @NotNull FluidStack drain(FluidStack resource, IFluidHandler.FluidAction action) { + return FluidStack.EMPTY; + } +} From b0117437e5cc36fcbdc696310c3d5dd701940482 Mon Sep 17 00:00:00 2001 From: DenizD Date: Wed, 5 Oct 2022 15:52:08 +0200 Subject: [PATCH 003/228] No Energy --- .../peripheral/FluidDetectorPeripheral.java | 6 +++--- .../blocks/blockentities/FluidDetectorEntity.java | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/FluidDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/FluidDetectorPeripheral.java index b4ece60af..024ab4395 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/FluidDetectorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/FluidDetectorPeripheral.java @@ -8,7 +8,7 @@ public class FluidDetectorPeripheral extends BasePeripheral> { - public static final String TYPE = "energyDetector"; + public static final String TYPE = "fluidDetector"; public FluidDetectorPeripheral(FluidDetectorEntity tileEntity) { super(TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); @@ -16,7 +16,7 @@ public FluidDetectorPeripheral(FluidDetectorEntity tileEntity) { @Override public boolean isEnabled() { - return APConfig.PERIPHERALS_CONFIG.enableEnergyDetector.get(); + return APConfig.PERIPHERALS_CONFIG.enableFluidDetector.get(); } @LuaFunction(mainThread = true) @@ -31,7 +31,7 @@ public final String getTransferedFluid() { @LuaFunction(mainThread = true) public final void setTransferRateLimit(long transferRate) { - transferRate = Math.min(APConfig.PERIPHERALS_CONFIG.energyDetectorMaxFlow.get(), transferRate); + transferRate = Math.min(APConfig.PERIPHERALS_CONFIG.fluidDetectorMaxFlow.get(), transferRate); owner.tileEntity.storageProxy.setMaxTransferRate((int) transferRate); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/FluidDetectorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/FluidDetectorEntity.java index 98f99a75c..59d5a07ad 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/FluidDetectorEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/FluidDetectorEntity.java @@ -26,13 +26,13 @@ public class FluidDetectorEntity extends PeripheralBlockEntity { - //a zero size, zero transfer energy storage to ensure that cables connect + //a zero size, zero transfer fluid storage to ensure that cables connect private final FluidTank zeroStorage = new FluidTank(0); public int transferRate = 0; public FluidStack lastFlowedLiquid = FluidStack.EMPTY; - //storageProxy that will forward the energy to the output but limit it to maxTransferRate - public FluidStorageProxy storageProxy = new FluidStorageProxy(this, APConfig.PERIPHERALS_CONFIG.energyDetectorMaxFlow.get()); - LazyOptional energyStorageCap = LazyOptional.of(() -> storageProxy); + //storageProxy that will forward the fluid to the output but limit it to maxTransferRate + public FluidStorageProxy storageProxy = new FluidStorageProxy(this, APConfig.PERIPHERALS_CONFIG.fluidDetectorMaxFlow.get()); + LazyOptional fluidStorageCap = LazyOptional.of(() -> storageProxy); Direction fluidInDetection = Direction.NORTH; Direction fluidOutDirection = Direction.SOUTH; LazyOptional zeroStorageCap = LazyOptional.of(() -> zeroStorage); @@ -40,7 +40,7 @@ public class FluidDetectorEntity extends PeripheralBlockEntity outReceivingStorage = Optional.empty(); public FluidDetectorEntity(BlockPos pos, BlockState state) { - super(APBlockEntityTypes.ENERGY_DETECTOR.get(), pos, state); + super(APBlockEntityTypes.FLUID_DETECTOR.get(), pos, state); } @NotNull @@ -56,7 +56,7 @@ public LazyOptional getCapability(@NotNull Capability cap, @Nullable D fluidOutDirection = getBlockState().getValue(APBlockEntityBlock.FACING).getOpposite(); if (cap == ForgeCapabilities.FLUID_HANDLER) { if (direction == fluidInDetection) { - return energyStorageCap.cast(); + return fluidStorageCap.cast(); } else if (direction == fluidOutDirection) { return zeroStorageCap.cast(); } @@ -73,7 +73,7 @@ public void saveAdditional(@NotNull CompoundTag compound) { @Override public void handleTick(Level level, BlockState state, BlockEntityType type) { if (!level.isClientSide) { - // this handles the rare edge case that receiveEnergy is called multiple times in one tick + // this handles the rare edge case that receiveFluid is called multiple times in one tick transferRate = storageProxy.getTransferedInThisTick(); storageProxy.resetTransferedInThisTick(); } From 8e7665b50f17767277f18919634fcb97b2ac62ed Mon Sep 17 00:00:00 2001 From: DenizD Date: Fri, 7 Oct 2022 09:51:21 +0200 Subject: [PATCH 004/228] Added the gas detector --- build.gradle | 7 ++ gradle.properties | 1 + .../peripheral/FluidDetectorPeripheral.java | 3 +- .../peripheral/GasDetectorPeripheral.java | 42 +++++++ .../addons/mekanism/MekanismCapabilities.java | 13 +++ .../blockentities/EnergyDetectorEntity.java | 25 +++-- .../blockentities/FluidDetectorEntity.java | 21 ++-- .../blockentities/GasDetectorEntity.java | 106 ++++++++++++++++++ .../configuration/PeripheralsConfig.java | 10 +- .../common/setup/APBlockEntityTypes.java | 2 + .../common/setup/APBlocks.java | 1 + .../common/util/FluidStorageProxy.java | 4 +- .../common/util/GasStorageProxy.java | 99 ++++++++++++++++ .../common/util/ZeroGasTank.java | 47 ++++++++ 14 files changed, 356 insertions(+), 25 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/GasDetectorPeripheral.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/MekanismCapabilities.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/GasDetectorEntity.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/util/GasStorageProxy.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/util/ZeroGasTank.java diff --git a/build.gradle b/build.gradle index 8717436c1..4035d5ec8 100644 --- a/build.gradle +++ b/build.gradle @@ -264,6 +264,13 @@ dependencies { transitive false } + compileOnly "mekanism:Mekanism:${mekanism_version}:api" + + runtimeOnly fg.deobf("mekanism:Mekanism:${mekanism_version}")// core + runtimeOnly fg.deobf("mekanism:Mekanism:${mekanism_version}:additions")// Mekanism: Additions + runtimeOnly fg.deobf("mekanism:Mekanism:${mekanism_version}:generators")// Mekanism: Generators + runtimeOnly fg.deobf("mekanism:Mekanism:${mekanism_version}:tools")// Mekanism: Tools + // Botania implementation fg.deobf("vazkii.botania:Botania:${botania_version}") diff --git a/gradle.properties b/gradle.properties index cc976944b..3d8f4ef85 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,6 +28,7 @@ refinedstorage_version=1.11.0 botania_version=1.19.2-436-SNAPSHOT create_version=0.5.0.d flywheel_version=0.6.5 +mekanism_version=1.19.2-10.3.3.470 # Mod dependencies which are needed for other mods # For minecolonies diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/FluidDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/FluidDetectorPeripheral.java index 024ab4395..740b18f98 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/FluidDetectorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/FluidDetectorPeripheral.java @@ -5,6 +5,7 @@ import de.srendi.advancedperipherals.common.blocks.blockentities.FluidDetectorEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; +import net.minecraftforge.registries.ForgeRegistries; public class FluidDetectorPeripheral extends BasePeripheral> { @@ -26,7 +27,7 @@ public final int getTransferRateLimit() { @LuaFunction(mainThread = true) public final String getTransferedFluid() { - return owner.tileEntity.lastFlowedLiquid.getFluid().toString(); + return ForgeRegistries.FLUIDS.getKey(owner.tileEntity.lastFlowedLiquid.getFluid()).toString(); } @LuaFunction(mainThread = true) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/GasDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/GasDetectorPeripheral.java new file mode 100644 index 000000000..d344acaf4 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/GasDetectorPeripheral.java @@ -0,0 +1,42 @@ +package de.srendi.advancedperipherals.common.addons.computercraft.peripheral; + +import dan200.computercraft.api.lua.LuaFunction; +import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner; +import de.srendi.advancedperipherals.common.blocks.blockentities.GasDetectorEntity; +import de.srendi.advancedperipherals.common.configuration.APConfig; +import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; + +public class GasDetectorPeripheral extends BasePeripheral> { + + public static final String TYPE = "gasDetector"; + + public GasDetectorPeripheral(GasDetectorEntity tileEntity) { + super(TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); + } + + @Override + public boolean isEnabled() { + return APConfig.PERIPHERALS_CONFIG.enableGasDetector.get(); + } + + @LuaFunction(mainThread = true) + public final int getTransferRateLimit() { + return owner.tileEntity.storageProxy.getMaxTransferRate(); + } + + @LuaFunction(mainThread = true) + public final String getTransferedGas() { + return owner.tileEntity.lastFlowedGas.getRaw().getRegistryName().toString(); + } + + @LuaFunction(mainThread = true) + public final void setTransferRateLimit(long transferRate) { + transferRate = Math.min(APConfig.PERIPHERALS_CONFIG.gasDetectorMaxFlow.get(), transferRate); + owner.tileEntity.storageProxy.setMaxTransferRate((int) transferRate); + } + + @LuaFunction(mainThread = true) + public final int getTransferRate() { + return owner.tileEntity.transferRate; + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/MekanismCapabilities.java b/src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/MekanismCapabilities.java new file mode 100644 index 000000000..a9e20a1f9 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/MekanismCapabilities.java @@ -0,0 +1,13 @@ +package de.srendi.advancedperipherals.common.addons.mekanism; + +import mekanism.api.chemical.gas.IGasHandler; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.CapabilityToken; + +import static net.minecraftforge.common.capabilities.CapabilityManager.get; + +public class MekanismCapabilities { + + public static final Capability GAS_HANDLER = get(new CapabilityToken<>(){}); + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnergyDetectorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnergyDetectorEntity.java index 38a98b4ca..6111e0970 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnergyDetectorEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnergyDetectorEntity.java @@ -14,8 +14,8 @@ import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.CapabilityEnergy; import net.minecraftforge.energy.EnergyStorage; import net.minecraftforge.energy.IEnergyStorage; import org.jetbrains.annotations.NotNull; @@ -25,18 +25,19 @@ public class EnergyDetectorEntity extends PeripheralBlockEntity { - //a zero size, zero transfer energy storage to ensure that cables connect - private final EnergyStorage zeroStorage = new EnergyStorage(0, 0, 0); public int transferRate = 0; //storageProxy that will forward the energy to the output but limit it to maxTransferRate - public EnergyStorageProxy storageProxy = new EnergyStorageProxy(this, APConfig.PERIPHERALS_CONFIG.energyDetectorMaxFlow.get()); - LazyOptional energyStorageCap = LazyOptional.of(() -> storageProxy); - Direction energyInDirection = Direction.NORTH; - Direction energyOutDirection = Direction.SOUTH; - LazyOptional zeroStorageCap = LazyOptional.of(() -> zeroStorage); + public final EnergyStorageProxy storageProxy = new EnergyStorageProxy(this, APConfig.PERIPHERALS_CONFIG.energyDetectorMaxFlow.get()); + //a zero size, zero transfer energy storage to ensure that cables connect + private final EnergyStorage zeroStorage = new EnergyStorage(0, 0, 0); + private final LazyOptional energyStorageCap = LazyOptional.of(() -> storageProxy); + private final LazyOptional zeroStorageCap = LazyOptional.of(() -> zeroStorage); @NotNull private Optional outReceivingStorage = Optional.empty(); + private Direction energyInDirection = Direction.NORTH; + private Direction energyOutDirection = Direction.SOUTH; + public EnergyDetectorEntity(BlockPos pos, BlockState state) { super(APBlockEntityTypes.ENERGY_DETECTOR.get(), pos, state); } @@ -52,7 +53,7 @@ protected EnergyDetectorPeripheral createPeripheral() { public LazyOptional getCapability(@NotNull Capability cap, @Nullable Direction direction) { energyInDirection = getBlockState().getValue(APBlockEntityBlock.FACING); energyOutDirection = getBlockState().getValue(APBlockEntityBlock.FACING).getOpposite(); - if (cap == CapabilityEnergy.ENERGY) { + if (cap == ForgeCapabilities.ENERGY) { if (direction == energyInDirection) { return energyStorageCap.cast(); } else if (direction == energyOutDirection) { @@ -83,16 +84,16 @@ public void deserializeNBT(CompoundTag nbt) { super.deserializeNBT(nbt); } - // returns the cached output storage of the receiving block or refetches it if it has been invalidated + // returns the cached output storage of the receiving block or fetches it if it has been invalidated @NotNull public Optional getOutputStorage() { - // the documentation says that the value of the LazyOptional should be cached locally and invallidated using addListener + // the documentation says that the value of the LazyOptional should be cached locally and invalidated using addListener if (outReceivingStorage.isEmpty()) { BlockEntity teOut = level.getBlockEntity(worldPosition.relative(energyOutDirection)); if (teOut == null) { return Optional.empty(); } - LazyOptional lazyOptionalOutStorage = teOut.getCapability(CapabilityEnergy.ENERGY, energyOutDirection.getOpposite()); + LazyOptional lazyOptionalOutStorage = teOut.getCapability(ForgeCapabilities.ENERGY, energyOutDirection.getOpposite()); outReceivingStorage = lazyOptionalOutStorage.resolve(); lazyOptionalOutStorage.addListener(l -> { outReceivingStorage = Optional.empty(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/FluidDetectorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/FluidDetectorEntity.java index 59d5a07ad..b3ed0b9fd 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/FluidDetectorEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/FluidDetectorEntity.java @@ -26,19 +26,20 @@ public class FluidDetectorEntity extends PeripheralBlockEntity { - //a zero size, zero transfer fluid storage to ensure that cables connect - private final FluidTank zeroStorage = new FluidTank(0); public int transferRate = 0; public FluidStack lastFlowedLiquid = FluidStack.EMPTY; + //storageProxy that will forward the fluid to the output but limit it to maxTransferRate - public FluidStorageProxy storageProxy = new FluidStorageProxy(this, APConfig.PERIPHERALS_CONFIG.fluidDetectorMaxFlow.get()); - LazyOptional fluidStorageCap = LazyOptional.of(() -> storageProxy); - Direction fluidInDetection = Direction.NORTH; - Direction fluidOutDirection = Direction.SOUTH; - LazyOptional zeroStorageCap = LazyOptional.of(() -> zeroStorage); - @NotNull + public final FluidStorageProxy storageProxy = new FluidStorageProxy(this, APConfig.PERIPHERALS_CONFIG.fluidDetectorMaxFlow.get()); + //a zero size, zero transfer fluid storage to ensure that cables connect + private final FluidTank zeroStorage = new FluidTank(0); + private final LazyOptional fluidStorageCap = LazyOptional.of(() -> storageProxy); + private final LazyOptional zeroStorageCap = LazyOptional.of(() -> zeroStorage); private Optional outReceivingStorage = Optional.empty(); + private Direction fluidInDetection = Direction.NORTH; + private Direction fluidOutDirection = Direction.SOUTH; + public FluidDetectorEntity(BlockPos pos, BlockState state) { super(APBlockEntityTypes.FLUID_DETECTOR.get(), pos, state); } @@ -85,10 +86,10 @@ public void deserializeNBT(CompoundTag nbt) { super.deserializeNBT(nbt); } - // returns the cached output storage of the receiving block or refetches it if it has been invalidated + // returns the cached output storage of the receiving block or fetches it if it has been invalidated @NotNull public Optional getOutputStorage() { - // the documentation says that the value of the LazyOptional should be cached locally and invallidated using addListener + // the documentation says that the value of the LazyOptional should be cached locally and invalidated using addListener if (outReceivingStorage.isEmpty()) { BlockEntity teOut = level.getBlockEntity(worldPosition.relative(fluidOutDirection)); if (teOut == null) { diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/GasDetectorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/GasDetectorEntity.java new file mode 100644 index 000000000..e45eea337 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/GasDetectorEntity.java @@ -0,0 +1,106 @@ +package de.srendi.advancedperipherals.common.blocks.blockentities; + +import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.GasDetectorPeripheral; +import de.srendi.advancedperipherals.common.addons.mekanism.MekanismCapabilities; +import de.srendi.advancedperipherals.common.blocks.base.APBlockEntityBlock; +import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; +import de.srendi.advancedperipherals.common.configuration.APConfig; +import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; +import de.srendi.advancedperipherals.common.util.GasStorageProxy; +import de.srendi.advancedperipherals.common.util.ZeroGasTank; +import mekanism.api.chemical.gas.GasStack; +import mekanism.api.chemical.gas.IGasHandler; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.util.LazyOptional; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Optional; + +public class GasDetectorEntity extends PeripheralBlockEntity { + + public int transferRate = 0; + public GasStack lastFlowedGas = GasStack.EMPTY; + + //storageProxy that will forward the gas to the output but limit it to maxTransferRate + public final GasStorageProxy storageProxy = new GasStorageProxy(this, APConfig.PERIPHERALS_CONFIG.gasDetectorMaxFlow.get()); + //a zero size, zero transfer gas storage to ensure that cables connect + private final IGasHandler zeroStorage = new ZeroGasTank(); + private final LazyOptional gasStorageCap = LazyOptional.of(() -> storageProxy); + private final LazyOptional zeroStorageCap = LazyOptional.of(() -> zeroStorage); + private Optional outReceivingStorage = Optional.empty(); + + private Direction gasInDirection = Direction.NORTH; + private Direction gasOutDirection = Direction.SOUTH; + + public GasDetectorEntity(BlockPos pos, BlockState state) { + super(APBlockEntityTypes.GAS_DETECTOR.get(), pos, state); + } + + @NotNull + @Override + protected GasDetectorPeripheral createPeripheral() { + return new GasDetectorPeripheral(this); + } + + @NotNull + @Override + public LazyOptional getCapability(@NotNull Capability cap, @Nullable Direction direction) { + gasInDirection = getBlockState().getValue(APBlockEntityBlock.FACING); + gasOutDirection = getBlockState().getValue(APBlockEntityBlock.FACING).getOpposite(); + if (cap == MekanismCapabilities.GAS_HANDLER) { + if (direction == gasInDirection) { + return gasStorageCap.cast(); + } else if (direction == gasOutDirection) { + return zeroStorageCap.cast(); + } + } + return super.getCapability(cap, direction); + } + + @Override + public void saveAdditional(@NotNull CompoundTag compound) { + super.saveAdditional(compound); + compound.putInt("rateLimit", storageProxy.getMaxTransferRate()); + } + + @Override + public void handleTick(Level level, BlockState state, BlockEntityType type) { + if (!level.isClientSide) { + // this handles the rare edge case that receiveGas is called multiple times in one tick + transferRate = storageProxy.getTransferedInThisTick(); + storageProxy.resetTransferedInThisTick(); + } + } + + @Override + public void deserializeNBT(CompoundTag nbt) { + storageProxy.setMaxTransferRate(nbt.getInt("rateLimit")); + super.deserializeNBT(nbt); + } + + // returns the cached output storage of the receiving block or fetches it if it has been invalidated + @NotNull + public Optional getOutputStorage() { + // the documentation says that the value of the LazyOptional should be cached locally and invalidated using addListener + if (outReceivingStorage.isEmpty()) { + BlockEntity teOut = level.getBlockEntity(worldPosition.relative(gasOutDirection)); + if (teOut == null) { + return Optional.empty(); + } + LazyOptional lazyOptionalOutStorage = teOut.getCapability(MekanismCapabilities.GAS_HANDLER, gasOutDirection.getOpposite()); + outReceivingStorage = lazyOptionalOutStorage.resolve(); + lazyOptionalOutStorage.addListener(l -> { + outReceivingStorage = Optional.empty(); + }); + } + return outReceivingStorage; + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java index 86a79f8ef..49e88e0c5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java @@ -16,9 +16,12 @@ public class PeripheralsConfig implements IAPConfig { //Energy Detector public final ForgeConfigSpec.IntValue energyDetectorMaxFlow; public final ForgeConfigSpec.BooleanValue enableEnergyDetector; - //Energy Detector + //Fluid Detector public final ForgeConfigSpec.IntValue fluidDetectorMaxFlow; public final ForgeConfigSpec.BooleanValue enableFluidDetector; + //Gas Detector + public final ForgeConfigSpec.IntValue gasDetectorMaxFlow; + public final ForgeConfigSpec.BooleanValue enableGasDetector; //NBT Storage public final ForgeConfigSpec.IntValue nbtStorageMaxSize; public final ForgeConfigSpec.BooleanValue enableNBTStorage; @@ -77,6 +80,11 @@ public PeripheralsConfig() { enableFluidDetector = builder.comment("Enable the Fluid Detector or not.").define("enableFluidDetector", true); fluidDetectorMaxFlow = builder.comment("Defines the maximum fluid flow of the fluid detector.").defineInRange("energyDetectorMaxFlow", Integer.MAX_VALUE, 0, Integer.MAX_VALUE); + pop("Gas_Detector", builder); + + enableGasDetector = builder.comment("Enable the Gas Detector or not.").define("enableGasDetector", true); + gasDetectorMaxFlow = builder.comment("Defines the maximum gas flow of the gas detector.").defineInRange("gasDetectorMaxFlow", Integer.MAX_VALUE, 0, Integer.MAX_VALUE); + pop("NBT_Storage", builder); enableNBTStorage = builder.comment("Enable the nbt storage block or not").define("enableNBTStorage", true); diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java index 5bf1d64d9..50f30a154 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java @@ -7,6 +7,7 @@ import de.srendi.advancedperipherals.common.blocks.blockentities.EnergyDetectorEntity; import de.srendi.advancedperipherals.common.blocks.blockentities.EnvironmentDetectorEntity; import de.srendi.advancedperipherals.common.blocks.blockentities.FluidDetectorEntity; +import de.srendi.advancedperipherals.common.blocks.blockentities.GasDetectorEntity; import de.srendi.advancedperipherals.common.blocks.blockentities.GeoScannerEntity; import de.srendi.advancedperipherals.common.blocks.blockentities.InventoryManagerEntity; import de.srendi.advancedperipherals.common.blocks.blockentities.MeBridgeEntity; @@ -31,6 +32,7 @@ static void register() { public static final RegistryObject> RS_BRIDGE = ModList.get().isLoaded("refinedstorage") ? APRegistration.TILE_ENTITIES.register("rs_bridge", () -> new BlockEntityType<>(RsBridgeEntity::new, Sets.newHashSet(APBlocks.RS_BRIDGE.get()), null)) : null; public static final RegistryObject> ENERGY_DETECTOR = APRegistration.TILE_ENTITIES.register("energy_detector", () -> new BlockEntityType<>(EnergyDetectorEntity::new, Sets.newHashSet(APBlocks.ENERGY_DETECTOR.get()), null)); public static final RegistryObject> FLUID_DETECTOR = APRegistration.TILE_ENTITIES.register("fluid_detector", () -> new BlockEntityType<>(FluidDetectorEntity::new, Sets.newHashSet(APBlocks.FLUID_DETECTOR.get()), null)); + public static final RegistryObject> GAS_DETECTOR = APRegistration.TILE_ENTITIES.register("gas_detector", () -> new BlockEntityType<>(GasDetectorEntity::new, Sets.newHashSet(APBlocks.GAS_DETECTOR.get()), null)); public static final RegistryObject> AR_CONTROLLER = APRegistration.TILE_ENTITIES.register("ar_controller", () -> new BlockEntityType<>(SmartGlassesControllerEntity::new, Sets.newHashSet(APBlocks.AR_CONTROLLER.get()), null)); public static final RegistryObject> INVENTORY_MANAGER = APRegistration.TILE_ENTITIES.register("inventory_manager", () -> new BlockEntityType<>(InventoryManagerEntity::new, Sets.newHashSet(APBlocks.INVENTORY_MANAGER.get()), null)); public static final RegistryObject> REDSTONE_INTEGRATOR = APRegistration.TILE_ENTITIES.register("redstone_integrator", () -> new BlockEntityType<>(RedstoneIntegratorEntity::new, Sets.newHashSet(APBlocks.REDSTONE_INTEGRATOR.get()), null)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java index 26e98c114..e253dbfdd 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java @@ -29,6 +29,7 @@ static void register() { public static final RegistryObject RS_BRIDGE = register("rs_bridge", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("refinedstorage") ? APBlockEntityTypes.RS_BRIDGE : null, false), () -> new APBlockItem(APBlocks.RS_BRIDGE.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableRSBridge)); public static final RegistryObject ENERGY_DETECTOR = register("energy_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.ENERGY_DETECTOR, true), () -> new APBlockItem(APBlocks.ENERGY_DETECTOR.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableEnergyDetector)); public static final RegistryObject FLUID_DETECTOR = register("fluid_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.FLUID_DETECTOR, true), () -> new APBlockItem(APBlocks.FLUID_DETECTOR.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableFluidDetector)); + public static final RegistryObject GAS_DETECTOR = register("gas_detector", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("mekanism") ? APBlockEntityTypes.GAS_DETECTOR : null, true), () -> new APBlockItem(APBlocks.GAS_DETECTOR.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableGasDetector)); public static final RegistryObject PERIPHERAL_CASING = register("peripheral_casing", BaseBlock::new, () -> new APBlockItem(APBlocks.PERIPHERAL_CASING.get(), new Item.Properties().stacksTo(16), null, null, () -> true)); public static final RegistryObject AR_CONTROLLER = register("ar_controller", () -> new APBlockEntityBlock<>(APBlockEntityTypes.AR_CONTROLLER, false), () -> new APBlockItem(APBlocks.AR_CONTROLLER.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableSmartGlasses)); public static final RegistryObject INVENTORY_MANAGER = register("inventory_manager", () -> new APBlockEntityBlock<>(APBlockEntityTypes.INVENTORY_MANAGER, false), () -> new APBlockItem(APBlocks.INVENTORY_MANAGER.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableInventoryManager)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/FluidStorageProxy.java b/src/main/java/de/srendi/advancedperipherals/common/util/FluidStorageProxy.java index 8b5bb4311..e75f2e599 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/FluidStorageProxy.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/FluidStorageProxy.java @@ -68,7 +68,9 @@ public boolean isFluidValid(int tank, @NotNull FluidStack stack) { public int fill(FluidStack resource, IFluidHandler.FluidAction action) { Optional out = fluidDetectorEntity.getOutputStorage(); return out.map(outStorage -> { - int transferred = outStorage.fill(resource, action); + FluidStack transferring = resource.copy(); + transferring.setAmount(Math.min(resource.getAmount(), maxTransferRate)); + int transferred = outStorage.fill(transferring, action); if (!action.simulate()) { transferedInThisTick += transferred; fluidDetectorEntity.lastFlowedLiquid = resource.copy(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/GasStorageProxy.java b/src/main/java/de/srendi/advancedperipherals/common/util/GasStorageProxy.java new file mode 100644 index 000000000..136416645 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/util/GasStorageProxy.java @@ -0,0 +1,99 @@ +package de.srendi.advancedperipherals.common.util; + +import de.srendi.advancedperipherals.common.blocks.blockentities.GasDetectorEntity; +import mekanism.api.Action; +import mekanism.api.chemical.gas.GasStack; +import mekanism.api.chemical.gas.IGasHandler; +import org.jetbrains.annotations.NotNull; + +import java.util.Optional; + +public class GasStorageProxy implements IGasHandler { + + private final GasDetectorEntity fluidDetectorEntity; + private int maxTransferRate; + private int transferedInThisTick = 0; + + public GasStorageProxy(GasDetectorEntity fluidDetectorEntity, int maxTransferRate) { + this.fluidDetectorEntity = fluidDetectorEntity; + this.maxTransferRate = maxTransferRate; + } + + + public int getMaxTransferRate() { + return maxTransferRate; + } + + public void setMaxTransferRate(int rate) { + maxTransferRate = rate; + } + + /** + * should be called on every tick + */ + public void resetTransferedInThisTick() { + transferedInThisTick = 0; + } + + public int getTransferedInThisTick() { + return transferedInThisTick; + } + + @Override + public int getTanks() { + return 1; + } + + @NotNull + @Override + public GasStack getChemicalInTank(int tank) { + Optional out = fluidDetectorEntity.getOutputStorage(); + return out.map(outStorage -> outStorage.getChemicalInTank(tank)).orElse(GasStack.EMPTY); + } + + @Override + public void setChemicalInTank(int tank, @NotNull GasStack stack) { + Optional out = fluidDetectorEntity.getOutputStorage(); + out.ifPresent(outStorage -> outStorage.setChemicalInTank(tank, stack)); + } + + @Override + public long getTankCapacity(int tank) { + Optional out = fluidDetectorEntity.getOutputStorage(); + return out.map(outStorage -> outStorage.getTankCapacity(tank)).orElse(0L); + } + + @Override + public boolean isValid(int tank, @NotNull GasStack stack) { + Optional out = fluidDetectorEntity.getOutputStorage(); + return out.map(outStorage -> outStorage.isValid(tank, stack)).orElse(false); + } + + @NotNull + @Override + public GasStack insertChemical(@NotNull GasStack stack, @NotNull Action action) { + Optional out = fluidDetectorEntity.getOutputStorage(); + return out.map(outStorage -> { + GasStack transferring = stack.copy(); + transferring.setAmount(Math.min(stack.getAmount(), maxTransferRate)); + GasStack transferred = outStorage.insertChemical(transferring, action); + if (!action.simulate()) { + transferedInThisTick += transferred.getAmount(); + fluidDetectorEntity.lastFlowedGas = stack.copy(); + } + return transferred; + }).orElse(GasStack.EMPTY); + } + + @NotNull + @Override + public GasStack insertChemical(int tank, @NotNull GasStack stack, @NotNull Action action) { + return insertChemical(stack, action); + } + + @NotNull + @Override + public GasStack extractChemical(int tank, long amount, @NotNull Action action) { + return GasStack.EMPTY; + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ZeroGasTank.java b/src/main/java/de/srendi/advancedperipherals/common/util/ZeroGasTank.java new file mode 100644 index 000000000..48f81d3b1 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ZeroGasTank.java @@ -0,0 +1,47 @@ +package de.srendi.advancedperipherals.common.util; + +import mekanism.api.Action; +import mekanism.api.chemical.gas.GasStack; +import mekanism.api.chemical.gas.IGasHandler; +import org.jetbrains.annotations.NotNull; + +public class ZeroGasTank implements IGasHandler { + + @Override + public int getTanks() { + return 0; + } + + @NotNull + @Override + public GasStack getChemicalInTank(int tank) { + return GasStack.EMPTY; + } + + @Override + public void setChemicalInTank(int tank, GasStack stack) { + + } + + @Override + public long getTankCapacity(int tank) { + return 0; + } + + @Override + public boolean isValid(int tank, @NotNull GasStack stack) { + return false; + } + + @NotNull + @Override + public GasStack insertChemical(int tank, @NotNull GasStack stack, @NotNull Action action) { + return GasStack.EMPTY; + } + + @NotNull + @Override + public GasStack extractChemical(int tank, long amount, @NotNull Action action) { + return GasStack.EMPTY; + } +} From f73ec763f2107e1c4700dc9ad4ffabfaab8882b5 Mon Sep 17 00:00:00 2001 From: DenizD Date: Fri, 7 Oct 2022 14:13:57 +0200 Subject: [PATCH 005/228] Fixed detectors not saving max flow rate --- build.gradle | 10 +- gradle.properties | 16 +-- .../67cce32b1c3cbbcb1f646605f4914e3f196986c2 | 4 +- .../9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e | 5 +- .../c622617f6fabf890a00b9275cd5f643584a8a2c8 | 4 +- .../f95c7003282837dabaa33e3ffceec4e6865b5218 | 6 +- .../advancedperipherals/lang/en_us.json | 6 +- .../loot_tables/blocks/fluid_detector.json | 20 ++++ .../loot_tables/blocks/gas_detector.json | 20 ++++ .../tags/blocks/mineable/pickaxe.json | 2 + .../tags/blocks/needs_iron_tool.json | 2 + .../blockentities/EnergyDetectorEntity.java | 4 +- .../blockentities/FluidDetectorEntity.java | 4 +- .../blockentities/GasDetectorEntity.java | 4 +- .../common/data/EnUsLanguageProvider.java | 98 +++++++++---------- .../common/data/RecipesProvider.java | 13 ++- 16 files changed, 136 insertions(+), 82 deletions(-) create mode 100644 src/generated/resources/data/advancedperipherals/loot_tables/blocks/fluid_detector.json create mode 100644 src/generated/resources/data/advancedperipherals/loot_tables/blocks/gas_detector.json diff --git a/build.gradle b/build.gradle index 30e301837..fc8f8b115 100644 --- a/build.gradle +++ b/build.gradle @@ -270,11 +270,11 @@ dependencies { // Minecolonies // Change to compileOnly when running `runData` - implementation fg.deobf("com.ldtteam:minecolonies:${minecolonies_version}") - implementation fg.deobf("com.ldtteam:structurize:${structurize_version}") - implementation fg.deobf("com.ldtteam:multi-piston:${multipiston_version}") - implementation fg.deobf("com.ldtteam:domum_ornamentum:${domumornamentum_version}:universal") - implementation fg.deobf("com.ldtteam:blockui:${blockui_version}") + compileOnly fg.deobf("com.ldtteam:minecolonies:${minecolonies_version}") + compileOnly fg.deobf("com.ldtteam:structurize:${structurize_version}") + compileOnly fg.deobf("com.ldtteam:multi-piston:${multipiston_version}") + compileOnly fg.deobf("com.ldtteam:domum_ornamentum:${domumornamentum_version}:universal") + compileOnly fg.deobf("com.ldtteam:blockui:${blockui_version}") //Patchouli runtimeOnly fg.deobf("vazkii.patchouli:Patchouli:${patchouli_version}") diff --git a/gradle.properties b/gradle.properties index 3d8f4ef85..33ea268fa 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,9 +4,9 @@ org.gradle.logging.level=info # Minecraft related minecraft_version=1.19.2 -forge_version=43.1.25 -mod_version=0.7.19a -release_type=alpha +forge_version=43.1.32 +mod_version=0.7.21b +release_type=beta mappings_channel=parchment mappings_version=2022.09.18-1.19.2 jb_annotations=21.0.1 @@ -21,20 +21,20 @@ ttoolkit_version=0.1.3 # Mod dependencies cc_version=1.19.1:1.100.9 curios_version=1.19.2-5.1.1.0 -minecolonies_version=1.19.2-1.0.1039-ALPHA +minecolonies_version=1.19.2-1.0.1060-ALPHA appliedenergistics_version=12.1.2-beta patchouli_version=1.19.2-76 refinedstorage_version=1.11.0 botania_version=1.19.2-436-SNAPSHOT -create_version=0.5.0.d -flywheel_version=0.6.5 +create_version=0.5.0.f-15 +flywheel_version=0.6.7-8 mekanism_version=1.19.2-10.3.3.470 # Mod dependencies which are needed for other mods # For minecolonies -structurize_version=1.19.2-1.0.446-ALPHA +structurize_version=1.19.2-1.0.452-ALPHA domumornamentum_version=1.19-1.0.58-ALPHA -blockui_version=1.19-0.0.60-ALPHA +blockui_version=1.19-0.0.64-ALPHA multipiston_version=1.19-1.2.14-ALPHA # Mod dependencies for testing stuff(Only used in the dev environment) diff --git a/src/generated/resources/.cache/67cce32b1c3cbbcb1f646605f4914e3f196986c2 b/src/generated/resources/.cache/67cce32b1c3cbbcb1f646605f4914e3f196986c2 index 6b97ec5b9..f2175ec6a 100644 --- a/src/generated/resources/.cache/67cce32b1c3cbbcb1f646605f4914e3f196986c2 +++ b/src/generated/resources/.cache/67cce32b1c3cbbcb1f646605f4914e3f196986c2 @@ -1,10 +1,12 @@ -// 1.19.2 2022-09-18T21:59:59.2621294 LootTables +// 1.19.2 2022-10-07T10:24:52.2412454 LootTables fecb8d92386c87945125ce5e4266faeb8275b540 data/advancedperipherals/loot_tables/blocks/ar_controller.json d865e8ac35302c486faf5c7122569c554186186d data/advancedperipherals/loot_tables/blocks/block_reader.json a6f896cc3dbd8da12737825ec71e32970f54025c data/advancedperipherals/loot_tables/blocks/chat_box.json f50f506ae1987537f76be4c05a81689b25798f91 data/advancedperipherals/loot_tables/blocks/colony_integrator.json 1d1b858d09538dc66bab2c33a2f9c58361a9c472 data/advancedperipherals/loot_tables/blocks/energy_detector.json 317004b1358ef9bf83957d2d6796529a226161c7 data/advancedperipherals/loot_tables/blocks/environment_detector.json +df6186990887f77b7db37ebb8ee50a7e7f096b0a data/advancedperipherals/loot_tables/blocks/fluid_detector.json +cea5a036d4ccdcc6ef026d1a226b5e13f1060676 data/advancedperipherals/loot_tables/blocks/gas_detector.json d5a3964f518b138cbd7305c819a36af3d9340e4a data/advancedperipherals/loot_tables/blocks/geo_scanner.json 8aa1deea908fd02f049e047c8ca16679bbef68a2 data/advancedperipherals/loot_tables/blocks/inventory_manager.json 9a2898a63e2e0c087ce8eba211c63d1c8b9fd4aa data/advancedperipherals/loot_tables/blocks/me_bridge.json diff --git a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e index e8bb7ec6b..ca7d18598 100644 --- a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e +++ b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e @@ -1,4 +1,4 @@ -// 1.19.2 2022-09-22T14:09:48.8685449 Recipes +// 1.19.2 2022-10-07T10:24:52.2479404 Recipes 045608027e4a5ea2d7dee7f402346b8e69f21675 data/advancedperipherals/advancements/recipes/advancedperipheralstab/armor/smart_glasses_netherite.json f472724394edd655a415d4af08c9a63509cc5098 data/advancedperipherals/advancements/recipes/advancedperipheralstab/ar_controller.json db2dada2fdf42ca1bbf47f1eb075d1f9de89dfa8 data/advancedperipherals/advancements/recipes/advancedperipheralstab/block_reader.json @@ -24,12 +24,14 @@ fc0c3d99bec43318802f357083c7d98fde92567f data/advancedperipherals/advancements/r b10b5cbcc668438001744d5b90d9838ab4d293cb data/advancedperipherals/recipes/block_reader.json 3c9618832fe0ac32cac0f04fbc5afad225418239 data/advancedperipherals/recipes/chat_box.json a78adfcca4c7579b143aac5648a7eca9085c0dba data/advancedperipherals/recipes/chunk_controller.json +d4c090dc64185fab9b123fffeda6966308b6c3d0 data/advancedperipherals/recipes/colony_integrator.json f1f468c732f8c802c27776d3fd7aac432bcac8e3 data/advancedperipherals/recipes/computer_tool.json 4f0d0427d8c8774e350e7cfd1767a9e4802f4ca1 data/advancedperipherals/recipes/energy_detector.json 55c257e4e8548d1453a7ab96c547d64c22b3e1d6 data/advancedperipherals/recipes/environment_detector.json 2ddf64c122165bcd3a277db8a1c7e96b4d510c67 data/advancedperipherals/recipes/geo_scanner.json ebe70aa9fe80c5b962c13aa1fbadc32269ba81b9 data/advancedperipherals/recipes/inventory_manager.json 809bc6929cf5eab72648e8f1fb565b58749fec12 data/advancedperipherals/recipes/memory_card.json +82895838af6c6aea0c60e3a3fbf71073ab684167 data/advancedperipherals/recipes/me_bridge.json 8a73c4eb66e7a1cdc8e51d33466cf5a30da9270e data/advancedperipherals/recipes/nbt_storage.json 360432f30d61291066aa8c54692629f7a92e178d data/advancedperipherals/recipes/overpowered_end_automata_core.json 4ea6e90d13a61d90ad245539d20020ff9cb843e1 data/advancedperipherals/recipes/overpowered_husbandry_automata_core.json @@ -37,5 +39,6 @@ ebe70aa9fe80c5b962c13aa1fbadc32269ba81b9 data/advancedperipherals/recipes/invent a91556eb09a2a8c57b323928a76095a4b17241b7 data/advancedperipherals/recipes/peripheral_casing.json 1d476bfb11dcf490cefa9916695d91aec0cc8a19 data/advancedperipherals/recipes/player_detector.json 110983bae78f033dc8b12fd04ba3b7edcf035237 data/advancedperipherals/recipes/redstone_integrator.json +4ba2670271ef2b7c8be861f6277ae24c307dac5b data/advancedperipherals/recipes/rs_bridge.json 7008b3421135b3150e8c7e509166498a2b2df131 data/advancedperipherals/recipes/smart_glasses.json 7c783b341e783b22be4e40efbe3c88947e1902ec data/advancedperipherals/recipes/weak_automata_core.json diff --git a/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 b/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 index 509dce641..bed03da69 100644 --- a/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 +++ b/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 @@ -1,2 +1,2 @@ -// 1.19.2 2022-09-30T16:40:29.8471928 Languages: en_us -f5f8c5cae824fc715613b498e8c9fbdba7d1e4cf assets/advancedperipherals/lang/en_us.json +// 1.19.2 2022-10-07T10:24:52.2614728 Languages: en_us +c2fe721c9d493494ac03242345af883cea5f2d07 assets/advancedperipherals/lang/en_us.json diff --git a/src/generated/resources/.cache/f95c7003282837dabaa33e3ffceec4e6865b5218 b/src/generated/resources/.cache/f95c7003282837dabaa33e3ffceec4e6865b5218 index 48b0ea12c..7d6ca6f74 100644 --- a/src/generated/resources/.cache/f95c7003282837dabaa33e3ffceec4e6865b5218 +++ b/src/generated/resources/.cache/f95c7003282837dabaa33e3ffceec4e6865b5218 @@ -1,4 +1,4 @@ -// 1.19.2 2022-09-18T21:59:59.2631306 Block tags +// 1.19.2 2022-10-07T10:24:52.2564506 Block tags e1f71dcb4f9e7e36e29b0ad09d6520dc3adfa4a6 data/forge/tags/blocks/needs_wood_tool.json -aa3c995c482070372988ae730b3a4ade69199ee8 data/minecraft/tags/blocks/mineable/pickaxe.json -211d5a3979636298f7cc099cc8b4ffa6664d18a8 data/minecraft/tags/blocks/needs_iron_tool.json +a2af89cb645c94eccda0bca93ec0255f23602444 data/minecraft/tags/blocks/mineable/pickaxe.json +b67fec361e71d5073cbcdfaf8a5f8dbdf1c56971 data/minecraft/tags/blocks/needs_iron_tool.json diff --git a/src/generated/resources/assets/advancedperipherals/lang/en_us.json b/src/generated/resources/assets/advancedperipherals/lang/en_us.json index c216841cc..51e266d28 100644 --- a/src/generated/resources/assets/advancedperipherals/lang/en_us.json +++ b/src/generated/resources/assets/advancedperipherals/lang/en_us.json @@ -42,7 +42,7 @@ "item.advancedperipherals.tooltip.chat_box": "&7Interacts with the ingame chat, can read and write messages.", "item.advancedperipherals.tooltip.chunk_controller": "&7A crafting ingredient for the Chunky Turtle.", "item.advancedperipherals.tooltip.colony_integrator": "&7Interacts with Minecolonies to read data about your colony and citizens.", - "item.advancedperipherals.tooltip.computer_tool": "&7This tool was made to tune our blocks. But for now, it's just a blue useless wrench.", + "item.advancedperipherals.tooltip.computer_tool": "&7This tool was made to tune our APBlocks. But for now, it's just a blue useless wrench.", "item.advancedperipherals.tooltip.disabled": "&cThis item is disabled in config, so you can craft it, but it'll not have any functionality.", "item.advancedperipherals.tooltip.end_automata_core": "&7Upgrade for turtles, that allows basic interaction with the world and teleportation in one dimension.", "item.advancedperipherals.tooltip.energy_detector": "&7Can detect energy flow and acts as a resistor.", @@ -50,7 +50,7 @@ "item.advancedperipherals.tooltip.geo_scanner": "&7Scans the area around it to find some shiny ores.", "item.advancedperipherals.tooltip.husbandry_automata_core": "&7Upgrade for turtles, that allows basic and advanced interaction with animals.", "item.advancedperipherals.tooltip.inventory_manager": "&7This block is able to send or receive specific items from a player inventory.", - "item.advancedperipherals.tooltip.me_bridge": "&7This peripheral interacts with Applied Energistics 2 to read and craft items.", + "item.advancedperipherals.tooltip.me_bridge": "&7This peripheral interacts with Applied Energistics 2 to read and craft APItems.", "item.advancedperipherals.tooltip.memory_card": "&7Can save the rights of a player to use it in an inventory manager.", "item.advancedperipherals.tooltip.memory_card.bound": "&7Bound to &b%s&7.", "item.advancedperipherals.tooltip.nbt_storage": "&7Acts like a storage disk. Can store nbt based data like.", @@ -60,7 +60,7 @@ "item.advancedperipherals.tooltip.peripheral_casing": "&7An empty hull without the love it deserves. Used as crafting ingredient", "item.advancedperipherals.tooltip.player_detector": "&7This peripheral can be used to interact with players, but don't be a stalker.", "item.advancedperipherals.tooltip.redstone_integrator": "&7This block is able to interact with redstone. Works exactly like the redstone api of an computer.", - "item.advancedperipherals.tooltip.rs_bridge": "&7This wonderful block interacts with Refined Storage to read and craft items.", + "item.advancedperipherals.tooltip.rs_bridge": "&7This wonderful block interacts with Refined Storage to read and craft APItems.", "item.advancedperipherals.tooltip.show_desc": "&b[&7%s&b] &7For Description", "item.advancedperipherals.tooltip.weak_automata_core": "&7Upgrade for turtles, which makes turtles more useful.", "item.advancedperipherals.weak_automata_core": "Weak Automata Core", diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/fluid_detector.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/fluid_detector.json new file mode 100644 index 000000000..731bc1f02 --- /dev/null +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/fluid_detector.json @@ -0,0 +1,20 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "advancedperipherals:fluid_detector" + } + ], + "rolls": 1.0 + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/gas_detector.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/gas_detector.json new file mode 100644 index 000000000..dadeb8bc5 --- /dev/null +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/gas_detector.json @@ -0,0 +1,20 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "advancedperipherals:gas_detector" + } + ], + "rolls": 1.0 + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json b/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json index 8bf77ff86..b0331ffb1 100644 --- a/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json +++ b/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json @@ -6,6 +6,8 @@ "advancedperipherals:me_bridge", "advancedperipherals:rs_bridge", "advancedperipherals:energy_detector", + "advancedperipherals:fluid_detector", + "advancedperipherals:gas_detector", "advancedperipherals:peripheral_casing", "advancedperipherals:ar_controller", "advancedperipherals:inventory_manager", diff --git a/src/generated/resources/data/minecraft/tags/blocks/needs_iron_tool.json b/src/generated/resources/data/minecraft/tags/blocks/needs_iron_tool.json index 5f8f25023..31ba7d77c 100644 --- a/src/generated/resources/data/minecraft/tags/blocks/needs_iron_tool.json +++ b/src/generated/resources/data/minecraft/tags/blocks/needs_iron_tool.json @@ -6,6 +6,8 @@ "advancedperipherals:me_bridge", "advancedperipherals:rs_bridge", "advancedperipherals:energy_detector", + "advancedperipherals:fluid_detector", + "advancedperipherals:gas_detector", "advancedperipherals:ar_controller", "advancedperipherals:inventory_manager", "advancedperipherals:redstone_integrator", diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnergyDetectorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnergyDetectorEntity.java index 6111e0970..06228579f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnergyDetectorEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnergyDetectorEntity.java @@ -79,9 +79,9 @@ public void handleTick(Level level, BlockState state, Bl } @Override - public void deserializeNBT(CompoundTag nbt) { + public void load(CompoundTag nbt) { storageProxy.setMaxTransferRate(nbt.getInt("rateLimit")); - super.deserializeNBT(nbt); + super.load(nbt); } // returns the cached output storage of the receiving block or fetches it if it has been invalidated diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/FluidDetectorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/FluidDetectorEntity.java index b3ed0b9fd..95f692c26 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/FluidDetectorEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/FluidDetectorEntity.java @@ -81,9 +81,9 @@ public void handleTick(Level level, BlockState state, Bl } @Override - public void deserializeNBT(CompoundTag nbt) { + public void load(CompoundTag nbt) { storageProxy.setMaxTransferRate(nbt.getInt("rateLimit")); - super.deserializeNBT(nbt); + super.load(nbt); } // returns the cached output storage of the receiving block or fetches it if it has been invalidated diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/GasDetectorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/GasDetectorEntity.java index e45eea337..395558529 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/GasDetectorEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/GasDetectorEntity.java @@ -81,9 +81,9 @@ public void handleTick(Level level, BlockState state, Bl } @Override - public void deserializeNBT(CompoundTag nbt) { + public void load(CompoundTag nbt) { storageProxy.setMaxTransferRate(nbt.getInt("rateLimit")); - super.deserializeNBT(nbt); + super.load(nbt); } // returns the cached output storage of the receiving block or fetches it if it has been invalidated diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java index 7bafb3746..1d7d70ebe 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java @@ -2,10 +2,10 @@ import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.client.KeyBindings; -import de.srendi.advancedperipherals.common.setup.Blocks; +import de.srendi.advancedperipherals.common.setup.APBlocks; +import de.srendi.advancedperipherals.common.setup.APItems; +import de.srendi.advancedperipherals.common.setup.APVillagers; import de.srendi.advancedperipherals.common.setup.CCRegistration; -import de.srendi.advancedperipherals.common.setup.Items; -import de.srendi.advancedperipherals.common.setup.Villagers; import net.minecraft.client.KeyMapping; import net.minecraft.data.DataGenerator; import net.minecraft.resources.ResourceLocation; @@ -34,37 +34,37 @@ protected void addTranslations() { addTooltips(); addKeybinds(); addText(); - add(Villagers.COMPUTER_SCIENTIST, "Computer Scientist"); + add(APVillagers.COMPUTER_SCIENTIST, "Computer Scientist"); add("itemGroup." + AdvancedPeripherals.TAB.getRecipeFolderName(), "Advanced Peripherals"); } private void addItems() { - addItem(Items.CHUNK_CONTROLLER, "Chunk Controller"); - addItem(Items.COMPUTER_TOOL, "Computer Tool"); - addItem(Items.WEAK_AUTOMATA_CORE, "Weak Automata Core"); - addItem(Items.HUSBANDRY_AUTOMATA_CORE, "Husbandry Automata Core"); - addItem(Items.END_AUTOMATA_CORE, "End Automata Core"); - addItem(Items.OVERPOWERED_WEAK_AUTOMATA_CORE, "Overpowered Weak Automata Core"); - addItem(Items.OVERPOWERED_HUSBANDRY_AUTOMATA_CORE, "Overpowered Husbandry Automata Core"); - addItem(Items.OVERPOWERED_END_AUTOMATA_CORE, "Overpowered End Automata Core"); - addItem(Items.MEMORY_CARD, "Memory Card"); + addItem(APItems.CHUNK_CONTROLLER, "Chunk Controller"); + addItem(APItems.COMPUTER_TOOL, "Computer Tool"); + addItem(APItems.WEAK_AUTOMATA_CORE, "Weak Automata Core"); + addItem(APItems.HUSBANDRY_AUTOMATA_CORE, "Husbandry Automata Core"); + addItem(APItems.END_AUTOMATA_CORE, "End Automata Core"); + addItem(APItems.OVERPOWERED_WEAK_AUTOMATA_CORE, "Overpowered Weak Automata Core"); + addItem(APItems.OVERPOWERED_HUSBANDRY_AUTOMATA_CORE, "Overpowered Husbandry Automata Core"); + addItem(APItems.OVERPOWERED_END_AUTOMATA_CORE, "Overpowered End Automata Core"); + addItem(APItems.MEMORY_CARD, "Memory Card"); } private void addBlocks() { - addBlock(Blocks.BLOCK_READER, "Block Reader"); - addBlock(Blocks.CHAT_BOX, "Chat Box"); - addBlock(Blocks.AR_CONTROLLER, "Ar Controller"); - addBlock(Blocks.COLONY_INTEGRATOR, "Colony Integrator"); - addBlock(Blocks.ENERGY_DETECTOR, "Energy Detector"); - addBlock(Blocks.ENVIRONMENT_DETECTOR, "Environment Detector"); - addBlock(Blocks.GEO_SCANNER, "Geo Scanner"); - addBlock(Blocks.INVENTORY_MANAGER, "Inventory Manager"); - addBlock(Blocks.ME_BRIDGE, "ME Bridge"); - addBlock(Blocks.RS_BRIDGE, "RS Bridge"); - addBlock(Blocks.NBT_STORAGE, "NBT Storage"); - addBlock(Blocks.PERIPHERAL_CASING, "Peripheral Casing"); - addBlock(Blocks.PLAYER_DETECTOR, "Player Detector"); - addBlock(Blocks.REDSTONE_INTEGRATOR, "Redstone Integrator"); + addBlock(APBlocks.BLOCK_READER, "Block Reader"); + addBlock(APBlocks.CHAT_BOX, "Chat Box"); + addBlock(APBlocks.AR_CONTROLLER, "Ar Controller"); + addBlock(APBlocks.COLONY_INTEGRATOR, "Colony Integrator"); + addBlock(APBlocks.ENERGY_DETECTOR, "Energy Detector"); + addBlock(APBlocks.ENVIRONMENT_DETECTOR, "Environment Detector"); + addBlock(APBlocks.GEO_SCANNER, "Geo Scanner"); + addBlock(APBlocks.INVENTORY_MANAGER, "Inventory Manager"); + addBlock(APBlocks.ME_BRIDGE, "ME Bridge"); + addBlock(APBlocks.RS_BRIDGE, "RS Bridge"); + addBlock(APBlocks.NBT_STORAGE, "NBT Storage"); + addBlock(APBlocks.PERIPHERAL_CASING, "Peripheral Casing"); + addBlock(APBlocks.PLAYER_DETECTOR, "Player Detector"); + addBlock(APBlocks.REDSTONE_INTEGRATOR, "Redstone Integrator"); } private void addTurtles() { @@ -105,29 +105,29 @@ private void addAdvancements() { private void addTooltips() { addTooltip("show_desc", "&b[&7%s&b] &7For Description"); addTooltip("disabled", "&cThis item is disabled in config, so you can craft it, but it'll not have any functionality."); - addTooltip(Items.COMPUTER_TOOL.get(), "&7This tool was made to tune our blocks. But for now, it's just a blue useless wrench."); - addTooltip(Blocks.ENERGY_DETECTOR.get(), "&7Can detect energy flow and acts as a resistor."); - addTooltip(Items.CHUNK_CONTROLLER.get(), "&7A crafting ingredient for the Chunky Turtle."); - addTooltip(Blocks.ENVIRONMENT_DETECTOR.get(), "&7This peripheral interacts with the minecraft world."); - addTooltip(Blocks.PLAYER_DETECTOR.get(), "&7This peripheral can be used to interact with players, but don't be a stalker."); - addTooltip(Blocks.RS_BRIDGE.get(), "&7This wonderful block interacts with Refined Storage to read and craft items."); - addTooltip(Blocks.ME_BRIDGE.get(), "&7This peripheral interacts with Applied Energistics 2 to read and craft items."); - addTooltip(Blocks.CHAT_BOX.get(), "&7Interacts with the ingame chat, can read and write messages."); - addTooltip(Blocks.PERIPHERAL_CASING.get(), "&7An empty hull without the love it deserves. Used as crafting ingredient"); - addTooltip(Items.MEMORY_CARD.get(), "&7Can save the rights of a player to use it in an inventory manager."); + addTooltip(APItems.COMPUTER_TOOL.get(), "&7This tool was made to tune our APBlocks. But for now, it's just a blue useless wrench."); + addTooltip(APBlocks.ENERGY_DETECTOR.get(), "&7Can detect energy flow and acts as a resistor."); + addTooltip(APItems.CHUNK_CONTROLLER.get(), "&7A crafting ingredient for the Chunky Turtle."); + addTooltip(APBlocks.ENVIRONMENT_DETECTOR.get(), "&7This peripheral interacts with the minecraft world."); + addTooltip(APBlocks.PLAYER_DETECTOR.get(), "&7This peripheral can be used to interact with players, but don't be a stalker."); + addTooltip(APBlocks.RS_BRIDGE.get(), "&7This wonderful block interacts with Refined Storage to read and craft APItems."); + addTooltip(APBlocks.ME_BRIDGE.get(), "&7This peripheral interacts with Applied Energistics 2 to read and craft APItems."); + addTooltip(APBlocks.CHAT_BOX.get(), "&7Interacts with the ingame chat, can read and write messages."); + addTooltip(APBlocks.PERIPHERAL_CASING.get(), "&7An empty hull without the love it deserves. Used as crafting ingredient"); + addTooltip(APItems.MEMORY_CARD.get(), "&7Can save the rights of a player to use it in an inventory manager."); addTooltip("memory_card.bound", "&7Bound to &b%s&7."); - addTooltip(Blocks.INVENTORY_MANAGER.get(), "&7This block is able to send or receive specific items from a player inventory."); - addTooltip(Blocks.REDSTONE_INTEGRATOR.get(), "&7This block is able to interact with redstone. Works exactly like the redstone api of an computer."); - addTooltip(Blocks.BLOCK_READER.get(), "&7Reads nbt data of blocks to interact with blocks which do not have computer support."); - addTooltip(Blocks.GEO_SCANNER.get(), "&7Scans the area around it to find some shiny ores."); - addTooltip(Blocks.COLONY_INTEGRATOR.get(), "&7Interacts with Minecolonies to read data about your colony and citizens."); - addTooltip(Blocks.NBT_STORAGE.get(), "&7Acts like a storage disk. Can store nbt based data like."); - addTooltip(Items.WEAK_AUTOMATA_CORE.get(), "&7Upgrade for turtles, which makes turtles more useful."); - addTooltip(Items.OVERPOWERED_WEAK_AUTOMATA_CORE.get(), "&7Improved version of the weak automata core, that provide some overpowered uses! Be careful, the upgrade is very fragile."); - addTooltip(Items.HUSBANDRY_AUTOMATA_CORE.get(), "&7Upgrade for turtles, that allows basic and advanced interaction with animals."); - addTooltip(Items.OVERPOWERED_HUSBANDRY_AUTOMATA_CORE.get(), "&7Improved version of the husbandry automata core, that provides some overpowered uses! Be careful, the upgrade is very fragile."); - addTooltip(Items.END_AUTOMATA_CORE.get(), "&7Upgrade for turtles, that allows basic interaction with the world and teleportation in one dimension."); - addTooltip(Items.OVERPOWERED_END_AUTOMATA_CORE.get(), "&7Improved version of the end automata core, that provides some overpowered uses! Be careful, the upgrade is very fragile."); + addTooltip(APBlocks.INVENTORY_MANAGER.get(), "&7This block is able to send or receive specific items from a player inventory."); + addTooltip(APBlocks.REDSTONE_INTEGRATOR.get(), "&7This block is able to interact with redstone. Works exactly like the redstone api of an computer."); + addTooltip(APBlocks.BLOCK_READER.get(), "&7Reads nbt data of blocks to interact with blocks which do not have computer support."); + addTooltip(APBlocks.GEO_SCANNER.get(), "&7Scans the area around it to find some shiny ores."); + addTooltip(APBlocks.COLONY_INTEGRATOR.get(), "&7Interacts with Minecolonies to read data about your colony and citizens."); + addTooltip(APBlocks.NBT_STORAGE.get(), "&7Acts like a storage disk. Can store nbt based data like."); + addTooltip(APItems.WEAK_AUTOMATA_CORE.get(), "&7Upgrade for turtles, which makes turtles more useful."); + addTooltip(APItems.OVERPOWERED_WEAK_AUTOMATA_CORE.get(), "&7Improved version of the weak automata core, that provide some overpowered uses! Be careful, the upgrade is very fragile."); + addTooltip(APItems.HUSBANDRY_AUTOMATA_CORE.get(), "&7Upgrade for turtles, that allows basic and advanced interaction with animals."); + addTooltip(APItems.OVERPOWERED_HUSBANDRY_AUTOMATA_CORE.get(), "&7Improved version of the husbandry automata core, that provides some overpowered uses! Be careful, the upgrade is very fragile."); + addTooltip(APItems.END_AUTOMATA_CORE.get(), "&7Upgrade for turtles, that allows basic interaction with the world and teleportation in one dimension."); + addTooltip(APItems.OVERPOWERED_END_AUTOMATA_CORE.get(), "&7Improved version of the end automata core, that provides some overpowered uses! Be careful, the upgrade is very fragile."); } private void addText() { diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java index 3b36a9e8f..6d81f03a7 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java @@ -1,9 +1,13 @@ package de.srendi.advancedperipherals.common.data; +import appeng.core.definitions.AEBlocks; +import com.refinedmods.refinedstorage.RSBlocks; +import com.refinedmods.refinedstorage.RSItems; import dan200.computercraft.shared.Registry; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.setup.APBlocks; import de.srendi.advancedperipherals.common.setup.APItems; +import de.srendi.advancedperipherals.common.util.RawValue; import net.minecraft.data.DataGenerator; import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.data.recipes.RecipeProvider; @@ -19,6 +23,7 @@ import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.level.block.Block; import net.minecraftforge.common.Tags; +import net.minecraftforge.common.crafting.ConditionalRecipe; import net.minecraftforge.common.crafting.StrictNBTIngredient; import net.minecraftforge.common.crafting.conditions.IConditionBuilder; import org.jetbrains.annotations.NotNull; @@ -225,7 +230,7 @@ private void addShaped(@NotNull Consumer consumer) { modLoaded("minecolonies") ) .addRecipe( - ShapedRecipeBuilder.shaped(Blocks.COLONY_INTEGRATOR.get()) + ShapedRecipeBuilder.shaped(APBlocks.COLONY_INTEGRATOR.get()) .define('O', ItemTags.LOGS) .define('A', CASING) .define('R', Ingredient.fromValues(Stream.of(new RawValue(new ResourceLocation("minecolonies", "blockminecoloniesrack"))))) @@ -240,7 +245,7 @@ private void addShaped(@NotNull Consumer consumer) { modLoaded("ae2") ) .addRecipe( - ShapedRecipeBuilder.shaped(Blocks.ME_BRIDGE.get()) + ShapedRecipeBuilder.shaped(APBlocks.ME_BRIDGE.get()) .define('F', AEBlocks.FLUIX_BLOCK.asItem()) .define('A', CASING) .define('I', AEBlocks.INTERFACE.asItem()) @@ -255,7 +260,7 @@ private void addShaped(@NotNull Consumer consumer) { modLoaded("refinedstorage") ) .addRecipe( - ShapedRecipeBuilder.shaped(Blocks.RS_BRIDGE.get()) + ShapedRecipeBuilder.shaped(APBlocks.RS_BRIDGE.get()) .define('Q', RSItems.QUARTZ_ENRICHED_IRON.get()) .define('A', CASING) .define('I', RSBlocks.INTERFACE.get()) @@ -265,7 +270,7 @@ private void addShaped(@NotNull Consumer consumer) { .unlockedBy("has_item", has(CASING))::save ).build(consumer, new ResourceLocation(AdvancedPeripherals.MOD_ID, "rs_bridge")); - ShapedRecipeBuilder.shaped(de.srendi.advancedperipherals.common.setup.Items.WEAK_AUTOMATA_CORE.get()) + ShapedRecipeBuilder.shaped(APItems.WEAK_AUTOMATA_CORE.get()) .define('A', CASING) .define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE) .define('S', Items.SOUL_LANTERN) From a8cd77811923f272d4c121403b39700745033253 Mon Sep 17 00:00:00 2001 From: Sr_endi Date: Sat, 8 Oct 2022 22:09:11 +0200 Subject: [PATCH 006/228] Fixed `getTransferRate()` - gas detector --- .../srendi/advancedperipherals/common/util/GasStorageProxy.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/GasStorageProxy.java b/src/main/java/de/srendi/advancedperipherals/common/util/GasStorageProxy.java index 136416645..18335eb6d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/GasStorageProxy.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/GasStorageProxy.java @@ -78,7 +78,7 @@ public GasStack insertChemical(@NotNull GasStack stack, @NotNull Action action) transferring.setAmount(Math.min(stack.getAmount(), maxTransferRate)); GasStack transferred = outStorage.insertChemical(transferring, action); if (!action.simulate()) { - transferedInThisTick += transferred.getAmount(); + transferedInThisTick += transferring.getAmount() - transferred.getAmount(); fluidDetectorEntity.lastFlowedGas = stack.copy(); } return transferred; From e70e1c8955c8a3cce2a8973f9d1676b6bd851a00 Mon Sep 17 00:00:00 2001 From: DenizD Date: Thu, 20 Oct 2022 13:39:42 +0200 Subject: [PATCH 007/228] [#320] Added the basics of a distance detector Checking the distance does work for the upper direction of the block The key elements are mising - Height mode - Mode for transparent blocks - Mode for entities - Laser visibility - direction of the block --- .../DistanceDetectorPeripheral.java | 75 +++++++++++++++++++ .../blockentities/DistanceDetectorEntity.java | 22 ++++++ .../common/setup/APBlockEntityTypes.java | 2 + .../common/setup/APBlocks.java | 1 + .../common/setup/APItems.java | 4 +- .../common/util/GasStorageProxy.java | 2 +- 6 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java new file mode 100644 index 000000000..922f02b1a --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java @@ -0,0 +1,75 @@ +package de.srendi.advancedperipherals.common.addons.computercraft.peripheral; + +import dan200.computercraft.api.lua.LuaFunction; +import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner; +import de.srendi.advancedperipherals.common.blocks.blockentities.DistanceDetectorEntity; +import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; +import net.minecraft.core.Direction; +import net.minecraft.world.level.ClipContext; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.HitResult; +import net.minecraft.world.phys.Vec3; + +public class DistanceDetectorPeripheral extends BasePeripheral> { + + public static final String TYPE = "distanceDetector"; + private double height = 0.5; + + public DistanceDetectorPeripheral(DistanceDetectorEntity tileEntity) { + super(TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); + } + + @Override + public boolean isEnabled() { + return true; + } + + + public final boolean setLaserVisibility(boolean laser) { + return false; + } + + public final boolean getLaserVisibility() { + return false; + } + + public final boolean setTransparencyDetection(boolean enable) { + return false; + } + + public final boolean getTransparencyDetection() { + return false; + } + + public final boolean setAllowEntityDetection(boolean enable) { + return false; + } + + public final boolean getEntityDetection() { + return false; + } + + public final double setHeight(double height) { + if(height > 1) + this.height = 1; + if(height < 0) + this.height = 0; + return this.height; + } + + public final double getHeight() { + return this.height; + } + + @LuaFunction(mainThread = true) + public final double getDistance() { + //Just testing, will be the direction of the block later + Direction direction = Direction.UP; + Vec3 from = Vec3.atCenterOf(getPos()).add(direction.getNormal().getX() * 0.501, direction.getNormal().getY() * 0.501, direction.getNormal().getZ() * 0.501); + Vec3 to = from.add(direction.getNormal().getX() * 16, direction.getNormal().getY() * 16, direction.getNormal().getZ() * 16); + BlockHitResult result = getLevel().clip(new ClipContext(from, to, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, null)); + + return result.getType() != HitResult.Type.MISS ? getPos().distManhattan(result.getBlockPos())-1 : -1; + } + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java new file mode 100644 index 000000000..8a256e024 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java @@ -0,0 +1,22 @@ +package de.srendi.advancedperipherals.common.blocks.blockentities; + +import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.DistanceDetectorPeripheral; +import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; +import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.NotNull; + +public class DistanceDetectorEntity extends PeripheralBlockEntity { + + public DistanceDetectorEntity(BlockPos pos, BlockState state) { + super(APBlockEntityTypes.DISTANCE_DETECTOR.get(), pos, state); + } + + @NotNull + @Override + protected DistanceDetectorPeripheral createPeripheral() { + return new DistanceDetectorPeripheral(this); + } + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java index 50f30a154..3bb5efeb1 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java @@ -4,6 +4,7 @@ import de.srendi.advancedperipherals.common.blocks.blockentities.BlockReaderEntity; import de.srendi.advancedperipherals.common.blocks.blockentities.ChatBoxEnity; import de.srendi.advancedperipherals.common.blocks.blockentities.ColonyIntegratorEntity; +import de.srendi.advancedperipherals.common.blocks.blockentities.DistanceDetectorEntity; import de.srendi.advancedperipherals.common.blocks.blockentities.EnergyDetectorEntity; import de.srendi.advancedperipherals.common.blocks.blockentities.EnvironmentDetectorEntity; import de.srendi.advancedperipherals.common.blocks.blockentities.FluidDetectorEntity; @@ -40,5 +41,6 @@ static void register() { public static final RegistryObject> GEO_SCANNER = APRegistration.TILE_ENTITIES.register("geo_scanner", () -> new BlockEntityType<>(GeoScannerEntity::new, Sets.newHashSet(APBlocks.GEO_SCANNER.get()), null)); public static final RegistryObject> COLONY_INTEGRATOR = APRegistration.TILE_ENTITIES.register("colony_integrator", () -> new BlockEntityType<>(ColonyIntegratorEntity::new, Sets.newHashSet(APBlocks.COLONY_INTEGRATOR.get()), null)); public static final RegistryObject> NBT_STORAGE = APRegistration.TILE_ENTITIES.register("nbt_storage", () -> new BlockEntityType<>(NBTStorageEntity::new, Sets.newHashSet(APBlocks.NBT_STORAGE.get()), null)); + public static final RegistryObject> DISTANCE_DETECTOR = APRegistration.TILE_ENTITIES.register("distance_detector", () -> new BlockEntityType<>(DistanceDetectorEntity::new, Sets.newHashSet(APBlocks.DISTANCE_DETECTOR.get()), null)); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java index e253dbfdd..f8d6c5915 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java @@ -38,6 +38,7 @@ static void register() { public static final RegistryObject GEO_SCANNER = register("geo_scanner", () -> new APBlockEntityBlock<>(APBlockEntityTypes.GEO_SCANNER, false), () -> new APBlockItem(APBlocks.GEO_SCANNER.get(), CCRegistration.ID.GEOSCANNER_TURTLE, CCRegistration.ID.GEOSCANNER_POCKET, APConfig.PERIPHERALS_CONFIG.enableGeoScanner)); public static final RegistryObject COLONY_INTEGRATOR = register("colony_integrator", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("minecolonies") ? APBlockEntityTypes.COLONY_INTEGRATOR : null, false), () -> new APBlockItem(APBlocks.COLONY_INTEGRATOR.get(), null, CCRegistration.ID.COLONY_POCKET, APConfig.PERIPHERALS_CONFIG.enableColonyIntegrator)); public static final RegistryObject NBT_STORAGE = register("nbt_storage", () -> new APBlockEntityBlock<>(APBlockEntityTypes.NBT_STORAGE, false), () -> new APBlockItem(APBlocks.NBT_STORAGE.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableNBTStorage)); + public static final RegistryObject DISTANCE_DETECTOR = register("distance_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.DISTANCE_DETECTOR, false), () -> new APBlockItem(APBlocks.DISTANCE_DETECTOR.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableNBTStorage)); private static RegistryObject registerNoItem(String name, Supplier block) { return APRegistration.BLOCKS.register(name, block); diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java index f53d49cc9..9cbfde8ce 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java @@ -13,9 +13,9 @@ public class APItems { public static final RegistryObject CHUNK_CONTROLLER = APRegistration.ITEMS.register("chunk_controller", () -> new APItem(new Item.Properties().stacksTo(16), CCRegistration.ID.CHUNKY_TURTLE, null, APConfig.PERIPHERALS_CONFIG.enableChunkyTurtle::get)); - public static final RegistryObject SMART_GLASSES = APRegistration.ITEMS.register("smart_glasses", ()-> new SmartGlassesItem(ArmorMaterials.CHAIN)); + public static final RegistryObject SMART_GLASSES = APRegistration.ITEMS.register("smart_glasses", () -> new SmartGlassesItem(ArmorMaterials.CHAIN)); - public static final RegistryObject SMART_GLASSES_NETHERITE = APRegistration.ITEMS.register("smart_glasses_netherite", ()-> new SmartGlassesItem(ArmorMaterials.NETHERITE)); + public static final RegistryObject SMART_GLASSES_NETHERITE = APRegistration.ITEMS.register("smart_glasses_netherite", () -> new SmartGlassesItem(ArmorMaterials.NETHERITE)); public static final RegistryObject COMPUTER_TOOL = APRegistration.ITEMS.register("computer_tool", () -> new APItem(new Item.Properties().stacksTo(1), null, null, () -> true)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/GasStorageProxy.java b/src/main/java/de/srendi/advancedperipherals/common/util/GasStorageProxy.java index 18335eb6d..d4e514a6d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/GasStorageProxy.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/GasStorageProxy.java @@ -73,7 +73,7 @@ public boolean isValid(int tank, @NotNull GasStack stack) { @Override public GasStack insertChemical(@NotNull GasStack stack, @NotNull Action action) { Optional out = fluidDetectorEntity.getOutputStorage(); - return out.map(outStorage -> { + return out.map(outStorage -> { GasStack transferring = stack.copy(); transferring.setAmount(Math.min(stack.getAmount(), maxTransferRate)); GasStack transferred = outStorage.insertChemical(transferring, action); From c6e99d828d81f899463025efa07c25a81fab0645 Mon Sep 17 00:00:00 2001 From: DenizD Date: Thu, 20 Oct 2022 15:11:02 +0200 Subject: [PATCH 008/228] Added `getRadiation` to the environment detector --- .../IntegrationPeripheralProvider.java | 2 +- .../mekanism/EnvironmentRadiationPlugin.java | 21 +++++++++++++++++++ .../common/addons/mekanism/Integration.java | 11 ++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/EnvironmentRadiationPlugin.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/Integration.java diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/IntegrationPeripheralProvider.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/IntegrationPeripheralProvider.java index a6361b418..4c02f107e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/IntegrationPeripheralProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/IntegrationPeripheralProvider.java @@ -23,7 +23,7 @@ public class IntegrationPeripheralProvider implements IPeripheralProvider { - private static final String[] SUPPORTED_MODS = new String[]{"botania", "create"}; + private static final String[] SUPPORTED_MODS = new String[]{"botania", "create", "mekanism"}; private static final PriorityQueue integrations = new PriorityQueue<>(Comparator.comparingInt(IPeripheralIntegration::getPriority)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/EnvironmentRadiationPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/EnvironmentRadiationPlugin.java new file mode 100644 index 000000000..66dddef0b --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/EnvironmentRadiationPlugin.java @@ -0,0 +1,21 @@ +package de.srendi.advancedperipherals.common.addons.mekanism; + +import dan200.computercraft.api.lua.LuaFunction; +import de.srendi.advancedperipherals.common.addons.computercraft.owner.IPeripheralOwner; +import de.srendi.advancedperipherals.lib.peripherals.IPeripheralPlugin; +import mekanism.api.Coord4D; +import mekanism.api.MekanismAPI; + +public class EnvironmentRadiationPlugin implements IPeripheralPlugin { + private final IPeripheralOwner owner; + + public EnvironmentRadiationPlugin(IPeripheralOwner owner) { + this.owner = owner; + } + + @LuaFunction(mainThread = true) + public final double getRadiation() { + return MekanismAPI.getRadiationManager().getRadiationLevel(new Coord4D(owner.getPos(), owner.getLevel())); + } + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/Integration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/Integration.java new file mode 100644 index 000000000..9f880445a --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/Integration.java @@ -0,0 +1,11 @@ +package de.srendi.advancedperipherals.common.addons.mekanism; + +import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.EnvironmentDetectorPeripheral; + +public class Integration implements Runnable { + + @Override + public void run() { + EnvironmentDetectorPeripheral.addIntegrationPlugin(EnvironmentRadiationPlugin::new); + } +} From 4e3f144839066da91b5c1c31e55558e0b1c4d366 Mon Sep 17 00:00:00 2001 From: DenizD Date: Tue, 20 Dec 2022 13:03:00 +0100 Subject: [PATCH 009/228] 1.19.3 for 0.8 --- build.gradle | 7 - gradle.properties | 7 +- .../2db41954e490230d51b10affff25ee2ee27b8d5b | 2 +- ... 59eb3dbb5f86130e09b3c62d89b9525ee01cf52d} | 3 +- .../5a761efb7472ef97566e41e81451930a004134bf | 2 +- .../9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e | 84 +++--- .../ae219fa7c7d3297c14e454863eac3998a4eab78c | 2 +- .../c622617f6fabf890a00b9275cd5f643584a8a2c8 | 4 +- .../f95c7003282837dabaa33e3ffceec4e6865b5218 | 6 +- .../advancedperipherals/lang/en_us.json | 4 +- .../ar_controller.json | 0 .../armor/smart_glasses_netherite.json | 0 .../block_reader.json | 0 .../chat_box.json | 0 .../chunk_controller.json | 0 .../computer_tool.json | 0 .../energy_detector.json | 0 .../environment_detector.json | 0 .../geo_scanner.json | 0 .../inventory_manager.json | 0 .../memory_card.json | 0 .../nbt_storage.json | 0 .../overpowered_end_automata_core.json | 0 .../overpowered_husbandry_automata_core.json | 0 .../overpowered_weak_automata_core.json | 0 .../peripheral_casing.json | 0 .../player_detector.json | 0 .../redstone_integrator.json | 0 .../smart_glasses.json | 0 .../weak_automata_core.json | 0 .../loot_tables/blocks/distance_detector.json | 20 ++ .../recipes/block_reader.json | 1 + .../recipes/colony_integrator.json | 1 + .../recipes/geo_scanner.json | 1 + .../recipes/inventory_manager.json | 1 + .../recipes/me_bridge.json | 35 --- .../recipes/memory_card.json | 1 + .../recipes/nbt_storage.json | 1 + .../overpowered_end_automata_core.json | 1 + .../overpowered_husbandry_automata_core.json | 1 + .../overpowered_weak_automata_core.json | 1 + .../recipes/peripheral_casing.json | 1 + .../recipes/player_detector.json | 1 + .../recipes/redstone_integrator.json | 1 + .../recipes/rs_bridge.json | 35 --- .../recipes/weak_automata_core.json | 1 + .../tags/blocks/mineable/pickaxe.json | 3 +- .../tags/blocks/needs_iron_tool.json | 3 +- .../advancedperipherals/APCreativeTab.java | 8 +- .../AdvancedPeripherals.java | 21 +- .../common/addons/APAddons.java | 10 +- .../peripheral/ARControllerPeripheral.java | 0 .../DistanceDetectorPeripheral.java | 8 +- .../mekanism/EnvironmentRadiationPlugin.java | 2 - .../common/data/BlockLootTables.java | 6 +- .../common/data/BlockLootTablesProvider.java | 5 +- .../common/data/DataGenerators.java | 14 +- .../common/data/EnUsLanguageProvider.java | 102 +++---- .../common/data/PoiTypeProvider.java | 6 +- .../common/data/RecipesProvider.java | 261 ++++++++++++++++-- .../common/data/TurtleUpgradesProvider.java | 26 +- .../common/items/SmartGlassesItem.java | 3 +- .../common/setup/APBlockEntityTypes.java | 8 +- .../common/setup/APVillagers.java | 6 +- .../common/village/VillagerTrades.java | 2 - 65 files changed, 436 insertions(+), 282 deletions(-) rename src/generated/resources/.cache/{67cce32b1c3cbbcb1f646605f4914e3f196986c2 => 59eb3dbb5f86130e09b3c62d89b9525ee01cf52d} (91%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/ar_controller.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/armor/smart_glasses_netherite.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/block_reader.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/chat_box.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/chunk_controller.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/computer_tool.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/energy_detector.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/environment_detector.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/geo_scanner.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/inventory_manager.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/memory_card.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/nbt_storage.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/overpowered_end_automata_core.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/overpowered_husbandry_automata_core.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/overpowered_weak_automata_core.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/peripheral_casing.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/player_detector.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/redstone_integrator.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/smart_glasses.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/weak_automata_core.json (100%) create mode 100644 src/generated/resources/data/advancedperipherals/loot_tables/blocks/distance_detector.json delete mode 100644 src/generated/resources/data/advancedperipherals/recipes/me_bridge.json delete mode 100644 src/generated/resources/data/advancedperipherals/recipes/rs_bridge.json delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ARControllerPeripheral.java diff --git a/build.gradle b/build.gradle index e81024a0d..d58f86cf9 100644 --- a/build.gradle +++ b/build.gradle @@ -274,13 +274,6 @@ dependencies { transitive false } - compileOnly "mekanism:Mekanism:${mekanism_version}:api" - - runtimeOnly fg.deobf("mekanism:Mekanism:${mekanism_version}")// core - runtimeOnly fg.deobf("mekanism:Mekanism:${mekanism_version}:additions")// Mekanism: Additions - runtimeOnly fg.deobf("mekanism:Mekanism:${mekanism_version}:generators")// Mekanism: Generators - runtimeOnly fg.deobf("mekanism:Mekanism:${mekanism_version}:tools")// Mekanism: Tools - // Botania compileOnly fg.deobf("vazkii.botania:Botania:${botania_version}") diff --git a/gradle.properties b/gradle.properties index 97c319485..7b62c940e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,12 +4,11 @@ org.gradle.logging.level=info # Minecraft related minecraft_version=1.19.3 -forge_version=44.0.11 +forge_version=44.0.37 mod_version=0.7.22b release_type=beta -mappings_channel=official -#mappings_version=2022.11.27-1.19.2 -mappings_version=1.19.3 +mappings_channel=parchment +mappings_version=2022.12.18-1.19.3 jb_annotations=21.0.1 # Test dependencies diff --git a/src/generated/resources/.cache/2db41954e490230d51b10affff25ee2ee27b8d5b b/src/generated/resources/.cache/2db41954e490230d51b10affff25ee2ee27b8d5b index 85fe05707..601f02d7a 100644 --- a/src/generated/resources/.cache/2db41954e490230d51b10affff25ee2ee27b8d5b +++ b/src/generated/resources/.cache/2db41954e490230d51b10affff25ee2ee27b8d5b @@ -1,2 +1,2 @@ -// 1.19.2 2022-09-18T22:02:48.4292279 AP POI Type Tags +// 1.19.3 2022-12-20T12:47:00.0699917 AP POI Type Tags d3d6b837660a4e213f287ad9d11e12368b90cd8e data/minecraft/tags/point_of_interest_type/acquirable_job_site.json diff --git a/src/generated/resources/.cache/67cce32b1c3cbbcb1f646605f4914e3f196986c2 b/src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d similarity index 91% rename from src/generated/resources/.cache/67cce32b1c3cbbcb1f646605f4914e3f196986c2 rename to src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d index f2175ec6a..e21cd9619 100644 --- a/src/generated/resources/.cache/67cce32b1c3cbbcb1f646605f4914e3f196986c2 +++ b/src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d @@ -1,8 +1,9 @@ -// 1.19.2 2022-10-07T10:24:52.2412454 LootTables +// 1.19.3 2022-12-20T12:47:00.0739925 Loot Tables fecb8d92386c87945125ce5e4266faeb8275b540 data/advancedperipherals/loot_tables/blocks/ar_controller.json d865e8ac35302c486faf5c7122569c554186186d data/advancedperipherals/loot_tables/blocks/block_reader.json a6f896cc3dbd8da12737825ec71e32970f54025c data/advancedperipherals/loot_tables/blocks/chat_box.json f50f506ae1987537f76be4c05a81689b25798f91 data/advancedperipherals/loot_tables/blocks/colony_integrator.json +4dcad851450e4ddd8d28a0017a417bf6e5579bda data/advancedperipherals/loot_tables/blocks/distance_detector.json 1d1b858d09538dc66bab2c33a2f9c58361a9c472 data/advancedperipherals/loot_tables/blocks/energy_detector.json 317004b1358ef9bf83957d2d6796529a226161c7 data/advancedperipherals/loot_tables/blocks/environment_detector.json df6186990887f77b7db37ebb8ee50a7e7f096b0a data/advancedperipherals/loot_tables/blocks/fluid_detector.json diff --git a/src/generated/resources/.cache/5a761efb7472ef97566e41e81451930a004134bf b/src/generated/resources/.cache/5a761efb7472ef97566e41e81451930a004134bf index 96a9ae3e9..bf74b4055 100644 --- a/src/generated/resources/.cache/5a761efb7472ef97566e41e81451930a004134bf +++ b/src/generated/resources/.cache/5a761efb7472ef97566e41e81451930a004134bf @@ -1,4 +1,4 @@ -// 1.19.2 2022-09-18T21:59:59.2606291 Turtle Upgrades +// 1.19.3 2022-12-20T12:47:00.0559511 Turtle Upgrades b8f19ae0fb5bb898facc08e3787e0f96c8211881 data/advancedperipherals/computercraft/turtle_upgrades/chatty_turtle.json fe98c60e7d61139aacf2d0872873e610aac8a37b data/advancedperipherals/computercraft/turtle_upgrades/chunky_turtle.json ae619da638ad89d7302d832d6c09e2c87401c539 data/advancedperipherals/computercraft/turtle_upgrades/compass_turtle.json diff --git a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e index ca7d18598..0c27216dd 100644 --- a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e +++ b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e @@ -1,44 +1,42 @@ -// 1.19.2 2022-10-07T10:24:52.2479404 Recipes -045608027e4a5ea2d7dee7f402346b8e69f21675 data/advancedperipherals/advancements/recipes/advancedperipheralstab/armor/smart_glasses_netherite.json -f472724394edd655a415d4af08c9a63509cc5098 data/advancedperipherals/advancements/recipes/advancedperipheralstab/ar_controller.json -db2dada2fdf42ca1bbf47f1eb075d1f9de89dfa8 data/advancedperipherals/advancements/recipes/advancedperipheralstab/block_reader.json -77c55e8500be4a344ca563a8bf7642257cdc7b8b data/advancedperipherals/advancements/recipes/advancedperipheralstab/chat_box.json -96208b06b0c3c125762cd517506a5ffb6b1d55ac data/advancedperipherals/advancements/recipes/advancedperipheralstab/chunk_controller.json -eb1d84b0b82fd6671876d0885746f9e3e15803e3 data/advancedperipherals/advancements/recipes/advancedperipheralstab/computer_tool.json -5a1e92ee63dce1cb74c56b7e70587a0c54132de4 data/advancedperipherals/advancements/recipes/advancedperipheralstab/energy_detector.json -34d04b885af7947279752129f1f6e107cdf3cf05 data/advancedperipherals/advancements/recipes/advancedperipheralstab/environment_detector.json -91af310c4f272e800172a7f7e717fa29fc35dc62 data/advancedperipherals/advancements/recipes/advancedperipheralstab/geo_scanner.json -65184f82a2fe743edc4db31c0c362c74d1e4df84 data/advancedperipherals/advancements/recipes/advancedperipheralstab/inventory_manager.json -e575414582eb367f0689a3a90fc75aca2d6cd2fc data/advancedperipherals/advancements/recipes/advancedperipheralstab/memory_card.json -cb79be6d0ee7890abb2238b53edd55fd2338ed81 data/advancedperipherals/advancements/recipes/advancedperipheralstab/nbt_storage.json -e2d8bd0a887eb42d05f460d6fee007b7bb4c533c data/advancedperipherals/advancements/recipes/advancedperipheralstab/overpowered_end_automata_core.json -1db7ed04f8af5413308160b03f5b21d5932195f5 data/advancedperipherals/advancements/recipes/advancedperipheralstab/overpowered_husbandry_automata_core.json -d3d8709f4fdb3d68613d751bba5b9a94b8842046 data/advancedperipherals/advancements/recipes/advancedperipheralstab/overpowered_weak_automata_core.json -d27c1267208fd9036c5c45f7f6cbd4f6f67b3845 data/advancedperipherals/advancements/recipes/advancedperipheralstab/peripheral_casing.json -d8870644bb7d48c5ae33dcea2afbcfa106729d7b data/advancedperipherals/advancements/recipes/advancedperipheralstab/player_detector.json -7acff70533792bd089a655f8f24cdea6995aac0c data/advancedperipherals/advancements/recipes/advancedperipheralstab/redstone_integrator.json -c0373a4597bfbd9b005cbe0a6289779ffd4053ea data/advancedperipherals/advancements/recipes/advancedperipheralstab/smart_glasses.json -fc0c3d99bec43318802f357083c7d98fde92567f data/advancedperipherals/advancements/recipes/advancedperipheralstab/weak_automata_core.json +// 1.19.3 2022-12-20T12:49:29.6915309 Recipes +045608027e4a5ea2d7dee7f402346b8e69f21675 data/advancedperipherals/advancements/recipes/redstone/armor/smart_glasses_netherite.json +f472724394edd655a415d4af08c9a63509cc5098 data/advancedperipherals/advancements/recipes/redstone/ar_controller.json +db2dada2fdf42ca1bbf47f1eb075d1f9de89dfa8 data/advancedperipherals/advancements/recipes/redstone/block_reader.json +77c55e8500be4a344ca563a8bf7642257cdc7b8b data/advancedperipherals/advancements/recipes/redstone/chat_box.json +96208b06b0c3c125762cd517506a5ffb6b1d55ac data/advancedperipherals/advancements/recipes/redstone/chunk_controller.json +eb1d84b0b82fd6671876d0885746f9e3e15803e3 data/advancedperipherals/advancements/recipes/redstone/computer_tool.json +5a1e92ee63dce1cb74c56b7e70587a0c54132de4 data/advancedperipherals/advancements/recipes/redstone/energy_detector.json +34d04b885af7947279752129f1f6e107cdf3cf05 data/advancedperipherals/advancements/recipes/redstone/environment_detector.json +91af310c4f272e800172a7f7e717fa29fc35dc62 data/advancedperipherals/advancements/recipes/redstone/geo_scanner.json +65184f82a2fe743edc4db31c0c362c74d1e4df84 data/advancedperipherals/advancements/recipes/redstone/inventory_manager.json +e575414582eb367f0689a3a90fc75aca2d6cd2fc data/advancedperipherals/advancements/recipes/redstone/memory_card.json +cb79be6d0ee7890abb2238b53edd55fd2338ed81 data/advancedperipherals/advancements/recipes/redstone/nbt_storage.json +e2d8bd0a887eb42d05f460d6fee007b7bb4c533c data/advancedperipherals/advancements/recipes/redstone/overpowered_end_automata_core.json +1db7ed04f8af5413308160b03f5b21d5932195f5 data/advancedperipherals/advancements/recipes/redstone/overpowered_husbandry_automata_core.json +d3d8709f4fdb3d68613d751bba5b9a94b8842046 data/advancedperipherals/advancements/recipes/redstone/overpowered_weak_automata_core.json +d27c1267208fd9036c5c45f7f6cbd4f6f67b3845 data/advancedperipherals/advancements/recipes/redstone/peripheral_casing.json +d8870644bb7d48c5ae33dcea2afbcfa106729d7b data/advancedperipherals/advancements/recipes/redstone/player_detector.json +7acff70533792bd089a655f8f24cdea6995aac0c data/advancedperipherals/advancements/recipes/redstone/redstone_integrator.json +c0373a4597bfbd9b005cbe0a6289779ffd4053ea data/advancedperipherals/advancements/recipes/redstone/smart_glasses.json +fc0c3d99bec43318802f357083c7d98fde92567f data/advancedperipherals/advancements/recipes/redstone/weak_automata_core.json 66999fea36aa4113567753f104630f6490dda6ba data/advancedperipherals/recipes/armor/smart_glasses_netherite.json -6396232db4a526763d5b6625572677d7e8fc001e data/advancedperipherals/recipes/ar_controller.json -b10b5cbcc668438001744d5b90d9838ab4d293cb data/advancedperipherals/recipes/block_reader.json -3c9618832fe0ac32cac0f04fbc5afad225418239 data/advancedperipherals/recipes/chat_box.json -a78adfcca4c7579b143aac5648a7eca9085c0dba data/advancedperipherals/recipes/chunk_controller.json -d4c090dc64185fab9b123fffeda6966308b6c3d0 data/advancedperipherals/recipes/colony_integrator.json -f1f468c732f8c802c27776d3fd7aac432bcac8e3 data/advancedperipherals/recipes/computer_tool.json -4f0d0427d8c8774e350e7cfd1767a9e4802f4ca1 data/advancedperipherals/recipes/energy_detector.json -55c257e4e8548d1453a7ab96c547d64c22b3e1d6 data/advancedperipherals/recipes/environment_detector.json -2ddf64c122165bcd3a277db8a1c7e96b4d510c67 data/advancedperipherals/recipes/geo_scanner.json -ebe70aa9fe80c5b962c13aa1fbadc32269ba81b9 data/advancedperipherals/recipes/inventory_manager.json -809bc6929cf5eab72648e8f1fb565b58749fec12 data/advancedperipherals/recipes/memory_card.json -82895838af6c6aea0c60e3a3fbf71073ab684167 data/advancedperipherals/recipes/me_bridge.json -8a73c4eb66e7a1cdc8e51d33466cf5a30da9270e data/advancedperipherals/recipes/nbt_storage.json -360432f30d61291066aa8c54692629f7a92e178d data/advancedperipherals/recipes/overpowered_end_automata_core.json -4ea6e90d13a61d90ad245539d20020ff9cb843e1 data/advancedperipherals/recipes/overpowered_husbandry_automata_core.json -6c4b197e7579a8868668be231ba36487a0e3626d data/advancedperipherals/recipes/overpowered_weak_automata_core.json -a91556eb09a2a8c57b323928a76095a4b17241b7 data/advancedperipherals/recipes/peripheral_casing.json -1d476bfb11dcf490cefa9916695d91aec0cc8a19 data/advancedperipherals/recipes/player_detector.json -110983bae78f033dc8b12fd04ba3b7edcf035237 data/advancedperipherals/recipes/redstone_integrator.json -4ba2670271ef2b7c8be861f6277ae24c307dac5b data/advancedperipherals/recipes/rs_bridge.json -7008b3421135b3150e8c7e509166498a2b2df131 data/advancedperipherals/recipes/smart_glasses.json -7c783b341e783b22be4e40efbe3c88947e1902ec data/advancedperipherals/recipes/weak_automata_core.json +37c811b8a2537af60e96cc4fda950538b8bd041d data/advancedperipherals/recipes/ar_controller.json +f8acf88364459d1b38a9ac0fc3a2e87821f98edf data/advancedperipherals/recipes/block_reader.json +b1f3b9f50e62e2f53b23ad14248cb91acb745c37 data/advancedperipherals/recipes/chat_box.json +3c6f45e5977b200c900a71bad4b531d2b7e1164c data/advancedperipherals/recipes/chunk_controller.json +6d66e5c84b0cad46dfa654107499b45adfaa840c data/advancedperipherals/recipes/colony_integrator.json +a39d46363291e5d98a8b96e17bfcfd44fbe3789d data/advancedperipherals/recipes/computer_tool.json +66d1e3ed636629a9a5f7e1a8b0b7d222f0300e00 data/advancedperipherals/recipes/energy_detector.json +85920e576d404f5ad78ba228f9d6cb9aed3d4962 data/advancedperipherals/recipes/environment_detector.json +4bf49ae496c60e5487c1e87013ef25e14bb13e3a data/advancedperipherals/recipes/geo_scanner.json +2eb633f159ac1b9feaffab383548f56b573f1519 data/advancedperipherals/recipes/inventory_manager.json +dbefebf13084fce55660cffabb955f25901a30f9 data/advancedperipherals/recipes/memory_card.json +fddcb2d34c37f4fd5834e077efd27f2cb6127c73 data/advancedperipherals/recipes/nbt_storage.json +afb8673c5643adbbf69a469776ac4cd908ab17e8 data/advancedperipherals/recipes/overpowered_end_automata_core.json +7c98974c9e5999b0186011ff7f910ae2b3cc76b6 data/advancedperipherals/recipes/overpowered_husbandry_automata_core.json +40110dc9c8616e5c9b30b087cfc2f9254c433025 data/advancedperipherals/recipes/overpowered_weak_automata_core.json +346dd97a088087077c157c29cb1ac7b25b0a0cef data/advancedperipherals/recipes/peripheral_casing.json +cba141d36a134a03ae91869abb91c9695bd92898 data/advancedperipherals/recipes/player_detector.json +d5a72afad727dd9814f4c8ef6b177a0db0bc9989 data/advancedperipherals/recipes/redstone_integrator.json +a56e462fe4cee2298e4a71e1072b1d66c649604d data/advancedperipherals/recipes/smart_glasses.json +a5cd6136f9d7f6271820656343f41a6ebb9cb9f0 data/advancedperipherals/recipes/weak_automata_core.json diff --git a/src/generated/resources/.cache/ae219fa7c7d3297c14e454863eac3998a4eab78c b/src/generated/resources/.cache/ae219fa7c7d3297c14e454863eac3998a4eab78c index be8f6a054..43df559c6 100644 --- a/src/generated/resources/.cache/ae219fa7c7d3297c14e454863eac3998a4eab78c +++ b/src/generated/resources/.cache/ae219fa7c7d3297c14e454863eac3998a4eab78c @@ -1,4 +1,4 @@ -// 1.19.2 2022-09-18T21:59:59.2641513 Pocket Computer Upgrades +// 1.19.3 2022-12-20T12:47:00.0789795 Pocket Computer Upgrades b672635324c0df354e587efc81d0b19a581eae2f data/advancedperipherals/computercraft/pocket_upgrades/chatty_pocket.json 30b8f663613c7ce77048fd69631afcc11a682276 data/advancedperipherals/computercraft/pocket_upgrades/colony_pocket.json d4647159c2f2693a9c5e8d12bf740635751d29a8 data/advancedperipherals/computercraft/pocket_upgrades/environment_pocket.json diff --git a/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 b/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 index bed03da69..4fa0dd6ee 100644 --- a/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 +++ b/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 @@ -1,2 +1,2 @@ -// 1.19.2 2022-10-07T10:24:52.2614728 Languages: en_us -c2fe721c9d493494ac03242345af883cea5f2d07 assets/advancedperipherals/lang/en_us.json +// 1.19.3 2022-12-20T12:47:00.0839886 Languages: en_us +8b2d44fddffb8378ff40c628111474972b7971fd assets/advancedperipherals/lang/en_us.json diff --git a/src/generated/resources/.cache/f95c7003282837dabaa33e3ffceec4e6865b5218 b/src/generated/resources/.cache/f95c7003282837dabaa33e3ffceec4e6865b5218 index 7d6ca6f74..b0f23c9e9 100644 --- a/src/generated/resources/.cache/f95c7003282837dabaa33e3ffceec4e6865b5218 +++ b/src/generated/resources/.cache/f95c7003282837dabaa33e3ffceec4e6865b5218 @@ -1,4 +1,4 @@ -// 1.19.2 2022-10-07T10:24:52.2564506 Block tags +// 1.19.3 2022-12-20T12:47:00.0649699 Block tags e1f71dcb4f9e7e36e29b0ad09d6520dc3adfa4a6 data/forge/tags/blocks/needs_wood_tool.json -a2af89cb645c94eccda0bca93ec0255f23602444 data/minecraft/tags/blocks/mineable/pickaxe.json -b67fec361e71d5073cbcdfaf8a5f8dbdf1c56971 data/minecraft/tags/blocks/needs_iron_tool.json +f397bc09e95d0258b5ba711d5e1fb0b7da8419db data/minecraft/tags/blocks/mineable/pickaxe.json +055dd6291658fb34ab62ebf6e7223e11eb1aa052 data/minecraft/tags/blocks/needs_iron_tool.json diff --git a/src/generated/resources/assets/advancedperipherals/lang/en_us.json b/src/generated/resources/assets/advancedperipherals/lang/en_us.json index 51e266d28..771fe7b33 100644 --- a/src/generated/resources/assets/advancedperipherals/lang/en_us.json +++ b/src/generated/resources/assets/advancedperipherals/lang/en_us.json @@ -1,4 +1,5 @@ { + "advancedperipherals.name": "Advanced Peripherals", "advancements.advancedperipherals.base_toolkit": "Gentleman's set!", "advancements.advancedperipherals.base_toolkit.description": "Collect a redstone integrator, inventory manager and energy detector. How did you even play without this?", "advancements.advancedperipherals.end_automata_core": "End automata core", @@ -42,7 +43,7 @@ "item.advancedperipherals.tooltip.chat_box": "&7Interacts with the ingame chat, can read and write messages.", "item.advancedperipherals.tooltip.chunk_controller": "&7A crafting ingredient for the Chunky Turtle.", "item.advancedperipherals.tooltip.colony_integrator": "&7Interacts with Minecolonies to read data about your colony and citizens.", - "item.advancedperipherals.tooltip.computer_tool": "&7This tool was made to tune our APBlocks. But for now, it's just a blue useless wrench.", + "item.advancedperipherals.tooltip.computer_tool": "&7This tool was made to tune our blocks. But for now, it's just a blue useless wrench.", "item.advancedperipherals.tooltip.disabled": "&cThis item is disabled in config, so you can craft it, but it'll not have any functionality.", "item.advancedperipherals.tooltip.end_automata_core": "&7Upgrade for turtles, that allows basic interaction with the world and teleportation in one dimension.", "item.advancedperipherals.tooltip.energy_detector": "&7Can detect energy flow and acts as a resistor.", @@ -64,7 +65,6 @@ "item.advancedperipherals.tooltip.show_desc": "&b[&7%s&b] &7For Description", "item.advancedperipherals.tooltip.weak_automata_core": "&7Upgrade for turtles, which makes turtles more useful.", "item.advancedperipherals.weak_automata_core": "Weak Automata Core", - "itemGroup.advancedperipheralstab": "Advanced Peripherals", "keybind.advancedperipherals.category": "Advanced Peripherals", "keybind.advancedperipherals.description": "Show Description", "pocket.advancedperipherals.chatty_pocket": "Chatty", diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/ar_controller.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/ar_controller.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/ar_controller.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/ar_controller.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/armor/smart_glasses_netherite.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/armor/smart_glasses_netherite.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/armor/smart_glasses_netherite.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/armor/smart_glasses_netherite.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/block_reader.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/block_reader.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/block_reader.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/block_reader.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/chat_box.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/chat_box.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/chat_box.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/chat_box.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/chunk_controller.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/chunk_controller.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/chunk_controller.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/chunk_controller.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/computer_tool.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/computer_tool.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/computer_tool.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/computer_tool.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/energy_detector.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/energy_detector.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/energy_detector.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/energy_detector.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/environment_detector.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/environment_detector.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/environment_detector.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/environment_detector.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/geo_scanner.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/geo_scanner.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/geo_scanner.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/geo_scanner.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/inventory_manager.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/inventory_manager.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/inventory_manager.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/inventory_manager.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/memory_card.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/memory_card.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/memory_card.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/memory_card.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/nbt_storage.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/nbt_storage.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/nbt_storage.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/nbt_storage.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/overpowered_end_automata_core.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/overpowered_end_automata_core.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/overpowered_end_automata_core.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/overpowered_end_automata_core.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/overpowered_husbandry_automata_core.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/overpowered_husbandry_automata_core.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/overpowered_husbandry_automata_core.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/overpowered_husbandry_automata_core.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/overpowered_weak_automata_core.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/overpowered_weak_automata_core.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/overpowered_weak_automata_core.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/overpowered_weak_automata_core.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/peripheral_casing.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/peripheral_casing.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/peripheral_casing.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/peripheral_casing.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/player_detector.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/player_detector.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/player_detector.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/player_detector.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/redstone_integrator.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/redstone_integrator.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/redstone_integrator.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/redstone_integrator.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/smart_glasses.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/smart_glasses.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/smart_glasses.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/smart_glasses.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/weak_automata_core.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/weak_automata_core.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/weak_automata_core.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/weak_automata_core.json diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/distance_detector.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/distance_detector.json new file mode 100644 index 000000000..21855bf71 --- /dev/null +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/distance_detector.json @@ -0,0 +1,20 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "advancedperipherals:distance_detector" + } + ], + "rolls": 1.0 + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/advancedperipherals/recipes/block_reader.json b/src/generated/resources/data/advancedperipherals/recipes/block_reader.json index e6850a3ba..e93bf3731 100644 --- a/src/generated/resources/data/advancedperipherals/recipes/block_reader.json +++ b/src/generated/resources/data/advancedperipherals/recipes/block_reader.json @@ -1,5 +1,6 @@ { "type": "minecraft:crafting_shaped", + "category": "redstone", "key": { "A": { "item": "advancedperipherals:peripheral_casing" diff --git a/src/generated/resources/data/advancedperipherals/recipes/colony_integrator.json b/src/generated/resources/data/advancedperipherals/recipes/colony_integrator.json index ee200a21d..9839197d1 100644 --- a/src/generated/resources/data/advancedperipherals/recipes/colony_integrator.json +++ b/src/generated/resources/data/advancedperipherals/recipes/colony_integrator.json @@ -10,6 +10,7 @@ ], "recipe": { "type": "minecraft:crafting_shaped", + "category": "redstone", "key": { "A": { "item": "advancedperipherals:peripheral_casing" diff --git a/src/generated/resources/data/advancedperipherals/recipes/geo_scanner.json b/src/generated/resources/data/advancedperipherals/recipes/geo_scanner.json index 5da17ecef..250c20e3d 100644 --- a/src/generated/resources/data/advancedperipherals/recipes/geo_scanner.json +++ b/src/generated/resources/data/advancedperipherals/recipes/geo_scanner.json @@ -1,5 +1,6 @@ { "type": "minecraft:crafting_shaped", + "category": "redstone", "key": { "C": { "item": "advancedperipherals:peripheral_casing" diff --git a/src/generated/resources/data/advancedperipherals/recipes/inventory_manager.json b/src/generated/resources/data/advancedperipherals/recipes/inventory_manager.json index 04233359b..e6f605ca9 100644 --- a/src/generated/resources/data/advancedperipherals/recipes/inventory_manager.json +++ b/src/generated/resources/data/advancedperipherals/recipes/inventory_manager.json @@ -1,5 +1,6 @@ { "type": "minecraft:crafting_shaped", + "category": "redstone", "key": { "A": { "item": "advancedperipherals:peripheral_casing" diff --git a/src/generated/resources/data/advancedperipherals/recipes/me_bridge.json b/src/generated/resources/data/advancedperipherals/recipes/me_bridge.json deleted file mode 100644 index 0e0946063..000000000 --- a/src/generated/resources/data/advancedperipherals/recipes/me_bridge.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "type": "forge:conditional", - "recipes": [ - { - "conditions": [ - { - "type": "forge:mod_loaded", - "modid": "ae2" - } - ], - "recipe": { - "type": "minecraft:crafting_shaped", - "key": { - "A": { - "item": "advancedperipherals:peripheral_casing" - }, - "F": { - "item": "ae2:fluix_block" - }, - "I": { - "item": "ae2:interface" - } - }, - "pattern": [ - "FIF", - "IAI", - "FIF" - ], - "result": { - "item": "advancedperipherals:me_bridge" - } - } - } - ] -} \ No newline at end of file diff --git a/src/generated/resources/data/advancedperipherals/recipes/memory_card.json b/src/generated/resources/data/advancedperipherals/recipes/memory_card.json index e00c50b0b..65cae3b62 100644 --- a/src/generated/resources/data/advancedperipherals/recipes/memory_card.json +++ b/src/generated/resources/data/advancedperipherals/recipes/memory_card.json @@ -1,5 +1,6 @@ { "type": "minecraft:crafting_shaped", + "category": "redstone", "key": { "G": { "tag": "forge:ingots/gold" diff --git a/src/generated/resources/data/advancedperipherals/recipes/nbt_storage.json b/src/generated/resources/data/advancedperipherals/recipes/nbt_storage.json index b0d80dac8..b933398b0 100644 --- a/src/generated/resources/data/advancedperipherals/recipes/nbt_storage.json +++ b/src/generated/resources/data/advancedperipherals/recipes/nbt_storage.json @@ -1,5 +1,6 @@ { "type": "minecraft:crafting_shaped", + "category": "redstone", "key": { "A": { "item": "advancedperipherals:peripheral_casing" diff --git a/src/generated/resources/data/advancedperipherals/recipes/overpowered_end_automata_core.json b/src/generated/resources/data/advancedperipherals/recipes/overpowered_end_automata_core.json index 631a1790c..2bcbba59c 100644 --- a/src/generated/resources/data/advancedperipherals/recipes/overpowered_end_automata_core.json +++ b/src/generated/resources/data/advancedperipherals/recipes/overpowered_end_automata_core.json @@ -1,5 +1,6 @@ { "type": "minecraft:crafting_shapeless", + "category": "redstone", "ingredients": [ { "item": "advancedperipherals:end_automata_core" diff --git a/src/generated/resources/data/advancedperipherals/recipes/overpowered_husbandry_automata_core.json b/src/generated/resources/data/advancedperipherals/recipes/overpowered_husbandry_automata_core.json index 6df0def3f..21d781502 100644 --- a/src/generated/resources/data/advancedperipherals/recipes/overpowered_husbandry_automata_core.json +++ b/src/generated/resources/data/advancedperipherals/recipes/overpowered_husbandry_automata_core.json @@ -1,5 +1,6 @@ { "type": "minecraft:crafting_shapeless", + "category": "redstone", "ingredients": [ { "item": "advancedperipherals:husbandry_automata_core" diff --git a/src/generated/resources/data/advancedperipherals/recipes/overpowered_weak_automata_core.json b/src/generated/resources/data/advancedperipherals/recipes/overpowered_weak_automata_core.json index 28b3f0528..07bccaddd 100644 --- a/src/generated/resources/data/advancedperipherals/recipes/overpowered_weak_automata_core.json +++ b/src/generated/resources/data/advancedperipherals/recipes/overpowered_weak_automata_core.json @@ -1,5 +1,6 @@ { "type": "minecraft:crafting_shapeless", + "category": "redstone", "ingredients": [ { "item": "advancedperipherals:weak_automata_core" diff --git a/src/generated/resources/data/advancedperipherals/recipes/peripheral_casing.json b/src/generated/resources/data/advancedperipherals/recipes/peripheral_casing.json index 2c9616751..b2c43ded1 100644 --- a/src/generated/resources/data/advancedperipherals/recipes/peripheral_casing.json +++ b/src/generated/resources/data/advancedperipherals/recipes/peripheral_casing.json @@ -1,5 +1,6 @@ { "type": "minecraft:crafting_shaped", + "category": "redstone", "key": { "I": { "tag": "forge:ingots/iron" diff --git a/src/generated/resources/data/advancedperipherals/recipes/player_detector.json b/src/generated/resources/data/advancedperipherals/recipes/player_detector.json index faeccd09a..6473313fc 100644 --- a/src/generated/resources/data/advancedperipherals/recipes/player_detector.json +++ b/src/generated/resources/data/advancedperipherals/recipes/player_detector.json @@ -1,5 +1,6 @@ { "type": "minecraft:crafting_shaped", + "category": "redstone", "key": { "A": { "item": "advancedperipherals:peripheral_casing" diff --git a/src/generated/resources/data/advancedperipherals/recipes/redstone_integrator.json b/src/generated/resources/data/advancedperipherals/recipes/redstone_integrator.json index c6e837d02..2608082bd 100644 --- a/src/generated/resources/data/advancedperipherals/recipes/redstone_integrator.json +++ b/src/generated/resources/data/advancedperipherals/recipes/redstone_integrator.json @@ -1,5 +1,6 @@ { "type": "minecraft:crafting_shaped", + "category": "redstone", "key": { "A": { "item": "advancedperipherals:peripheral_casing" diff --git a/src/generated/resources/data/advancedperipherals/recipes/rs_bridge.json b/src/generated/resources/data/advancedperipherals/recipes/rs_bridge.json deleted file mode 100644 index f8c233104..000000000 --- a/src/generated/resources/data/advancedperipherals/recipes/rs_bridge.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "type": "forge:conditional", - "recipes": [ - { - "conditions": [ - { - "type": "forge:mod_loaded", - "modid": "refinedstorage" - } - ], - "recipe": { - "type": "minecraft:crafting_shaped", - "key": { - "A": { - "item": "advancedperipherals:peripheral_casing" - }, - "I": { - "item": "refinedstorage:interface" - }, - "Q": { - "item": "refinedstorage:quartz_enriched_iron" - } - }, - "pattern": [ - "QIQ", - "IAI", - "QIQ" - ], - "result": { - "item": "advancedperipherals:rs_bridge" - } - } - } - ] -} \ No newline at end of file diff --git a/src/generated/resources/data/advancedperipherals/recipes/weak_automata_core.json b/src/generated/resources/data/advancedperipherals/recipes/weak_automata_core.json index 51851c0cb..d3c0fc266 100644 --- a/src/generated/resources/data/advancedperipherals/recipes/weak_automata_core.json +++ b/src/generated/resources/data/advancedperipherals/recipes/weak_automata_core.json @@ -1,5 +1,6 @@ { "type": "minecraft:crafting_shaped", + "category": "redstone", "key": { "A": { "item": "advancedperipherals:peripheral_casing" diff --git a/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json b/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json index b0331ffb1..66d6c5726 100644 --- a/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json +++ b/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json @@ -15,6 +15,7 @@ "advancedperipherals:block_reader", "advancedperipherals:geo_scanner", "advancedperipherals:colony_integrator", - "advancedperipherals:nbt_storage" + "advancedperipherals:nbt_storage", + "advancedperipherals:distance_detector" ] } \ No newline at end of file diff --git a/src/generated/resources/data/minecraft/tags/blocks/needs_iron_tool.json b/src/generated/resources/data/minecraft/tags/blocks/needs_iron_tool.json index 31ba7d77c..2952ba4f1 100644 --- a/src/generated/resources/data/minecraft/tags/blocks/needs_iron_tool.json +++ b/src/generated/resources/data/minecraft/tags/blocks/needs_iron_tool.json @@ -14,6 +14,7 @@ "advancedperipherals:block_reader", "advancedperipherals:geo_scanner", "advancedperipherals:colony_integrator", - "advancedperipherals:nbt_storage" + "advancedperipherals:nbt_storage", + "advancedperipherals:distance_detector" ] } \ No newline at end of file diff --git a/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java b/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java index 96b470525..b5e5f0c17 100644 --- a/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java +++ b/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java @@ -1,7 +1,7 @@ package de.srendi.advancedperipherals; -import de.srendi.advancedperipherals.common.setup.Blocks; -import de.srendi.advancedperipherals.common.setup.Registration; +import de.srendi.advancedperipherals.common.setup.APBlocks; +import de.srendi.advancedperipherals.common.setup.APRegistration; import net.minecraft.network.chat.Component; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.ItemStack; @@ -20,9 +20,9 @@ public static void registerCreativeTab(CreativeModeTabEvent.Register event) { private static void populateCreativeTabBuilder(CreativeModeTab.Builder builder) { builder.displayItems((set, out, unknownMagicBoolean) -> { - Registration.ITEMS.getEntries().stream().map(RegistryObject::get).forEach(out::accept); + APRegistration.ITEMS.getEntries().stream().map(RegistryObject::get).forEach(out::accept); }); - builder.icon(() -> new ItemStack(Blocks.CHAT_BOX.get())); + builder.icon(() -> new ItemStack(APBlocks.CHAT_BOX.get())); builder.title(Component.translatable("advancedperipherals.name")); builder.withSearchBar(); } diff --git a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java index 0956305d4..2557a67ed 100644 --- a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java +++ b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java @@ -1,17 +1,15 @@ package de.srendi.advancedperipherals; -import de.srendi.advancedperipherals.client.HudOverlayHandler; import de.srendi.advancedperipherals.common.addons.APAddons; import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.setup.Registration; +import de.srendi.advancedperipherals.common.network.PacketHandler; +import de.srendi.advancedperipherals.common.setup.APRegistration; import de.srendi.advancedperipherals.common.village.VillageStructures; -import de.srendi.advancedperipherals.network.MNetwork; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import org.apache.logging.log4j.Level; @@ -26,7 +24,7 @@ public class AdvancedPeripherals { public static final String MOD_ID = "advancedperipherals"; public static final Logger LOGGER = LogManager.getLogger("Advanced Peripherals"); public static final Random RANDOM = new Random(); - public static final APAddons addons = new APAddons(); + public static final APAddons ADDONS = new APAddons(); public AdvancedPeripherals() { LOGGER.info("AdvancedPeripherals says hello!"); @@ -35,8 +33,7 @@ public AdvancedPeripherals() { APConfig.register(ModLoadingContext.get()); modBus.addListener(this::commonSetup); - modBus.addListener(this::clientSetup); - modBus.addListener(addons::interModComms); + modBus.addListener(ADDONS::interModComms); APRegistration.register(); MinecraftForge.EVENT_BUS.register(this); } @@ -56,19 +53,11 @@ public static ResourceLocation getRL(String resource) { } public void commonSetup(FMLCommonSetupEvent event) { - addons.commonSetup(); + ADDONS.commonSetup(); event.enqueueWork(() -> { VillageStructures.init(); PacketHandler.init(); }); } - @SubscribeEvent - public void interModComms(InterModEnqueueEvent event) { - if (!curiosLoaded) return; - //InterModComms.sendTo("curios", SlotTypeMessage.REGISTER_TYPE, () -> new SlotTypeMessage.Builder("glasses") - //.size(1).icon(new ResourceLocation(MOD_ID, "textures/item/empty_glasses_slot.png")).build()); - InterModComms.sendTo("curios", SlotTypeMessage.REGISTER_TYPE, () -> new SlotTypeMessage.Builder("glasses").size(1).build()); - } - } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java b/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java index 8d0ab442d..fb74d1652 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java @@ -10,18 +10,24 @@ public class APAddons { public static final String CURIOS_MODID = "curios"; public static final String REFINEDSTORAGE_MODID = "refinedstorage"; + public static final String APPLIEDENERGISTICS_MODID = "ae2"; + public static final String MEKANISM_MODID = "mekanism"; public boolean curiosLoaded; public boolean refinedStorageLoaded; + public boolean appliedEnergisticsLoaded; + public boolean mekanismLoaded; public void commonSetup() { ModList modList = ModList.get(); curiosLoaded = modList.isLoaded(CURIOS_MODID); refinedStorageLoaded = modList.isLoaded(REFINEDSTORAGE_MODID); + appliedEnergisticsLoaded = modList.isLoaded(APPLIEDENERGISTICS_MODID); + mekanismLoaded = modList.isLoaded(MEKANISM_MODID); - if (refinedStorageLoaded) { + if (refinedStorageLoaded) RefinedStorage.instance = new RefinedStorage(); - } + } public void interModComms(InterModEnqueueEvent event) { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ARControllerPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ARControllerPeripheral.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java index 922f02b1a..ebe8aae35 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java @@ -50,10 +50,8 @@ public final boolean getEntityDetection() { } public final double setHeight(double height) { - if(height > 1) - this.height = 1; - if(height < 0) - this.height = 0; + if (height > 1) this.height = 1; + if (height < 0) this.height = 0; return this.height; } @@ -69,7 +67,7 @@ public final double getDistance() { Vec3 to = from.add(direction.getNormal().getX() * 16, direction.getNormal().getY() * 16, direction.getNormal().getZ() * 16); BlockHitResult result = getLevel().clip(new ClipContext(from, to, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, null)); - return result.getType() != HitResult.Type.MISS ? getPos().distManhattan(result.getBlockPos())-1 : -1; + return result.getType() != HitResult.Type.MISS ? getPos().distManhattan(result.getBlockPos()) - 1 : -1; } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/EnvironmentRadiationPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/EnvironmentRadiationPlugin.java index 74ddffcda..9bb14e274 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/EnvironmentRadiationPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/EnvironmentRadiationPlugin.java @@ -3,8 +3,6 @@ import dan200.computercraft.api.lua.LuaFunction; import de.srendi.advancedperipherals.common.addons.computercraft.owner.IPeripheralOwner; import de.srendi.advancedperipherals.lib.peripherals.IPeripheralPlugin; -import mekanism.api.Coord4D; -import mekanism.api.MekanismAPI; public class EnvironmentRadiationPlugin implements IPeripheralPlugin { private final IPeripheralOwner owner; diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java b/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java index 2d825a312..888aecaf8 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java @@ -1,6 +1,6 @@ package de.srendi.advancedperipherals.common.data; -import de.srendi.advancedperipherals.common.setup.Registration; +import de.srendi.advancedperipherals.common.setup.APRegistration; import net.minecraft.data.loot.BlockLootSubProvider; import net.minecraft.world.flag.FeatureFlags; import net.minecraft.world.level.block.Block; @@ -17,12 +17,12 @@ protected BlockLootTables() { @Override protected void generate() { - Registration.BLOCKS.getEntries().stream().map(RegistryObject::get).forEach(this::dropSelf); + APRegistration.BLOCKS.getEntries().stream().map(RegistryObject::get).forEach(this::dropSelf); } @NotNull @Override protected Iterable getKnownBlocks() { - return Registration.BLOCKS.getEntries().stream().map(RegistryObject::get)::iterator; + return APRegistration.BLOCKS.getEntries().stream().map(RegistryObject::get)::iterator; } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTablesProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTablesProvider.java index a5f1c67db..6e58534c6 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTablesProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTablesProvider.java @@ -7,6 +7,7 @@ import net.minecraft.world.level.storage.loot.LootTable; import net.minecraft.world.level.storage.loot.LootTables; import net.minecraft.world.level.storage.loot.ValidationContext; +import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -16,12 +17,12 @@ public class BlockLootTablesProvider extends LootTableProvider { public BlockLootTablesProvider(PackOutput output) { - super(output, Set.of(), ImmutableList.of(new SubProviderEntry(BlockLootTables::new, null))); + super(output, Set.of(), ImmutableList.of(new SubProviderEntry(BlockLootTables::new, LootContextParamSets.BLOCK))); } @Override public @NotNull List getTables() { - return ImmutableList.of(new SubProviderEntry(BlockLootTables::new, null)); + return ImmutableList.of(new SubProviderEntry(BlockLootTables::new, LootContextParamSets.BLOCK)); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/DataGenerators.java b/src/main/java/de/srendi/advancedperipherals/common/data/DataGenerators.java index a20e67e7d..23a3ed7f0 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/DataGenerators.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/DataGenerators.java @@ -1,13 +1,18 @@ package de.srendi.advancedperipherals.common.data; import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.common.setup.Registration; +import de.srendi.advancedperipherals.common.setup.APRegistration; +import net.minecraft.Util; +import net.minecraft.core.HolderLookup; import net.minecraft.data.DataGenerator; +import net.minecraft.data.registries.VanillaRegistries; import net.minecraftforge.common.data.ExistingFileHelper; import net.minecraftforge.data.event.GatherDataEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; +import java.util.concurrent.CompletableFuture; + @Mod.EventBusSubscriber(modid = AdvancedPeripherals.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) public class DataGenerators { @@ -19,14 +24,15 @@ public static void genData(GatherDataEvent event) { DataGenerator generator = event.getGenerator(); ExistingFileHelper existingFileHelper = event.getExistingFileHelper(); - generator.addProvider(event.includeServer(), new BlockTagsProvider(generator.getPackOutput(), null, existingFileHelper, Registration.BLOCKS)); + CompletableFuture completablefuture = CompletableFuture.supplyAsync(VanillaRegistries::createLookup, Util.backgroundExecutor()); + generator.addProvider(event.includeServer(), new BlockTagsProvider(generator.getPackOutput(), completablefuture, existingFileHelper, APRegistration.BLOCKS)); generator.addProvider(event.includeServer(), new RecipesProvider(generator.getPackOutput())); generator.addProvider(event.includeServer(), new BlockLootTablesProvider(generator.getPackOutput())); generator.addProvider(event.includeServer(), new TurtleUpgradesProvider(generator.getPackOutput())); generator.addProvider(event.includeServer(), new PocketUpgradesProvider(generator.getPackOutput())); - generator.addProvider(event.includeServer(), new PoiTypeProvider(generator.getPackOutput(), null, existingFileHelper)); + generator.addProvider(event.includeServer(), new PoiTypeProvider(generator.getPackOutput(), completablefuture, existingFileHelper)); - generator.addProvider(event.includeClient(), new EnUsLanguageProvider(generator)); + generator.addProvider(event.includeClient(), new EnUsLanguageProvider(generator.getPackOutput())); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java index 761b9b7bd..32c6cacbd 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java @@ -2,12 +2,12 @@ import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.client.KeyBindings; -import de.srendi.advancedperipherals.common.setup.Blocks; +import de.srendi.advancedperipherals.common.setup.APBlocks; +import de.srendi.advancedperipherals.common.setup.APItems; +import de.srendi.advancedperipherals.common.setup.APVillagers; import de.srendi.advancedperipherals.common.setup.CCRegistration; -import de.srendi.advancedperipherals.common.setup.Items; -import de.srendi.advancedperipherals.common.setup.Villagers; import net.minecraft.client.KeyMapping; -import net.minecraft.data.DataGenerator; +import net.minecraft.data.PackOutput; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.npc.VillagerProfession; import net.minecraft.world.item.Item; @@ -20,7 +20,7 @@ public class EnUsLanguageProvider extends LanguageProvider { - public EnUsLanguageProvider(DataGenerator gen) { + public EnUsLanguageProvider(PackOutput gen) { super(gen, AdvancedPeripherals.MOD_ID, "en_us"); } @@ -34,37 +34,37 @@ protected void addTranslations() { addTooltips(); addKeybinds(); addText(); - add(Villagers.COMPUTER_SCIENTIST, "Computer Scientist"); + add(APVillagers.COMPUTER_SCIENTIST, "Computer Scientist"); add("advancedperipherals.name", "Advanced Peripherals"); } private void addItems() { - addItem(Items.CHUNK_CONTROLLER, "Chunk Controller"); - addItem(Items.COMPUTER_TOOL, "Computer Tool"); - addItem(Items.WEAK_AUTOMATA_CORE, "Weak Automata Core"); - addItem(Items.HUSBANDRY_AUTOMATA_CORE, "Husbandry Automata Core"); - addItem(Items.END_AUTOMATA_CORE, "End Automata Core"); - addItem(Items.OVERPOWERED_WEAK_AUTOMATA_CORE, "Overpowered Weak Automata Core"); - addItem(Items.OVERPOWERED_HUSBANDRY_AUTOMATA_CORE, "Overpowered Husbandry Automata Core"); - addItem(Items.OVERPOWERED_END_AUTOMATA_CORE, "Overpowered End Automata Core"); - addItem(Items.MEMORY_CARD, "Memory Card"); + addItem(APItems.CHUNK_CONTROLLER, "Chunk Controller"); + addItem(APItems.COMPUTER_TOOL, "Computer Tool"); + addItem(APItems.WEAK_AUTOMATA_CORE, "Weak Automata Core"); + addItem(APItems.HUSBANDRY_AUTOMATA_CORE, "Husbandry Automata Core"); + addItem(APItems.END_AUTOMATA_CORE, "End Automata Core"); + addItem(APItems.OVERPOWERED_WEAK_AUTOMATA_CORE, "Overpowered Weak Automata Core"); + addItem(APItems.OVERPOWERED_HUSBANDRY_AUTOMATA_CORE, "Overpowered Husbandry Automata Core"); + addItem(APItems.OVERPOWERED_END_AUTOMATA_CORE, "Overpowered End Automata Core"); + addItem(APItems.MEMORY_CARD, "Memory Card"); } private void addBlocks() { - addBlock(Blocks.BLOCK_READER, "Block Reader"); - addBlock(Blocks.CHAT_BOX, "Chat Box"); - addBlock(Blocks.AR_CONTROLLER, "Ar Controller"); - addBlock(Blocks.COLONY_INTEGRATOR, "Colony Integrator"); - addBlock(Blocks.ENERGY_DETECTOR, "Energy Detector"); - addBlock(Blocks.ENVIRONMENT_DETECTOR, "Environment Detector"); - addBlock(Blocks.GEO_SCANNER, "Geo Scanner"); - addBlock(Blocks.INVENTORY_MANAGER, "Inventory Manager"); - addBlock(Blocks.ME_BRIDGE, "ME Bridge"); - addBlock(Blocks.RS_BRIDGE, "RS Bridge"); - addBlock(Blocks.NBT_STORAGE, "NBT Storage"); - addBlock(Blocks.PERIPHERAL_CASING, "Peripheral Casing"); - addBlock(Blocks.PLAYER_DETECTOR, "Player Detector"); - addBlock(Blocks.REDSTONE_INTEGRATOR, "Redstone Integrator"); + addBlock(APBlocks.BLOCK_READER, "Block Reader"); + addBlock(APBlocks.CHAT_BOX, "Chat Box"); + addBlock(APBlocks.AR_CONTROLLER, "Ar Controller"); + addBlock(APBlocks.COLONY_INTEGRATOR, "Colony Integrator"); + addBlock(APBlocks.ENERGY_DETECTOR, "Energy Detector"); + addBlock(APBlocks.ENVIRONMENT_DETECTOR, "Environment Detector"); + addBlock(APBlocks.GEO_SCANNER, "Geo Scanner"); + addBlock(APBlocks.INVENTORY_MANAGER, "Inventory Manager"); + addBlock(APBlocks.ME_BRIDGE, "ME Bridge"); + addBlock(APBlocks.RS_BRIDGE, "RS Bridge"); + addBlock(APBlocks.NBT_STORAGE, "NBT Storage"); + addBlock(APBlocks.PERIPHERAL_CASING, "Peripheral Casing"); + addBlock(APBlocks.PLAYER_DETECTOR, "Player Detector"); + addBlock(APBlocks.REDSTONE_INTEGRATOR, "Redstone Integrator"); } private void addTurtles() { @@ -105,29 +105,29 @@ private void addAdvancements() { private void addTooltips() { addTooltip("show_desc", "&b[&7%s&b] &7For Description"); addTooltip("disabled", "&cThis item is disabled in config, so you can craft it, but it'll not have any functionality."); - addTooltip(Items.COMPUTER_TOOL.get(), "&7This tool was made to tune our blocks. But for now, it's just a blue useless wrench."); - addTooltip(Blocks.ENERGY_DETECTOR.get(), "&7Can detect energy flow and acts as a resistor."); - addTooltip(Items.CHUNK_CONTROLLER.get(), "&7A crafting ingredient for the Chunky Turtle."); - addTooltip(Blocks.ENVIRONMENT_DETECTOR.get(), "&7This peripheral interacts with the minecraft world."); - addTooltip(Blocks.PLAYER_DETECTOR.get(), "&7This peripheral can be used to interact with players, but don't be a stalker."); - addTooltip(Blocks.RS_BRIDGE.get(), "&7This wonderful block interacts with Refined Storage to read and craft items."); - addTooltip(Blocks.ME_BRIDGE.get(), "&7This peripheral interacts with Applied Energistics 2 to read and craft items."); - addTooltip(Blocks.CHAT_BOX.get(), "&7Interacts with the ingame chat, can read and write messages."); - addTooltip(Blocks.PERIPHERAL_CASING.get(), "&7An empty hull without the love it deserves. Used as crafting ingredient"); - addTooltip(Items.MEMORY_CARD.get(), "&7Can save the rights of a player to use it in an inventory manager."); + addTooltip(APItems.COMPUTER_TOOL.get(), "&7This tool was made to tune our blocks. But for now, it's just a blue useless wrench."); + addTooltip(APBlocks.ENERGY_DETECTOR.get(), "&7Can detect energy flow and acts as a resistor."); + addTooltip(APItems.CHUNK_CONTROLLER.get(), "&7A crafting ingredient for the Chunky Turtle."); + addTooltip(APBlocks.ENVIRONMENT_DETECTOR.get(), "&7This peripheral interacts with the minecraft world."); + addTooltip(APBlocks.PLAYER_DETECTOR.get(), "&7This peripheral can be used to interact with players, but don't be a stalker."); + addTooltip(APBlocks.RS_BRIDGE.get(), "&7This wonderful block interacts with Refined Storage to read and craft APItems."); + addTooltip(APBlocks.ME_BRIDGE.get(), "&7This peripheral interacts with Applied Energistics 2 to read and craft APItems."); + addTooltip(APBlocks.CHAT_BOX.get(), "&7Interacts with the ingame chat, can read and write messages."); + addTooltip(APBlocks.PERIPHERAL_CASING.get(), "&7An empty hull without the love it deserves. Used as crafting ingredient"); + addTooltip(APItems.MEMORY_CARD.get(), "&7Can save the rights of a player to use it in an inventory manager."); addTooltip("memory_card.bound", "&7Bound to &b%s&7."); - addTooltip(Blocks.INVENTORY_MANAGER.get(), "&7This block is able to send or receive specific items from a player inventory."); - addTooltip(Blocks.REDSTONE_INTEGRATOR.get(), "&7This block is able to interact with redstone. Works exactly like the redstone api of an computer."); - addTooltip(Blocks.BLOCK_READER.get(), "&7Reads nbt data of blocks to interact with blocks which do not have computer support."); - addTooltip(Blocks.GEO_SCANNER.get(), "&7Scans the area around it to find some shiny ores."); - addTooltip(Blocks.COLONY_INTEGRATOR.get(), "&7Interacts with Minecolonies to read data about your colony and citizens."); - addTooltip(Blocks.NBT_STORAGE.get(), "&7Acts like a storage disk. Can store nbt based data like."); - addTooltip(Items.WEAK_AUTOMATA_CORE.get(), "&7Upgrade for turtles, which makes turtles more useful."); - addTooltip(Items.OVERPOWERED_WEAK_AUTOMATA_CORE.get(), "&7Improved version of the weak automata core, that provide some overpowered uses! Be careful, the upgrade is very fragile."); - addTooltip(Items.HUSBANDRY_AUTOMATA_CORE.get(), "&7Upgrade for turtles, that allows basic and advanced interaction with animals."); - addTooltip(Items.OVERPOWERED_HUSBANDRY_AUTOMATA_CORE.get(), "&7Improved version of the husbandry automata core, that provides some overpowered uses! Be careful, the upgrade is very fragile."); - addTooltip(Items.END_AUTOMATA_CORE.get(), "&7Upgrade for turtles, that allows basic interaction with the world and teleportation in one dimension."); - addTooltip(Items.OVERPOWERED_END_AUTOMATA_CORE.get(), "&7Improved version of the end automata core, that provides some overpowered uses! Be careful, the upgrade is very fragile."); + addTooltip(APBlocks.INVENTORY_MANAGER.get(), "&7This block is able to send or receive specific items from a player inventory."); + addTooltip(APBlocks.REDSTONE_INTEGRATOR.get(), "&7This block is able to interact with redstone. Works exactly like the redstone api of an computer."); + addTooltip(APBlocks.BLOCK_READER.get(), "&7Reads nbt data of blocks to interact with blocks which do not have computer support."); + addTooltip(APBlocks.GEO_SCANNER.get(), "&7Scans the area around it to find some shiny ores."); + addTooltip(APBlocks.COLONY_INTEGRATOR.get(), "&7Interacts with Minecolonies to read data about your colony and citizens."); + addTooltip(APBlocks.NBT_STORAGE.get(), "&7Acts like a storage disk. Can store nbt based data like."); + addTooltip(APItems.WEAK_AUTOMATA_CORE.get(), "&7Upgrade for turtles, which makes turtles more useful."); + addTooltip(APItems.OVERPOWERED_WEAK_AUTOMATA_CORE.get(), "&7Improved version of the weak automata core, that provide some overpowered uses! Be careful, the upgrade is very fragile."); + addTooltip(APItems.HUSBANDRY_AUTOMATA_CORE.get(), "&7Upgrade for turtles, that allows basic and advanced interaction with animals."); + addTooltip(APItems.OVERPOWERED_HUSBANDRY_AUTOMATA_CORE.get(), "&7Improved version of the husbandry automata core, that provides some overpowered uses! Be careful, the upgrade is very fragile."); + addTooltip(APItems.END_AUTOMATA_CORE.get(), "&7Upgrade for turtles, that allows basic interaction with the world and teleportation in one dimension."); + addTooltip(APItems.OVERPOWERED_END_AUTOMATA_CORE.get(), "&7Improved version of the end automata core, that provides some overpowered uses! Be careful, the upgrade is very fragile."); } private void addText() { diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/PoiTypeProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/PoiTypeProvider.java index fb39483ad..fe33a4ae6 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/PoiTypeProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/PoiTypeProvider.java @@ -1,7 +1,7 @@ package de.srendi.advancedperipherals.common.data; import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.common.setup.Registration; +import de.srendi.advancedperipherals.common.setup.APRegistration; import net.minecraft.core.HolderLookup; import net.minecraft.data.PackOutput; import net.minecraft.data.tags.PoiTypeTagsProvider; @@ -24,9 +24,9 @@ public PoiTypeProvider(PackOutput output, CompletableFuture appender = tag(PoiTypeTags.ACQUIRABLE_JOB_SITE); - Registration.POI_TYPES.getEntries().stream().map(RegistryObject::getKey).filter(Objects::nonNull).forEach(appender::add); + APRegistration.POI_TYPES.getEntries().stream().map(RegistryObject::getKey).filter(Objects::nonNull).forEach(appender::add); } @NotNull diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java index d5bb1f466..9f300548f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java @@ -1,11 +1,9 @@ package de.srendi.advancedperipherals.common.data; -import appeng.core.definitions.AEBlocks; -import com.refinedmods.refinedstorage.RSBlocks; -import com.refinedmods.refinedstorage.RSItems; import dan200.computercraft.shared.ModRegistry; import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.common.setup.Blocks; +import de.srendi.advancedperipherals.common.setup.APBlocks; +import de.srendi.advancedperipherals.common.setup.APItems; import de.srendi.advancedperipherals.common.util.RawValue; import net.minecraft.data.PackOutput; import net.minecraft.data.recipes.FinishedRecipe; @@ -13,6 +11,7 @@ import net.minecraft.data.recipes.RecipeProvider; import net.minecraft.data.recipes.ShapedRecipeBuilder; import net.minecraft.data.recipes.ShapelessRecipeBuilder; +import net.minecraft.data.recipes.UpgradeRecipeBuilder; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.ItemTags; import net.minecraft.world.item.ItemStack; @@ -32,57 +31,261 @@ public class RecipesProvider extends RecipeProvider implements IConditionBuilder { - private static final Block CASING = Blocks.PERIPHERAL_CASING.get(); + private static final Block CASING = APBlocks.PERIPHERAL_CASING.get(); - public RecipesProvider(PackOutput output) { - super(output); + public RecipesProvider(PackOutput packOutput) { + super(packOutput); } @Override protected void buildRecipes(@NotNull Consumer consumer) { - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, Blocks.AR_CONTROLLER.get()).define('E', Tags.Items.ENDER_PEARLS).define('C', CASING).define('G', Items.SMOOTH_STONE).pattern("GEG").pattern("ECE").pattern("GEG").unlockedBy("has_item", has(CASING)).save(consumer); + addShapeless(consumer); + addShaped(consumer); + addSmithing(consumer); + } + + private void addShapeless(@NotNull Consumer consumer) { + ShapelessRecipeBuilder.shapeless(RecipeCategory.REDSTONE, APItems.OVERPOWERED_WEAK_AUTOMATA_CORE.get()) + .requires(APItems.WEAK_AUTOMATA_CORE.get()) + .requires(Items.NETHER_STAR) + .unlockedBy("has_item", has(APItems.WEAK_AUTOMATA_CORE.get())) + .save(consumer); - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, de.srendi.advancedperipherals.common.setup.Items.AR_GOGGLES.get()).define('E', Tags.Items.ENDER_PEARLS).define('S', Tags.Items.RODS_WOODEN).define('G', Tags.Items.GLASS_BLACK).pattern("GSG").pattern(" E ").unlockedBy("has_item", has(Items.STICK)).save(consumer); + ShapelessRecipeBuilder.shapeless(RecipeCategory.REDSTONE, APItems.OVERPOWERED_END_AUTOMATA_CORE.get()) + .requires(APItems.END_AUTOMATA_CORE.get()) + .requires(Items.NETHER_STAR) + .unlockedBy("has_item", has(APItems.END_AUTOMATA_CORE.get())) + .save(consumer); - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, Blocks.CHAT_BOX.get()).define('P', ItemTags.LOGS).define('A', CASING).define('G', Tags.Items.INGOTS_GOLD).pattern("PPP").pattern("PAP").pattern("PGP").unlockedBy("has_item", has(CASING)).save(consumer); + ShapelessRecipeBuilder.shapeless(RecipeCategory.REDSTONE, APItems.OVERPOWERED_HUSBANDRY_AUTOMATA_CORE.get()) + .requires(APItems.HUSBANDRY_AUTOMATA_CORE.get()) + .requires(Items.NETHER_STAR) + .unlockedBy("has_item", has(APItems.HUSBANDRY_AUTOMATA_CORE.get())) + .save(consumer); + } - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, de.srendi.advancedperipherals.common.setup.Items.CHUNK_CONTROLLER.get()).define('I', Tags.Items.INGOTS_IRON).define('R', Tags.Items.DUSTS_REDSTONE).define('A', Items.ENDER_EYE).pattern("IRI").pattern("RAR").pattern("IRI").unlockedBy("has_item", has(Items.RESPAWN_ANCHOR)).save(consumer); + private void addShaped(@NotNull Consumer consumer) { + ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APBlocks.AR_CONTROLLER.get()) + .define('E', Tags.Items.ENDER_PEARLS) + .define('C', CASING) + .define('G', Items.SMOOTH_STONE) + .pattern("GEG") + .pattern("ECE") + .pattern("GEG") + .unlockedBy("has_item", has(CASING)) + .save(consumer); - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, de.srendi.advancedperipherals.common.setup.Items.COMPUTER_TOOL.get()).define('I', Tags.Items.INGOTS_IRON).define('B', Items.BLUE_TERRACOTTA).pattern("I I").pattern("IBI").pattern(" B ").unlockedBy("has_item", has(Items.BLUE_TERRACOTTA)).save(consumer); + ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APItems.SMART_GLASSES.get()) + .define('E', Tags.Items.ENDER_PEARLS) + .define('S', Tags.Items.RODS_WOODEN) + .define('G', Tags.Items.GLASS_BLACK) + .pattern("GSG") + .pattern(" E ") + .unlockedBy("has_item", has(Items.STICK)) + .save(consumer); - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, Blocks.ENERGY_DETECTOR.get()).define('B', Tags.Items.STORAGE_BLOCKS_REDSTONE).define('R', Items.REDSTONE_TORCH).define('C', Items.COMPARATOR).define('A', CASING).define('G', Tags.Items.INGOTS_GOLD).pattern("BRB").pattern("CAC").pattern("BGB").unlockedBy("has_item", has(CASING)).save(consumer); + ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APBlocks.CHAT_BOX.get()) + .define('P', ItemTags.LOGS) + .define('A', CASING) + .define('G', Tags.Items.INGOTS_GOLD) + .pattern("PPP") + .pattern("PAP") + .pattern("PGP") + .unlockedBy("has_item", has(CASING)) + .save(consumer); - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, Blocks.ENVIRONMENT_DETECTOR.get()).define('W', ItemTags.WOOL).define('S', ItemTags.SAPLINGS).define('C', Tags.Items.CROPS).define('A', CASING).define('L', ItemTags.LEAVES).pattern("WSW").pattern("LAL").pattern("WCW").unlockedBy("has_item", has(CASING)).save(consumer); + ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APItems.CHUNK_CONTROLLER.get()) + .define('I', Tags.Items.INGOTS_IRON) + .define('R', Tags.Items.DUSTS_REDSTONE) + .define('A', Items.ENDER_EYE) + .pattern("IRI") + .pattern("RAR") + .pattern("IRI") + .unlockedBy("has_item", has(Items.RESPAWN_ANCHOR)) + .save(consumer); - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, Blocks.INVENTORY_MANAGER.get()).define('I', Tags.Items.INGOTS_IRON).define('C', Tags.Items.CHESTS).define('A', CASING).pattern("ICI").pattern("CAC").pattern("ICI").unlockedBy("has_item", has(CASING)).save(consumer); + ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APItems.COMPUTER_TOOL.get()) + .define('I', Tags.Items.INGOTS_IRON) + .define('B', Items.BLUE_TERRACOTTA) + .pattern("I I") + .pattern("IBI") + .pattern(" B ") + .unlockedBy("has_item", has(Items.BLUE_TERRACOTTA)) + .save(consumer); - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, de.srendi.advancedperipherals.common.setup.Items.MEMORY_CARD.get()).define('I', Tags.Items.INGOTS_IRON).define('W', Tags.Items.GLASS_WHITE).define('O', Items.OBSERVER).define('G', Tags.Items.INGOTS_GOLD).pattern("IWI").pattern("IOI").pattern(" G ").unlockedBy("has_item", has(Items.OBSERVER)).save(consumer); + ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APBlocks.ENERGY_DETECTOR.get()) + .define('B', Tags.Items.STORAGE_BLOCKS_REDSTONE) + .define('R', Items.REDSTONE_TORCH) + .define('C', Items.COMPARATOR) + .define('A', CASING) + .define('G', Tags.Items.INGOTS_GOLD) + .pattern("BRB") + .pattern("CAC") + .pattern("BGB") + .unlockedBy("has_item", has(CASING)) + .save(consumer); - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, Blocks.PERIPHERAL_CASING.get()).define('I', Tags.Items.INGOTS_IRON).define('i', Items.IRON_BARS).define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE).pattern("IiI").pattern("iRi").pattern("IiI").unlockedBy("has_item", has(Items.REDSTONE_BLOCK)).save(consumer); + ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APBlocks.ENVIRONMENT_DETECTOR.get()) + .define('W', ItemTags.WOOL) + .define('S', ItemTags.SAPLINGS) + .define('C', Tags.Items.CROPS) + .define('A', CASING) + .define('L', ItemTags.LEAVES) + .pattern("WSW") + .pattern("LAL") + .pattern("WCW") + .unlockedBy("has_item", has(CASING)) + .save(consumer); - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, Blocks.PLAYER_DETECTOR.get()).define('S', Items.SMOOTH_STONE).define('A', CASING).define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE).pattern("SSS").pattern("SAS").pattern("SRS").unlockedBy("has_item", has(CASING)).save(consumer); + ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APBlocks.INVENTORY_MANAGER.get()) + .define('I', Tags.Items.INGOTS_IRON) + .define('C', Tags.Items.CHESTS) + .define('A', CASING) + .pattern("ICI") + .pattern("CAC") + .pattern("ICI") + .unlockedBy("has_item", has(CASING)) + .save(consumer); - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, Blocks.REDSTONE_INTEGRATOR.get()).define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE).define('A', CASING).define('C', Items.COMPARATOR).pattern("RCR").pattern("CAC").pattern("RCR").unlockedBy("has_item", has(CASING)).save(consumer); + ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APItems.MEMORY_CARD.get()) + .define('I', Tags.Items.INGOTS_IRON) + .define('W', Tags.Items.GLASS_WHITE) + .define('O', Items.OBSERVER) + .define('G', Tags.Items.INGOTS_GOLD) + .pattern("IWI") + .pattern("IOI") + .pattern(" G ") + .unlockedBy("has_item", has(Items.OBSERVER)) + .save(consumer); - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, Blocks.BLOCK_READER.get()).define('O', Items.OBSERVER).define('I', Tags.Items.INGOTS_IRON).define('M', ModRegistry.Blocks.WIRED_MODEM_FULL.get()).define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE).define('A', CASING).pattern("IRI").pattern("MAO").pattern("IRI").unlockedBy("has_item", has(CASING)).save(consumer); + ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APBlocks.PERIPHERAL_CASING.get()) + .define('I', Tags.Items.INGOTS_IRON) + .define('i', Items.IRON_BARS) + .define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE) + .pattern("IiI") + .pattern("iRi") + .pattern("IiI") + .unlockedBy("has_item", has(Items.REDSTONE_BLOCK)) + .save(consumer); - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, Blocks.GEO_SCANNER.get()).define('O', Items.OBSERVER).define('D', Tags.Items.GEMS_DIAMOND).define('C', CASING).define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE).define('M', ModRegistry.Blocks.WIRED_MODEM_FULL.get()).pattern("DMD").pattern("DCD").pattern("ROR").unlockedBy("has_item", has(CASING)).save(consumer); + ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APBlocks.PLAYER_DETECTOR.get()) + .define('S', Items.SMOOTH_STONE) + .define('A', CASING) + .define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE) + .pattern("SSS") + .pattern("SAS") + .pattern("SRS") + .unlockedBy("has_item", has(CASING)) + .save(consumer); - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, Blocks.NBT_STORAGE.get()).define('C', Tags.Items.CHESTS).define('A', CASING).define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE).define('I', Tags.Items.INGOTS_IRON).pattern("ICI").pattern("CAC").pattern("RCR").unlockedBy("has_item", has(CASING)).save(consumer); + ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APBlocks.REDSTONE_INTEGRATOR.get()) + .define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE) + .define('A', CASING) + .define('C', Items.COMPARATOR) + .pattern("RCR") + .pattern("CAC") + .pattern("RCR") + .unlockedBy("has_item", has(CASING)) + .save(consumer); - ConditionalRecipe.builder().addCondition(modLoaded("minecolonies")).addRecipe(ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, Blocks.COLONY_INTEGRATOR.get()).define('O', ItemTags.LOGS).define('A', CASING).define('R', Ingredient.fromValues(Stream.of(new RawValue(new ResourceLocation("minecolonies", "blockminecoloniesrack"))))).pattern("ORO").pattern(" A ").pattern("ORO").unlockedBy("has_item", has(CASING))::save).build(consumer, new ResourceLocation(AdvancedPeripherals.MOD_ID, "colony_integrator")); + ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APBlocks.BLOCK_READER.get()) + .define('O', Items.OBSERVER) + .define('I', Tags.Items.INGOTS_IRON) + .define('M', ModRegistry.Blocks.WIRED_MODEM_FULL.get()) + .define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE) + .define('A', CASING) + .pattern("IRI") + .pattern("MAO") + .pattern("IRI") + .unlockedBy("has_item", has(CASING)) + .save(consumer); - ConditionalRecipe.builder().addCondition(modLoaded("ae2")).addRecipe(ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, Blocks.ME_BRIDGE.get()).define('F', AEBlocks.FLUIX_BLOCK.asItem()).define('A', CASING).define('I', AEBlocks.INTERFACE.asItem()).pattern("FIF").pattern("IAI").pattern("FIF").unlockedBy("has_item", has(CASING))::save).build(consumer, new ResourceLocation(AdvancedPeripherals.MOD_ID, "me_bridge")); + ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APBlocks.GEO_SCANNER.get()) + .define('O', Items.OBSERVER) + .define('D', Tags.Items.GEMS_DIAMOND) + .define('C', CASING) + .define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE) + .define('M', ModRegistry.Blocks.WIRED_MODEM_FULL.get()) + .pattern("DMD") + .pattern("DCD") + .pattern("ROR") + .unlockedBy("has_item", has(CASING)) + .save(consumer); - ConditionalRecipe.builder().addCondition(modLoaded("refinedstorage")).addRecipe(ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, Blocks.RS_BRIDGE.get()).define('Q', RSItems.QUARTZ_ENRICHED_IRON.get()).define('A', CASING).define('I', RSBlocks.INTERFACE.get()).pattern("QIQ").pattern("IAI").pattern("QIQ").unlockedBy("has_item", has(CASING))::save).build(consumer, new ResourceLocation(AdvancedPeripherals.MOD_ID, "rs_bridge")); + ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APBlocks.NBT_STORAGE.get()) + .define('C', Tags.Items.CHESTS) + .define('A', CASING) + .define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE) + .define('I', Tags.Items.INGOTS_IRON) + .pattern("ICI") + .pattern("CAC") + .pattern("RCR") + .unlockedBy("has_item", has(CASING)) + .save(consumer); - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, de.srendi.advancedperipherals.common.setup.Items.WEAK_AUTOMATA_CORE.get()).define('A', CASING).define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE).define('S', Items.SOUL_LANTERN).define('D', Tags.Items.GEMS_DIAMOND).define('L', StrictNBTIngredient.of(PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.LONG_REGENERATION))).pattern("RAR").pattern("DSD").pattern("RLR").unlockedBy("has_item", has(CASING)).save(consumer); + ConditionalRecipe.builder() + .addCondition( + modLoaded("minecolonies") + ) + .addRecipe( + ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APBlocks.COLONY_INTEGRATOR.get()) + .define('O', ItemTags.LOGS) + .define('A', CASING) + .define('R', Ingredient.fromValues(Stream.of(new RawValue(new ResourceLocation("minecolonies", "blockminecoloniesrack"))))) + .pattern("ORO") + .pattern(" A ") + .pattern("ORO") + .unlockedBy("has_item", has(CASING))::save + ).build(consumer, new ResourceLocation(AdvancedPeripherals.MOD_ID, "colony_integrator")); - ShapelessRecipeBuilder.shapeless(RecipeCategory.REDSTONE, de.srendi.advancedperipherals.common.setup.Items.OVERPOWERED_WEAK_AUTOMATA_CORE.get()).requires(de.srendi.advancedperipherals.common.setup.Items.WEAK_AUTOMATA_CORE.get()).requires(Items.NETHER_STAR).unlockedBy("has_item", has(de.srendi.advancedperipherals.common.setup.Items.WEAK_AUTOMATA_CORE.get())).save(consumer); + /*ConditionalRecipe.builder() + .addCondition( + modLoaded("ae2") + ) + .addRecipe( + ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APBlocks.ME_BRIDGE.get()) + .define('F', AEBlocks.FLUIX_BLOCK.asItem()) + .define('A', CASING) + .define('I', AEBlocks.INTERFACE.asItem()) + .pattern("FIF") + .pattern("IAI") + .pattern("FIF") + .unlockedBy("has_item", has(CASING))::save + ).build(consumer, new ResourceLocation(AdvancedPeripherals.MOD_ID, "me_bridge")); - ShapelessRecipeBuilder.shapeless(RecipeCategory.REDSTONE, de.srendi.advancedperipherals.common.setup.Items.OVERPOWERED_END_AUTOMATA_CORE.get()).requires(de.srendi.advancedperipherals.common.setup.Items.END_AUTOMATA_CORE.get()).requires(Items.NETHER_STAR).unlockedBy("has_item", has(de.srendi.advancedperipherals.common.setup.Items.END_AUTOMATA_CORE.get())).save(consumer); + ConditionalRecipe.builder() + .addCondition( + modLoaded("refinedstorage") + ) + .addRecipe( + ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APBlocks.RS_BRIDGE.get()) + .define('Q', RSItems.QUARTZ_ENRICHED_IRON.get()) + .define('A', CASING) + .define('I', RSBlocks.INTERFACE.get()) + .pattern("QIQ") + .pattern("IAI") + .pattern("QIQ") + .unlockedBy("has_item", has(CASING))::save + ).build(consumer, new ResourceLocation(AdvancedPeripherals.MOD_ID, "rs_bridge")); +*/ + ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APItems.WEAK_AUTOMATA_CORE.get()) + .define('A', CASING) + .define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE) + .define('S', Items.SOUL_LANTERN) + .define('D', Tags.Items.GEMS_DIAMOND) + .define('L', StrictNBTIngredient.of(PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.LONG_REGENERATION))) + .pattern("RAR") + .pattern("DSD") + .pattern("RLR") + .unlockedBy("has_item", has(CASING)) + .save(consumer); + } - ShapelessRecipeBuilder.shapeless(RecipeCategory.REDSTONE, de.srendi.advancedperipherals.common.setup.Items.OVERPOWERED_HUSBANDRY_AUTOMATA_CORE.get()).requires(de.srendi.advancedperipherals.common.setup.Items.HUSBANDRY_AUTOMATA_CORE.get()).requires(Items.NETHER_STAR).unlockedBy("has_item", has(de.srendi.advancedperipherals.common.setup.Items.HUSBANDRY_AUTOMATA_CORE.get())).save(consumer); + private void addSmithing(@NotNull Consumer consumer) { + UpgradeRecipeBuilder + .smithing(Ingredient.of(APItems.SMART_GLASSES.get()), Ingredient.of(Items.NETHERITE_INGOT), RecipeCategory.REDSTONE, APItems.SMART_GLASSES_NETHERITE.get()) + .unlocks("has_item", has(Items.NETHERITE_INGOT)) + .save(consumer, new ResourceLocation(AdvancedPeripherals.MOD_ID, "armor/" + APItems.SMART_GLASSES_NETHERITE.getKey().location().getPath())); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/TurtleUpgradesProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/TurtleUpgradesProvider.java index 8a034f61a..9ca170b03 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/TurtleUpgradesProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/TurtleUpgradesProvider.java @@ -2,9 +2,9 @@ import dan200.computercraft.api.turtle.TurtleUpgradeDataProvider; import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser; -import de.srendi.advancedperipherals.common.setup.Blocks; +import de.srendi.advancedperipherals.common.setup.APBlocks; +import de.srendi.advancedperipherals.common.setup.APItems; import de.srendi.advancedperipherals.common.setup.CCRegistration; -import de.srendi.advancedperipherals.common.setup.Items; import net.minecraft.data.PackOutput; import org.jetbrains.annotations.NotNull; @@ -18,18 +18,18 @@ public TurtleUpgradesProvider(PackOutput generator) { @Override protected void addUpgrades(@NotNull Consumer>> addUpgrade) { - simpleWithCustomItem(CCRegistration.ID.CHATTY_TURTLE, CCRegistration.CHAT_BOX_TURTLE.get(), Blocks.CHAT_BOX.get().asItem()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.PLAYER_TURTLE, CCRegistration.PLAYER_DETECTOR_TURTLE.get(), Blocks.PLAYER_DETECTOR.get().asItem()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.ENVIRONMENT_TURTLE, CCRegistration.ENVIRONMENT_TURTLE.get(), Blocks.ENVIRONMENT_DETECTOR.get().asItem()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.CHUNKY_TURTLE, CCRegistration.CHUNKY_TURTLE.get(), Items.CHUNK_CONTROLLER.get()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.GEOSCANNER_TURTLE, CCRegistration.GEO_SCANNER_TURTLE.get(), Blocks.GEO_SCANNER.get().asItem()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.CHATTY_TURTLE, CCRegistration.CHAT_BOX_TURTLE.get(), APBlocks.CHAT_BOX.get().asItem()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.PLAYER_TURTLE, CCRegistration.PLAYER_DETECTOR_TURTLE.get(), APBlocks.PLAYER_DETECTOR.get().asItem()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.ENVIRONMENT_TURTLE, CCRegistration.ENVIRONMENT_TURTLE.get(), APBlocks.ENVIRONMENT_DETECTOR.get().asItem()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.CHUNKY_TURTLE, CCRegistration.CHUNKY_TURTLE.get(), APItems.CHUNK_CONTROLLER.get()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.GEOSCANNER_TURTLE, CCRegistration.GEO_SCANNER_TURTLE.get(), APBlocks.GEO_SCANNER.get().asItem()).add(addUpgrade); simpleWithCustomItem(CCRegistration.ID.COMPASS_TURTLE, CCRegistration.COMPASS_TURTLE.get(), net.minecraft.world.item.Items.COMPASS).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.WEAK_AUTOMATA, CCRegistration.WEAK_TURTLE.get(), Items.WEAK_AUTOMATA_CORE.get()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.END_AUTOMATA, CCRegistration.END_TURTLE.get(), Items.END_AUTOMATA_CORE.get()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.HUSBANDRY_AUTOMATA, CCRegistration.HUSBANDRY_TURTLE.get(), Items.HUSBANDRY_AUTOMATA_CORE.get()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.OP_WEAK_AUTOMATA, CCRegistration.OP_WEAK_TURTLE.get(), Items.OVERPOWERED_WEAK_AUTOMATA_CORE.get()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.OP_END_AUTOMATA, CCRegistration.OP_END_TURTLE.get(), Items.OVERPOWERED_END_AUTOMATA_CORE.get()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.OP_HUSBANDRY_AUTOMATA, CCRegistration.OP_HUSBANDRY_TURTLE.get(), Items.OVERPOWERED_HUSBANDRY_AUTOMATA_CORE.get()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.WEAK_AUTOMATA, CCRegistration.WEAK_TURTLE.get(), APItems.WEAK_AUTOMATA_CORE.get()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.END_AUTOMATA, CCRegistration.END_TURTLE.get(), APItems.END_AUTOMATA_CORE.get()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.HUSBANDRY_AUTOMATA, CCRegistration.HUSBANDRY_TURTLE.get(), APItems.HUSBANDRY_AUTOMATA_CORE.get()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.OP_WEAK_AUTOMATA, CCRegistration.OP_WEAK_TURTLE.get(), APItems.OVERPOWERED_WEAK_AUTOMATA_CORE.get()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.OP_END_AUTOMATA, CCRegistration.OP_END_TURTLE.get(), APItems.OVERPOWERED_END_AUTOMATA_CORE.get()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.OP_HUSBANDRY_AUTOMATA, CCRegistration.OP_HUSBANDRY_TURTLE.get(), APItems.OVERPOWERED_HUSBANDRY_AUTOMATA_CORE.get()).add(addUpgrade); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java index 0a0042c65..053d5b5a4 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java @@ -1,6 +1,5 @@ package de.srendi.advancedperipherals.common.items; -import de.srendi.advancedperipherals.AdvancedPeripherals; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.item.ArmorItem; @@ -16,7 +15,7 @@ public class SmartGlassesItem extends ArmorItem { public SmartGlassesItem(ArmorMaterials material) { - super(material, EquipmentSlot.HEAD, new Properties().tab(AdvancedPeripherals.TAB).stacksTo(1)); + super(material, EquipmentSlot.HEAD, new Properties().stacksTo(1)); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java index 3bb5efeb1..4083fd13b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java @@ -1,6 +1,7 @@ package de.srendi.advancedperipherals.common.setup; import com.google.common.collect.Sets; +import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.blocks.blockentities.BlockReaderEntity; import de.srendi.advancedperipherals.common.blocks.blockentities.ChatBoxEnity; import de.srendi.advancedperipherals.common.blocks.blockentities.ColonyIntegratorEntity; @@ -18,7 +19,6 @@ import de.srendi.advancedperipherals.common.blocks.blockentities.RsBridgeEntity; import de.srendi.advancedperipherals.common.blocks.blockentities.SmartGlassesControllerEntity; import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraftforge.fml.ModList; import net.minecraftforge.registries.RegistryObject; public class APBlockEntityTypes { @@ -29,11 +29,11 @@ static void register() { public static final RegistryObject> CHAT_BOX = APRegistration.TILE_ENTITIES.register("chat_box", () -> new BlockEntityType<>(ChatBoxEnity::new, Sets.newHashSet(APBlocks.CHAT_BOX.get()), null)); public static final RegistryObject> ENVIRONMENT_DETECTOR = APRegistration.TILE_ENTITIES.register("environment_detector", () -> new BlockEntityType<>(EnvironmentDetectorEntity::new, Sets.newHashSet(APBlocks.ENVIRONMENT_DETECTOR.get()), null)); public static final RegistryObject> PLAYER_DETECTOR = APRegistration.TILE_ENTITIES.register("player_detector", () -> new BlockEntityType<>(PlayerDetectorEntity::new, Sets.newHashSet(APBlocks.PLAYER_DETECTOR.get()), null)); - public static final RegistryObject> ME_BRIDGE = ModList.get().isLoaded("ae2") ? APRegistration.TILE_ENTITIES.register("me_bridge", () -> new BlockEntityType<>(MeBridgeEntity::new, Sets.newHashSet(APBlocks.ME_BRIDGE.get()), null)) : null; - public static final RegistryObject> RS_BRIDGE = ModList.get().isLoaded("refinedstorage") ? APRegistration.TILE_ENTITIES.register("rs_bridge", () -> new BlockEntityType<>(RsBridgeEntity::new, Sets.newHashSet(APBlocks.RS_BRIDGE.get()), null)) : null; + public static final RegistryObject> ME_BRIDGE = AdvancedPeripherals.ADDONS.appliedEnergisticsLoaded ? APRegistration.TILE_ENTITIES.register("me_bridge", () -> new BlockEntityType<>(MeBridgeEntity::new, Sets.newHashSet(APBlocks.ME_BRIDGE.get()), null)) : null; + public static final RegistryObject> RS_BRIDGE = AdvancedPeripherals.ADDONS.refinedStorageLoaded ? APRegistration.TILE_ENTITIES.register("rs_bridge", () -> new BlockEntityType<>(RsBridgeEntity::new, Sets.newHashSet(APBlocks.RS_BRIDGE.get()), null)) : null; public static final RegistryObject> ENERGY_DETECTOR = APRegistration.TILE_ENTITIES.register("energy_detector", () -> new BlockEntityType<>(EnergyDetectorEntity::new, Sets.newHashSet(APBlocks.ENERGY_DETECTOR.get()), null)); public static final RegistryObject> FLUID_DETECTOR = APRegistration.TILE_ENTITIES.register("fluid_detector", () -> new BlockEntityType<>(FluidDetectorEntity::new, Sets.newHashSet(APBlocks.FLUID_DETECTOR.get()), null)); - public static final RegistryObject> GAS_DETECTOR = APRegistration.TILE_ENTITIES.register("gas_detector", () -> new BlockEntityType<>(GasDetectorEntity::new, Sets.newHashSet(APBlocks.GAS_DETECTOR.get()), null)); + public static final RegistryObject> GAS_DETECTOR = AdvancedPeripherals.ADDONS.mekanismLoaded ? APRegistration.TILE_ENTITIES.register("gas_detector", () -> new BlockEntityType<>(GasDetectorEntity::new, Sets.newHashSet(APBlocks.GAS_DETECTOR.get()), null)) : null; public static final RegistryObject> AR_CONTROLLER = APRegistration.TILE_ENTITIES.register("ar_controller", () -> new BlockEntityType<>(SmartGlassesControllerEntity::new, Sets.newHashSet(APBlocks.AR_CONTROLLER.get()), null)); public static final RegistryObject> INVENTORY_MANAGER = APRegistration.TILE_ENTITIES.register("inventory_manager", () -> new BlockEntityType<>(InventoryManagerEntity::new, Sets.newHashSet(APBlocks.INVENTORY_MANAGER.get()), null)); public static final RegistryObject> REDSTONE_INTEGRATOR = APRegistration.TILE_ENTITIES.register("redstone_integrator", () -> new BlockEntityType<>(RedstoneIntegratorEntity::new, Sets.newHashSet(APBlocks.REDSTONE_INTEGRATOR.get()), null)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APVillagers.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APVillagers.java index 823d40cdc..201f947d5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APVillagers.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APVillagers.java @@ -1,7 +1,7 @@ package de.srendi.advancedperipherals.common.setup; import com.google.common.collect.ImmutableSet; -import dan200.computercraft.shared.Registry; +import dan200.computercraft.shared.ModRegistry; import de.srendi.advancedperipherals.AdvancedPeripherals; import net.minecraft.sounds.SoundEvents; import net.minecraft.world.entity.ai.village.poi.PoiType; @@ -10,9 +10,9 @@ public class APVillagers { - public static final RegistryObject COMPUTER_SCIENTIST_POI = APRegistration.POI_TYPES.register("computer_scientist", () -> new PoiType(ImmutableSet.copyOf(Registry.ModBlocks.COMPUTER_ADVANCED.get().getStateDefinition().getPossibleStates()), 1, 1)); + public static final RegistryObject COMPUTER_SCIENTIST_POI = APRegistration.POI_TYPES.register("computer_scientist", () -> new PoiType(ImmutableSet.copyOf(ModRegistry.Blocks.COMPUTER_ADVANCED.get().getStateDefinition().getPossibleStates()), 1, 1)); - public static final RegistryObject COMPUTER_SCIENTIST = APRegistration.VILLAGER_PROFESSIONS.register("computer_scientist", () -> new VillagerProfession(AdvancedPeripherals.MOD_ID + ":computer_scientist", holder -> holder.is(COMPUTER_SCIENTIST_POI.getKey()), holder -> holder.is(COMPUTER_SCIENTIST_POI.getKey()), ImmutableSet.of(), ImmutableSet.of(Registry.ModBlocks.COMPUTER_ADVANCED.get()), SoundEvents.VILLAGER_WORK_TOOLSMITH)); + public static final RegistryObject COMPUTER_SCIENTIST = APRegistration.VILLAGER_PROFESSIONS.register("computer_scientist", () -> new VillagerProfession(AdvancedPeripherals.MOD_ID + ":computer_scientist", holder -> holder.is(COMPUTER_SCIENTIST_POI.getKey()), holder -> holder.is(COMPUTER_SCIENTIST_POI.getKey()), ImmutableSet.of(), ImmutableSet.of(ModRegistry.Blocks.COMPUTER_ADVANCED.get()), SoundEvents.VILLAGER_WORK_TOOLSMITH)); public static void register() { } diff --git a/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrades.java b/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrades.java index 1b28c4c8b..534a36b05 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrades.java +++ b/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrades.java @@ -6,8 +6,6 @@ import de.srendi.advancedperipherals.common.setup.APItems; import de.srendi.advancedperipherals.common.setup.APVillagers; import de.srendi.advancedperipherals.common.setup.CCRegistration; -import de.srendi.advancedperipherals.common.setup.Items; -import de.srendi.advancedperipherals.common.setup.Villagers; import de.srendi.advancedperipherals.common.util.ItemUtil; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import net.minecraftforge.event.village.VillagerTradesEvent; From d07cc596b0a76963bc3e497642ea1f3bec5d929f Mon Sep 17 00:00:00 2001 From: Sr_endi Date: Mon, 2 Jan 2023 21:33:56 +0100 Subject: [PATCH 010/228] Adapt me and rs bridge functions. Both bridges now have the same functions with the same names. This makes it easier to support both in the same script Still needs some adjustments and documentation --- .../addons/appliedenergistics/CraftJob.java | 1 - .../addons/base/IStoragePeripheral.java | 94 ++++++ .../peripheral/MeBridgePeripheral.java | 313 ++++++++++++------ .../peripheral/RsBridgePeripheral.java | 304 +++++++++-------- .../blocks/blockentities/MeBridgeEntity.java | 10 +- 5 files changed, 479 insertions(+), 243 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/addons/base/IStoragePeripheral.java diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/CraftJob.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/CraftJob.java index 7e97e310a..8060a6ad5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/CraftJob.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/CraftJob.java @@ -53,7 +53,6 @@ protected void fireEvent(boolean success, @Nullable String exception) { this.result = MethodResult.of(success, exception); this.exception = new LuaException(exception); this.computer.queueEvent(EVENT, success, exception); - } protected void fireNotConnected() { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/base/IStoragePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/base/IStoragePeripheral.java new file mode 100644 index 000000000..5c4272322 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/base/IStoragePeripheral.java @@ -0,0 +1,94 @@ +package de.srendi.advancedperipherals.common.addons.base; + +import dan200.computercraft.api.lua.IArguments; +import dan200.computercraft.api.lua.LuaException; +import dan200.computercraft.api.lua.LuaFunction; +import dan200.computercraft.api.lua.MethodResult; +import dan200.computercraft.api.peripheral.IComputerAccess; + +/** + * Implementation for common storage peripheral functions. Used for AE2 {@link de.srendi.advancedperipherals.common.addons.computercraft.peripheral.MeBridgePeripheral} + * and RS {@link de.srendi.advancedperipherals.common.addons.computercraft.peripheral.RsBridgePeripheral} + * + * This ensures that these both bridges use the same methods. This makes it easier to support both in the same script + * In case there is a new mod which adds new ways to store and craft items, this ensures that the new peripheral + * has the same functions as the other ones + */ +public interface IStoragePeripheral { + + @LuaFunction(mainThread = true) + MethodResult isConnected(); + + @LuaFunction(mainThread = true) + MethodResult isOnline(); + + @LuaFunction(mainThread = true) + MethodResult getItem(IArguments arguments) throws LuaException; + + @LuaFunction(mainThread = true) + MethodResult getFluid(IArguments arguments) throws LuaException; + + @LuaFunction(mainThread = true) + MethodResult listItems(); + + @LuaFunction(mainThread = true) + MethodResult listFluids(); + + @LuaFunction(mainThread = true) + MethodResult listCraftableItems(); + + @LuaFunction(mainThread = true) + MethodResult listCraftableFluids(); + + @LuaFunction(mainThread = true) + MethodResult importItem(IArguments arguments) throws LuaException; + + @LuaFunction(mainThread = true) + MethodResult exportItem(IArguments arguments) throws LuaException; + + @LuaFunction(mainThread = true) + MethodResult importItemFromPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException; + + @LuaFunction(mainThread = true) + MethodResult exportItemToPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException; + + @LuaFunction(mainThread = true) + MethodResult getPattern(IArguments arguments) throws LuaException; + + @LuaFunction(mainThread = true) + MethodResult getPatterns(); + + @LuaFunction(mainThread = true) + MethodResult getStoredEnergy(); + + @LuaFunction(mainThread = true) + MethodResult getEnergyCapacity(); + + @LuaFunction(mainThread = true) + MethodResult getEnergyUsage(); + + @LuaFunction(mainThread = true) + MethodResult getMaxItemExternalStorage(); + + @LuaFunction(mainThread = true) + MethodResult getMaxFluidExternalStorage(); + + @LuaFunction(mainThread = true) + MethodResult getMaxItemDiskStorage(); + + @LuaFunction(mainThread = true) + MethodResult getMaxFluidDiskStorage(); + + @LuaFunction(mainThread = true) + MethodResult craftItem(IComputerAccess computer, IArguments arguments) throws LuaException; + + @LuaFunction(mainThread = true) + MethodResult craftFluid(IComputerAccess computer, IArguments arguments) throws LuaException; + + @LuaFunction(mainThread = true) + MethodResult isItemCraftable(IArguments arguments) throws LuaException; + + @LuaFunction(mainThread = true) + MethodResult isItemCrafting(IArguments arguments) throws LuaException; + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java index 79ec16278..02cfe4df8 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java @@ -15,6 +15,7 @@ import dan200.computercraft.api.peripheral.IComputerAccess; import de.srendi.advancedperipherals.common.addons.appliedenergistics.AppEngApi; import de.srendi.advancedperipherals.common.addons.appliedenergistics.CraftJob; +import de.srendi.advancedperipherals.common.addons.base.IStoragePeripheral; import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner; import de.srendi.advancedperipherals.common.blocks.blockentities.MeBridgeEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; @@ -29,11 +30,11 @@ import net.minecraftforge.items.ItemHandlerHelper; import org.jetbrains.annotations.NotNull; -import java.util.HashMap; +import java.util.ArrayList; import java.util.Iterator; -import java.util.Map; +import java.util.List; -public class MeBridgePeripheral extends BasePeripheral> { +public class MeBridgePeripheral extends BasePeripheral> implements IStoragePeripheral { public static final String PERIPHERAL_TYPE = "meBridge"; private final MeBridgeEntity tile; @@ -58,6 +59,10 @@ private ICraftingService getCraftingService() { return node.getGrid().getCraftingService(); } + private boolean canRun() { + return node.isActive(); + } + /** * exports an item out of the system to a valid inventory * @@ -66,33 +71,34 @@ private ICraftingService getCraftingService() { * @return the exportable amount * @throws LuaException if stack does not exist or the system is offline - will be removed in 0.8 */ - protected long exportToChest(@NotNull IArguments arguments, @NotNull IItemHandler targetInventory) throws LuaException { + protected MethodResult exportToChest(@NotNull IArguments arguments, @NotNull IItemHandler targetInventory) throws LuaException { MEStorage monitor = AppEngApi.getMonitor(node); ItemStack stack = ItemUtil.getItemStack(arguments.getTable(0), monitor); + if (stack.isEmpty()) + return MethodResult.of(0, "Could not find item"); AEItemKey targetStack = AEItemKey.of(stack); - if (targetStack == null) throw new LuaException("Illegal AE2 state ..."); long extracted = monitor.extract(targetStack, stack.getCount(), Actionable.SIMULATE, tile.getActionSource()); if (extracted == 0) - throw new LuaException("Item " + stack + " does not exists in the ME system or the system is offline"); + return MethodResult.of(0, "Item " + stack + " does not exists in the ME system"); long transferableAmount = extracted; ItemStack remaining = ItemHandlerHelper.insertItemStacked(targetInventory, stack, true); - if (!remaining.isEmpty()) { + if (!remaining.isEmpty()) transferableAmount -= remaining.getCount(); - } - if (transferableAmount == 0) return transferableAmount; + if (transferableAmount == 0) + return MethodResult.of(transferableAmount); extracted = monitor.extract(targetStack, transferableAmount, Actionable.MODULATE, tile.getActionSource()); stack.setCount((int) extracted); remaining = ItemHandlerHelper.insertItemStacked(targetInventory, stack, false); - if (!remaining.isEmpty()) { + if (!remaining.isEmpty()) monitor.insert(AEItemKey.of(remaining), remaining.getCount(), Actionable.MODULATE, tile.getActionSource()); - } - return transferableAmount; + + return MethodResult.of(transferableAmount); } /** @@ -103,15 +109,16 @@ protected long exportToChest(@NotNull IArguments arguments, @NotNull IItemHandle * @return the imported amount * @throws LuaException if system is offline - will be removed in 0.8 */ - protected int importToME(@NotNull IArguments arguments, @NotNull IItemHandler targetInventory) throws LuaException { + protected MethodResult importToME(@NotNull IArguments arguments, @NotNull IItemHandler targetInventory) throws LuaException { MEStorage monitor = AppEngApi.getMonitor(node); ItemStack stack = ItemUtil.getItemStack(arguments.getTable(0), monitor); - AEItemKey aeStack = AEItemKey.of(stack); + if (stack.isEmpty()) + return MethodResult.of(0, "Could not find item"); + AEItemKey targetStack = AEItemKey.of(stack); int amount = stack.getCount(); - if (aeStack == null) throw new LuaException("Illegal AE2 state ..."); - - if (stack.getCount() == 0) return 0; + if (stack.getCount() == 0) + return MethodResult.of(0); int transferableAmount = 0; @@ -120,146 +127,242 @@ protected int importToME(@NotNull IArguments arguments, @NotNull IItemHandler ta int countInSlot = targetInventory.getStackInSlot(i).getCount(); int extractCount = Math.min(countInSlot, amount); amount -= extractCount; - int extracted = (int) monitor.insert(aeStack, extractCount, Actionable.MODULATE, tile.getActionSource()); + int extracted = (int) monitor.insert(targetStack, extractCount, Actionable.MODULATE, tile.getActionSource()); targetInventory.extractItem(i, extracted, false); transferableAmount += extracted; } } - return transferableAmount; + return MethodResult.of(transferableAmount); } - @LuaFunction - public final MethodResult craftItem(IComputerAccess computer, IArguments arguments) throws LuaException { - MEStorage monitor = AppEngApi.getMonitor(node); - ItemStack itemToCraft = ItemUtil.getItemStack(arguments.getTable(0), monitor); - if (itemToCraft.isEmpty()) return MethodResult.of(false, "Item " + itemToCraft + " does not exists"); - CraftJob job = new CraftJob(owner.getLevel(), computer, node, itemToCraft, tile, tile); - tile.addJob(job); - ServerWorker.add(job::startCrafting); - return MethodResult.of(true); - //TODO - 0.8: This needs our attention. We need to return better and more useful data to the user. See https://github.com/Seniorendi/AdvancedPeripherals/issues/323 - //return MethodResult.pullEvent("crafting", job); + @Override + public final MethodResult isConnected() { + return MethodResult.of(node.isOnline()); } - @LuaFunction(mainThread = true) - public final double getEnergyUsage() { - return node.getGrid().getEnergyService().getAvgPowerUsage(); + @Override + public MethodResult isOnline() { + if (!node.isOnline()) + return MethodResult.of(false, "Not connected"); + return MethodResult.of(canRun()); } - @LuaFunction(mainThread = true) - public final double getEnergyStorage() { - return node.getGrid().getEnergyService().getStoredPower(); + @Override + public final MethodResult getItem(IArguments arguments) throws LuaException { + if (!canRun()) + return MethodResult.of(null, "System not connected or offline"); + + MEStorage monitor = AppEngApi.getMonitor(node); + ItemStack stack = ItemUtil.getItemStack(arguments.getTable(0), monitor); + if (stack.isEmpty()) + return MethodResult.of(null, "Could not find item"); + //TODO: We already do something like this when retrieving the stack. Check if we still need this before next release + for (Object2LongMap.Entry potentialStack : monitor.getAvailableStacks()) { + if (potentialStack.getKey() instanceof AEItemKey itemKey && itemKey.matches(stack)) { + return MethodResult.of(AppEngApi.getObjectFromStack(Pair.of(potentialStack.getLongValue(), itemKey), getCraftingService())); + } + } + return MethodResult.of(null, "Could not find item"); } - @LuaFunction(mainThread = true) - public final double getAvgPowerUsage() { - return node.getGrid().getEnergyService().getAvgPowerUsage(); + @Override + public MethodResult getFluid(IArguments arguments) throws LuaException { + return null; } - @LuaFunction(mainThread = true) - public final double getAvgPowerInjection() { - return node.getGrid().getEnergyService().getAvgPowerInjection(); + @Override + public final MethodResult listItems() { + if (!canRun()) + return MethodResult.of(null, "System not connected or offline"); + + return MethodResult.of(AppEngApi.listStacks(AppEngApi.getMonitor(node), getCraftingService(), 0)); } + @Override + public final MethodResult listCraftableItems() { + if (!canRun()) + return MethodResult.of(null, "System not connected or offline"); - @LuaFunction(mainThread = true) - public final double getMaxEnergyStorage() { - return node.getGrid().getEnergyService().getMaxStoredPower(); + return MethodResult.of(AppEngApi.listStacks(AppEngApi.getMonitor(node), getCraftingService(), 2)); } - @LuaFunction(mainThread = true) - public final boolean isItemCrafting(IArguments arguments) throws LuaException { - MEStorage monitor = AppEngApi.getMonitor(node); - ICraftingService grid = node.getGrid().getService(ICraftingService.class); + @Override + public final MethodResult listFluids() { + if (!canRun()) + return MethodResult.of(null, "System not connected or offline"); - ItemStack itemStack = ItemUtil.getItemStack(arguments.getTable(0), monitor); - return AppEngApi.isItemCrafting(monitor, grid, itemStack); + return MethodResult.of(AppEngApi.listFluids(AppEngApi.getMonitor(node), getCraftingService(), 0)); + } + + @Override + public final MethodResult listCraftableFluids() { + if (!canRun()) + return MethodResult.of(null, "System not connected or offline"); + + return MethodResult.of(AppEngApi.listFluids(AppEngApi.getMonitor(node), getCraftingService(), 2)); } @LuaFunction(mainThread = true) - public final boolean isItemCraftable(IArguments arguments) throws LuaException { - MEStorage monitor = AppEngApi.getMonitor(node); - ICraftingService crafting = node.getGrid().getService(ICraftingService.class); - Pair stack = AppEngApi.findAEStackFromItemStack(monitor, crafting, ItemUtil.getItemStack(arguments.getTable(0), monitor)); + public final MethodResult getCraftingCPUs() throws LuaException { + if (!canRun()) + return MethodResult.of(null, "System not connected or offline"); - if (stack == null) { - // If the item stack does not exist, it cannot be craftable. - return false; + ICraftingService grid = node.getGrid().getService(ICraftingService.class); + List list = new ArrayList<>(); + Iterator iterator = grid.getCpus().iterator(); + if (!iterator.hasNext()) + return null; + int i = 1; + while (iterator.hasNext()) { + list.add(i++, AppEngApi.getObjectFromCPU(iterator.next())); } - return getCraftingService().isCraftable(stack.getRight()); + return MethodResult.of(list); } - @LuaFunction(mainThread = true) - public final long exportItem(@NotNull IArguments arguments) throws LuaException { + @Override + public final MethodResult importItem(IArguments arguments) throws LuaException { + if (!canRun()) + return MethodResult.of(0, "System not connected or offline"); IItemHandler inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); - return exportToChest(arguments, inventory); + return importToME(arguments, inventory); } - @LuaFunction(mainThread = true) - public final long exportItemToPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { - IItemHandler inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); + @Override + public final MethodResult exportItem(@NotNull IArguments arguments) throws LuaException { + if (!canRun()) + return MethodResult.of(0, "System not connected or offline"); + IItemHandler inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); return exportToChest(arguments, inventory); } - @LuaFunction(mainThread = true) - public final int importItem(IArguments arguments) throws LuaException { - IItemHandler inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); + @Override + public final MethodResult importItemFromPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { + if (!canRun()) + return MethodResult.of(0, "System not connected or offline"); + + IItemHandler inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); return importToME(arguments, inventory); } - @LuaFunction(mainThread = true) - public final int importItemFromPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { + @Override + public final MethodResult exportItemToPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { + if (!canRun()) + return MethodResult.of(0, "System not connected or offline"); IItemHandler inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); - return importToME(arguments, inventory); + return exportToChest(arguments, inventory); } - @LuaFunction(mainThread = true) - public final MethodResult getItem(IArguments arguments) throws LuaException { - MEStorage monitor = AppEngApi.getMonitor(node); - ItemStack stack = ItemUtil.getItemStack(arguments.getTable(0), monitor); - if (stack.isEmpty()) return MethodResult.of(null, "Cannot determinate item for search"); - for (Object2LongMap.Entry potentialStack : monitor.getAvailableStacks()) { - if (potentialStack.getKey() instanceof AEItemKey itemKey) { - if (itemKey.matches(stack)) - return MethodResult.of(AppEngApi.getObjectFromStack(new Pair<>(potentialStack.getLongValue(), itemKey), getCraftingService())); - } - } - return MethodResult.of((Object) null); + @Override + public MethodResult getPattern(IArguments arguments) throws LuaException { + return null; } - @LuaFunction(mainThread = true) - public final Object[] listItems() { - return new Object[]{AppEngApi.listStacks(AppEngApi.getMonitor(node), getCraftingService(), 0)}; + @Override + public MethodResult getPatterns() { + return null; } - @LuaFunction(mainThread = true) - public final Object[] listCraftableItems() { - return new Object[]{AppEngApi.listStacks(AppEngApi.getMonitor(node), getCraftingService(), 2)}; + @Override + public final MethodResult getEnergyUsage() { + if (!canRun()) + return MethodResult.of(0, "System not connected or offline"); + return MethodResult.of(node.getGrid().getEnergyService().getIdlePowerUsage()); } - @LuaFunction(mainThread = true) - public final Object[] listFluid() { - return new Object[]{AppEngApi.listFluids(AppEngApi.getMonitor(node), getCraftingService(), 0)}; + @Override + public final MethodResult getStoredEnergy() { + if (!canRun()) + return MethodResult.of(0, "System not connected or offline"); + return MethodResult.of(node.getGrid().getEnergyService().getStoredPower()); } @LuaFunction(mainThread = true) - public final Object[] listCraftableFluid() { - return new Object[]{AppEngApi.listFluids(AppEngApi.getMonitor(node), getCraftingService(), 2)}; + public final MethodResult getAvgPowerUsage() { + if (!canRun()) + return MethodResult.of(0, "System not connected or offline"); + return MethodResult.of(node.getGrid().getEnergyService().getAvgPowerUsage()); } @LuaFunction(mainThread = true) - public final Object[] getCraftingCPUs() throws LuaException { + public final MethodResult getAvgPowerInjection() { + if (!canRun()) + return MethodResult.of(0, "System not connected or offline"); + return MethodResult.of(node.getGrid().getEnergyService().getAvgPowerInjection()); + } + + @Override + public final MethodResult getEnergyCapacity() { + if (!canRun()) + return MethodResult.of(0, "System not connected or offline"); + return MethodResult.of(node.getGrid().getEnergyService().getMaxStoredPower()); + } + + @Override + public MethodResult getMaxItemExternalStorage() { + return null; + } + + @Override + public MethodResult getMaxFluidExternalStorage() { + return null; + } + + @Override + public MethodResult getMaxItemDiskStorage() { + return null; + } + + @Override + public MethodResult getMaxFluidDiskStorage() { + return null; + } + + @Override + public final MethodResult craftItem(IComputerAccess computer, IArguments arguments) throws LuaException { + if (!canRun()) + return MethodResult.of(false, "System not connected or offline"); + + MEStorage monitor = AppEngApi.getMonitor(node); + ItemStack itemToCraft = ItemUtil.getItemStack(arguments.getTable(0), monitor); + if (itemToCraft.isEmpty()) + return MethodResult.of(false, "Item " + itemToCraft + " does not exists"); + CraftJob job = new CraftJob(owner.getLevel(), computer, node, itemToCraft, tile, tile); + tile.addJob(job); + ServerWorker.add(job::startCrafting); + return MethodResult.of(job); + } + + @Override + public MethodResult craftFluid(IComputerAccess computer, IArguments arguments) throws LuaException { + return null; + } + + @Override + public final MethodResult isItemCraftable(IArguments arguments) throws LuaException { + if (!canRun()) + return MethodResult.of(false, "System not connected or offline"); + MEStorage monitor = AppEngApi.getMonitor(node); + ICraftingService crafting = node.getGrid().getService(ICraftingService.class); + Pair stack = AppEngApi.findAEStackFromItemStack(monitor, crafting, ItemUtil.getItemStack(arguments.getTable(0), monitor)); + + if (stack == null) + return MethodResult.of(false, "Could not find item"); + + return MethodResult.of(getCraftingService().isCraftable(stack.getRight())); + } + + @Override + public final MethodResult isItemCrafting(IArguments arguments) throws LuaException { + if (!canRun()) + return MethodResult.of(0, "System not connected or offline"); + MEStorage monitor = AppEngApi.getMonitor(node); ICraftingService grid = node.getGrid().getService(ICraftingService.class); - if (grid == null) throw new LuaException("Not connected"); - Map map = new HashMap<>(); - Iterator iterator = grid.getCpus().iterator(); - if (!iterator.hasNext()) return null; - int i = 1; - while (iterator.hasNext()) { - Object o = AppEngApi.getObjectFromCPU(iterator.next()); - map.put(i++, o); - } - return new Object[]{map}; + + ItemStack itemStack = ItemUtil.getItemStack(arguments.getTable(0), monitor); + if (itemStack.isEmpty()) + return MethodResult.of(false, "Could not find item"); + return MethodResult.of(AppEngApi.isItemCrafting(monitor, grid, itemStack)); } + } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java index 80f6a69ad..e2960343e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java @@ -7,10 +7,10 @@ import com.refinedmods.refinedstorage.api.util.Action; import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.LuaException; -import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.lua.MethodResult; import dan200.computercraft.api.peripheral.IComputerAccess; import dan200.computercraft.api.peripheral.IPeripheral; +import de.srendi.advancedperipherals.common.addons.base.IStoragePeripheral; import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner; import de.srendi.advancedperipherals.common.addons.refinedstorage.RefinedStorage; import de.srendi.advancedperipherals.common.addons.refinedstorage.RefinedStorageNode; @@ -22,17 +22,16 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.registries.ForgeRegistries; import java.util.ArrayList; import java.util.List; -import java.util.function.Supplier; -public class RsBridgePeripheral extends BasePeripheral> { +public class RsBridgePeripheral extends BasePeripheral> implements IStoragePeripheral { public static final String PERIPHERAL_TYPE = "rsBridge"; @@ -48,16 +47,8 @@ private INetwork getNetwork() { return getNode().getNetwork(); } - /** - * Used to avoid NPE exceptions when the system is offline or the bridge not connected - * - * @param defaultValue return value if block is not connected - * @param returnValue return value if block is connected - * @return defaultValue if system is not connected, returnValue if it is - */ - private Object ensureIsConnected(Object defaultValue, Supplier returnValue) { - if (!isConnected() || !getNetwork().canRun()) return defaultValue; - return returnValue.get(); + private boolean canRun() { + return getNetwork() != null || getNetwork().canRun(); } @Override @@ -65,127 +56,158 @@ public boolean isEnabled() { return APConfig.PERIPHERALS_CONFIG.enableRSBridge.get(); } - @LuaFunction(mainThread = true) - public final boolean isConnected() { - return getNetwork() != null; + @Override + public final MethodResult isConnected() { + return MethodResult.of(getNetwork() != null); } - @LuaFunction(mainThread = true) - public final Object listItems() { - return ensureIsConnected(null, () -> RefinedStorage.listItems(getNetwork())); + @Override + public MethodResult isOnline() { + if (getNetwork() == null) + return MethodResult.of(false, "Not connected"); + return MethodResult.of(getNetwork().canRun()); } - @LuaFunction(mainThread = true) - public final Object listCraftableItems() { - if (!isConnected()) - return null; + @Override + public final MethodResult listItems() { + if (!canRun()) + return MethodResult.of(null, "System not connected or offline"); + return MethodResult.of(RefinedStorage.listItems(getNetwork())); + } + + @Override + public final MethodResult listCraftableItems() { + if (!canRun()) + return MethodResult.of(null, "System not connected or offline"); List items = new ArrayList<>(); RefinedStorage.getCraftableItems(getNetwork()).forEach(item -> items.add(RefinedStorage.getObjectFromStack(item, getNetwork()))); - return items; + return MethodResult.of(items); } - @LuaFunction(mainThread = true) - public final Object listCraftableFluids() { - if (!isConnected()) - return null; + @Override + public final MethodResult listCraftableFluids() { + if (!canRun()) + return MethodResult.of(null, "System not connected or offline"); List fluids = new ArrayList<>(); RefinedStorage.getCraftableFluids(getNetwork()).forEach(fluid -> fluids.add(RefinedStorage.getObjectFromFluid(fluid, getNetwork()))); - return fluids; + return MethodResult.of(fluids); } - @LuaFunction(mainThread = true) - public final int getMaxItemDiskStorage() { - return (int) ensureIsConnected(0, () -> RefinedStorage.getMaxItemDiskStorage(getNetwork())); + @Override + public final MethodResult getMaxItemDiskStorage() { + if (!canRun()) + return MethodResult.of(0, "System not connected or offline"); + return MethodResult.of(RefinedStorage.getMaxItemDiskStorage(getNetwork())); } - @LuaFunction(mainThread = true) - public final int getMaxFluidDiskStorage() { - return (int) ensureIsConnected(0, () -> RefinedStorage.getMaxFluidDiskStorage(getNetwork())); + @Override + public final MethodResult getMaxFluidDiskStorage() { + if (!canRun()) + return MethodResult.of(0, "System not connected or offline"); + return MethodResult.of(RefinedStorage.getMaxFluidDiskStorage(getNetwork())); } - @LuaFunction(mainThread = true) - public final int getMaxItemExternalStorage() { - return (int) ensureIsConnected(0, () -> RefinedStorage.getMaxItemExternalStorage(getNetwork())); + @Override + public final MethodResult getMaxItemExternalStorage() { + if (!canRun()) + return MethodResult.of(0, "System not connected or offline"); + return MethodResult.of(RefinedStorage.getMaxItemExternalStorage(getNetwork())); } - @LuaFunction(mainThread = true) - public final int getMaxFluidExternalStorage() { - return (int) ensureIsConnected(0, () -> RefinedStorage.getMaxFluidExternalStorage(getNetwork())); + @Override + public final MethodResult getMaxFluidExternalStorage() { + if (!canRun()) + return MethodResult.of(0, "System not connected or offline"); + return MethodResult.of(RefinedStorage.getMaxFluidExternalStorage(getNetwork())); } - @LuaFunction(mainThread = true) - public final Object listFluids() { - return ensureIsConnected(null, () -> RefinedStorage.listFluids(getNetwork())); + @Override + public final MethodResult listFluids() { + if (!canRun()) + return MethodResult.of(null, "System not connected or offline"); + return MethodResult.of(RefinedStorage.listFluids(getNetwork())); } - @LuaFunction(mainThread = true) - public final int getEnergyUsage() { - return (int) ensureIsConnected(0, () -> getNetwork().getEnergyUsage()); + @Override + public final MethodResult getEnergyUsage() { + if (!canRun()) + return MethodResult.of(0, "System not connected or offline"); + return MethodResult.of(getNetwork().getEnergyUsage()); } - @LuaFunction(mainThread = true) - public final int getMaxEnergyStorage() { - return (int) ensureIsConnected(0, () -> getNetwork().getEnergyStorage().getMaxEnergyStored()); + @Override + public final MethodResult getEnergyCapacity() { + if (!canRun()) + return MethodResult.of(0, "System not connected or offline"); + return MethodResult.of(getNetwork().getEnergyStorage().getMaxEnergyStored()); } - @LuaFunction(mainThread = true) - public final int getEnergyStorage() { - return (int) ensureIsConnected(0, () -> getNetwork().getEnergyStorage().getEnergyStored()); + @Override + public final MethodResult getStoredEnergy() { + if (!canRun()) + return MethodResult.of(0, "System not connected or offline"); + return MethodResult.of(getNetwork().getEnergyStorage().getEnergyStored()); } - @LuaFunction(mainThread = true) + @Override public final MethodResult getPattern(IArguments arguments) { - return (MethodResult) ensureIsConnected(null, () -> { - try { - return RefinedStorage.getObjectFromPattern(getNetwork().getCraftingManager().getPattern(ItemUtil.getItemStackRS(arguments.getTable(0), RefinedStorage.getItems(getNetwork()))), getNetwork()); - } catch (LuaException e) { - return MethodResult.of(null, "unknown: " + e.getMessage()); - } - }); + if (!canRun()) + return MethodResult.of(null, "System not connected or offline"); + try { + return MethodResult.of(RefinedStorage.getObjectFromPattern(getNetwork().getCraftingManager().getPattern(ItemUtil.getItemStackRS(arguments.getTable(0), RefinedStorage.getItems(getNetwork()))), getNetwork())); + } catch (LuaException e) { + return MethodResult.of(null, "Could not get pattern " + e.getMessage()); + } + } + + @Override + public MethodResult getPatterns() { + return null; } - @LuaFunction(mainThread = true) - public final int exportItem(IArguments arguments) throws LuaException { - if (!isConnected()) - return 0; + @Override + public final MethodResult exportItem(IArguments arguments) throws LuaException { + if (!canRun()) + return MethodResult.of(0, "System not connected or offline"); ItemStack stack = ItemUtil.getItemStackRS(arguments.getTable(0), RefinedStorage.getItems(getNetwork())); Direction direction = validateSide(arguments.getString(1)); BlockEntity targetEntity = owner.tileEntity.getLevel().getBlockEntity(owner.tileEntity.getBlockPos().relative(direction)); - IItemHandler inventory = targetEntity != null ? targetEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, direction.getOpposite()).resolve().orElse(null) : null; + IItemHandler inventory = targetEntity != null ? targetEntity.getCapability(ForgeCapabilities.ITEM_HANDLER, direction.getOpposite()).resolve().orElse(null) : null; if (inventory == null) - throw new LuaException("No valid inventory at " + arguments.getString(1)); + return MethodResult.of(0, "No valid inventory at " + arguments.getString(1)); ItemStack extracted = getNetwork().extractItem(stack, stack.getCount(), 1, Action.SIMULATE); if (extracted.isEmpty()) - return 0; + return MethodResult.of(0); int transferableAmount = extracted.getCount(); ItemStack remaining = ItemHandlerHelper.insertItemStacked(inventory, extracted, true); - if (!remaining.isEmpty()) transferableAmount -= remaining.getCount(); + if (!remaining.isEmpty()) + transferableAmount -= remaining.getCount(); extracted = getNetwork().extractItem(stack, transferableAmount, 1, Action.PERFORM); remaining = ItemHandlerHelper.insertItemStacked(inventory, extracted, false); - if (!remaining.isEmpty()) { + if (!remaining.isEmpty()) getNetwork().insertItem(remaining, remaining.getCount(), Action.PERFORM); - } - return transferableAmount; + return MethodResult.of(transferableAmount); } - @LuaFunction(mainThread = true) - public final int importItem(IArguments arguments) throws LuaException { - if (!isConnected()) - return 0; + @Override + public final MethodResult importItem(IArguments arguments) throws LuaException { + if (!canRun()) + return MethodResult.of(0, "System not connected or offline"); + ItemStack stack = ItemUtil.getItemStackRS(arguments.getTable(0), RefinedStorage.getItems(getNetwork())); Direction direction = validateSide(arguments.getString(1)); BlockEntity targetEntity = owner.tileEntity.getLevel().getBlockEntity(owner.tileEntity.getBlockPos().relative(direction)); - IItemHandler inventory = targetEntity != null ? targetEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, direction.getOpposite()).resolve().orElse(null) : null; + IItemHandler inventory = targetEntity != null ? targetEntity.getCapability(ForgeCapabilities.ITEM_HANDLER, direction.getOpposite()).resolve().orElse(null) : null; if (inventory == null) - throw new LuaException("No valid inventory at " + arguments.getString(1)); + return MethodResult.of(0, "No valid inventory at " + arguments.getString(1)); int amount = stack.getCount(); int transferableAmount = 0; @@ -205,27 +227,27 @@ public final int importItem(IArguments arguments) throws LuaException { } } } - return transferableAmount; + return MethodResult.of(transferableAmount); } - @LuaFunction(mainThread = true) - public final int exportItemToPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { - if (!isConnected()) - return 0; + @Override + public final MethodResult exportItemToPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { + if (!canRun()) + return MethodResult.of(0, "System not connected or offline"); + ItemStack stack = ItemUtil.getItemStackRS(arguments.getTable(0), RefinedStorage.getItems(getNetwork())); IPeripheral chest = computer.getAvailablePeripheral(arguments.getString(1)); if (chest == null) - throw new LuaException("No valid inventory block for " + arguments.getString(1)); + return MethodResult.of(0, arguments.getString(1) + " does not exists"); BlockEntity targetEntity = (BlockEntity) chest.getTarget(); - IItemHandler inventory = targetEntity != null ? targetEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).resolve().orElse(null) : null; + IItemHandler inventory = targetEntity != null ? targetEntity.getCapability(ForgeCapabilities.ITEM_HANDLER).resolve().orElse(null) : null; if (inventory == null) - throw new LuaException("No valid inventory for " + arguments.getString(1)); + return MethodResult.of(0, "No valid inventory at " + arguments.getString(1)); ItemStack extracted = getNetwork().extractItem(stack, stack.getCount(), 1, Action.SIMULATE); if (extracted.isEmpty()) - return 0; - //throw new LuaException("Item " + item + " does not exists in the RS system or the system is offline"); + return MethodResult.of(0, "Item " + stack.getItem() + " does not exists in the RS system"); int transferableAmount = extracted.getCount(); @@ -239,23 +261,24 @@ public final int exportItemToPeripheral(IComputerAccess computer, IArguments arg if (!remaining.isEmpty()) getNetwork().insertItem(remaining, remaining.getCount(), Action.PERFORM); - return transferableAmount; + return MethodResult.of(transferableAmount); } - @LuaFunction(mainThread = true) - public final int importItemFromPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { - if (!isConnected()) - return 0; + @Override + public final MethodResult importItemFromPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { + if (!canRun()) + return MethodResult.of(0, "System not connected or offline"); + ItemStack stack = ItemUtil.getItemStackRS(arguments.getTable(0), RefinedStorage.getItems(getNetwork())); IPeripheral chest = computer.getAvailablePeripheral(arguments.getString(1)); int count = stack.getCount(); if (chest == null) - throw new LuaException("No inventory block for " + arguments.getString(1)); + return MethodResult.of(0, arguments.getString(1) + " does not exists"); BlockEntity targetEntity = (BlockEntity) chest.getTarget(); - IItemHandler inventory = targetEntity != null ? targetEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).resolve().orElse(null) : null; + IItemHandler inventory = targetEntity != null ? targetEntity.getCapability(ForgeCapabilities.ITEM_HANDLER).resolve().orElse(null) : null; if (inventory == null) - throw new LuaException("No valid inventory for " + arguments.getString(1)); + return MethodResult.of(0, "No valid inventory for " + arguments.getString(1)); int amount = count; @@ -276,63 +299,84 @@ public final int importItemFromPeripheral(IComputerAccess computer, IArguments a } } } - return transferableAmount; + return MethodResult.of(transferableAmount); } - @LuaFunction(mainThread = true) + @Override public final MethodResult getItem(IArguments arguments) { - return (MethodResult) ensureIsConnected(null, () -> { - try { - return RefinedStorage.getItem(getNetwork(), ItemUtil.getItemStackRS(arguments.getTable(0), RefinedStorage.getItems(getNetwork()))); - } catch (LuaException e) { - return MethodResult.of(null, "unknown: " + e.getMessage()); - } - }); + if (!canRun()) + return MethodResult.of(null, "System not connected or offline"); + try { + return MethodResult.of(RefinedStorage.getItem(getNetwork(), ItemUtil.getItemStackRS(arguments.getTable(0), RefinedStorage.getItems(getNetwork())))); + } catch (LuaException e) { + return MethodResult.of(null, "Could not get item: " + e.getMessage()); + } + + } + + @Override + public MethodResult getFluid(IArguments arguments) { + if (!canRun()) + return MethodResult.of(null, "System not connected or offline"); + try { + return MethodResult.of(RefinedStorage.getItem(getNetwork(), ItemUtil.getItemStackRS(arguments.getTable(0), RefinedStorage.getItems(getNetwork())))); + } catch (LuaException e) { + return MethodResult.of(null, "Could not get item: " + e.getMessage()); + } } - @LuaFunction(mainThread = true) - public final boolean craftItem(IArguments arguments) throws LuaException { - if (!isConnected()) - return false; + @Override + public final MethodResult craftItem(IComputerAccess computer, IArguments arguments) throws LuaException { + if (!canRun()) + return MethodResult.of(false, "System not connected or offline"); + ItemStack stack = ItemUtil.getItemStackRS(arguments.getTable(0), RefinedStorage.getItems(getNetwork())); if (stack == null) - throw new LuaException("The item " + arguments.getTable(0).get("name") + "is not craftable"); + return MethodResult.of(false, "The item " + arguments.getTable(0).get("name") + "is not craftable"); ICalculationResult result = getNetwork().getCraftingManager().create(stack, stack.getCount()); CalculationResultType type = result.getType(); if (result.getType() == CalculationResultType.OK) getNetwork().getCraftingManager().start(result.getTask()); - return type == CalculationResultType.OK; + return MethodResult.of(type == CalculationResultType.OK); } - @LuaFunction(mainThread = true) - public final boolean craftFluid(String fluid, int count) { - if (!isConnected()) - return false; - ICalculationResult result = getNetwork().getCraftingManager().create(new FluidStack(ForgeRegistries.FLUIDS.getValue(new ResourceLocation(fluid)), 0), count); + @Override + public final MethodResult craftFluid(IComputerAccess computer, IArguments arguments) throws LuaException { + if (!canRun()) + return MethodResult.of(false, "System not connected or offline"); + + ICalculationResult result = getNetwork().getCraftingManager().create(new FluidStack(ForgeRegistries.FLUIDS.getValue(new ResourceLocation(arguments.getTable(0).toString())), 0), (int) arguments.getTable(0).get("count")); CalculationResultType type = result.getType(); if (result.getType() == CalculationResultType.OK) getNetwork().getCraftingManager().start(result.getTask()); - return type == CalculationResultType.OK; + return MethodResult.of(type == CalculationResultType.OK); } - @LuaFunction(mainThread = true) - public final boolean isItemCrafting(String item) { - if (!isConnected()) - return false; - ItemStack stack = new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation(item))); + @Override + public final MethodResult isItemCrafting(IArguments arguments) throws LuaException { + if (!canRun()) + return MethodResult.of(false, "System not connected or offline"); + + ItemStack stack = new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation((String) arguments.getTable(0).get("name")))); + if(stack.isEmpty()) + return MethodResult.of(false, "Could not find item"); + for (ICraftingTask task : getNetwork().getCraftingManager().getTasks()) { ItemStack taskStack = task.getRequested().getItem(); if (taskStack.sameItem(stack)) - return true; + return MethodResult.of(true); } - return false; + return MethodResult.of(false); } - @LuaFunction(mainThread = true) - public final boolean isItemCraftable(IArguments arguments) throws LuaException { - if (!isConnected()) - return false; + @Override + public final MethodResult isItemCraftable(IArguments arguments) throws LuaException { + if (!canRun()) + return MethodResult.of(false, "System not connected or offline"); + ItemStack stack = ItemUtil.getItemStackRS(arguments.getTable(0), RefinedStorage.getItems(getNetwork())); - return RefinedStorage.isItemCraftable(getNetwork(), stack); + if(stack.isEmpty()) + return MethodResult.of(false, "Could not find item"); + return MethodResult.of(RefinedStorage.isItemCraftable(getNetwork(), stack)); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/MeBridgeEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/MeBridgeEntity.java index 4ae51bbe1..529166ddb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/MeBridgeEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/MeBridgeEntity.java @@ -1,10 +1,6 @@ package de.srendi.advancedperipherals.common.blocks.blockentities; -import appeng.api.networking.GridFlags; -import appeng.api.networking.GridHelper; -import appeng.api.networking.IGridNode; -import appeng.api.networking.IInWorldGridNodeHost; -import appeng.api.networking.IManagedGridNode; +import appeng.api.networking.*; import appeng.api.networking.crafting.ICraftingSimulationRequester; import appeng.api.networking.security.IActionHost; import appeng.api.networking.security.IActionSource; @@ -66,9 +62,9 @@ public void handleTick(Level level, BlockState state, Bl initialized = true; AdvancedPeripherals.debug("DEBUG2 " + mainNode.isReady(), org.apache.logging.log4j.Level.ERROR); } - for (CraftJob job : jobs) { + for (CraftJob job : jobs) job.maybeCraft(); - } + jobs.removeIf(CraftJob::isCraftingStarted); } } From c52dac595dacf2b610931621b36596511150b036 Mon Sep 17 00:00:00 2001 From: Srendi Date: Wed, 22 Feb 2023 10:07:31 +0100 Subject: [PATCH 011/228] Some distance detector stuff --- .../DistanceDetectorPeripheral.java | 22 ++++++++++++++++--- .../common/commands/APCommands.java | 4 +++- .../container/InventoryManagerContainer.java | 4 ++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java index ebe8aae35..9c88d7c3b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java @@ -6,6 +6,9 @@ import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; import net.minecraft.core.Direction; import net.minecraft.world.level.ClipContext; +import net.minecraft.world.level.block.SlabBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.SlabType; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; @@ -62,12 +65,25 @@ public final double getHeight() { @LuaFunction(mainThread = true) public final double getDistance() { //Just testing, will be the direction of the block later - Direction direction = Direction.UP; + Direction direction = getPeripheralOwner().getOrientation().front(); Vec3 from = Vec3.atCenterOf(getPos()).add(direction.getNormal().getX() * 0.501, direction.getNormal().getY() * 0.501, direction.getNormal().getZ() * 0.501); - Vec3 to = from.add(direction.getNormal().getX() * 16, direction.getNormal().getY() * 16, direction.getNormal().getZ() * 16); + Vec3 to = from.add(direction.getNormal().getX() * 256, direction.getNormal().getY() * 256, direction.getNormal().getZ() * 256); BlockHitResult result = getLevel().clip(new ClipContext(from, to, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, null)); - return result.getType() != HitResult.Type.MISS ? getPos().distManhattan(result.getBlockPos()) - 1 : -1; + float distance = 0; + BlockState resultBlock; + if (result.getType() != HitResult.Type.MISS) { + resultBlock = getLevel().getBlockState(result.getBlockPos()); + distance = getPos().distManhattan(result.getBlockPos()); + + if(resultBlock.getBlock() instanceof SlabBlock && direction.getAxis() == Direction.Axis.Y) { + if(resultBlock.getValue(SlabBlock.TYPE) == SlabType.TOP && direction == Direction.UP) + distance = distance + 0.5f; + if(resultBlock.getValue(SlabBlock.TYPE) == SlabType.BOTTOM && direction == Direction.DOWN) + distance = distance - 0.5f; + } + } + return distance - 1; } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java b/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java index cd606f38e..ff11c0e53 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java +++ b/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java @@ -20,7 +20,9 @@ public class APCommands { @SubscribeEvent public static void register(RegisterCommandsEvent event) { - event.getDispatcher().register(Commands.literal("advancedperipherals").then(Commands.literal("getHashItem").executes(context -> getHashItem(context.getSource())))); + event.getDispatcher().register(Commands.literal("advancedperipherals") + .then(Commands.literal("getHashItem") + .executes(context -> getHashItem(context.getSource())))); } private static int getHashItem(CommandSourceStack source) throws CommandSyntaxException { diff --git a/src/main/java/de/srendi/advancedperipherals/common/container/InventoryManagerContainer.java b/src/main/java/de/srendi/advancedperipherals/common/container/InventoryManagerContainer.java index 7fb9b9537..b4116aa2c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/container/InventoryManagerContainer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/container/InventoryManagerContainer.java @@ -11,7 +11,7 @@ import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; -import net.minecraftforge.items.CapabilityItemHandler; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import org.jetbrains.annotations.NotNull; public class InventoryManagerContainer extends BaseContainer { @@ -20,7 +20,7 @@ public InventoryManagerContainer(int id, Inventory inventory, BlockPos pos, Leve super(APContainerTypes.INVENTORY_MANAGER_CONTAINER.get(), id, inventory, pos, level); layoutPlayerInventorySlots(7, 84); if (tileEntity != null) { - tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).ifPresent(handler -> { + tileEntity.getCapability(ForgeCapabilities.ITEM_HANDLER).ifPresent(handler -> { addSlot(new SlotInputHandler(handler, 0, 79, 29, new SlotCondition().setNeededItem(APItems.MEMORY_CARD.get()))); //Input }); } From 43ddbcb1ba6bf2a3fcf6e72028f0b4c87acc73c7 Mon Sep 17 00:00:00 2001 From: srendi Date: Thu, 23 Feb 2023 15:12:30 +0100 Subject: [PATCH 012/228] Some distance detection work, added the ability to also scan for entities --- .../AdvancedPeripherals.java | 1 - .../DistanceDetectorPeripheral.java | 27 +++++--- .../blockentities/EnergyDetectorEntity.java | 1 - .../blockentities/FluidDetectorEntity.java | 1 - .../blockentities/GasDetectorEntity.java | 1 - .../common/items/ARGogglesItem.java | 0 .../common/util/HitResultUtil.java | 69 +++++++++++++++++++ 7 files changed, 86 insertions(+), 14 deletions(-) delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/items/ARGogglesItem.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java diff --git a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java index c48c5aec9..4a487e1e6 100644 --- a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java +++ b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java @@ -4,7 +4,6 @@ import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.network.PacketHandler; import de.srendi.advancedperipherals.common.setup.APRegistration; -import de.srendi.advancedperipherals.common.village.VillageStructures; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.IEventBus; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java index 9c88d7c3b..6cd7243e5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java @@ -3,13 +3,15 @@ import dan200.computercraft.api.lua.LuaFunction; import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner; import de.srendi.advancedperipherals.common.blocks.blockentities.DistanceDetectorEntity; +import de.srendi.advancedperipherals.common.util.HitResultUtil; import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; import net.minecraft.core.Direction; -import net.minecraft.world.level.ClipContext; +import net.minecraft.core.Vec3i; import net.minecraft.world.level.block.SlabBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.SlabType; import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; @@ -68,19 +70,24 @@ public final double getDistance() { Direction direction = getPeripheralOwner().getOrientation().front(); Vec3 from = Vec3.atCenterOf(getPos()).add(direction.getNormal().getX() * 0.501, direction.getNormal().getY() * 0.501, direction.getNormal().getZ() * 0.501); Vec3 to = from.add(direction.getNormal().getX() * 256, direction.getNormal().getY() * 256, direction.getNormal().getZ() * 256); - BlockHitResult result = getLevel().clip(new ClipContext(from, to, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, null)); + HitResult result = HitResultUtil.getHitResult(to, from, getLevel()); float distance = 0; BlockState resultBlock; if (result.getType() != HitResult.Type.MISS) { - resultBlock = getLevel().getBlockState(result.getBlockPos()); - distance = getPos().distManhattan(result.getBlockPos()); - - if(resultBlock.getBlock() instanceof SlabBlock && direction.getAxis() == Direction.Axis.Y) { - if(resultBlock.getValue(SlabBlock.TYPE) == SlabType.TOP && direction == Direction.UP) - distance = distance + 0.5f; - if(resultBlock.getValue(SlabBlock.TYPE) == SlabType.BOTTOM && direction == Direction.DOWN) - distance = distance - 0.5f; + if (result instanceof BlockHitResult blockHitResult) { + resultBlock = getLevel().getBlockState(blockHitResult.getBlockPos()); + distance = getPos().distManhattan(blockHitResult.getBlockPos()); + + if (resultBlock.getBlock() instanceof SlabBlock && direction.getAxis() == Direction.Axis.Y) { + if (resultBlock.getValue(SlabBlock.TYPE) == SlabType.TOP && direction == Direction.UP) + distance = distance + 0.5f; + if (resultBlock.getValue(SlabBlock.TYPE) == SlabType.BOTTOM && direction == Direction.DOWN) + distance = distance - 0.5f; + } + } + if (result instanceof EntityHitResult entityHitResult) { + distance = getPos().distManhattan(new Vec3i(entityHitResult.getLocation().x, entityHitResult.getLocation().y, entityHitResult.getLocation().z)); } } return distance - 1; diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnergyDetectorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnergyDetectorEntity.java index 6864852c0..c331d6d38 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnergyDetectorEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnergyDetectorEntity.java @@ -1,7 +1,6 @@ package de.srendi.advancedperipherals.common.blocks.blockentities; import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.EnergyDetectorPeripheral; -import de.srendi.advancedperipherals.common.blocks.base.APBlockEntityBlock; import de.srendi.advancedperipherals.common.blocks.base.BaseBlock; import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/FluidDetectorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/FluidDetectorEntity.java index 06cd92f63..3a808db82 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/FluidDetectorEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/FluidDetectorEntity.java @@ -1,7 +1,6 @@ package de.srendi.advancedperipherals.common.blocks.blockentities; import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.FluidDetectorPeripheral; -import de.srendi.advancedperipherals.common.blocks.base.APBlockEntityBlock; import de.srendi.advancedperipherals.common.blocks.base.BaseBlock; import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/GasDetectorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/GasDetectorEntity.java index 95ed1ba51..23f7dda1c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/GasDetectorEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/GasDetectorEntity.java @@ -2,7 +2,6 @@ import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.GasDetectorPeripheral; import de.srendi.advancedperipherals.common.addons.mekanism.MekanismCapabilities; -import de.srendi.advancedperipherals.common.blocks.base.APBlockEntityBlock; import de.srendi.advancedperipherals.common.blocks.base.BaseBlock; import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/ARGogglesItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/ARGogglesItem.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java new file mode 100644 index 000000000..60c147a2f --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java @@ -0,0 +1,69 @@ +package de.srendi.advancedperipherals.common.util; + +import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.DistanceDetectorPeripheral; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.ClipContext; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.*; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public class HitResultUtil { + + @NotNull + public static HitResult getHitResult(Vec3 to, Vec3 from, Level level) { + BlockHitResult blockResult = getBlockHitResult(to, from, level); + + if(blockResult.getType() != HitResult.Type.MISS) + return blockResult; + + return getEntityHitResult(to, from, level); + } + + /** + * This method is used to get the hit result of an entity from the start position of a block + * This could be used to find an entity from the eyes position of another entity but since + * this method uses one AABB made out of the two coordinates, this would also find any entities + * which are not located in the ray you might want. {@link DistanceDetectorPeripheral#getDistance()} + * + * + * @param to the target position or max distance + * @param from the source position like a block + * @param level the world + * @return the entity hit result. An empty HitResult with {@link HitResult.Type#MISS} as type if nothing found + */ + @NotNull + public static EntityHitResult getEntityHitResult(Vec3 to, Vec3 from, Level level) { + AABB checkingBox = new AABB(to, from); + + List entities = level.getEntities((Entity) null, checkingBox, (entity) -> true); + + if(entities.isEmpty()) + return new EmptyEntityHitResult(); + + return new EntityHitResult(entities.get(0)); + } + + @NotNull + public static BlockHitResult getBlockHitResult(Vec3 to, Vec3 from, Level level) { + BlockHitResult result = level.clip(new ClipContext(from, to, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, null)); + return result; + } + + public static class EmptyEntityHitResult extends EntityHitResult { + + /** + * The super constructor is a NotNull argument but since this result is empty, we'll just return null + */ + public EmptyEntityHitResult() { + super(null); + } + + @NotNull + @Override + public Type getType() { + return Type.MISS; + } + } +} From 8c148c3411ffbfdb0201a5d632a58dbc1d827abb Mon Sep 17 00:00:00 2001 From: Srendi Date: Sun, 26 Feb 2023 18:49:15 +0100 Subject: [PATCH 013/228] Laser pew pew --- gradle.properties | 2 +- .../client/ClientRegistry.java | 10 +- .../renderer/DistanceDetectorRenderer.java | 110 ++++++++++++++++++ .../owner/BlockEntityPeripheralOwner.java | 2 +- .../DistanceDetectorPeripheral.java | 51 ++++++-- .../blocks/base/PeripheralBlockEntity.java | 5 + .../configuration/PeripheralsConfig.java | 9 ++ .../common/util/EnumColor.java | 46 +++++--- .../common/util/HitResultUtil.java | 18 ++- 9 files changed, 218 insertions(+), 35 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java diff --git a/gradle.properties b/gradle.properties index 36ca261be..a51f6e309 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ org.gradle.logging.level=info # Minecraft related minecraft_version=1.19.3 -forge_version=44.1.16 +forge_version=44.1.17 mod_version=0.7.25b release_type=beta mappings_channel=parchment diff --git a/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java b/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java index ac6082694..d128ffc0a 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java +++ b/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java @@ -3,13 +3,16 @@ import dan200.computercraft.api.client.ComputerCraftAPIClient; import dan200.computercraft.api.client.turtle.TurtleUpgradeModeller; import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.client.renderer.DistanceDetectorRenderer; import de.srendi.advancedperipherals.common.container.InventoryManagerScreen; +import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; import de.srendi.advancedperipherals.common.setup.APContainerTypes; import de.srendi.advancedperipherals.common.setup.CCRegistration; import net.minecraft.client.gui.screens.MenuScreens; import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.client.event.EntityRenderersEvent; import net.minecraftforge.client.event.ModelEvent; import net.minecraftforge.client.event.RegisterKeyMappingsEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; @@ -47,10 +50,15 @@ public static void onClientSetup(FMLClientSetupEvent event) { } @SubscribeEvent - public static void onClientSetup(RegisterKeyMappingsEvent event) { + public static void registeringKeymappings(RegisterKeyMappingsEvent event) { KeyBindings.register(event); } + @SubscribeEvent + public static void registeringRenderers(EntityRenderersEvent.RegisterRenderers event) { + event.registerBlockEntityRenderer(APBlockEntityTypes.DISTANCE_DETECTOR.get(), DistanceDetectorRenderer::new); + } + //TODO change the icon of the curio icon /*@SubscribeEvent public static void onTextureStitching(TextureStitchEvent.Pre event) { diff --git a/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java b/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java new file mode 100644 index 000000000..fd0c8dc68 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java @@ -0,0 +1,110 @@ +package de.srendi.advancedperipherals.client.renderer; + +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import com.mojang.math.Axis; +import de.srendi.advancedperipherals.common.blocks.base.BaseBlock; +import de.srendi.advancedperipherals.common.blocks.blockentities.DistanceDetectorEntity; +import de.srendi.advancedperipherals.common.util.EnumColor; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.blockentity.BeaconRenderer; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; +import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; +import net.minecraft.client.renderer.texture.OverlayTexture; +import net.minecraft.core.Direction; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; +import net.minecraft.world.level.block.entity.BeaconBlockEntity; +import net.minecraft.world.phys.Vec3; +import org.jetbrains.annotations.NotNull; +import org.joml.Matrix3f; +import org.joml.Matrix4f; + +public class DistanceDetectorRenderer implements BlockEntityRenderer { + + public DistanceDetectorRenderer(BlockEntityRendererProvider.Context pContext) { + super(); + } + + @Override + public void render(@NotNull DistanceDetectorEntity pBlockEntity, float pPartialTick, @NotNull PoseStack pPoseStack, MultiBufferSource pBufferSource, int pPackedLight, int pPackedOverlay) { + long i = pBlockEntity.getLevel().getGameTime(); + renderBeaconBeam(pBlockEntity, pPoseStack, pBufferSource, BeaconRenderer.BEAM_LOCATION, pPartialTick, 1, i, 0, 1, EnumColor.DARK_RED.getRgb(), 0.05f, 0.09f); + renderBeaconBeam(pBlockEntity, pPoseStack, pBufferSource, BeaconRenderer.BEAM_LOCATION, pPartialTick, 1, i, 1, 1, EnumColor.DARK_RED.getRgb(), 0.05f, 0.09f); + renderBeaconBeam(pBlockEntity, pPoseStack, pBufferSource, BeaconRenderer.BEAM_LOCATION, pPartialTick, 1, i, 2, 1, EnumColor.DARK_RED.getRgb(), 0.05f, 0.09f); + } + + public boolean shouldRenderOffScreen(DistanceDetectorEntity pBlockEntity) { + return true; + } + + public int getViewDistance() { + return 256; + } + + public boolean shouldRender(DistanceDetectorEntity pBlockEntity, Vec3 pCameraPos) { + return Vec3.atCenterOf(pBlockEntity.getBlockPos()).multiply(1.0D, 0.0D, 1.0D).closerThan(pCameraPos.multiply(1.0D, 0.0D, 1.0D), (double) this.getViewDistance()); + } + + public static void renderBeaconBeam(DistanceDetectorEntity detectorEntity, PoseStack pPoseStack, MultiBufferSource pBufferSource, ResourceLocation pBeamLocation, float pPartialTick, float pTextureScale, long pGameTime, int pYOffset, int pHeight, float[] pColors, float pBeamRadius, float pGlowRadius) { + int i = pYOffset + pHeight; + Direction direction = detectorEntity.getBlockState().getValue(BaseBlock.ORIENTATION).front(); + pPoseStack.pushPose(); + pPoseStack.translate(0.5D, 0.5D, 0.5D); + float f = (float) Math.floorMod(pGameTime, 360) + pPartialTick; + float f1 = pHeight < 0 ? f : -f; + float f2 = Mth.frac(f1 * 0.2F - (float) Mth.floor(f1 * 0.1F)); + float f3 = pColors[0]; + float f4 = pColors[1]; + float f5 = pColors[2]; + pPoseStack.pushPose(); + pPoseStack.mulPose(direction.getRotation()); + pPoseStack.mulPose(Axis.YP.rotationDegrees(f * 2.25F - 45.0F)); + float f6 = 0.0F; + float f8 = 0.0F; + float f9 = -pBeamRadius; + float f10 = 0.0F; + float f11 = 0.0F; + float f12 = -pBeamRadius; + float f13 = 0.0F; + float f14 = 1.0F; + float f15 = -1.0F + f2; + float f16 = (float) pHeight * pTextureScale * (0.5F / pBeamRadius) + f15; + renderPart(pPoseStack, pBufferSource.getBuffer(RenderType.beaconBeam(pBeamLocation, false)), f3, f4, f5, 1.0F, pYOffset, i, 0.0F, pBeamRadius, pBeamRadius, 0.0F, f9, 0.0F, 0.0F, f12, 0.0F, 1.0F, f16, f15); + pPoseStack.popPose(); + pPoseStack.mulPose(direction.getRotation()); + f6 = -pGlowRadius; + float f7 = -pGlowRadius; + f8 = -pGlowRadius; + f9 = -pGlowRadius; + f13 = 0.0F; + f14 = 1.0F; + f15 = -1.0F + f2; + f16 = (float) pHeight * pTextureScale + f15; + renderPart(pPoseStack, pBufferSource.getBuffer(RenderType.beaconBeam(pBeamLocation, true)), f3, f4, f5, 0.225F, pYOffset, i, f6, f7, pGlowRadius, f8, f9, pGlowRadius, pGlowRadius, pGlowRadius, 0.0F, 1.0F, f16, f15); + pPoseStack.popPose(); + } + + private static void renderPart(PoseStack pPoseStack, VertexConsumer pConsumer, float pRed, float pGreen, float pBlue, float pAlpha, int pMinY, int pMaxY, float pX0, float pZ0, float pX1, float pZ1, float pX2, float pZ2, float pX3, float pZ3, float pMinU, float pMaxU, float pMinV, float pMaxV) { + PoseStack.Pose posestack$pose = pPoseStack.last(); + Matrix4f matrix4f = posestack$pose.pose(); + Matrix3f matrix3f = posestack$pose.normal(); + renderQuad(matrix4f, matrix3f, pConsumer, pRed, pGreen, pBlue, pAlpha, pMinY, pMaxY, pX0, pZ0, pX1, pZ1, pMinU, pMaxU, pMinV, pMaxV); + renderQuad(matrix4f, matrix3f, pConsumer, pRed, pGreen, pBlue, pAlpha, pMinY, pMaxY, pX3, pZ3, pX2, pZ2, pMinU, pMaxU, pMinV, pMaxV); + renderQuad(matrix4f, matrix3f, pConsumer, pRed, pGreen, pBlue, pAlpha, pMinY, pMaxY, pX1, pZ1, pX3, pZ3, pMinU, pMaxU, pMinV, pMaxV); + renderQuad(matrix4f, matrix3f, pConsumer, pRed, pGreen, pBlue, pAlpha, pMinY, pMaxY, pX2, pZ2, pX0, pZ0, pMinU, pMaxU, pMinV, pMaxV); + } + + private static void renderQuad(Matrix4f pPose, Matrix3f pNormal, VertexConsumer pConsumer, float pRed, float pGreen, float pBlue, float pAlpha, int pMinY, int pMaxY, float pMinX, float pMinZ, float pMaxX, float pMaxZ, float pMinU, float pMaxU, float pMinV, float pMaxV) { + addVertex(pPose, pNormal, pConsumer, pRed, pGreen, pBlue, pAlpha, pMaxY, pMinX, pMinZ, pMaxU, pMinV); + addVertex(pPose, pNormal, pConsumer, pRed, pGreen, pBlue, pAlpha, pMinY, pMinX, pMinZ, pMaxU, pMaxV); + addVertex(pPose, pNormal, pConsumer, pRed, pGreen, pBlue, pAlpha, pMinY, pMaxX, pMaxZ, pMinU, pMaxV); + addVertex(pPose, pNormal, pConsumer, pRed, pGreen, pBlue, pAlpha, pMaxY, pMaxX, pMaxZ, pMinU, pMinV); + } + + private static void addVertex(Matrix4f pPose, Matrix3f pNormal, VertexConsumer pConsumer, float pRed, float pGreen, float pBlue, float pAlpha, int pY, float pX, float pZ, float pU, float pV) { + pConsumer.vertex(pPose, pX, (float) pY, pZ).color(pRed, pGreen, pBlue, pAlpha).uv(pU, pV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(15728880).normal(pNormal, 0.0F, 1.0F, 0.0F).endVertex(); + } + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java index 0317806d4..0f0857fdb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java @@ -50,7 +50,7 @@ public BlockPos getPos() { @NotNull @Override public Direction getFacing() { - return tileEntity.getBlockState().getValue(JigsawBlock.ORIENTATION).front(); + return getOrientation().front(); } @NotNull diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java index 6cd7243e5..cca9b9963 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java @@ -3,6 +3,7 @@ import dan200.computercraft.api.lua.LuaFunction; import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner; import de.srendi.advancedperipherals.common.blocks.blockentities.DistanceDetectorEntity; +import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.util.HitResultUtil; import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; import net.minecraft.core.Direction; @@ -19,6 +20,9 @@ public class DistanceDetectorPeripheral extends BasePeripheral(tileEntity)); @@ -26,32 +30,50 @@ public DistanceDetectorPeripheral(DistanceDetectorEntity tileEntity) { @Override public boolean isEnabled() { - return true; + return APConfig.PERIPHERALS_CONFIG.enableDistanceDetector.get(); } - + @LuaFunction public final boolean setLaserVisibility(boolean laser) { - return false; + return laserVisible = laser; } + @LuaFunction public final boolean getLaserVisibility() { - return false; + return laserVisible; } + @LuaFunction public final boolean setTransparencyDetection(boolean enable) { - return false; + return ignoreTransparent = enable; } + @LuaFunction public final boolean getTransparencyDetection() { - return false; + return ignoreTransparent; + } + + @LuaFunction + public final String setDetectionMode(int mode) { + if (mode > 2) mode = 2; + if (mode < 0) mode = 0; + detectionType = DetectionType.values()[mode]; + return detectionType.toString(); } - public final boolean setAllowEntityDetection(boolean enable) { - return false; + @LuaFunction + public final boolean detectsEntities() { + return detectionType == DetectionType.ENTITIES || detectionType == DetectionType.BOTH; } - public final boolean getEntityDetection() { - return false; + @LuaFunction + public final boolean detectsBlocks() { + return detectionType == DetectionType.BLOCK || detectionType == DetectionType.BOTH; + } + + @LuaFunction + public final String getDetectionMode() { + return detectionType.toString(); } public final double setHeight(double height) { @@ -66,11 +88,10 @@ public final double getHeight() { @LuaFunction(mainThread = true) public final double getDistance() { - //Just testing, will be the direction of the block later Direction direction = getPeripheralOwner().getOrientation().front(); Vec3 from = Vec3.atCenterOf(getPos()).add(direction.getNormal().getX() * 0.501, direction.getNormal().getY() * 0.501, direction.getNormal().getZ() * 0.501); Vec3 to = from.add(direction.getNormal().getX() * 256, direction.getNormal().getY() * 256, direction.getNormal().getZ() * 256); - HitResult result = HitResultUtil.getHitResult(to, from, getLevel()); + HitResult result = detectionType == DetectionType.BOTH ? HitResultUtil.getHitResult(to, from, getLevel()) : detectionType == DetectionType.BLOCK ? HitResultUtil.getBlockHitResult(to, from, getLevel()) : HitResultUtil.getEntityHitResult(to, from, getLevel()); float distance = 0; BlockState resultBlock; @@ -93,4 +114,10 @@ public final double getDistance() { return distance - 1; } + private enum DetectionType { + BLOCK, + ENTITIES, + BOTH + } + } diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PeripheralBlockEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PeripheralBlockEntity.java index f73eb1fc7..c3b60a46c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PeripheralBlockEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PeripheralBlockEntity.java @@ -111,6 +111,11 @@ public List getConnectedComputers() { return peripheral.getConnectedComputers(); } + @Nullable + public T getPeripheral() { + return peripheral; + } + /*@Override public ITextComponent getDisplayName() { return this instanceof IInventoryBlock ? ((IInventoryBlock) this).getDisplayName() : null; diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java index 49e88e0c5..e5a713cbb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java @@ -53,6 +53,10 @@ public class PeripheralsConfig implements IAPConfig { public final ForgeConfigSpec.BooleanValue enableColonyIntegrator; //Compass turtle public final ForgeConfigSpec.BooleanValue enableCompassTurtle; + //Compass turtle + public final ForgeConfigSpec.BooleanValue enableDistanceDetector; + public final ForgeConfigSpec.DoubleValue distanceDetectorRange; + //Powered Peripherals public final ForgeConfigSpec.BooleanValue enablePoweredPeripherals; public final ForgeConfigSpec.IntValue poweredPeripheralMaxEnergyStorage; @@ -141,6 +145,11 @@ public PeripheralsConfig() { enableCompassTurtle = builder.comment("Enable the compass turtle or not.").define("enableCompassTurtle", true); + pop("Distance_Detector", builder); + + enableDistanceDetector = builder.comment("Enable the distance detector or not.").define("enableDistanceDetector", true); + distanceDetectorRange = builder.comment("Maximum range of the distance detector").defineInRange("distanceDetectorRange", 64D, 0D, Integer.MAX_VALUE); + pop("Powered_Peripherals", builder); enablePoweredPeripherals = builder.comment("Enable RF storage for peripherals, that could use it").define("enablePoweredPeripherals", false); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/EnumColor.java b/src/main/java/de/srendi/advancedperipherals/common/util/EnumColor.java index 415b45b23..9273fc561 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/EnumColor.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/EnumColor.java @@ -4,33 +4,37 @@ public enum EnumColor { - BLACK("\u00a70", "Black", "black", "&0"), - DARK_BLUE("\u00a71", "Blue", "blue", "&1"), - DARK_GREEN("\u00a72", "Green", "green", "&2"), - DARK_AQUA("\u00a73", "Cyan", "cyan", "&3"), - DARK_RED("\u00a74", "Dark Red", "dark_red", "&4"), - DARK_PURPLE("\u00a75", "Purple", "purple", "&5"), - GOLD("\u00a76", "Orange", "orange", "&6"), - GRAY("\u00a77", "Light Gray", "light_gray", "&7"), - DARK_GRAY("\u00a78", "Gray", "gray", "&8"), - BLUE("\u00a79", "Light Blue", "light_blue", "&9"), - GREEN("\u00a7a", "Lime", "lime", "&a"), - AQUA("\u00a7b", "Aqua", "aqua", "&b"), - RED("\u00a7c", "Red", "red", "&c"), - LIGHT_PURPLE("\u00a7d", "Magenta", "magenta", "&d"), - YELLOW("\u00a7e", "Yellow", "yellow", "&e"), - WHITE("\u00a7f", "White", "white", "&f"); + BLACK("\u00a70", "Black", "black", "§0", 0, new float[]{0f, 0f, 0f, 1f}), + DARK_BLUE("\u00a71", "Blue", "blue", "§1", 0xFF0000c9, new float[]{0f, 0f, 0.804f, 1f}), + DARK_GREEN("\u00a72", "Green", "green", "§2", 0xFF0c9400, new float[]{0.048f, 0.592f, 0f, 1f}), + DARK_AQUA("\u00a73", "Cyan", "cyan", "§3", 0xFF009494, new float[]{0f, 0.592f, 0.592f, 1f}), + DARK_RED("\u00a74", "Dark Red", "dark_red", "§4", 0xFF940000, new float[]{0.592f, 0f, 0f, 1f}), + DARK_PURPLE("\u00a75", "Purple", "purple", "§5", 0xFF510094, new float[]{0.324f, 0f, 0.592f, 1f}), + GOLD("\u00a76", "Orange", "orange", "§6", 0xFFb59700, new float[]{1f, 0.407f, 0f, 1f}), + GRAY("\u00a77", "Light Gray", "light_gray", "§7", 0xFF616161, new float[]{0.388f, 0.388f, 0.388f, 1f}), + DARK_GRAY("\u00a78", "Gray", "gray", "§8", 0xFF4a4a4a, new float[]{0.296f, 0.296f, 0.296f, 1f}), + BLUE("\u00a79", "Light Blue", "light_blue", "§9", 0xFF1919ff, new float[]{0.098f, 0.098f, 1f, 1f}), + GREEN("\u00a7a", "Lime", "lime", "§a", 0xFF00e02d, new float[]{0f, 0.878f, 0.176f, 1f}), + AQUA("\u00a7b", "Aqua", "aqua", "§b", 0xFF17ffe4, new float[]{0.090f, 1f, 0.894f, 1f}), + RED("\u00a7c", "Red", "red", "§c", 0xFFff1c1c, new float[]{1f, 0.109f, 0.109f, 1f}), + LIGHT_PURPLE("\u00a7d", "Magenta", "magenta", "§d", 0xFF7424ff, new float[]{0.454f, 0.141f, 1f, 1f}), + YELLOW("\u00a7e", "Yellow", "yellow", "§e", 0xFFc8ff00, new float[]{0.784f, 1f, 0f, 1f}), + WHITE("\u00a7f", "White", "white", "§f", 0xFFffffff, new float[]{1f, 1f, 1f, 1f}); private final String code; private final String name; private final String technicalName; private final String alternativeCode; + private final int hex; + private final float[] rgb; - EnumColor(String code, String name, String technicalName, String alternativeCode) { + EnumColor(String code, String name, String technicalName, String alternativeCode, int hex, float[] rgb) { this.code = code; this.name = name; this.technicalName = technicalName; this.alternativeCode = alternativeCode; + this.hex = hex; + this.rgb = rgb; } public static Component buildTextComponent(Component textComponent) { @@ -41,6 +45,10 @@ public static Component buildTextComponent(Component textComponent) { return Component.literal(text); } + public float[] getRgb() { + return rgb; + } + public String getCode() { return code; } @@ -52,4 +60,8 @@ public String getType() { public String getTechnicalName() { return technicalName; } + + public int getHex() { + return hex; + } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java index 60c147a2f..9512c9de0 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java @@ -1,6 +1,8 @@ package de.srendi.advancedperipherals.common.util; import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.DistanceDetectorPeripheral; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Vec3i; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.Level; @@ -13,12 +15,22 @@ public class HitResultUtil { @NotNull public static HitResult getHitResult(Vec3 to, Vec3 from, Level level) { + EntityHitResult entityResult = getEntityHitResult(to, from, level); BlockHitResult blockResult = getBlockHitResult(to, from, level); - if(blockResult.getType() != HitResult.Type.MISS) + if(entityResult.getType() != HitResult.Type.MISS && blockResult.getType() == HitResult.Type.MISS) + return entityResult; + + if(entityResult.getType() == HitResult.Type.MISS && blockResult.getType() != HitResult.Type.MISS) + return blockResult; + + double blockDistance = new BlockPos(from).distManhattan(blockResult.getBlockPos()); + double entityDistance = new BlockPos(from).distManhattan(new Vec3i(entityResult.getLocation().x, entityResult.getLocation().y, entityResult.getLocation().z)); + + if(blockDistance < entityDistance) return blockResult; - return getEntityHitResult(to, from, level); + return entityResult; } /** @@ -57,7 +69,7 @@ public static class EmptyEntityHitResult extends EntityHitResult { * The super constructor is a NotNull argument but since this result is empty, we'll just return null */ public EmptyEntityHitResult() { - super(null); + super(null, null); } @NotNull From 8f138e80929c78082aa6597b21ce96d71aa40d29 Mon Sep 17 00:00:00 2001 From: srendi Date: Thu, 2 Mar 2023 09:09:56 +0100 Subject: [PATCH 014/228] Remove deprecation of IInventoryBlock.java --- .../advancedperipherals/common/blocks/base/IInventoryBlock.java | 2 -- .../common/blocks/base/PeripheralBlockEntity.java | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/IInventoryBlock.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/IInventoryBlock.java index 3d118525b..5bfa6325c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/IInventoryBlock.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/IInventoryBlock.java @@ -10,10 +10,8 @@ * Used to assign a container to a TileEntity * * @param The container related to this inventory - * @deprecated Will be merged with the APBlock in 0.9 */ -@Deprecated(since = "0.7.16", forRemoval = true) public interface IInventoryBlock { Component getDisplayName(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PeripheralBlockEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PeripheralBlockEntity.java index f73eb1fc7..dda0cd4b8 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PeripheralBlockEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PeripheralBlockEntity.java @@ -35,7 +35,7 @@ import java.util.List; public abstract class PeripheralBlockEntity> extends BaseContainerBlockEntity implements WorldlyContainer, MenuProvider, IPeripheralTileEntity { - // TODO: move inventory logic to another tile entity! + private static final String PERIPHERAL_SETTINGS_KEY = "peripheralSettings"; protected CompoundTag peripheralSettings; protected NonNullList items; From a91567f5faec10310709830d6a7971975a0346dd Mon Sep 17 00:00:00 2001 From: Srendi Date: Sat, 4 Mar 2023 20:02:13 +0100 Subject: [PATCH 015/228] Update some dependencies --- gradle.properties | 6 +++--- .../client/renderer/DistanceDetectorRenderer.java | 7 +++---- .../computercraft/owner/BlockEntityPeripheralOwner.java | 1 - .../common/util/fakeplayer/FakePlayerProviderTurtle.java | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/gradle.properties b/gradle.properties index a51f6e309..308214a02 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,11 +4,11 @@ org.gradle.logging.level=info # Minecraft related minecraft_version=1.19.3 -forge_version=44.1.17 +forge_version=44.1.21 mod_version=0.7.25b release_type=beta mappings_channel=parchment -mappings_version=2022.12.18-1.19.3 +mappings_version=2023.02.26-1.19.3 jb_annotations=21.0.1 # Test dependencies @@ -19,7 +19,7 @@ kotlinx_coroutines_version=1.6.0-RC3 ttoolkit_version=0.1.3 # Mod dependencies -cc_version=1.102.0-SNAPSHOT +cc_version=1.103.1 curios_version=1.19.3-5.1.1.2 minecolonies_version=1.19.2-1.0.1060-ALPHA appliedenergistics_version=13.0.9-beta diff --git a/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java b/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java index fd0c8dc68..77222a875 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java +++ b/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java @@ -15,7 +15,6 @@ import net.minecraft.core.Direction; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; -import net.minecraft.world.level.block.entity.BeaconBlockEntity; import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.NotNull; import org.joml.Matrix3f; @@ -87,9 +86,9 @@ public static void renderBeaconBeam(DistanceDetectorEntity detectorEntity, PoseS } private static void renderPart(PoseStack pPoseStack, VertexConsumer pConsumer, float pRed, float pGreen, float pBlue, float pAlpha, int pMinY, int pMaxY, float pX0, float pZ0, float pX1, float pZ1, float pX2, float pZ2, float pX3, float pZ3, float pMinU, float pMaxU, float pMinV, float pMaxV) { - PoseStack.Pose posestack$pose = pPoseStack.last(); - Matrix4f matrix4f = posestack$pose.pose(); - Matrix3f matrix3f = posestack$pose.normal(); + PoseStack.Pose posestackPose = pPoseStack.last(); + Matrix4f matrix4f = posestackPose.pose(); + Matrix3f matrix3f = posestackPose.normal(); renderQuad(matrix4f, matrix3f, pConsumer, pRed, pGreen, pBlue, pAlpha, pMinY, pMaxY, pX0, pZ0, pX1, pZ1, pMinU, pMaxU, pMinV, pMaxV); renderQuad(matrix4f, matrix3f, pConsumer, pRed, pGreen, pBlue, pAlpha, pMinY, pMaxY, pX3, pZ3, pX2, pZ2, pMinU, pMaxU, pMinV, pMaxV); renderQuad(matrix4f, matrix3f, pConsumer, pRed, pGreen, pBlue, pAlpha, pMinY, pMaxY, pX1, pZ1, pX3, pZ3, pMinU, pMaxU, pMinV, pMaxV); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java index 0f0857fdb..ed3c89cbb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java @@ -12,7 +12,6 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.JigsawBlock; import net.minecraft.world.level.block.entity.BlockEntity; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/FakePlayerProviderTurtle.java b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/FakePlayerProviderTurtle.java index 1923bdaaf..b3488d3b7 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/FakePlayerProviderTurtle.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/FakePlayerProviderTurtle.java @@ -94,7 +94,7 @@ public static void unload(APFakePlayer player, ITurtleAccess turtle) { remaining = InventoryUtil.storeItemsFromOffset(turtleInventory, remaining, 0); if (!remaining.isEmpty()) { BlockPos position = turtle.getPosition(); - WorldUtil.dropItemStack(remaining, turtle.getLevel(), position, turtle.getDirection().getOpposite()); + WorldUtil.dropItemStack(turtle.getLevel(), position, turtle.getDirection().getOpposite(), remaining); } } From 7c2298d2ed9643fd8dd5368f77f96448cd9a005a Mon Sep 17 00:00:00 2001 From: Srendi Date: Sat, 4 Mar 2023 20:04:07 +0100 Subject: [PATCH 016/228] Run on selfhosted --- .github/workflows/gradle-snapshot.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gradle-snapshot.yml b/.github/workflows/gradle-snapshot.yml index 67be6b7f0..c12beea53 100644 --- a/.github/workflows/gradle-snapshot.yml +++ b/.github/workflows/gradle-snapshot.yml @@ -10,7 +10,7 @@ on: jobs: build: name: Build - runs-on: ubuntu-latest + runs-on: self-hosted steps: - uses: actions/checkout@v2 with: From 62f946954ea1dd60cb063162ae0622c1e839c6d6 Mon Sep 17 00:00:00 2001 From: Srendi Date: Sun, 5 Mar 2023 02:48:13 +0100 Subject: [PATCH 017/228] Some very very basic smart glasses approaches. This just adds the smart glasses as item and the computer with a terminal behind it. A custom API and a `flat.lua` file in the rom do exist too --- .../client/ClientRegistry.java | 3 + .../container/SmartGlassesContainer.java | 38 +++ .../common/items/SmartGlassesItem.java | 217 +++++++++++++++++- .../common/setup/APContainerTypes.java | 13 ++ .../common/smartglasses/SmartGlassesAPI.java | 12 + .../smartglasses/SmartGlassesComputer.java | 163 +++++++++++++ .../SmartGlassesMenuProvider.java | 51 ++++ .../computercraft/lua/rom/programs/flat.lua | 1 + 8 files changed, 494 insertions(+), 4 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesAPI.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesMenuProvider.java create mode 100644 src/main/resources/data/computercraft/lua/rom/programs/flat.lua diff --git a/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java b/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java index d128ffc0a..c5fae8259 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java +++ b/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java @@ -2,9 +2,11 @@ import dan200.computercraft.api.client.ComputerCraftAPIClient; import dan200.computercraft.api.client.turtle.TurtleUpgradeModeller; +import dan200.computercraft.client.gui.ComputerScreen; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.client.renderer.DistanceDetectorRenderer; import de.srendi.advancedperipherals.common.container.InventoryManagerScreen; +import de.srendi.advancedperipherals.common.container.SmartGlassesContainer; import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; import de.srendi.advancedperipherals.common.setup.APContainerTypes; import de.srendi.advancedperipherals.common.setup.CCRegistration; @@ -34,6 +36,7 @@ public static void registerModels(ModelEvent.RegisterAdditional event) { @SubscribeEvent public static void onClientSetup(FMLClientSetupEvent event) { MenuScreens.register(APContainerTypes.INVENTORY_MANAGER_CONTAINER.get(), InventoryManagerScreen::new); + MenuScreens.register(APContainerTypes.SMART_GLASSES_CONTAINER.get(), ComputerScreen::new); ComputerCraftAPIClient.registerTurtleUpgradeModeller(CCRegistration.CHUNKY_TURTLE.get(), TurtleUpgradeModeller.flatItem()); ComputerCraftAPIClient.registerTurtleUpgradeModeller(CCRegistration.COMPASS_TURTLE.get(), TurtleUpgradeModeller.flatItem()); diff --git a/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java b/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java new file mode 100644 index 000000000..4e05e2328 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java @@ -0,0 +1,38 @@ +package de.srendi.advancedperipherals.common.container; + +import dan200.computercraft.shared.computer.core.ComputerFamily; +import dan200.computercraft.shared.computer.core.ServerComputer; +import dan200.computercraft.shared.computer.inventory.AbstractComputerMenu; +import dan200.computercraft.shared.computer.inventory.ComputerMenuWithoutInventory; +import dan200.computercraft.shared.network.container.ComputerContainerData; +import de.srendi.advancedperipherals.common.setup.APContainerTypes; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Predicate; + +public class SmartGlassesContainer extends AbstractComputerMenu { + + public SmartGlassesContainer(int id, Predicate canUse, + ServerComputer computer + ) { + super(APContainerTypes.SMART_GLASSES_CONTAINER.get(), id, canUse, ComputerFamily.ADVANCED, computer, null); + } + public SmartGlassesContainer(int id, Predicate predicate, ServerComputer computer, ComputerContainerData data) { + super(APContainerTypes.SMART_GLASSES_CONTAINER.get(), id, predicate, ComputerFamily.ADVANCED, computer, data); + getTerminal().resize(48,48); + } + + @Override + public ItemStack quickMoveStack(@NotNull Player pPlayer, int pIndex) { + return null; + } + + @Override + public boolean stillValid(Player player) { + return true; + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java index 053d5b5a4..1871fe8cf 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java @@ -1,7 +1,29 @@ package de.srendi.advancedperipherals.common.items; +import com.google.common.base.Objects; +import dan200.computercraft.annotations.ForgeOverride; +import dan200.computercraft.api.ComputerCraftAPI; +import dan200.computercraft.api.filesystem.Mount; +import dan200.computercraft.api.media.IMedia; +import dan200.computercraft.shared.computer.core.ComputerFamily; +import dan200.computercraft.shared.computer.core.ServerContext; +import dan200.computercraft.shared.computer.items.IComputerItem; +import dan200.computercraft.shared.config.Config; +import dan200.computercraft.shared.network.container.ComputerContainerData; +import dan200.computercraft.shared.util.IDAssigner; +import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesAPI; +import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesComputer; +import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesMenuProvider; +import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.*; +import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ArmorItem; import net.minecraft.world.item.ArmorMaterials; import net.minecraft.world.item.ItemStack; @@ -12,16 +34,203 @@ import java.util.List; -public class SmartGlassesItem extends ArmorItem { +public class SmartGlassesItem extends ArmorItem implements IComputerItem, IMedia { + + private static final String NBT_UPGRADE = "Upgrade"; + private static final String NBT_UPGRADE_INFO = "UpgradeInfo"; + public static final String NBT_LIGHT = "Light"; + public static final String NBT_ON = "On"; + + private static final String NBT_INSTANCE = "InstanceId"; + private static final String NBT_SESSION = "SessionId"; + public SmartGlassesItem(ArmorMaterials material) { super(material, EquipmentSlot.HEAD, new Properties().stacksTo(1)); } + + private boolean tick(ItemStack stack, Level world, Entity entity, SmartGlassesComputer computer) { + computer.setLevel((ServerLevel) world); + + var changed = false; + + // Sync ID + var id = computer.getID(); + if (id != getComputerID(stack)) { + changed = true; + setComputerID(stack, id); + } + + // Sync label + var label = computer.getLabel(); + if (!Objects.equal(label, getLabel(stack))) { + changed = true; + setLabel(stack, label); + } + + var on = computer.isOn(); + if (on != isMarkedOn(stack)) { + changed = true; + stack.getOrCreateTag().putBoolean(NBT_ON, on); + } + + return changed; + } + + @Override + public void inventoryTick(ItemStack stack, Level world, Entity entity, int slotNum, boolean selected) { + if (world.isClientSide) return; + Container inventory = entity instanceof Player player ? player.getInventory() : null; + var computer = createServerComputer((ServerLevel) world, entity, inventory, stack); + computer.keepAlive(); + + var changed = tick(stack, world, entity, computer); + if (changed && inventory != null) inventory.setChanged(); + } + + @ForgeOverride + public boolean onEntityItemUpdate(ItemStack stack, ItemEntity entity) { + if (entity.level.isClientSide || entity.level.getServer() == null) return false; + + var computer = getServerComputer(entity.level.getServer(), stack); + if (computer != null && tick(stack, entity.level, entity, computer)) entity.setItem(stack.copy()); + return false; + } + + @NotNull + @Override + public InteractionResultHolder use(Level world, Player player, InteractionHand hand) { + var stack = player.getItemInHand(hand); + if (!world.isClientSide) { + var computer = createServerComputer((ServerLevel) world, player, player.getInventory(), stack); + computer.turnOn(); + + var stop = false; + if (!stop) { + var isTypingOnly = hand == InteractionHand.OFF_HAND; + new ComputerContainerData(computer, stack).open(player, new SmartGlassesMenuProvider(computer, stack, this, hand, isTypingOnly)); + } + } + return new InteractionResultHolder<>(InteractionResult.sidedSuccess(world.isClientSide), stack); + } + + public ItemStack create(int id, @Nullable String label) { + var result = new ItemStack(this); + if (id >= 0) result.getOrCreateTag().putInt(NBT_ID, id); + if (label != null) result.setHoverName(Component.literal(label)); + return result; + } + + @Override + public ComputerFamily getFamily() { + return ComputerFamily.ADVANCED; + } + + @Override + public ItemStack withFamily(ItemStack stack, ComputerFamily family) { + return create(getComputerID(stack), getLabel(stack)); + } + + @Override + public void appendHoverText(ItemStack stack, @javax.annotation.Nullable Level world, List list, TooltipFlag flag) { + if (flag.isAdvanced() || getLabel(stack) == null) { + var id = getComputerID(stack); + if (id >= 0) { + list.add(Component.translatable("gui.computercraft.tooltip.computer_id", id) + .withStyle(ChatFormatting.GRAY)); + } + } + } + + public String getCreatorModId(ItemStack stack) { + return AdvancedPeripherals.MOD_ID; + } + + public SmartGlassesComputer createServerComputer(ServerLevel level, Entity entity, @javax.annotation.Nullable Container inventory, ItemStack stack) { + var sessionID = getSessionID(stack); + + var registry = ServerContext.get(level.getServer()).registry(); + var computer = (SmartGlassesComputer) registry.get(sessionID, getInstanceID(stack)); + if (computer == null) { + var computerID = getComputerID(stack); + if (computerID < 0) { + computerID = ComputerCraftAPI.createUniqueNumberedSaveDir(level.getServer(), IDAssigner.COMPUTER); + setComputerID(stack, computerID); + } + + computer = new SmartGlassesComputer(level, entity.blockPosition(), getComputerID(stack), getLabel(stack), getFamily()); + + setInstanceID(stack, computer.register()); + setSessionID(stack, registry.getSessionID()); + + computer.addAPI(new SmartGlassesAPI()); + + // Only turn on when initially creating the computer, rather than each tick. + if (isMarkedOn(stack) && entity instanceof Player) computer.turnOn(); + + if (inventory != null) inventory.setChanged(); + } + computer.setLevel(level); + return computer; + } + + @Nullable + public static SmartGlassesComputer getServerComputer(MinecraftServer server, ItemStack stack) { + return (SmartGlassesComputer) ServerContext.get(server).registry().get(getSessionID(stack), getInstanceID(stack)); + } + + // IComputerItem implementation + + private static void setComputerID(ItemStack stack, int computerID) { + stack.getOrCreateTag().putInt(NBT_ID, computerID); + } + @Override - public void appendHoverText(@NotNull ItemStack stack, @Nullable Level levelIn, @NotNull List tooltip, @NotNull TooltipFlag flagIn) { - super.appendHoverText(stack, levelIn, tooltip, flagIn); - tooltip.add(Component.literal("Temporarily disabled until rewrite")); + public @javax.annotation.Nullable String getLabel(ItemStack stack) { + return IComputerItem.super.getLabel(stack); + } + + @Override + public boolean setLabel(ItemStack stack, @javax.annotation.Nullable String label) { + if (label != null) { + stack.setHoverName(Component.literal(label)); + } else { + stack.resetHoverName(); + } + return true; + } + + @Override + public @Nullable Mount createDataMount(ItemStack stack, ServerLevel level) { + var id = getComputerID(stack); + if (id >= 0) { + return ComputerCraftAPI.createSaveDirMount(level.getServer(), "computer/" + id, Config.computerSpaceLimit); + } + return null; + } + + public static int getInstanceID(ItemStack stack) { + var nbt = stack.getTag(); + return nbt != null && nbt.contains(NBT_INSTANCE) ? nbt.getInt(NBT_INSTANCE) : -1; + } + + private static void setInstanceID(ItemStack stack, int instanceID) { + stack.getOrCreateTag().putInt(NBT_INSTANCE, instanceID); + } + + private static int getSessionID(ItemStack stack) { + var nbt = stack.getTag(); + return nbt != null && nbt.contains(NBT_SESSION) ? nbt.getInt(NBT_SESSION) : -1; + } + + private static void setSessionID(ItemStack stack, int sessionID) { + stack.getOrCreateTag().putInt(NBT_SESSION, sessionID); + } + + private static boolean isMarkedOn(ItemStack stack) { + var nbt = stack.getTag(); + return nbt != null && nbt.getBoolean(NBT_ON); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java index 6b38187ab..3344732e5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java @@ -1,11 +1,20 @@ package de.srendi.advancedperipherals.common.setup; +import dan200.computercraft.api.ComputerCraftAPI; +import dan200.computercraft.shared.ModRegistry; +import dan200.computercraft.shared.computer.blocks.ComputerBlockEntity; +import dan200.computercraft.shared.computer.core.ServerComputer; +import dan200.computercraft.shared.computer.inventory.ComputerMenuWithoutInventory; +import dan200.computercraft.shared.network.container.ComputerContainerData; +import dan200.computercraft.shared.network.container.ContainerData; import de.srendi.advancedperipherals.common.container.InventoryManagerContainer; +import de.srendi.advancedperipherals.common.container.SmartGlassesContainer; import net.minecraft.core.BlockPos; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.level.Level; import net.minecraftforge.common.extensions.IForgeMenuType; import net.minecraftforge.registries.RegistryObject; +import org.apache.logging.log4j.core.jmx.Server; public class APContainerTypes { @@ -15,6 +24,10 @@ public class APContainerTypes { return new InventoryManagerContainer(windowId, inv, pos, level); })); + public static final RegistryObject> SMART_GLASSES_CONTAINER = APRegistration.CONTAINER_TYPES.register("smart_glasses_container", () -> ContainerData.toType(ComputerContainerData::new, + (id, inv, data) -> new SmartGlassesContainer(id, player -> true, null, data) + )); + public static void register() { } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesAPI.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesAPI.java new file mode 100644 index 000000000..8eb0cf83f --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesAPI.java @@ -0,0 +1,12 @@ +package de.srendi.advancedperipherals.common.smartglasses; + +import dan200.computercraft.api.lua.ILuaAPI; +import dan200.computercraft.api.lua.LuaFunction; + +public class SmartGlassesAPI implements ILuaAPI { + @Override + public String[] getNames() { + return new String[]{"smartglasses"}; + } + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java new file mode 100644 index 000000000..cccda53c9 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java @@ -0,0 +1,163 @@ +package de.srendi.advancedperipherals.common.smartglasses; + +import dan200.computercraft.api.peripheral.IPeripheral; +import dan200.computercraft.api.pocket.IPocketAccess; +import dan200.computercraft.api.pocket.IPocketUpgrade; +import dan200.computercraft.core.computer.ComputerSide; +import dan200.computercraft.shared.common.IColouredItem; +import dan200.computercraft.shared.computer.core.ComputerFamily; +import dan200.computercraft.shared.computer.core.ServerComputer; +import dan200.computercraft.shared.config.Config; +import dan200.computercraft.shared.network.client.PocketComputerDataMessage; +import dan200.computercraft.shared.network.client.PocketComputerDeletedClientMessage; +import dan200.computercraft.shared.platform.PlatformHelper; +import dan200.computercraft.shared.pocket.items.PocketComputerItem; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; + +import javax.annotation.Nullable; +import java.util.*; + +/** + * Basically just a {@link dan200.computercraft.shared.pocket.core.PocketServerComputer} but with some changes + */ +public class SmartGlassesComputer extends ServerComputer implements IPocketAccess { + + private @Nullable Entity entity; + private ItemStack stack = ItemStack.EMPTY; + + private int lightColour = -1; + private boolean lightChanged = false; + + private final Set tracking = new HashSet<>(); + + public SmartGlassesComputer(ServerLevel world, BlockPos position, int computerID, @Nullable String label, ComputerFamily family) { + super(world, position, computerID, label, family, 48, 48); + } + + @Nullable + @Override + public Entity getEntity() { + var entity = this.entity; + if (entity == null || stack.isEmpty() || !entity.isAlive()) return null; + + if (entity instanceof Player) { + var inventory = ((Player) entity).getInventory(); + return inventory.items.contains(stack) || inventory.offhand.contains(stack) ? entity : null; + } else if (entity instanceof LivingEntity living) { + return living.getMainHandItem() == stack || living.getOffhandItem() == stack ? entity : null; + } else if (entity instanceof ItemEntity itemEntity) { + return itemEntity.getItem() == stack ? entity : null; + } else { + return null; + } + } + + @Override + public int getColour() { + return IColouredItem.getColourBasic(stack); + } + + @Override + public void setColour(int colour) { + IColouredItem.setColourBasic(stack, colour); + updateUpgradeNBTData(); + } + + @Override + public int getLight() { + return lightColour; + } + + @Override + public void setLight(int colour) { + if (colour < 0 || colour > 0xFFFFFF) colour = -1; + + if (lightColour == colour) return; + lightColour = colour; + lightChanged = true; + } + + @Override + public CompoundTag getUpgradeNBTData() { + return PocketComputerItem.getUpgradeInfo(stack); + } + + @Override + public void updateUpgradeNBTData() { + if (entity instanceof Player player) player.getInventory().setChanged(); + } + + @Override + public void invalidatePeripheral() { + } + + @Override + public Map getUpgrades() { + return Collections.emptyMap(); + } + + + public synchronized void updateValues(@Nullable Entity entity, ItemStack stack, @Nullable IPocketUpgrade upgrade) { + if (entity != null) { + setLevel((ServerLevel) entity.getCommandSenderWorld()); + setPosition(entity.blockPosition()); + } + + // If a new entity has picked it up then rebroadcast the terminal to them + if (entity != this.entity && entity instanceof ServerPlayer) markTerminalChanged(); + + this.entity = entity; + this.stack = stack; + + invalidatePeripheral(); + + } + + @Override + public void tickServer() { + super.tickServer(); + + // Find any players which have gone missing and remove them from the tracking list. + tracking.removeIf(player -> !player.isAlive() || player.level != getLevel()); + + // And now find any new players, add them to the tracking list, and broadcast state where appropriate. + var sendState = hasOutputChanged() || lightChanged; + lightChanged = false; + if (sendState) { + // Broadcast the state to all players + tracking.addAll(getLevel().players()); + } else { + // Broadcast the state to new players. + List added = new ArrayList<>(); + for (var player : getLevel().players()) { + if (tracking.add(player)) added.add(player); + } + if (!added.isEmpty()) { + } + } + } + + @Override + protected void onTerminalChanged() { + super.onTerminalChanged(); + + if (entity instanceof ServerPlayer player && entity.isAlive()) { + // Broadcast the terminal to the current player. + } + } + + @Override + protected void onRemoved() { + super.onRemoved(); + } + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesMenuProvider.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesMenuProvider.java new file mode 100644 index 000000000..02cb2a0d9 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesMenuProvider.java @@ -0,0 +1,51 @@ +package de.srendi.advancedperipherals.common.smartglasses; + +import dan200.computercraft.shared.ModRegistry; +import dan200.computercraft.shared.computer.core.ServerComputer; +import dan200.computercraft.shared.computer.inventory.ComputerMenuWithoutInventory; +import dan200.computercraft.shared.pocket.items.PocketComputerItem; +import de.srendi.advancedperipherals.common.container.SmartGlassesContainer; +import de.srendi.advancedperipherals.common.items.SmartGlassesItem; +import net.minecraft.network.chat.Component; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.NotNull; + +import javax.annotation.Nullable; + +public class SmartGlassesMenuProvider implements MenuProvider { + private final ServerComputer computer; + private final Component name; + private final SmartGlassesItem item; + private final InteractionHand hand; + private final boolean isTypingOnly; + + public SmartGlassesMenuProvider(ServerComputer computer, ItemStack stack, SmartGlassesItem item, InteractionHand hand, boolean isTypingOnly) { + this.computer = computer; + name = stack.getHoverName(); + this.item = item; + this.hand = hand; + this.isTypingOnly = isTypingOnly; + } + + + @Override + public Component getDisplayName() { + return name; + } + + @Nullable + @Override + public AbstractContainerMenu createMenu(int id, @NotNull Inventory inventory, @NotNull Player entity) { + return new SmartGlassesContainer(id, + p -> { + return true; + }, + computer + ); + } +} diff --git a/src/main/resources/data/computercraft/lua/rom/programs/flat.lua b/src/main/resources/data/computercraft/lua/rom/programs/flat.lua new file mode 100644 index 000000000..05956edff --- /dev/null +++ b/src/main/resources/data/computercraft/lua/rom/programs/flat.lua @@ -0,0 +1 @@ +print("The earth is flat, at least in minecraft!") \ No newline at end of file From 6222b3fa54cf6b0d56fae178adcad8ee32eb15c3 Mon Sep 17 00:00:00 2001 From: Srendi Date: Sun, 5 Mar 2023 03:37:48 +0100 Subject: [PATCH 018/228] Checked the style --- .../common/container/SmartGlassesContainer.java | 8 +++----- .../common/setup/APContainerTypes.java | 6 ------ .../common/smartglasses/SmartGlassesAPI.java | 1 - .../common/smartglasses/SmartGlassesComputer.java | 12 +++--------- .../smartglasses/SmartGlassesMenuProvider.java | 3 --- 5 files changed, 6 insertions(+), 24 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java b/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java index 4e05e2328..889c25712 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java @@ -3,12 +3,9 @@ import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ServerComputer; import dan200.computercraft.shared.computer.inventory.AbstractComputerMenu; -import dan200.computercraft.shared.computer.inventory.ComputerMenuWithoutInventory; import dan200.computercraft.shared.network.container.ComputerContainerData; import de.srendi.advancedperipherals.common.setup.APContainerTypes; -import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.NotNull; @@ -17,13 +14,14 @@ public class SmartGlassesContainer extends AbstractComputerMenu { public SmartGlassesContainer(int id, Predicate canUse, - ServerComputer computer + ServerComputer computer ) { super(APContainerTypes.SMART_GLASSES_CONTAINER.get(), id, canUse, ComputerFamily.ADVANCED, computer, null); } + public SmartGlassesContainer(int id, Predicate predicate, ServerComputer computer, ComputerContainerData data) { super(APContainerTypes.SMART_GLASSES_CONTAINER.get(), id, predicate, ComputerFamily.ADVANCED, computer, data); - getTerminal().resize(48,48); + getTerminal().resize(48, 48); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java index 3344732e5..e41f3e629 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java @@ -1,10 +1,5 @@ package de.srendi.advancedperipherals.common.setup; -import dan200.computercraft.api.ComputerCraftAPI; -import dan200.computercraft.shared.ModRegistry; -import dan200.computercraft.shared.computer.blocks.ComputerBlockEntity; -import dan200.computercraft.shared.computer.core.ServerComputer; -import dan200.computercraft.shared.computer.inventory.ComputerMenuWithoutInventory; import dan200.computercraft.shared.network.container.ComputerContainerData; import dan200.computercraft.shared.network.container.ContainerData; import de.srendi.advancedperipherals.common.container.InventoryManagerContainer; @@ -14,7 +9,6 @@ import net.minecraft.world.level.Level; import net.minecraftforge.common.extensions.IForgeMenuType; import net.minecraftforge.registries.RegistryObject; -import org.apache.logging.log4j.core.jmx.Server; public class APContainerTypes { diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesAPI.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesAPI.java index 8eb0cf83f..04baafc24 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesAPI.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesAPI.java @@ -1,7 +1,6 @@ package de.srendi.advancedperipherals.common.smartglasses; import dan200.computercraft.api.lua.ILuaAPI; -import dan200.computercraft.api.lua.LuaFunction; public class SmartGlassesAPI implements ILuaAPI { @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java index cccda53c9..685c80236 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java @@ -3,14 +3,9 @@ import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.pocket.IPocketAccess; import dan200.computercraft.api.pocket.IPocketUpgrade; -import dan200.computercraft.core.computer.ComputerSide; import dan200.computercraft.shared.common.IColouredItem; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ServerComputer; -import dan200.computercraft.shared.config.Config; -import dan200.computercraft.shared.network.client.PocketComputerDataMessage; -import dan200.computercraft.shared.network.client.PocketComputerDeletedClientMessage; -import dan200.computercraft.shared.platform.PlatformHelper; import dan200.computercraft.shared.pocket.items.PocketComputerItem; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; @@ -141,8 +136,7 @@ public void tickServer() { for (var player : getLevel().players()) { if (tracking.add(player)) added.add(player); } - if (!added.isEmpty()) { - } + } } @@ -150,9 +144,9 @@ public void tickServer() { protected void onTerminalChanged() { super.onTerminalChanged(); - if (entity instanceof ServerPlayer player && entity.isAlive()) { + /*if (entity instanceof ServerPlayer player && entity.isAlive()) { // Broadcast the terminal to the current player. - } + }*/ } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesMenuProvider.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesMenuProvider.java index 02cb2a0d9..3e8d7bd29 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesMenuProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesMenuProvider.java @@ -1,9 +1,6 @@ package de.srendi.advancedperipherals.common.smartglasses; -import dan200.computercraft.shared.ModRegistry; import dan200.computercraft.shared.computer.core.ServerComputer; -import dan200.computercraft.shared.computer.inventory.ComputerMenuWithoutInventory; -import dan200.computercraft.shared.pocket.items.PocketComputerItem; import de.srendi.advancedperipherals.common.container.SmartGlassesContainer; import de.srendi.advancedperipherals.common.items.SmartGlassesItem; import net.minecraft.network.chat.Component; From 4a0533add7a042edb6b99857b5ab83d2dff2b96d Mon Sep 17 00:00:00 2001 From: DenizD Date: Wed, 8 Mar 2023 13:49:48 +0100 Subject: [PATCH 019/228] Re-add the smart glasses model --- .../common/items/SmartGlassesItem.java | 21 ++--- .../items/base/SmartGlassesMaterials.java | 80 ++++++++++++++++++ .../common/setup/APItems.java | 6 +- .../models/item/ar_goggles.json | 6 -- .../models/item/smart_glasses.json | 6 ++ .../textures/item/memory_card.png | Bin 774 -> 708 bytes .../{ar_goggles.png => smart_glasses.png} | Bin .../textures/models/ar_goggles.png | Bin 1133 -> 0 bytes .../models/armor/smart_glasses_layer_1.png | Bin 0 -> 191 bytes 9 files changed, 100 insertions(+), 19 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/items/base/SmartGlassesMaterials.java delete mode 100644 src/main/resources/assets/advancedperipherals/models/item/ar_goggles.json create mode 100644 src/main/resources/assets/advancedperipherals/models/item/smart_glasses.json rename src/main/resources/assets/advancedperipherals/textures/item/{ar_goggles.png => smart_glasses.png} (100%) delete mode 100644 src/main/resources/assets/advancedperipherals/textures/models/ar_goggles.png create mode 100644 src/main/resources/assets/advancedperipherals/textures/models/armor/smart_glasses_layer_1.png diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java index 1871fe8cf..b3f97c232 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java @@ -19,13 +19,16 @@ import net.minecraft.network.chat.Component; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.*; +import net.minecraft.world.Container; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ArmorItem; -import net.minecraft.world.item.ArmorMaterials; +import net.minecraft.world.item.ArmorMaterial; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.level.Level; @@ -44,12 +47,10 @@ public class SmartGlassesItem extends ArmorItem implements IComputerItem, IMedia private static final String NBT_INSTANCE = "InstanceId"; private static final String NBT_SESSION = "SessionId"; - - public SmartGlassesItem(ArmorMaterials material) { + public SmartGlassesItem(ArmorMaterial material) { super(material, EquipmentSlot.HEAD, new Properties().stacksTo(1)); } - private boolean tick(ItemStack stack, Level world, Entity entity, SmartGlassesComputer computer) { computer.setLevel((ServerLevel) world); @@ -79,7 +80,7 @@ private boolean tick(ItemStack stack, Level world, Entity entity, SmartGlassesCo } @Override - public void inventoryTick(ItemStack stack, Level world, Entity entity, int slotNum, boolean selected) { + public void inventoryTick(@NotNull ItemStack stack, Level world, @NotNull Entity entity, int slotNum, boolean selected) { if (world.isClientSide) return; Container inventory = entity instanceof Player player ? player.getInventory() : null; var computer = createServerComputer((ServerLevel) world, entity, inventory, stack); @@ -100,7 +101,7 @@ public boolean onEntityItemUpdate(ItemStack stack, ItemEntity entity) { @NotNull @Override - public InteractionResultHolder use(Level world, Player player, InteractionHand hand) { + public InteractionResultHolder use(Level world, Player player, @NotNull InteractionHand hand) { var stack = player.getItemInHand(hand); if (!world.isClientSide) { var computer = createServerComputer((ServerLevel) world, player, player.getInventory(), stack); @@ -133,7 +134,7 @@ public ItemStack withFamily(ItemStack stack, ComputerFamily family) { } @Override - public void appendHoverText(ItemStack stack, @javax.annotation.Nullable Level world, List list, TooltipFlag flag) { + public void appendHoverText(@NotNull ItemStack stack, @javax.annotation.Nullable Level world, @NotNull List list, TooltipFlag flag) { if (flag.isAdvanced() || getLabel(stack) == null) { var id = getComputerID(stack); if (id >= 0) { @@ -181,7 +182,6 @@ public static SmartGlassesComputer getServerComputer(MinecraftServer server, Ite } // IComputerItem implementation - private static void setComputerID(ItemStack stack, int computerID) { stack.getOrCreateTag().putInt(NBT_ID, computerID); } @@ -201,8 +201,9 @@ public boolean setLabel(ItemStack stack, @javax.annotation.Nullable String label return true; } + @Nullable @Override - public @Nullable Mount createDataMount(ItemStack stack, ServerLevel level) { + public Mount createDataMount(ItemStack stack, ServerLevel level) { var id = getComputerID(stack); if (id >= 0) { return ComputerCraftAPI.createSaveDirMount(level.getServer(), "computer/" + id, Config.computerSpaceLimit); diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/base/SmartGlassesMaterials.java b/src/main/java/de/srendi/advancedperipherals/common/items/base/SmartGlassesMaterials.java new file mode 100644 index 000000000..99bb4890f --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/items/base/SmartGlassesMaterials.java @@ -0,0 +1,80 @@ +package de.srendi.advancedperipherals.common.items.base; + +import de.srendi.advancedperipherals.AdvancedPeripherals; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.util.LazyLoadedValue; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.item.ArmorMaterial; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.crafting.Ingredient; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Supplier; + +public enum SmartGlassesMaterials implements ArmorMaterial { + + // We use the same name, so they use the same model texture + CHAIN("smart_glasses", 15, new int[]{1, 4, 5, 2}, 12, SoundEvents.ARMOR_EQUIP_CHAIN, 0.0F, 0.0F, () -> { + return Ingredient.of(Items.IRON_INGOT); + }), + NETHERITE("smart_glasses", 37, new int[]{3, 6, 8, 3}, 15, SoundEvents.ARMOR_EQUIP_NETHERITE, 3.0F, 0.1F, () -> { + return Ingredient.of(Items.NETHERITE_INGOT); + }); + + private static final int[] HEALTH_PER_SLOT = new int[]{13, 15, 16, 11}; + private final String name; + private final int durabilityMultiplier; + private final int[] slotProtections; + private final int enchantmentValue; + private final SoundEvent sound; + private final float toughness; + private final float knockbackResistance; + private final LazyLoadedValue repairIngredient; + + SmartGlassesMaterials(String pName, int pDurabilityMultiplier, int[] pSlotProtections, int pEnchantmentValue, SoundEvent pSound, float pToughness, float pKnockbackResistance, Supplier pRepairIngredient) { + this.name = pName; + this.durabilityMultiplier = pDurabilityMultiplier; + this.slotProtections = pSlotProtections; + this.enchantmentValue = pEnchantmentValue; + this.sound = pSound; + this.toughness = pToughness; + this.knockbackResistance = pKnockbackResistance; + this.repairIngredient = new LazyLoadedValue<>(pRepairIngredient); + } + + public int getDurabilityForSlot(EquipmentSlot pSlot) { + return HEALTH_PER_SLOT[pSlot.getIndex()] * this.durabilityMultiplier; + } + + public int getDefenseForSlot(EquipmentSlot pSlot) { + return this.slotProtections[pSlot.getIndex()]; + } + + public int getEnchantmentValue() { + return this.enchantmentValue; + } + + @NotNull + public SoundEvent getEquipSound() { + return this.sound; + } + + @NotNull + public Ingredient getRepairIngredient() { + return this.repairIngredient.get(); + } + + @NotNull + public String getName() { + return AdvancedPeripherals.MOD_ID + ":" + this.name; + } + + public float getToughness() { + return this.toughness; + } + + public float getKnockbackResistance() { + return this.knockbackResistance; + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java index 9cbfde8ce..2672bb396 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java @@ -5,7 +5,7 @@ import de.srendi.advancedperipherals.common.items.MemoryCardItem; import de.srendi.advancedperipherals.common.items.SmartGlassesItem; import de.srendi.advancedperipherals.common.items.WeakAutomataCore; -import net.minecraft.world.item.ArmorMaterials; +import de.srendi.advancedperipherals.common.items.base.SmartGlassesMaterials; import net.minecraft.world.item.Item; import net.minecraftforge.registries.RegistryObject; @@ -13,9 +13,9 @@ public class APItems { public static final RegistryObject CHUNK_CONTROLLER = APRegistration.ITEMS.register("chunk_controller", () -> new APItem(new Item.Properties().stacksTo(16), CCRegistration.ID.CHUNKY_TURTLE, null, APConfig.PERIPHERALS_CONFIG.enableChunkyTurtle::get)); - public static final RegistryObject SMART_GLASSES = APRegistration.ITEMS.register("smart_glasses", () -> new SmartGlassesItem(ArmorMaterials.CHAIN)); + public static final RegistryObject SMART_GLASSES = APRegistration.ITEMS.register("smart_glasses", () -> new SmartGlassesItem(SmartGlassesMaterials.CHAIN)); - public static final RegistryObject SMART_GLASSES_NETHERITE = APRegistration.ITEMS.register("smart_glasses_netherite", () -> new SmartGlassesItem(ArmorMaterials.NETHERITE)); + public static final RegistryObject SMART_GLASSES_NETHERITE = APRegistration.ITEMS.register("smart_glasses_netherite", () -> new SmartGlassesItem(SmartGlassesMaterials.NETHERITE)); public static final RegistryObject COMPUTER_TOOL = APRegistration.ITEMS.register("computer_tool", () -> new APItem(new Item.Properties().stacksTo(1), null, null, () -> true)); diff --git a/src/main/resources/assets/advancedperipherals/models/item/ar_goggles.json b/src/main/resources/assets/advancedperipherals/models/item/ar_goggles.json deleted file mode 100644 index 8cedf86ab..000000000 --- a/src/main/resources/assets/advancedperipherals/models/item/ar_goggles.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "parent": "item/generated", - "textures": { - "layer0": "advancedperipherals:item/ar_goggles" - } -} \ No newline at end of file diff --git a/src/main/resources/assets/advancedperipherals/models/item/smart_glasses.json b/src/main/resources/assets/advancedperipherals/models/item/smart_glasses.json new file mode 100644 index 000000000..bc29777ce --- /dev/null +++ b/src/main/resources/assets/advancedperipherals/models/item/smart_glasses.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "advancedperipherals:item/smart_glasses" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/advancedperipherals/textures/item/memory_card.png b/src/main/resources/assets/advancedperipherals/textures/item/memory_card.png index 6da07f35e3f043f394b9b0813641b774c0cd2b69..089f0e39c492b08c24efc9f4924e3444ea7d38b9 100644 GIT binary patch delta 684 zcmV;d0#p5l2E+xBB!72lLqkwWLqi}?a&Km7Y-IodD3NuMJ4*vW6otP$MA1kJMMNx8 zsHBJ>3Sub{OcO1V2u5v^HJb>#>$005!B()b2v~?Vz6$?=wt}sKASi-}jeo#bBeLEx zLPT_y+52&3&SmBd_>+cay1^kZt+JC!#3QrWxk&RPK>~CUCV!gKTze`#nc?5@c8yQf zt3lQ4|9yXsw#9<0fv-h)RI{D3@VIbtrEDwS5bo4UxkceU;g}-_6h2pazRnMdi*||0C;8#5(#UGsi!CJ{Ng`>iKrcu$p&!cVONPJ}!amM|zYDAkh8 z{`L)h`KDPGkAEhAn<|btij>3~6SX2;3sQB_3-TFMRqns@boG(pdiPKqn(jUCxgVN0 z;iKkx@B5zjaR7lkIJFx7WyxvmRrFdz>)VC!8XTWBwEPyFtV8#$opW+uQb49(*Wu|1 z+OyDc39a+>tiIPdyn)QBJkbSg@4$fU4=;QI+=XZQCVyl04*&oG2uVaiR5*>rlCes} zKomt!-t1^12>!sb&6X)ssrdjwZ2W>i{$^{lASuMk#wJa^K(O^&1OrZH#=_koOtQN+ z`nt#5d*8ip9{hJjQx8Q^c%>8~f^!alx~>Df9749%A|jM!=?@Z6O7V!MX&RpN32oc* z;1t%{0Dn81ig2Vg?>D!wA!!j5D!`380QfY9)8={TBNdV-9f$~3zvktt;G)0d^|}P} zv5gP`!!AZ07-PO|YfWe1GOCCECwWp}0|emhxTLpWtsTB|uYhxo&cM09M??bAy#m|G z+c-1D==7bH=eb{1OP{8xUsX$=Wm#}Uu;UK8t|eo>I3tc>zKBVZh3jcw&f~|reD1wNMf52BGVZCDl z38IBF%-)YPdoD9)z!}Nw1_{G>Qr=QqV> zJUS(JQ$2mz7S>u=&zS|`fUv)iujq~QsGE4w#rc@j0a=4sM42Is4~+^d}(G~3O!La=AUH$^xg=hK?l7Gpj00009a7bBm000ic000ic z0Tn1pfB*miHc3Q5R5(w~lD$rZKoo_KBun@S0b>Y-8cp2oC@E|pF&0!?TGjxXU@GD{5c1W_HZ1h76bud7=q_{ zuq+GD^M88hnMONoFUN5VP18^m1tdv=>$-Jwq-D^6u$(Qix>&*YeFQ;(g|a|dmd);t zL4z#Iz(4YkpJmi{HBCa+B*{+(4M<#aDY}iQ(d2$Y>#C|!-Dl9Cswx~^-C+Jc$9i@N z`^|=BS#+QqI)fZ-A&(`dq@-=LbYlge=QVb;sxo$jh&} zh%`;19G`$;nEezjV=ZL%^pLipC`#K7G5$5CY1R)<(^}Vcs)k|oJ`rIs0U^(GoSrG* gIF2g$&i@hM8$tPbpXQ3R-T(jq07*qoM6N<$f*2TCdjJ3c diff --git a/src/main/resources/assets/advancedperipherals/textures/item/ar_goggles.png b/src/main/resources/assets/advancedperipherals/textures/item/smart_glasses.png similarity index 100% rename from src/main/resources/assets/advancedperipherals/textures/item/ar_goggles.png rename to src/main/resources/assets/advancedperipherals/textures/item/smart_glasses.png diff --git a/src/main/resources/assets/advancedperipherals/textures/models/ar_goggles.png b/src/main/resources/assets/advancedperipherals/textures/models/ar_goggles.png deleted file mode 100644 index 5ec507c48ee0a0c05dbc570c76a83bd57baf4645..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1133 zcmaJ=&r1|h93M4Hwj>WB=s||@&=1|6A3D44wgQBW7FH@d4G+#WOYetkZl@6Wjv@9VDg z)%pm6sEqYU2|Ul>x4q&h{;qFKPvfZub*4~1OrxA)10t%yAwb3qWf&xYqD_pgfL4Mi zqx577rR0l(3XOo`VFIpUVKzauwz-y~jsQdsfnnW@P}@(IDN@%W)BrCtvL%9y-ZN=~ z{>i?iIys_-HLC3b+3E^dzyL@gU1QXA1UEwM>I!)69n%!K3qd0hYR{>Z94AF+1CkFk z`BjEx$zU+RHuJ$C+emT@%h3#ef_}DH;DZ7eBJ+d7)@&^;B&4pqExe0R8H6l>rgOPm zAlDRt_At$c!(mT@qbLk(je?VtoW@b^$*CplpOIsqJ*wN+fWbiHTF5=0v)2--;q zM+;euXCQ)323n-pA0*EV=%xm9&e>hOEDJHyL5it@m=vL~LO|CwAsh{LMWan2QRGCH z?c`cGo)LMmh2cd$)FFult_0Pr0ZdfjY6skwqFk>P3=3P9fUS=Mt;>c6xf`;e7x#rP zs+Z?##eE4D<Gei|p+D;t0 z`8BpV8kHJ%w%qg$c7D0^<;vp7{ImNf*B&mMpPH&JXWm`?R-4|QYMYyzdc68|IrZvy z&5x($cNgB?yi)gKX8CfcYp}PWt?bmX_|}8*N3i5jE5+>}-1zEBPY~JD4O|v(yddz1 Mb@oXM9fQ~Y0tFming9R* diff --git a/src/main/resources/assets/advancedperipherals/textures/models/armor/smart_glasses_layer_1.png b/src/main/resources/assets/advancedperipherals/textures/models/armor/smart_glasses_layer_1.png new file mode 100644 index 0000000000000000000000000000000000000000..c94f2085af38b661aefa042c3799e03f04ca10e1 GIT binary patch literal 191 zcmeAS@N?(olHy`uVBq!ia0vp^4M6O`!3HERU8}DLQjEnx?oJHr&dIz4aw Date: Thu, 9 Mar 2023 12:04:44 +0100 Subject: [PATCH 020/228] Away with you --- .../common/items/APBlockItem.java | 14 ++------ .../common/items/APItem.java | 14 ++------ .../common/items/WeakAutomataCore.java | 9 +++-- .../common/setup/APBlocks.java | 34 +++++++++---------- .../common/setup/APItems.java | 16 ++++----- 5 files changed, 33 insertions(+), 54 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/APBlockItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/APBlockItem.java index 1bb62e4e0..5acdfe14b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/APBlockItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/APBlockItem.java @@ -1,31 +1,21 @@ package de.srendi.advancedperipherals.common.items; import de.srendi.advancedperipherals.common.items.base.BaseBlockItem; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.Block; -import org.jetbrains.annotations.Nullable; import java.util.function.Supplier; public class APBlockItem extends BaseBlockItem { - @Nullable - private final ResourceLocation turtleID; - @Nullable - private final ResourceLocation pocketID; private final Supplier enabledSup; - public APBlockItem(Block blockIn, Properties properties, @Nullable ResourceLocation turtleID, @Nullable ResourceLocation pocketID, Supplier enabledSup) { + public APBlockItem(Block blockIn, Properties properties, Supplier enabledSup) { super(blockIn, properties); - this.turtleID = turtleID; - this.pocketID = pocketID; this.enabledSup = enabledSup; } - public APBlockItem(Block blockIn, @Nullable ResourceLocation turtleID, @Nullable ResourceLocation pocketID, Supplier enabledSup) { + public APBlockItem(Block blockIn, Supplier enabledSup) { super(blockIn); - this.turtleID = turtleID; - this.pocketID = pocketID; this.enabledSup = enabledSup; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/APItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/APItem.java index d931b024f..34ffcbeb5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/APItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/APItem.java @@ -1,30 +1,20 @@ package de.srendi.advancedperipherals.common.items; import de.srendi.advancedperipherals.common.items.base.BaseItem; -import net.minecraft.resources.ResourceLocation; -import org.jetbrains.annotations.Nullable; import java.util.function.Supplier; public class APItem extends BaseItem { - @Nullable - private final ResourceLocation turtleID; - @Nullable - private final ResourceLocation pocketID; private final Supplier enabledSup; - public APItem(Properties properties, @Nullable ResourceLocation turtleID, @Nullable ResourceLocation pocketID, Supplier enabledSup) { + public APItem(Properties properties, Supplier enabledSup) { super(properties); - this.turtleID = turtleID; - this.pocketID = pocketID; this.enabledSup = enabledSup; } - public APItem(@Nullable ResourceLocation turtleID, @Nullable ResourceLocation pocketID, Supplier enabledSup) { + public APItem(Supplier enabledSup) { super(); - this.turtleID = turtleID; - this.pocketID = pocketID; this.enabledSup = enabledSup; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/WeakAutomataCore.java b/src/main/java/de/srendi/advancedperipherals/common/items/WeakAutomataCore.java index a78d461e3..49fcb2b16 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/WeakAutomataCore.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/WeakAutomataCore.java @@ -6,7 +6,6 @@ import de.srendi.advancedperipherals.lib.metaphysics.IFeedableAutomataCore; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; @@ -49,12 +48,12 @@ public class WeakAutomataCore extends APItem implements IFeedableAutomataCore { husbandrySoulRecord.ingredients.keySet().forEach(entityType -> AUTOMATA_CORE_REGISTRY.put(entityType, husbandrySoulRecord)); } - public WeakAutomataCore(Properties properties, @Nullable ResourceLocation turtleID, @Nullable ResourceLocation pocketID) { - super(properties, turtleID, pocketID, APConfig.METAPHYSICS_CONFIG.enableWeakAutomataCore); + public WeakAutomataCore(Properties properties) { + super(properties, APConfig.METAPHYSICS_CONFIG.enableWeakAutomataCore); } - public WeakAutomataCore(@Nullable ResourceLocation turtleID, @Nullable ResourceLocation pocketID) { - super(turtleID, pocketID, APConfig.METAPHYSICS_CONFIG.enableWeakAutomataCore); + public WeakAutomataCore() { + super(APConfig.METAPHYSICS_CONFIG.enableWeakAutomataCore); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java index f8d6c5915..22b3b0ee8 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java @@ -22,23 +22,23 @@ public class APBlocks { static void register() { } - public static final RegistryObject ENVIRONMENT_DETECTOR = register("environment_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.ENVIRONMENT_DETECTOR, false), () -> new APBlockItem(APBlocks.ENVIRONMENT_DETECTOR.get(), CCRegistration.ID.ENVIRONMENT_TURTLE, CCRegistration.ID.ENVIRONMENT_POCKET, APConfig.PERIPHERALS_CONFIG.enableEnvironmentDetector)); - public static final RegistryObject CHAT_BOX = register("chat_box", () -> new APBlockEntityBlock<>(APBlockEntityTypes.CHAT_BOX, true), () -> new APBlockItem(APBlocks.CHAT_BOX.get(), CCRegistration.ID.CHATTY_TURTLE, CCRegistration.ID.CHATTY_POCKET, APConfig.PERIPHERALS_CONFIG.enableChatBox)); - public static final RegistryObject PLAYER_DETECTOR = register("player_detector", PlayerDetectorBlock::new, () -> new APBlockItem(APBlocks.PLAYER_DETECTOR.get(), CCRegistration.ID.PLAYER_TURTLE, CCRegistration.ID.PLAYER_POCKET, APConfig.PERIPHERALS_CONFIG.enablePlayerDetector)); - public static final RegistryObject ME_BRIDGE = register("me_bridge", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("ae2") ? APBlockEntityTypes.ME_BRIDGE : null, ModList.get().isLoaded("ae2")), () -> new APBlockItem(APBlocks.ME_BRIDGE.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableMEBridge)); - public static final RegistryObject RS_BRIDGE = register("rs_bridge", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("refinedstorage") ? APBlockEntityTypes.RS_BRIDGE : null, false), () -> new APBlockItem(APBlocks.RS_BRIDGE.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableRSBridge)); - public static final RegistryObject ENERGY_DETECTOR = register("energy_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.ENERGY_DETECTOR, true), () -> new APBlockItem(APBlocks.ENERGY_DETECTOR.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableEnergyDetector)); - public static final RegistryObject FLUID_DETECTOR = register("fluid_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.FLUID_DETECTOR, true), () -> new APBlockItem(APBlocks.FLUID_DETECTOR.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableFluidDetector)); - public static final RegistryObject GAS_DETECTOR = register("gas_detector", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("mekanism") ? APBlockEntityTypes.GAS_DETECTOR : null, true), () -> new APBlockItem(APBlocks.GAS_DETECTOR.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableGasDetector)); - public static final RegistryObject PERIPHERAL_CASING = register("peripheral_casing", BaseBlock::new, () -> new APBlockItem(APBlocks.PERIPHERAL_CASING.get(), new Item.Properties().stacksTo(16), null, null, () -> true)); - public static final RegistryObject AR_CONTROLLER = register("ar_controller", () -> new APBlockEntityBlock<>(APBlockEntityTypes.AR_CONTROLLER, false), () -> new APBlockItem(APBlocks.AR_CONTROLLER.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableSmartGlasses)); - public static final RegistryObject INVENTORY_MANAGER = register("inventory_manager", () -> new APBlockEntityBlock<>(APBlockEntityTypes.INVENTORY_MANAGER, false), () -> new APBlockItem(APBlocks.INVENTORY_MANAGER.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableInventoryManager)); - public static final RegistryObject REDSTONE_INTEGRATOR = register("redstone_integrator", RedstoneIntegratorBlock::new, () -> new APBlockItem(APBlocks.REDSTONE_INTEGRATOR.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableRedstoneIntegrator)); - public static final RegistryObject BLOCK_READER = register("block_reader", () -> new APBlockEntityBlock<>(APBlockEntityTypes.BLOCK_READER, true), () -> new APBlockItem(APBlocks.BLOCK_READER.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableBlockReader)); - public static final RegistryObject GEO_SCANNER = register("geo_scanner", () -> new APBlockEntityBlock<>(APBlockEntityTypes.GEO_SCANNER, false), () -> new APBlockItem(APBlocks.GEO_SCANNER.get(), CCRegistration.ID.GEOSCANNER_TURTLE, CCRegistration.ID.GEOSCANNER_POCKET, APConfig.PERIPHERALS_CONFIG.enableGeoScanner)); - public static final RegistryObject COLONY_INTEGRATOR = register("colony_integrator", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("minecolonies") ? APBlockEntityTypes.COLONY_INTEGRATOR : null, false), () -> new APBlockItem(APBlocks.COLONY_INTEGRATOR.get(), null, CCRegistration.ID.COLONY_POCKET, APConfig.PERIPHERALS_CONFIG.enableColonyIntegrator)); - public static final RegistryObject NBT_STORAGE = register("nbt_storage", () -> new APBlockEntityBlock<>(APBlockEntityTypes.NBT_STORAGE, false), () -> new APBlockItem(APBlocks.NBT_STORAGE.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableNBTStorage)); - public static final RegistryObject DISTANCE_DETECTOR = register("distance_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.DISTANCE_DETECTOR, false), () -> new APBlockItem(APBlocks.DISTANCE_DETECTOR.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableNBTStorage)); + public static final RegistryObject ENVIRONMENT_DETECTOR = register("environment_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.ENVIRONMENT_DETECTOR, false), () -> new APBlockItem(APBlocks.ENVIRONMENT_DETECTOR.get(), APConfig.PERIPHERALS_CONFIG.enableEnvironmentDetector)); + public static final RegistryObject CHAT_BOX = register("chat_box", () -> new APBlockEntityBlock<>(APBlockEntityTypes.CHAT_BOX, true), () -> new APBlockItem(APBlocks.CHAT_BOX.get(), APConfig.PERIPHERALS_CONFIG.enableChatBox)); + public static final RegistryObject PLAYER_DETECTOR = register("player_detector", PlayerDetectorBlock::new, () -> new APBlockItem(APBlocks.PLAYER_DETECTOR.get(), APConfig.PERIPHERALS_CONFIG.enablePlayerDetector)); + public static final RegistryObject ME_BRIDGE = register("me_bridge", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("ae2") ? APBlockEntityTypes.ME_BRIDGE : null, ModList.get().isLoaded("ae2")), () -> new APBlockItem(APBlocks.ME_BRIDGE.get(), APConfig.PERIPHERALS_CONFIG.enableMEBridge)); + public static final RegistryObject RS_BRIDGE = register("rs_bridge", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("refinedstorage") ? APBlockEntityTypes.RS_BRIDGE : null, false), () -> new APBlockItem(APBlocks.RS_BRIDGE.get(), APConfig.PERIPHERALS_CONFIG.enableRSBridge)); + public static final RegistryObject ENERGY_DETECTOR = register("energy_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.ENERGY_DETECTOR, true), () -> new APBlockItem(APBlocks.ENERGY_DETECTOR.get(), APConfig.PERIPHERALS_CONFIG.enableEnergyDetector)); + public static final RegistryObject FLUID_DETECTOR = register("fluid_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.FLUID_DETECTOR, true), () -> new APBlockItem(APBlocks.FLUID_DETECTOR.get(), APConfig.PERIPHERALS_CONFIG.enableFluidDetector)); + public static final RegistryObject GAS_DETECTOR = register("gas_detector", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("mekanism") ? APBlockEntityTypes.GAS_DETECTOR : null, true), () -> new APBlockItem(APBlocks.GAS_DETECTOR.get(), APConfig.PERIPHERALS_CONFIG.enableGasDetector)); + public static final RegistryObject PERIPHERAL_CASING = register("peripheral_casing", BaseBlock::new, () -> new APBlockItem(APBlocks.PERIPHERAL_CASING.get(), new Item.Properties().stacksTo(16), () -> true)); + public static final RegistryObject AR_CONTROLLER = register("ar_controller", () -> new APBlockEntityBlock<>(APBlockEntityTypes.AR_CONTROLLER, false), () -> new APBlockItem(APBlocks.AR_CONTROLLER.get(), APConfig.PERIPHERALS_CONFIG.enableSmartGlasses)); + public static final RegistryObject INVENTORY_MANAGER = register("inventory_manager", () -> new APBlockEntityBlock<>(APBlockEntityTypes.INVENTORY_MANAGER, false), () -> new APBlockItem(APBlocks.INVENTORY_MANAGER.get(), APConfig.PERIPHERALS_CONFIG.enableInventoryManager)); + public static final RegistryObject REDSTONE_INTEGRATOR = register("redstone_integrator", RedstoneIntegratorBlock::new, () -> new APBlockItem(APBlocks.REDSTONE_INTEGRATOR.get(), APConfig.PERIPHERALS_CONFIG.enableRedstoneIntegrator)); + public static final RegistryObject BLOCK_READER = register("block_reader", () -> new APBlockEntityBlock<>(APBlockEntityTypes.BLOCK_READER, true), () -> new APBlockItem(APBlocks.BLOCK_READER.get(), APConfig.PERIPHERALS_CONFIG.enableBlockReader)); + public static final RegistryObject GEO_SCANNER = register("geo_scanner", () -> new APBlockEntityBlock<>(APBlockEntityTypes.GEO_SCANNER, false), () -> new APBlockItem(APBlocks.GEO_SCANNER.get(), APConfig.PERIPHERALS_CONFIG.enableGeoScanner)); + public static final RegistryObject COLONY_INTEGRATOR = register("colony_integrator", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("minecolonies") ? APBlockEntityTypes.COLONY_INTEGRATOR : null, false), () -> new APBlockItem(APBlocks.COLONY_INTEGRATOR.get(), APConfig.PERIPHERALS_CONFIG.enableColonyIntegrator)); + public static final RegistryObject NBT_STORAGE = register("nbt_storage", () -> new APBlockEntityBlock<>(APBlockEntityTypes.NBT_STORAGE, false), () -> new APBlockItem(APBlocks.NBT_STORAGE.get(), APConfig.PERIPHERALS_CONFIG.enableNBTStorage)); + public static final RegistryObject DISTANCE_DETECTOR = register("distance_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.DISTANCE_DETECTOR, false), () -> new APBlockItem(APBlocks.DISTANCE_DETECTOR.get(), APConfig.PERIPHERALS_CONFIG.enableNBTStorage)); private static RegistryObject registerNoItem(String name, Supplier block) { return APRegistration.BLOCKS.register(name, block); diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java index 2672bb396..464702e0d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java @@ -11,27 +11,27 @@ public class APItems { - public static final RegistryObject CHUNK_CONTROLLER = APRegistration.ITEMS.register("chunk_controller", () -> new APItem(new Item.Properties().stacksTo(16), CCRegistration.ID.CHUNKY_TURTLE, null, APConfig.PERIPHERALS_CONFIG.enableChunkyTurtle::get)); + public static final RegistryObject CHUNK_CONTROLLER = APRegistration.ITEMS.register("chunk_controller", () -> new APItem(new Item.Properties().stacksTo(16), APConfig.PERIPHERALS_CONFIG.enableChunkyTurtle)); public static final RegistryObject SMART_GLASSES = APRegistration.ITEMS.register("smart_glasses", () -> new SmartGlassesItem(SmartGlassesMaterials.CHAIN)); public static final RegistryObject SMART_GLASSES_NETHERITE = APRegistration.ITEMS.register("smart_glasses_netherite", () -> new SmartGlassesItem(SmartGlassesMaterials.NETHERITE)); - public static final RegistryObject COMPUTER_TOOL = APRegistration.ITEMS.register("computer_tool", () -> new APItem(new Item.Properties().stacksTo(1), null, null, () -> true)); + public static final RegistryObject COMPUTER_TOOL = APRegistration.ITEMS.register("computer_tool", () -> new APItem(new Item.Properties().stacksTo(1), () -> true)); public static final RegistryObject MEMORY_CARD = APRegistration.ITEMS.register("memory_card", MemoryCardItem::new); - public static final RegistryObject END_AUTOMATA_CORE = APRegistration.ITEMS.register("end_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), CCRegistration.ID.END_AUTOMATA, null, APConfig.METAPHYSICS_CONFIG.enableEndAutomataCore)); + public static final RegistryObject END_AUTOMATA_CORE = APRegistration.ITEMS.register("end_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableEndAutomataCore)); - public static final RegistryObject HUSBANDRY_AUTOMATA_CORE = APRegistration.ITEMS.register("husbandry_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), CCRegistration.ID.WEAK_AUTOMATA, null, APConfig.METAPHYSICS_CONFIG.enableHusbandryAutomataCore)); + public static final RegistryObject HUSBANDRY_AUTOMATA_CORE = APRegistration.ITEMS.register("husbandry_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableHusbandryAutomataCore)); - public static final RegistryObject WEAK_AUTOMATA_CORE = APRegistration.ITEMS.register("weak_automata_core", () -> new WeakAutomataCore(new Item.Properties().stacksTo(1), CCRegistration.ID.WEAK_AUTOMATA, null)); + public static final RegistryObject WEAK_AUTOMATA_CORE = APRegistration.ITEMS.register("weak_automata_core", () -> new WeakAutomataCore(new Item.Properties().stacksTo(1))); - public static final RegistryObject OVERPOWERED_WEAK_AUTOMATA_CORE = APRegistration.ITEMS.register("overpowered_weak_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), CCRegistration.ID.OP_WEAK_AUTOMATA, null, APConfig.METAPHYSICS_CONFIG.enableWeakAutomataCore)); + public static final RegistryObject OVERPOWERED_WEAK_AUTOMATA_CORE = APRegistration.ITEMS.register("overpowered_weak_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableWeakAutomataCore)); - public static final RegistryObject OVERPOWERED_END_AUTOMATA_CORE = APRegistration.ITEMS.register("overpowered_end_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), CCRegistration.ID.OP_END_AUTOMATA, null, APConfig.METAPHYSICS_CONFIG.enableEndAutomataCore)); + public static final RegistryObject OVERPOWERED_END_AUTOMATA_CORE = APRegistration.ITEMS.register("overpowered_end_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableEndAutomataCore)); - public static final RegistryObject OVERPOWERED_HUSBANDRY_AUTOMATA_CORE = APRegistration.ITEMS.register("overpowered_husbandry_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), CCRegistration.ID.OP_HUSBANDRY_AUTOMATA, null, APConfig.METAPHYSICS_CONFIG.enableHusbandryAutomataCore)); + public static final RegistryObject OVERPOWERED_HUSBANDRY_AUTOMATA_CORE = APRegistration.ITEMS.register("overpowered_husbandry_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableHusbandryAutomataCore)); public static void register() { } From a2af4b5c5150f00c012659ad84abfac2fd7698c3 Mon Sep 17 00:00:00 2001 From: Srendi Date: Thu, 9 Mar 2023 12:52:34 +0100 Subject: [PATCH 021/228] Add a new memory card texture with a bounded property --- build.gradle | 12 ++++++------ gradle.properties | 18 +++++++++--------- gradle/wrapper/gradle-wrapper.properties | 2 +- .../client/ClientRegistry.java | 2 ++ .../client/ItemPropertiesRegistry.java | 18 ++++++++++++++++++ .../common/util/inventory/InventoryUtil.java | 4 ++-- .../models/item/memory_card.json | 12 ++++++++++-- .../models/item/memory_card_bounded.json | 6 ++++++ .../textures/item/memory_card.png | Bin 708 -> 702 bytes .../textures/item/memory_card_bounded.png | Bin 0 -> 699 bytes src/main/resources/pack.mcmeta | 3 +-- 11 files changed, 55 insertions(+), 22 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/client/ItemPropertiesRegistry.java create mode 100644 src/main/resources/assets/advancedperipherals/models/item/memory_card_bounded.json create mode 100644 src/main/resources/assets/advancedperipherals/textures/item/memory_card_bounded.png diff --git a/build.gradle b/build.gradle index 1033bedda..02e85086b 100644 --- a/build.gradle +++ b/build.gradle @@ -35,7 +35,7 @@ apply plugin: 'org.parchmentmc.librarian.forgegradle' java.toolchain.languageVersion = JavaLanguageVersion.of(17) wrapper { - gradleVersion = '7.5' + gradleVersion = '7.6.1' distributionType = Wrapper.DistributionType.ALL } @@ -293,11 +293,11 @@ dependencies { // Minecolonies // Change to compileOnly when running `runData` - compileOnly fg.deobf("com.ldtteam:minecolonies:${minecolonies_version}") - compileOnly fg.deobf("com.ldtteam:structurize:${structurize_version}") - compileOnly fg.deobf("com.ldtteam:multi-piston:${multipiston_version}") - compileOnly fg.deobf("com.ldtteam:domum_ornamentum:${domumornamentum_version}:universal") - compileOnly fg.deobf("com.ldtteam:blockui:${blockui_version}") + implementation fg.deobf("com.ldtteam:minecolonies:${minecolonies_version}") + implementation fg.deobf("com.ldtteam:structurize:${structurize_version}") + implementation fg.deobf("com.ldtteam:multipiston:${multipiston_version}") + implementation fg.deobf("com.ldtteam:domum_ornamentum:${domumornamentum_version}:universal") + implementation fg.deobf("com.ldtteam:blockui:${blockui_version}") //Patchouli runtimeOnly fg.deobf("vazkii.patchouli:Patchouli:${patchouli_version}") diff --git a/gradle.properties b/gradle.properties index 308214a02..46521f01d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,26 +21,26 @@ ttoolkit_version=0.1.3 # Mod dependencies cc_version=1.103.1 curios_version=1.19.3-5.1.1.2 -minecolonies_version=1.19.2-1.0.1060-ALPHA -appliedenergistics_version=13.0.9-beta -patchouli_version=1.19.2-76 -refinedstorage_version=1.11.1 +minecolonies_version=1.19.3-1.0.1275-ALPHA +appliedenergistics_version=13.0.10-beta +patchouli_version=1.19.3-78 +refinedstorage_version=1.11.5 botania_version=1.19.2-436-SNAPSHOT create_version=0.5.0.f-15 mekanism_version=1.19.2-10.3.5.474 # Mod dependencies which are needed for other mods # For minecolonies -structurize_version=1.19.2-1.0.452-ALPHA -domumornamentum_version=1.19-1.0.58-ALPHA -blockui_version=1.19-0.0.64-ALPHA -multipiston_version=1.19-1.2.14-ALPHA +structurize_version=1.19.3-1.0.474-ALPHA +domumornamentum_version=1.19.3-1.0.78-ALPHA +blockui_version=1.19.3-0.0.66-ALPHA +multipiston_version=1.19.3-1.2.26-ALPHA # For create flywheel_version=0.6.8.a-1 # Mod dependencies for testing stuff(Only used in the dev environment) -jei_version=1.19.3-forge:12.1.1.13 +jei_version=1.19.3-forge:12.3.0.18 # Credentials for the intelligence repository spaceUsername = Srendi diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8fad3f5a9..31cca4913 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java b/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java index c5fae8259..079a1fa43 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java +++ b/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java @@ -50,6 +50,8 @@ public static void onClientSetup(FMLClientSetupEvent event) { ComputerCraftAPIClient.registerTurtleUpgradeModeller(CCRegistration.HUSBANDRY_TURTLE.get(), new MetaTurtleUpgradeModeller<>()); ComputerCraftAPIClient.registerTurtleUpgradeModeller(CCRegistration.END_TURTLE.get(), new MetaTurtleUpgradeModeller<>()); ComputerCraftAPIClient.registerTurtleUpgradeModeller(CCRegistration.WEAK_TURTLE.get(), new MetaTurtleUpgradeModeller<>()); + + ItemPropertiesRegistry.register(); } @SubscribeEvent diff --git a/src/main/java/de/srendi/advancedperipherals/client/ItemPropertiesRegistry.java b/src/main/java/de/srendi/advancedperipherals/client/ItemPropertiesRegistry.java new file mode 100644 index 000000000..7fa4aa3b7 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/client/ItemPropertiesRegistry.java @@ -0,0 +1,18 @@ +package de.srendi.advancedperipherals.client; + +import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.common.setup.APItems; +import net.minecraft.client.renderer.item.ItemProperties; +import net.minecraft.resources.ResourceLocation; + +public class ItemPropertiesRegistry { + + public static void register() { + ItemProperties.register(APItems.MEMORY_CARD.get(), new ResourceLocation(AdvancedPeripherals.MOD_ID, "bounded"), (stack, level, entity, seed) -> { + boolean bounded = stack.getOrCreateTag().contains("owner"); + + return bounded ? 1 : 0; + }); + } + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/InventoryUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/InventoryUtil.java index b31523048..cd761543a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/InventoryUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/InventoryUtil.java @@ -10,11 +10,11 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.capability.IFluidHandler; -import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.items.wrapper.InvWrapper; @@ -27,7 +27,7 @@ public class InventoryUtil { public static IItemHandler extractHandler(@Nullable Object object) { if (object instanceof ICapabilityProvider capabilityProvider) { - LazyOptional cap = capabilityProvider.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY); + LazyOptional cap = capabilityProvider.getCapability(ForgeCapabilities.ITEM_HANDLER); if (cap.isPresent()) return cap.orElseThrow(NullPointerException::new); } diff --git a/src/main/resources/assets/advancedperipherals/models/item/memory_card.json b/src/main/resources/assets/advancedperipherals/models/item/memory_card.json index 0579cb7a6..c39681fc7 100644 --- a/src/main/resources/assets/advancedperipherals/models/item/memory_card.json +++ b/src/main/resources/assets/advancedperipherals/models/item/memory_card.json @@ -1,6 +1,14 @@ { - "parent": "item/generated", + "parent": "minecraft:item/generated", "textures": { "layer0": "advancedperipherals:item/memory_card" - } + }, + "overrides": [ + { + "predicate": { + "advancedperipherals:bounded": 1 + }, + "model": "advancedperipherals:item/memory_card_bounded" + } + ] } \ No newline at end of file diff --git a/src/main/resources/assets/advancedperipherals/models/item/memory_card_bounded.json b/src/main/resources/assets/advancedperipherals/models/item/memory_card_bounded.json new file mode 100644 index 000000000..cf7733990 --- /dev/null +++ b/src/main/resources/assets/advancedperipherals/models/item/memory_card_bounded.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "advancedperipherals:item/memory_card_bounded" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/advancedperipherals/textures/item/memory_card.png b/src/main/resources/assets/advancedperipherals/textures/item/memory_card.png index 089f0e39c492b08c24efc9f4924e3444ea7d38b9..27df1d9f4374d215f0ffe85a37dc7db8927be606 100644 GIT binary patch delta 289 zcmV++0p9+^1-=EarvZNgNklUu6998A8DgkiuxbxnbAWc(@G1PS({^9)W3IJ8*gNQ*@;zkpi nronqpr-k3z_)8hPHSPsp|B`PlWn^?d00000NkvXXu0mjfbfbnh delta 295 zcmV+?0oeY&1;hogrvZNmNkl}Vng{=l-$mMK%I`2ay|{DMIK zW^1z`Da6XgCQZITu=QI615Ref!rdTDvb#3=y2spm-@R`h{C7oD4@FUUr4%B9a}I#I zt^>RrLblc-B9vw64-!yH@rb5r8lLnCZQJtT6xP}RJDZAdq&0uPWp z_%w#o=6UEN6_O_%hzM1`=H;s3qQB$yx&-sFjSvCDE=C;~W4>)`O=sXTs)zn3c~W2l z1mNwsq_<$L9lmp~fOC${z`4IiL;}&h0^7;kI5WlQ^qrOGxnEUFpQfo_RZE{`S#U(K t;|{v6W4<^ej$t3Zh)I&4Tx04R}lkvmHRK@^3*JVen*3PnULQmCYeAPQnB5lj;;k_bj^k~NzMyX&%> zAi-9!u?Sd*Hogk~fwqFJf*>e@h>d^1S0l3CF+xOimf8DpX3k~i4EU3VX1c*4Fs-ta zO2i|x*||vbBS8Xm5hj|`Tze`#nc?5@c8yQft3lQ4|9yXsw#9<0fv-h)RI{D3@VIbt zrEDwS5bo4UxkceU;g}-_6h2pazRnMdi*||0C;8#5(#UGsi!CJ{Ng`>iKrcu$p z&!cVONPJ}!amM|zYDAkh8{`L)h`KDPGk0yVcDvmgcl*AhowIW>$ zQgzV_@)=ZB?!WVN^^xIv_fQ;~?mh3hADTDeqvm<<`=0l40D(I=wHp3q$!Y9W^jbsf z+lBBN9G^9`{1%+7L-(znb8=r&K&D^U;pqt4v(Rw~t@HJ)zSlXtfy}Br(FJVpz<}%z zFMI;rg=hLEWA+aK0093Eyum%`+e_y2ZtK`ZWKka4a4wHk#ml+ zEC)TnPoXgeRYgP)5pJJfko5`?K~+i9)I)*}a5{V7Jb%O(eumr;wm6H`{MO!cNY3y8|qfIjYKWT>)UDxcAksFr;Z3pTou59qfbqBw$om*vXW( hZE?>1&o>?lz5!bDZ#f#Oo=N}!002ovPDHLkV1le|LYe>o literal 0 HcmV?d00001 diff --git a/src/main/resources/pack.mcmeta b/src/main/resources/pack.mcmeta index 1c0067a65..4cf3c0150 100644 --- a/src/main/resources/pack.mcmeta +++ b/src/main/resources/pack.mcmeta @@ -1,7 +1,6 @@ { "pack": { "description": "Advanced peripherals resources", - "pack_format": 8, - "_comment": "A pack_format of 6 requires json lang files and some texture changes from 1.16.2. Note: we require v6 pack meta for all mods." + "pack_format": 10 } } From 8e9aaf49589f7f4966de8d8c1673113ce160dc1a Mon Sep 17 00:00:00 2001 From: Srendi Date: Thu, 9 Mar 2023 23:13:10 +0100 Subject: [PATCH 022/228] Added an inventory and an item handler for the glasses Items will be saved in the stack but the slots are WIP. --- .../client/ClientRegistry.java | 5 +- .../container/SmartGlassesContainer.java | 78 ++++++++-- .../common/container/SmartGlassesScreen.java | 44 ++++++ .../common/items/SmartGlassesItem.java | 25 +++- .../common/setup/APContainerTypes.java | 2 +- .../smartglasses/SmartGlassesComputer.java | 2 +- .../smartglasses/SmartGlassesItemHandler.java | 138 ++++++++++++++++++ .../SmartGlassesMenuProvider.java | 11 +- .../textures/gui/corners_glasses.png | Bin 0 -> 999 bytes .../textures/gui/smart_glasses_gui.png | Bin 0 -> 1816 bytes 10 files changed, 286 insertions(+), 19 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesScreen.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java create mode 100644 src/main/resources/assets/advancedperipherals/textures/gui/corners_glasses.png create mode 100644 src/main/resources/assets/advancedperipherals/textures/gui/smart_glasses_gui.png diff --git a/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java b/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java index 079a1fa43..56c0c958f 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java +++ b/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java @@ -2,11 +2,10 @@ import dan200.computercraft.api.client.ComputerCraftAPIClient; import dan200.computercraft.api.client.turtle.TurtleUpgradeModeller; -import dan200.computercraft.client.gui.ComputerScreen; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.client.renderer.DistanceDetectorRenderer; import de.srendi.advancedperipherals.common.container.InventoryManagerScreen; -import de.srendi.advancedperipherals.common.container.SmartGlassesContainer; +import de.srendi.advancedperipherals.common.container.SmartGlassesScreen; import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; import de.srendi.advancedperipherals.common.setup.APContainerTypes; import de.srendi.advancedperipherals.common.setup.CCRegistration; @@ -36,7 +35,7 @@ public static void registerModels(ModelEvent.RegisterAdditional event) { @SubscribeEvent public static void onClientSetup(FMLClientSetupEvent event) { MenuScreens.register(APContainerTypes.INVENTORY_MANAGER_CONTAINER.get(), InventoryManagerScreen::new); - MenuScreens.register(APContainerTypes.SMART_GLASSES_CONTAINER.get(), ComputerScreen::new); + MenuScreens.register(APContainerTypes.SMART_GLASSES_CONTAINER.get(), SmartGlassesScreen::new); ComputerCraftAPIClient.registerTurtleUpgradeModeller(CCRegistration.CHUNKY_TURTLE.get(), TurtleUpgradeModeller.flatItem()); ComputerCraftAPIClient.registerTurtleUpgradeModeller(CCRegistration.COMPASS_TURTLE.get(), TurtleUpgradeModeller.flatItem()); diff --git a/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java b/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java index 889c25712..2a10b02ce 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java @@ -5,28 +5,88 @@ import dan200.computercraft.shared.computer.inventory.AbstractComputerMenu; import dan200.computercraft.shared.network.container.ComputerContainerData; import de.srendi.advancedperipherals.common.setup.APContainerTypes; +import de.srendi.advancedperipherals.common.setup.APItems; +import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; +import net.minecraftforge.common.capabilities.ForgeCapabilities; +import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.items.SlotItemHandler; import org.jetbrains.annotations.NotNull; import java.util.function.Predicate; public class SmartGlassesContainer extends AbstractComputerMenu { + public static final int BORDER = 8; + public static final int PLAYER_START_Y = 134; + public static final int TURTLE_START_X = SIDEBAR_WIDTH + 175; + public static final int PLAYER_START_X = SIDEBAR_WIDTH + BORDER; - public SmartGlassesContainer(int id, Predicate canUse, - ServerComputer computer - ) { - super(APContainerTypes.SMART_GLASSES_CONTAINER.get(), id, canUse, ComputerFamily.ADVANCED, computer, null); + public SmartGlassesContainer(int id, Predicate canUse, ServerComputer computer, Inventory playerInventory, IItemHandler inventory, ComputerContainerData data) { + super(APContainerTypes.SMART_GLASSES_CONTAINER.get(), id, canUse, ComputerFamily.ADVANCED, computer, data); + // Turtle inventory + for (var y = 0; y < 4; y++) { + for (var x = 0; x < 4; x++) { + addSlot(new SlotItemHandler(inventory, x + y * 4, TURTLE_START_X + 1 + x * 18, PLAYER_START_Y + 1 + y * 18)); + } + } + + // Player inventory + for (var y = 0; y < 3; y++) { + for (var x = 0; x < 9; x++) { + addSlot(new Slot(playerInventory, x + y * 9 + 9, PLAYER_START_X + x * 18, PLAYER_START_Y + 1 + y * 18)); + } + } + + // Player hotbar + for (var x = 0; x < 9; x++) { + addSlot(new Slot(playerInventory, x, PLAYER_START_X + x * 18, PLAYER_START_Y + 3 * 18 + 5)); + } } - public SmartGlassesContainer(int id, Predicate predicate, ServerComputer computer, ComputerContainerData data) { - super(APContainerTypes.SMART_GLASSES_CONTAINER.get(), id, predicate, ComputerFamily.ADVANCED, computer, data); - getTerminal().resize(48, 48); + public SmartGlassesContainer(int id, Predicate predicate, ServerComputer computer, ComputerContainerData data, Inventory player) { + this( id, predicate, computer, player, player.getSelected().getCapability(ForgeCapabilities.ITEM_HANDLER).resolve().get(), data); + + //getTerminal().resize(48, 48); } + @NotNull @Override - public ItemStack quickMoveStack(@NotNull Player pPlayer, int pIndex) { - return null; + public ItemStack quickMoveStack(@NotNull Player player, int index) { + ItemStack itemstack = ItemStack.EMPTY; + Slot slot = this.slots.get(index); + if (slot.hasItem()) { + ItemStack itemstack1 = slot.getItem(); + itemstack = itemstack1.copy(); + if (index >= 36) { + if (!this.moveItemStackTo(itemstack1, 0, 36, true)) { + return ItemStack.EMPTY; + } + } else if (index <= 35) { + if (itemstack1.getItem().equals(APItems.MEMORY_CARD.get())) { + if (!this.moveItemStackTo(itemstack1, 36, 37, true)) { + return ItemStack.EMPTY; + } + } + } else if (!this.moveItemStackTo(itemstack1, 0, 36, false)) { + return ItemStack.EMPTY; + } + + if (itemstack1.isEmpty()) { + slot.set(ItemStack.EMPTY); + } else { + slot.setChanged(); + } + + if (itemstack1.getCount() == itemstack.getCount()) { + return ItemStack.EMPTY; + } + + slot.onTake(player, itemstack1); + } + + return itemstack; } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesScreen.java b/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesScreen.java new file mode 100644 index 000000000..2b9d8705d --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesScreen.java @@ -0,0 +1,44 @@ +package de.srendi.advancedperipherals.common.container; + +import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.PoseStack; +import dan200.computercraft.client.gui.AbstractComputerScreen; +import dan200.computercraft.client.gui.widgets.ComputerSidebar; +import dan200.computercraft.client.gui.widgets.TerminalWidget; +import dan200.computercraft.shared.computer.inventory.AbstractComputerMenu; +import de.srendi.advancedperipherals.AdvancedPeripherals; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Inventory; + +import static dan200.computercraft.shared.turtle.inventory.TurtleMenu.*; + +public class SmartGlassesScreen extends AbstractComputerScreen { + + private static final ResourceLocation BACKGROUND = new ResourceLocation(AdvancedPeripherals.MOD_ID, "textures/gui/smart_glasses_gui.png"); + public static final ResourceLocation SIDEBAR = new ResourceLocation(AdvancedPeripherals.MOD_ID, "textures/gui/corners_glasses.png"); + + private static final int TEX_WIDTH = 254; + private static final int TEX_HEIGHT = 217; + + public SmartGlassesScreen(SmartGlassesContainer container, Inventory player, Component title) { + super(container, player, title, BORDER); + + imageWidth = TEX_WIDTH + AbstractComputerMenu.SIDEBAR_WIDTH; + imageHeight = TEX_HEIGHT; + } + + @Override + protected TerminalWidget createTerminal() { + return new TerminalWidget(terminalData, input, leftPos + BORDER + AbstractComputerMenu.SIDEBAR_WIDTH, topPos + BORDER); + } + + @Override + protected void renderBg(PoseStack transform, float partialTicks, int mouseX, int mouseY) { + RenderSystem.setShaderTexture(0, BACKGROUND); + blit(transform, leftPos + AbstractComputerMenu.SIDEBAR_WIDTH, topPos, 0, 0, TEX_WIDTH, TEX_HEIGHT); + + RenderSystem.setShaderTexture(0, SIDEBAR); + ComputerSidebar.renderBackground(transform, leftPos, topPos + sidebarYOffset); + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java index b3f97c232..801feee99 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java @@ -14,8 +14,11 @@ import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesAPI; import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesComputer; +import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesItemHandler; import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesMenuProvider; import net.minecraft.ChatFormatting; +import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; @@ -32,6 +35,11 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.level.Level; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.ForgeCapabilities; +import net.minecraftforge.common.capabilities.ICapabilityProvider; +import net.minecraftforge.common.util.LazyOptional; +import net.minecraftforge.items.IItemHandler; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -51,6 +59,20 @@ public SmartGlassesItem(ArmorMaterial material) { super(material, EquipmentSlot.HEAD, new Properties().stacksTo(1)); } + @Nullable + @Override + public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundTag nbt) { + return new ICapabilityProvider() { + @NotNull + @Override + public LazyOptional getCapability(@NotNull Capability cap, @Nullable Direction side) { + if(cap == ForgeCapabilities.ITEM_HANDLER) + return LazyOptional.of(() -> new SmartGlassesItemHandler(stack)).cast(); + return LazyOptional.empty(); + } + }; + } + private boolean tick(ItemStack stack, Level world, Entity entity, SmartGlassesComputer computer) { computer.setLevel((ServerLevel) world); @@ -110,7 +132,8 @@ public InteractionResultHolder use(Level world, Player player, @NotNu var stop = false; if (!stop) { var isTypingOnly = hand == InteractionHand.OFF_HAND; - new ComputerContainerData(computer, stack).open(player, new SmartGlassesMenuProvider(computer, stack, this, hand, isTypingOnly)); + LazyOptional itemHandler = stack.getCapability(ForgeCapabilities.ITEM_HANDLER); + new ComputerContainerData(computer, stack).open(player, new SmartGlassesMenuProvider(computer, stack, this, hand, itemHandler.resolve().get())); } } return new InteractionResultHolder<>(InteractionResult.sidedSuccess(world.isClientSide), stack); diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java index e41f3e629..3d5a6c62c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java @@ -19,7 +19,7 @@ public class APContainerTypes { })); public static final RegistryObject> SMART_GLASSES_CONTAINER = APRegistration.CONTAINER_TYPES.register("smart_glasses_container", () -> ContainerData.toType(ComputerContainerData::new, - (id, inv, data) -> new SmartGlassesContainer(id, player -> true, null, data) + (id, inv, data) -> new SmartGlassesContainer(id, player -> true, null, data, inv) )); public static void register() { diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java index 685c80236..44542b705 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java @@ -35,7 +35,7 @@ public class SmartGlassesComputer extends ServerComputer implements IPocketAcces private final Set tracking = new HashSet<>(); public SmartGlassesComputer(ServerLevel world, BlockPos position, int computerID, @Nullable String label, ComputerFamily family) { - super(world, position, computerID, label, family, 48, 48); + super(world, position, computerID, label, family, 39, 13); } @Nullable diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java new file mode 100644 index 000000000..8ab3b6e0b --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java @@ -0,0 +1,138 @@ +package de.srendi.advancedperipherals.common.smartglasses; + +import de.srendi.advancedperipherals.common.setup.APItems; +import net.minecraft.core.NonNullList; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.ContainerHelper; +import net.minecraft.world.item.ItemStack; +import net.minecraftforge.common.util.INBTSerializable; +import net.minecraftforge.items.IItemHandlerModifiable; +import net.minecraftforge.items.ItemHandlerHelper; +import org.jetbrains.annotations.NotNull; + +import javax.annotation.Nonnull; + +public class SmartGlassesItemHandler implements IItemHandlerModifiable, INBTSerializable { + + private static final int SLOTS = 16; + + private final NonNullList items = NonNullList.withSize(SLOTS, ItemStack.EMPTY); + private final ItemStack stack; + + public SmartGlassesItemHandler(ItemStack stack) { + this.stack = stack; + deserializeNBT(stack.getOrCreateTagElement("Items")); + } + + @Override + public int getSlots() { + return items.size(); + } + + @NotNull + @Override + public ItemStack getStackInSlot(int slot) { + return items.get(slot); + } + + @Override + @Nonnull + public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) { + if (stack.isEmpty()) + return ItemStack.EMPTY; + + if (!isItemValid(slot, stack)) + return stack; + + ItemStack existing = getStackInSlot(slot); + + int limit = getSlotLimit(slot); + + if (!existing.isEmpty()) { + if (!ItemHandlerHelper.canItemStacksStack(stack, existing)) + return stack; + + limit -= existing.getCount(); + } + + if (limit <= 0) + return stack; + + boolean reachedLimit = stack.getCount() > limit; + + if (!simulate) { + if (existing.isEmpty()) { + setStackInSlot(slot, reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, limit) : stack); + } else { + existing.grow(reachedLimit ? limit : stack.getCount()); + } + + setChanged(); + } + + return reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, stack.getCount() - limit) : ItemStack.EMPTY; + } + + @Override + @Nonnull + public ItemStack extractItem(int slot, int amount, boolean simulate) { + if (amount == 0) + return ItemStack.EMPTY; + + ItemStack existing = getStackInSlot(slot); + + if (existing.isEmpty()) + return ItemStack.EMPTY; + + int toExtract = Math.min(amount, existing.getMaxStackSize()); + + if (existing.getCount() <= toExtract) { + if (!simulate) { + setStackInSlot(slot, ItemStack.EMPTY); + return existing; + } else { + return existing.copy(); + } + } else { + if (!simulate) { + setStackInSlot(slot, ItemHandlerHelper.copyStackWithSize(existing, existing.getCount() - toExtract)); + setChanged(); + } + + return ItemHandlerHelper.copyStackWithSize(existing, toExtract); + } + + } + + @Override + public int getSlotLimit(int slot) { + return 64; + } + + @Override + public boolean isItemValid(int slot, @NotNull ItemStack stack) { + return !stack.is(APItems.SMART_GLASSES.get()); + } + + @Override + public void setStackInSlot(int slot, @NotNull ItemStack stack) { + items.set(slot, stack); + setChanged(); + } + + public void setChanged() { + stack.getOrCreateTag().put("Items", serializeNBT()); + } + + @Override + public CompoundTag serializeNBT() { + CompoundTag itemNBT = new CompoundTag(); + ContainerHelper.saveAllItems(itemNBT, items); + return itemNBT; + } + + @Override + public void deserializeNBT(CompoundTag nbt) { + ContainerHelper.loadAllItems(nbt, items); + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesMenuProvider.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesMenuProvider.java index 3e8d7bd29..e4fa014cf 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesMenuProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesMenuProvider.java @@ -10,6 +10,7 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; +import net.minecraftforge.items.IItemHandler; import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; @@ -19,17 +20,19 @@ public class SmartGlassesMenuProvider implements MenuProvider { private final Component name; private final SmartGlassesItem item; private final InteractionHand hand; - private final boolean isTypingOnly; - public SmartGlassesMenuProvider(ServerComputer computer, ItemStack stack, SmartGlassesItem item, InteractionHand hand, boolean isTypingOnly) { + private final IItemHandler glassesContainer; + + public SmartGlassesMenuProvider(ServerComputer computer, ItemStack stack, SmartGlassesItem item, InteractionHand hand, IItemHandler glassesContainer) { this.computer = computer; name = stack.getHoverName(); this.item = item; this.hand = hand; - this.isTypingOnly = isTypingOnly; + this.glassesContainer = glassesContainer; } + @NotNull @Override public Component getDisplayName() { return name; @@ -42,7 +45,7 @@ public AbstractContainerMenu createMenu(int id, @NotNull Inventory inventory, @N p -> { return true; }, - computer + computer, inventory, glassesContainer, null ); } } diff --git a/src/main/resources/assets/advancedperipherals/textures/gui/corners_glasses.png b/src/main/resources/assets/advancedperipherals/textures/gui/corners_glasses.png new file mode 100644 index 0000000000000000000000000000000000000000..18cf12823149b6195ab687d0015a1f5a3d098a85 GIT binary patch literal 999 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G!U;i$lZxy-8q?;3=GT*JzX3_ zD(1YsyVv)Pg9zIN!y?wpP0|WV3#Yz4V4Cw}MuGJLQT6D9TqhSXt9vY|J1G3(E%%R) zRkky#{n(O03DNFy%!^aBOcwJ|R4&9y`y{oOeBsP2(%Z)X&FR?N_y`rzL zzcibHYa?^R0Tu=pH3kI(MutXC1`ZzvhlH;NJRrH1TbP_<@)#8i(t&vG0f8CO5NRd` zCSeAF84O^Z%S0uZHUkZr!wU2ULqq&JpvC#_P4-rj7Cg?ce*gQs@b)Br{{OWTzK5Mp z-@0VVxmS$)*3bJ{etA+c3t#);6ve~8o_%5T`Te)LrOLyMmKYOoTLeRiF}cqePafpulv6E58si+}KZR}_PZ@8V#AI*aXaUqJmY%HMGLWymfT zj@P&Uv&kIaXeGmUId8kSzrX+W6`T<#*T^2Q=)3y(@#96UGX3ttb&08)r5k}^JZ;Xy z^pDIy?;j`)iLO`fZ*Mn<-}}}0ckK14dW>eP%hKc@Y2D-EnWBsm$|%8z8UaA5)$NHI zvCIJ-vJ5O~DiWZu{Zn+mu3=j7ynAk)^(KK85^X>qdTB1*mTUhv$4m2T?fZptYcjsw zZrq>r`n^oU{dZZ67fjB!hu1E!>2-j`7KSy5h=d0LL-NUmb0QC$7o7w7{rvg!-D1fK z9BZ<_C7rhP|Ni}Zw`kJG!@u;R3cU9PA9%#xAi6icRDb8J-BpLp_MT;#qbK>`X6ap{ zs|>4md20Ip{=2V4)`79~+|M`SYCoN1(t91m?2iQP5f;#J2c|TXFbL~^JR>eXKG^Hr tGiMWX&84p%K3oXW%*PDMFoOofe`Y_F^FYB_FMSutO`fiPF6*2UngGweOez2X literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/advancedperipherals/textures/gui/smart_glasses_gui.png b/src/main/resources/assets/advancedperipherals/textures/gui/smart_glasses_gui.png new file mode 100644 index 0000000000000000000000000000000000000000..041eadca258e1273ce2222d0925ed2045497a20a GIT binary patch literal 1816 zcmdUwdo&wX9LH}Yo<$!jrYyR4V>_o4I&G;aE0gKG4#MUYs$*zqYKbr;rJc4$+Nnbo zt6EffA{{*{r$e5-?`^P zgV7ddJInw876G68g#iH3FCoChNI%7%yp_CRWrd*+1ID1e3;?6Y0e+uGkZKg7ps**g z4!u+4$4$4khxbz3pai?)XDm#1ACPt~OC}6MBT_4%=PxE$V}m9k`;iVqP&3*76WEb^ z&7`wMx*zSe_E)qV2IXesO0#%|#bUwpoVmO5b(%Z!XxRA41>e)9rKPm=5Uq69SfNxR z<#`mt@v*VnYPGsL&@pZ;ciT5e2g%doJql4V2&n)*Ep}O;5|^2Yl%pthT{)^}gGm_{ zJ{bP7y|U?Jl;6iDCK`*1iae?8PXK2^10XJ6a@Oh(Wq~b$U}qKZae+`03_uSI6q*8< z6)xn{EYkPb9u$2M) z8ofhmDpAjl5Kf$Esp3K4gZ6)`GAHn$C=?1~@~Mi7igB^{KpB4CYfvti7xhhvMJqV2 ze%m^=A1#HwnVT#qb`mN6$eiry(TPpqjAtise{t*8Xc1fo}nV>wNgE-v%w zwOx1jz3lSc`F_Zo30s0vyq`aTyPJZo+St*h>4%l^y)tPYq9gPOIP3beVX*I4AAW85 z3Qp$k3wR@MOI21n(AGS6(Wmb@c!3DZO`9`0R?|aGLSJ2RHGVV6W1A@^zA+NFOJ~9i zd`|QE{CL53RIAtkE*yB9eWue9$2`9U@B^tqdt|5L@$rYw-Zo_)mE zHYF#gy?Y)WNxl; zd`UhbA)y#jsWeT5IJSL^vTT(_dE?iiY%5qIa)8MA2zYvW_@ zH$0ko(8FXGU@#*D8%{>G>dKn;OC58#+!&FJV&7*o=tDnwd(YfiQwZ;hCMV;OPDcIM zRcRm9E?c`A9UV=hb+|eK^Y9qLp+_Ud<>loxTFD43Vf5Kz0Jpo)pg+o!oes?zPZ_FH zdnTmkKu~ZThHQi5xeMfj8BPR#vM`+)PcVXwMy`wAl{%tP0?SxrP+< zH7^vZ@kXj#qtWyf4J>Wn0!a4b3#3>lC#SAXgZ?_lP6MuVcz;m1bfK*h>_H;2bK79% z;x@U?Do;7tMPF8mvzY^4)i-YQc)XG(u5+diA17p~7pEVVa8f*6P?k1Pa(zKc{Tu9> zp*-2Ib>8H7p6rD`jG;99Hs*cGl&x}pUZ4+yLe7E^ cuMG)e-B?1p$R4{ld2quO@L8}Q<8VUZpJespQ2+n{ literal 0 HcmV?d00001 From 7f582ee1a233bbb47dfbe833be8d074ef842ccf0 Mon Sep 17 00:00:00 2001 From: DenizD Date: Mon, 13 Mar 2023 15:42:53 +0100 Subject: [PATCH 023/228] Added a smart glasses interface --- .../renderer/DistanceDetectorRenderer.java | 2 +- .../common/addons/APAddons.java | 23 +++++- .../container/SmartGlassesContainer.java | 4 +- .../common/data/RecipesProvider.java | 13 ++-- .../items/SmartGlassesInterfaceItem.java | 71 +++++++++++++++++ .../common/items/SmartGlassesItem.java | 73 +++++++++--------- .../common/setup/APContainerTypes.java | 2 +- .../common/setup/APItems.java | 7 +- .../SmartGlassesMenuProvider.java | 10 +-- .../resources/META-INF/accesstransformer.cfg | 2 +- .../{item => slot}/empty_glasses_slot.png | Bin .../data/curios/tags/items/glasses.json | 3 +- 12 files changed, 146 insertions(+), 64 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesInterfaceItem.java rename src/main/resources/assets/advancedperipherals/textures/{item => slot}/empty_glasses_slot.png (100%) diff --git a/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java b/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java index 77222a875..a118d4322 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java +++ b/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java @@ -34,7 +34,7 @@ public void render(@NotNull DistanceDetectorEntity pBlockEntity, float pPartialT renderBeaconBeam(pBlockEntity, pPoseStack, pBufferSource, BeaconRenderer.BEAM_LOCATION, pPartialTick, 1, i, 2, 1, EnumColor.DARK_RED.getRgb(), 0.05f, 0.09f); } - public boolean shouldRenderOffScreen(DistanceDetectorEntity pBlockEntity) { + public boolean shouldRenderOffScreen(@NotNull DistanceDetectorEntity pBlockEntity) { return true; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java b/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java index 6f2f21623..b5052f08e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java @@ -2,13 +2,20 @@ import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.addons.refinedstorage.RefinedStorage; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.InterModComms; import net.minecraftforge.fml.ModList; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent; +import top.theillusivec4.curios.api.CuriosApi; +import top.theillusivec4.curios.api.SlotResult; import top.theillusivec4.curios.api.SlotTypeMessage; +import java.util.List; + @Mod.EventBusSubscriber(modid = AdvancedPeripherals.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) public class APAddons { @@ -42,6 +49,20 @@ public static void interModComms(InterModEnqueueEvent event) { if (!curiosLoaded) return; - InterModComms.sendTo("curios", SlotTypeMessage.REGISTER_TYPE, () -> new SlotTypeMessage.Builder("glasses").size(1).build()); + InterModComms.sendTo("curios", SlotTypeMessage.REGISTER_TYPE, + () -> new SlotTypeMessage.Builder("glasses") + .size(1) + .icon(new ResourceLocation(AdvancedPeripherals.MOD_ID, "slot/empty_glasses_slot")) + .build()); + } + + public static ItemStack getCurioGlasses(Player player) { + if(!curiosLoaded) + return ItemStack.EMPTY; + List curioSlots = CuriosApi.getCuriosHelper().findCurios(player,"glasses"); + if(curioSlots.isEmpty()) + return ItemStack.EMPTY; + + return curioSlots.get(0).stack(); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java b/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java index 2a10b02ce..17a0589e2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java @@ -45,8 +45,8 @@ public SmartGlassesContainer(int id, Predicate canUse, ServerComputer co } } - public SmartGlassesContainer(int id, Predicate predicate, ServerComputer computer, ComputerContainerData data, Inventory player) { - this( id, predicate, computer, player, player.getSelected().getCapability(ForgeCapabilities.ITEM_HANDLER).resolve().get(), data); + public SmartGlassesContainer(int id, Predicate predicate, ServerComputer computer, ComputerContainerData data, Inventory player, ItemStack glasses) { + this( id, predicate, computer, player, glasses.getCapability(ForgeCapabilities.ITEM_HANDLER).resolve().get(), data); //getTerminal().resize(48, 48); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java index 9f300548f..71e4682da 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java @@ -6,12 +6,7 @@ import de.srendi.advancedperipherals.common.setup.APItems; import de.srendi.advancedperipherals.common.util.RawValue; import net.minecraft.data.PackOutput; -import net.minecraft.data.recipes.FinishedRecipe; -import net.minecraft.data.recipes.RecipeCategory; -import net.minecraft.data.recipes.RecipeProvider; -import net.minecraft.data.recipes.ShapedRecipeBuilder; -import net.minecraft.data.recipes.ShapelessRecipeBuilder; -import net.minecraft.data.recipes.UpgradeRecipeBuilder; +import net.minecraft.data.recipes.*; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.ItemTags; import net.minecraft.world.item.ItemStack; @@ -79,8 +74,10 @@ private void addShaped(@NotNull Consumer consumer) { .define('E', Tags.Items.ENDER_PEARLS) .define('S', Tags.Items.RODS_WOODEN) .define('G', Tags.Items.GLASS_BLACK) - .pattern("GSG") - .pattern(" E ") + .define('C', ModRegistry.Items.COMPUTER_ADVANCED.get()) + .define('M', ModRegistry.Items.WIRELESS_MODEM_ADVANCED.get()) + .pattern("GEG") + .pattern("M C") .unlockedBy("has_item", has(Items.STICK)) .save(consumer); diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesInterfaceItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesInterfaceItem.java new file mode 100644 index 000000000..3df07d864 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesInterfaceItem.java @@ -0,0 +1,71 @@ +package de.srendi.advancedperipherals.common.items; + +import dan200.computercraft.shared.network.container.ComputerContainerData; +import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.common.addons.APAddons; +import de.srendi.advancedperipherals.common.items.base.BaseItem; +import de.srendi.advancedperipherals.common.setup.APItems; +import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesComputer; +import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesMenuProvider; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraftforge.common.capabilities.ForgeCapabilities; +import net.minecraftforge.common.util.LazyOptional; +import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.network.NetworkHooks; +import org.jetbrains.annotations.NotNull; + +public class SmartGlassesInterfaceItem extends BaseItem { + + public SmartGlassesInterfaceItem() { + super(new Properties().stacksTo(1)); + } + + @Override + public InteractionResultHolder use(@NotNull Level world, @NotNull Player player, InteractionHand hand) { + if (world.isClientSide) + return new InteractionResultHolder<>(InteractionResult.PASS, player.getItemInHand(hand)); + + ItemStack findGlasses = player.getItemBySlot(EquipmentSlot.HEAD); + + // In case this method gets executed by the smart glasses interface, we need to check if the glasses may be in the + // curio slot or on the head + if (!findGlasses.is(APItems.SMART_GLASSES.get())) { + if (APAddons.curiosLoaded) findGlasses = APAddons.getCurioGlasses(player); + if (!findGlasses.is(APItems.SMART_GLASSES.get())) { + player.displayClientMessage(Component.translatable("item.advancedperipherals.smartglasses.dontwear"), false); + return InteractionResultHolder.fail(findGlasses); + } + } + + // The constructor of the ComputerContainerData in the lambda wants a final version of this var + ItemStack glasses = findGlasses; + + SmartGlassesItem smartGlasses = (SmartGlassesItem) glasses.getItem(); + + SmartGlassesComputer computer = smartGlasses.createServerComputer((ServerLevel) world, player, player.getInventory(), glasses); + computer.turnOn(); + + LazyOptional itemHandler = glasses.getCapability(ForgeCapabilities.ITEM_HANDLER); + if (itemHandler.resolve().isEmpty()) { + AdvancedPeripherals.debug("There was an issue with the item handler of the glasses while trying to open the gui"); + return InteractionResultHolder.fail(player.getItemInHand(hand)); + } + NetworkHooks.openScreen((ServerPlayer) player, new SmartGlassesMenuProvider(computer, glasses, itemHandler.resolve().get()), (bytes) -> new ComputerContainerData(computer, glasses).toBytes(bytes)); + + return super.use(world, player, hand); + } + + @Override + public boolean isEnabled() { + return true; + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java index 801feee99..742df39c9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java @@ -6,6 +6,7 @@ import dan200.computercraft.api.filesystem.Mount; import dan200.computercraft.api.media.IMedia; import dan200.computercraft.shared.computer.core.ComputerFamily; +import dan200.computercraft.shared.computer.core.ServerComputerRegistry; import dan200.computercraft.shared.computer.core.ServerContext; import dan200.computercraft.shared.computer.items.IComputerItem; import dan200.computercraft.shared.config.Config; @@ -24,7 +25,6 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.world.Container; import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EquipmentSlot; @@ -66,7 +66,7 @@ public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundT @NotNull @Override public LazyOptional getCapability(@NotNull Capability cap, @Nullable Direction side) { - if(cap == ForgeCapabilities.ITEM_HANDLER) + if (cap == ForgeCapabilities.ITEM_HANDLER) return LazyOptional.of(() -> new SmartGlassesItemHandler(stack)).cast(); return LazyOptional.empty(); } @@ -76,23 +76,23 @@ public LazyOptional getCapability(@NotNull Capability cap, @Nullable D private boolean tick(ItemStack stack, Level world, Entity entity, SmartGlassesComputer computer) { computer.setLevel((ServerLevel) world); - var changed = false; + boolean changed = false; // Sync ID - var id = computer.getID(); + int id = computer.getID(); if (id != getComputerID(stack)) { changed = true; setComputerID(stack, id); } // Sync label - var label = computer.getLabel(); + String label = computer.getLabel(); if (!Objects.equal(label, getLabel(stack))) { changed = true; setLabel(stack, label); } - var on = computer.isOn(); + boolean on = computer.isOn(); if (on != isMarkedOn(stack)) { changed = true; stack.getOrCreateTag().putBoolean(NBT_ON, on); @@ -105,7 +105,7 @@ private boolean tick(ItemStack stack, Level world, Entity entity, SmartGlassesCo public void inventoryTick(@NotNull ItemStack stack, Level world, @NotNull Entity entity, int slotNum, boolean selected) { if (world.isClientSide) return; Container inventory = entity instanceof Player player ? player.getInventory() : null; - var computer = createServerComputer((ServerLevel) world, entity, inventory, stack); + SmartGlassesComputer computer = createServerComputer((ServerLevel) world, entity, inventory, stack); computer.keepAlive(); var changed = tick(stack, world, entity, computer); @@ -116,7 +116,7 @@ public void inventoryTick(@NotNull ItemStack stack, Level world, @NotNull Entity public boolean onEntityItemUpdate(ItemStack stack, ItemEntity entity) { if (entity.level.isClientSide || entity.level.getServer() == null) return false; - var computer = getServerComputer(entity.level.getServer(), stack); + SmartGlassesComputer computer = getServerComputer(entity.level.getServer(), stack); if (computer != null && tick(stack, entity.level, entity, computer)) entity.setItem(stack.copy()); return false; } @@ -124,23 +124,24 @@ public boolean onEntityItemUpdate(ItemStack stack, ItemEntity entity) { @NotNull @Override public InteractionResultHolder use(Level world, Player player, @NotNull InteractionHand hand) { - var stack = player.getItemInHand(hand); + ItemStack glasses = player.getItemInHand(hand); + if (!world.isClientSide) { - var computer = createServerComputer((ServerLevel) world, player, player.getInventory(), stack); + SmartGlassesComputer computer = createServerComputer((ServerLevel) world, player, player.getInventory(), glasses); computer.turnOn(); - var stop = false; - if (!stop) { - var isTypingOnly = hand == InteractionHand.OFF_HAND; - LazyOptional itemHandler = stack.getCapability(ForgeCapabilities.ITEM_HANDLER); - new ComputerContainerData(computer, stack).open(player, new SmartGlassesMenuProvider(computer, stack, this, hand, itemHandler.resolve().get())); + LazyOptional itemHandler = glasses.getCapability(ForgeCapabilities.ITEM_HANDLER); + if (itemHandler.resolve().isEmpty()) { + AdvancedPeripherals.debug("There was an issue with the item handler of the glasses while trying to open the gui"); + return InteractionResultHolder.sidedSuccess(player.getItemInHand(hand), world.isClientSide); } + new ComputerContainerData(computer, glasses).open(player, new SmartGlassesMenuProvider(computer, glasses, itemHandler.resolve().get())); } - return new InteractionResultHolder<>(InteractionResult.sidedSuccess(world.isClientSide), stack); + return super.use(world, player, hand); } public ItemStack create(int id, @Nullable String label) { - var result = new ItemStack(this); + ItemStack result = new ItemStack(this); if (id >= 0) result.getOrCreateTag().putInt(NBT_ID, id); if (label != null) result.setHoverName(Component.literal(label)); return result; @@ -157,12 +158,11 @@ public ItemStack withFamily(ItemStack stack, ComputerFamily family) { } @Override - public void appendHoverText(@NotNull ItemStack stack, @javax.annotation.Nullable Level world, @NotNull List list, TooltipFlag flag) { + public void appendHoverText(@NotNull ItemStack stack, @Nullable Level world, @NotNull List list, TooltipFlag flag) { if (flag.isAdvanced() || getLabel(stack) == null) { - var id = getComputerID(stack); + int id = getComputerID(stack); if (id >= 0) { - list.add(Component.translatable("gui.computercraft.tooltip.computer_id", id) - .withStyle(ChatFormatting.GRAY)); + list.add(Component.translatable("gui.computercraft.tooltip.computer_id", id).withStyle(ChatFormatting.GRAY)); } } } @@ -171,13 +171,13 @@ public String getCreatorModId(ItemStack stack) { return AdvancedPeripherals.MOD_ID; } - public SmartGlassesComputer createServerComputer(ServerLevel level, Entity entity, @javax.annotation.Nullable Container inventory, ItemStack stack) { - var sessionID = getSessionID(stack); + public SmartGlassesComputer createServerComputer(ServerLevel level, Entity entity, @Nullable Container inventory, ItemStack stack) { + int sessionID = getSessionID(stack); - var registry = ServerContext.get(level.getServer()).registry(); - var computer = (SmartGlassesComputer) registry.get(sessionID, getInstanceID(stack)); + ServerComputerRegistry registry = ServerContext.get(level.getServer()).registry(); + SmartGlassesComputer computer = (SmartGlassesComputer) registry.get(sessionID, getInstanceID(stack)); if (computer == null) { - var computerID = getComputerID(stack); + int computerID = getComputerID(stack); if (computerID < 0) { computerID = ComputerCraftAPI.createUniqueNumberedSaveDir(level.getServer(), IDAssigner.COMPUTER); setComputerID(stack, computerID); @@ -205,12 +205,13 @@ public static SmartGlassesComputer getServerComputer(MinecraftServer server, Ite } // IComputerItem implementation - private static void setComputerID(ItemStack stack, int computerID) { + protected static void setComputerID(ItemStack stack, int computerID) { stack.getOrCreateTag().putInt(NBT_ID, computerID); } + @Nullable @Override - public @javax.annotation.Nullable String getLabel(ItemStack stack) { + public String getLabel(ItemStack stack) { return IComputerItem.super.getLabel(stack); } @@ -227,7 +228,7 @@ public boolean setLabel(ItemStack stack, @javax.annotation.Nullable String label @Nullable @Override public Mount createDataMount(ItemStack stack, ServerLevel level) { - var id = getComputerID(stack); + int id = getComputerID(stack); if (id >= 0) { return ComputerCraftAPI.createSaveDirMount(level.getServer(), "computer/" + id, Config.computerSpaceLimit); } @@ -235,25 +236,25 @@ public Mount createDataMount(ItemStack stack, ServerLevel level) { } public static int getInstanceID(ItemStack stack) { - var nbt = stack.getTag(); + CompoundTag nbt = stack.getTag(); return nbt != null && nbt.contains(NBT_INSTANCE) ? nbt.getInt(NBT_INSTANCE) : -1; } - private static void setInstanceID(ItemStack stack, int instanceID) { + protected static void setInstanceID(ItemStack stack, int instanceID) { stack.getOrCreateTag().putInt(NBT_INSTANCE, instanceID); } - private static int getSessionID(ItemStack stack) { - var nbt = stack.getTag(); + protected static int getSessionID(ItemStack stack) { + CompoundTag nbt = stack.getTag(); return nbt != null && nbt.contains(NBT_SESSION) ? nbt.getInt(NBT_SESSION) : -1; } - private static void setSessionID(ItemStack stack, int sessionID) { + protected static void setSessionID(ItemStack stack, int sessionID) { stack.getOrCreateTag().putInt(NBT_SESSION, sessionID); } - private static boolean isMarkedOn(ItemStack stack) { - var nbt = stack.getTag(); + protected static boolean isMarkedOn(ItemStack stack) { + CompoundTag nbt = stack.getTag(); return nbt != null && nbt.getBoolean(NBT_ON); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java index 3d5a6c62c..8f7f7da07 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java @@ -19,7 +19,7 @@ public class APContainerTypes { })); public static final RegistryObject> SMART_GLASSES_CONTAINER = APRegistration.CONTAINER_TYPES.register("smart_glasses_container", () -> ContainerData.toType(ComputerContainerData::new, - (id, inv, data) -> new SmartGlassesContainer(id, player -> true, null, data, inv) + (id, inv, data) -> new SmartGlassesContainer(id, player -> true, null, data, inv, data.displayStack()) )); public static void register() { diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java index 464702e0d..8aff2993a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java @@ -1,10 +1,7 @@ package de.srendi.advancedperipherals.common.setup; import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.items.APItem; -import de.srendi.advancedperipherals.common.items.MemoryCardItem; -import de.srendi.advancedperipherals.common.items.SmartGlassesItem; -import de.srendi.advancedperipherals.common.items.WeakAutomataCore; +import de.srendi.advancedperipherals.common.items.*; import de.srendi.advancedperipherals.common.items.base.SmartGlassesMaterials; import net.minecraft.world.item.Item; import net.minecraftforge.registries.RegistryObject; @@ -17,6 +14,8 @@ public class APItems { public static final RegistryObject SMART_GLASSES_NETHERITE = APRegistration.ITEMS.register("smart_glasses_netherite", () -> new SmartGlassesItem(SmartGlassesMaterials.NETHERITE)); + public static final RegistryObject SMART_GLASSES_INTERFACE = APRegistration.ITEMS.register("smart_glasses_interface", SmartGlassesInterfaceItem::new); + public static final RegistryObject COMPUTER_TOOL = APRegistration.ITEMS.register("computer_tool", () -> new APItem(new Item.Properties().stacksTo(1), () -> true)); public static final RegistryObject MEMORY_CARD = APRegistration.ITEMS.register("memory_card", MemoryCardItem::new); diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesMenuProvider.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesMenuProvider.java index e4fa014cf..688915cc6 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesMenuProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesMenuProvider.java @@ -2,9 +2,7 @@ import dan200.computercraft.shared.computer.core.ServerComputer; import de.srendi.advancedperipherals.common.container.SmartGlassesContainer; -import de.srendi.advancedperipherals.common.items.SmartGlassesItem; import net.minecraft.network.chat.Component; -import net.minecraft.world.InteractionHand; import net.minecraft.world.MenuProvider; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; @@ -18,20 +16,14 @@ public class SmartGlassesMenuProvider implements MenuProvider { private final ServerComputer computer; private final Component name; - private final SmartGlassesItem item; - private final InteractionHand hand; - private final IItemHandler glassesContainer; - public SmartGlassesMenuProvider(ServerComputer computer, ItemStack stack, SmartGlassesItem item, InteractionHand hand, IItemHandler glassesContainer) { + public SmartGlassesMenuProvider(ServerComputer computer, ItemStack stack, IItemHandler glassesContainer) { this.computer = computer; name = stack.getHoverName(); - this.item = item; - this.hand = hand; this.glassesContainer = glassesContainer; } - @NotNull @Override public Component getDisplayName() { diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index be93663b7..e26abcd49 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -1,4 +1,4 @@ public net.minecraft.world.level.block.entity.BeaconBlockEntity f_58652_ public net.minecraft.world.level.block.entity.BeaconBlockEntity f_58653_ public-f net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool f_210559_ # rawTemplates -public-f net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool f_210560_ # templates +public-f net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool f_210560_ # templates \ No newline at end of file diff --git a/src/main/resources/assets/advancedperipherals/textures/item/empty_glasses_slot.png b/src/main/resources/assets/advancedperipherals/textures/slot/empty_glasses_slot.png similarity index 100% rename from src/main/resources/assets/advancedperipherals/textures/item/empty_glasses_slot.png rename to src/main/resources/assets/advancedperipherals/textures/slot/empty_glasses_slot.png diff --git a/src/main/resources/data/curios/tags/items/glasses.json b/src/main/resources/data/curios/tags/items/glasses.json index 9c5ee4bb5..1f793687e 100644 --- a/src/main/resources/data/curios/tags/items/glasses.json +++ b/src/main/resources/data/curios/tags/items/glasses.json @@ -1,5 +1,6 @@ { "values": [ - "advancedperipherals:ar_goggles" + "advancedperipherals:smart_glasses", + "advancedperipherals:smart_glasses_netherite" ] } \ No newline at end of file From 7f8cc594ba269f217b386d6d6fc58a86d1ba5647 Mon Sep 17 00:00:00 2001 From: DenizD Date: Tue, 14 Mar 2023 10:54:13 +0100 Subject: [PATCH 024/228] [#423] Fixed that some functions of the me and rs bridge ignore or increasing the count they want to export --- .../common/addons/appliedenergistics/MeFluidHandler.java | 2 +- .../common/addons/appliedenergistics/MeItemHandler.java | 5 +++-- .../common/addons/refinedstorage/RsItemHandler.java | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeFluidHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeFluidHandler.java index 561f7ffcb..8072a777d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeFluidHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeFluidHandler.java @@ -42,7 +42,7 @@ public FluidStack drain(FluidFilter filter, FluidAction simulate) { Pair itemKey = AppEngApi.findAEFluidFromFilter(storageMonitor, null, filter); if(itemKey == null) return FluidStack.EMPTY; - long extracted = storageMonitor.extract(itemKey.getRight(), Math.max(64, filter.getCount()), simulate == FluidAction.SIMULATE ? Actionable.SIMULATE : Actionable.MODULATE, actionSource); + long extracted = storageMonitor.extract(itemKey.getRight(), filter.getCount(), simulate == FluidAction.SIMULATE ? Actionable.SIMULATE : Actionable.MODULATE, actionSource); return new FluidStack(itemKey.getRight().getFluid(), (int) Math.min(extracted, Integer.MAX_VALUE)); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeItemHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeItemHandler.java index 4b260012d..5f8e7e89e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeItemHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeItemHandler.java @@ -12,6 +12,7 @@ /** * Used to transfer item between an inventory and the ME system. + * * @see de.srendi.advancedperipherals.common.addons.computercraft.peripheral.MeBridgePeripheral */ public class MeItemHandler implements IStorageSystemItemHandler { @@ -40,9 +41,9 @@ public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate @Override public ItemStack extractItem(ItemFilter filter, boolean simulate) { Pair itemKey = AppEngApi.findAEStackFromFilter(storageMonitor, null, filter); - if(itemKey == null) + if (itemKey.getRight() == null) return ItemStack.EMPTY; - long extracted = storageMonitor.extract(itemKey.getRight(), Math.max(64, filter.getCount()), simulate ? Actionable.SIMULATE : Actionable.MODULATE, actionSource); + long extracted = storageMonitor.extract(itemKey.getRight(), filter.getCount(), simulate ? Actionable.SIMULATE : Actionable.MODULATE, actionSource); // Safe to cast here, the amount will never be higher than 64 return new ItemStack(itemKey.getRight().getItem(), (int) extracted); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java index 2ad1a9ee8..591421c92 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java @@ -32,7 +32,7 @@ public ItemStack extractItem(ItemFilter filter, boolean simulate) { ItemStack item = RefinedStorage.findStackFromFilter(network, network.getCraftingManager(), filter); if(item == null) return ItemStack.EMPTY; - return network.extractItem(item, Math.max(64, filter.getCount()), filter.getNbt() != null ? IComparer.COMPARE_NBT : IComparer.COMPARE_QUANTITY, simulate ? Action.SIMULATE : Action.PERFORM); + return network.extractItem(item, filter.getCount(), filter.getNbt() != null ? IComparer.COMPARE_NBT : IComparer.COMPARE_QUANTITY, simulate ? Action.SIMULATE : Action.PERFORM); } } From 811b7228dce29b301f2d77c051479f2f75ef8700 Mon Sep 17 00:00:00 2001 From: DenizD Date: Tue, 14 Mar 2023 10:56:07 +0100 Subject: [PATCH 025/228] tidy --- .../common/addons/refinedstorage/RsItemHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java index 591421c92..8ea6c5329 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java @@ -9,7 +9,7 @@ import org.jetbrains.annotations.NotNull; /** - * Used to transfer item between an inventory and the ME system. + * Used to transfer item between an inventory and the RS system. * @see de.srendi.advancedperipherals.common.addons.computercraft.peripheral.RsBridgePeripheral */ public class RsItemHandler implements IStorageSystemItemHandler { From 1ac99ddf55328154149144b884184c85c5e0368d Mon Sep 17 00:00:00 2001 From: DenizD Date: Tue, 14 Mar 2023 16:36:41 +0100 Subject: [PATCH 026/228] Refactored the screens into the client package Added a debug to the server worker The next thing I want to do is a structured UI for the glasses to insert the modules and the peripherals. Currently there is just a 4x4 field of slots --- .../de/srendi/advancedperipherals/client/ClientRegistry.java | 4 ++-- .../container => client/screens}/InventoryManagerScreen.java | 5 +++-- .../container => client/screens}/SmartGlassesScreen.java | 5 +++-- .../container => client/screens}/base/BaseItemScreen.java | 3 ++- .../container => client/screens}/base/BaseScreen.java | 3 ++- .../srendi/advancedperipherals/common/util/ServerWorker.java | 3 +++ 6 files changed, 15 insertions(+), 8 deletions(-) rename src/main/java/de/srendi/advancedperipherals/{common/container => client/screens}/InventoryManagerScreen.java (78%) rename src/main/java/de/srendi/advancedperipherals/{common/container => client/screens}/SmartGlassesScreen.java (93%) rename src/main/java/de/srendi/advancedperipherals/{common/container => client/screens}/base/BaseItemScreen.java (91%) rename src/main/java/de/srendi/advancedperipherals/{common/container => client/screens}/base/BaseScreen.java (91%) diff --git a/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java b/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java index 56c0c958f..3d44304b9 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java +++ b/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java @@ -4,8 +4,8 @@ import dan200.computercraft.api.client.turtle.TurtleUpgradeModeller; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.client.renderer.DistanceDetectorRenderer; -import de.srendi.advancedperipherals.common.container.InventoryManagerScreen; -import de.srendi.advancedperipherals.common.container.SmartGlassesScreen; +import de.srendi.advancedperipherals.client.screens.InventoryManagerScreen; +import de.srendi.advancedperipherals.client.screens.SmartGlassesScreen; import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; import de.srendi.advancedperipherals.common.setup.APContainerTypes; import de.srendi.advancedperipherals.common.setup.CCRegistration; diff --git a/src/main/java/de/srendi/advancedperipherals/common/container/InventoryManagerScreen.java b/src/main/java/de/srendi/advancedperipherals/client/screens/InventoryManagerScreen.java similarity index 78% rename from src/main/java/de/srendi/advancedperipherals/common/container/InventoryManagerScreen.java rename to src/main/java/de/srendi/advancedperipherals/client/screens/InventoryManagerScreen.java index e4d88e29c..d1730b50b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/container/InventoryManagerScreen.java +++ b/src/main/java/de/srendi/advancedperipherals/client/screens/InventoryManagerScreen.java @@ -1,7 +1,8 @@ -package de.srendi.advancedperipherals.common.container; +package de.srendi.advancedperipherals.client.screens; import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.common.container.base.BaseScreen; +import de.srendi.advancedperipherals.client.screens.base.BaseScreen; +import de.srendi.advancedperipherals.common.container.InventoryManagerContainer; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; diff --git a/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesScreen.java b/src/main/java/de/srendi/advancedperipherals/client/screens/SmartGlassesScreen.java similarity index 93% rename from src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesScreen.java rename to src/main/java/de/srendi/advancedperipherals/client/screens/SmartGlassesScreen.java index 2b9d8705d..abfa6bb83 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesScreen.java +++ b/src/main/java/de/srendi/advancedperipherals/client/screens/SmartGlassesScreen.java @@ -1,4 +1,4 @@ -package de.srendi.advancedperipherals.common.container; +package de.srendi.advancedperipherals.client.screens; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; @@ -7,11 +7,12 @@ import dan200.computercraft.client.gui.widgets.TerminalWidget; import dan200.computercraft.shared.computer.inventory.AbstractComputerMenu; import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.common.container.SmartGlassesContainer; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; -import static dan200.computercraft.shared.turtle.inventory.TurtleMenu.*; +import static dan200.computercraft.shared.turtle.inventory.TurtleMenu.BORDER; public class SmartGlassesScreen extends AbstractComputerScreen { diff --git a/src/main/java/de/srendi/advancedperipherals/common/container/base/BaseItemScreen.java b/src/main/java/de/srendi/advancedperipherals/client/screens/base/BaseItemScreen.java similarity index 91% rename from src/main/java/de/srendi/advancedperipherals/common/container/base/BaseItemScreen.java rename to src/main/java/de/srendi/advancedperipherals/client/screens/base/BaseItemScreen.java index 527878f10..edc6f57a2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/container/base/BaseItemScreen.java +++ b/src/main/java/de/srendi/advancedperipherals/client/screens/base/BaseItemScreen.java @@ -1,7 +1,8 @@ -package de.srendi.advancedperipherals.common.container.base; +package de.srendi.advancedperipherals.client.screens.base; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; +import de.srendi.advancedperipherals.common.container.base.BaseItemContainer; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.network.chat.Component; diff --git a/src/main/java/de/srendi/advancedperipherals/common/container/base/BaseScreen.java b/src/main/java/de/srendi/advancedperipherals/client/screens/base/BaseScreen.java similarity index 91% rename from src/main/java/de/srendi/advancedperipherals/common/container/base/BaseScreen.java rename to src/main/java/de/srendi/advancedperipherals/client/screens/base/BaseScreen.java index f9311435e..9d00cace8 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/container/base/BaseScreen.java +++ b/src/main/java/de/srendi/advancedperipherals/client/screens/base/BaseScreen.java @@ -1,7 +1,8 @@ -package de.srendi.advancedperipherals.common.container.base; +package de.srendi.advancedperipherals.client.screens.base; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; +import de.srendi.advancedperipherals.common.container.base.BaseContainer; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.network.chat.Component; diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ServerWorker.java b/src/main/java/de/srendi/advancedperipherals/common/util/ServerWorker.java index 54d06ee6d..e88622bbc 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ServerWorker.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ServerWorker.java @@ -12,6 +12,7 @@ public class ServerWorker { private static final Queue callQueue = new ArrayDeque<>(); + private static int tasksRan = 0; public static void add(final Runnable call) { callQueue.add(call); @@ -22,6 +23,8 @@ public static void serverTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.END) { while (!callQueue.isEmpty()) { final Runnable runnable = callQueue.poll(); + tasksRan++; + AdvancedPeripherals.debug("Running task #" + tasksRan + ". Running " + runnable.getClass()); runnable.run(); } } From bc02347c84e983cd399ddb9ca14e6bf59ebb4d05 Mon Sep 17 00:00:00 2001 From: DenizD Date: Wed, 15 Mar 2023 15:46:07 +0100 Subject: [PATCH 027/228] Some UI stuff --- .../client/screens/SmartGlassesScreen.java | 13 +++- .../widgets/SmartGlassesSettingsSwitch.java | 69 ++++++++++++++++++ .../container/SmartGlassesContainer.java | 29 +++++--- .../common/smartglasses/SlotType.java | 18 +++++ .../common/smartglasses/SmartGlassesSlot.java | 26 +++++++ .../textures/gui/smart_glasses_gui.png | Bin 1816 -> 1941 bytes 6 files changed, 144 insertions(+), 11 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/client/widgets/SmartGlassesSettingsSwitch.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/SlotType.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesSlot.java diff --git a/src/main/java/de/srendi/advancedperipherals/client/screens/SmartGlassesScreen.java b/src/main/java/de/srendi/advancedperipherals/client/screens/SmartGlassesScreen.java index abfa6bb83..0f6fed980 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/screens/SmartGlassesScreen.java +++ b/src/main/java/de/srendi/advancedperipherals/client/screens/SmartGlassesScreen.java @@ -7,10 +7,13 @@ import dan200.computercraft.client.gui.widgets.TerminalWidget; import dan200.computercraft.shared.computer.inventory.AbstractComputerMenu; import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.client.widgets.SmartGlassesSettingsSwitch; import de.srendi.advancedperipherals.common.container.SmartGlassesContainer; +import de.srendi.advancedperipherals.common.smartglasses.SlotType; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; +import org.jetbrains.annotations.NotNull; import static dan200.computercraft.shared.turtle.inventory.TurtleMenu.BORDER; @@ -27,6 +30,14 @@ public SmartGlassesScreen(SmartGlassesContainer container, Inventory player, Com imageWidth = TEX_WIDTH + AbstractComputerMenu.SIDEBAR_WIDTH; imageHeight = TEX_HEIGHT; + + } + + @Override + protected void init() { + super.init(); + addRenderableWidget(new SmartGlassesSettingsSwitch(0, 0, SlotType.PERIPHERALS, this)); + addRenderableWidget(new SmartGlassesSettingsSwitch(0, 0, SlotType.MODULES, this)); } @Override @@ -35,7 +46,7 @@ protected TerminalWidget createTerminal() { } @Override - protected void renderBg(PoseStack transform, float partialTicks, int mouseX, int mouseY) { + protected void renderBg(@NotNull PoseStack transform, float partialTicks, int mouseX, int mouseY) { RenderSystem.setShaderTexture(0, BACKGROUND); blit(transform, leftPos + AbstractComputerMenu.SIDEBAR_WIDTH, topPos, 0, 0, TEX_WIDTH, TEX_HEIGHT); diff --git a/src/main/java/de/srendi/advancedperipherals/client/widgets/SmartGlassesSettingsSwitch.java b/src/main/java/de/srendi/advancedperipherals/client/widgets/SmartGlassesSettingsSwitch.java new file mode 100644 index 000000000..d839168f2 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/client/widgets/SmartGlassesSettingsSwitch.java @@ -0,0 +1,69 @@ +package de.srendi.advancedperipherals.client.widgets; + +import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.PoseStack; +import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.client.screens.SmartGlassesScreen; +import de.srendi.advancedperipherals.common.smartglasses.SlotType; +import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesSlot; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.components.AbstractWidget; +import net.minecraft.client.gui.narration.NarrationElementOutput; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.inventory.Slot; +import org.jetbrains.annotations.NotNull; + +public class SmartGlassesSettingsSwitch extends AbstractWidget { + + private static final ResourceLocation BACKGROUND = new ResourceLocation(AdvancedPeripherals.MOD_ID, "textures/gui/smart_glasses_gui.png"); + + private final SmartGlassesScreen screen; + private final SlotType type; + private final int leftPos; + private final int topPos; + + public SmartGlassesSettingsSwitch(int x, int y, SlotType type, SmartGlassesScreen screen) { + super(screen.getGuiLeft() + x, screen.getGuiTop() + y, 21, 22, type.getName()); + this.screen = screen; + this.type = type; + this.leftPos = screen.getGuiLeft(); + this.topPos = screen.getGuiTop(); + } + + @Override + protected void updateWidgetNarration(@NotNull NarrationElementOutput pNarrationElementOutput) { + + } + + @Override + public void render(@NotNull PoseStack pPoseStack, int pMouseX, int pMouseY, float pPartialTick) { + renderBg(pPoseStack, Minecraft.getInstance(), pMouseX, pMouseY); + } + + @Override + public void renderButton(@NotNull PoseStack pPoseStack, int pMouseX, int pMouseY, float pPartialTick) { + } + + @Override + protected void renderBg(@NotNull PoseStack pPoseStack, @NotNull Minecraft pMinecraft, int pMouseX, int pMouseY) { + RenderSystem.setShaderTexture(0, BACKGROUND); + blit(pPoseStack, leftPos + this.getX(), topPos + this.getY(), 45, 217, 21, 22); + } + + @Override + public void onClick(double pMouseX, double pMouseY) { + for(Slot slot : screen.getMenu().slots) { + if(slot instanceof SmartGlassesSlot smartGlassesSlot) { + if(smartGlassesSlot.slotType == this.type) { + smartGlassesSlot.setEnabled(true); + } + smartGlassesSlot.setEnabled(false); + } + } + } + + @Override + public boolean isMouseOver(double pMouseX, double pMouseY) { + return this.active && this.visible && pMouseX >= (double)this.getX() && pMouseY >= (double)this.getY() && pMouseX < (double)(this.getX() + this.width) && pMouseY < (double)(this.getY() + this.height); + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java b/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java index 17a0589e2..545859acd 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java @@ -6,13 +6,14 @@ import dan200.computercraft.shared.network.container.ComputerContainerData; import de.srendi.advancedperipherals.common.setup.APContainerTypes; import de.srendi.advancedperipherals.common.setup.APItems; +import de.srendi.advancedperipherals.common.smartglasses.SlotType; +import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesSlot; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.items.SlotItemHandler; import org.jetbrains.annotations.NotNull; import java.util.function.Predicate; @@ -20,17 +21,26 @@ public class SmartGlassesContainer extends AbstractComputerMenu { public static final int BORDER = 8; public static final int PLAYER_START_Y = 134; - public static final int TURTLE_START_X = SIDEBAR_WIDTH + 175; public static final int PLAYER_START_X = SIDEBAR_WIDTH + BORDER; public SmartGlassesContainer(int id, Predicate canUse, ServerComputer computer, Inventory playerInventory, IItemHandler inventory, ComputerContainerData data) { super(APContainerTypes.SMART_GLASSES_CONTAINER.get(), id, canUse, ComputerFamily.ADVANCED, computer, data); - // Turtle inventory - for (var y = 0; y < 4; y++) { - for (var x = 0; x < 4; x++) { - addSlot(new SlotItemHandler(inventory, x + y * 4, TURTLE_START_X + 1 + x * 18, PLAYER_START_Y + 1 + y * 18)); - } - } + + // Glasses Peripherals + addSlot(new SmartGlassesSlot(inventory, 0, 222, 148, SlotType.PERIPHERALS)); + addSlot(new SmartGlassesSlot(inventory, 1, 204, 166, SlotType.PERIPHERALS)); + addSlot(new SmartGlassesSlot(inventory, 2, 222, 166, SlotType.PERIPHERALS)); + addSlot(new SmartGlassesSlot(inventory, 3, 240, 166, SlotType.PERIPHERALS)); + addSlot(new SmartGlassesSlot(inventory, 4, 222, 184, SlotType.PERIPHERALS)); + addSlot(new SmartGlassesSlot(inventory, 5, 240, 184, SlotType.PERIPHERALS)); + + // Glasses Modules + addSlot(new SmartGlassesSlot(inventory, 6, 222, 148, SlotType.MODULES)); + addSlot(new SmartGlassesSlot(inventory, 7, 204, 166, SlotType.MODULES)); + addSlot(new SmartGlassesSlot(inventory, 8, 222, 166, SlotType.MODULES)); + addSlot(new SmartGlassesSlot(inventory, 9, 240, 166, SlotType.MODULES)); + addSlot(new SmartGlassesSlot(inventory, 10, 222, 184, SlotType.MODULES)); + addSlot(new SmartGlassesSlot(inventory, 11, 240, 184, SlotType.MODULES)); // Player inventory for (var y = 0; y < 3; y++) { @@ -43,12 +53,11 @@ public SmartGlassesContainer(int id, Predicate canUse, ServerComputer co for (var x = 0; x < 9; x++) { addSlot(new Slot(playerInventory, x, PLAYER_START_X + x * 18, PLAYER_START_Y + 3 * 18 + 5)); } + } public SmartGlassesContainer(int id, Predicate predicate, ServerComputer computer, ComputerContainerData data, Inventory player, ItemStack glasses) { this( id, predicate, computer, player, glasses.getCapability(ForgeCapabilities.ITEM_HANDLER).resolve().get(), data); - - //getTerminal().resize(48, 48); } @NotNull diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SlotType.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SlotType.java new file mode 100644 index 000000000..2262922f3 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SlotType.java @@ -0,0 +1,18 @@ +package de.srendi.advancedperipherals.common.smartglasses; + +import net.minecraft.network.chat.Component; + +public enum SlotType { + PERIPHERALS(Component.literal("Peripherals")), + MODULES(Component.literal("Modules")); + + private Component name; + + SlotType(Component name) { + this.name = name; + } + + public Component getName() { + return name; + } +} \ No newline at end of file diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesSlot.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesSlot.java new file mode 100644 index 000000000..30ff1818e --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesSlot.java @@ -0,0 +1,26 @@ +package de.srendi.advancedperipherals.common.smartglasses; + +import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.items.SlotItemHandler; + +public class SmartGlassesSlot extends SlotItemHandler { + + public final SlotType slotType; + private boolean isEnabled = false; + + public SmartGlassesSlot(IItemHandler itemHandler, int index, int xPosition, int yPosition, SlotType slotType) { + super(itemHandler, index, xPosition, yPosition); + this.slotType = slotType; + this.isEnabled = slotType == SlotType.PERIPHERALS; + } + + public void setEnabled(boolean enabled) { + isEnabled = enabled; + } + + @Override + public boolean isActive() { + return isEnabled; + } + +} diff --git a/src/main/resources/assets/advancedperipherals/textures/gui/smart_glasses_gui.png b/src/main/resources/assets/advancedperipherals/textures/gui/smart_glasses_gui.png index 041eadca258e1273ce2222d0925ed2045497a20a..97fe8a04c7a5b978eebbd8427394489159ae161f 100644 GIT binary patch delta 1482 zcmZ9JdsNbQ7{-5~i4N~BD=%QS^mM#nrCUm(wQ?&3ZT8ce7j&+pri4m}cT8rkIklpW z_gI_a2`^}xcLgtHoe|m)$qQbl;*?NJydpZP?VO#x=e&Qt@B2L8&+{$Ny{~uMfeQ0J zcjnZ^gc6z96Za|6^x0I!Pitn(pIxiCJ)g%!|A}~=?(iLKv8%VP16J|Fp8bYcv;7{w z-hvfvX}nG`+sQaj_Km@ddVN=X=v!owr!dNQSF|_gz7t20eT_gM@cW=V!PZuiuuijK zb|y>H#>NKh!_4R9aw5XR!-Mng=}Xh00gJsHs{kIl5jHlNoUGtoJ7jk=Ax{xSpXW+JmNyV z1|0%Tpoc&Y{L{t;mjXZ`S$q}=bHHQodjtAdx;`}WKN~t!Q{|MjwGgo<=AZ`%Vg=iC zZjFS1%F0TTt3`-?E9*E0GS)_6tK5z;dLRLnl%$DVcZoKY?_pmtb<|+V#$B0Y`7j(*-_=dyh4ME_EPd*x-3dSAS?cPRE@AM@R}**rb~chX%l~ zuPjI!Zhg7#^Efp2w2+M*{#0w>H?E}&VM8*uY!Cah*v)rzDz18 z^;H`Xb>DK9IC$AZEDC^+bTtt9=EM=5EBsP4WkD)p)0`0`{(~_8$>BPiT4x#~>|kts zAU#;!SQqXuJ9Pw-&WRBs?!{@*V9E7R!`ljf+&xvXCk|alN zySejR@jg`Wbr7V#C@W$-=x?yB%+EUZdJ*wuaaE@v)m1pau8<C98TRX~RadYhS zBsmMusjc-<`HXX@co6JoxGl|E;5(9p!iRKn(nNP+HJgnrghzS^C~`d{=Aww~ROqFP zo5{?~q#i;&=#=_{*NjJ!%D_8$fU4GEz6n3xhQU|4xkO#tlxbn5z2*lZew(!^qQQg_o9FLU2K z5m0t9ZjI|?Jj5YDCjVYVBH4rd#DOT2mvY#d?%C-vi4AZ#Tu2V0u9Dr{M;q-SlXoLH zsR}==U{IAV-!;0mA|2q)4&-|Lwzatuj>-oF-bSjexQJrrqgN4wp1|T*3#r!A2hS|d zmdhw@WvB065bl_#sIF_Qy&qf`ymVFlx>zixRdaQT+p&S8jb!OiHH}@2(S0+M8H!Gb zp(ZD{r5PI=;{tWPtmv(2$|S56-N@iXr_Dg*ofB+TnydrSBe5y@7r*}FWb#^-V&m;} zSKr$FszM&Lyz*{Y=NgLfB`j?4Rud_?8zJY`L{% P?`P-E;?C5Z4$1f%NBY_0 delta 1376 zcmZvadsNbA7{}iq;H^w66K6W?vgtaf2{tQD3^$t|o3~PQ^M+>2si83kqEjKQY&oSy z9?jHct{Zr%F-b)Q&zg41TM>9c1Y>p-MN&c$(e|r9_Q%fN|DN}G-tYH$KF?cjTWNC{ z$1r~$bma3$dbLI#a{NV{OV1?ZdE?z}5k0I{B-QEk`AwF)52`wrmE&gNk*Vd#OIH%@ zNg)%^0j$d)a>LAlGo;~1&Gd^!reBpU+3nT!;Gp~3yoHbRp&9y#zsev-P7y!Rl%Ll~8(ed$yqM{-nmf$lW95(<6_qA}X?r;|S z7{ZU#bcEHjVY@U;PGc_8G1>nGYtBZOk74j9b2)?$+KiksMVqBamq5Pbsr34=tWJSM!91M2A);M+uWKSB=W>}d= zGB*Bw;dfCGP}=(5G7C+B-sSJdlAx%ls5CNJ(@lEh)ss|N#ZkjNIh>3+<%z%@D(j@` zy5LG;4ats0wMnG;hPkpix^zXEUytLum;W`~kC*x&HUWVNUqUhouV0|OtiTpy+{n_@ z(~5+i8C4#pJ^U!R=<%CbsQ)*gd}{*=tpJL*`!dCxV57@Q2gd5xICv_bfy*>hZrYsX z$?9%aa^Q^>4-57&2*Vh)Wm@{jDm|~BKaTJ_Cy_`Jq}%WA6A|y_;0|H_rwG8nK!%a)t^$z@J#FKy|EYm@)Yl~HaWr}Lg+&nMQfU;C zi1ld&e|pL$)AwDAtRbz!n6JTWfSBNIOLwMjwl^a=xt>O&p|b--Bub9WjkY(da--2m z^4^)~;Z8C|7c74DaEJ$?HBa^{7TvORKs) z#&6{Dcsk*Tr-T|`Q(G&g=jl}_fk2?25#O1mK<207sMJE`++4%hl6qW8$2X}|sx%qD ztgI|8HFf4?>(gFVKs_w4hyS11x*c(6xc=GnlWv}%fJhvs zItVkWbl2AiZ%w=*wgu)CUhr7Z#2x&VK$w28rjb3APfR3W-OT$)tEyg>Q?_w6CMJf% zY4>mg))BGP!_S6`*=#n4Q!+R zi~5(gZ3cAbu?2dZo10r_2coamwFAKrsfG@OM5q>8E5KeXmNd5&Wvysco9yzm6P?^; zts(j{X%x9 Date: Wed, 15 Mar 2023 18:20:13 +0100 Subject: [PATCH 028/228] Added a new taiga village structure --- build.gradle | 13 +- .../loot_tables/chest/scientist_common.json | 133 ++++++++++++++++++ .../structures/villages/scientist_taiga.nbt | Bin 4478 -> 6265 bytes 3 files changed, 142 insertions(+), 4 deletions(-) create mode 100644 src/main/resources/data/advancedperipherals/loot_tables/chest/scientist_common.json diff --git a/build.gradle b/build.gradle index 02e85086b..b61c72ad9 100644 --- a/build.gradle +++ b/build.gradle @@ -309,6 +309,9 @@ dependencies { //Removed until fully ported //testImplementation fg.deobf("site.siredvin.ttoolkit:ttoolkit-${minecraft_version}:${ttoolkit_version}") + // Worldedit + runtimeOnly fg.deobf("curse.maven:worldedit-225608:4162208") + testImplementation "org.junit.jupiter:junit-jupiter-api:${junit_version}" testImplementation "org.junit.jupiter:junit-jupiter-params:${junit_version}" testImplementation "org.hamcrest:hamcrest:${hamcrest_version}" @@ -331,7 +334,7 @@ changelog { //1.16.5-1.1.1.1b //1.18-1.0r //1.19-1.0.0a - headerParserRegex = ~/\d+(\.\d+){1,2}-\d+(\.\d+){1,3}\w/ + headerParserRegex = ~/^\d{1,2}\.\d{1,2}(\.\d{1,2})?-\d{1,2}(\.\d{1,2}){0,3}[a-zA-Z]$/ itemPrefix = "-" keepUnreleasedSection = true unreleasedTerm = "[Unreleased]" @@ -342,7 +345,7 @@ compileTestModJava { dependsOn(compileJava) } -task setupServer(type: Copy) { +tasks.register('setupServer', Copy) { group "test server" description "Sets up the environment for the test server." @@ -378,8 +381,10 @@ test { } afterEvaluate { - tasks.withType(JavaCompile) { - options.compilerArgs << "-Xmaxerrs" << "2000" + tasks.withType(JavaCompile).tap { + configureEach { + options.compilerArgs << "-Xmaxerrs" << "2000" + } } } diff --git a/src/main/resources/data/advancedperipherals/loot_tables/chest/scientist_common.json b/src/main/resources/data/advancedperipherals/loot_tables/chest/scientist_common.json new file mode 100644 index 000000000..8f7871296 --- /dev/null +++ b/src/main/resources/data/advancedperipherals/loot_tables/chest/scientist_common.json @@ -0,0 +1,133 @@ +{ + "type": "minecraft:chest", + "pools": [ + { + "bonus_rolls": 0.0, + "entries": [ + { + "type": "minecraft:item", + "functions": [ + { + "add": false, + "count": { + "type": "minecraft:uniform", + "max": 3.0, + "min": 1.0 + }, + "function": "minecraft:set_count" + } + ], + "name": "minecraft:diamond" + }, + { + "type": "minecraft:item", + "functions": [ + { + "add": false, + "count": { + "type": "minecraft:uniform", + "max": 3.0, + "min": 1.0 + }, + "function": "minecraft:set_count" + } + ], + "name": "advancedperipherals:weak_automata_core" + }, + { + "type": "minecraft:item", + "functions": [ + { + "add": false, + "count": { + "type": "minecraft:uniform", + "max": 3.0, + "min": 1.0 + }, + "function": "minecraft:set_count" + } + ], + "name": "advancedperipherals:peripheral_casing", + "weight": 5 + }, + { + "type": "minecraft:item", + "functions": [ + { + "add": false, + "count": { + "type": "minecraft:uniform", + "max": 5.0, + "min": 1.0 + }, + "function": "minecraft:set_count" + } + ], + "name": "minecraft:iron_ingot", + "weight": 5 + }, + { + "type": "minecraft:item", + "functions": [ + { + "add": false, + "count": { + "type": "minecraft:uniform", + "max": 3.0, + "min": 1.0 + }, + "function": "minecraft:set_count" + } + ], + "name": "minecraft:gold_ingot" + }, + { + "type": "minecraft:item", + "functions": [ + { + "add": false, + "count": { + "type": "minecraft:uniform", + "max": 3.0, + "min": 1.0 + }, + "function": "minecraft:set_count" + } + ], + "name": "minecraft:bread", + "weight": 10 + }, + { + "type": "minecraft:item", + "name": "minecraft:iron_pickaxe", + "weight": 5 + }, + { + "type": "minecraft:item", + "functions": [ + { + "add": false, + "count": { + "type": "minecraft:uniform", + "max": 3.0, + "min": 1.0 + }, + "function": "minecraft:set_count" + } + ], + "name": "minecraft:coal" + }, + { + "type": "minecraft:item", + "name": "minecraft:iron_shovel", + "weight": 5 + } + ], + "rolls": { + "type": "minecraft:uniform", + "max": 8.0, + "min": 3.0 + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/advancedperipherals/structures/villages/scientist_taiga.nbt b/src/main/resources/data/advancedperipherals/structures/villages/scientist_taiga.nbt index fff19535bc88e57d545fc4d41676c6c96a740d29..f154b6eb9d137c312dc3077039e74b410ee9085b 100644 GIT binary patch literal 6265 zcmcII30RZIwk^J(f`YF|SyZsqf+CV&SOg7RT4~E|fTBo{B_VLxS7nnWpje%jGc*60v&}hYW}=z8 z<-PUaS`%eC*rPcrDgC^*r*_0{W0hlRPzgVVgvB!LK8f#~?1rc{w%^bx3Dn$RanJO`@kZC%ixAxB=*kqwFMMVM3;xta9s}gp`#xFk$}+ zrnCqXZsjQe^jkpQgjTM@v!ti3!ONxLL>z!Qowr=yuz#mBfmxUKTQR@w z1GPWq$SOnJ{xe8`4*rghRnSlW9J&h|;Uu5ay_ESK+;>1+ zRe259_9?Z=lYWvXjk(BZnPy!`Y5&A6KXmK*@Yhu$gTl0HBeu?5n~T2wJ%jBkn%I6o&5R{*t5LeB92L*CoyT^olAJW7& zCEqQ71f;_3IL2p#59_2y3m@#zdiWYPYdw4e-lPs~3jY^Dc4-YK)EnP||KNcF+nY%A zkBYy8Fy?M=Ud9Bnoml+HrmRxUn|InhzqTz6^UzzhKRx_M0ir^4@=NNmm7n5t#kQRK zp4Cw=>i%WwmDW@&jWVFIH&8n=y);4=Uf&b#CwA~eS2{l;wxwd5YQ|2trf%|BpkSK@#!t7tgUToa16KVlZSww`wbWxcPn<4Y z_TR44r{>^uw6*LS8E2#i=_G)3%EJdJIH8Qc5afJ_Jb=(vM$;3<9T2s0G+e_r9TFY} z(t@Yly5G&_$kNj;u03_YG;`vVdjJYO*TP6HnyH#YbRsG>Xoi{2il-={llZ>&JN3j( zG+c)Qk&zt1uxKimRTghMWUw3ZNHP%YtjGW|QDxCdthomhQ4e25Z&6|-BRc*BRcI*O zTMtPPl^a8<&F9STx<0g@+t=ZoVZ- z&Nj;;75<9w`8mlcei~XgqreZ&~uz(-`Zf+v^&@Sk>Et^3}%+T zCewWxc=cV_WAC#C#B!Ku7*@tKv{4;m4*gfF^{xzb*kO_lOvrHSn?oK%NH0gMhfSZ_ zX~c+}*U5%l*=;kU>2E47sNQLNXsCIij8Yn9LGp!1atd##Wpq+&%*zSNj(e?n>fiS7vuu^0!Xm*5hbI(!h(QJ$ns(D1sQ(KT`BiBrL4 z|ArIga!Q>O2ZW>cTsxY;mvQCL((&74NOW06{Rw~hbriZ8ROOTU5vuIbz8-x3@?Lb9 z<~J$Rmk=F<9a`0jjjttx3$S&MYv{?lw{9J8e!o$KYX3FIJ&k3Pqs}m`o0_CAHAz-q7lXnUQnAKj zaY2psQD_8d3U;bc0iUmaiA8X|iJyR>W2S2`ZXZ+d??9hvJR7Lf<){2>*?dz!chG9J zYH)7(AT3dxP9)l1@a9B#+p$A&9fw%aNht>3ybFHHymPs}TRcqKXD|9rN}ORdh9FW7 z9TuOQGCcz{UfHG3C(;y&o}Wwh@QxI8%7WgmW4|{1gNRJE!}NMbF9VL7E;0v)xQg4p zhHG%VJ#`s}$UMYO!3`gNjc-KgVj`O0s{9Ps7xKJwHx^+YRS#DZd?#0GWjuO?vlm%Y zzDr>`>lo~#_KY^$fKP{73HAMYP@r|$G3TybcZFSge9?Z{pX;8!8f3%-ssqFxEmf3Wgr>UX z9@%{>2`qGAT!SNRItBQvNGK>epbw$zukaUHXiA){Wzin~qj7Klf2;Bzp@8F#lmo}D zud500NM?a%#-6x`_p$^WFwZ=TKU3xN9g=|tkeYlN63hX2yet8_M)d+;)C8<6x*lOb zS76X@DXVZltgqMsR)Cm@>IFX24N!lXjk%hHuwyiCW-qe!0;+?5`(<};Sz*X zH9OT_avFC$krmLXLU7Y{p0m_com8R*Z<%!MTxojM!vlPu={2RhVFM=XZ~opay1Iw1SML{xZchkK@0=8KMVC%sUn0l$F<^pS*JFr~VDtr|<_H}>#(>mozN_-`t1+@Wu0t(9N z1IsUwfaMlwu7xGo^4EOUi6NKm1y`a>i(3v56(nkX4szoTXhZj|_k?ORMrd?=GHcuS z6E1$uN4^EIq;`*FmDrA$-+j+dgO_*7v5ngkx}!KsHAcbRP|-tR(RxaiZ$0j9o%Poc z2n^Jp)^nsLyhSfEQF zC7xMd7QQN#@mS=82w8z5WEF~#cn~3h+t;qwgCX!oJQN8WG{`L+?ISeXVeJmItYE`s z9ewf}a0B;cm&Y(7YUEDs_IDlxL{t{5b~|YGIa=V7@7RR|YED9G&Ov({4J`FUffOjg zF4by$@|RE^@WC0uN&@Sa_r?rSOi-?;2pNzUg>SnHP!W&ZB`kiv6Kr6PC!`11`)1|!%ev#|NZ_!7GieQ=M@Uj`E&TK| z)tEXDe>f4fsia(mm-jv}?J5po2LhmUzhoz`Zp3h7 zGVmPpn7L#KTxN0$3NL&clTG*s^a}M5__Z;i2kY~l;Kj)+p+nV12x7^_cL}*>oNtM5Sva#qD zB#Hh65|sumIc9pGi8~4YWRY54 zWJwM{j0zw|>7X!99lyV#?f@BXXY_iMuo21MH!1o7ca6r5E!kx##W6&DS7ff92*dAf zDjYvd7kIU87Kr%0i(b)H%THV8V$bU1uoUq3Q(IV+SwC{J)2|~oOt2DN=ZI!{X);xW zi|3YKL{w(CMfBT+Mw{SlRJ<#*r0pncd|J(xZ;}EN^o&o=ag_fnvL6TDoGVl zVrDUtV)5)^q1qHJ#!F>hS8Wkb5C6VUk~RL*7v#>m8QTw$Nki51*E)kLqj~4!?RU?- zsNALbVim?0;6m=DoBq4^dhY%vDF$xds(D;Pv^ddQ+WB%sGQQ7tn3K#j5{l=iTHM1| z7bo`&KRsF}Y<+e2A;%_CXop;!jb_J7;R++<6#?Cr&Q6c3Sb7pq-Yiu!mc|daMSjE#kW}69qE@IU*{w?J2p13a&&ks zfW3S^#%wriDwchWecGs?+jz#ZD$4p{Dm$+%`h{^bHjLasFYX+rwo%)HvVQIm+&2Cy z&flpfCjK#B%BPK%21$&>go-|El}bkL>gZH#U0&dt|1q}D5hb{Ia5(On`u0s}M;Nt( zI$Y^@8o?(`TdYMhSQaA!CM8rcG^d+6bwh1N%~v(zBa_0ktw+r>i#F{u@Npf{ywZKt zcWCihKwVYFGJSNkR9w;GvQYc9+BgYS_s^w_0BX(E;@NA(D;{T<3z`*oT?I6%z$n{D zsAwmpyO0&Ve)5%c;kBlMO_E#gpsuVoFoh!5@3<}p&s7qn4#f#{L06W>K|iNDvUIN~Yl6*Lh1=y)MwEu4aTI9UH1}bbY25Q5RjZ5XRAi&n%y;)*pI*IIwp0IVYLDGEFmj zDP2mNJ+yWcj-5EYpk5QXc9SlID_J=E*T-c^3K?`^lcx}OD{sahDNJp8Jaj(7q+eIU z+#Mn`Bhx?FFWc?6~q;*ZXqV9VgH`lyctSQB`Y|ncQ%4N8Dm?w@MVIO z=0{*TDKD*lj~atx$b&*=rF?(qT=ziYP{5LU>`{Y z!bZr}RLe2#7Wz$N#h6%bvAAs|e>@~%&+QQ7hASL41)suUq?|23ItA+zJ{xhK{3?C< zlkQioWw;rC|A?~@`mWg44<(%iE#$*evgOZ)S!VIlhJrc@(}>USUw$=tD7X7;%=xbq zO(qp5$Ie7pMmM8EcxP2JP!2MWuMNQ`8p`eT)6_L*;oMo}N>6Q4baNbR! zw*DkGoZhau^mu3V)^c1#*7N(NMH7v|exKIP4vqN>mk+6jT0CbmTe0DWQHge(#&TN> znR{?NEV4&EE$Gp)e)@sF=&&)3y14VTW-$*kRALwLvFT|_+xL6-M&T)BeG ze0)^QUUa4jqD2aixv-Kkd;Sg;9!%pbX8aIx#}#?irczSO{ftfCB=Q&yqBXtX$d`T` id3-R?Mp3bUHKw9h!;2v4S~FZzOi%dfTkGZb-uoYg8IwQ& literal 4478 zcmZ`*2UJtp)>c$NjW7%?NU@;8sFWCxCPY98AQ~7z2asYwiVdX*1OXj}nh+^Um0l+b zj5KKh8Ay;4K&pUX0TL-8l!Q_whC@vEbcGb-QyP{o%JeQq4je>00?ZpHx3S5*GWC;}>kl2`spr zRyNYhoa29WV&YhU+=0-aI2o0jUe~rF2QO$zTUkHLizfyh^1h%xT&$^=rWAj>Pl$P4 z^R&sv=vviyV*U-Epe@erq{}2{^#Q)GkF^*iQb%P$|3iL>z5Y7Mxvrb_wd=h@mW%z) zNm0E`x1Y{EZN1CULrLe|s9c);t13l+!yau_zZ8JIpZQze*Ej1|1x-y9+9)Xcr&=on zQ_yhASr47QI-k~1&mM_K<;Y^@#BQJhuZzWO+-)!|o-WBgP9&eJ(WG(AS|6lObJOs~ z=?)#-GINK9TMiN;0gSfK7tn4?p5|AK>#aomOWsTNmp-jxd|1wvZ?U>U=sbX*Dooj0 zdWCzsKbbh;=IU}(L~`wpHkxH(ZyCS#(FS|xlmrz=0ue|qz+^E_i! zxpi^wL6%eTagY9seLa#{CTm#{ipQFAGk%TgN2C1idD|ghGKn}gHz$%qI=y&KA@O>D)1849dwKlA zK&H-IM^|(-P9FU+wPkv7%AaWO$Gt}k(<7%(PNk|M6TKD>>z>iZ_`dF=xIf6O(~C~{ z5^m6ifHNu54jzT`J>U2bx~=wD%s5`1`ob^Si&fqkvRBfyz0ruO9@Th3CZ95Ynb4($ zc-$h6&|x(j@s2Nn=k-!YWKsfJ5HhXQ2}3rlvJR{L+dM%Z^8SA_c!&*;h5gIz-wuo6 zW04E~a#ThdJi{0J@W+F8sh=8m&woaM!Yv1M0461!+h9MUOrJv(wp74qk3;rK5ZKB) z?;kkft*oQHQy+6r821$2RqBAF?p3J2M(Dcwwp+?Zr8enplTnyb>-=$v`iO<1?TohR z{|_qI*~W;^r?4wg@cN^8B@4{$ce2t145p(SnabxU$J?KnJQV7(q%5e{Dz8})q%6MwskmfZgsz4QaU8fLdnMyUoD?bDQV6UO ztPN2<*PJOe{xYEXH}2c+acnosEjFt~RiF)#t5NQDMc{<9a$Mtz%0;}3t&S|MCtJf) zSqEAwC(cEcVco94wA->j7D8nK76$-*JkZm68+YK)s&@C=t9 zRL3H9RkLUj*HeX>&dP?}F?`sq4pnGg6!EZsY!JR+?bPfVEtH}9p9flml|IWqG|;gUDov<)RVn3k3MjA=4+Lu1hm~sJJ3YuObb2x%~`*W8?ZVQG+;y z$-5zC+hu?g(Z@i&s0ZFyzmBB#<$y^D$vjX-77H~GJq!bmTU%wNuk&8ms26YgbKOo3B_lwBY+Sa0cqW22>>Lm|38 zq7YnoEny0>aLSRieyS)X6>qLO_er6nXpopDrQv zk%+?1oRwx6NH-{d3Tu|8hQfOTTWW?u4cwAJ>$-l&N7NsThktGXrCV5;{Zq)zDhWn_ z6pZxQ2-z=g*%V9f&K{y<9wZLv*{B4!HD<06*hctt;RKs-Y#|(IwnE(fiWsfZCfrjM z>qb1C!tzlrT+Y50Es+ul&M0y&Uxl!ovLNx0n&SBXPj&jGNi0EsNG7GW-<9hYT&M&)9dOlx-z9H>MPQMh~* zO1*dlpiJI$hFVl@0soR_mVWRUEL(7Toav|Hz{0V`cq2GqoU>7XDWq6C^uBIk20 z1oEdgbogW?#xpga)b*;`fnwd)Ygf;wcb_4)8nvr)wUX%S8I^qpa>L=4IWhFNXA+Ax zGvQRi{Rmyvos&lpmso=8a0eOCP{Bn-F)0#?UV#BP8Sm%kux1;Gk}^+3;pSmhbLLve z_p2A&hLFKKP@06w=kiIL_73U`7$T^;6#}5iV2!&98X=D!~5ce4m?`wzwY>L0LSphew5D;2@ppdo7$eQ@DxRAbAN4FGG zML1+l+-5)4Y)cP-Y}`5ku3?VSl1-p^$XcSmb_0If=7Fe#{6I&h9o~ZC1Rr5}qxiu- zz;S`|R|r6b#1EkZF5r|Fmz4~Zf*N-OaqEvYi6dwnTytaQW+>UBEb|75KBd%D}cSHyR z%6<>X7+OQ8Hp)X5>`Dwwd)J)=csVB~w4MFrz}%DxL&?BpWyFKWgjO(~n zb4>pU_N%#=Hby-uKV1$~U)%`e{B9hZQoZ&Rgy}UfMP5ZQ9L+rR#+<@{06p|nqu_n1 zX3`%0=DSv&QU(*HOua5; z_$Xgub!ouaTONm5LQpMybI7K!8pc894Xhc<@H<Mi6r9_BWsSzHQwO02+UZRT+>8B^!($6NRWW$O4?D za!3f-s0Ok4aXwQ`sjKUEUe%{Y$JJ?NOpZi{%ZQJR_-p=J4P8g%`vk{QAa{E7iL*6l6CSkbPAZ9c!n6OEmG*I z#X#nV=cA&k2|OOSZ&8_YMP05nF_y-*-j(^d&Cj#fCzwULzov~T7Dwve9QY$en}!ps zrtHdNK2f?%x*N!zrXshR>PrsV94tOG`b*gOpPjt>-hH!6bh#b*sUnuy_=Fz3!d2x; zNk-4-X~C)4I>ua+bMYb%eJa z-Jw>R?{FgC*mwE-#N=x=!TQnmwzdbq$qxO2$TKazA^dLGL1w^DhV6XqvTslESZX`# z?AejOl1!It)3XL8wE{jH3tBLrSO{^V+&9$S4=(GXE4tTz+NV=-)UQMyM{Fua1nRiA zFNQSu`o={TBZD?m$^pg;34Cd3#QQI!AEL}({&w6+=5JiX2bTvr zv+Ks+1Uhd{Fk&wSsOvwuIozay+h10C7G03EvE!UaJo+mC0HZenZMT1RX^ext6}>2@ zGNbUUenfCV4#^zta$e_MYcQIqwL;Dr>Q{MLjq}@m4AQUBN2yBRe}h7dpnHWiL}&Bq z_DXH1rLBygiOLEMj(ZpIHRQg09<_8xN7`5Lm&f5+%Z1$2sjRCNXVdQP!;g+m`hD#i zZo?7cf8ENjwG}y)+%Lw&y1Ht1CR{9gJ~>8D#;ZvCyiSu9?8)`5l?}&|b>dey%AfbW U5}#@Kd25%?A2&n;<96)$Kdd|T!~g&Q From 306e2a698aecec75627d1d4f72c707232f6835d0 Mon Sep 17 00:00:00 2001 From: DenizD Date: Fri, 17 Mar 2023 16:44:28 +0100 Subject: [PATCH 029/228] Finished the UI. Added a modules and peripheral tab with proper visualization. Added the ability to add peripherals to the glasses which also get added to the glasses computer --- build.gradle | 10 +-- ... 59eb3dbb5f86130e09b3c62d89b9525ee01cf52d} | 2 +- .../9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e | 4 +- .../b8526e444ae7356037f3a813274f6835d1f3dd16 | 2 +- .../c622617f6fabf890a00b9275cd5f643584a8a2c8 | 4 +- .../advancedperipherals/lang/en_us.json | 9 ++- .../ar_controller.json | 0 .../armor/smart_glasses_netherite.json | 0 .../block_reader.json | 0 .../chat_box.json | 0 .../chunk_controller.json | 0 .../computer_tool.json | 0 .../energy_detector.json | 0 .../environment_detector.json | 0 .../geo_scanner.json | 0 .../inventory_manager.json | 0 .../memory_card.json | 0 .../nbt_storage.json | 0 .../overpowered_end_automata_core.json | 0 .../overpowered_husbandry_automata_core.json | 0 .../overpowered_weak_automata_core.json | 0 .../peripheral_casing.json | 0 .../player_detector.json | 0 .../redstone_integrator.json | 0 .../smart_glasses.json | 0 .../weak_automata_core.json | 0 .../recipes/me_bridge.json | 35 ---------- .../recipes/rs_bridge.json | 35 ---------- .../recipes/smart_glasses.json | 11 ++- .../client/screens/SmartGlassesScreen.java | 27 +++++++- .../widgets/SmartGlassesSettingsSwitch.java | 40 +++++++---- .../common/data/EnUsLanguageProvider.java | 7 +- .../common/data/RecipesProvider.java | 1 + .../common/items/SmartGlassesItem.java | 9 ++- .../common/smartglasses/SlotType.java | 10 ++- .../smartglasses/SmartGlassesAccess.java | 63 ++++++++++++++++++ .../smartglasses/SmartGlassesComputer.java | 21 +++++- .../smartglasses/SmartGlassesItemHandler.java | 2 +- .../common/smartglasses/SmartGlassesSlot.java | 16 ++++- .../textures/gui/smart_glasses_gui.png | Bin 1941 -> 1974 bytes 40 files changed, 197 insertions(+), 111 deletions(-) rename src/generated/resources/.cache/{67cce32b1c3cbbcb1f646605f4914e3f196986c2 => 59eb3dbb5f86130e09b3c62d89b9525ee01cf52d} (97%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/ar_controller.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/armor/smart_glasses_netherite.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/block_reader.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/chat_box.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/chunk_controller.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/computer_tool.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/energy_detector.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/environment_detector.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/geo_scanner.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/inventory_manager.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/memory_card.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/nbt_storage.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/overpowered_end_automata_core.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/overpowered_husbandry_automata_core.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/overpowered_weak_automata_core.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/peripheral_casing.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/player_detector.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/redstone_integrator.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/smart_glasses.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{advancedperipheralstab => redstone}/weak_automata_core.json (100%) delete mode 100644 src/generated/resources/data/advancedperipherals/recipes/me_bridge.json delete mode 100644 src/generated/resources/data/advancedperipherals/recipes/rs_bridge.json create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesAccess.java diff --git a/build.gradle b/build.gradle index b61c72ad9..42b3f6927 100644 --- a/build.gradle +++ b/build.gradle @@ -293,11 +293,11 @@ dependencies { // Minecolonies // Change to compileOnly when running `runData` - implementation fg.deobf("com.ldtteam:minecolonies:${minecolonies_version}") - implementation fg.deobf("com.ldtteam:structurize:${structurize_version}") - implementation fg.deobf("com.ldtteam:multipiston:${multipiston_version}") - implementation fg.deobf("com.ldtteam:domum_ornamentum:${domumornamentum_version}:universal") - implementation fg.deobf("com.ldtteam:blockui:${blockui_version}") + compileOnly fg.deobf("com.ldtteam:minecolonies:${minecolonies_version}") + compileOnly fg.deobf("com.ldtteam:structurize:${structurize_version}") + compileOnly fg.deobf("com.ldtteam:multipiston:${multipiston_version}") + compileOnly fg.deobf("com.ldtteam:domum_ornamentum:${domumornamentum_version}:universal") + compileOnly fg.deobf("com.ldtteam:blockui:${blockui_version}") //Patchouli runtimeOnly fg.deobf("vazkii.patchouli:Patchouli:${patchouli_version}") diff --git a/src/generated/resources/.cache/67cce32b1c3cbbcb1f646605f4914e3f196986c2 b/src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d similarity index 97% rename from src/generated/resources/.cache/67cce32b1c3cbbcb1f646605f4914e3f196986c2 rename to src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d index e21cd9619..6b4cf1780 100644 --- a/src/generated/resources/.cache/67cce32b1c3cbbcb1f646605f4914e3f196986c2 +++ b/src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d @@ -1,4 +1,4 @@ -// 1.19.3 2022-12-20T12:47:00.0739925 Loot Tables +// 1.19.3 2023-03-17T14:14:31.5837804 Loot Tables fecb8d92386c87945125ce5e4266faeb8275b540 data/advancedperipherals/loot_tables/blocks/ar_controller.json d865e8ac35302c486faf5c7122569c554186186d data/advancedperipherals/loot_tables/blocks/block_reader.json a6f896cc3dbd8da12737825ec71e32970f54025c data/advancedperipherals/loot_tables/blocks/chat_box.json diff --git a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e index 0c27216dd..eda98d326 100644 --- a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e +++ b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e @@ -1,4 +1,4 @@ -// 1.19.3 2022-12-20T12:49:29.6915309 Recipes +// 1.19.3 2023-03-17T14:14:31.5938615 Recipes 045608027e4a5ea2d7dee7f402346b8e69f21675 data/advancedperipherals/advancements/recipes/redstone/armor/smart_glasses_netherite.json f472724394edd655a415d4af08c9a63509cc5098 data/advancedperipherals/advancements/recipes/redstone/ar_controller.json db2dada2fdf42ca1bbf47f1eb075d1f9de89dfa8 data/advancedperipherals/advancements/recipes/redstone/block_reader.json @@ -38,5 +38,5 @@ afb8673c5643adbbf69a469776ac4cd908ab17e8 data/advancedperipherals/recipes/overpo 346dd97a088087077c157c29cb1ac7b25b0a0cef data/advancedperipherals/recipes/peripheral_casing.json cba141d36a134a03ae91869abb91c9695bd92898 data/advancedperipherals/recipes/player_detector.json d5a72afad727dd9814f4c8ef6b177a0db0bc9989 data/advancedperipherals/recipes/redstone_integrator.json -a56e462fe4cee2298e4a71e1072b1d66c649604d data/advancedperipherals/recipes/smart_glasses.json +00937671ea7c33badf81e3f7a83350b41f5dc0f1 data/advancedperipherals/recipes/smart_glasses.json a5cd6136f9d7f6271820656343f41a6ebb9cb9f0 data/advancedperipherals/recipes/weak_automata_core.json diff --git a/src/generated/resources/.cache/b8526e444ae7356037f3a813274f6835d1f3dd16 b/src/generated/resources/.cache/b8526e444ae7356037f3a813274f6835d1f3dd16 index 4651ba1fe..82b08d1a2 100644 --- a/src/generated/resources/.cache/b8526e444ae7356037f3a813274f6835d1f3dd16 +++ b/src/generated/resources/.cache/b8526e444ae7356037f3a813274f6835d1f3dd16 @@ -1,4 +1,4 @@ -// 1.19.2 2023-03-01T20:25:08.487016 Block States: advancedperipherals +// 1.19.3 2023-03-17T14:14:31.6028885 Block States: advancedperipherals eedcacd50d047b9172b7ac55fd67d09beeca2704 assets/advancedperipherals/blockstates/ar_controller.json 5e28ce1be9a6996d982641e5df1fa7162090b8cc assets/advancedperipherals/blockstates/block_reader.json f42bdde60f84fdb312f7cf3b2be461d9c11ebdc8 assets/advancedperipherals/blockstates/chat_box.json diff --git a/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 b/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 index 4fa0dd6ee..43ea3d5e6 100644 --- a/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 +++ b/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 @@ -1,2 +1,2 @@ -// 1.19.3 2022-12-20T12:47:00.0839886 Languages: en_us -8b2d44fddffb8378ff40c628111474972b7971fd assets/advancedperipherals/lang/en_us.json +// 1.19.3 2023-03-17T14:31:56.1206942 Languages: en_us +7ef4e5276c1b6ed2dec8976a297a6d8c3f52e18f assets/advancedperipherals/lang/en_us.json diff --git a/src/generated/resources/assets/advancedperipherals/lang/en_us.json b/src/generated/resources/assets/advancedperipherals/lang/en_us.json index 0993cb3ac..b64cedbf7 100644 --- a/src/generated/resources/assets/advancedperipherals/lang/en_us.json +++ b/src/generated/resources/assets/advancedperipherals/lang/en_us.json @@ -30,7 +30,8 @@ "block.advancedperipherals.player_detector": "Player Detector", "block.advancedperipherals.redstone_integrator": "Redstone Integrator", "block.advancedperipherals.rs_bridge": "RS Bridge", - "entity.minecraft.villager.advancedperipherals.computer_scientist": "Computer Scientist", + "curios.identifier.glasses": "Glasses", + "entity.minecraft.villager.advancedperipherals.advancedperipherals:computer_scientist": "Computer Scientist", "item.advancedperipherals.chunk_controller": "Chunk Controller", "item.advancedperipherals.computer_tool": "Computer Tool", "item.advancedperipherals.end_automata_core": "End Automata Core", @@ -39,6 +40,9 @@ "item.advancedperipherals.overpowered_end_automata_core": "Overpowered End Automata Core", "item.advancedperipherals.overpowered_husbandry_automata_core": "Overpowered Husbandry Automata Core", "item.advancedperipherals.overpowered_weak_automata_core": "Overpowered Weak Automata Core", + "item.advancedperipherals.smart_glasses": "Smart Glasses", + "item.advancedperipherals.smart_glasses_interface": "Smart Glasses Interface", + "item.advancedperipherals.smart_glasses_netherite": "Netherite reinforced Smart Glasses", "item.advancedperipherals.tooltip.block_reader": "&7Reads nbt data of blocks to interact with blocks which do not have computer support.", "item.advancedperipherals.tooltip.chat_box": "&7Interacts with the ingame chat, can read and write messages.", "item.advancedperipherals.tooltip.chunk_controller": "&7A crafting ingredient for the Chunky Turtle.", @@ -65,7 +69,6 @@ "item.advancedperipherals.tooltip.show_desc": "&b[&7%s&b] &7For Description", "item.advancedperipherals.tooltip.weak_automata_core": "&7Upgrade for turtles, which makes turtles more useful.", "item.advancedperipherals.weak_automata_core": "Weak Automata Core", - "itemGroup.advancedperipheralstab": "Advanced Peripherals", "keybind.advancedperipherals.category": "Advanced Peripherals", "keybind.advancedperipherals.description": "Show Description", "pocket.advancedperipherals.chatty_pocket": "Chatty", @@ -76,6 +79,8 @@ "text.advancedperipherals.added_player": "Added you to the memory card", "text.advancedperipherals.automata_core_feed_by_player": "You trying to feed entity to soul, but your own body refuses to do this. Maybe something more mechanical can do this?", "text.advancedperipherals.removed_player": "Cleared the memory card", + "text.advancedperipherals.smart_glasses.modules": "Modules", + "text.advancedperipherals.smart_glasses.peripherals": "Peripherals", "turtle.advancedperipherals.chatty_turtle": "Chatty", "turtle.advancedperipherals.chunky_turtle": "Chunky", "turtle.advancedperipherals.compass_turtle": "Compass", diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/ar_controller.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/ar_controller.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/ar_controller.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/ar_controller.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/armor/smart_glasses_netherite.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/armor/smart_glasses_netherite.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/armor/smart_glasses_netherite.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/armor/smart_glasses_netherite.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/block_reader.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/block_reader.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/block_reader.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/block_reader.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/chat_box.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/chat_box.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/chat_box.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/chat_box.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/chunk_controller.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/chunk_controller.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/chunk_controller.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/chunk_controller.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/computer_tool.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/computer_tool.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/computer_tool.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/computer_tool.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/energy_detector.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/energy_detector.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/energy_detector.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/energy_detector.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/environment_detector.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/environment_detector.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/environment_detector.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/environment_detector.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/geo_scanner.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/geo_scanner.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/geo_scanner.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/geo_scanner.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/inventory_manager.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/inventory_manager.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/inventory_manager.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/inventory_manager.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/memory_card.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/memory_card.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/memory_card.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/memory_card.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/nbt_storage.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/nbt_storage.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/nbt_storage.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/nbt_storage.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/overpowered_end_automata_core.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/overpowered_end_automata_core.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/overpowered_end_automata_core.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/overpowered_end_automata_core.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/overpowered_husbandry_automata_core.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/overpowered_husbandry_automata_core.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/overpowered_husbandry_automata_core.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/overpowered_husbandry_automata_core.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/overpowered_weak_automata_core.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/overpowered_weak_automata_core.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/overpowered_weak_automata_core.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/overpowered_weak_automata_core.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/peripheral_casing.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/peripheral_casing.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/peripheral_casing.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/peripheral_casing.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/player_detector.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/player_detector.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/player_detector.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/player_detector.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/redstone_integrator.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/redstone_integrator.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/redstone_integrator.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/redstone_integrator.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/smart_glasses.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/smart_glasses.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/smart_glasses.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/smart_glasses.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/weak_automata_core.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/weak_automata_core.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/weak_automata_core.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/weak_automata_core.json diff --git a/src/generated/resources/data/advancedperipherals/recipes/me_bridge.json b/src/generated/resources/data/advancedperipherals/recipes/me_bridge.json deleted file mode 100644 index 0e0946063..000000000 --- a/src/generated/resources/data/advancedperipherals/recipes/me_bridge.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "type": "forge:conditional", - "recipes": [ - { - "conditions": [ - { - "type": "forge:mod_loaded", - "modid": "ae2" - } - ], - "recipe": { - "type": "minecraft:crafting_shaped", - "key": { - "A": { - "item": "advancedperipherals:peripheral_casing" - }, - "F": { - "item": "ae2:fluix_block" - }, - "I": { - "item": "ae2:interface" - } - }, - "pattern": [ - "FIF", - "IAI", - "FIF" - ], - "result": { - "item": "advancedperipherals:me_bridge" - } - } - } - ] -} \ No newline at end of file diff --git a/src/generated/resources/data/advancedperipherals/recipes/rs_bridge.json b/src/generated/resources/data/advancedperipherals/recipes/rs_bridge.json deleted file mode 100644 index f8c233104..000000000 --- a/src/generated/resources/data/advancedperipherals/recipes/rs_bridge.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "type": "forge:conditional", - "recipes": [ - { - "conditions": [ - { - "type": "forge:mod_loaded", - "modid": "refinedstorage" - } - ], - "recipe": { - "type": "minecraft:crafting_shaped", - "key": { - "A": { - "item": "advancedperipherals:peripheral_casing" - }, - "I": { - "item": "refinedstorage:interface" - }, - "Q": { - "item": "refinedstorage:quartz_enriched_iron" - } - }, - "pattern": [ - "QIQ", - "IAI", - "QIQ" - ], - "result": { - "item": "advancedperipherals:rs_bridge" - } - } - } - ] -} \ No newline at end of file diff --git a/src/generated/resources/data/advancedperipherals/recipes/smart_glasses.json b/src/generated/resources/data/advancedperipherals/recipes/smart_glasses.json index 74e75c45a..daf33e9c3 100644 --- a/src/generated/resources/data/advancedperipherals/recipes/smart_glasses.json +++ b/src/generated/resources/data/advancedperipherals/recipes/smart_glasses.json @@ -2,19 +2,26 @@ "type": "minecraft:crafting_shaped", "category": "redstone", "key": { + "C": { + "item": "computercraft:computer_advanced" + }, "E": { "tag": "forge:ender_pearls" }, "G": { "tag": "forge:glass/black" }, + "M": { + "item": "computercraft:wireless_modem_advanced" + }, "S": { "tag": "forge:rods/wooden" } }, "pattern": [ - "GSG", - " E " + "S S", + "GEG", + "M C" ], "result": { "item": "advancedperipherals:smart_glasses" diff --git a/src/main/java/de/srendi/advancedperipherals/client/screens/SmartGlassesScreen.java b/src/main/java/de/srendi/advancedperipherals/client/screens/SmartGlassesScreen.java index 0f6fed980..5c4ebf5f0 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/screens/SmartGlassesScreen.java +++ b/src/main/java/de/srendi/advancedperipherals/client/screens/SmartGlassesScreen.java @@ -12,6 +12,7 @@ import de.srendi.advancedperipherals.common.smartglasses.SlotType; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.FormattedCharSequence; import net.minecraft.world.entity.player.Inventory; import org.jetbrains.annotations.NotNull; @@ -24,20 +25,20 @@ public class SmartGlassesScreen extends AbstractComputerScreen { + if (renderable instanceof SmartGlassesSettingsSwitch smartGlassesSettingsSwitch) { + smartGlassesSettingsSwitch.renderTooltip(poseStack, x, y); + } + }); + } + + @Override + protected void renderLabels(PoseStack poseStack, int x, int y) { + FormattedCharSequence formattedcharsequence = currentType.getName().getVisualOrderText(); + this.font.draw(poseStack, formattedcharsequence, (float)(212 + AbstractComputerMenu.SIDEBAR_WIDTH - this.font.width(formattedcharsequence) / 2), (float)133, 4210752); + } + + public void setCurrentType(SlotType currentType) { + this.currentType = currentType; + } } diff --git a/src/main/java/de/srendi/advancedperipherals/client/widgets/SmartGlassesSettingsSwitch.java b/src/main/java/de/srendi/advancedperipherals/client/widgets/SmartGlassesSettingsSwitch.java index d839168f2..ce1d9641f 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/widgets/SmartGlassesSettingsSwitch.java +++ b/src/main/java/de/srendi/advancedperipherals/client/widgets/SmartGlassesSettingsSwitch.java @@ -2,6 +2,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; +import dan200.computercraft.shared.computer.inventory.AbstractComputerMenu; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.client.screens.SmartGlassesScreen; import de.srendi.advancedperipherals.common.smartglasses.SlotType; @@ -13,21 +14,21 @@ import net.minecraft.world.inventory.Slot; import org.jetbrains.annotations.NotNull; +import java.util.Collections; + public class SmartGlassesSettingsSwitch extends AbstractWidget { private static final ResourceLocation BACKGROUND = new ResourceLocation(AdvancedPeripherals.MOD_ID, "textures/gui/smart_glasses_gui.png"); private final SmartGlassesScreen screen; private final SlotType type; - private final int leftPos; - private final int topPos; + private boolean isEnabled; public SmartGlassesSettingsSwitch(int x, int y, SlotType type, SmartGlassesScreen screen) { - super(screen.getGuiLeft() + x, screen.getGuiTop() + y, 21, 22, type.getName()); + super(screen.getGuiLeft() + x + AbstractComputerMenu.SIDEBAR_WIDTH, screen.getGuiTop() + y, 21, 22, type.getName()); this.screen = screen; this.type = type; - this.leftPos = screen.getGuiLeft(); - this.topPos = screen.getGuiTop(); + this.isEnabled = type == SlotType.defaultType(); } @Override @@ -47,23 +48,38 @@ public void renderButton(@NotNull PoseStack pPoseStack, int pMouseX, int pMouseY @Override protected void renderBg(@NotNull PoseStack pPoseStack, @NotNull Minecraft pMinecraft, int pMouseX, int pMouseY) { RenderSystem.setShaderTexture(0, BACKGROUND); - blit(pPoseStack, leftPos + this.getX(), topPos + this.getY(), 45, 217, 21, 22); + if(isEnabled) { + blit(pPoseStack, this.getX()-3, this.getY(), 45, 217, 23, 22); + } else { + blit(pPoseStack, this.getX(), this.getY(), 23, 217, 21, 22); + } } @Override public void onClick(double pMouseX, double pMouseY) { - for(Slot slot : screen.getMenu().slots) { - if(slot instanceof SmartGlassesSlot smartGlassesSlot) { - if(smartGlassesSlot.slotType == this.type) { + if(this.isEnabled) + return; + for (Slot slot : screen.getMenu().slots) { + if (slot instanceof SmartGlassesSlot smartGlassesSlot) { + if (smartGlassesSlot.slotType == this.type) { smartGlassesSlot.setEnabled(true); + continue; } smartGlassesSlot.setEnabled(false); } } + screen.renderables.forEach(renderable -> { + if (renderable instanceof SmartGlassesSettingsSwitch smartGlassesSettingsSwitch) { + smartGlassesSettingsSwitch.isEnabled = false; + } + }); + screen.setCurrentType(this.type); + this.isEnabled = true; } - @Override - public boolean isMouseOver(double pMouseX, double pMouseY) { - return this.active && this.visible && pMouseX >= (double)this.getX() && pMouseY >= (double)this.getY() && pMouseX < (double)(this.getX() + this.width) && pMouseY < (double)(this.getY() + this.height); + public void renderTooltip(PoseStack poseStack, int x, int y) { + if (screen != null && isMouseOver(x, y)) + screen.renderComponentTooltip(poseStack, Collections.singletonList(type.getName()), x, y); } + } diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java index 32c6cacbd..36579c704 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java @@ -36,6 +36,7 @@ protected void addTranslations() { addText(); add(APVillagers.COMPUTER_SCIENTIST, "Computer Scientist"); add("advancedperipherals.name", "Advanced Peripherals"); + add("curios.identifier.glasses", "Glasses"); } private void addItems() { @@ -48,6 +49,9 @@ private void addItems() { addItem(APItems.OVERPOWERED_HUSBANDRY_AUTOMATA_CORE, "Overpowered Husbandry Automata Core"); addItem(APItems.OVERPOWERED_END_AUTOMATA_CORE, "Overpowered End Automata Core"); addItem(APItems.MEMORY_CARD, "Memory Card"); + addItem(APItems.SMART_GLASSES, "Smart Glasses"); + addItem(APItems.SMART_GLASSES_NETHERITE, "Netherite reinforced Smart Glasses"); + addItem(APItems.SMART_GLASSES_INTERFACE, "Smart Glasses Interface"); } private void addBlocks() { @@ -80,7 +84,6 @@ private void addTurtles() { addTurtle(CCRegistration.ID.OP_WEAK_AUTOMATA, "Overpowered weak automata"); addTurtle(CCRegistration.ID.OP_HUSBANDRY_AUTOMATA, "Overpowered husbandry automata"); addTurtle(CCRegistration.ID.OP_END_AUTOMATA, "Overpowered end automata"); - } private void addPockets() { @@ -134,6 +137,8 @@ private void addText() { add("text." + AdvancedPeripherals.MOD_ID + ".removed_player", "Cleared the memory card"); add("text." + AdvancedPeripherals.MOD_ID + ".added_player", "Added you to the memory card"); add("text." + AdvancedPeripherals.MOD_ID + ".automata_core_feed_by_player", "You trying to feed entity to soul, but your own body refuses to do this. Maybe something more mechanical can do this?"); + add("text." + AdvancedPeripherals.MOD_ID + ".smart_glasses.peripherals", "Peripherals"); + add("text." + AdvancedPeripherals.MOD_ID + ".smart_glasses.modules", "Modules"); } private void addKeybinds() { diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java index 71e4682da..a688af33b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java @@ -76,6 +76,7 @@ private void addShaped(@NotNull Consumer consumer) { .define('G', Tags.Items.GLASS_BLACK) .define('C', ModRegistry.Items.COMPUTER_ADVANCED.get()) .define('M', ModRegistry.Items.WIRELESS_MODEM_ADVANCED.get()) + .pattern("S S") .pattern("GEG") .pattern("M C") .unlockedBy("has_item", has(Items.STICK)) diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java index 742df39c9..4b51d74a5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java @@ -98,6 +98,7 @@ private boolean tick(ItemStack stack, Level world, Entity entity, SmartGlassesCo stack.getOrCreateTag().putBoolean(NBT_ON, on); } + return changed; } @@ -110,6 +111,12 @@ public void inventoryTick(@NotNull ItemStack stack, Level world, @NotNull Entity var changed = tick(stack, world, entity, computer); if (changed && inventory != null) inventory.setChanged(); + + LazyOptional itemHandler = stack.getCapability(ForgeCapabilities.ITEM_HANDLER); + if (itemHandler.isPresent() && itemHandler.resolve().isPresent()) { + IItemHandler glassesItemHandler = itemHandler.resolve().get(); + computer.updatePeripherals(stack, glassesItemHandler); + } } @ForgeOverride @@ -216,7 +223,7 @@ public String getLabel(ItemStack stack) { } @Override - public boolean setLabel(ItemStack stack, @javax.annotation.Nullable String label) { + public boolean setLabel(ItemStack stack, @Nullable String label) { if (label != null) { stack.setHoverName(Component.literal(label)); } else { diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SlotType.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SlotType.java index 2262922f3..693373f59 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SlotType.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SlotType.java @@ -3,10 +3,10 @@ import net.minecraft.network.chat.Component; public enum SlotType { - PERIPHERALS(Component.literal("Peripherals")), - MODULES(Component.literal("Modules")); + PERIPHERALS(Component.translatable("text.advancedperipherals.smart_glasses.peripherals")), + MODULES(Component.translatable("text.advancedperipherals.smart_glasses.modules")); - private Component name; + private final Component name; SlotType(Component name) { this.name = name; @@ -15,4 +15,8 @@ public enum SlotType { public Component getName() { return name; } + + public static SlotType defaultType() { + return PERIPHERALS; + } } \ No newline at end of file diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesAccess.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesAccess.java new file mode 100644 index 000000000..636f278ac --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesAccess.java @@ -0,0 +1,63 @@ +package de.srendi.advancedperipherals.common.smartglasses; + +import dan200.computercraft.api.peripheral.IPeripheral; +import dan200.computercraft.api.pocket.IPocketAccess; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.Entity; +import org.jetbrains.annotations.Nullable; + +import java.util.Map; + +public class SmartGlassesAccess implements IPocketAccess { + + private SmartGlassesComputer computer; + + public SmartGlassesAccess(SmartGlassesComputer computer) { + this.computer = computer; + } + + @Nullable + @Override + public Entity getEntity() { + return computer.getEntity(); + } + + @Override + public int getColour() { + return 0; + } + + @Override + public void setColour(int colour) { + } + + @Override + public int getLight() { + return 0; + } + + @Override + public void setLight(int colour) { + } + + @Override + public CompoundTag getUpgradeNBTData() { + return new CompoundTag(); + } + + @Override + public void updateUpgradeNBTData() { + + } + + @Override + public void invalidatePeripheral() { + + } + + @Override + public Map getUpgrades() { + return computer.getUpgrades(); + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java index 44542b705..7faeab5e2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java @@ -3,10 +3,10 @@ import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.pocket.IPocketAccess; import dan200.computercraft.api.pocket.IPocketUpgrade; +import dan200.computercraft.impl.PocketUpgrades; import dan200.computercraft.shared.common.IColouredItem; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ServerComputer; -import dan200.computercraft.shared.pocket.items.PocketComputerItem; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; @@ -17,6 +17,8 @@ import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; +import net.minecraftforge.items.IItemHandler; +import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; import java.util.*; @@ -28,6 +30,7 @@ public class SmartGlassesComputer extends ServerComputer implements IPocketAcces private @Nullable Entity entity; private ItemStack stack = ItemStack.EMPTY; + private final SmartGlassesAccess smartGlassesAccess = new SmartGlassesAccess(this); private int lightColour = -1; private boolean lightChanged = false; @@ -83,7 +86,7 @@ public void setLight(int colour) { @Override public CompoundTag getUpgradeNBTData() { - return PocketComputerItem.getUpgradeInfo(stack); + return new CompoundTag(); } @Override @@ -100,6 +103,19 @@ public Map getUpgrades() { return Collections.emptyMap(); } + public void updatePeripherals(@NotNull ItemStack glasses, IItemHandler itemHandler) { + for (int slot = 0; slot < 6; slot++) { + ItemStack peripheralItem = itemHandler.getStackInSlot(slot); + if (!peripheralItem.isEmpty()) { + IPocketUpgrade upgrade = PocketUpgrades.instance().get(peripheralItem); + if (upgrade != null) { + IPeripheral peripheral = upgrade.createPeripheral(smartGlassesAccess); + if (peripheral != null) + setPeripheral(SmartGlassesSlot.indexToSide(slot), peripheral); + } + } + } + } public synchronized void updateValues(@Nullable Entity entity, ItemStack stack, @Nullable IPocketUpgrade upgrade) { if (entity != null) { @@ -136,7 +152,6 @@ public void tickServer() { for (var player : getLevel().players()) { if (tracking.add(player)) added.add(player); } - } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java index 8ab3b6e0b..9fba96322 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java @@ -14,7 +14,7 @@ public class SmartGlassesItemHandler implements IItemHandlerModifiable, INBTSerializable { - private static final int SLOTS = 16; + private static final int SLOTS = 12; private final NonNullList items = NonNullList.withSize(SLOTS, ItemStack.EMPTY); private final ItemStack stack; diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesSlot.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesSlot.java index 30ff1818e..42a0f3684 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesSlot.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesSlot.java @@ -1,17 +1,18 @@ package de.srendi.advancedperipherals.common.smartglasses; +import dan200.computercraft.core.computer.ComputerSide; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.SlotItemHandler; public class SmartGlassesSlot extends SlotItemHandler { public final SlotType slotType; - private boolean isEnabled = false; + private boolean isEnabled; public SmartGlassesSlot(IItemHandler itemHandler, int index, int xPosition, int yPosition, SlotType slotType) { super(itemHandler, index, xPosition, yPosition); this.slotType = slotType; - this.isEnabled = slotType == SlotType.PERIPHERALS; + this.isEnabled = slotType == SlotType.defaultType(); } public void setEnabled(boolean enabled) { @@ -23,4 +24,15 @@ public boolean isActive() { return isEnabled; } + public static ComputerSide indexToSide(int slot) { + return switch (slot) { + case 0 -> ComputerSide.TOP; + case 1 -> ComputerSide.LEFT; + case 2 -> ComputerSide.FRONT; + case 3 -> ComputerSide.RIGHT; + case 4 -> ComputerSide.BOTTOM; + default -> ComputerSide.BACK; + }; + } + } diff --git a/src/main/resources/assets/advancedperipherals/textures/gui/smart_glasses_gui.png b/src/main/resources/assets/advancedperipherals/textures/gui/smart_glasses_gui.png index 97fe8a04c7a5b978eebbd8427394489159ae161f..7606b08a65e7bfeb87fa72ceebe827b2749a6be0 100644 GIT binary patch delta 1514 zcmY+Cdo0y;xnk zlkSMiNU0z}%n+9nYGakGs1Xt>8kZJvi7JUC7VY-O-v8e7yx;SFp6C1i3~PqnKL*D6 z`<@I*E|yKA3Fcuoz0)8@5K(Y->}3PgL2L-e!N!57cdhFU4)!L)0?Lo<|54X0)BXU| zEFZaHlA)f38r^Rosk{ds!9`X=#=t-w&HWBj!}$#NlPgb|Lx_xw>=i-<&+qMZWCi&# zj?!#wYiesTzbKg~q`FM4R)>W}z??q!@bGAAYrEJpUC*|e(iKS^ofIFV)7H>bze9lO zl3-sKNh}us*0zUn4TkV+S#_P)XRuBPglal^9z%}U0>Z~!>Tu^W_ z*5BV>(KkKspgJaz%jFd>BpUU0Q&ZCwE2(M&X<1g;cl5va0lU*SF&WrrMFQRxZHj^T|6JHJX=2%I=}Wuvp@;u_~5(LdHGwo7v7V zseqpmHZoM)!ioi?3Qwy&?A*D|U1eui8MkfFr=5c!&Ypk)nyxZ@oEc#IruA2RY%DvU zq--hS6CRiW-wKBHD^tepub2QCMu2XD?S0bR4J+pS1n{O+@{N{VhFrgHJ6J|~FW5l? z^IT~sAqY^A0{GIoCPC{B=gt6k>l+%L^Gh=P#P)}P)jO8a?z^GGsb4Df=YFZZ@4%m<}wR4IhIKIGm!X^7-C>C^gM5aX<2spY%j z_tF0w-8=-=Wpkl1=PM`x;)af&Y1N}qAr|1*H*=gfrA}Uf7&06V$6z{&B~U@-nh{oe zRSQwe?RwPjpu5YVss-xQTpy}k`#+-b@q$SU$jnIj zWB^B>-ejK8nWDuD#klUvVMP}z<+JF?&h#|-f$pKG5WM*Ou**m@-Wo(85bADbb=~5E zM8eR|q~)0}EiaEQ3OPj!j`nsAsbq2!yYTNC$I3`UW8ztI{7uQ~YQ5;~j7WlWsv=Hx zV#LiG8;im=lC*b*+=t~gHincBRlVp)3&mgtO1u_lZLuAxBO}#D$|-PXWJ__&`*HHx zOF>#!89W;`GzIcNY=m$m%B3)1rlO+4+z|mTglg~JO+g;E`m3ltX(edZw$wZQBJsuJ zf`CB-7~+zWSbPGH$Jbu&qzTTvN%x{` z)gO0rvomj8skBT=OpMXmx!v>7(6n5=wI(eHR)RdTv^R&va*l;|QDWG+mP+NSdV7<_ zdWwfSO)=#MaoCd(Cfgc}(Mb`-3hOpJaItBSOBQ$xNNbKRbocbUZVZI_hGS@z+YYg+ z;UCt5b*PHbT$FnILMsZ1tYWb^Sl;E-BRHjKtr9H7inmki0D4`bXPDNJA`f)bqcoD0PHHDWs{)y(JxF_)N+_@2U~0$n46d-OAv8g-f@ z7myOo2@pw4R1vef8#jmsmM2=BPaLXpl=k>BUx(T;pOnEvti8H7wQf`8GyZPg6XjZJ zB$95Wm#C8D4TGZQ+Hfu*P&1M2vFc*S@i)$Q8*kxpxuIw@`WnIDbosdm-i?mayIaBWA=+JUTJ8|?m~|9bYW=mMT8Ur@O2pEn6p%4Nn;S7O(V4Z1aI`y~vXLsk_ecyfF=XqwYy5o;( zt<_x%0MK$icK9R!2zZGA8tU-m6Zz}8l^yxyQAfby>yH3{baOs@=+vcrnb-yY2}$os zf6@0d`ivj!O1RCRhll-P_=;xrHFCVMrMw*HNr{OpEa};S8h(sd4RfQ*5ScnmpYdjnpOw}+mGlN>OBbgbT z;Gm!&zgAV=i<0qkNY z`xv=)POvy^UqSRP zE-oh98T(t-F!x~*uWPAnn6tg~W`u;V`<|k)j{P+1L{EW2&)m}TC7+*RBUzlvFDxu1 zxAk)h<^#EpA3r9?Co5(rL=p*OC8&>j@nB%n2U(se@=ihsdsQR9jOIFnKD2KkGT%pK zRSZRbDl5g5irF?Lj<+W@;5?J*?d@I6v@K6gGq}v#)|7w8{1zmmZ_cJ@`Nv>0TL+j* za&Lx%WL+ZPU5Cdq3H^Y!lyE_xN636NnnpbKRYi4m=WqGgjN!WV$2Gy8D{`8^-SEc! zcVg|__%y$RnN^VWD$yXlkXomui8k5!STQeLU1Zw?1*at>nxdxIv)w+cK|+eJ-RZ6sE%mWcQEC}JVx^S!&Z&hiT| z)KRI3oor)B=HCwV>gy~wE3-+a2X2pu`n!Aow9+|yFo*Jz9omhcal(a$HzGCv(`U6R zdHd#Ucz6#;+|~6J1felipxIj7A9~QxOGa0~@5ouTDd2SXRnAX`R^GpV5+-B{W76lS z@2489t&Fd%tBc!?RO7YwXDvS^C5%X7thsdtHp6*a(0&&oDC^nXT*f_8Z-Y?QUAaEt zvjaJTt-(#X?=aY5*?O1TEmK>QbVn6V=#?HZuHSy5CdM3ntGuG;v)l$4Ym=-UlaFNoqxog8L#+NX~9)MK)e z;}+y0_0dy|*(}Q0vxR;Qal2Joba8HPS<+D$!m#Z|L%Wy`B8g z)6-eZ+=lVfue-XKLqkKlnXM)ccW0)C+jjMgEDO{1zF;!(C7PhQ!&8QqPxlYE(IE(# zt;sEWK8WWwB&qN`G4Uexw+}@uUn$jJ`bMS7yoL;L^ zx+dy^b>5ix*@?iR1S++X$!thmP8dJK9eX68E@SO0W+?=OmA6d(4GcuG#%Qe-NhUAg zuu~k;XyMThQ7Dv<;yX>Tcj&ILMD$$`=EN&Jae@xGwS2p9cLhcIvNV~Uht(b%ObNhT3QvrUt<}-d!TV^tnr77`C}VJ@S(`T=XfSIJ zxpsgJx01OntScfe`_!@D55~@vDCXV_G`7x+Oe^HRi*u$w3EWguE7xJ_0{)a|G!bf1 p)75*p*DQEJ)?47O^xwns$ub~RKRaR0ExWrCaXx}S%yRTk`U{T38&UuO From 6296e86a6291c987440d2b7103e597a975cdc265 Mon Sep 17 00:00:00 2001 From: DenizD Date: Thu, 23 Mar 2023 15:04:29 +0100 Subject: [PATCH 030/228] First thoughts about the module system This commit mainly just exists because I'm moving to another computer --- .../smartglasses/SmartGlassesComputer.java | 6 +- .../common/smartglasses/modules/IModule.java | 4 + .../modules/ModulePeripheralOwner.java | 115 ++++++++++++++++++ 3 files changed, 121 insertions(+), 4 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheralOwner.java diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java index 7faeab5e2..155974497 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java @@ -4,7 +4,6 @@ import dan200.computercraft.api.pocket.IPocketAccess; import dan200.computercraft.api.pocket.IPocketUpgrade; import dan200.computercraft.impl.PocketUpgrades; -import dan200.computercraft.shared.common.IColouredItem; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ServerComputer; import net.minecraft.core.BlockPos; @@ -61,13 +60,12 @@ public Entity getEntity() { @Override public int getColour() { - return IColouredItem.getColourBasic(stack); + return 0; } @Override public void setColour(int colour) { - IColouredItem.setColourBasic(stack, colour); - updateUpgradeNBTData(); + } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java new file mode 100644 index 000000000..7f721f40c --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java @@ -0,0 +1,4 @@ +package de.srendi.advancedperipherals.common.smartglasses.modules; + +public interface IModule { +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheralOwner.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheralOwner.java new file mode 100644 index 000000000..2a09d0527 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheralOwner.java @@ -0,0 +1,115 @@ +package de.srendi.advancedperipherals.common.smartglasses.modules; + +import dan200.computercraft.api.pocket.IPocketAccess; +import de.srendi.advancedperipherals.common.addons.computercraft.owner.IOwnerAbility; +import de.srendi.advancedperipherals.common.addons.computercraft.owner.IPeripheralOwner; +import de.srendi.advancedperipherals.common.addons.computercraft.owner.PeripheralOwnerAbility; +import de.srendi.advancedperipherals.common.util.fakeplayer.APFakePlayer; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.core.FrontAndTop; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; +import java.util.function.Function; + +public class ModulePeripheralOwner implements IPeripheralOwner { + + //TODO: Think about making our own smart glasses access so we don't have the not used stuff like the color or the light + // We would need to remove the pocket stuff from the SmartGlassesComputer + private IPocketAccess access; + + public ModulePeripheralOwner(IPocketAccess access) { + this.access = access; + } + + @Override + public @Nullable String getCustomName() { + return null; + } + + @Override + public @Nullable Level getLevel() { + return access.getEntity().getLevel(); + } + + @Override + public @NotNull BlockPos getPos() { + return access.getEntity().getOnPos(); + } + + @Override + public @NotNull Direction getFacing() { + return null; + } + + @Override + public @NotNull FrontAndTop getOrientation() { + return null; + } + + @Override + public @Nullable Player getOwner() { + return null; + } + + @Override + public @NotNull CompoundTag getDataStorage() { + return null; + } + + @Override + public void markDataStorageDirty() { + + } + + @Override + public T withPlayer(Function function) { + return null; + } + + @Override + public ItemStack getToolInMainHand() { + return null; + } + + @Override + public ItemStack storeItem(ItemStack stored) { + return null; + } + + @Override + public void destroyUpgrade() { + + } + + @Override + public boolean isMovementPossible(@NotNull Level level, @NotNull BlockPos pos) { + return false; + } + + @Override + public boolean move(@NotNull Level level, @NotNull BlockPos pos) { + return false; + } + + @Override + public void attachAbility(PeripheralOwnerAbility ability, T abilityImplementation) { + + } + + @Override + public @Nullable T getAbility(PeripheralOwnerAbility ability) { + return null; + } + + @Override + public Collection getAbilities() { + return null; + } +} From 0897103af7523352b7255463ebd40c13fc95531d Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 24 Mar 2023 14:41:16 +0100 Subject: [PATCH 031/228] Added modules in the form of items, every item which is a module implements IModuleItem which contains a method for the actual IModel. The IModel then contains a tick method and a method for the name of the module. To implement lua functions into that module, we create a class which implements IModuleFunctions which then contains the methods annotated with the LuaFunction annotation The modules can be accessed by the peripheral on the back of the glasses. Because of that, I removed the back slot of the peripheral slots. Modules and peripherals are now indexed when the inventory updates and not every tick --- config/checkstyle/checkstyle.xml | 1 - .../widgets/SmartGlassesSettingsSwitch.java | 6 +- .../common/addons/APAddons.java | 6 +- .../owner/PocketPeripheralOwner.java | 8 +- .../container/SmartGlassesContainer.java | 13 ++- .../common/items/APItem.java | 2 +- .../items/SmartGlassesInterfaceItem.java | 2 +- .../common/items/SmartGlassesItem.java | 20 ++--- .../common/items/WeakAutomataCore.java | 10 ++- .../common/setup/APItems.java | 13 +-- .../common/smartglasses/SlotType.java | 2 +- .../smartglasses/SmartGlassesComputer.java | 22 ++++- .../smartglasses/SmartGlassesItemHandler.java | 5 +- .../common/smartglasses/SmartGlassesSlot.java | 3 +- .../common/smartglasses/modules/IModule.java | 15 ++++ .../modules/IModuleFunctions.java | 11 +++ .../smartglasses/modules/IModuleItem.java | 7 ++ .../modules/ModulePeripheral.java | 29 +++++++ .../modules/ModulePeripheralOwner.java | 81 +++++++++---------- .../modules/overlay/OverlayGlassesItem.java | 18 +++++ .../modules/overlay/OverlayModule.java | 29 +++++++ 21 files changed, 207 insertions(+), 96 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModuleFunctions.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModuleItem.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesItem.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml index b31efbaec..1b9212af6 100644 --- a/config/checkstyle/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -37,7 +37,6 @@ - diff --git a/src/main/java/de/srendi/advancedperipherals/client/widgets/SmartGlassesSettingsSwitch.java b/src/main/java/de/srendi/advancedperipherals/client/widgets/SmartGlassesSettingsSwitch.java index ce1d9641f..69eeb60dd 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/widgets/SmartGlassesSettingsSwitch.java +++ b/src/main/java/de/srendi/advancedperipherals/client/widgets/SmartGlassesSettingsSwitch.java @@ -48,8 +48,8 @@ public void renderButton(@NotNull PoseStack pPoseStack, int pMouseX, int pMouseY @Override protected void renderBg(@NotNull PoseStack pPoseStack, @NotNull Minecraft pMinecraft, int pMouseX, int pMouseY) { RenderSystem.setShaderTexture(0, BACKGROUND); - if(isEnabled) { - blit(pPoseStack, this.getX()-3, this.getY(), 45, 217, 23, 22); + if (isEnabled) { + blit(pPoseStack, this.getX() - 3, this.getY(), 45, 217, 23, 22); } else { blit(pPoseStack, this.getX(), this.getY(), 23, 217, 21, 22); } @@ -57,7 +57,7 @@ protected void renderBg(@NotNull PoseStack pPoseStack, @NotNull Minecraft pMinec @Override public void onClick(double pMouseX, double pMouseY) { - if(this.isEnabled) + if (this.isEnabled) return; for (Slot slot : screen.getMenu().slots) { if (slot instanceof SmartGlassesSlot smartGlassesSlot) { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java b/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java index b5052f08e..6918ca942 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java @@ -57,10 +57,10 @@ public static void interModComms(InterModEnqueueEvent event) { } public static ItemStack getCurioGlasses(Player player) { - if(!curiosLoaded) + if (!curiosLoaded) return ItemStack.EMPTY; - List curioSlots = CuriosApi.getCuriosHelper().findCurios(player,"glasses"); - if(curioSlots.isEmpty()) + List curioSlots = CuriosApi.getCuriosHelper().findCurios(player, "glasses"); + if (curioSlots.isEmpty()) return ItemStack.EMPTY; return curioSlots.get(0).stack(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/PocketPeripheralOwner.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/PocketPeripheralOwner.java index 65595fce5..424c4fd1a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/PocketPeripheralOwner.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/PocketPeripheralOwner.java @@ -11,6 +11,7 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; +import org.apache.commons.lang3.NotImplementedException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -85,7 +86,7 @@ public void markDataStorageDirty() { @Override public T withPlayer(Function function) { - throw new RuntimeException("Not implemented yet"); + throw new NotImplementedException(); } @Override @@ -95,13 +96,12 @@ public ItemStack getToolInMainHand() { @Override public ItemStack storeItem(ItemStack stored) { - // Tricks with inventory needed - throw new RuntimeException("Not implemented yet"); + throw new NotImplementedException(); } @Override public void destroyUpgrade() { - throw new RuntimeException("Not implemented yet"); + throw new NotImplementedException(); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java b/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java index 545859acd..87858c74d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java @@ -32,15 +32,14 @@ public SmartGlassesContainer(int id, Predicate canUse, ServerComputer co addSlot(new SmartGlassesSlot(inventory, 2, 222, 166, SlotType.PERIPHERALS)); addSlot(new SmartGlassesSlot(inventory, 3, 240, 166, SlotType.PERIPHERALS)); addSlot(new SmartGlassesSlot(inventory, 4, 222, 184, SlotType.PERIPHERALS)); - addSlot(new SmartGlassesSlot(inventory, 5, 240, 184, SlotType.PERIPHERALS)); // Glasses Modules - addSlot(new SmartGlassesSlot(inventory, 6, 222, 148, SlotType.MODULES)); - addSlot(new SmartGlassesSlot(inventory, 7, 204, 166, SlotType.MODULES)); - addSlot(new SmartGlassesSlot(inventory, 8, 222, 166, SlotType.MODULES)); - addSlot(new SmartGlassesSlot(inventory, 9, 240, 166, SlotType.MODULES)); - addSlot(new SmartGlassesSlot(inventory, 10, 222, 184, SlotType.MODULES)); - addSlot(new SmartGlassesSlot(inventory, 11, 240, 184, SlotType.MODULES)); + addSlot(new SmartGlassesSlot(inventory, 5, 222, 148, SlotType.MODULES)); + addSlot(new SmartGlassesSlot(inventory, 6, 204, 166, SlotType.MODULES)); + addSlot(new SmartGlassesSlot(inventory, 7, 222, 166, SlotType.MODULES)); + addSlot(new SmartGlassesSlot(inventory, 8, 240, 166, SlotType.MODULES)); + addSlot(new SmartGlassesSlot(inventory, 9, 222, 184, SlotType.MODULES)); + addSlot(new SmartGlassesSlot(inventory, 10, 240, 184, SlotType.MODULES)); // Player inventory for (var y = 0; y < 3; y++) { diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/APItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/APItem.java index 34ffcbeb5..4959c75f0 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/APItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/APItem.java @@ -4,7 +4,7 @@ import java.util.function.Supplier; -public class APItem extends BaseItem { +public final class APItem extends BaseItem { private final Supplier enabledSup; diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesInterfaceItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesInterfaceItem.java index 3df07d864..ba924b23b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesInterfaceItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesInterfaceItem.java @@ -51,7 +51,7 @@ public InteractionResultHolder use(@NotNull Level world, @NotNull Pla SmartGlassesItem smartGlasses = (SmartGlassesItem) glasses.getItem(); - SmartGlassesComputer computer = smartGlasses.createServerComputer((ServerLevel) world, player, player.getInventory(), glasses); + SmartGlassesComputer computer = smartGlasses.getOrCreateComputer((ServerLevel) world, player, player.getInventory(), glasses); computer.turnOn(); LazyOptional itemHandler = glasses.getCapability(ForgeCapabilities.ITEM_HANDLER); diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java index 4b51d74a5..51d1a0e1a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java @@ -5,6 +5,7 @@ import dan200.computercraft.api.ComputerCraftAPI; import dan200.computercraft.api.filesystem.Mount; import dan200.computercraft.api.media.IMedia; +import dan200.computercraft.core.computer.ComputerSide; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ServerComputerRegistry; import dan200.computercraft.shared.computer.core.ServerContext; @@ -17,6 +18,7 @@ import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesComputer; import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesItemHandler; import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesMenuProvider; +import de.srendi.advancedperipherals.common.smartglasses.modules.ModulePeripheral; import net.minecraft.ChatFormatting; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; @@ -40,6 +42,7 @@ import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.server.ServerLifecycleHooks; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -67,7 +70,7 @@ public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundT @Override public LazyOptional getCapability(@NotNull Capability cap, @Nullable Direction side) { if (cap == ForgeCapabilities.ITEM_HANDLER) - return LazyOptional.of(() -> new SmartGlassesItemHandler(stack)).cast(); + return LazyOptional.of(() -> new SmartGlassesItemHandler(stack, getServerComputer(ServerLifecycleHooks.getCurrentServer(), stack))).cast(); return LazyOptional.empty(); } }; @@ -97,8 +100,6 @@ private boolean tick(ItemStack stack, Level world, Entity entity, SmartGlassesCo changed = true; stack.getOrCreateTag().putBoolean(NBT_ON, on); } - - return changed; } @@ -106,17 +107,11 @@ private boolean tick(ItemStack stack, Level world, Entity entity, SmartGlassesCo public void inventoryTick(@NotNull ItemStack stack, Level world, @NotNull Entity entity, int slotNum, boolean selected) { if (world.isClientSide) return; Container inventory = entity instanceof Player player ? player.getInventory() : null; - SmartGlassesComputer computer = createServerComputer((ServerLevel) world, entity, inventory, stack); + SmartGlassesComputer computer = getOrCreateComputer((ServerLevel) world, entity, inventory, stack); computer.keepAlive(); var changed = tick(stack, world, entity, computer); if (changed && inventory != null) inventory.setChanged(); - - LazyOptional itemHandler = stack.getCapability(ForgeCapabilities.ITEM_HANDLER); - if (itemHandler.isPresent() && itemHandler.resolve().isPresent()) { - IItemHandler glassesItemHandler = itemHandler.resolve().get(); - computer.updatePeripherals(stack, glassesItemHandler); - } } @ForgeOverride @@ -134,7 +129,7 @@ public InteractionResultHolder use(Level world, Player player, @NotNu ItemStack glasses = player.getItemInHand(hand); if (!world.isClientSide) { - SmartGlassesComputer computer = createServerComputer((ServerLevel) world, player, player.getInventory(), glasses); + SmartGlassesComputer computer = getOrCreateComputer((ServerLevel) world, player, player.getInventory(), glasses); computer.turnOn(); LazyOptional itemHandler = glasses.getCapability(ForgeCapabilities.ITEM_HANDLER); @@ -178,7 +173,7 @@ public String getCreatorModId(ItemStack stack) { return AdvancedPeripherals.MOD_ID; } - public SmartGlassesComputer createServerComputer(ServerLevel level, Entity entity, @Nullable Container inventory, ItemStack stack) { + public SmartGlassesComputer getOrCreateComputer(ServerLevel level, Entity entity, @Nullable Container inventory, ItemStack stack) { int sessionID = getSessionID(stack); ServerComputerRegistry registry = ServerContext.get(level.getServer()).registry(); @@ -195,6 +190,7 @@ public SmartGlassesComputer createServerComputer(ServerLevel level, Entity entit setInstanceID(stack, computer.register()); setSessionID(stack, registry.getSessionID()); + computer.setPeripheral(ComputerSide.BACK, new ModulePeripheral(computer)); computer.addAPI(new SmartGlassesAPI()); // Only turn on when initially creating the computer, rather than each tick. diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/WeakAutomataCore.java b/src/main/java/de/srendi/advancedperipherals/common/items/WeakAutomataCore.java index 49fcb2b16..0dd8b101f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/WeakAutomataCore.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/WeakAutomataCore.java @@ -1,6 +1,7 @@ package de.srendi.advancedperipherals.common.items; import de.srendi.advancedperipherals.common.configuration.APConfig; +import de.srendi.advancedperipherals.common.items.base.BaseItem; import de.srendi.advancedperipherals.common.setup.APItems; import de.srendi.advancedperipherals.common.util.EnumColor; import de.srendi.advancedperipherals.lib.metaphysics.IFeedableAutomataCore; @@ -26,7 +27,7 @@ import java.util.Map; import java.util.Optional; -public class WeakAutomataCore extends APItem implements IFeedableAutomataCore { +public class WeakAutomataCore extends BaseItem implements IFeedableAutomataCore { private static final String CONSUMED_ENTITY_COUNT = "consumed_entity_count"; private static final String CONSUMED_ENTITY_NAME = "consumed_entity_name"; @@ -49,11 +50,12 @@ public class WeakAutomataCore extends APItem implements IFeedableAutomataCore { } public WeakAutomataCore(Properties properties) { - super(properties, APConfig.METAPHYSICS_CONFIG.enableWeakAutomataCore); + super(properties); } - public WeakAutomataCore() { - super(APConfig.METAPHYSICS_CONFIG.enableWeakAutomataCore); + @Override + public boolean isEnabled() { + return APConfig.METAPHYSICS_CONFIG.enableWeakAutomataCore.get(); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java index 8aff2993a..5c4c9e05b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java @@ -3,33 +3,24 @@ import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.items.*; import de.srendi.advancedperipherals.common.items.base.SmartGlassesMaterials; +import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.OverlayGlassesItem; import net.minecraft.world.item.Item; import net.minecraftforge.registries.RegistryObject; public class APItems { public static final RegistryObject CHUNK_CONTROLLER = APRegistration.ITEMS.register("chunk_controller", () -> new APItem(new Item.Properties().stacksTo(16), APConfig.PERIPHERALS_CONFIG.enableChunkyTurtle)); - public static final RegistryObject SMART_GLASSES = APRegistration.ITEMS.register("smart_glasses", () -> new SmartGlassesItem(SmartGlassesMaterials.CHAIN)); - public static final RegistryObject SMART_GLASSES_NETHERITE = APRegistration.ITEMS.register("smart_glasses_netherite", () -> new SmartGlassesItem(SmartGlassesMaterials.NETHERITE)); - public static final RegistryObject SMART_GLASSES_INTERFACE = APRegistration.ITEMS.register("smart_glasses_interface", SmartGlassesInterfaceItem::new); - + public static final RegistryObject OVERLAY_GLASSES = APRegistration.ITEMS.register("overlayglasses", OverlayGlassesItem::new); public static final RegistryObject COMPUTER_TOOL = APRegistration.ITEMS.register("computer_tool", () -> new APItem(new Item.Properties().stacksTo(1), () -> true)); - public static final RegistryObject MEMORY_CARD = APRegistration.ITEMS.register("memory_card", MemoryCardItem::new); - public static final RegistryObject END_AUTOMATA_CORE = APRegistration.ITEMS.register("end_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableEndAutomataCore)); - public static final RegistryObject HUSBANDRY_AUTOMATA_CORE = APRegistration.ITEMS.register("husbandry_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableHusbandryAutomataCore)); - public static final RegistryObject WEAK_AUTOMATA_CORE = APRegistration.ITEMS.register("weak_automata_core", () -> new WeakAutomataCore(new Item.Properties().stacksTo(1))); - public static final RegistryObject OVERPOWERED_WEAK_AUTOMATA_CORE = APRegistration.ITEMS.register("overpowered_weak_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableWeakAutomataCore)); - public static final RegistryObject OVERPOWERED_END_AUTOMATA_CORE = APRegistration.ITEMS.register("overpowered_end_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableEndAutomataCore)); - public static final RegistryObject OVERPOWERED_HUSBANDRY_AUTOMATA_CORE = APRegistration.ITEMS.register("overpowered_husbandry_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableHusbandryAutomataCore)); public static void register() { diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SlotType.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SlotType.java index 693373f59..f5498935a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SlotType.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SlotType.java @@ -19,4 +19,4 @@ public Component getName() { public static SlotType defaultType() { return PERIPHERALS; } -} \ No newline at end of file +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java index 155974497..7334edd2a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java @@ -6,6 +6,8 @@ import dan200.computercraft.impl.PocketUpgrades; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ServerComputer; +import de.srendi.advancedperipherals.common.smartglasses.modules.IModule; +import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleItem; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; @@ -17,7 +19,6 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraftforge.items.IItemHandler; -import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; import java.util.*; @@ -35,6 +36,7 @@ public class SmartGlassesComputer extends ServerComputer implements IPocketAcces private boolean lightChanged = false; private final Set tracking = new HashSet<>(); + private final Set modules = new HashSet<>(); public SmartGlassesComputer(ServerLevel world, BlockPos position, int computerID, @Nullable String label, ComputerFamily family) { super(world, position, computerID, label, family, 39, 13); @@ -101,8 +103,8 @@ public Map getUpgrades() { return Collections.emptyMap(); } - public void updatePeripherals(@NotNull ItemStack glasses, IItemHandler itemHandler) { - for (int slot = 0; slot < 6; slot++) { + public void updatePeripheralsAndModules(IItemHandler itemHandler) { + for (int slot = 0; slot < 5; slot++) { ItemStack peripheralItem = itemHandler.getStackInSlot(slot); if (!peripheralItem.isEmpty()) { IPocketUpgrade upgrade = PocketUpgrades.instance().get(peripheralItem); @@ -113,6 +115,13 @@ public void updatePeripherals(@NotNull ItemStack glasses, IItemHandler itemHandl } } } + modules.clear(); + for (int slot = 6; slot < 11; slot++) { + ItemStack peripheralItem = itemHandler.getStackInSlot(slot); + if (!peripheralItem.isEmpty() && peripheralItem.getItem() instanceof IModuleItem module) { + modules.add(module.getModule()); + } + } } public synchronized void updateValues(@Nullable Entity entity, ItemStack stack, @Nullable IPocketUpgrade upgrade) { @@ -128,7 +137,6 @@ public synchronized void updateValues(@Nullable Entity entity, ItemStack stack, this.stack = stack; invalidatePeripheral(); - } @Override @@ -151,6 +159,12 @@ public void tickServer() { if (tracking.add(player)) added.add(player); } } + + modules.forEach(module -> module.tick(smartGlassesAccess)); + } + + public Set getModules() { + return modules; } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java index 9fba96322..381bba03a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java @@ -18,9 +18,11 @@ public class SmartGlassesItemHandler implements IItemHandlerModifiable, INBTSeri private final NonNullList items = NonNullList.withSize(SLOTS, ItemStack.EMPTY); private final ItemStack stack; + private final SmartGlassesComputer computer; - public SmartGlassesItemHandler(ItemStack stack) { + public SmartGlassesItemHandler(ItemStack stack, SmartGlassesComputer computer) { this.stack = stack; + this.computer = computer; deserializeNBT(stack.getOrCreateTagElement("Items")); } @@ -122,6 +124,7 @@ public void setStackInSlot(int slot, @NotNull ItemStack stack) { public void setChanged() { stack.getOrCreateTag().put("Items", serializeNBT()); + computer.updatePeripheralsAndModules(this); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesSlot.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesSlot.java index 42a0f3684..5c16249b8 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesSlot.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesSlot.java @@ -30,8 +30,7 @@ public static ComputerSide indexToSide(int slot) { case 1 -> ComputerSide.LEFT; case 2 -> ComputerSide.FRONT; case 3 -> ComputerSide.RIGHT; - case 4 -> ComputerSide.BOTTOM; - default -> ComputerSide.BACK; + default -> ComputerSide.BOTTOM; }; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java index 7f721f40c..c30f0cc54 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java @@ -1,4 +1,19 @@ package de.srendi.advancedperipherals.common.smartglasses.modules; +import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesAccess; +import net.minecraft.resources.ResourceLocation; + public interface IModule { + + ResourceLocation getName(); + + /** + * Used to define the available functions of the module. This method only gets called once when indexing the modules + * + * @return an object containing lua functions {@link dan200.computercraft.api.lua.LuaFunction} + */ + IModuleFunctions getMethods(); + + void tick(SmartGlassesAccess smartGlassesAccess); + } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModuleFunctions.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModuleFunctions.java new file mode 100644 index 000000000..6b873c4cb --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModuleFunctions.java @@ -0,0 +1,11 @@ +package de.srendi.advancedperipherals.common.smartglasses.modules; + +/** + * Used to define the available functions of the module. + * Functions can be defined by creating final public methods annotated with the @{@link dan200.computercraft.api.lua.LuaFunction} annotation + */ +public interface IModuleFunctions { + + IModuleFunctions EMPTY = new IModuleFunctions() {}; + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModuleItem.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModuleItem.java new file mode 100644 index 000000000..748063fef --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModuleItem.java @@ -0,0 +1,7 @@ +package de.srendi.advancedperipherals.common.smartglasses.modules; + +public interface IModuleItem { + + IModule getModule(); + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java new file mode 100644 index 000000000..1fe4bb8a0 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java @@ -0,0 +1,29 @@ +package de.srendi.advancedperipherals.common.smartglasses.modules; + +import dan200.computercraft.api.lua.LuaFunction; +import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesComputer; +import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; + +import java.util.ArrayList; +import java.util.List; + +public class ModulePeripheral extends BasePeripheral { + + public static final String PERIPHERAL_TYPE = "smartGlasses"; + + public ModulePeripheral(SmartGlassesComputer computer) { + super(PERIPHERAL_TYPE, new ModulePeripheralOwner(computer)); + } + + @Override + public boolean isEnabled() { + return true; + } + + @LuaFunction + public final String[] getModules() { + List modules = new ArrayList<>(getPeripheralOwner().getComputer().getModules().size()); + getPeripheralOwner().getComputer().getModules().forEach(module -> modules.add(module.getName().toString())); + return modules.toArray(new String[0]); + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheralOwner.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheralOwner.java index 2a09d0527..67bf2b6f0 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheralOwner.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheralOwner.java @@ -1,91 +1,104 @@ package de.srendi.advancedperipherals.common.smartglasses.modules; -import dan200.computercraft.api.pocket.IPocketAccess; -import de.srendi.advancedperipherals.common.addons.computercraft.owner.IOwnerAbility; -import de.srendi.advancedperipherals.common.addons.computercraft.owner.IPeripheralOwner; -import de.srendi.advancedperipherals.common.addons.computercraft.owner.PeripheralOwnerAbility; +import de.srendi.advancedperipherals.common.addons.computercraft.owner.BasePeripheralOwner; +import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesComputer; import de.srendi.advancedperipherals.common.util.fakeplayer.APFakePlayer; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.FrontAndTop; import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; +import org.apache.commons.lang3.NotImplementedException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collection; import java.util.function.Function; -public class ModulePeripheralOwner implements IPeripheralOwner { +public class ModulePeripheralOwner extends BasePeripheralOwner { //TODO: Think about making our own smart glasses access so we don't have the not used stuff like the color or the light // We would need to remove the pocket stuff from the SmartGlassesComputer - private IPocketAccess access; + private final SmartGlassesComputer computer; - public ModulePeripheralOwner(IPocketAccess access) { - this.access = access; + public ModulePeripheralOwner(SmartGlassesComputer computer) { + this.computer = computer; } + @Nullable @Override - public @Nullable String getCustomName() { - return null; + public String getCustomName() { + return "smartglasses"; } + @Nullable @Override - public @Nullable Level getLevel() { - return access.getEntity().getLevel(); + public Level getLevel() { + return computer.getEntity().getLevel(); } + @NotNull @Override - public @NotNull BlockPos getPos() { - return access.getEntity().getOnPos(); + public BlockPos getPos() { + return computer.getEntity().getOnPos(); } + @NotNull @Override - public @NotNull Direction getFacing() { - return null; + public Direction getFacing() { + return Direction.NORTH; } + @NotNull @Override - public @NotNull FrontAndTop getOrientation() { - return null; + public FrontAndTop getOrientation() { + return FrontAndTop.NORTH_UP; } + @NotNull + public SmartGlassesComputer getComputer() { + return computer; + } + + @Nullable @Override - public @Nullable Player getOwner() { + public Player getOwner() { + Entity owner = computer.getEntity(); + if (owner instanceof Player player) return player; return null; } + @NotNull @Override - public @NotNull CompoundTag getDataStorage() { - return null; + public CompoundTag getDataStorage() { + return computer.getUpgradeNBTData(); } @Override public void markDataStorageDirty() { - + computer.updateUpgradeNBTData(); } @Override public T withPlayer(Function function) { - return null; + throw new NotImplementedException(); } @Override public ItemStack getToolInMainHand() { - return null; + return ItemStack.EMPTY; } @Override public ItemStack storeItem(ItemStack stored) { - return null; + throw new NotImplementedException(); } @Override public void destroyUpgrade() { - + throw new NotImplementedException(); } @Override @@ -98,18 +111,4 @@ public boolean move(@NotNull Level level, @NotNull BlockPos pos) { return false; } - @Override - public void attachAbility(PeripheralOwnerAbility ability, T abilityImplementation) { - - } - - @Override - public @Nullable T getAbility(PeripheralOwnerAbility ability) { - return null; - } - - @Override - public Collection getAbilities() { - return null; - } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesItem.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesItem.java new file mode 100644 index 000000000..d0c743865 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesItem.java @@ -0,0 +1,18 @@ +package de.srendi.advancedperipherals.common.smartglasses.modules.overlay; + +import de.srendi.advancedperipherals.common.items.base.BaseItem; +import de.srendi.advancedperipherals.common.smartglasses.modules.IModule; +import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleItem; + +public class OverlayGlassesItem extends BaseItem implements IModuleItem { + + @Override + public boolean isEnabled() { + return true; + } + + @Override + public IModule getModule() { + return new OverlayModule(); + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java new file mode 100644 index 000000000..5d8e9aac9 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java @@ -0,0 +1,29 @@ +package de.srendi.advancedperipherals.common.smartglasses.modules.overlay; + +import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesAccess; +import de.srendi.advancedperipherals.common.smartglasses.modules.IModule; +import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleFunctions; +import net.minecraft.resources.ResourceLocation; + +/** + * We want to support scripts which were made for the plethora classes. So we call this item the same as the overlay item from plethora + * We'll also add the same functions + */ +public class OverlayModule implements IModule { + + @Override + public ResourceLocation getName() { + return new ResourceLocation(AdvancedPeripherals.MOD_ID, "glasses"); + } + + @Override + public IModuleFunctions getMethods() { + return IModuleFunctions.EMPTY; + } + + @Override + public void tick(SmartGlassesAccess smartGlassesAccess) { + + } +} From 3ec874bf340cd584c570ce7fb58130e505435fbb Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 24 Mar 2023 14:56:50 +0100 Subject: [PATCH 032/228] Remove old ar controller block and peripheral --- .../peripheral/SmartGlassesPeripheral.java | 19 ---------------- .../SmartGlassesControllerEntity.java | 22 ------------------- .../container/SmartGlassesContainer.java | 2 +- .../data/BlockStatesAndModelsProvider.java | 1 - .../common/data/EnUsLanguageProvider.java | 1 - .../common/data/RecipesProvider.java | 10 --------- .../common/setup/APBlockEntityTypes.java | 1 - .../common/setup/APBlocks.java | 1 - 8 files changed, 1 insertion(+), 56 deletions(-) delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/SmartGlassesPeripheral.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/SmartGlassesControllerEntity.java diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/SmartGlassesPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/SmartGlassesPeripheral.java deleted file mode 100644 index 73b327bea..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/SmartGlassesPeripheral.java +++ /dev/null @@ -1,19 +0,0 @@ -package de.srendi.advancedperipherals.common.addons.computercraft.peripheral; - -import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner; -import de.srendi.advancedperipherals.common.blocks.blockentities.SmartGlassesControllerEntity; -import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; - -public class SmartGlassesPeripheral extends BasePeripheral> { - - public SmartGlassesPeripheral(SmartGlassesControllerEntity tileEntity) { - super("smartglasses", new BlockEntityPeripheralOwner<>(tileEntity)); - } - - @Override - public boolean isEnabled() { - return APConfig.PERIPHERALS_CONFIG.enableSmartGlasses.get(); - } - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/SmartGlassesControllerEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/SmartGlassesControllerEntity.java deleted file mode 100644 index 458d1b633..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/SmartGlassesControllerEntity.java +++ /dev/null @@ -1,22 +0,0 @@ -package de.srendi.advancedperipherals.common.blocks.blockentities; - -import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.SmartGlassesPeripheral; -import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; -import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.block.state.BlockState; -import org.jetbrains.annotations.NotNull; - -public class SmartGlassesControllerEntity extends PeripheralBlockEntity { - - public SmartGlassesControllerEntity(BlockPos pos, BlockState state) { - super(APBlockEntityTypes.AR_CONTROLLER.get(), pos, state); - } - - - @NotNull - @Override - protected SmartGlassesPeripheral createPeripheral() { - return null; - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java b/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java index 87858c74d..c53cc5092 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java @@ -56,7 +56,7 @@ public SmartGlassesContainer(int id, Predicate canUse, ServerComputer co } public SmartGlassesContainer(int id, Predicate predicate, ServerComputer computer, ComputerContainerData data, Inventory player, ItemStack glasses) { - this( id, predicate, computer, player, glasses.getCapability(ForgeCapabilities.ITEM_HANDLER).resolve().get(), data); + this( id, predicate, computer, player, glasses.getCapability(ForgeCapabilities.ITEM_HANDLER).resolve().orElseThrow(), data); } @NotNull diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/BlockStatesAndModelsProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/BlockStatesAndModelsProvider.java index 18995fb8d..c3c000061 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/BlockStatesAndModelsProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/BlockStatesAndModelsProvider.java @@ -27,7 +27,6 @@ protected void registerStatesAndModels() { peripheralBlock(APBlocks.RS_BRIDGE.get(), "front"); peripheralBlock(APBlocks.ENERGY_DETECTOR.get(), "front", "back"); peripheralBlock(APBlocks.PERIPHERAL_CASING.get()); - peripheralBlock(APBlocks.AR_CONTROLLER.get(), "front"); peripheralBlock(APBlocks.INVENTORY_MANAGER.get(), "front"); peripheralBlock(APBlocks.REDSTONE_INTEGRATOR.get(), "front"); peripheralBlock(APBlocks.BLOCK_READER.get(), generateModel(APBlocks.BLOCK_READER.get(), false, "north", "south", "east", "west", "up", "down")); diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java index 36579c704..e05c801d3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java @@ -57,7 +57,6 @@ private void addItems() { private void addBlocks() { addBlock(APBlocks.BLOCK_READER, "Block Reader"); addBlock(APBlocks.CHAT_BOX, "Chat Box"); - addBlock(APBlocks.AR_CONTROLLER, "Ar Controller"); addBlock(APBlocks.COLONY_INTEGRATOR, "Colony Integrator"); addBlock(APBlocks.ENERGY_DETECTOR, "Energy Detector"); addBlock(APBlocks.ENVIRONMENT_DETECTOR, "Environment Detector"); diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java index a688af33b..876c98221 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java @@ -60,16 +60,6 @@ private void addShapeless(@NotNull Consumer consumer) { } private void addShaped(@NotNull Consumer consumer) { - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APBlocks.AR_CONTROLLER.get()) - .define('E', Tags.Items.ENDER_PEARLS) - .define('C', CASING) - .define('G', Items.SMOOTH_STONE) - .pattern("GEG") - .pattern("ECE") - .pattern("GEG") - .unlockedBy("has_item", has(CASING)) - .save(consumer); - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APItems.SMART_GLASSES.get()) .define('E', Tags.Items.ENDER_PEARLS) .define('S', Tags.Items.RODS_WOODEN) diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java index 74541e747..89c23bbc7 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java @@ -19,7 +19,6 @@ static void register() { public static final RegistryObject> ENERGY_DETECTOR = APRegistration.TILE_ENTITIES.register("energy_detector", () -> new BlockEntityType<>(EnergyDetectorEntity::new, Sets.newHashSet(APBlocks.ENERGY_DETECTOR.get()), null)); public static final RegistryObject> FLUID_DETECTOR = APRegistration.TILE_ENTITIES.register("fluid_detector", () -> new BlockEntityType<>(FluidDetectorEntity::new, Sets.newHashSet(APBlocks.FLUID_DETECTOR.get()), null)); public static final RegistryObject> GAS_DETECTOR = APAddons.mekanismLoaded ? APRegistration.TILE_ENTITIES.register("gas_detector", () -> new BlockEntityType<>(GasDetectorEntity::new, Sets.newHashSet(APBlocks.GAS_DETECTOR.get()), null)) : null; - public static final RegistryObject> AR_CONTROLLER = APRegistration.TILE_ENTITIES.register("ar_controller", () -> new BlockEntityType<>(SmartGlassesControllerEntity::new, Sets.newHashSet(APBlocks.AR_CONTROLLER.get()), null)); public static final RegistryObject> INVENTORY_MANAGER = APRegistration.TILE_ENTITIES.register("inventory_manager", () -> new BlockEntityType<>(InventoryManagerEntity::new, Sets.newHashSet(APBlocks.INVENTORY_MANAGER.get()), null)); public static final RegistryObject> REDSTONE_INTEGRATOR = APRegistration.TILE_ENTITIES.register("redstone_integrator", () -> new BlockEntityType<>(RedstoneIntegratorEntity::new, Sets.newHashSet(APBlocks.REDSTONE_INTEGRATOR.get()), null)); public static final RegistryObject> BLOCK_READER = APRegistration.TILE_ENTITIES.register("block_reader", () -> new BlockEntityType<>(BlockReaderEntity::new, Sets.newHashSet(APBlocks.BLOCK_READER.get()), null)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java index 22b3b0ee8..d3ac032c9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java @@ -31,7 +31,6 @@ static void register() { public static final RegistryObject FLUID_DETECTOR = register("fluid_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.FLUID_DETECTOR, true), () -> new APBlockItem(APBlocks.FLUID_DETECTOR.get(), APConfig.PERIPHERALS_CONFIG.enableFluidDetector)); public static final RegistryObject GAS_DETECTOR = register("gas_detector", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("mekanism") ? APBlockEntityTypes.GAS_DETECTOR : null, true), () -> new APBlockItem(APBlocks.GAS_DETECTOR.get(), APConfig.PERIPHERALS_CONFIG.enableGasDetector)); public static final RegistryObject PERIPHERAL_CASING = register("peripheral_casing", BaseBlock::new, () -> new APBlockItem(APBlocks.PERIPHERAL_CASING.get(), new Item.Properties().stacksTo(16), () -> true)); - public static final RegistryObject AR_CONTROLLER = register("ar_controller", () -> new APBlockEntityBlock<>(APBlockEntityTypes.AR_CONTROLLER, false), () -> new APBlockItem(APBlocks.AR_CONTROLLER.get(), APConfig.PERIPHERALS_CONFIG.enableSmartGlasses)); public static final RegistryObject INVENTORY_MANAGER = register("inventory_manager", () -> new APBlockEntityBlock<>(APBlockEntityTypes.INVENTORY_MANAGER, false), () -> new APBlockItem(APBlocks.INVENTORY_MANAGER.get(), APConfig.PERIPHERALS_CONFIG.enableInventoryManager)); public static final RegistryObject REDSTONE_INTEGRATOR = register("redstone_integrator", RedstoneIntegratorBlock::new, () -> new APBlockItem(APBlocks.REDSTONE_INTEGRATOR.get(), APConfig.PERIPHERALS_CONFIG.enableRedstoneIntegrator)); public static final RegistryObject BLOCK_READER = register("block_reader", () -> new APBlockEntityBlock<>(APBlockEntityTypes.BLOCK_READER, true), () -> new APBlockItem(APBlocks.BLOCK_READER.get(), APConfig.PERIPHERALS_CONFIG.enableBlockReader)); From 0c718cc1eeae4301bce3db3ea457392dccefafe4 Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 24 Mar 2023 17:00:30 +0100 Subject: [PATCH 033/228] Some distance detector progress This commits mainly exists because I'm swichting to another computer --- .../renderer/DistanceDetectorRenderer.java | 63 ++++++++----------- .../client/screens/SmartGlassesScreen.java | 4 +- .../client/screens/base/BaseItemScreen.java | 5 +- .../DistanceDetectorPeripheral.java | 6 +- .../blockentities/DistanceDetectorEntity.java | 57 +++++++++++++++++ .../container/SmartGlassesContainer.java | 13 ++-- .../common/smartglasses/SmartGlassesSlot.java | 5 ++ 7 files changed, 100 insertions(+), 53 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java b/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java index a118d4322..2593df24a 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java +++ b/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java @@ -28,64 +28,51 @@ public DistanceDetectorRenderer(BlockEntityRendererProvider.Context pContext) { @Override public void render(@NotNull DistanceDetectorEntity pBlockEntity, float pPartialTick, @NotNull PoseStack pPoseStack, MultiBufferSource pBufferSource, int pPackedLight, int pPackedOverlay) { - long i = pBlockEntity.getLevel().getGameTime(); - renderBeaconBeam(pBlockEntity, pPoseStack, pBufferSource, BeaconRenderer.BEAM_LOCATION, pPartialTick, 1, i, 0, 1, EnumColor.DARK_RED.getRgb(), 0.05f, 0.09f); - renderBeaconBeam(pBlockEntity, pPoseStack, pBufferSource, BeaconRenderer.BEAM_LOCATION, pPartialTick, 1, i, 1, 1, EnumColor.DARK_RED.getRgb(), 0.05f, 0.09f); - renderBeaconBeam(pBlockEntity, pPoseStack, pBufferSource, BeaconRenderer.BEAM_LOCATION, pPartialTick, 1, i, 2, 1, EnumColor.DARK_RED.getRgb(), 0.05f, 0.09f); + if(pBlockEntity.getLaserVisibility()) + renderBeaconBeam(pBlockEntity, pPoseStack, pBufferSource, BeaconRenderer.BEAM_LOCATION, pPartialTick, 1, 0, pBlockEntity.getDistance() + 0.5f, EnumColor.DARK_RED.getRgb(), 0.05f, 0.09f); } + @Override public boolean shouldRenderOffScreen(@NotNull DistanceDetectorEntity pBlockEntity) { return true; } + @Override public int getViewDistance() { return 256; } public boolean shouldRender(DistanceDetectorEntity pBlockEntity, Vec3 pCameraPos) { - return Vec3.atCenterOf(pBlockEntity.getBlockPos()).multiply(1.0D, 0.0D, 1.0D).closerThan(pCameraPos.multiply(1.0D, 0.0D, 1.0D), (double) this.getViewDistance()); + return true; } - public static void renderBeaconBeam(DistanceDetectorEntity detectorEntity, PoseStack pPoseStack, MultiBufferSource pBufferSource, ResourceLocation pBeamLocation, float pPartialTick, float pTextureScale, long pGameTime, int pYOffset, int pHeight, float[] pColors, float pBeamRadius, float pGlowRadius) { - int i = pYOffset + pHeight; + public static void renderBeaconBeam(DistanceDetectorEntity detectorEntity, PoseStack pPoseStack, MultiBufferSource pBufferSource, ResourceLocation pBeamLocation, float pPartialTick, float pTextureScale, int pYOffset, float pHeight, float[] pColors, float pBeamRadius, float pGlowRadius) { + long pGameTime = detectorEntity.getLevel().getGameTime(); + float maxX = pYOffset + pHeight; Direction direction = detectorEntity.getBlockState().getValue(BaseBlock.ORIENTATION).front(); pPoseStack.pushPose(); pPoseStack.translate(0.5D, 0.5D, 0.5D); - float f = (float) Math.floorMod(pGameTime, 360) + pPartialTick; - float f1 = pHeight < 0 ? f : -f; - float f2 = Mth.frac(f1 * 0.2F - (float) Mth.floor(f1 * 0.1F)); - float f3 = pColors[0]; - float f4 = pColors[1]; - float f5 = pColors[2]; + float degrees = Math.floorMod(pGameTime, 360) + pPartialTick; + float reversedDegrees = pHeight < 0 ? degrees : -degrees; + float time = Mth.frac(reversedDegrees * 0.2F - Mth.floor(reversedDegrees * 0.1F)); + float r = pColors[0]; + float g = pColors[1]; + float b = pColors[2]; pPoseStack.pushPose(); pPoseStack.mulPose(direction.getRotation()); - pPoseStack.mulPose(Axis.YP.rotationDegrees(f * 2.25F - 45.0F)); - float f6 = 0.0F; - float f8 = 0.0F; - float f9 = -pBeamRadius; - float f10 = 0.0F; - float f11 = 0.0F; - float f12 = -pBeamRadius; - float f13 = 0.0F; - float f14 = 1.0F; - float f15 = -1.0F + f2; - float f16 = (float) pHeight * pTextureScale * (0.5F / pBeamRadius) + f15; - renderPart(pPoseStack, pBufferSource.getBuffer(RenderType.beaconBeam(pBeamLocation, false)), f3, f4, f5, 1.0F, pYOffset, i, 0.0F, pBeamRadius, pBeamRadius, 0.0F, f9, 0.0F, 0.0F, f12, 0.0F, 1.0F, f16, f15); + pPoseStack.mulPose(Axis.YP.rotationDegrees(degrees * 2.25F - 45.0F)); + float f15 = -1.0F + time; + float f16 = pHeight * pTextureScale * (0.5F / pBeamRadius) + f15; + renderPart(pPoseStack, pBufferSource.getBuffer(RenderType.beaconBeam(pBeamLocation, false)), r, g, b, 1.0F, pYOffset, maxX, 0.0F, pBeamRadius, pBeamRadius, 0.0F, -pBeamRadius, 0.0F, 0.0F, -pBeamRadius, 0.0F, 1.0F, f16, f15); pPoseStack.popPose(); pPoseStack.mulPose(direction.getRotation()); - f6 = -pGlowRadius; - float f7 = -pGlowRadius; - f8 = -pGlowRadius; - f9 = -pGlowRadius; - f13 = 0.0F; - f14 = 1.0F; - f15 = -1.0F + f2; - f16 = (float) pHeight * pTextureScale + f15; - renderPart(pPoseStack, pBufferSource.getBuffer(RenderType.beaconBeam(pBeamLocation, true)), f3, f4, f5, 0.225F, pYOffset, i, f6, f7, pGlowRadius, f8, f9, pGlowRadius, pGlowRadius, pGlowRadius, 0.0F, 1.0F, f16, f15); + f15 = -1.0F + time; + f16 = pHeight * pTextureScale + f15; + renderPart(pPoseStack, pBufferSource.getBuffer(RenderType.beaconBeam(pBeamLocation, true)), r, g, b, 0.225F, pYOffset, maxX, -pGlowRadius, -pGlowRadius, pGlowRadius, -pGlowRadius, -pBeamRadius, pGlowRadius, pGlowRadius, pGlowRadius, 0.0F, 1.0F, f16, f15); pPoseStack.popPose(); } - private static void renderPart(PoseStack pPoseStack, VertexConsumer pConsumer, float pRed, float pGreen, float pBlue, float pAlpha, int pMinY, int pMaxY, float pX0, float pZ0, float pX1, float pZ1, float pX2, float pZ2, float pX3, float pZ3, float pMinU, float pMaxU, float pMinV, float pMaxV) { + private static void renderPart(PoseStack pPoseStack, VertexConsumer pConsumer, float pRed, float pGreen, float pBlue, float pAlpha, int pMinY, float pMaxY, float pX0, float pZ0, float pX1, float pZ1, float pX2, float pZ2, float pX3, float pZ3, float pMinU, float pMaxU, float pMinV, float pMaxV) { PoseStack.Pose posestackPose = pPoseStack.last(); Matrix4f matrix4f = posestackPose.pose(); Matrix3f matrix3f = posestackPose.normal(); @@ -95,15 +82,15 @@ private static void renderPart(PoseStack pPoseStack, VertexConsumer pConsumer, f renderQuad(matrix4f, matrix3f, pConsumer, pRed, pGreen, pBlue, pAlpha, pMinY, pMaxY, pX2, pZ2, pX0, pZ0, pMinU, pMaxU, pMinV, pMaxV); } - private static void renderQuad(Matrix4f pPose, Matrix3f pNormal, VertexConsumer pConsumer, float pRed, float pGreen, float pBlue, float pAlpha, int pMinY, int pMaxY, float pMinX, float pMinZ, float pMaxX, float pMaxZ, float pMinU, float pMaxU, float pMinV, float pMaxV) { + private static void renderQuad(Matrix4f pPose, Matrix3f pNormal, VertexConsumer pConsumer, float pRed, float pGreen, float pBlue, float pAlpha, int pMinY, float pMaxY, float pMinX, float pMinZ, float pMaxX, float pMaxZ, float pMinU, float pMaxU, float pMinV, float pMaxV) { addVertex(pPose, pNormal, pConsumer, pRed, pGreen, pBlue, pAlpha, pMaxY, pMinX, pMinZ, pMaxU, pMinV); addVertex(pPose, pNormal, pConsumer, pRed, pGreen, pBlue, pAlpha, pMinY, pMinX, pMinZ, pMaxU, pMaxV); addVertex(pPose, pNormal, pConsumer, pRed, pGreen, pBlue, pAlpha, pMinY, pMaxX, pMaxZ, pMinU, pMaxV); addVertex(pPose, pNormal, pConsumer, pRed, pGreen, pBlue, pAlpha, pMaxY, pMaxX, pMaxZ, pMinU, pMinV); } - private static void addVertex(Matrix4f pPose, Matrix3f pNormal, VertexConsumer pConsumer, float pRed, float pGreen, float pBlue, float pAlpha, int pY, float pX, float pZ, float pU, float pV) { - pConsumer.vertex(pPose, pX, (float) pY, pZ).color(pRed, pGreen, pBlue, pAlpha).uv(pU, pV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(15728880).normal(pNormal, 0.0F, 1.0F, 0.0F).endVertex(); + private static void addVertex(Matrix4f pPose, Matrix3f pNormal, VertexConsumer pConsumer, float pRed, float pGreen, float pBlue, float pAlpha, float pY, float pX, float pZ, float pU, float pV) { + pConsumer.vertex(pPose, pX, pY, pZ).color(pRed, pGreen, pBlue, pAlpha).uv(pU, pV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(15728880).normal(pNormal, 0.0F, 1.0F, 0.0F).endVertex(); } } diff --git a/src/main/java/de/srendi/advancedperipherals/client/screens/SmartGlassesScreen.java b/src/main/java/de/srendi/advancedperipherals/client/screens/SmartGlassesScreen.java index 5c4ebf5f0..3f6d8475e 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/screens/SmartGlassesScreen.java +++ b/src/main/java/de/srendi/advancedperipherals/client/screens/SmartGlassesScreen.java @@ -25,7 +25,7 @@ public class SmartGlassesScreen extends AbstractComputerScreen extends AbstractContainerScreen { @@ -19,14 +20,14 @@ public BaseItemScreen(T screenContainer, Inventory inv, Component titleIn) { } @Override - public void render(PoseStack matrixStack, int x, int y, float partialTicks) { + public void render(@NotNull PoseStack matrixStack, int x, int y, float partialTicks) { renderBackground(matrixStack); super.render(matrixStack, x, y, partialTicks); renderTooltip(matrixStack, x, y); } @Override - protected void renderBg(PoseStack matrixStack, float partialTicks, int x, int y) { + protected void renderBg(@NotNull PoseStack matrixStack, float partialTicks, int x, int y) { RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShaderTexture(0, getTexture()); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java index cca9b9963..3add59f17 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java @@ -18,14 +18,14 @@ public class DistanceDetectorPeripheral extends BasePeripheral> { - public static final String TYPE = "distanceDetector"; + public static final String PERIPHERAL_TYPE = "distanceDetector"; private double height = 0.5; private DetectionType detectionType = DetectionType.BOTH; private boolean ignoreTransparent = true; private boolean laserVisible = true; public DistanceDetectorPeripheral(DistanceDetectorEntity tileEntity) { - super(TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); + super(PERIPHERAL_TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); } @Override @@ -35,6 +35,7 @@ public boolean isEnabled() { @LuaFunction public final boolean setLaserVisibility(boolean laser) { + getPeripheralOwner().tileEntity.setShowLaser(laser); return laserVisible = laser; } @@ -111,6 +112,7 @@ public final double getDistance() { distance = getPos().distManhattan(new Vec3i(entityHitResult.getLocation().x, entityHitResult.getLocation().y, entityHitResult.getLocation().z)); } } + getPeripheralOwner().tileEntity.setDistance(distance -1); return distance - 1; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java index 8a256e024..174573697 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java @@ -4,11 +4,19 @@ import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.Connection; +import net.minecraft.network.protocol.PacketFlow; +import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class DistanceDetectorEntity extends PeripheralBlockEntity { + private float distance = 0; + private boolean showLaser = true; + public DistanceDetectorEntity(BlockPos pos, BlockState state) { super(APBlockEntityTypes.DISTANCE_DETECTOR.get(), pos, state); } @@ -19,4 +27,53 @@ protected DistanceDetectorPeripheral createPeripheral() { return new DistanceDetectorPeripheral(this); } + public void setShowLaser(boolean showLaser) { + if(this.showLaser != showLaser) + level.setBlockAndUpdate(getBlockPos(), getBlockState()); + + this.showLaser = showLaser; + } + + public void setDistance(float distance) { + if(this.distance != distance) + level.setBlockAndUpdate(getBlockPos(), getBlockState()); + this.distance = distance; + } + + public float getDistance() { + return distance; + } + + public boolean getLaserVisibility() { + return showLaser; + } + + @Override + public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) { + if (level.isClientSide && net.getDirection() == PacketFlow.CLIENTBOUND) { + //Handle the update tag when we are on the client + handleUpdateTag(pkt.getTag()); + } + } + + @Override + public CompoundTag getUpdateTag() { + CompoundTag tag = new CompoundTag(); + tag.putFloat("distance", distance); + tag.putBoolean("showLaser", showLaser); + return tag; + } + + @Override + public void handleUpdateTag(CompoundTag tag) { + this.distance = tag.getFloat("distance"); + this.showLaser = tag.getBoolean("showLaser"); + } + + @Nullable + @Override + public ClientboundBlockEntityDataPacket getUpdatePacket() { + return ClientboundBlockEntityDataPacket.create(this); + } + } diff --git a/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java b/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java index c53cc5092..6b0660aae 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java @@ -5,7 +5,6 @@ import dan200.computercraft.shared.computer.inventory.AbstractComputerMenu; import dan200.computercraft.shared.network.container.ComputerContainerData; import de.srendi.advancedperipherals.common.setup.APContainerTypes; -import de.srendi.advancedperipherals.common.setup.APItems; import de.srendi.advancedperipherals.common.smartglasses.SlotType; import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesSlot; import net.minecraft.world.entity.player.Inventory; @@ -56,7 +55,7 @@ public SmartGlassesContainer(int id, Predicate canUse, ServerComputer co } public SmartGlassesContainer(int id, Predicate predicate, ServerComputer computer, ComputerContainerData data, Inventory player, ItemStack glasses) { - this( id, predicate, computer, player, glasses.getCapability(ForgeCapabilities.ITEM_HANDLER).resolve().orElseThrow(), data); + this(id, predicate, computer, player, glasses.getCapability(ForgeCapabilities.ITEM_HANDLER).resolve().orElseThrow(), data); } @NotNull @@ -71,14 +70,10 @@ public ItemStack quickMoveStack(@NotNull Player player, int index) { if (!this.moveItemStackTo(itemstack1, 0, 36, true)) { return ItemStack.EMPTY; } - } else if (index <= 35) { - if (itemstack1.getItem().equals(APItems.MEMORY_CARD.get())) { - if (!this.moveItemStackTo(itemstack1, 36, 37, true)) { - return ItemStack.EMPTY; - } + } else { + if (!this.moveItemStackTo(itemstack1, 36, 37, true)) { + return ItemStack.EMPTY; } - } else if (!this.moveItemStackTo(itemstack1, 0, 36, false)) { - return ItemStack.EMPTY; } if (itemstack1.isEmpty()) { diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesSlot.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesSlot.java index 5c16249b8..ed8a0752d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesSlot.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesSlot.java @@ -24,6 +24,11 @@ public boolean isActive() { return isEnabled; } + @Override + public int getMaxStackSize() { + return 1; + } + public static ComputerSide indexToSide(int slot) { return switch (slot) { case 0 -> ComputerSide.TOP; From 5dba4d5c5d6383d04ab62e436d424a8c0afece4e Mon Sep 17 00:00:00 2001 From: Srendi Date: Sat, 25 Mar 2023 02:03:28 +0100 Subject: [PATCH 034/228] [#320] Finished the distance detector. Everything seems to work fine, the only thing I want to add is an event. --- .../renderer/DistanceDetectorRenderer.java | 5 +- .../DistanceDetectorPeripheral.java | 81 ++++++------- .../blocks/base/BaseBlockEntityBlock.java | 3 +- .../blockentities/DistanceDetectorEntity.java | 111 ++++++++++++++---- .../configuration/PeripheralsConfig.java | 3 + .../network/DistanceDetectorSyncPacket.java | 64 ++++++++++ .../common/network/PacketHandler.java | 11 +- .../common/setup/APBlocks.java | 4 +- .../common/util/HitResultUtil.java | 60 +++++++++- .../resources/META-INF/accesstransformer.cfg | 3 +- 10 files changed, 266 insertions(+), 79 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/network/DistanceDetectorSyncPacket.java diff --git a/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java b/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java index 2593df24a..8b9706331 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java +++ b/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java @@ -29,7 +29,7 @@ public DistanceDetectorRenderer(BlockEntityRendererProvider.Context pContext) { @Override public void render(@NotNull DistanceDetectorEntity pBlockEntity, float pPartialTick, @NotNull PoseStack pPoseStack, MultiBufferSource pBufferSource, int pPackedLight, int pPackedOverlay) { if(pBlockEntity.getLaserVisibility()) - renderBeaconBeam(pBlockEntity, pPoseStack, pBufferSource, BeaconRenderer.BEAM_LOCATION, pPartialTick, 1, 0, pBlockEntity.getDistance() + 0.5f, EnumColor.DARK_RED.getRgb(), 0.05f, 0.09f); + renderBeaconBeam(pBlockEntity, pPoseStack, pBufferSource, BeaconRenderer.BEAM_LOCATION, pPartialTick, 1, 0, pBlockEntity.getDistance() - 0.5f, EnumColor.RED.getRgb(), 0.05f, 0.09f); } @Override @@ -42,7 +42,8 @@ public int getViewDistance() { return 256; } - public boolean shouldRender(DistanceDetectorEntity pBlockEntity, Vec3 pCameraPos) { + @Override + public boolean shouldRender(@NotNull DistanceDetectorEntity pBlockEntity, @NotNull Vec3 pCameraPos) { return true; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java index 3add59f17..3434dfdce 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java @@ -16,13 +16,13 @@ import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; +import java.util.List; + public class DistanceDetectorPeripheral extends BasePeripheral> { public static final String PERIPHERAL_TYPE = "distanceDetector"; private double height = 0.5; private DetectionType detectionType = DetectionType.BOTH; - private boolean ignoreTransparent = true; - private boolean laserVisible = true; public DistanceDetectorPeripheral(DistanceDetectorEntity tileEntity) { super(PERIPHERAL_TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); @@ -34,24 +34,23 @@ public boolean isEnabled() { } @LuaFunction - public final boolean setLaserVisibility(boolean laser) { + public final void setLaserVisibility(boolean laser) { getPeripheralOwner().tileEntity.setShowLaser(laser); - return laserVisible = laser; } @LuaFunction public final boolean getLaserVisibility() { - return laserVisible; + return getPeripheralOwner().tileEntity.getLaserVisibility(); } @LuaFunction - public final boolean setTransparencyDetection(boolean enable) { - return ignoreTransparent = enable; + public final void setIgnoreTransparency(boolean enable) { + getPeripheralOwner().tileEntity.setIgnoreTransparent(enable); } @LuaFunction - public final boolean getTransparencyDetection() { - return ignoreTransparent; + public final boolean ignoresTransparency() { + return getPeripheralOwner().tileEntity.ignoreTransparent(); } @LuaFunction @@ -77,46 +76,48 @@ public final String getDetectionMode() { return detectionType.toString(); } + @LuaFunction public final double setHeight(double height) { - if (height > 1) this.height = 1; - if (height < 0) this.height = 0; + this.height = Math.max(0, Math.min(1, height)); return this.height; } + @LuaFunction public final double getHeight() { return this.height; } - @LuaFunction(mainThread = true) + @LuaFunction public final double getDistance() { - Direction direction = getPeripheralOwner().getOrientation().front(); - Vec3 from = Vec3.atCenterOf(getPos()).add(direction.getNormal().getX() * 0.501, direction.getNormal().getY() * 0.501, direction.getNormal().getZ() * 0.501); - Vec3 to = from.add(direction.getNormal().getX() * 256, direction.getNormal().getY() * 256, direction.getNormal().getZ() * 256); - HitResult result = detectionType == DetectionType.BOTH ? HitResultUtil.getHitResult(to, from, getLevel()) : detectionType == DetectionType.BLOCK ? HitResultUtil.getBlockHitResult(to, from, getLevel()) : HitResultUtil.getEntityHitResult(to, from, getLevel()); - - float distance = 0; - BlockState resultBlock; - if (result.getType() != HitResult.Type.MISS) { - if (result instanceof BlockHitResult blockHitResult) { - resultBlock = getLevel().getBlockState(blockHitResult.getBlockPos()); - distance = getPos().distManhattan(blockHitResult.getBlockPos()); - - if (resultBlock.getBlock() instanceof SlabBlock && direction.getAxis() == Direction.Axis.Y) { - if (resultBlock.getValue(SlabBlock.TYPE) == SlabType.TOP && direction == Direction.UP) - distance = distance + 0.5f; - if (resultBlock.getValue(SlabBlock.TYPE) == SlabType.BOTTOM && direction == Direction.DOWN) - distance = distance - 0.5f; - } - } - if (result instanceof EntityHitResult entityHitResult) { - distance = getPos().distManhattan(new Vec3i(entityHitResult.getLocation().x, entityHitResult.getLocation().y, entityHitResult.getLocation().z)); - } - } - getPeripheralOwner().tileEntity.setDistance(distance -1); - return distance - 1; - } - - private enum DetectionType { + return getPeripheralOwner().tileEntity.getDistance() - 1; + } + + @LuaFunction + public final double calculateDistance() { + return getPeripheralOwner().tileEntity.calculateDistance() - 1; + } + + @LuaFunction + public final boolean shouldCalculatePeriodically() { + return getPeripheralOwner().tileEntity.shouldCalculatePeriodically(); + } + + @LuaFunction + public final void setCalculatePeriodically(boolean shouldRenderPeriodically) { + getPeripheralOwner().tileEntity.setShouldCalculatePeriodically(shouldRenderPeriodically); + } + + @LuaFunction + public final void setMaxRange(double maxDistance) { + getPeripheralOwner().tileEntity.setMaxRange(Math.max(0, Math.min(APConfig.PERIPHERALS_CONFIG.distanceDetectorRange.get(), maxDistance))); + } + + @LuaFunction + public final double getMaxRange() { + return getPeripheralOwner().tileEntity.getMaxDistance(); + } + + public enum DetectionType { BLOCK, ENTITIES, BOTH diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlockEntityBlock.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlockEntityBlock.java index 7c611bb9c..f61085f95 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlockEntityBlock.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlockEntityBlock.java @@ -91,7 +91,8 @@ public MenuProvider getMenuProvider(@NotNull BlockState pState, Level pLevel, @N return menuProvider; } - public @NotNull RenderShape getRenderShape(@NotNull BlockState state) { + @NotNull + public RenderShape getRenderShape(@NotNull BlockState state) { return RenderShape.MODEL; } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java index 174573697..fa6798a51 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java @@ -1,21 +1,32 @@ package de.srendi.advancedperipherals.common.blocks.blockentities; import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.DistanceDetectorPeripheral; +import de.srendi.advancedperipherals.common.blocks.base.BaseBlock; import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; +import de.srendi.advancedperipherals.common.configuration.APConfig; +import de.srendi.advancedperipherals.common.network.DistanceDetectorSyncPacket; +import de.srendi.advancedperipherals.common.network.PacketHandler; import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; +import de.srendi.advancedperipherals.common.util.HitResultUtil; import net.minecraft.core.BlockPos; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.Connection; -import net.minecraft.network.protocol.PacketFlow; -import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; +import net.minecraft.core.Direction; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.SlabBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.SlabType; +import net.minecraft.world.phys.*; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public class DistanceDetectorEntity extends PeripheralBlockEntity { + private DistanceDetectorPeripheral.DetectionType detectionType = DistanceDetectorPeripheral.DetectionType.BOTH; private float distance = 0; + private double maxRange = APConfig.PERIPHERALS_CONFIG.distanceDetectorRange.get(); private boolean showLaser = true; + private boolean shouldCalculatePeriodically = false; + private boolean ignoreTransparent = true; public DistanceDetectorEntity(BlockPos pos, BlockState state) { super(APBlockEntityTypes.DISTANCE_DETECTOR.get(), pos, state); @@ -29,17 +40,24 @@ protected DistanceDetectorPeripheral createPeripheral() { public void setShowLaser(boolean showLaser) { if(this.showLaser != showLaser) - level.setBlockAndUpdate(getBlockPos(), getBlockState()); - + PacketHandler.sendToAll(new DistanceDetectorSyncPacket(getBlockPos(), getLevel().dimension(), distance, showLaser)); this.showLaser = showLaser; } public void setDistance(float distance) { if(this.distance != distance) - level.setBlockAndUpdate(getBlockPos(), getBlockState()); + PacketHandler.sendToAll(new DistanceDetectorSyncPacket(getBlockPos(), getLevel().dimension(), distance, showLaser)); this.distance = distance; } + public void setShouldCalculatePeriodically(boolean shouldCalculatePeriodically) { + this.shouldCalculatePeriodically = shouldCalculatePeriodically; + } + + public void setMaxRange(double maxRange) { + this.maxRange = maxRange; + } + public float getDistance() { return distance; } @@ -48,32 +66,73 @@ public boolean getLaserVisibility() { return showLaser; } - @Override - public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) { - if (level.isClientSide && net.getDirection() == PacketFlow.CLIENTBOUND) { - //Handle the update tag when we are on the client - handleUpdateTag(pkt.getTag()); - } + public boolean shouldCalculatePeriodically() { + return shouldCalculatePeriodically; } - @Override - public CompoundTag getUpdateTag() { - CompoundTag tag = new CompoundTag(); - tag.putFloat("distance", distance); - tag.putBoolean("showLaser", showLaser); - return tag; + public void setIgnoreTransparent(boolean ignoreTransparent) { + this.ignoreTransparent = ignoreTransparent; + } + + public boolean ignoreTransparent() { + return ignoreTransparent; + } + + public double getMaxDistance() { + return maxRange; } @Override - public void handleUpdateTag(CompoundTag tag) { - this.distance = tag.getFloat("distance"); - this.showLaser = tag.getBoolean("showLaser"); + public void handleTick(Level level, BlockState state, BlockEntityType type) { + if (level.getGameTime() % APConfig.PERIPHERALS_CONFIG.distanceDetectorUpdateRate.get() == 0 && shouldCalculatePeriodically) { + // We calculate the distance every 2 ticks, so we do not have to run the getDistance function of the peripheral + // on the main thread which prevents the 1 tick yield time of the function. + // The calculateDistance function is not thread safe, so we have to run it on the main thread. + // It should be okay to run that function every 2 ticks, calculating it does not take too much time. + calculateDistance(); + } } - @Nullable @Override - public ClientboundBlockEntityDataPacket getUpdatePacket() { - return ClientboundBlockEntityDataPacket.create(this); + public AABB getRenderBoundingBox() { + Direction direction = getBlockState().getValue(BaseBlock.ORIENTATION).front(); + return AABB.ofSize(getBlockPos().getCenter(), direction.getStepX() * distance + 1, direction.getStepY() * distance + 1, direction.getStepZ() * distance + 1) + .move(direction.getStepX() * distance / 2, direction.getStepY() * distance / 2, direction.getStepZ() * distance / 2); + } + + public double calculateDistance() { + Direction direction = getBlockState().getValue(BaseBlock.ORIENTATION).front(); + Vec3 from = Vec3.atCenterOf(getBlockPos()).add(direction.getNormal().getX() * 0.501, direction.getNormal().getY() * 0.501, direction.getNormal().getZ() * 0.501); + Vec3 to = from.add(direction.getNormal().getX() * maxRange, direction.getNormal().getY() * maxRange, direction.getNormal().getZ() * maxRange); + HitResult result = detectionType == DistanceDetectorPeripheral.DetectionType.BOTH ? HitResultUtil.getHitResult(to, from, getLevel(), ignoreTransparent) : detectionType == DistanceDetectorPeripheral.DetectionType.BLOCK ? HitResultUtil.getBlockHitResult(to, from, getLevel(), ignoreTransparent) : HitResultUtil.getEntityHitResult(to, from, getLevel()); + + float distance = 0; + BlockState resultBlock; + if (result.getType() != HitResult.Type.MISS) { + if (result instanceof BlockHitResult blockHitResult) { + resultBlock = getLevel().getBlockState(blockHitResult.getBlockPos()); + distance = distManhattan(blockHitResult.getBlockPos().getCenter(), getBlockPos().getCenter()); + + if (resultBlock.getBlock() instanceof SlabBlock && direction.getAxis() == Direction.Axis.Y) { + if (resultBlock.getValue(SlabBlock.TYPE) == SlabType.TOP && direction == Direction.UP) + distance = distance + 0.5f; + if (resultBlock.getValue(SlabBlock.TYPE) == SlabType.BOTTOM && direction == Direction.DOWN) + distance = distance - 0.5f; + } + } + if (result instanceof EntityHitResult entityHitResult) { + distance = distManhattan(entityHitResult.getLocation(), getBlockPos().getCenter()); + } + } + setDistance(distance); + return distance; } + + private float distManhattan(Vec3 from, Vec3 to) { + float f = (float)Math.abs(from.x - to.x); + float f1 = (float)Math.abs(from.y - to.y); + float f2 = (float)Math.abs(from.z - to.z); + return f + f1 + f2; + } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java index e5a713cbb..720500193 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java @@ -56,6 +56,7 @@ public class PeripheralsConfig implements IAPConfig { //Compass turtle public final ForgeConfigSpec.BooleanValue enableDistanceDetector; public final ForgeConfigSpec.DoubleValue distanceDetectorRange; + public final ForgeConfigSpec.IntValue distanceDetectorUpdateRate; //Powered Peripherals public final ForgeConfigSpec.BooleanValue enablePoweredPeripherals; @@ -149,6 +150,8 @@ public PeripheralsConfig() { enableDistanceDetector = builder.comment("Enable the distance detector or not.").define("enableDistanceDetector", true); distanceDetectorRange = builder.comment("Maximum range of the distance detector").defineInRange("distanceDetectorRange", 64D, 0D, Integer.MAX_VALUE); + distanceDetectorUpdateRate = builder.comment("Defines how often the distance detector updates it's distance if periodically updates are enabled. \n" + + "Periodically updates exists so we do not need to run \"getDistance\" on the main thread which eliminates the 1 tick yield of the lua function").defineInRange("maxUpdateRate", 2, 1, 100); pop("Powered_Peripherals", builder); diff --git a/src/main/java/de/srendi/advancedperipherals/common/network/DistanceDetectorSyncPacket.java b/src/main/java/de/srendi/advancedperipherals/common/network/DistanceDetectorSyncPacket.java new file mode 100644 index 000000000..7c46dfb85 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/network/DistanceDetectorSyncPacket.java @@ -0,0 +1,64 @@ +package de.srendi.advancedperipherals.common.network; + +import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.common.blocks.blockentities.DistanceDetectorEntity; +import de.srendi.advancedperipherals.common.network.base.IPacket; +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.Registries; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraftforge.network.NetworkEvent; +import net.minecraftforge.server.ServerLifecycleHooks; + +public class DistanceDetectorSyncPacket implements IPacket { + + private final BlockPos position; + private final ResourceKey world; + private final float distance; + private final boolean showLaser; + + public DistanceDetectorSyncPacket(BlockPos position, ResourceKey world, float distance, boolean showLaser) { + this.position = position; + this.world = world; + this.distance = distance; + this.showLaser = showLaser; + } + + @Override + public void handle(NetworkEvent.Context context) { + ClientLevel level = Minecraft.getInstance().level; + if(!level.dimension().equals(world)) + return; + + BlockEntity tileEntity = level.getBlockEntity(position); + if(tileEntity == null) { + AdvancedPeripherals.debug("Could not update distance detector at " + position + " in world " + world.location() + + " because the world or the tile entity couldn't be found. Ignoring it"); + return; + } + if (tileEntity instanceof DistanceDetectorEntity detector) { + detector.setDistance(distance); + detector.setShowLaser(showLaser); + } + } + + @Override + public void encode(FriendlyByteBuf buffer) { + buffer.writeBlockPos(position); + buffer.writeResourceKey(world); + buffer.writeFloat(distance); + buffer.writeBoolean(showLaser); + } + + public static DistanceDetectorSyncPacket decode(FriendlyByteBuf buffer) { + return new DistanceDetectorSyncPacket(buffer.readBlockPos(), buffer.readResourceKey(Registries.DIMENSION),buffer.readFloat(), buffer.readBoolean()); + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/network/PacketHandler.java b/src/main/java/de/srendi/advancedperipherals/common/network/PacketHandler.java index 94197c83b..5928489a6 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/network/PacketHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/network/PacketHandler.java @@ -5,6 +5,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.level.ChunkPos; @@ -15,6 +16,7 @@ import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.PacketDistributor; import net.minecraftforge.network.simple.SimpleChannel; +import net.minecraftforge.server.ServerLifecycleHooks; import java.util.Optional; import java.util.function.Function; @@ -28,7 +30,7 @@ public class PacketHandler { private static int index = 0; public static void init() { - + registerServerToClient(DistanceDetectorSyncPacket.class, DistanceDetectorSyncPacket::decode); } public static void registerServerToClient(Class packet, Function decode) { @@ -40,7 +42,6 @@ public static void registerClientToServer(Class packe } public static void sendToClient(Object packet, ServerPlayer player) { - CHANNEL.sendTo(packet, player.connection.getConnection(), NetworkDirection.PLAY_TO_CLIENT); } @@ -54,9 +55,13 @@ public static void sendTo(Object packet, ServerPlayer player) { } } + public static void sendToAll(Object packet) { + MinecraftServer server = ServerLifecycleHooks.getCurrentServer(); + server.getPlayerList().getPlayers().forEach(player -> sendTo(packet, player)); + } + public static void sendToAllTracking(Object packet, Level world, BlockPos pos) { if (world instanceof ServerLevel) { - ((ServerLevel) world).getChunkSource().chunkMap.getPlayers(new ChunkPos(pos), false).forEach(p -> sendTo(packet, p)); } else { CHANNEL.send(PacketDistributor.TRACKING_CHUNK.with(() -> world.getChunk(pos.getX() >> 4, pos.getZ() >> 4)), packet); diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java index d3ac032c9..a014e95f7 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java @@ -11,7 +11,9 @@ import net.minecraft.world.item.Item; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Material; import net.minecraftforge.fml.ModList; import net.minecraftforge.registries.RegistryObject; @@ -37,7 +39,7 @@ static void register() { public static final RegistryObject GEO_SCANNER = register("geo_scanner", () -> new APBlockEntityBlock<>(APBlockEntityTypes.GEO_SCANNER, false), () -> new APBlockItem(APBlocks.GEO_SCANNER.get(), APConfig.PERIPHERALS_CONFIG.enableGeoScanner)); public static final RegistryObject COLONY_INTEGRATOR = register("colony_integrator", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("minecolonies") ? APBlockEntityTypes.COLONY_INTEGRATOR : null, false), () -> new APBlockItem(APBlocks.COLONY_INTEGRATOR.get(), APConfig.PERIPHERALS_CONFIG.enableColonyIntegrator)); public static final RegistryObject NBT_STORAGE = register("nbt_storage", () -> new APBlockEntityBlock<>(APBlockEntityTypes.NBT_STORAGE, false), () -> new APBlockItem(APBlocks.NBT_STORAGE.get(), APConfig.PERIPHERALS_CONFIG.enableNBTStorage)); - public static final RegistryObject DISTANCE_DETECTOR = register("distance_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.DISTANCE_DETECTOR, false), () -> new APBlockItem(APBlocks.DISTANCE_DETECTOR.get(), APConfig.PERIPHERALS_CONFIG.enableNBTStorage)); + public static final RegistryObject DISTANCE_DETECTOR = register("distance_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.DISTANCE_DETECTOR, BlockBehaviour.Properties.of(Material.METAL).noOcclusion(),true), () -> new APBlockItem(APBlocks.DISTANCE_DETECTOR.get(), APConfig.PERIPHERALS_CONFIG.enableNBTStorage)); private static RegistryObject registerNoItem(String name, Supplier block) { return APRegistration.BLOCKS.register(name, block); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java index 9512c9de0..8dc4d5e2e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java @@ -4,19 +4,25 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Vec3i; import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.*; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.Shapes; +import net.minecraft.world.phys.shapes.VoxelShape; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; public class HitResultUtil { @NotNull - public static HitResult getHitResult(Vec3 to, Vec3 from, Level level) { + public static HitResult getHitResult(Vec3 to, Vec3 from, Level level, boolean ignoreTransparent) { EntityHitResult entityResult = getEntityHitResult(to, from, level); - BlockHitResult blockResult = getBlockHitResult(to, from, level); + BlockHitResult blockResult = getBlockHitResult(to, from, level, ignoreTransparent); if(entityResult.getType() != HitResult.Type.MISS && blockResult.getType() == HitResult.Type.MISS) return entityResult; @@ -24,6 +30,9 @@ public static HitResult getHitResult(Vec3 to, Vec3 from, Level level) { if(entityResult.getType() == HitResult.Type.MISS && blockResult.getType() != HitResult.Type.MISS) return blockResult; + if(entityResult.getType() == HitResult.Type.MISS && blockResult.getType() == HitResult.Type.MISS) + return BlockHitResult.miss(from, null, new BlockPos(to)); + double blockDistance = new BlockPos(from).distManhattan(blockResult.getBlockPos()); double entityDistance = new BlockPos(from).distManhattan(new Vec3i(entityResult.getLocation().x, entityResult.getLocation().y, entityResult.getLocation().z)); @@ -54,12 +63,27 @@ public static EntityHitResult getEntityHitResult(Vec3 to, Vec3 from, Level level if(entities.isEmpty()) return new EmptyEntityHitResult(); - return new EntityHitResult(entities.get(0)); + Entity nearestEntity = null; + + for (Entity entity : entities) { + if(nearestEntity == null) { + nearestEntity = entity; + continue; + } + + double distance = new BlockPos(from).distManhattan(new Vec3i(entity.getX(), entity.getY(), entity.getZ())); + double nearestDistance = new BlockPos(from).distManhattan(new Vec3i(nearestEntity.getX(), nearestEntity.getY(), nearestEntity.getZ())); + + if(distance < nearestDistance) + nearestEntity = entity; + } + + return new EntityHitResult(nearestEntity); } @NotNull - public static BlockHitResult getBlockHitResult(Vec3 to, Vec3 from, Level level) { - BlockHitResult result = level.clip(new ClipContext(from, to, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, null)); + public static BlockHitResult getBlockHitResult(Vec3 to, Vec3 from, Level level, boolean ignoreNoOccluded) { + BlockHitResult result = level.clip(new AdvancecClipContext(from, to, ignoreNoOccluded ? IgnoreNoOccludedContext.INSTANCE : ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, null)); return result; } @@ -78,4 +102,30 @@ public Type getType() { return Type.MISS; } } + + private enum IgnoreNoOccludedContext implements ClipContext.ShapeGetter { + + INSTANCE; + + @NotNull + @Override + public VoxelShape get(BlockState pState, @NotNull BlockGetter pBlock, @NotNull BlockPos pPos, @NotNull CollisionContext pCollisionContext) { + return !pState.canOcclude() ? Shapes.empty() : pState.getCollisionShape(pBlock, pPos, pCollisionContext); + } + } + + private static class AdvancecClipContext extends ClipContext { + + private final ShapeGetter blockShapeGetter; + + public AdvancecClipContext(Vec3 from, Vec3 to, ShapeGetter blockShapeGetter, Fluid fluidShapeGetter, @Nullable Entity entity) { + super(from, to, Block.COLLIDER, fluidShapeGetter, entity); + this.blockShapeGetter = blockShapeGetter; + } + + @Override + public VoxelShape getBlockShape(BlockState pBlockState, BlockGetter pLevel, BlockPos pPos) { + return blockShapeGetter.get(pBlockState, pLevel, pPos, this.collisionContext); + } + } } diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index e26abcd49..5eca3ccef 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -1,4 +1,5 @@ public net.minecraft.world.level.block.entity.BeaconBlockEntity f_58652_ public net.minecraft.world.level.block.entity.BeaconBlockEntity f_58653_ public-f net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool f_210559_ # rawTemplates -public-f net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool f_210560_ # templates \ No newline at end of file +public-f net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool f_210560_ # templates +protected net.minecraft.world.level.ClipContext f_45686_ # collisionContext \ No newline at end of file From 481df9ca6d2b61038207bf0a02b569c2cd8803e9 Mon Sep 17 00:00:00 2001 From: Srendi Date: Sat, 25 Mar 2023 02:10:52 +0100 Subject: [PATCH 035/228] Add some documentation and satisfy checkstyle --- .../DistanceDetectorPeripheral.java | 12 ----- .../network/DistanceDetectorSyncPacket.java | 11 ++--- .../common/setup/APBlocks.java | 2 +- .../common/util/HitResultUtil.java | 47 ++++++++++++++----- 4 files changed, 40 insertions(+), 32 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java index 3434dfdce..6fa53f4b4 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java @@ -4,19 +4,7 @@ import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner; import de.srendi.advancedperipherals.common.blocks.blockentities.DistanceDetectorEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.util.HitResultUtil; import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; -import net.minecraft.core.Direction; -import net.minecraft.core.Vec3i; -import net.minecraft.world.level.block.SlabBlock; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.properties.SlabType; -import net.minecraft.world.phys.BlockHitResult; -import net.minecraft.world.phys.EntityHitResult; -import net.minecraft.world.phys.HitResult; -import net.minecraft.world.phys.Vec3; - -import java.util.List; public class DistanceDetectorPeripheral extends BasePeripheral> { diff --git a/src/main/java/de/srendi/advancedperipherals/common/network/DistanceDetectorSyncPacket.java b/src/main/java/de/srendi/advancedperipherals/common/network/DistanceDetectorSyncPacket.java index 7c46dfb85..04e139eb1 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/network/DistanceDetectorSyncPacket.java +++ b/src/main/java/de/srendi/advancedperipherals/common/network/DistanceDetectorSyncPacket.java @@ -6,17 +6,12 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.core.BlockPos; -import net.minecraft.core.Registry; import net.minecraft.core.registries.Registries; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceKey; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraftforge.network.NetworkEvent; -import net.minecraftforge.server.ServerLifecycleHooks; public class DistanceDetectorSyncPacket implements IPacket { @@ -35,11 +30,11 @@ public DistanceDetectorSyncPacket(BlockPos position, ResourceKey world, f @Override public void handle(NetworkEvent.Context context) { ClientLevel level = Minecraft.getInstance().level; - if(!level.dimension().equals(world)) + if (!level.dimension().equals(world)) return; BlockEntity tileEntity = level.getBlockEntity(position); - if(tileEntity == null) { + if (tileEntity == null) { AdvancedPeripherals.debug("Could not update distance detector at " + position + " in world " + world.location() + " because the world or the tile entity couldn't be found. Ignoring it"); return; @@ -59,6 +54,6 @@ public void encode(FriendlyByteBuf buffer) { } public static DistanceDetectorSyncPacket decode(FriendlyByteBuf buffer) { - return new DistanceDetectorSyncPacket(buffer.readBlockPos(), buffer.readResourceKey(Registries.DIMENSION),buffer.readFloat(), buffer.readBoolean()); + return new DistanceDetectorSyncPacket(buffer.readBlockPos(), buffer.readResourceKey(Registries.DIMENSION), buffer.readFloat(), buffer.readBoolean()); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java index a014e95f7..b72c8cd23 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java @@ -39,7 +39,7 @@ static void register() { public static final RegistryObject GEO_SCANNER = register("geo_scanner", () -> new APBlockEntityBlock<>(APBlockEntityTypes.GEO_SCANNER, false), () -> new APBlockItem(APBlocks.GEO_SCANNER.get(), APConfig.PERIPHERALS_CONFIG.enableGeoScanner)); public static final RegistryObject COLONY_INTEGRATOR = register("colony_integrator", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("minecolonies") ? APBlockEntityTypes.COLONY_INTEGRATOR : null, false), () -> new APBlockItem(APBlocks.COLONY_INTEGRATOR.get(), APConfig.PERIPHERALS_CONFIG.enableColonyIntegrator)); public static final RegistryObject NBT_STORAGE = register("nbt_storage", () -> new APBlockEntityBlock<>(APBlockEntityTypes.NBT_STORAGE, false), () -> new APBlockItem(APBlocks.NBT_STORAGE.get(), APConfig.PERIPHERALS_CONFIG.enableNBTStorage)); - public static final RegistryObject DISTANCE_DETECTOR = register("distance_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.DISTANCE_DETECTOR, BlockBehaviour.Properties.of(Material.METAL).noOcclusion(),true), () -> new APBlockItem(APBlocks.DISTANCE_DETECTOR.get(), APConfig.PERIPHERALS_CONFIG.enableNBTStorage)); + public static final RegistryObject DISTANCE_DETECTOR = register("distance_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.DISTANCE_DETECTOR, BlockBehaviour.Properties.of(Material.METAL).noOcclusion(), true), () -> new APBlockItem(APBlocks.DISTANCE_DETECTOR.get(), APConfig.PERIPHERALS_CONFIG.enableNBTStorage)); private static RegistryObject registerNoItem(String name, Supplier block) { return APRegistration.BLOCKS.register(name, block); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java index 8dc4d5e2e..593f47317 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java @@ -2,6 +2,7 @@ import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.DistanceDetectorPeripheral; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.core.Vec3i; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.BlockGetter; @@ -19,24 +20,32 @@ public class HitResultUtil { + /** + * This method is used to get the hit result of an entity from the start position of a block + * @param to the target position/max position + * @param from the source position like a block + * @param level the level + * @param ignoreTransparent if transparent blocks should be ignored + * @return the hit result {@link BlockHitResult#miss(Vec3, Direction, BlockPos)} if nothing found + */ @NotNull public static HitResult getHitResult(Vec3 to, Vec3 from, Level level, boolean ignoreTransparent) { EntityHitResult entityResult = getEntityHitResult(to, from, level); BlockHitResult blockResult = getBlockHitResult(to, from, level, ignoreTransparent); - if(entityResult.getType() != HitResult.Type.MISS && blockResult.getType() == HitResult.Type.MISS) + if (entityResult.getType() != HitResult.Type.MISS && blockResult.getType() == HitResult.Type.MISS) return entityResult; - if(entityResult.getType() == HitResult.Type.MISS && blockResult.getType() != HitResult.Type.MISS) + if (entityResult.getType() == HitResult.Type.MISS && blockResult.getType() != HitResult.Type.MISS) return blockResult; - if(entityResult.getType() == HitResult.Type.MISS && blockResult.getType() == HitResult.Type.MISS) + if (entityResult.getType() == HitResult.Type.MISS && blockResult.getType() == HitResult.Type.MISS) return BlockHitResult.miss(from, null, new BlockPos(to)); double blockDistance = new BlockPos(from).distManhattan(blockResult.getBlockPos()); double entityDistance = new BlockPos(from).distManhattan(new Vec3i(entityResult.getLocation().x, entityResult.getLocation().y, entityResult.getLocation().z)); - if(blockDistance < entityDistance) + if (blockDistance < entityDistance) return blockResult; return entityResult; @@ -48,9 +57,8 @@ public static HitResult getHitResult(Vec3 to, Vec3 from, Level level, boolean ig * this method uses one AABB made out of the two coordinates, this would also find any entities * which are not located in the ray you might want. {@link DistanceDetectorPeripheral#getDistance()} * - * - * @param to the target position or max distance - * @param from the source position like a block + * @param to the target position/max position + * @param from the source position like a block * @param level the world * @return the entity hit result. An empty HitResult with {@link HitResult.Type#MISS} as type if nothing found */ @@ -60,13 +68,14 @@ public static EntityHitResult getEntityHitResult(Vec3 to, Vec3 from, Level level List entities = level.getEntities((Entity) null, checkingBox, (entity) -> true); - if(entities.isEmpty()) + if (entities.isEmpty()) return new EmptyEntityHitResult(); Entity nearestEntity = null; + // Find the nearest entity for (Entity entity : entities) { - if(nearestEntity == null) { + if (nearestEntity == null) { nearestEntity = entity; continue; } @@ -74,13 +83,23 @@ public static EntityHitResult getEntityHitResult(Vec3 to, Vec3 from, Level level double distance = new BlockPos(from).distManhattan(new Vec3i(entity.getX(), entity.getY(), entity.getZ())); double nearestDistance = new BlockPos(from).distManhattan(new Vec3i(nearestEntity.getX(), nearestEntity.getY(), nearestEntity.getZ())); - if(distance < nearestDistance) + // If it's closer, set it as the nearest entity + if (distance < nearestDistance) nearestEntity = entity; } return new EntityHitResult(nearestEntity); } + /** + * This method is used to get the hit result of a block from the start position of a block + * + * @param to the target position/max position + * @param from the source position + * @param level the world + * @param ignoreNoOccluded if true, the method will ignore blocks which are not occluding like glass + * @return the block hit result. {@link BlockHitResult#miss(Vec3, Direction, BlockPos)} if nothing found + */ @NotNull public static BlockHitResult getBlockHitResult(Vec3 to, Vec3 from, Level level, boolean ignoreNoOccluded) { BlockHitResult result = level.clip(new AdvancecClipContext(from, to, ignoreNoOccluded ? IgnoreNoOccludedContext.INSTANCE : ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, null)); @@ -103,6 +122,9 @@ public Type getType() { } } + /** + * A shape getter which ignores blocks which are not occluding like glass + */ private enum IgnoreNoOccludedContext implements ClipContext.ShapeGetter { INSTANCE; @@ -114,11 +136,14 @@ public VoxelShape get(BlockState pState, @NotNull BlockGetter pBlock, @NotNull B } } + /** + * A clip context but with a custom shape getter. Used to define another shape getter for the block like {@link IgnoreNoOccludedContext} + */ private static class AdvancecClipContext extends ClipContext { private final ShapeGetter blockShapeGetter; - public AdvancecClipContext(Vec3 from, Vec3 to, ShapeGetter blockShapeGetter, Fluid fluidShapeGetter, @Nullable Entity entity) { + protected AdvancecClipContext(Vec3 from, Vec3 to, ShapeGetter blockShapeGetter, Fluid fluidShapeGetter, @Nullable Entity entity) { super(from, to, Block.COLLIDER, fluidShapeGetter, entity); this.blockShapeGetter = blockShapeGetter; } From 319504879d10a9287d4ceded439cd0c43eb45ff3 Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 27 Mar 2023 13:29:51 +0200 Subject: [PATCH 036/228] =?UTF-8?q?=F0=9F=A7=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/ClientRegistry.java | 6 -- .../client/MetaTurtleUpgradeModeller.java | 2 +- .../renderer/DistanceDetectorRenderer.java | 4 +- .../client/screens/base/BaseItemScreen.java | 2 +- .../client/screens/base/BaseScreen.java | 2 +- .../widgets/SmartGlassesSettingsSwitch.java | 4 +- .../common/addons/APAddons.java | 2 +- .../addons/appliedenergistics/AppEngApi.java | 67 ++++++++-------- .../MeBridgeEntityListener.java | 5 +- .../appliedenergistics/MeFluidHandler.java | 5 +- .../addons/base/IStoragePeripheral.java | 2 +- .../integrations/BeaconIntegration.java | 5 +- .../operations/SingleOperation.java | 10 +-- .../owner/BasePeripheralOwner.java | 2 +- .../owner/BlockEntityPeripheralOwner.java | 5 +- .../computercraft/owner/FuelAbility.java | 2 +- .../owner/PeripheralOwnerAbility.java | 2 +- .../owner/TurtlePeripheralOwner.java | 2 - .../peripheral/BlockReaderPeripheral.java | 2 +- .../DistanceDetectorPeripheral.java | 2 +- .../EnvironmentDetectorPeripheral.java | 12 +-- .../InventoryManagerPeripheral.java | 4 +- .../peripheral/MeBridgePeripheral.java | 31 ++++---- .../peripheral/PlayerDetectorPeripheral.java | 6 +- .../peripheral/RsBridgePeripheral.java | 9 ++- ...oweredHusbandryAutomataCorePeripheral.java | 1 + ...OverpoweredWeakAutomataCorePeripheral.java | 1 + .../WeakAutomataCorePeripheral.java | 6 +- .../plugins/AutomataEntityTransferPlugin.java | 2 +- .../addons/create/BasinIntegration.java | 6 +- .../addons/mekanism/MekanismCapabilities.java | 3 +- .../addons/refinedstorage/RefinedStorage.java | 10 +-- .../addons/refinedstorage/RsFluidHandler.java | 4 +- .../addons/refinedstorage/RsItemHandler.java | 3 +- .../blocks/base/BaseBlockEntityBlock.java | 6 +- .../blocks/base/PeripheralBlockEntity.java | 2 +- .../base/PoweredPeripheralBlockEntity.java | 2 +- .../blockentities/DistanceDetectorEntity.java | 78 ++++++++++++------- .../RedstoneIntegratorEntity.java | 4 +- .../common/configuration/GeneralConfig.java | 1 - .../common/container/base/SlotCondition.java | 10 +-- .../data/BlockStatesAndModelsProvider.java | 5 +- .../items/SmartGlassesInterfaceItem.java | 2 +- .../common/items/SmartGlassesItem.java | 13 +++- .../items/base/SmartGlassesMaterials.java | 19 ++--- .../network/DistanceDetectorSyncPacket.java | 2 +- .../common/setup/APBlockEntityTypes.java | 2 +- .../common/setup/APBlocks.java | 2 +- .../common/setup/APContainerTypes.java | 3 +- .../common/setup/APItems.java | 3 +- .../common/setup/APVillagers.java | 2 +- .../common/setup/CCRegistration.java | 22 +----- .../smartglasses/SmartGlassesAccess.java | 2 +- .../smartglasses/SmartGlassesComputer.java | 28 ++----- .../SmartGlassesMenuProvider.java | 4 +- .../common/util/ChunkManager.java | 6 +- .../common/util/CoordUtil.java | 6 +- .../common/util/FluidStorageProxy.java | 2 +- .../common/util/HitResultUtil.java | 16 ++-- .../advancedperipherals/common/util/Pair.java | 4 +- .../common/util/fakeplayer/APFakePlayer.java | 8 +- .../common/util/inventory/FluidFilter.java | 5 +- .../inventory/IStorageSystemFluidHandler.java | 2 +- .../inventory/IStorageSystemItemHandler.java | 2 +- .../common/util/inventory/InventoryUtil.java | 2 +- .../common/util/inventory/ItemFilter.java | 5 +- .../common/village/VillagerTrade.java | 38 ++++----- .../metaphysics/IFeedableAutomataCore.java | 3 +- .../lib/peripherals/BasePeripheral.java | 13 +--- .../resources/META-INF/accesstransformer.cfg | 3 +- 70 files changed, 252 insertions(+), 306 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java b/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java index 3d44304b9..d5e52ae28 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java +++ b/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java @@ -62,10 +62,4 @@ public static void registeringKeymappings(RegisterKeyMappingsEvent event) { public static void registeringRenderers(EntityRenderersEvent.RegisterRenderers event) { event.registerBlockEntityRenderer(APBlockEntityTypes.DISTANCE_DETECTOR.get(), DistanceDetectorRenderer::new); } - - //TODO change the icon of the curio icon - /*@SubscribeEvent - public static void onTextureStitching(TextureStitchEvent.Pre event) { - event.addSprite(new ResourceLocation(AdvancedPeripherals.MOD_ID, "item/empty_glasses_slot")); - }*/ } diff --git a/src/main/java/de/srendi/advancedperipherals/client/MetaTurtleUpgradeModeller.java b/src/main/java/de/srendi/advancedperipherals/client/MetaTurtleUpgradeModeller.java index 485a77e93..38f624e6e 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/MetaTurtleUpgradeModeller.java +++ b/src/main/java/de/srendi/advancedperipherals/client/MetaTurtleUpgradeModeller.java @@ -23,7 +23,7 @@ public TransformedModel getModel(T upgrade, @Nullable ITurtleAccess turtle, @Not stack.translate(0.0f, 0.5f, 0.5f); if (turtle != null) { int rotationStep = DataStorageUtil.RotationCharge.get(turtle, side); - stack.mulPose(Axis.XN.rotationDegrees(-10 * rotationStep)); + stack.mulPose(Axis.XN.rotationDegrees(-10f * rotationStep)); } stack.translate(0.0f, -0.5f, -0.5f); stack.mulPose(Axis.YN.rotationDegrees(90)); diff --git a/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java b/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java index 8b9706331..a7c678b1f 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java +++ b/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java @@ -28,8 +28,8 @@ public DistanceDetectorRenderer(BlockEntityRendererProvider.Context pContext) { @Override public void render(@NotNull DistanceDetectorEntity pBlockEntity, float pPartialTick, @NotNull PoseStack pPoseStack, MultiBufferSource pBufferSource, int pPackedLight, int pPackedOverlay) { - if(pBlockEntity.getLaserVisibility()) - renderBeaconBeam(pBlockEntity, pPoseStack, pBufferSource, BeaconRenderer.BEAM_LOCATION, pPartialTick, 1, 0, pBlockEntity.getDistance() - 0.5f, EnumColor.RED.getRgb(), 0.05f, 0.09f); + if (pBlockEntity.getLaserVisibility()) + renderBeaconBeam(pBlockEntity, pPoseStack, pBufferSource, BeaconRenderer.BEAM_LOCATION, pPartialTick, 1, 0, pBlockEntity.getCurrentDistance() - 0.5f, EnumColor.RED.getRgb(), 0.05f, 0.09f); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/client/screens/base/BaseItemScreen.java b/src/main/java/de/srendi/advancedperipherals/client/screens/base/BaseItemScreen.java index 6ddf1f538..a7e7e9476 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/screens/base/BaseItemScreen.java +++ b/src/main/java/de/srendi/advancedperipherals/client/screens/base/BaseItemScreen.java @@ -12,7 +12,7 @@ public abstract class BaseItemScreen extends AbstractContainerScreen { - public BaseItemScreen(T screenContainer, Inventory inv, Component titleIn) { + protected BaseItemScreen(T screenContainer, Inventory inv, Component titleIn) { super(screenContainer, inv, titleIn); imageWidth = getSizeX(); diff --git a/src/main/java/de/srendi/advancedperipherals/client/screens/base/BaseScreen.java b/src/main/java/de/srendi/advancedperipherals/client/screens/base/BaseScreen.java index 9d00cace8..9390fa902 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/screens/base/BaseScreen.java +++ b/src/main/java/de/srendi/advancedperipherals/client/screens/base/BaseScreen.java @@ -12,7 +12,7 @@ public abstract class BaseScreen extends AbstractContainerScreen { - public BaseScreen(T screenContainer, Inventory inv, Component titleIn) { + protected BaseScreen(T screenContainer, Inventory inv, Component titleIn) { super(screenContainer, inv, titleIn); imageWidth = getSizeX(); imageHeight = getSizeY(); diff --git a/src/main/java/de/srendi/advancedperipherals/client/widgets/SmartGlassesSettingsSwitch.java b/src/main/java/de/srendi/advancedperipherals/client/widgets/SmartGlassesSettingsSwitch.java index 69eeb60dd..df49fef4a 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/widgets/SmartGlassesSettingsSwitch.java +++ b/src/main/java/de/srendi/advancedperipherals/client/widgets/SmartGlassesSettingsSwitch.java @@ -9,6 +9,7 @@ import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesSlot; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.AbstractWidget; +import net.minecraft.client.gui.narration.NarratedElementType; import net.minecraft.client.gui.narration.NarrationElementOutput; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.inventory.Slot; @@ -33,7 +34,7 @@ public SmartGlassesSettingsSwitch(int x, int y, SlotType type, SmartGlassesScree @Override protected void updateWidgetNarration(@NotNull NarrationElementOutput pNarrationElementOutput) { - + pNarrationElementOutput.add(NarratedElementType.TITLE, type.getName()); } @Override @@ -43,6 +44,7 @@ public void render(@NotNull PoseStack pPoseStack, int pMouseX, int pMouseY, floa @Override public void renderButton(@NotNull PoseStack pPoseStack, int pMouseX, int pMouseY, float pPartialTick) { + // Disable rendering of default buttons } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java b/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java index 6918ca942..99eb16e23 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java @@ -49,7 +49,7 @@ public static void interModComms(InterModEnqueueEvent event) { if (!curiosLoaded) return; - InterModComms.sendTo("curios", SlotTypeMessage.REGISTER_TYPE, + InterModComms.sendTo(CURIOS_MODID, SlotTypeMessage.REGISTER_TYPE, () -> new SlotTypeMessage.Builder("glasses") .size(1) .icon(new ResourceLocation(AdvancedPeripherals.MOD_ID, "slot/empty_glasses_slot")) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java index 9072b3cf4..76baeea4e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java @@ -28,12 +28,7 @@ import org.apache.logging.log4j.Level; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; +import java.util.*; public class AppEngApi { @@ -176,9 +171,9 @@ public static Map getObjectFromJob(CraftingJobStatus job) { } public static Map getObjectFromGenericStack(GenericStack stack) { - if(stack.what() instanceof AEItemKey aeItemKey) + if (stack.what() instanceof AEItemKey aeItemKey) return getObjectFromItemStack(Pair.of(stack.amount(), aeItemKey), null); - if(stack.what() instanceof AEFluidKey aeFluidKey) + if (stack.what() instanceof AEFluidKey aeFluidKey) return getObjectFromFluidStack(Pair.of(stack.amount(), aeFluidKey), null); return Collections.emptyMap(); } @@ -220,7 +215,7 @@ public static boolean isItemCrafting(MEStorage monitor, ICraftingService grid, I return false; // If the passed cpu is null, check all cpus - if(craftingCPU == null) { + if (craftingCPU == null) { // Loop through all crafting cpus and check if the item is being crafted. for (ICraftingCPU cpu : grid.getCpus()) { if (cpu.isBusy()) { @@ -257,17 +252,17 @@ public static long getTotalItemStorage(IGridNode node) { if (!iterator.hasNext()) return 0; while (iterator.hasNext()) { DriveBlockEntity entity = (DriveBlockEntity) iterator.next().getService(IStorageProvider.class); - if(entity == null) continue; + if (entity == null) continue; InternalInventory inventory = entity.getInternalInventory(); - for(int i = 0; i < inventory.size(); i++) { + for (int i = 0; i < inventory.size(); i++) { ItemStack stack = inventory.getStackInSlot(i); - if(stack.isEmpty()) continue; + if (stack.isEmpty()) continue; - if(stack.getItem() instanceof BasicStorageCell cell) { - if(cell.getKeyType().getClass().isAssignableFrom(AEKeyType.items().getClass())) { + if (stack.getItem() instanceof BasicStorageCell cell) { + if (cell.getKeyType().getClass().isAssignableFrom(AEKeyType.items().getClass())) { total += cell.getBytes(null); } } @@ -285,17 +280,17 @@ public static long getTotalFluidStorage(IGridNode node) { if (!iterator.hasNext()) return 0; while (iterator.hasNext()) { DriveBlockEntity entity = (DriveBlockEntity) iterator.next().getService(IStorageProvider.class); - if(entity == null) continue; + if (entity == null) continue; InternalInventory inventory = entity.getInternalInventory(); - for(int i = 0; i < inventory.size(); i++) { + for (int i = 0; i < inventory.size(); i++) { ItemStack stack = inventory.getStackInSlot(i); - if(stack.isEmpty()) continue; + if (stack.isEmpty()) continue; - if(stack.getItem() instanceof BasicStorageCell cell) { - if(cell.getKeyType().getClass().isAssignableFrom(AEKeyType.fluids().getClass())) { + if (stack.getItem() instanceof BasicStorageCell cell) { + if (cell.getKeyType().getClass().isAssignableFrom(AEKeyType.fluids().getClass())) { total += cell.getBytes(null); } } @@ -313,20 +308,20 @@ public static long getUsedItemStorage(IGridNode node) { if (!iterator.hasNext()) return 0; while (iterator.hasNext()) { DriveBlockEntity entity = (DriveBlockEntity) iterator.next().getService(IStorageProvider.class); - if(entity == null) continue; + if (entity == null) continue; InternalInventory inventory = entity.getInternalInventory(); - for(int i = 0; i < inventory.size(); i++) { + for (int i = 0; i < inventory.size(); i++) { ItemStack stack = inventory.getStackInSlot(i); - if(stack.isEmpty()) continue; + if (stack.isEmpty()) continue; - if(stack.getItem() instanceof BasicStorageCell cell) { + if (stack.getItem() instanceof BasicStorageCell cell) { int bytesPerType = cell.getBytesPerType(null); - if(cell.getKeyType().getClass().isAssignableFrom(AEKeyType.items().getClass())) { - if(stack.getTag() == null) continue; + if (cell.getKeyType().getClass().isAssignableFrom(AEKeyType.items().getClass())) { + if (stack.getTag() == null) continue; int numOfType = stack.getTag().getLongArray("amts").length; long numItemsInCell = stack.getTag().getLong("ic"); @@ -347,18 +342,18 @@ public static long getUsedFluidStorage(IGridNode node) { if (!iterator.hasNext()) return 0; while (iterator.hasNext()) { DriveBlockEntity entity = (DriveBlockEntity) iterator.next().getService(IStorageProvider.class); - if(entity == null) continue; + if (entity == null) continue; InternalInventory inventory = entity.getInternalInventory(); - for(int i = 0; i < inventory.size(); i++) { + for (int i = 0; i < inventory.size(); i++) { ItemStack stack = inventory.getStackInSlot(i); - if(stack.getItem() instanceof BasicStorageCell cell) { + if (stack.getItem() instanceof BasicStorageCell cell) { int bytesPerType = cell.getBytesPerType(null); - if(cell.getKeyType().getClass().isAssignableFrom(AEKeyType.fluids().getClass())) { - if(stack.getTag() == null) continue; + if (cell.getKeyType().getClass().isAssignableFrom(AEKeyType.fluids().getClass())) { + if (stack.getTag() == null) continue; int numOfType = stack.getTag().getLongArray("amts").length; long numBucketsInCell = stack.getTag().getLong("ic") / 1000; @@ -387,16 +382,16 @@ public static List listCells(IGridNode node) { if (!iterator.hasNext()) return items; while (iterator.hasNext()) { DriveBlockEntity entity = (DriveBlockEntity) iterator.next().getService(IStorageProvider.class); - if(entity == null) continue; + if (entity == null) continue; InternalInventory inventory = entity.getInternalInventory(); - for(int i = 0; i < inventory.size(); i++) { + for (int i = 0; i < inventory.size(); i++) { ItemStack stack = inventory.getStackInSlot(i); - if(stack.isEmpty()) continue; + if (stack.isEmpty()) continue; - if(stack.getItem() instanceof BasicStorageCell cell) { + if (stack.getItem() instanceof BasicStorageCell cell) { items.add(getObjectFromCell(cell, stack)); } } @@ -412,9 +407,9 @@ private static Map getObjectFromCell(BasicStorageCell cell, Item String cellType = ""; - if(cell.getKeyType().getClass().isAssignableFrom(AEKeyType.items().getClass())) { + if (cell.getKeyType().getClass().isAssignableFrom(AEKeyType.items().getClass())) { cellType = "item"; - } else if(cell.getKeyType().getClass().isAssignableFrom(AEKeyType.fluids().getClass())) { + } else if (cell.getKeyType().getClass().isAssignableFrom(AEKeyType.fluids().getClass())) { cellType = "fluid"; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeBridgeEntityListener.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeBridgeEntityListener.java index 1aee16c85..10cc242fb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeBridgeEntityListener.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeBridgeEntityListener.java @@ -4,18 +4,17 @@ import appeng.api.networking.IGridNodeListener; import de.srendi.advancedperipherals.common.blocks.blockentities.MeBridgeEntity; -//TODO: Maybe do something special with these methods? public class MeBridgeEntityListener implements IGridNodeListener { public static final MeBridgeEntityListener INSTANCE = new MeBridgeEntityListener(); @Override public void onSecurityBreak(MeBridgeEntity nodeOwner, IGridNode node) { - + // Maybe do something special with these methods? } @Override public void onSaveChanges(MeBridgeEntity nodeOwner, IGridNode node) { - + // Maybe do something special with these methods? } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeFluidHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeFluidHandler.java index 8072a777d..6f10b6be9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeFluidHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeFluidHandler.java @@ -12,6 +12,7 @@ /** * Used to transfer item between an inventory and the ME system. + * * @see de.srendi.advancedperipherals.common.addons.computercraft.peripheral.MeBridgePeripheral */ public class MeFluidHandler implements IStorageSystemFluidHandler { @@ -28,7 +29,7 @@ public MeFluidHandler(@NotNull MEStorage storageMonitor, @NotNull IActionSource @Override public int fill(FluidStack resource, FluidAction action) { - if(resource.isEmpty()) + if (resource.isEmpty()) return 0; AEFluidKey itemKey = AEFluidKey.of(resource.getFluid()); long inserted = storageMonitor.insert(itemKey, resource.getAmount(), action == FluidAction.SIMULATE ? Actionable.SIMULATE : Actionable.MODULATE, actionSource); @@ -40,7 +41,7 @@ public int fill(FluidStack resource, FluidAction action) { @Override public FluidStack drain(FluidFilter filter, FluidAction simulate) { Pair itemKey = AppEngApi.findAEFluidFromFilter(storageMonitor, null, filter); - if(itemKey == null) + if (itemKey == null) return FluidStack.EMPTY; long extracted = storageMonitor.extract(itemKey.getRight(), filter.getCount(), simulate == FluidAction.SIMULATE ? Actionable.SIMULATE : Actionable.MODULATE, actionSource); return new FluidStack(itemKey.getRight().getFluid(), (int) Math.min(extracted, Integer.MAX_VALUE)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/base/IStoragePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/base/IStoragePeripheral.java index 5c4272322..339c5b18c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/base/IStoragePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/base/IStoragePeripheral.java @@ -9,7 +9,7 @@ /** * Implementation for common storage peripheral functions. Used for AE2 {@link de.srendi.advancedperipherals.common.addons.computercraft.peripheral.MeBridgePeripheral} * and RS {@link de.srendi.advancedperipherals.common.addons.computercraft.peripheral.RsBridgePeripheral} - * + *

* This ensures that these both bridges use the same methods. This makes it easier to support both in the same script * In case there is a new mod which adds new ways to store and craft items, this ensures that the new peripheral * has the same functions as the other ones diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/BeaconIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/BeaconIntegration.java index 09e655726..0a35755df 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/BeaconIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/BeaconIntegration.java @@ -2,7 +2,6 @@ import dan200.computercraft.api.lua.LuaFunction; import de.srendi.advancedperipherals.lib.peripherals.BlockEntityIntegrationPeripheral; -import net.minecraft.nbt.CompoundTag; import net.minecraft.world.level.block.entity.BeaconBlockEntity; import net.minecraft.world.level.block.entity.BlockEntity; import org.jetbrains.annotations.NotNull; @@ -20,9 +19,7 @@ public BeaconIntegration(BlockEntity entity) { @LuaFunction(mainThread = true) public final int getLevel() { - // because levels are now protected field .... why? - CompoundTag savedData = blockEntity.saveWithoutMetadata(); - return savedData.getInt("Levels"); + return blockEntity.levels; } @LuaFunction(mainThread = true) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SingleOperation.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SingleOperation.java index 08ebd3c6b..df8cd27e9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SingleOperation.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SingleOperation.java @@ -5,7 +5,7 @@ import java.util.HashMap; import java.util.Map; -import java.util.function.Function; +import java.util.function.UnaryOperator; public enum SingleOperation implements IPeripheralOperation { DIG(1000, 1), @@ -76,9 +76,9 @@ public enum DistancePolicy { IGNORED(d -> 1), SQRT(d -> (int) Math.sqrt(d)); - private final Function factorFunction; + private final UnaryOperator factorFunction; - DistancePolicy(Function factorFunction) { + DistancePolicy(UnaryOperator factorFunction) { this.factorFunction = factorFunction; } @@ -90,9 +90,9 @@ public int getFactor(int distance) { public enum CountPolicy { MULTIPLY(c -> c); - private final Function factorFunction; + private final UnaryOperator factorFunction; - CountPolicy(Function factorFunction) { + CountPolicy(UnaryOperator factorFunction) { this.factorFunction = factorFunction; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BasePeripheralOwner.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BasePeripheralOwner.java index c23b0d025..5503c3bdf 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BasePeripheralOwner.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BasePeripheralOwner.java @@ -9,7 +9,7 @@ public abstract class BasePeripheralOwner implements IPeripheralOwner { private final Map, IOwnerAbility> abilities; - public BasePeripheralOwner() { + protected BasePeripheralOwner() { abilities = new HashMap<>(); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java index ed3c89cbb..4e7d1bd94 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java @@ -13,6 +13,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; +import org.apache.commons.lang3.NotImplementedException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -79,7 +80,7 @@ public void markDataStorageDirty() { @Override public T1 withPlayer(Function function) { - throw new RuntimeException("Not implemented yet"); + throw new NotImplementedException(); } @Override @@ -90,7 +91,7 @@ public ItemStack getToolInMainHand() { @Override public ItemStack storeItem(ItemStack stored) { // TODO: tricks with capability needed - throw new RuntimeException("Not implemented yet"); + throw new NotImplementedException(); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/FuelAbility.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/FuelAbility.java index 07245d648..80ecdefb0 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/FuelAbility.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/FuelAbility.java @@ -14,7 +14,7 @@ public abstract class FuelAbility implements IOwnerA protected @NotNull T owner; - public FuelAbility(@NotNull T owner) { + protected FuelAbility(@NotNull T owner) { this.owner = owner; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/PeripheralOwnerAbility.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/PeripheralOwnerAbility.java index 4f5627f5e..fefa8a5be 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/PeripheralOwnerAbility.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/PeripheralOwnerAbility.java @@ -5,6 +5,6 @@ public class PeripheralOwnerAbility { public static final PeripheralOwnerAbility> FUEL = new PeripheralOwnerAbility<>(); public static final PeripheralOwnerAbility OPERATION = new PeripheralOwnerAbility<>(); - public PeripheralOwnerAbility() { + private PeripheralOwnerAbility() { } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/TurtlePeripheralOwner.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/TurtlePeripheralOwner.java index c96fb8ce8..d3a842800 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/TurtlePeripheralOwner.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/TurtlePeripheralOwner.java @@ -106,8 +106,6 @@ public boolean isMovementPossible(@NotNull Level level, @NotNull BlockPos pos) { return FakePlayerProviderTurtle.withPlayer(turtle, player -> { if (level.isOutsideBuildHeight(pos)) return false; if (!level.isInWorldBounds(pos)) return false; - //if (Config.turtlesObeyBlockProtection && !TurtlePermissions.isBlockEnterable(level, pos, player)) - // return false; if (!level.isAreaLoaded(pos, 0)) return false; return level.getWorldBorder().isWithinBounds(pos); }); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/BlockReaderPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/BlockReaderPeripheral.java index ba04a80b9..c56de4466 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/BlockReaderPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/BlockReaderPeripheral.java @@ -35,7 +35,7 @@ public final Object getBlockData() { if (getBlockInFront().is(Blocks.AIR)) return null; BlockEntity target = getLevel().getBlockEntity(getPos().relative(owner.getFacing())); - if(target == null) + if (target == null) return null; return NBTUtil.toLua(target.saveWithoutMetadata()); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java index 6fa53f4b4..2ac3df181 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java @@ -77,7 +77,7 @@ public final double getHeight() { @LuaFunction public final double getDistance() { - return getPeripheralOwner().tileEntity.getDistance() - 1; + return getPeripheralOwner().tileEntity.getCurrentDistance() - 1; } @LuaFunction diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/EnvironmentDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/EnvironmentDetectorPeripheral.java index f37aa156e..e2c9caff3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/EnvironmentDetectorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/EnvironmentDetectorPeripheral.java @@ -36,7 +36,6 @@ import net.minecraftforge.event.entity.player.SleepingTimeCheckEvent; import net.minecraftforge.eventbus.api.Event; import net.minecraftforge.server.ServerLifecycleHooks; - import org.jetbrains.annotations.NotNull; import java.util.*; @@ -173,13 +172,10 @@ private Map getCurrentMoonPhase() { case 5 -> moon.put(5, "Waxing crescent"); case 6 -> moon.put(6, "First quarter"); case 7 -> moon.put(7, "Waxing gibbous"); - default -> - //should never happen - moon.put(0, "What is a moon"); + default -> moon.put(0, "What is a moon"); } } else { - //Yay, easter egg - //Returns when the function is not used in the overworld + // aren't we in the overworld? moon.put(0, "Moon.exe not found..."); } return moon; @@ -232,10 +228,10 @@ public final MethodResult canSleepHere() { @LuaFunction(mainThread = true) public final MethodResult canSleepPlayer(String playername) { Player player = ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayerByName(playername); - if(player == null) + if (player == null) return MethodResult.of(false, "player_not_online"); - if(!player.level.dimensionType().bedWorks()) + if (!player.level.dimensionType().bedWorks()) return MethodResult.of(false, "not_allowed_in_dimension"); SleepingTimeCheckEvent evt = new SleepingTimeCheckEvent(player, Optional.empty()); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java index d2afd122d..832d9985d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java @@ -258,12 +258,12 @@ private Player getOwnerPlayer() throws LuaException { private Pair getHandlerFromSlot(int slot) throws LuaException { IItemHandler handler; - if(slot >= 100 && slot <= 103) { + if (slot >= 100 && slot <= 103) { handler = new PlayerArmorInvWrapper(getOwnerPlayer().getInventory()); // If the slot is between 100 and 103, change the index to a normal index between 0 and 3. // This is necessary since the PlayerArmorInvWrapper does not work with these higher indexes slot = getArmorSlot(slot); - } else if(slot == 36) { + } else if (slot == 36) { handler = new PlayerOffhandInvWrapper(getOwnerPlayer().getInventory()); // Set the "from slot" to zero so the offhand wrapper can work with that slot = 0; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java index 8f5639fae..cd74d4b19 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java @@ -29,7 +29,10 @@ import net.minecraftforge.items.IItemHandler; import org.jetbrains.annotations.NotNull; -import java.util.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Objects; public class MeBridgePeripheral extends BasePeripheral> { @@ -68,7 +71,7 @@ protected MethodResult exportToChest(@NotNull IArguments arguments, @NotNull IIt MeItemHandler itemHandler = new MeItemHandler(monitor, tile); Pair filter = ItemFilter.parse(arguments.getTable(0)); - if(filter.rightPresent()) + if (filter.rightPresent()) return MethodResult.of(0, filter.getRight()); return MethodResult.of(InventoryUtil.moveItem(itemHandler, targetInventory, filter.getLeft()), null); @@ -77,7 +80,7 @@ protected MethodResult exportToChest(@NotNull IArguments arguments, @NotNull IIt /** * exports a fluid out of the system to a valid tank * - * @param arguments the arguments given by the computer + * @param arguments the arguments given by the computer * @param targetTank the give tank * @return the exportable amount or null with a string if something went wrong */ @@ -86,7 +89,7 @@ protected MethodResult exportToTank(@NotNull IArguments arguments, @NotNull IFlu MeFluidHandler fluidHandler = new MeFluidHandler(monitor, tile); Pair filter = FluidFilter.parse(arguments.getTable(0)); - if(filter.rightPresent()) + if (filter.rightPresent()) return MethodResult.of(0, filter.getRight()); return MethodResult.of(InventoryUtil.moveFluid(fluidHandler, targetTank, filter.getLeft()), null); @@ -104,7 +107,7 @@ protected MethodResult importToME(@NotNull IArguments arguments, @NotNull IItemH MeItemHandler itemHandler = new MeItemHandler(monitor, tile); Pair filter = ItemFilter.parse(arguments.getTable(0)); - if(filter.rightPresent()) + if (filter.rightPresent()) return MethodResult.of(0, filter.getRight()); return MethodResult.of(InventoryUtil.moveItem(targetInventory, itemHandler, filter.getLeft()), null); @@ -113,7 +116,7 @@ protected MethodResult importToME(@NotNull IArguments arguments, @NotNull IItemH /** * imports a fluid to the system from a valid tank * - * @param arguments the arguments given by the computer + * @param arguments the arguments given by the computer * @param targetTank the give tank * @return the imported amount or null with a string if something went wrong */ @@ -122,7 +125,7 @@ protected MethodResult importToME(@NotNull IArguments arguments, @NotNull IFluid MeFluidHandler fluidHandler = new MeFluidHandler(monitor, tile); Pair filter = FluidFilter.parse(arguments.getTable(0)); - if(filter.rightPresent()) + if (filter.rightPresent()) return MethodResult.of(0, filter.getRight()); return MethodResult.of(InventoryUtil.moveFluid(targetTank, fluidHandler, filter.getLeft()), null); @@ -143,7 +146,7 @@ public final MethodResult craftItem(IComputerAccess computer, IArguments argumen return notConnected(); Pair filter = ItemFilter.parse(arguments.getTable(0)); - if(filter.rightPresent()) + if (filter.rightPresent()) return MethodResult.of(false, filter.getRight()); ItemFilter parsedFilter = filter.getLeft(); @@ -152,7 +155,7 @@ public final MethodResult craftItem(IComputerAccess computer, IArguments argumen String cpuName = arguments.optString(1, ""); ICraftingCPU target = getCraftingCPU(cpuName); - if(!cpuName.isEmpty() && target == null) + if (!cpuName.isEmpty() && target == null) return MethodResult.of(false, "CPU " + cpuName + " does not exists"); ICraftingService craftingGrid = node.getGrid().getService(ICraftingService.class); @@ -216,7 +219,7 @@ public final MethodResult isItemCrafting(IArguments arguments) throws LuaExcepti ICraftingService grid = node.getGrid().getService(ICraftingService.class); Pair filter = ItemFilter.parse(arguments.getTable(0)); - if(filter.rightPresent()) + if (filter.rightPresent()) return MethodResult.of(false, filter.getRight()); ItemFilter parsedFilter = filter.getLeft(); @@ -234,7 +237,7 @@ public final MethodResult isItemCraftable(IArguments arguments) throws LuaExcept return notConnected(); Pair filter = ItemFilter.parse(arguments.getTable(0)); - if(filter.rightPresent()) + if (filter.rightPresent()) return MethodResult.of(false, filter.getRight()); ItemFilter parsedFilter = filter.getLeft(); @@ -313,7 +316,7 @@ public final MethodResult getItem(IArguments arguments) throws LuaException { MEStorage monitor = AppEngApi.getMonitor(node); Pair filter = ItemFilter.parse(arguments.getTable(0)); - if(filter.rightPresent()) + if (filter.rightPresent()) return MethodResult.of(null, filter.getRight()); ItemFilter parsedFilter = filter.getLeft(); @@ -427,7 +430,7 @@ public final MethodResult getCraftingCPUs() throws LuaException { } public final ICraftingCPU getCraftingCPU(String cpuName) { - if(cpuName.isEmpty()) return null; + if (cpuName.isEmpty()) return null; ICraftingService grid = node.getGrid().getService(ICraftingService.class); if (grid == null) return null; @@ -437,7 +440,7 @@ public final ICraftingCPU getCraftingCPU(String cpuName) { while (iterator.hasNext()) { ICraftingCPU cpu = iterator.next(); - if(Objects.requireNonNull(cpu.getName()).getString().equals(cpuName)) { + if (Objects.requireNonNull(cpu.getName()).getString().equals(cpuName)) { return cpu; } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/PlayerDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/PlayerDetectorPeripheral.java index 0e2788630..03ebdae1a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/PlayerDetectorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/PlayerDetectorPeripheral.java @@ -113,7 +113,7 @@ public final boolean isPlayerInCoords(Map firstCoord, Map secondCoor BlockPos secondPos = LuaConverter.convertToBlockPos(secondCoord); for (Player player : getPlayers()) { if (CoordUtil.isInRange(getPos(), player, getLevel(), firstPos, secondPos)) - if(player.getName().getString().equals(username)) + if (player.getName().getString().equals(username)) return true; } return false; @@ -123,7 +123,7 @@ public final boolean isPlayerInCoords(Map firstCoord, Map secondCoor public final boolean isPlayerInCubic(int x, int y, int z, String username) { for (Player player : getPlayers()) { if (CoordUtil.isInRange(getPos(), getLevel(), player, x, y, z)) { - if(player.getName().getString().equals(username)) + if (player.getName().getString().equals(username)) return true; } } @@ -134,7 +134,7 @@ public final boolean isPlayerInCubic(int x, int y, int z, String username) { public final boolean isPlayerInRange(int range, String username) { for (Player player : getPlayers()) { if (CoordUtil.isInRange(getPos(), getLevel(), player, range)) { - if(player.getName().getString().equals(username)) + if (player.getName().getString().equals(username)) return true; } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java index a4bea171f..c01d2cb8f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java @@ -27,6 +27,7 @@ import net.minecraftforge.items.IItemHandler; import net.minecraftforge.registries.ForgeRegistries; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -171,7 +172,7 @@ public final MethodResult getPattern(IArguments arguments) throws LuaException { return MethodResult.of(RefinedStorage.getObjectFromPattern(getNetwork().getCraftingManager().getPattern(patternItem), getNetwork())); } - protected MethodResult exportToChest(@NotNull IArguments arguments, @NotNull IItemHandler targetInventory) throws LuaException { + protected MethodResult exportToChest(@NotNull IArguments arguments, @Nullable IItemHandler targetInventory) throws LuaException { RsItemHandler itemHandler = new RsItemHandler(getNetwork()); if (targetInventory == null) return MethodResult.of(0, "INVALID_TARGET"); @@ -183,7 +184,7 @@ protected MethodResult exportToChest(@NotNull IArguments arguments, @NotNull IIt return MethodResult.of(InventoryUtil.moveItem(itemHandler, targetInventory, filter.getLeft()), null); } - protected MethodResult importToSystem(@NotNull IArguments arguments, @NotNull IItemHandler targetInventory) throws LuaException { + protected MethodResult importToSystem(@NotNull IArguments arguments, @Nullable IItemHandler targetInventory) throws LuaException { RsItemHandler itemHandler = new RsItemHandler(getNetwork()); if (targetInventory == null) return MethodResult.of(0, "INVALID_TARGET"); @@ -195,7 +196,7 @@ protected MethodResult importToSystem(@NotNull IArguments arguments, @NotNull II return MethodResult.of(InventoryUtil.moveItem(targetInventory, itemHandler, filter.getLeft()), null); } - protected MethodResult exportToTank(@NotNull IArguments arguments, @NotNull IFluidHandler targetInventory) throws LuaException { + protected MethodResult exportToTank(@NotNull IArguments arguments, @Nullable IFluidHandler targetInventory) throws LuaException { RsFluidHandler itemHandler = new RsFluidHandler(getNetwork()); if (targetInventory == null) return MethodResult.of(0, "INVALID_TARGET"); @@ -207,7 +208,7 @@ protected MethodResult exportToTank(@NotNull IArguments arguments, @NotNull IFlu return MethodResult.of(InventoryUtil.moveFluid(itemHandler, targetInventory, filter.getLeft()), null); } - protected MethodResult importToSystem(@NotNull IArguments arguments, @NotNull IFluidHandler targetInventory) throws LuaException { + protected MethodResult importToSystem(@NotNull IArguments arguments, @Nullable IFluidHandler targetInventory) throws LuaException { RsFluidHandler itemHandler = new RsFluidHandler(getNetwork()); if (targetInventory == null) return MethodResult.of(0, "INVALID_TARGET"); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredHusbandryAutomataCorePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredHusbandryAutomataCorePeripheral.java index fc8f7e980..1a8bd8b68 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredHusbandryAutomataCorePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredHusbandryAutomataCorePeripheral.java @@ -15,6 +15,7 @@ public OverpoweredHusbandryAutomataCorePeripheral(ITurtleAccess turtle, TurtleSi setAttribute(ATTR_STORING_TOOL_DURABILITY); } + @Override public void addRotationCycle(int count) { super.addRotationCycle(count); if (AdvancedPeripherals.RANDOM.nextDouble() <= APConfig.METAPHYSICS_CONFIG.overpoweredAutomataBreakChance.get()) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredWeakAutomataCorePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredWeakAutomataCorePeripheral.java index cca911a2a..b902c81d0 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredWeakAutomataCorePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredWeakAutomataCorePeripheral.java @@ -15,6 +15,7 @@ public OverpoweredWeakAutomataCorePeripheral(ITurtleAccess turtle, TurtleSide si setAttribute(ATTR_STORING_TOOL_DURABILITY); } + @Override public void addRotationCycle(int count) { super.addRotationCycle(count); if (AdvancedPeripherals.RANDOM.nextDouble() <= APConfig.METAPHYSICS_CONFIG.overpoweredAutomataBreakChance.get()) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/WeakAutomataCorePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/WeakAutomataCorePeripheral.java index afaae9ebc..1d06638da 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/WeakAutomataCorePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/WeakAutomataCorePeripheral.java @@ -3,11 +3,7 @@ import dan200.computercraft.api.turtle.ITurtleAccess; import dan200.computercraft.api.turtle.TurtleSide; import de.srendi.advancedperipherals.common.addons.computercraft.operations.AutomataCoreTier; -import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.plugins.AutomataBlockHandPlugin; -import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.plugins.AutomataChargingPlugin; -import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.plugins.AutomataItemSuckPlugin; -import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.plugins.AutomataLookPlugin; -import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.plugins.AutomataSoulFeedingPlugin; +import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.plugins.*; import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.lib.metaphysics.IAutomataCoreTier; import de.srendi.advancedperipherals.lib.peripherals.AutomataCorePeripheral; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityTransferPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityTransferPlugin.java index b99d53de3..589f7cc16 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityTransferPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityTransferPlugin.java @@ -15,8 +15,8 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.HitResult; - import org.jetbrains.annotations.Nullable; + import java.util.function.Predicate; import static de.srendi.advancedperipherals.common.addons.computercraft.operations.SingleOperation.CAPTURE_ANIMAL; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/create/BasinIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/create/BasinIntegration.java index 09284ba09..12478030a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/create/BasinIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/create/BasinIntegration.java @@ -11,11 +11,7 @@ import net.minecraftforge.registries.ForgeRegistries; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; public class BasinIntegration extends BlockEntityIntegrationPeripheral { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/MekanismCapabilities.java b/src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/MekanismCapabilities.java index a9e20a1f9..69371ca95 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/MekanismCapabilities.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/MekanismCapabilities.java @@ -8,6 +8,7 @@ public class MekanismCapabilities { - public static final Capability GAS_HANDLER = get(new CapabilityToken<>(){}); + public static final Capability GAS_HANDLER = get(new CapabilityToken<>() { + }); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java index a90cdc096..34dc25437 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java @@ -29,13 +29,7 @@ import net.minecraftforge.registries.ForgeRegistries; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.*; import java.util.function.Supplier; import java.util.stream.Stream; @@ -69,7 +63,7 @@ public static ItemStack findStackFromFilter(INetwork network, ICraftingManager c return ItemStack.EMPTY; for (ICraftingPattern pattern : crafting.getPatterns()) { - for(ItemStack stack : pattern.getOutputs()) { + for (ItemStack stack : pattern.getOutputs()) { if (filter.test(stack.copy())) return stack.copy(); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsFluidHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsFluidHandler.java index d902570b5..46757ae19 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsFluidHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsFluidHandler.java @@ -19,7 +19,7 @@ public RsFluidHandler(@NotNull INetwork network) { @Override public int fill(FluidStack resource, FluidAction action) { - if(resource.isEmpty()) + if (resource.isEmpty()) return 0; return resource.getAmount() - network.insertFluid(resource, resource.getAmount(), action == FluidAction.SIMULATE ? Action.SIMULATE : Action.PERFORM).getAmount(); } @@ -28,7 +28,7 @@ public int fill(FluidStack resource, FluidAction action) { @Override public FluidStack drain(FluidFilter filter, FluidAction simulate) { FluidStack fluid = RefinedStorage.findFluidFromFilter(network, null, filter); - if(fluid == null) + if (fluid == null) return FluidStack.EMPTY; return network.extractFluid(fluid, filter.getCount(), filter.getNbt() != null ? IComparer.COMPARE_NBT : 0, simulate == FluidAction.SIMULATE ? Action.SIMULATE : Action.PERFORM); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java index 8ea6c5329..70f6d6a7c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java @@ -10,6 +10,7 @@ /** * Used to transfer item between an inventory and the RS system. + * * @see de.srendi.advancedperipherals.common.addons.computercraft.peripheral.RsBridgePeripheral */ public class RsItemHandler implements IStorageSystemItemHandler { @@ -30,7 +31,7 @@ public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate @Override public ItemStack extractItem(ItemFilter filter, boolean simulate) { ItemStack item = RefinedStorage.findStackFromFilter(network, network.getCraftingManager(), filter); - if(item == null) + if (item == null) return ItemStack.EMPTY; return network.extractItem(item, filter.getCount(), filter.getNbt() != null ? IComparer.COMPARE_NBT : IComparer.COMPARE_QUANTITY, simulate ? Action.SIMULATE : Action.PERFORM); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlockEntityBlock.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlockEntityBlock.java index f61085f95..3381c7172 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlockEntityBlock.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlockEntityBlock.java @@ -4,11 +4,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerPlayer; import net.minecraft.tags.BlockTags; -import net.minecraft.world.Container; -import net.minecraft.world.Containers; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.MenuProvider; +import net.minecraft.world.*; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PeripheralBlockEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PeripheralBlockEntity.java index 8e6e1d5bf..d4c09dbd3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PeripheralBlockEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PeripheralBlockEntity.java @@ -45,7 +45,7 @@ public abstract class PeripheralBlockEntity> extends private LazyOptional fluidHandler; private LazyOptional peripheralCap; - public PeripheralBlockEntity(BlockEntityType tileEntityTypeIn, BlockPos pos, BlockState state) { + protected PeripheralBlockEntity(BlockEntityType tileEntityTypeIn, BlockPos pos, BlockState state) { super(tileEntityTypeIn, pos, state); if (this instanceof IInventoryBlock inventoryBlock) { items = NonNullList.withSize(inventoryBlock.getInvSize(), ItemStack.EMPTY); diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PoweredPeripheralBlockEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PoweredPeripheralBlockEntity.java index bace719d3..21a25c070 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PoweredPeripheralBlockEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PoweredPeripheralBlockEntity.java @@ -19,7 +19,7 @@ public abstract class PoweredPeripheralBlockEntity> private final LazyOptional lazyEnergyStorage; - public PoweredPeripheralBlockEntity(BlockEntityType tileEntityTypeIn, BlockPos pos, BlockState state) { + protected PoweredPeripheralBlockEntity(BlockEntityType tileEntityTypeIn, BlockPos pos, BlockState state) { super(tileEntityTypeIn, pos, state); if (APConfig.PERIPHERALS_CONFIG.enablePoweredPeripherals.get()) { lazyEnergyStorage = LazyOptional.of(() -> new EnergyStorage(this.getMaxEnergyStored())); diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java index fa6798a51..fe36128b9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java @@ -21,8 +21,8 @@ public class DistanceDetectorEntity extends PeripheralBlockEntity { - private DistanceDetectorPeripheral.DetectionType detectionType = DistanceDetectorPeripheral.DetectionType.BOTH; - private float distance = 0; + private final DistanceDetectorPeripheral.DetectionType detectionType = DistanceDetectorPeripheral.DetectionType.BOTH; + private float currentDistance = 0; private double maxRange = APConfig.PERIPHERALS_CONFIG.distanceDetectorRange.get(); private boolean showLaser = true; private boolean shouldCalculatePeriodically = false; @@ -39,15 +39,15 @@ protected DistanceDetectorPeripheral createPeripheral() { } public void setShowLaser(boolean showLaser) { - if(this.showLaser != showLaser) - PacketHandler.sendToAll(new DistanceDetectorSyncPacket(getBlockPos(), getLevel().dimension(), distance, showLaser)); + if (this.showLaser != showLaser) + PacketHandler.sendToAll(new DistanceDetectorSyncPacket(getBlockPos(), getLevel().dimension(), currentDistance, showLaser)); this.showLaser = showLaser; } - public void setDistance(float distance) { - if(this.distance != distance) - PacketHandler.sendToAll(new DistanceDetectorSyncPacket(getBlockPos(), getLevel().dimension(), distance, showLaser)); - this.distance = distance; + public void setCurrentDistance(float currentDistance) { + if (this.currentDistance != currentDistance) + PacketHandler.sendToAll(new DistanceDetectorSyncPacket(getBlockPos(), getLevel().dimension(), currentDistance, showLaser)); + this.currentDistance = currentDistance; } public void setShouldCalculatePeriodically(boolean shouldCalculatePeriodically) { @@ -58,8 +58,8 @@ public void setMaxRange(double maxRange) { this.maxRange = maxRange; } - public float getDistance() { - return distance; + public float getCurrentDistance() { + return currentDistance; } public boolean getLaserVisibility() { @@ -96,43 +96,61 @@ public void handleTick(Level level, BlockState state, Bl @Override public AABB getRenderBoundingBox() { Direction direction = getBlockState().getValue(BaseBlock.ORIENTATION).front(); - return AABB.ofSize(getBlockPos().getCenter(), direction.getStepX() * distance + 1, direction.getStepY() * distance + 1, direction.getStepZ() * distance + 1) - .move(direction.getStepX() * distance / 2, direction.getStepY() * distance / 2, direction.getStepZ() * distance / 2); + return AABB.ofSize(getBlockPos().getCenter(), direction.getStepX() * currentDistance + 1, direction.getStepY() * currentDistance + 1, direction.getStepZ() * currentDistance + 1) + .move(direction.getStepX() * currentDistance / 2, direction.getStepY() * currentDistance / 2, direction.getStepZ() * currentDistance / 2); } public double calculateDistance() { Direction direction = getBlockState().getValue(BaseBlock.ORIENTATION).front(); - Vec3 from = Vec3.atCenterOf(getBlockPos()).add(direction.getNormal().getX() * 0.501, direction.getNormal().getY() * 0.501, direction.getNormal().getZ() * 0.501); - Vec3 to = from.add(direction.getNormal().getX() * maxRange, direction.getNormal().getY() * maxRange, direction.getNormal().getZ() * maxRange); - HitResult result = detectionType == DistanceDetectorPeripheral.DetectionType.BOTH ? HitResultUtil.getHitResult(to, from, getLevel(), ignoreTransparent) : detectionType == DistanceDetectorPeripheral.DetectionType.BLOCK ? HitResultUtil.getBlockHitResult(to, from, getLevel(), ignoreTransparent) : HitResultUtil.getEntityHitResult(to, from, getLevel()); + Vec3 center = getBlockPos().getCenter(); + Vec3 from = center.add(direction.getStepX() * 0.501, direction.getStepY() * 0.501, direction.getStepZ() * 0.501); + Vec3 to = from.add(direction.getStepX() * maxRange, direction.getStepY() * maxRange, direction.getStepZ() * maxRange); + HitResult result = getResult(to, from); + + float distance = calculateDistance(result, center, direction); + setCurrentDistance(distance); + return distance; + } + + private HitResult getResult(Vec3 to, Vec3 from) { + if (detectionType == DistanceDetectorPeripheral.DetectionType.ENTITIES) + return HitResultUtil.getEntityHitResult(to, from, getLevel()); + if (detectionType == DistanceDetectorPeripheral.DetectionType.BLOCK) + return HitResultUtil.getBlockHitResult(to, from, getLevel(), ignoreTransparent); + return HitResultUtil.getHitResult(to, from, getLevel(), ignoreTransparent); + } + private float calculateDistance(HitResult result, Vec3 center, Direction direction) { float distance = 0; - BlockState resultBlock; if (result.getType() != HitResult.Type.MISS) { if (result instanceof BlockHitResult blockHitResult) { - resultBlock = getLevel().getBlockState(blockHitResult.getBlockPos()); - distance = distManhattan(blockHitResult.getBlockPos().getCenter(), getBlockPos().getCenter()); - - if (resultBlock.getBlock() instanceof SlabBlock && direction.getAxis() == Direction.Axis.Y) { - if (resultBlock.getValue(SlabBlock.TYPE) == SlabType.TOP && direction == Direction.UP) - distance = distance + 0.5f; - if (resultBlock.getValue(SlabBlock.TYPE) == SlabType.BOTTOM && direction == Direction.DOWN) - distance = distance - 0.5f; - } + BlockState resultBlock = getLevel().getBlockState(blockHitResult.getBlockPos()); + distance = distManhattan(blockHitResult.getBlockPos().getCenter(), center); + + distance = amendDistance(resultBlock, direction, distance); } if (result instanceof EntityHitResult entityHitResult) { - distance = distManhattan(entityHitResult.getLocation(), getBlockPos().getCenter()); + distance = distManhattan(entityHitResult.getLocation(), center); } } - setDistance(distance); return distance; } + private float amendDistance(BlockState resultBlock, Direction direction, float distance) { + if (resultBlock.getBlock() instanceof SlabBlock && direction.getAxis() == Direction.Axis.Y) { + SlabType type = resultBlock.getValue(SlabBlock.TYPE); + if (type == SlabType.TOP && direction == Direction.UP) + return distance + 0.5f; + if (type == SlabType.BOTTOM && direction == Direction.DOWN) + return distance - 0.5f; + } + return distance; + } private float distManhattan(Vec3 from, Vec3 to) { - float f = (float)Math.abs(from.x - to.x); - float f1 = (float)Math.abs(from.y - to.y); - float f2 = (float)Math.abs(from.z - to.z); + float f = (float) Math.abs(from.x - to.x); + float f1 = (float) Math.abs(from.y - to.y); + float f2 = (float) Math.abs(from.z - to.z); return f + f1 + f2; } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RedstoneIntegratorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RedstoneIntegratorEntity.java index 007b9110f..ecf6ffff3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RedstoneIntegratorEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RedstoneIntegratorEntity.java @@ -3,8 +3,8 @@ import dan200.computercraft.shared.util.RedstoneUtil; import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.RedstoneIntegratorPeripheral; import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; -import de.srendi.advancedperipherals.common.util.ServerWorker; import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; +import de.srendi.advancedperipherals.common.util.ServerWorker; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; @@ -55,7 +55,7 @@ private void setRedstoneOutput(Direction direction, int power) { * See #384 * * @param direction Cardinal direction - * @param power The redstone power from 0 to 15 + * @param power The redstone power from 0 to 15 */ public void setOutput(Direction direction, int power) { ServerWorker.add(() -> setRedstoneOutput(direction, power)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/GeneralConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/GeneralConfig.java index 42ecd89ef..c6bdede53 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/GeneralConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/GeneralConfig.java @@ -26,7 +26,6 @@ public class GeneralConfig implements IAPConfig { configSpec = builder.build(); } - @Override public ForgeConfigSpec getConfigSpec() { return configSpec; diff --git a/src/main/java/de/srendi/advancedperipherals/common/container/base/SlotCondition.java b/src/main/java/de/srendi/advancedperipherals/common/container/base/SlotCondition.java index d1fae341c..1adcfcbc3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/container/base/SlotCondition.java +++ b/src/main/java/de/srendi/advancedperipherals/common/container/base/SlotCondition.java @@ -12,9 +12,9 @@ */ public class SlotCondition { - public List> neededTags = new ArrayList<>(); + private List> neededTags = new ArrayList<>(); - public List neededItems = new ArrayList<>(); + private List neededItems = new ArrayList<>(); /** * Sets the valid tags for the item @@ -75,9 +75,9 @@ public boolean isValid(ItemStack stack) { if (stack.getTags().noneMatch(tag::equals)) valid = false; } } - if (!neededItems.isEmpty()) { - if (!neededItems.contains(stack.getItem())) valid = false; - } + if (!neededItems.isEmpty() && (!neededItems.contains(stack.getItem()))) + valid = false; + return valid; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/BlockStatesAndModelsProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/BlockStatesAndModelsProvider.java index c3c000061..62d03547a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/BlockStatesAndModelsProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/BlockStatesAndModelsProvider.java @@ -42,7 +42,8 @@ private void peripheralBlock(Block block, ModelFile file) { getVariantBuilder(block).forAllStates(state -> { ConfiguredModel.Builder builder = ConfiguredModel.builder().modelFile(file); FrontAndTop orientation = state.getValue(BaseBlock.ORIENTATION); - int x = 0, y; + int x = 0; + int y; if (orientation.top().getAxis() == Direction.Axis.Y) { y = (int) (orientation.front().toYRot() + 180) % 360; } else { @@ -73,7 +74,7 @@ private BlockModelBuilder generateModel(Block block, boolean hasNormalSide, Stri for (Direction direction : Direction.Plane.HORIZONTAL) builder.texture(direction.toString(), blockTexture(block, sideTexture)); } - if(side.equals("north")) + if (side.equals("north")) particleTexture = blockTexture(block, "north"); if (side.equals("front")) { diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesInterfaceItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesInterfaceItem.java index ba924b23b..cae4c81f4 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesInterfaceItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesInterfaceItem.java @@ -59,7 +59,7 @@ public InteractionResultHolder use(@NotNull Level world, @NotNull Pla AdvancedPeripherals.debug("There was an issue with the item handler of the glasses while trying to open the gui"); return InteractionResultHolder.fail(player.getItemInHand(hand)); } - NetworkHooks.openScreen((ServerPlayer) player, new SmartGlassesMenuProvider(computer, glasses, itemHandler.resolve().get()), (bytes) -> new ComputerContainerData(computer, glasses).toBytes(bytes)); + NetworkHooks.openScreen((ServerPlayer) player, new SmartGlassesMenuProvider(computer, glasses, itemHandler.resolve().get()), bytes -> new ComputerContainerData(computer, glasses).toBytes(bytes)); return super.use(world, player, hand); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java index 51d1a0e1a..dc5a5980e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java @@ -1,7 +1,6 @@ package de.srendi.advancedperipherals.common.items; import com.google.common.base.Objects; -import dan200.computercraft.annotations.ForgeOverride; import dan200.computercraft.api.ComputerCraftAPI; import dan200.computercraft.api.filesystem.Mount; import dan200.computercraft.api.media.IMedia; @@ -100,6 +99,12 @@ private boolean tick(ItemStack stack, Level world, Entity entity, SmartGlassesCo changed = true; stack.getOrCreateTag().putBoolean(NBT_ON, on); } + + Entity computerEntity = computer.getEntity(); + if (computerEntity != entity) { + changed = true; + computer.setEntity(entity); + } return changed; } @@ -114,12 +119,13 @@ public void inventoryTick(@NotNull ItemStack stack, Level world, @NotNull Entity if (changed && inventory != null) inventory.setChanged(); } - @ForgeOverride + @Override public boolean onEntityItemUpdate(ItemStack stack, ItemEntity entity) { if (entity.level.isClientSide || entity.level.getServer() == null) return false; SmartGlassesComputer computer = getServerComputer(entity.level.getServer(), stack); - if (computer != null && tick(stack, entity.level, entity, computer)) entity.setItem(stack.copy()); + if (computer != null && tick(stack, entity.level, entity, computer)) + entity.setItem(stack.copy()); return false; } @@ -169,6 +175,7 @@ public void appendHoverText(@NotNull ItemStack stack, @Nullable Level world, @No } } + @Override public String getCreatorModId(ItemStack stack) { return AdvancedPeripherals.MOD_ID; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/base/SmartGlassesMaterials.java b/src/main/java/de/srendi/advancedperipherals/common/items/base/SmartGlassesMaterials.java index 99bb4890f..071976e3e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/base/SmartGlassesMaterials.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/base/SmartGlassesMaterials.java @@ -3,24 +3,17 @@ import de.srendi.advancedperipherals.AdvancedPeripherals; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvents; -import net.minecraft.util.LazyLoadedValue; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.item.ArmorMaterial; import net.minecraft.world.item.Items; import net.minecraft.world.item.crafting.Ingredient; import org.jetbrains.annotations.NotNull; -import java.util.function.Supplier; - public enum SmartGlassesMaterials implements ArmorMaterial { // We use the same name, so they use the same model texture - CHAIN("smart_glasses", 15, new int[]{1, 4, 5, 2}, 12, SoundEvents.ARMOR_EQUIP_CHAIN, 0.0F, 0.0F, () -> { - return Ingredient.of(Items.IRON_INGOT); - }), - NETHERITE("smart_glasses", 37, new int[]{3, 6, 8, 3}, 15, SoundEvents.ARMOR_EQUIP_NETHERITE, 3.0F, 0.1F, () -> { - return Ingredient.of(Items.NETHERITE_INGOT); - }); + CHAIN("smart_glasses", 15, new int[]{1, 4, 5, 2}, 12, SoundEvents.ARMOR_EQUIP_CHAIN, 0.0F, 0.0F, Ingredient.of(Items.IRON_INGOT)), + NETHERITE("smart_glasses", 37, new int[]{3, 6, 8, 3}, 15, SoundEvents.ARMOR_EQUIP_NETHERITE, 3.0F, 0.1F, Ingredient.of(Items.NETHERITE_INGOT)); private static final int[] HEALTH_PER_SLOT = new int[]{13, 15, 16, 11}; private final String name; @@ -30,9 +23,9 @@ public enum SmartGlassesMaterials implements ArmorMaterial { private final SoundEvent sound; private final float toughness; private final float knockbackResistance; - private final LazyLoadedValue repairIngredient; + private final Ingredient repairIngredient; - SmartGlassesMaterials(String pName, int pDurabilityMultiplier, int[] pSlotProtections, int pEnchantmentValue, SoundEvent pSound, float pToughness, float pKnockbackResistance, Supplier pRepairIngredient) { + SmartGlassesMaterials(String pName, int pDurabilityMultiplier, int[] pSlotProtections, int pEnchantmentValue, SoundEvent pSound, float pToughness, float pKnockbackResistance, Ingredient pRepairIngredient) { this.name = pName; this.durabilityMultiplier = pDurabilityMultiplier; this.slotProtections = pSlotProtections; @@ -40,7 +33,7 @@ public enum SmartGlassesMaterials implements ArmorMaterial { this.sound = pSound; this.toughness = pToughness; this.knockbackResistance = pKnockbackResistance; - this.repairIngredient = new LazyLoadedValue<>(pRepairIngredient); + this.repairIngredient = pRepairIngredient; } public int getDurabilityForSlot(EquipmentSlot pSlot) { @@ -62,7 +55,7 @@ public SoundEvent getEquipSound() { @NotNull public Ingredient getRepairIngredient() { - return this.repairIngredient.get(); + return this.repairIngredient; } @NotNull diff --git a/src/main/java/de/srendi/advancedperipherals/common/network/DistanceDetectorSyncPacket.java b/src/main/java/de/srendi/advancedperipherals/common/network/DistanceDetectorSyncPacket.java index 04e139eb1..267c8dad9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/network/DistanceDetectorSyncPacket.java +++ b/src/main/java/de/srendi/advancedperipherals/common/network/DistanceDetectorSyncPacket.java @@ -40,7 +40,7 @@ public void handle(NetworkEvent.Context context) { return; } if (tileEntity instanceof DistanceDetectorEntity detector) { - detector.setDistance(distance); + detector.setCurrentDistance(distance); detector.setShowLaser(showLaser); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java index 89c23bbc7..ab760488c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java @@ -8,7 +8,7 @@ public class APBlockEntityTypes { - static void register() { + protected static void register() { } public static final RegistryObject> CHAT_BOX = APRegistration.TILE_ENTITIES.register("chat_box", () -> new BlockEntityType<>(ChatBoxEntity::new, Sets.newHashSet(APBlocks.CHAT_BOX.get()), null)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java index b72c8cd23..c875e077a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java @@ -21,7 +21,7 @@ public class APBlocks { - static void register() { + protected static void register() { } public static final RegistryObject ENVIRONMENT_DETECTOR = register("environment_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.ENVIRONMENT_DETECTOR, false), () -> new APBlockItem(APBlocks.ENVIRONMENT_DETECTOR.get(), APConfig.PERIPHERALS_CONFIG.enableEnvironmentDetector)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java index 8f7f7da07..b51d363b3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java @@ -22,6 +22,7 @@ public class APContainerTypes { (id, inv, data) -> new SmartGlassesContainer(id, player -> true, null, data, inv, data.displayStack()) )); - public static void register() { + protected static void register() { } + } diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java index 5c4c9e05b..fea0fdebe 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java @@ -23,8 +23,7 @@ public class APItems { public static final RegistryObject OVERPOWERED_END_AUTOMATA_CORE = APRegistration.ITEMS.register("overpowered_end_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableEndAutomataCore)); public static final RegistryObject OVERPOWERED_HUSBANDRY_AUTOMATA_CORE = APRegistration.ITEMS.register("overpowered_husbandry_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableHusbandryAutomataCore)); - public static void register() { + protected static void register() { } - } diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APVillagers.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APVillagers.java index 201f947d5..3efecf50b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APVillagers.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APVillagers.java @@ -14,7 +14,7 @@ public class APVillagers { public static final RegistryObject COMPUTER_SCIENTIST = APRegistration.VILLAGER_PROFESSIONS.register("computer_scientist", () -> new VillagerProfession(AdvancedPeripherals.MOD_ID + ":computer_scientist", holder -> holder.is(COMPUTER_SCIENTIST_POI.getKey()), holder -> holder.is(COMPUTER_SCIENTIST_POI.getKey()), ImmutableSet.of(), ImmutableSet.of(ModRegistry.Blocks.COMPUTER_ADVANCED.get()), SoundEvents.VILLAGER_WORK_TOOLSMITH)); - public static void register() { + protected static void register() { } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/CCRegistration.java b/src/main/java/de/srendi/advancedperipherals/common/setup/CCRegistration.java index 5122fe172..11962445a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/CCRegistration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/CCRegistration.java @@ -5,23 +5,9 @@ import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.addons.computercraft.integrations.IntegrationPeripheralProvider; -import de.srendi.advancedperipherals.common.addons.computercraft.pocket.PocketChatBoxUpgrade; -import de.srendi.advancedperipherals.common.addons.computercraft.pocket.PocketColonyIntegratorUpgrade; -import de.srendi.advancedperipherals.common.addons.computercraft.pocket.PocketEnvironmentUpgrade; -import de.srendi.advancedperipherals.common.addons.computercraft.pocket.PocketGeoScannerUpgrade; -import de.srendi.advancedperipherals.common.addons.computercraft.pocket.PocketPlayerDetectorUpgrade; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.TurtleChatBoxUpgrade; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.TurtleChunkyUpgrade; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.TurtleCompassUpgrade; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.TurtleEnvironmentDetectorUpgrade; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.TurtleGeoScannerUpgrade; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.TurtlePlayerDetectorUpgrade; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.EndAutomata; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.HusbandryAutomata; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.OverpoweredEndAutomata; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.OverpoweredHusbandryAutomata; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.OverpoweredWeakAutomata; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.WeakAutomata; +import de.srendi.advancedperipherals.common.addons.computercraft.pocket.*; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.*; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.*; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.registries.RegistryObject; @@ -50,7 +36,7 @@ public class CCRegistration { public static IntegrationPeripheralProvider integrationPeripheralProvider; - public static void register() { + protected static void register() { IntegrationPeripheralProvider.load(); integrationPeripheralProvider = new IntegrationPeripheralProvider(); ForgeComputerCraftAPI.registerPeripheralProvider(integrationPeripheralProvider); diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesAccess.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesAccess.java index 636f278ac..85b8c21aa 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesAccess.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesAccess.java @@ -11,7 +11,7 @@ public class SmartGlassesAccess implements IPocketAccess { - private SmartGlassesComputer computer; + private final SmartGlassesComputer computer; public SmartGlassesAccess(SmartGlassesComputer computer) { this.computer = computer; diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java index 7334edd2a..12e442003 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java @@ -29,7 +29,7 @@ public class SmartGlassesComputer extends ServerComputer implements IPocketAccess { private @Nullable Entity entity; - private ItemStack stack = ItemStack.EMPTY; + private final ItemStack stack = ItemStack.EMPTY; private final SmartGlassesAccess smartGlassesAccess = new SmartGlassesAccess(this); private int lightColour = -1; @@ -45,11 +45,10 @@ public SmartGlassesComputer(ServerLevel world, BlockPos position, int computerID @Nullable @Override public Entity getEntity() { - var entity = this.entity; if (entity == null || stack.isEmpty() || !entity.isAlive()) return null; - if (entity instanceof Player) { - var inventory = ((Player) entity).getInventory(); + if (entity instanceof Player player) { + var inventory = player.getInventory(); return inventory.items.contains(stack) || inventory.offhand.contains(stack) ? entity : null; } else if (entity instanceof LivingEntity living) { return living.getMainHandItem() == stack || living.getOffhandItem() == stack ? entity : null; @@ -67,7 +66,7 @@ public int getColour() { @Override public void setColour(int colour) { - + // We don't have a color. } @Override @@ -124,21 +123,6 @@ public void updatePeripheralsAndModules(IItemHandler itemHandler) { } } - public synchronized void updateValues(@Nullable Entity entity, ItemStack stack, @Nullable IPocketUpgrade upgrade) { - if (entity != null) { - setLevel((ServerLevel) entity.getCommandSenderWorld()); - setPosition(entity.blockPosition()); - } - - // If a new entity has picked it up then rebroadcast the terminal to them - if (entity != this.entity && entity instanceof ServerPlayer) markTerminalChanged(); - - this.entity = entity; - this.stack = stack; - - invalidatePeripheral(); - } - @Override public void tickServer() { super.tickServer(); @@ -163,6 +147,10 @@ public void tickServer() { modules.forEach(module -> module.tick(smartGlassesAccess)); } + public void setEntity(@Nullable Entity entity) { + this.entity = entity; + } + public Set getModules() { return modules; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesMenuProvider.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesMenuProvider.java index 688915cc6..bf1fb3b53 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesMenuProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesMenuProvider.java @@ -35,8 +35,8 @@ public Component getDisplayName() { public AbstractContainerMenu createMenu(int id, @NotNull Inventory inventory, @NotNull Player entity) { return new SmartGlassesContainer(id, p -> { - return true; - }, + return true; + }, computer, inventory, glassesContainer, null ); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java index 59656b43b..a9142be64 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java @@ -18,11 +18,7 @@ import java.time.LocalDateTime; import java.time.ZoneOffset; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.util.*; @Mod.EventBusSubscriber(modid = AdvancedPeripherals.MOD_ID) public class ChunkManager extends SavedData { diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java index 7b75ab26b..921579bcb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java @@ -19,7 +19,7 @@ public class CoordUtil { public static boolean isInRange(@NotNull BlockPos pos, @NotNull Level world, @NotNull Player player, int range) { // There are rare cases where these are null. For example if a player detector pocket computer runs while not in a player inventory // Fixes https://github.com/SirEndii/AdvancedPeripherals/issues/356 - if(pos == null || world == null || player == null) + if (pos == null || world == null || player == null) return false; range = Math.min(range, APConfig.PERIPHERALS_CONFIG.playerDetMaxRange.get()); @@ -27,7 +27,7 @@ public static boolean isInRange(@NotNull BlockPos pos, @NotNull Level world, @No } public static boolean isInRange(@NotNull BlockPos pos, @NotNull Level world, @NotNull Player player, int x, int y, int z) { - if(pos == null || world == null || player == null) + if (pos == null || world == null || player == null) return false; x = Math.min(x * 2, APConfig.PERIPHERALS_CONFIG.playerDetMaxRange.get()); @@ -37,7 +37,7 @@ public static boolean isInRange(@NotNull BlockPos pos, @NotNull Level world, @No } public static boolean isInRange(@NotNull BlockPos blockPos, @NotNull Player player, @NotNull Level world, @NotNull BlockPos firstPos, @NotNull BlockPos secondPos) { - if(blockPos == null || world == null || player == null) + if (blockPos == null || world == null || player == null) return false; double i = player.getX() - blockPos.getX(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/FluidStorageProxy.java b/src/main/java/de/srendi/advancedperipherals/common/util/FluidStorageProxy.java index e75f2e599..a61361aa0 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/FluidStorageProxy.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/FluidStorageProxy.java @@ -14,7 +14,7 @@ public class FluidStorageProxy implements IFluidHandler { private final FluidDetectorEntity fluidDetectorEntity; private int maxTransferRate; private int transferedInThisTick = 0; - private Fluid fluid = Fluids.EMPTY; + private final Fluid fluid = Fluids.EMPTY; public FluidStorageProxy(FluidDetectorEntity fluidDetectorEntity, int maxTransferRate) { this.fluidDetectorEntity = fluidDetectorEntity; diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java index 593f47317..96bdfbb2b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java @@ -22,9 +22,10 @@ public class HitResultUtil { /** * This method is used to get the hit result of an entity from the start position of a block - * @param to the target position/max position - * @param from the source position like a block - * @param level the level + * + * @param to the target position/max position + * @param from the source position like a block + * @param level the level * @param ignoreTransparent if transparent blocks should be ignored * @return the hit result {@link BlockHitResult#miss(Vec3, Direction, BlockPos)} if nothing found */ @@ -94,9 +95,9 @@ public static EntityHitResult getEntityHitResult(Vec3 to, Vec3 from, Level level /** * This method is used to get the hit result of a block from the start position of a block * - * @param to the target position/max position - * @param from the source position - * @param level the world + * @param to the target position/max position + * @param from the source position + * @param level the world * @param ignoreNoOccluded if true, the method will ignore blocks which are not occluding like glass * @return the block hit result. {@link BlockHitResult#miss(Vec3, Direction, BlockPos)} if nothing found */ @@ -148,8 +149,9 @@ protected AdvancecClipContext(Vec3 from, Vec3 to, ShapeGetter blockShapeGetter, this.blockShapeGetter = blockShapeGetter; } + @NotNull @Override - public VoxelShape getBlockShape(BlockState pBlockState, BlockGetter pLevel, BlockPos pPos) { + public VoxelShape getBlockShape(@NotNull BlockState pBlockState, @NotNull BlockGetter pLevel, @NotNull BlockPos pPos) { return blockShapeGetter.get(pBlockState, pLevel, pPos, this.collisionContext); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/Pair.java b/src/main/java/de/srendi/advancedperipherals/common/util/Pair.java index 75f56c77e..1be3c86a5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/Pair.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/Pair.java @@ -42,12 +42,12 @@ public boolean rightPresent() { } public void ifRightPresent(Consumer consumer) { - if(rightPresent()) + if (rightPresent()) consumer.accept(right); } public void ifLeftPresent(Consumer consumer) { - if(leftPresent()) + if (leftPresent()) consumer.accept(left); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java index 804370617..8aa21ef45 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java @@ -34,11 +34,7 @@ import net.minecraft.world.level.block.StructureBlock; import net.minecraft.world.level.block.entity.SignBlockEntity; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.AABB; -import net.minecraft.world.phys.BlockHitResult; -import net.minecraft.world.phys.EntityHitResult; -import net.minecraft.world.phys.HitResult; -import net.minecraft.world.phys.Vec3; +import net.minecraft.world.phys.*; import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.ForgeMod; import net.minecraftforge.common.util.FakePlayer; @@ -46,8 +42,8 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.eventbus.api.Event; import org.jetbrains.annotations.NotNull; - import org.jetbrains.annotations.Nullable; + import java.lang.ref.WeakReference; import java.util.List; import java.util.Optional; diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java index d771437d4..acb173ede 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java @@ -105,10 +105,7 @@ public boolean test(FluidStack stack) { } if (tag != null && !stack.getFluid().is(tag)) return false; - if (nbt != null && !stack.getOrCreateTag().equals(nbt)) - return false; - - return true; + return nbt == null || stack.getOrCreateTag().equals(nbt); } public int getCount() { diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemFluidHandler.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemFluidHandler.java index f86f1e487..9cc76fbee 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemFluidHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemFluidHandler.java @@ -11,7 +11,7 @@ public interface IStorageSystemFluidHandler extends IFluidHandler { * Uses a filter to find the right item. The amount should never be greater than 64 * stack sizes greater than 64. * - * @param filter The parsed filter + * @param filter The parsed filter * @param simulate Should this action be simulated * @return extracted from the slot, must be empty if nothing can be extracted. The returned ItemStack can be safely modified after, so item handlers should return a new or copied stack. */ diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemItemHandler.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemItemHandler.java index a1e4fe663..2c595cf60 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemItemHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemItemHandler.java @@ -11,7 +11,7 @@ public interface IStorageSystemItemHandler extends IItemHandler { * Uses a filter to find the right item. The amount should never be greater than 64 * stack sizes greater than 64. * - * @param filter The parsed filter + * @param filter The parsed filter * @param simulate Should this action be simulated * @return extracted from the slot, must be empty if nothing can be extracted. The returned ItemStack can be safely modified after, so item handlers should return a new or copied stack. */ diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/InventoryUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/InventoryUtil.java index cd761543a..62086f3b0 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/InventoryUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/InventoryUtil.java @@ -119,7 +119,7 @@ public static int moveFluid(IFluidHandler inventoryFrom, IFluidHandler inventory FluidStack toExtract = inventoryFrom.getFluidInTank(0).copy(); toExtract.setAmount(amount); FluidStack extracted = inventoryFrom.drain(toExtract, IFluidHandler.FluidAction.SIMULATE); - if(extracted.isEmpty()) + if (extracted.isEmpty()) return 0; int inserted = storageSystemHandler.fill(extracted, IFluidHandler.FluidAction.EXECUTE); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java index 6703796ff..239ce4c1f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java @@ -120,10 +120,7 @@ public boolean test(ItemStack stack) { } if (tag != null && !stack.is(tag)) return false; - if (nbt != null && !stack.getOrCreateTag().equals(nbt)) - return false; - - return true; + return nbt == null || stack.getOrCreateTag().equals(nbt); } public int getCount() { diff --git a/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrade.java b/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrade.java index 37509a075..ce91b0037 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrade.java +++ b/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrade.java @@ -115,10 +115,10 @@ private TradeBuilder(WandererTradesEvent event, ItemStack stack, Type type, int * This one is for normal villagers with any type of{@link ItemLike}. * {@link net.minecraft.world.item.Item} or {@link net.minecraft.world.level.block.Block} as example. * - * @param event this should be executed in an event - pass the villager trade event here - * @param itemLike the item for trade - * @param type the trade type - * @param emeraldAmount the emerald amount of the trade + * @param event this should be executed in an event - pass the villager trade event here + * @param itemLike the item for trade + * @param type the trade type + * @param emeraldAmount the emerald amount of the trade * @param professionLevel the profession level of the villager. 1 to 5 * @return a builder instance */ @@ -130,10 +130,10 @@ public static TradeBuilder createTrade(VillagerTradesEvent event, ItemLike itemL * Creates a new TradeBuilder instance. Can be used to create villager trades for normal villagers * This one is for normal villagers with item stacks * - * @param event this should be executed in an event - pass the villager trade event here - * @param itemStack the item for trade - * @param type the trade type - * @param emeraldAmount the emerald amount of the trade + * @param event this should be executed in an event - pass the villager trade event here + * @param itemStack the item for trade + * @param type the trade type + * @param emeraldAmount the emerald amount of the trade * @param professionLevel the profession level of the villager. 1 to 5 * @return a builder instance */ @@ -146,10 +146,10 @@ public static TradeBuilder createTrade(VillagerTradesEvent event, ItemStack item * This one is for wandering traders with any type of{@link ItemLike}. * {@link net.minecraft.world.item.Item} or {@link net.minecraft.world.level.block.Block} as example. * - * @param event this should be executed in an event - pass the villager trade event here - * @param itemLike the item for trade - * @param type the trade type - * @param emeraldAmount the emerald amount of the trade + * @param event this should be executed in an event - pass the villager trade event here + * @param itemLike the item for trade + * @param type the trade type + * @param emeraldAmount the emerald amount of the trade * @param professionLevel the profession level of the villager. 1 to 5 * @return a builder instance */ @@ -161,10 +161,10 @@ public static TradeBuilder createTrade(WandererTradesEvent event, ItemLike itemL * Creates a new TradeBuilder instance. Can be used to create villager trades for wandering traders. * This one is for normal villagers with item stacks * - * @param event this should be executed in an event - pass the villager trade event here - * @param itemStack the item for trade - * @param type the trade type - * @param emeraldAmount the emerald amount of the trade + * @param event this should be executed in an event - pass the villager trade event here + * @param itemStack the item for trade + * @param type the trade type + * @param emeraldAmount the emerald amount of the trade * @param professionLevel the profession level of the villager. 1 to 5 * @return a builder instance */ @@ -213,10 +213,10 @@ public TradeBuilder setXp(int xp) { */ public void build() { VillagerTrade trade = new VillagerTrade(type, emeraldAmount, itemAmount, maxUses, xp, item, itemStack); - if(wandererEvent != null) { - if(professionLevel == 1) + if (wandererEvent != null) { + if (professionLevel == 1) wandererEvent.getGenericTrades().add(trade); - if(professionLevel == 2) + if (professionLevel == 2) wandererEvent.getRareTrades().add(trade); return; } diff --git a/src/main/java/de/srendi/advancedperipherals/lib/metaphysics/IFeedableAutomataCore.java b/src/main/java/de/srendi/advancedperipherals/lib/metaphysics/IFeedableAutomataCore.java index 6c3534300..c8a4586ab 100644 --- a/src/main/java/de/srendi/advancedperipherals/lib/metaphysics/IFeedableAutomataCore.java +++ b/src/main/java/de/srendi/advancedperipherals/lib/metaphysics/IFeedableAutomataCore.java @@ -1,3 +1,4 @@ package de.srendi.advancedperipherals.lib.metaphysics; -public interface IFeedableAutomataCore {} +public interface IFeedableAutomataCore { +} diff --git a/src/main/java/de/srendi/advancedperipherals/lib/peripherals/BasePeripheral.java b/src/main/java/de/srendi/advancedperipherals/lib/peripherals/BasePeripheral.java index 81261a0bc..685389e06 100644 --- a/src/main/java/de/srendi/advancedperipherals/lib/peripherals/BasePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/lib/peripherals/BasePeripheral.java @@ -1,10 +1,6 @@ package de.srendi.advancedperipherals.lib.peripherals; -import dan200.computercraft.api.lua.IArguments; -import dan200.computercraft.api.lua.ILuaContext; -import dan200.computercraft.api.lua.LuaException; -import dan200.computercraft.api.lua.LuaFunction; -import dan200.computercraft.api.lua.MethodResult; +import dan200.computercraft.api.lua.*; import dan200.computercraft.api.peripheral.IComputerAccess; import dan200.computercraft.api.peripheral.IDynamicPeripheral; import dan200.computercraft.api.peripheral.IPeripheral; @@ -18,12 +14,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.Map; +import java.util.*; import java.util.function.BiConsumer; import java.util.function.Consumer; diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index 5eca3ccef..dc4a3126c 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -2,4 +2,5 @@ public net.minecraft.world.level.block.entity.BeaconBlockEntity f_58652_ public net.minecraft.world.level.block.entity.BeaconBlockEntity f_58653_ public-f net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool f_210559_ # rawTemplates public-f net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool f_210560_ # templates -protected net.minecraft.world.level.ClipContext f_45686_ # collisionContext \ No newline at end of file +protected net.minecraft.world.level.ClipContext f_45686_ # collisionContext +public net.minecraft.world.level.block.entity.BeaconBlockEntity f_58650_ # levels \ No newline at end of file From 221ba87d25187f61a67e90c5742484beec69df9e Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 27 Mar 2023 14:15:57 +0200 Subject: [PATCH 037/228] Fixed detection type --- .../DistanceDetectorPeripheral.java | 21 +++++-------------- .../blockentities/DistanceDetectorEntity.java | 20 ++++++++++++------ 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java index 2ac3df181..65d8579c7 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java @@ -9,8 +9,6 @@ public class DistanceDetectorPeripheral extends BasePeripheral> { public static final String PERIPHERAL_TYPE = "distanceDetector"; - private double height = 0.5; - private DetectionType detectionType = DetectionType.BOTH; public DistanceDetectorPeripheral(DistanceDetectorEntity tileEntity) { super(PERIPHERAL_TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); @@ -42,39 +40,30 @@ public final boolean ignoresTransparency() { } @LuaFunction - public final String setDetectionMode(int mode) { + public final void setDetectionMode(int mode) { if (mode > 2) mode = 2; if (mode < 0) mode = 0; - detectionType = DetectionType.values()[mode]; - return detectionType.toString(); + getPeripheralOwner().tileEntity.setDetectionType(DetectionType.values()[mode]); } @LuaFunction public final boolean detectsEntities() { + DetectionType detectionType = getPeripheralOwner().tileEntity.getDetectionType(); return detectionType == DetectionType.ENTITIES || detectionType == DetectionType.BOTH; } @LuaFunction public final boolean detectsBlocks() { + DetectionType detectionType = getPeripheralOwner().tileEntity.getDetectionType(); return detectionType == DetectionType.BLOCK || detectionType == DetectionType.BOTH; } @LuaFunction public final String getDetectionMode() { + DetectionType detectionType = getPeripheralOwner().tileEntity.getDetectionType(); return detectionType.toString(); } - @LuaFunction - public final double setHeight(double height) { - this.height = Math.max(0, Math.min(1, height)); - return this.height; - } - - @LuaFunction - public final double getHeight() { - return this.height; - } - @LuaFunction public final double getDistance() { return getPeripheralOwner().tileEntity.getCurrentDistance() - 1; diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java index fe36128b9..cfc2b0296 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java @@ -21,12 +21,12 @@ public class DistanceDetectorEntity extends PeripheralBlockEntity { - private final DistanceDetectorPeripheral.DetectionType detectionType = DistanceDetectorPeripheral.DetectionType.BOTH; - private float currentDistance = 0; private double maxRange = APConfig.PERIPHERALS_CONFIG.distanceDetectorRange.get(); + private float currentDistance = 0; private boolean showLaser = true; private boolean shouldCalculatePeriodically = false; private boolean ignoreTransparent = true; + private DistanceDetectorPeripheral.DetectionType detectionType = DistanceDetectorPeripheral.DetectionType.BOTH; public DistanceDetectorEntity(BlockPos pos, BlockState state) { super(APBlockEntityTypes.DISTANCE_DETECTOR.get(), pos, state); @@ -54,6 +54,10 @@ public void setShouldCalculatePeriodically(boolean shouldCalculatePeriodically) this.shouldCalculatePeriodically = shouldCalculatePeriodically; } + public double getMaxDistance() { + return maxRange; + } + public void setMaxRange(double maxRange) { this.maxRange = maxRange; } @@ -70,16 +74,20 @@ public boolean shouldCalculatePeriodically() { return shouldCalculatePeriodically; } + public boolean ignoreTransparent() { + return ignoreTransparent; + } + public void setIgnoreTransparent(boolean ignoreTransparent) { this.ignoreTransparent = ignoreTransparent; } - public boolean ignoreTransparent() { - return ignoreTransparent; + public DistanceDetectorPeripheral.DetectionType getDetectionType() { + return detectionType; } - public double getMaxDistance() { - return maxRange; + public void setDetectionType(DistanceDetectorPeripheral.DetectionType detectionType) { + this.detectionType = detectionType; } @Override From e9f3fda78c443ac3fa6aa7b123ef91ec237e7bb5 Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 27 Mar 2023 20:55:47 +0200 Subject: [PATCH 038/228] Load ap addons statically Return an itemstack created from the AEItemKey instead of a new itemstack to fix #427 --- gradle.properties | 2 +- .../de/srendi/advancedperipherals/AdvancedPeripherals.java | 1 - .../srendi/advancedperipherals/common/addons/APAddons.java | 3 +-- .../common/addons/appliedenergistics/MeItemHandler.java | 4 +++- .../peripheral/plugins/AutomataBlockHandPlugin.java | 4 ++-- .../srendi/advancedperipherals/common/setup/APBlocks.java | 1 + .../advancedperipherals/common/util/HitResultUtil.java | 7 +++---- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/gradle.properties b/gradle.properties index 46521f01d..65a8bbf08 100644 --- a/gradle.properties +++ b/gradle.properties @@ -40,7 +40,7 @@ multipiston_version=1.19.3-1.2.26-ALPHA flywheel_version=0.6.8.a-1 # Mod dependencies for testing stuff(Only used in the dev environment) -jei_version=1.19.3-forge:12.3.0.18 +jei_version=1.19.3-forge:12.4.0.22 # Credentials for the intelligence repository spaceUsername = Srendi diff --git a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java index 4a487e1e6..0d70896d3 100644 --- a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java +++ b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java @@ -51,7 +51,6 @@ public static ResourceLocation getRL(String resource) { } public void commonSetup(FMLCommonSetupEvent event) { - APAddons.commonSetup(); event.enqueueWork(() -> { PacketHandler.init(); }); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java b/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java index 99eb16e23..4630988df 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java @@ -31,7 +31,7 @@ public class APAddons { public static boolean appliedEnergisticsLoaded; public static boolean mekanismLoaded; - public static void commonSetup() { + static { ModList modList = ModList.get(); curiosLoaded = modList.isLoaded(CURIOS_MODID); refinedStorageLoaded = modList.isLoaded(REFINEDSTORAGE_MODID); @@ -41,7 +41,6 @@ public static void commonSetup() { if (refinedStorageLoaded) RefinedStorage.instance = new RefinedStorage(); - } @SubscribeEvent diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeItemHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeItemHandler.java index 5f8e7e89e..f91644748 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeItemHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeItemHandler.java @@ -45,7 +45,9 @@ public ItemStack extractItem(ItemFilter filter, boolean simulate) { return ItemStack.EMPTY; long extracted = storageMonitor.extract(itemKey.getRight(), filter.getCount(), simulate ? Actionable.SIMULATE : Actionable.MODULATE, actionSource); // Safe to cast here, the amount will never be higher than 64 - return new ItemStack(itemKey.getRight().getItem(), (int) extracted); + ItemStack stack = itemKey.getRight().toStack(); + stack.setCount((int) extracted); + return stack; } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java index f4022a219..80e977443 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java @@ -34,11 +34,11 @@ public final MethodResult digBlock() throws LuaException { int previousDamageValue = selectedTool.getDamageValue(); Pair result = owner.withPlayer(apFakePlayer -> apFakePlayer.digBlock(owner.getFacing().getOpposite())); if (!result.getLeft()) { - return MethodResult.of(null, result.getRight()); + return MethodResult.of(false, result.getRight()); } if (automataCore.hasAttribute(AutomataCorePeripheral.ATTR_STORING_TOOL_DURABILITY)) selectedTool.setDamageValue(previousDamageValue); - return MethodResult.of(true); + return MethodResult.of(true, result.getRight()); }); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java index c875e077a..78fd013a0 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java @@ -1,5 +1,6 @@ package de.srendi.advancedperipherals.common.setup; +import de.srendi.advancedperipherals.common.addons.APAddons; import de.srendi.advancedperipherals.common.blocks.PlayerDetectorBlock; import de.srendi.advancedperipherals.common.blocks.RedstoneIntegratorBlock; import de.srendi.advancedperipherals.common.blocks.base.APBlockEntityBlock; diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java index 96bdfbb2b..1a9508a1e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java @@ -27,7 +27,7 @@ public class HitResultUtil { * @param from the source position like a block * @param level the level * @param ignoreTransparent if transparent blocks should be ignored - * @return the hit result {@link BlockHitResult#miss(Vec3, Direction, BlockPos)} if nothing found + * @return the hit result. {@link BlockHitResult#miss(Vec3, Direction, BlockPos)} if nothing found */ @NotNull public static HitResult getHitResult(Vec3 to, Vec3 from, Level level, boolean ignoreTransparent) { @@ -41,7 +41,7 @@ public static HitResult getHitResult(Vec3 to, Vec3 from, Level level, boolean ig return blockResult; if (entityResult.getType() == HitResult.Type.MISS && blockResult.getType() == HitResult.Type.MISS) - return BlockHitResult.miss(from, null, new BlockPos(to)); + return BlockHitResult.miss(from, blockResult.getDirection(), new BlockPos(to)); double blockDistance = new BlockPos(from).distManhattan(blockResult.getBlockPos()); double entityDistance = new BlockPos(from).distManhattan(new Vec3i(entityResult.getLocation().x, entityResult.getLocation().y, entityResult.getLocation().z)); @@ -103,8 +103,7 @@ public static EntityHitResult getEntityHitResult(Vec3 to, Vec3 from, Level level */ @NotNull public static BlockHitResult getBlockHitResult(Vec3 to, Vec3 from, Level level, boolean ignoreNoOccluded) { - BlockHitResult result = level.clip(new AdvancecClipContext(from, to, ignoreNoOccluded ? IgnoreNoOccludedContext.INSTANCE : ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, null)); - return result; + return level.clip(new AdvancecClipContext(from, to, ignoreNoOccluded ? IgnoreNoOccludedContext.INSTANCE : ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, null)); } public static class EmptyEntityHitResult extends EntityHitResult { From 147968f2eb6c0e8362631bedb529c737a7199e5b Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 14 Apr 2023 22:34:21 +0200 Subject: [PATCH 039/228] Fixed some compiling issues --- .../java/de/srendi/advancedperipherals/AdvancedPeripherals.java | 1 - .../common/addons/botania/ManaPoolIntegration.java | 2 +- .../common/addons/refinedstorage/RsItemHandler.java | 2 +- .../de/srendi/advancedperipherals/common/setup/APBlocks.java | 1 - .../common/util/fakeplayer/FakePlayerProviderTurtle.java | 2 +- 5 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java index 0d70896d3..5884a4eb9 100644 --- a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java +++ b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java @@ -1,6 +1,5 @@ package de.srendi.advancedperipherals; -import de.srendi.advancedperipherals.common.addons.APAddons; import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.network.PacketHandler; import de.srendi.advancedperipherals.common.setup.APRegistration; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaPoolIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaPoolIntegration.java index 28500bd2f..cea44bbe9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaPoolIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaPoolIntegration.java @@ -25,7 +25,7 @@ public final int getMana() { @LuaFunction(mainThread = true) public final int getMaxMana() { - return blockEntity.manaCap; + return blockEntity.getMaxMana(); } @LuaFunction(mainThread = true) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java index b688873f2..6d5d9665e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java @@ -33,7 +33,7 @@ public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate public ItemStack extractItem(ItemFilter filter, boolean simulate) { ItemStack item = RefinedStorage.findStackFromFilter(network, network.getCraftingManager(), filter); if (item == null) - AdvancedPeripherals.debug("Trying to extract item: " + item + " from filter: " + filter); + AdvancedPeripherals.debug("Trying to extract item: " + item + " from filter: " + filter); if(item == null) return ItemStack.EMPTY; ItemStack extracted = network.extractItem(item, filter.getCount(), IComparer.COMPARE_NBT, simulate ? Action.SIMULATE : Action.PERFORM); diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java index 78fd013a0..c875e077a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java @@ -1,6 +1,5 @@ package de.srendi.advancedperipherals.common.setup; -import de.srendi.advancedperipherals.common.addons.APAddons; import de.srendi.advancedperipherals.common.blocks.PlayerDetectorBlock; import de.srendi.advancedperipherals.common.blocks.RedstoneIntegratorBlock; import de.srendi.advancedperipherals.common.blocks.base.APBlockEntityBlock; diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/FakePlayerProviderTurtle.java b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/FakePlayerProviderTurtle.java index b3488d3b7..1923bdaaf 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/FakePlayerProviderTurtle.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/FakePlayerProviderTurtle.java @@ -94,7 +94,7 @@ public static void unload(APFakePlayer player, ITurtleAccess turtle) { remaining = InventoryUtil.storeItemsFromOffset(turtleInventory, remaining, 0); if (!remaining.isEmpty()) { BlockPos position = turtle.getPosition(); - WorldUtil.dropItemStack(turtle.getLevel(), position, turtle.getDirection().getOpposite(), remaining); + WorldUtil.dropItemStack(remaining, turtle.getLevel(), position, turtle.getDirection().getOpposite()); } } From 568e337825d9fe772fa233b44e4b6dda741ac17a Mon Sep 17 00:00:00 2001 From: Srendi Date: Sat, 15 Apr 2023 00:48:45 +0200 Subject: [PATCH 040/228] More context please --- gradle.properties | 2 +- .../common/smartglasses/modules/IModule.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 834a7bf62..f1417bdb5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -42,7 +42,7 @@ multipiston_version=1.19.3-1.2.26-ALPHA flywheel_version=0.6.8.a-1 # Mod dependencies for testing stuff(Only used in the dev environment) -jei_version=1.19.3-forge:12.1.1.13 +jei_version=1.19.3-forge:12.4.0.22 # Credentials for the intelligence repository spaceUsername = Srendi diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java index c30f0cc54..2a1021807 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java @@ -12,7 +12,7 @@ public interface IModule { * * @return an object containing lua functions {@link dan200.computercraft.api.lua.LuaFunction} */ - IModuleFunctions getMethods(); + IModuleFunctions getMethods(SmartGlassesAccess smartGlassesAccess); void tick(SmartGlassesAccess smartGlassesAccess); From 1e21135fa60bf462867f3b2cb93289ded419e7a8 Mon Sep 17 00:00:00 2001 From: srendi Date: Thu, 20 Apr 2023 21:02:49 +0200 Subject: [PATCH 041/228] Unify the rs and me bridge methods by using an interface. Adds more functions and makes the ME and RS Bridge work the same --- .../peripheral/MeBridgePeripheral.java | 427 ++++++++++-------- .../inventory}/IStoragePeripheral.java | 55 ++- 2 files changed, 290 insertions(+), 192 deletions(-) rename src/main/java/de/srendi/advancedperipherals/common/{addons/base => util/inventory}/IStoragePeripheral.java (64%) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java index ffd05f252..eaaad7351 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java @@ -21,10 +21,7 @@ import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.util.Pair; import de.srendi.advancedperipherals.common.util.ServerWorker; -import de.srendi.advancedperipherals.common.util.inventory.FluidFilter; -import de.srendi.advancedperipherals.common.util.inventory.FluidUtil; -import de.srendi.advancedperipherals.common.util.inventory.InventoryUtil; -import de.srendi.advancedperipherals.common.util.inventory.ItemFilter; +import de.srendi.advancedperipherals.common.util.inventory.*; import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.items.IItemHandler; @@ -35,7 +32,7 @@ import java.util.List; import java.util.Objects; -public class MeBridgePeripheral extends BasePeripheral> { +public class MeBridgePeripheral extends BasePeripheral> implements IStoragePeripheral { public static final String PERIPHERAL_TYPE = "meBridge"; private final MeBridgeEntity tile; @@ -136,317 +133,373 @@ private MethodResult notConnected() { return MethodResult.of(null, "NOT_CONNECTED"); } - @LuaFunction(mainThread = true) - public final boolean isConnected() { + private boolean isAvailable() { return node.getGrid() != null && node.hasGridBooted(); } - @LuaFunction - public final MethodResult craftItem(IComputerAccess computer, IArguments arguments) throws LuaException { - if (!isConnected()) + @Override + public final MethodResult isConnected() { + return MethodResult.of(isAvailable()); + } + + @Override + public MethodResult isOnline() { + return MethodResult.of(node.isOnline()); + } + + @Override + public final MethodResult getItem(IArguments arguments) throws LuaException { + if (!isAvailable()) return notConnected(); + MEStorage monitor = AppEngApi.getMonitor(node); Pair filter = ItemFilter.parse(arguments.getTable(0)); if (filter.rightPresent()) - return MethodResult.of(false, filter.getRight()); + return MethodResult.of(null, filter.getRight()); ItemFilter parsedFilter = filter.getLeft(); if (parsedFilter.isEmpty()) - return MethodResult.of(false, "EMPTY_FILTER"); - - String cpuName = arguments.optString(1, ""); - ICraftingCPU target = getCraftingCPU(cpuName); - if (!cpuName.isEmpty() && target == null) - return MethodResult.of(false, "CPU " + cpuName + " does not exists"); + return MethodResult.of(null, "EMPTY_FILTER"); - ICraftingService craftingGrid = node.getGrid().getService(ICraftingService.class); - Pair stack = AppEngApi.findAEStackFromFilter(AppEngApi.getMonitor(tile.getGridNode()), craftingGrid, filter.getLeft()); - if (stack.getRight() == null && stack.getLeft() == 0) - return MethodResult.of(null, "NOT_CRAFTABLE"); + return MethodResult.of(AppEngApi.getObjectFromStack(AppEngApi.findAEStackFromFilter(monitor, getCraftingService(), parsedFilter), getCraftingService())); + } - CraftJob job = new CraftJob(owner.getLevel(), computer, node, stack.getRight(), parsedFilter.getCount(), tile, tile, target); - tile.addJob(job); - ServerWorker.add(job::startCrafting); - return MethodResult.of(true); + @Override + public MethodResult getFluid(IArguments arguments) throws LuaException { + return null; } - @LuaFunction - public final MethodResult craftFluid(IComputerAccess computer, IArguments arguments) throws LuaException { - if (!isConnected()) + @Override + public final MethodResult listItems() { + if (!isAvailable()) return notConnected(); - Pair filter = FluidFilter.parse(arguments.getTable(0)); - if(filter.rightPresent()) - return MethodResult.of(false, filter.getRight()); - - FluidFilter parsedFilter = filter.getLeft(); - if (parsedFilter.isEmpty()) - return MethodResult.of(false, "EMPTY_FILTER"); - - String cpuName = arguments.optString(1, ""); - ICraftingCPU target = getCraftingCPU(cpuName); - if(!cpuName.isEmpty() && target == null) - return MethodResult.of(false, "CPU " + cpuName + " does not exists"); - - ICraftingService craftingGrid = node.getGrid().getService(ICraftingService.class); - Pair stack = AppEngApi.findAEFluidFromFilter(AppEngApi.getMonitor(tile.getGridNode()), craftingGrid, filter.getLeft()); - if (stack.getRight() == null && stack.getLeft() == 0) - return MethodResult.of(null, "NOT_CRAFTABLE"); - - CraftJob job = new CraftJob(owner.getLevel(), computer, node, stack.getRight(), parsedFilter.getCount(), tile, tile, target); - tile.addJob(job); - ServerWorker.add(job::startCrafting); - return MethodResult.of(true); + return MethodResult.of(AppEngApi.listStacks(AppEngApi.getMonitor(node), getCraftingService(), 0)); } - @LuaFunction(mainThread = true) - public final MethodResult getEnergyUsage() { - if (!isConnected()) + @Override + public final MethodResult listFluids() { + if (!isAvailable()) return notConnected(); - return MethodResult.of(node.getGrid().getEnergyService().getAvgPowerUsage()); + return MethodResult.of(AppEngApi.listFluids(AppEngApi.getMonitor(node), getCraftingService(), 0)); } - @LuaFunction(mainThread = true) - public final MethodResult getEnergyStorage() { - if (!isConnected()) + @Override + public final MethodResult listCraftableItems() { + if (!isAvailable()) return notConnected(); - return MethodResult.of(node.getGrid().getEnergyService().getStoredPower()); + return MethodResult.of(AppEngApi.listStacks(AppEngApi.getMonitor(node), getCraftingService(), 2)); } - @LuaFunction(mainThread = true) - public final MethodResult getAvgPowerUsage() { - if (!isConnected()) + @Override + public final MethodResult listCraftableFluids() { + if (!isAvailable()) return notConnected(); - return MethodResult.of(node.getGrid().getEnergyService().getAvgPowerUsage()); + return MethodResult.of(AppEngApi.listFluids(AppEngApi.getMonitor(node), getCraftingService(), 2)); } - @LuaFunction(mainThread = true) - public final MethodResult getAvgPowerInjection() { - if (!isConnected()) + @Override + public final MethodResult listCells() { + if (!isAvailable()) return notConnected(); - return MethodResult.of(node.getGrid().getEnergyService().getAvgPowerInjection()); + return MethodResult.of(AppEngApi.listCells(node)); } - - @LuaFunction(mainThread = true) - public final MethodResult getMaxEnergyStorage() { - if (!isConnected()) + @Override + public final MethodResult importItem(IArguments arguments) throws LuaException { + if (!isAvailable()) return notConnected(); - return MethodResult.of(node.getGrid().getEnergyService().getMaxStoredPower()); + IItemHandler inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); + return importToME(arguments, inventory); } - @LuaFunction(mainThread = true) - public final MethodResult isItemCrafting(IArguments arguments) throws LuaException { - if (!isConnected()) + @Override + public final MethodResult exportItem(@NotNull IArguments arguments) throws LuaException { + if (!isAvailable()) return notConnected(); - MEStorage monitor = AppEngApi.getMonitor(node); - ICraftingService grid = node.getGrid().getService(ICraftingService.class); - - Pair filter = ItemFilter.parse(arguments.getTable(0)); - if (filter.rightPresent()) - return MethodResult.of(false, filter.getRight()); - - ItemFilter parsedFilter = filter.getLeft(); - if (parsedFilter.isEmpty()) - return MethodResult.of(false, "EMPTY_FILTER"); - String cpuName = arguments.optString(1, ""); - ICraftingCPU craftingCPU = getCraftingCPU(cpuName); - - return MethodResult.of(AppEngApi.isItemCrafting(monitor, grid, parsedFilter, craftingCPU)); + IItemHandler inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); + return exportToChest(arguments, inventory); } - @LuaFunction(mainThread = true) - public final MethodResult isItemCraftable(IArguments arguments) throws LuaException { - if (!isConnected()) + @Override + public final MethodResult importItemFromPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { + if (!isAvailable()) return notConnected(); - Pair filter = ItemFilter.parse(arguments.getTable(0)); - if (filter.rightPresent()) - return MethodResult.of(false, filter.getRight()); + IItemHandler inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); + return importToME(arguments, inventory); + } - ItemFilter parsedFilter = filter.getLeft(); - if (parsedFilter.isEmpty()) - return MethodResult.of(false, "EMPTY_FILTER"); + @Override + public final MethodResult exportItemToPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { + if (!isAvailable()) + return notConnected(); - AEItemKey item = AEItemKey.of(parsedFilter.toItemStack()); + IItemHandler inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); + return exportToChest(arguments, inventory); + } - return MethodResult.of(getCraftingService().isCraftable(item)); + @Override + public final MethodResult importFluid(IArguments arguments) throws LuaException { + IFluidHandler handler = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); + return importToME(arguments, handler); } - @LuaFunction(mainThread = true) + @Override public final MethodResult exportFluid(@NotNull IArguments arguments) throws LuaException { IFluidHandler handler = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); return exportToTank(arguments, handler); } - @LuaFunction(mainThread = true) - public final MethodResult exportFluidToPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { + @Override + public final MethodResult importFluidFromPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { IFluidHandler handler = FluidUtil.getHandlerFromName(computer, arguments.getString(1)); - return exportToTank(arguments, handler); - } - - @LuaFunction(mainThread = true) - public final MethodResult importFluid(IArguments arguments) throws LuaException { - IFluidHandler handler = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); return importToME(arguments, handler); } - @LuaFunction(mainThread = true) - public final MethodResult importFluidFromPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { + @Override + public final MethodResult exportFluidToPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { IFluidHandler handler = FluidUtil.getHandlerFromName(computer, arguments.getString(1)); - return importToME(arguments, handler); + return exportToTank(arguments, handler); } - @LuaFunction(mainThread = true) - public final MethodResult exportItem(@NotNull IArguments arguments) throws LuaException { - if (!isConnected()) - return notConnected(); - - IItemHandler inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); - return exportToChest(arguments, inventory); + @Override + public MethodResult getPattern(IArguments arguments) throws LuaException { + return null; } - @LuaFunction(mainThread = true) - public final MethodResult exportItemToPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { - if (!isConnected()) - return notConnected(); - - IItemHandler inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); - return exportToChest(arguments, inventory); + @Override + public MethodResult getPatterns() { + return null; } - @LuaFunction(mainThread = true) - public final MethodResult importItem(IArguments arguments) throws LuaException { - if (!isConnected()) + @Override + public final MethodResult getStoredEnergy() { + if (!isAvailable()) return notConnected(); - IItemHandler inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); - return importToME(arguments, inventory); + return MethodResult.of(node.getGrid().getEnergyService().getStoredPower()); } - @LuaFunction(mainThread = true) - public final MethodResult importItemFromPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { - if (!isConnected()) + @Override + public final MethodResult getEnergyCapacity() { + if (!isAvailable()) return notConnected(); - IItemHandler inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); - return importToME(arguments, inventory); + return MethodResult.of(node.getGrid().getEnergyService().getMaxStoredPower()); } - @LuaFunction(mainThread = true) - public final MethodResult getItem(IArguments arguments) throws LuaException { - if (!isConnected()) + @Override + public final MethodResult getEnergyUsage() { + if (!isAvailable()) return notConnected(); - MEStorage monitor = AppEngApi.getMonitor(node); - Pair filter = ItemFilter.parse(arguments.getTable(0)); - if (filter.rightPresent()) - return MethodResult.of(null, filter.getRight()); - - ItemFilter parsedFilter = filter.getLeft(); - if (parsedFilter.isEmpty()) - return MethodResult.of(null, "EMPTY_FILTER"); - - return MethodResult.of(AppEngApi.getObjectFromStack(AppEngApi.findAEStackFromFilter(monitor, getCraftingService(), parsedFilter), getCraftingService())); + return MethodResult.of(node.getGrid().getEnergyService().getAvgPowerUsage()); } @LuaFunction(mainThread = true) - public final MethodResult listItems() { - if (!isConnected()) + public final MethodResult getAvgPowerInjection() { + if (!isAvailable()) return notConnected(); - return MethodResult.of(AppEngApi.listStacks(AppEngApi.getMonitor(node), getCraftingService(), 0)); + return MethodResult.of(node.getGrid().getEnergyService().getAvgPowerInjection()); } - @LuaFunction(mainThread = true) - public final MethodResult listCraftableItems() { - if (!isConnected()) - return notConnected(); - - return MethodResult.of(AppEngApi.listStacks(AppEngApi.getMonitor(node), getCraftingService(), 2)); + @Override + public MethodResult getTotalExternItemStorage() { + return null; } - @LuaFunction(mainThread = true) - public final MethodResult listFluid() { - if (!isConnected()) - return notConnected(); - - return MethodResult.of(AppEngApi.listFluids(AppEngApi.getMonitor(node), getCraftingService(), 0)); + @Override + public MethodResult getTotalExternFluidStorage() { + return null; } - @LuaFunction(mainThread = true) - public final MethodResult listCraftableFluid() { - if (!isConnected()) - return notConnected(); - - return MethodResult.of(AppEngApi.listFluids(AppEngApi.getMonitor(node), getCraftingService(), 2)); - } - @LuaFunction(mainThread = true) + @Override public final MethodResult getTotalItemStorage() { - if (!isConnected()) + if (!isAvailable()) return notConnected(); return MethodResult.of(AppEngApi.getTotalItemStorage(node)); } - @LuaFunction(mainThread = true) + @Override public final MethodResult getTotalFluidStorage() { - if (!isConnected()) + if (!isAvailable()) return notConnected(); return MethodResult.of(AppEngApi.getTotalFluidStorage(node)); } - @LuaFunction(mainThread = true) + @Override + public MethodResult getUsedExternItemStorage() { + return null; + } + + @Override + public MethodResult getUsedExternFluidStorage() { + return null; + } + + @Override public final MethodResult getUsedItemStorage() { - if (!isConnected()) + if (!isAvailable()) return notConnected(); return MethodResult.of(AppEngApi.getUsedItemStorage(node)); } - @LuaFunction(mainThread = true) + @Override public final MethodResult getUsedFluidStorage() { - if (!isConnected()) + if (!isAvailable()) return notConnected(); return MethodResult.of(AppEngApi.getUsedFluidStorage(node)); } - @LuaFunction(mainThread = true) + @Override + public MethodResult getAvailableExternItemStorage() { + return null; + } + + @Override + public MethodResult getAvailableExternFluidStorage() { + return null; + } + + @Override public final MethodResult getAvailableItemStorage() { - if (!isConnected()) + if (!isAvailable()) return notConnected(); return MethodResult.of(AppEngApi.getAvailableItemStorage(node)); } - @LuaFunction(mainThread = true) + @Override public final MethodResult getAvailableFluidStorage() { - if (!isConnected()) + if (!isAvailable()) return notConnected(); return MethodResult.of(AppEngApi.getAvailableFluidStorage(node)); } - @LuaFunction(mainThread = true) - public final MethodResult listCells() { - if (!isConnected()) + @Override + public final MethodResult craftItem(IComputerAccess computer, IArguments arguments) throws LuaException { + if (!isAvailable()) return notConnected(); - return MethodResult.of(AppEngApi.listCells(node)); + Pair filter = ItemFilter.parse(arguments.getTable(0)); + if (filter.rightPresent()) + return MethodResult.of(false, filter.getRight()); + + ItemFilter parsedFilter = filter.getLeft(); + if (parsedFilter.isEmpty()) + return MethodResult.of(false, "EMPTY_FILTER"); + + String cpuName = arguments.optString(1, ""); + ICraftingCPU target = getCraftingCPU(cpuName); + if (!cpuName.isEmpty() && target == null) + return MethodResult.of(false, "CPU " + cpuName + " does not exists"); + + ICraftingService craftingGrid = node.getGrid().getService(ICraftingService.class); + Pair stack = AppEngApi.findAEStackFromFilter(AppEngApi.getMonitor(tile.getGridNode()), craftingGrid, filter.getLeft()); + if (stack.getRight() == null && stack.getLeft() == 0) + return MethodResult.of(null, "NOT_CRAFTABLE"); + + CraftJob job = new CraftJob(owner.getLevel(), computer, node, stack.getRight(), parsedFilter.getCount(), tile, tile, target); + tile.addJob(job); + ServerWorker.add(job::startCrafting); + return MethodResult.of(true); + } + + @Override + public final MethodResult craftFluid(IComputerAccess computer, IArguments arguments) throws LuaException { + if (!isAvailable()) + return notConnected(); + + Pair filter = FluidFilter.parse(arguments.getTable(0)); + if (filter.rightPresent()) + return MethodResult.of(false, filter.getRight()); + + FluidFilter parsedFilter = filter.getLeft(); + if (parsedFilter.isEmpty()) + return MethodResult.of(false, "EMPTY_FILTER"); + + String cpuName = arguments.optString(1, ""); + ICraftingCPU target = getCraftingCPU(cpuName); + if (!cpuName.isEmpty() && target == null) + return MethodResult.of(false, "CPU " + cpuName + " does not exists"); + + ICraftingService craftingGrid = node.getGrid().getService(ICraftingService.class); + Pair stack = AppEngApi.findAEFluidFromFilter(AppEngApi.getMonitor(tile.getGridNode()), craftingGrid, filter.getLeft()); + if (stack.getRight() == null && stack.getLeft() == 0) + return MethodResult.of(null, "NOT_CRAFTABLE"); + + CraftJob job = new CraftJob(owner.getLevel(), computer, node, stack.getRight(), parsedFilter.getCount(), tile, tile, target); + tile.addJob(job); + ServerWorker.add(job::startCrafting); + return MethodResult.of(true); + } + + @Override + public final MethodResult isItemCraftable(IArguments arguments) throws LuaException { + if (!isAvailable()) + return notConnected(); + + Pair filter = ItemFilter.parse(arguments.getTable(0)); + if (filter.rightPresent()) + return MethodResult.of(false, filter.getRight()); + + ItemFilter parsedFilter = filter.getLeft(); + if (parsedFilter.isEmpty()) + return MethodResult.of(false, "EMPTY_FILTER"); + + AEItemKey item = AEItemKey.of(parsedFilter.toItemStack()); + + return MethodResult.of(getCraftingService().isCraftable(item)); + } + + @Override + public final MethodResult isItemCrafting(IArguments arguments) throws LuaException { + if (!isAvailable()) + return notConnected(); + + MEStorage monitor = AppEngApi.getMonitor(node); + ICraftingService grid = node.getGrid().getService(ICraftingService.class); + + Pair filter = ItemFilter.parse(arguments.getTable(0)); + if (filter.rightPresent()) + return MethodResult.of(false, filter.getRight()); + + ItemFilter parsedFilter = filter.getLeft(); + if (parsedFilter.isEmpty()) + return MethodResult.of(false, "EMPTY_FILTER"); + String cpuName = arguments.optString(1, ""); + ICraftingCPU craftingCPU = getCraftingCPU(cpuName); + + return MethodResult.of(AppEngApi.isItemCrafting(monitor, grid, parsedFilter, craftingCPU)); + } + + @Override + public MethodResult isFluidCraftable(IArguments arguments) throws LuaException { + return null; + } + + @Override + public MethodResult isFluidCrafting(IArguments arguments) throws LuaException { + return null; } @LuaFunction(mainThread = true) public final MethodResult getCraftingCPUs() throws LuaException { - if (!isConnected()) + if (!isAvailable()) return notConnected(); ICraftingService grid = node.getGrid().getService(ICraftingService.class); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/base/IStoragePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStoragePeripheral.java similarity index 64% rename from src/main/java/de/srendi/advancedperipherals/common/addons/base/IStoragePeripheral.java rename to src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStoragePeripheral.java index 339c5b18c..c1c45d3e5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/base/IStoragePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStoragePeripheral.java @@ -1,4 +1,4 @@ -package de.srendi.advancedperipherals.common.addons.base; +package de.srendi.advancedperipherals.common.util.inventory; import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.LuaException; @@ -40,6 +40,9 @@ public interface IStoragePeripheral { @LuaFunction(mainThread = true) MethodResult listCraftableFluids(); + @LuaFunction + MethodResult listCells(); + @LuaFunction(mainThread = true) MethodResult importItem(IArguments arguments) throws LuaException; @@ -52,6 +55,18 @@ public interface IStoragePeripheral { @LuaFunction(mainThread = true) MethodResult exportItemToPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException; + @LuaFunction(mainThread = true) + MethodResult importFluid(IArguments arguments) throws LuaException; + + @LuaFunction(mainThread = true) + MethodResult exportFluid(IArguments arguments) throws LuaException; + + @LuaFunction(mainThread = true) + MethodResult importFluidFromPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException; + + @LuaFunction(mainThread = true) + MethodResult exportFluidToPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException; + @LuaFunction(mainThread = true) MethodResult getPattern(IArguments arguments) throws LuaException; @@ -68,16 +83,40 @@ public interface IStoragePeripheral { MethodResult getEnergyUsage(); @LuaFunction(mainThread = true) - MethodResult getMaxItemExternalStorage(); + MethodResult getTotalExternItemStorage(); + + @LuaFunction(mainThread = true) + MethodResult getTotalExternFluidStorage(); + + @LuaFunction(mainThread = true) + MethodResult getTotalItemStorage(); + + @LuaFunction(mainThread = true) + MethodResult getTotalFluidStorage(); @LuaFunction(mainThread = true) - MethodResult getMaxFluidExternalStorage(); + MethodResult getUsedExternItemStorage(); @LuaFunction(mainThread = true) - MethodResult getMaxItemDiskStorage(); + MethodResult getUsedExternFluidStorage(); @LuaFunction(mainThread = true) - MethodResult getMaxFluidDiskStorage(); + MethodResult getUsedItemStorage(); + + @LuaFunction(mainThread = true) + MethodResult getUsedFluidStorage(); + + @LuaFunction(mainThread = true) + MethodResult getAvailableExternItemStorage(); + + @LuaFunction(mainThread = true) + MethodResult getAvailableExternFluidStorage(); + + @LuaFunction(mainThread = true) + MethodResult getAvailableItemStorage(); + + @LuaFunction(mainThread = true) + MethodResult getAvailableFluidStorage(); @LuaFunction(mainThread = true) MethodResult craftItem(IComputerAccess computer, IArguments arguments) throws LuaException; @@ -91,4 +130,10 @@ public interface IStoragePeripheral { @LuaFunction(mainThread = true) MethodResult isItemCrafting(IArguments arguments) throws LuaException; + @LuaFunction(mainThread = true) + MethodResult isFluidCraftable(IArguments arguments) throws LuaException; + + @LuaFunction(mainThread = true) + MethodResult isFluidCrafting(IArguments arguments) throws LuaException; + } From 6182229574c6bfa6376fe6a31d2f2b09bced162b Mon Sep 17 00:00:00 2001 From: srendi Date: Thu, 20 Apr 2023 21:26:15 +0200 Subject: [PATCH 042/228] Do the same for the rs bridge. --- .../peripheral/RsBridgePeripheral.java | 213 ++++++++++++------ 1 file changed, 142 insertions(+), 71 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java index c01d2cb8f..9a48dd853 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java @@ -2,11 +2,9 @@ import com.refinedmods.refinedstorage.api.autocrafting.task.CalculationResultType; import com.refinedmods.refinedstorage.api.autocrafting.task.ICalculationResult; -import com.refinedmods.refinedstorage.api.autocrafting.task.ICraftingTask; import com.refinedmods.refinedstorage.api.network.INetwork; import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.LuaException; -import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.lua.MethodResult; import dan200.computercraft.api.peripheral.IComputerAccess; import de.srendi.advancedperipherals.AdvancedPeripherals; @@ -20,19 +18,17 @@ import de.srendi.advancedperipherals.common.util.Pair; import de.srendi.advancedperipherals.common.util.inventory.*; import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.registries.ForgeRegistries; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; -public class RsBridgePeripheral extends BasePeripheral> { +public class RsBridgePeripheral extends BasePeripheral> implements IStoragePeripheral { public static final String PERIPHERAL_TYPE = "rsBridge"; @@ -52,27 +48,37 @@ private MethodResult notConnected() { return MethodResult.of(null, "NOT_CONNECTED"); } + private boolean isAvailable() { + return getNetwork() != null; + } + + @Override + public final MethodResult isConnected() { + return MethodResult.of(isAvailable()); + } + + @Override + public MethodResult isOnline() { + // Is there a more proper method? + return MethodResult.of(getNode().isActive()); + } @Override public boolean isEnabled() { return APConfig.PERIPHERALS_CONFIG.enableRSBridge.get(); } - @LuaFunction(mainThread = true) - public final boolean isConnected() { - return getNetwork() != null; - } - @LuaFunction(mainThread = true) + @Override public final MethodResult listItems() { - if (!isConnected()) + if (!isAvailable()) return notConnected(); return MethodResult.of(RefinedStorage.listItems(getNetwork())); } - @LuaFunction(mainThread = true) + @Override public final MethodResult listCraftableItems() { - if (!isConnected()) + if (!isAvailable()) return notConnected(); List items = new ArrayList<>(); @@ -80,9 +86,9 @@ public final MethodResult listCraftableItems() { return MethodResult.of(items); } - @LuaFunction(mainThread = true) - public final Object listCraftableFluids() { - if (!isConnected()) + @Override + public final MethodResult listCraftableFluids() { + if (!isAvailable()) return notConnected(); List fluids = new ArrayList<>(); @@ -90,73 +96,118 @@ public final Object listCraftableFluids() { return MethodResult.of(fluids); } - @LuaFunction(mainThread = true) - public final MethodResult getMaxItemDiskStorage() { - if (!isConnected()) + @Override + public MethodResult listCells() { + return null; + } + + @Override + public final MethodResult getTotalItemStorage() { + if (!isAvailable()) return notConnected(); return MethodResult.of(RefinedStorage.getMaxItemDiskStorage(getNetwork())); } - @LuaFunction(mainThread = true) - public final MethodResult getMaxFluidDiskStorage() { - if (!isConnected()) + @Override + public final MethodResult getTotalFluidStorage() { + if (!isAvailable()) return notConnected(); return MethodResult.of(RefinedStorage.getMaxFluidDiskStorage(getNetwork())); } - @LuaFunction(mainThread = true) - public final MethodResult getMaxItemExternalStorage() { - if (!isConnected()) + @Override + public MethodResult getUsedExternItemStorage() { + return null; + } + + @Override + public MethodResult getUsedExternFluidStorage() { + return null; + } + + @Override + public MethodResult getUsedItemStorage() { + return null; + } + + @Override + public MethodResult getUsedFluidStorage() { + return null; + } + + @Override + public MethodResult getAvailableExternItemStorage() { + return null; + } + + @Override + public MethodResult getAvailableExternFluidStorage() { + return null; + } + + @Override + public MethodResult getAvailableItemStorage() { + return null; + } + + @Override + public MethodResult getAvailableFluidStorage() { + return null; + } + + @Override + public final MethodResult getTotalExternItemStorage() { + if (!isAvailable()) return notConnected(); return MethodResult.of(RefinedStorage.getMaxItemExternalStorage(getNetwork())); } - @LuaFunction(mainThread = true) - public final MethodResult getMaxFluidExternalStorage() { - if (!isConnected()) + @Override + public final MethodResult getTotalExternFluidStorage() { + if (!isAvailable()) return notConnected(); return MethodResult.of(RefinedStorage.getMaxFluidExternalStorage(getNetwork())); } - @LuaFunction(mainThread = true) + @Override public final MethodResult listFluids() { - if (!isConnected()) + if (!isAvailable()) return notConnected(); return MethodResult.of(RefinedStorage.listFluids(getNetwork())); } - @LuaFunction(mainThread = true) + @Override public final MethodResult getEnergyUsage() { - if (!isConnected()) + if (!isAvailable()) return notConnected(); return MethodResult.of(getNetwork().getEnergyUsage()); } - @LuaFunction(mainThread = true) - public final MethodResult getMaxEnergyStorage() { - if (!isConnected()) + @Override + public final MethodResult getEnergyCapacity() { + if (!isAvailable()) return notConnected(); return MethodResult.of(getNetwork().getEnergyStorage().getMaxEnergyStored()); } - @LuaFunction(mainThread = true) - public final MethodResult getEnergyStorage() { - if (!isConnected()) + @Override + public final MethodResult getStoredEnergy() { + if (!isAvailable()) return notConnected(); return MethodResult.of(getNetwork().getEnergyStorage().getEnergyStored()); } - @LuaFunction(mainThread = true) + @Override public final MethodResult getPattern(IArguments arguments) throws LuaException { - if (!isConnected()) + if (!isAvailable()) return notConnected(); Pair filter = ItemFilter.parse(arguments.getTable(0)); @@ -172,6 +223,11 @@ public final MethodResult getPattern(IArguments arguments) throws LuaException { return MethodResult.of(RefinedStorage.getObjectFromPattern(getNetwork().getCraftingManager().getPattern(patternItem), getNetwork())); } + @Override + public MethodResult getPatterns() { + return null; + } + protected MethodResult exportToChest(@NotNull IArguments arguments, @Nullable IItemHandler targetInventory) throws LuaException { RsItemHandler itemHandler = new RsItemHandler(getNetwork()); if (targetInventory == null) @@ -220,81 +276,81 @@ protected MethodResult importToSystem(@NotNull IArguments arguments, @Nullable I return MethodResult.of(InventoryUtil.moveFluid(targetInventory, itemHandler, filter.getLeft()), null); } - @LuaFunction(mainThread = true) + @Override public final MethodResult exportItem(@NotNull IArguments arguments) throws LuaException { - if (!isConnected()) + if (!isAvailable()) return notConnected(); IItemHandler inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); return exportToChest(arguments, inventory); } - @LuaFunction(mainThread = true) + @Override public final MethodResult exportItemToPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { - if (!isConnected()) + if (!isAvailable()) return notConnected(); IItemHandler inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); return exportToChest(arguments, inventory); } - @LuaFunction(mainThread = true) + @Override public final MethodResult importItem(IArguments arguments) throws LuaException { - if (!isConnected()) + if (!isAvailable()) return notConnected(); IItemHandler inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); return importToSystem(arguments, inventory); } - @LuaFunction(mainThread = true) + @Override public final MethodResult importItemFromPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { - if (!isConnected()) + if (!isAvailable()) return notConnected(); IItemHandler inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); return importToSystem(arguments, inventory); } - @LuaFunction(mainThread = true) + @Override public final MethodResult exportFluid(@NotNull IArguments arguments) throws LuaException { - if (!isConnected()) + if (!isAvailable()) return notConnected(); IFluidHandler inventory = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); return exportToTank(arguments, inventory); } - @LuaFunction(mainThread = true) + @Override public final MethodResult exportFluidToPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { - if (!isConnected()) + if (!isAvailable()) return notConnected(); IFluidHandler inventory = FluidUtil.getHandlerFromName(computer, arguments.getString(1)); return exportToTank(arguments, inventory); } - @LuaFunction(mainThread = true) + @Override public final MethodResult importFluid(IArguments arguments) throws LuaException { - if (!isConnected()) + if (!isAvailable()) return notConnected(); IFluidHandler inventory = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); return importToSystem(arguments, inventory); } - @LuaFunction(mainThread = true) + @Override public final MethodResult importFluidFromPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { - if (!isConnected()) + if (!isAvailable()) return notConnected(); IFluidHandler inventory = FluidUtil.getHandlerFromName(computer, arguments.getString(1)); return importToSystem(arguments, inventory); } - @LuaFunction(mainThread = true) + @Override public final MethodResult getItem(IArguments arguments) throws LuaException { - if (!isConnected()) + if (!isAvailable()) return notConnected(); Pair filter = ItemFilter.parse(arguments.getTable(0)); @@ -304,9 +360,14 @@ public final MethodResult getItem(IArguments arguments) throws LuaException { return MethodResult.of(RefinedStorage.getObjectFromStack(RefinedStorage.findStackFromFilter(getNetwork(), getNetwork().getCraftingManager(), filter.getLeft()), getNetwork())); } - @LuaFunction(mainThread = true) - public final MethodResult craftItem(IArguments arguments) throws LuaException { - if (!isConnected()) + @Override + public MethodResult getFluid(IArguments arguments) throws LuaException { + return null; + } + + @Override + public final MethodResult craftItem(IComputerAccess computerAccess, IArguments arguments) throws LuaException { + if (!isAvailable()) return notConnected(); @@ -326,9 +387,9 @@ public final MethodResult craftItem(IArguments arguments) throws LuaException { return MethodResult.of(type == CalculationResultType.OK); } - @LuaFunction(mainThread = true) - public final MethodResult craftFluid(IArguments arguments, int count) throws LuaException { - if (!isConnected()) + @Override + public final MethodResult craftFluid(IComputerAccess computerAccess, IArguments arguments) throws LuaException { + if (!isAvailable()) return notConnected(); Pair filter = FluidFilter.parse(arguments.getTable(0)); @@ -347,23 +408,33 @@ public final MethodResult craftFluid(IArguments arguments, int count) throws Lua return MethodResult.of(type == CalculationResultType.OK); } - @LuaFunction(mainThread = true) - public final MethodResult isItemCrafting(String item) { - if (!isConnected()) + @Override + public final MethodResult isItemCrafting(IArguments arguments) { + if (!isAvailable()) return notConnected(); - +/* ItemStack stack = new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation(item))); for (ICraftingTask task : getNetwork().getCraftingManager().getTasks()) { ItemStack taskStack = task.getRequested().getItem(); if (taskStack.sameItem(stack)) return MethodResult.of(true); - } + }*/ return MethodResult.of(false); } - @LuaFunction(mainThread = true) + @Override + public MethodResult isFluidCraftable(IArguments arguments) throws LuaException { + return null; + } + + @Override + public MethodResult isFluidCrafting(IArguments arguments) throws LuaException { + return null; + } + + @Override public final MethodResult isItemCraftable(IArguments arguments) throws LuaException { - if (!isConnected()) + if (!isAvailable()) return notConnected(); Pair filter = ItemFilter.parse(arguments.getTable(0)); From 0fba0ab377c1275c86d518e1fb9485d3819a76fe Mon Sep 17 00:00:00 2001 From: Deniz Date: Sat, 17 Jun 2023 23:32:18 +0200 Subject: [PATCH 043/228] I'm casting away --- .../srendi/advancedperipherals/common/util/CoordUtil.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java index aeeb462af..af4c3f493 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java @@ -24,7 +24,7 @@ public static boolean isInRange(@Nullable BlockPos pos, @Nullable Level world, @ return false; range = Math.min(Math.abs(range), APConfig.PERIPHERALS_CONFIG.playerDetMaxRange.get()); - return isPlayerInBlockRange(pos, world, player, (double) range); + return isPlayerInBlockRange(pos, world, player, range); } // To fix issue #439 @@ -38,7 +38,7 @@ private static boolean isPlayerInBlockRange(@NotNull BlockPos pos, @NotNull Leve ey = y; y = tmp; } - double bx = (double)(pos.getX() + 0.5), by = (double)(pos.getY() + 0.5), bz = (double)(pos.getZ() + 0.5); + double bx = pos.getX() + 0.5, by = pos.getY() + 0.5, bz = pos.getZ() + 0.5; return Math.abs(x - bx) <= range && Math.abs(z - bz) <= range && // check both feet position and eye position, and ensure it will work if player is higher than 2 blocks ((y <= by && by <= ey) || Math.min(Math.abs(y - by), Math.abs(ey - by)) <= range); @@ -52,7 +52,7 @@ public static boolean isInRange(@Nullable BlockPos pos, @Nullable Level world, @ x = Math.min(Math.abs(x), APConfig.PERIPHERALS_CONFIG.playerDetMaxRange.get()); y = Math.min(Math.abs(y), APConfig.PERIPHERALS_CONFIG.playerDetMaxRange.get()); z = Math.min(Math.abs(z), APConfig.PERIPHERALS_CONFIG.playerDetMaxRange.get()); - return isPlayerInBlockRangeXYZ(pos, world, player, (double) x, (double) y, (double) z); + return isPlayerInBlockRangeXYZ(pos, world, player, x, y, z); } private static boolean isPlayerInBlockRangeXYZ(@NotNull BlockPos pos, @NotNull Level world, @NotNull Player player, double dx, double dy, double dz) { @@ -65,7 +65,7 @@ private static boolean isPlayerInBlockRangeXYZ(@NotNull BlockPos pos, @NotNull L ey = y; y = tmp; } - double bx = (double)(pos.getX() + 0.5), by = (double)(pos.getY() + 0.5), bz = (double)(pos.getZ() + 0.5); + double bx = pos.getX() + 0.5, by = pos.getY() + 0.5, bz = pos.getZ() + 0.5; return Math.abs(x - bx) <= dx && Math.abs(z - bz) <= dz && ((y <= by && by <= ey) || Math.min(Math.abs(y - by), Math.abs(ey - by)) <= dy); } From 77eabce6402ba8b8545d8969fbd4d049d38bd1f3 Mon Sep 17 00:00:00 2001 From: Deniz Date: Fri, 30 Jun 2023 23:38:36 +0200 Subject: [PATCH 044/228] Port 0.8 pack to 1.19.2 since we do not support 1.19.3 anymore. --- build.gradle | 37 +++--- gradle.properties | 39 +++--- .../advancedperipherals/APCreativeTab.java | 65 ---------- .../AdvancedPeripherals.java | 12 ++ .../client/MetaTurtleUpgradeModeller.java | 6 +- .../renderer/DistanceDetectorRenderer.java | 8 +- .../client/screens/SmartGlassesScreen.java | 22 ++-- .../widgets/SmartGlassesSettingsSwitch.java | 18 ++- .../owner/TurtleFuelAbility.java | 4 +- .../owner/TurtlePeripheralOwner.java | 2 +- .../turtles/TurtleChatBoxUpgrade.java | 4 +- .../addons/create/BasinIntegration.java | 4 +- .../addons/create/BlazeBurnerIntegration.java | 4 +- .../addons/create/FluidTankIntegration.java | 12 +- .../common/addons/create/Integration.java | 20 ++- .../create/MechanicalMixerIntegration.java | 8 +- .../ScrollValueBehaviourIntegration.java | 6 +- .../blockentities/DistanceDetectorEntity.java | 6 +- .../container/SmartGlassesContainer.java | 7 +- .../common/data/BlockLootTables.java | 12 +- .../common/data/BlockLootTablesProvider.java | 23 ++-- .../data/BlockStatesAndModelsProvider.java | 4 +- .../common/data/BlockTagsProvider.java | 26 ++-- .../common/data/DataGenerators.java | 23 ++-- .../common/data/EnUsLanguageProvider.java | 4 +- .../common/data/PocketUpgradesProvider.java | 4 +- .../common/data/PoiTypeProvider.java | 15 +-- .../common/data/RecipesProvider.java | 119 +++++++++--------- .../common/data/TurtleUpgradesProvider.java | 4 +- .../common/items/SmartGlassesItem.java | 12 +- .../network/DistanceDetectorSyncPacket.java | 4 +- .../common/setup/APVillagers.java | 6 +- .../smartglasses/SmartGlassesComputer.java | 7 +- .../fakeplayer/FakePlayerProviderTurtle.java | 11 +- .../common/util/inventory/FluidFilter.java | 4 +- .../common/util/inventory/ItemFilter.java | 6 +- .../common/util/inventory/ItemUtil.java | 10 +- .../common/village/VillageStructures.java | 69 +++++----- .../common/village/VillagerTrades.java | 16 +-- 39 files changed, 286 insertions(+), 377 deletions(-) delete mode 100644 src/main/java/de/srendi/advancedperipherals/APCreativeTab.java diff --git a/build.gradle b/build.gradle index d68f7b41f..6cecbab46 100644 --- a/build.gradle +++ b/build.gradle @@ -257,7 +257,7 @@ dependencies { // Minimal requirements compileOnly "org.jetbrains:annotations:${jb_annotations}" minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" - implementation fg.deobf("cc.tweaked:cc-tweaked-${minecraft_version}-forge:${cc_version}") + implementation fg.deobf("org.squiddev:cc-tweaked-${minecraft_version}:${cc_version}") // Compile-time API required // Ae2 compileOnly fg.deobf("appeng:appliedenergistics2-forge:${appliedenergistics_version}") @@ -267,35 +267,32 @@ dependencies { // Extended requirements // We don't use the api since we need a specific class from mekanism - compileOnly "mekanism:Mekanism:${mekanism_version}" - - // runtimeOnly fg.deobf("mekanism:Mekanism:${mekanism_version}")// core + implementation fg.deobf("mekanism:Mekanism:${mekanism_version}") // Applied Energistics 2 - runtimeOnly fg.deobf("appeng:appliedenergistics2-forge:${appliedenergistics_version}") + implementation fg.deobf("appeng:appliedenergistics2-forge:${appliedenergistics_version}") // Curios - runtimeOnly fg.deobf("top.theillusivec4.curios:curios-forge:${curios_version}") + implementation fg.deobf("top.theillusivec4.curios:curios-forge:${curios_version}") // Refined Storage - compileOnly fg.deobf("com.refinedmods:refinedstorage:${refinedstorage_version}") { + implementation fg.deobf("com.refinedmods:refinedstorage:${refinedstorage_version}") { transitive false } - // AE2 Things - removed until ported - // compileOnly "curse.maven:ae2things-609977:${ae2things_version}-sources" - // runtimeOnly fg.deobf("curse.maven:ae2things-609977:${ae2things_version}-sources") + //AE2 Things + compileOnly fg.deobf("curse.maven:ae2things-609977:${ae2things_version}-sources") + //runtimeOnly fg.deobf("curse.maven:ae2things-609977:${ae2things_version}-sources") // Botania - //compileOnly fg.deobf("vazkii.botania:Botania:${botania_version}") - + implementation fg.deobf("vazkii.botania:Botania:${botania_version}") // Minecolonies // Change to compileOnly when running `runData` - //compileOnly fg.deobf("com.ldtteam:minecolonies:${minecolonies_version}") - //compileOnly fg.deobf("com.ldtteam:structurize:${structurize_version}") - //compileOnly fg.deobf("com.ldtteam:multipiston:${multipiston_version}") - //compileOnly fg.deobf("com.ldtteam:domum_ornamentum:${domumornamentum_version}:universal") - //compileOnly fg.deobf("com.ldtteam:blockui:${blockui_version}") + implementation fg.deobf("com.ldtteam:minecolonies:${minecolonies_version}") + implementation fg.deobf("com.ldtteam:structurize:${structurize_version}") + implementation fg.deobf("com.ldtteam:multi-piston:${multipiston_version}") + implementation fg.deobf("com.ldtteam:domum_ornamentum:${domumornamentum_version}:universal") + implementation fg.deobf("com.ldtteam:blockui:${blockui_version}") //Patchouli runtimeOnly fg.deobf("vazkii.patchouli:Patchouli:${patchouli_version}") @@ -306,8 +303,10 @@ dependencies { //Removed until fully ported //testImplementation fg.deobf("site.siredvin.ttoolkit:ttoolkit-${minecraft_version}:${ttoolkit_version}") - // Worldedit - runtimeOnly fg.deobf("curse.maven:worldedit-225608:4162208") + //Powah + implementation fg.deobf("curse.maven:powah-633483:${powah_version}") + implementation fg.deobf("me.shedaniel.cloth:cloth-config-forge:8.2.88") + implementation fg.deobf("dev.architectury:architectury-forge:6.2.43") testImplementation "org.junit.jupiter:junit-jupiter-api:${junit_version}" testImplementation "org.junit.jupiter:junit-jupiter-params:${junit_version}" diff --git a/gradle.properties b/gradle.properties index 699bc99bc..e0aea3967 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,15 +1,14 @@ -org.gradle.jvmargs=-Xmx4G +org.gradle.jvmargs=-Xmx8G org.gradle.daemon=false org.gradle.logging.level=info # Minecraft related -minecraft_version=1.19.3 -forge_version=44.1.23 +minecraft_version=1.19.2 +forge_version=43.2.14 mod_version=0.7.29r release_type=release -mappings_channel=official -#mappings_version=2022.11.27-1.19.2 -mappings_version=1.19.3 +mappings_channel=parchment +mappings_version=2022.09.18-1.19.2 jb_annotations=21.0.1 # Test dependencies @@ -20,29 +19,27 @@ kotlinx_coroutines_version=1.6.0-RC3 ttoolkit_version=0.1.3 # Mod dependencies -cc_version=1.102.0-SNAPSHOT -curios_version=1.19.3-5.1.1.2 -minecolonies_version=1.19.3-1.0.1325-ALPHA -appliedenergistics_version=13.0.10-beta -patchouli_version=1.19.3-78 -refinedstorage_version=1.11.1 +cc_version=1.101.2 +curios_version=1.19.2-5.1.2.2 +minecolonies_version=1.19.2-1.0.1410-ALPHA +appliedenergistics_version=12.9.2 +patchouli_version=1.19.2-76 +refinedstorage_version=1.11.6 botania_version=1.19.2-438-FORGE-SNAPSHOT -create_version=0.5.0.j-2 +create_version=0.5.1.b-30 mekanism_version=1.19.2-10.3.8.477 ae2things_version=4367610 +powah_version=4183078 # Mod dependencies which are needed for other mods # For minecolonies -structurize_version=1.19.3-1.0.474-ALPHA -domumornamentum_version=1.19.3-1.0.78-ALPHA -blockui_version=1.19.3-0.0.66-ALPHA -multipiston_version=1.19.3-1.2.26-ALPHA - -# For create -flywheel_version=0.6.8.a-1 +structurize_version=1.19.2-1.0.491-ALPHA +domumornamentum_version=1.19-1.0.83-ALPHA +blockui_version=1.19-0.0.69-ALPHA +multipiston_version=1.19.2-1.2.19-ALPHA # Mod dependencies for testing stuff(Only used in the dev environment) -jei_version=1.19.3-forge:12.4.0.22 +jei_version=1.19.2-forge:11.6.0.1011 # Credentials for the intelligence repository spaceUsername = Pat diff --git a/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java b/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java deleted file mode 100644 index 67cb446c9..000000000 --- a/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java +++ /dev/null @@ -1,65 +0,0 @@ -package de.srendi.advancedperipherals; - -import de.srendi.advancedperipherals.common.setup.APBlocks; -import de.srendi.advancedperipherals.common.setup.APRegistration; -import de.srendi.advancedperipherals.common.setup.CCRegistration; -import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; -import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.CreativeModeTab; -import net.minecraft.world.item.ItemStack; -import net.minecraftforge.event.CreativeModeTabEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.registries.RegistryObject; - -import java.util.Collection; -import java.util.Set; - -@Mod.EventBusSubscriber(modid = AdvancedPeripherals.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) -public class APCreativeTab { - - @SubscribeEvent - public static void registerCreativeTab(CreativeModeTabEvent.Register event) { - event.registerCreativeModeTab(AdvancedPeripherals.getRL("creativetab"), APCreativeTab::populateCreativeTabBuilder); - } - - private static void populateCreativeTabBuilder(CreativeModeTab.Builder builder) { - builder.displayItems((set, out, unknownMagicBoolean) -> { - APRegistration.ITEMS.getEntries().stream().map(RegistryObject::get).forEach(out::accept); - out.acceptAll(pocketUpgrade(CCRegistration.ID.COLONY_POCKET)); - out.acceptAll(pocketUpgrade(CCRegistration.ID.CHATTY_POCKET)); - out.acceptAll(pocketUpgrade(CCRegistration.ID.PLAYER_POCKET)); - out.acceptAll(pocketUpgrade(CCRegistration.ID.ENVIRONMENT_POCKET)); - out.acceptAll(pocketUpgrade(CCRegistration.ID.GEOSCANNER_POCKET)); - - out.acceptAll(turtleUpgrade(CCRegistration.ID.CHATTY_TURTLE)); - out.acceptAll(turtleUpgrade(CCRegistration.ID.CHUNKY_TURTLE)); - out.acceptAll(turtleUpgrade(CCRegistration.ID.COMPASS_TURTLE)); - out.acceptAll(turtleUpgrade(CCRegistration.ID.PLAYER_TURTLE)); - out.acceptAll(turtleUpgrade(CCRegistration.ID.ENVIRONMENT_TURTLE)); - out.acceptAll(turtleUpgrade(CCRegistration.ID.GEOSCANNER_TURTLE)); - - out.acceptAll(turtleUpgrade(CCRegistration.ID.WEAK_AUTOMATA)); - out.acceptAll(turtleUpgrade(CCRegistration.ID.OP_WEAK_AUTOMATA)); - out.acceptAll(turtleUpgrade(CCRegistration.ID.HUSBANDRY_AUTOMATA)); - out.acceptAll(turtleUpgrade(CCRegistration.ID.OP_HUSBANDRY_AUTOMATA)); - out.acceptAll(turtleUpgrade(CCRegistration.ID.END_AUTOMATA)); - out.acceptAll(turtleUpgrade(CCRegistration.ID.OP_END_AUTOMATA)); - - }); - builder.icon(() -> new ItemStack(APBlocks.CHAT_BOX.get())); - builder.title(Component.translatable("advancedperipherals.name")); - } - - private static Collection pocketUpgrade(ResourceLocation pocketId) { - return Set.of(ItemUtil.makePocket(ItemUtil.POCKET_NORMAL, pocketId.toString()), - ItemUtil.makePocket(ItemUtil.POCKET_ADVANCED, pocketId.toString())); - } - - private static Collection turtleUpgrade(ResourceLocation pocketId) { - return Set.of(ItemUtil.makeTurtle(ItemUtil.TURTLE_NORMAL, pocketId.toString()), - ItemUtil.makeTurtle(ItemUtil.TURTLE_ADVANCED, pocketId.toString())); - } - -} diff --git a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java index 5884a4eb9..1b6b30512 100644 --- a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java +++ b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java @@ -2,8 +2,11 @@ import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.network.PacketHandler; +import de.srendi.advancedperipherals.common.setup.APBlocks; import de.srendi.advancedperipherals.common.setup.APRegistration; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.ModLoadingContext; @@ -13,6 +16,7 @@ import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.jetbrains.annotations.NotNull; import java.util.Random; @@ -23,7 +27,15 @@ public class AdvancedPeripherals { public static final String NAME = "Advanced Peripherals"; public static final Logger LOGGER = LogManager.getLogger(NAME); public static final Random RANDOM = new Random(); + public static final CreativeModeTab TAB = new CreativeModeTab("advancedperipheralstab") { + @Override + @NotNull + public ItemStack makeIcon() { + return new ItemStack(APBlocks.CHAT_BOX.get()); + } + + }; public AdvancedPeripherals() { LOGGER.info("AdvancedPeripherals says hello!"); IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus(); diff --git a/src/main/java/de/srendi/advancedperipherals/client/MetaTurtleUpgradeModeller.java b/src/main/java/de/srendi/advancedperipherals/client/MetaTurtleUpgradeModeller.java index 38f624e6e..0d6e14fe9 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/MetaTurtleUpgradeModeller.java +++ b/src/main/java/de/srendi/advancedperipherals/client/MetaTurtleUpgradeModeller.java @@ -1,8 +1,8 @@ package de.srendi.advancedperipherals.client; import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.math.Axis; import com.mojang.math.Transformation; +import com.mojang.math.Vector3f; import dan200.computercraft.api.client.TransformedModel; import dan200.computercraft.api.client.turtle.TurtleUpgradeModeller; import dan200.computercraft.api.turtle.ITurtleAccess; @@ -23,10 +23,10 @@ public TransformedModel getModel(T upgrade, @Nullable ITurtleAccess turtle, @Not stack.translate(0.0f, 0.5f, 0.5f); if (turtle != null) { int rotationStep = DataStorageUtil.RotationCharge.get(turtle, side); - stack.mulPose(Axis.XN.rotationDegrees(-10f * rotationStep)); + stack.mulPose(Vector3f.XN.rotationDegrees(-10f * rotationStep)); } stack.translate(0.0f, -0.5f, -0.5f); - stack.mulPose(Axis.YN.rotationDegrees(90)); + stack.mulPose(Vector3f.YN.rotationDegrees(90)); if (side == TurtleSide.LEFT) { stack.translate(0, 0, -0.6); } else { diff --git a/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java b/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java index a7c678b1f..6731f755e 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java +++ b/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java @@ -2,7 +2,9 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; -import com.mojang.math.Axis; +import com.mojang.math.Matrix3f; +import com.mojang.math.Matrix4f; +import com.mojang.math.Vector3f; import de.srendi.advancedperipherals.common.blocks.base.BaseBlock; import de.srendi.advancedperipherals.common.blocks.blockentities.DistanceDetectorEntity; import de.srendi.advancedperipherals.common.util.EnumColor; @@ -17,8 +19,6 @@ import net.minecraft.util.Mth; import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.NotNull; -import org.joml.Matrix3f; -import org.joml.Matrix4f; public class DistanceDetectorRenderer implements BlockEntityRenderer { @@ -61,7 +61,7 @@ public static void renderBeaconBeam(DistanceDetectorEntity detectorEntity, PoseS float b = pColors[2]; pPoseStack.pushPose(); pPoseStack.mulPose(direction.getRotation()); - pPoseStack.mulPose(Axis.YP.rotationDegrees(degrees * 2.25F - 45.0F)); + pPoseStack.mulPose(Vector3f.YP.rotationDegrees(degrees * 2.25F - 45.0F)); float f15 = -1.0F + time; float f16 = pHeight * pTextureScale * (0.5F / pBeamRadius) + f15; renderPart(pPoseStack, pBufferSource.getBuffer(RenderType.beaconBeam(pBeamLocation, false)), r, g, b, 1.0F, pYOffset, maxX, 0.0F, pBeamRadius, pBeamRadius, 0.0F, -pBeamRadius, 0.0F, 0.0F, -pBeamRadius, 0.0F, 1.0F, f16, f15); diff --git a/src/main/java/de/srendi/advancedperipherals/client/screens/SmartGlassesScreen.java b/src/main/java/de/srendi/advancedperipherals/client/screens/SmartGlassesScreen.java index 3f6d8475e..8e7d7cca1 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/screens/SmartGlassesScreen.java +++ b/src/main/java/de/srendi/advancedperipherals/client/screens/SmartGlassesScreen.java @@ -2,10 +2,10 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; -import dan200.computercraft.client.gui.AbstractComputerScreen; +import dan200.computercraft.client.gui.ComputerScreenBase; import dan200.computercraft.client.gui.widgets.ComputerSidebar; -import dan200.computercraft.client.gui.widgets.TerminalWidget; -import dan200.computercraft.shared.computer.inventory.AbstractComputerMenu; +import dan200.computercraft.client.gui.widgets.WidgetTerminal; +import dan200.computercraft.shared.turtle.inventory.ContainerTurtle; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.client.widgets.SmartGlassesSettingsSwitch; import de.srendi.advancedperipherals.common.container.SmartGlassesContainer; @@ -16,9 +16,7 @@ import net.minecraft.world.entity.player.Inventory; import org.jetbrains.annotations.NotNull; -import static dan200.computercraft.shared.turtle.inventory.TurtleMenu.BORDER; - -public class SmartGlassesScreen extends AbstractComputerScreen { +public class SmartGlassesScreen extends ComputerScreenBase { private static final ResourceLocation BACKGROUND = new ResourceLocation(AdvancedPeripherals.MOD_ID, "textures/gui/smart_glasses_gui.png"); public static final ResourceLocation SIDEBAR = new ResourceLocation(AdvancedPeripherals.MOD_ID, "textures/gui/corners_glasses.png"); @@ -28,9 +26,9 @@ public class SmartGlassesScreen extends AbstractComputerScreen { @@ -23,7 +23,7 @@ protected int getMaxFuelConsumptionRate() { @Override public boolean isFuelConsumptionDisable() { - return !Config.turtlesNeedFuel; + return !ComputerCraft.turtlesNeedFuel; } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/TurtlePeripheralOwner.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/TurtlePeripheralOwner.java index d3a842800..58e52e6f4 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/TurtlePeripheralOwner.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/TurtlePeripheralOwner.java @@ -93,7 +93,7 @@ public ItemStack getToolInMainHand() { @Override public ItemStack storeItem(ItemStack stored) { - return InventoryUtil.storeItemsIntoSlot(turtle.getInventory(), stored, turtle.getSelectedSlot()); + return InventoryUtil.storeItems(stored, turtle.getItemHandler(), turtle.getSelectedSlot()); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChatBoxUpgrade.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChatBoxUpgrade.java index 85b56b280..7a8f4d1bd 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChatBoxUpgrade.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChatBoxUpgrade.java @@ -3,7 +3,7 @@ import dan200.computercraft.api.turtle.ITurtleAccess; import dan200.computercraft.api.turtle.TurtleSide; import dan200.computercraft.shared.computer.core.ServerComputer; -import dan200.computercraft.shared.turtle.blocks.TurtleBlockEntity; +import dan200.computercraft.shared.turtle.blocks.TileTurtle; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.ChatBoxPeripheral; import de.srendi.advancedperipherals.common.events.Events; @@ -45,7 +45,7 @@ public void update(@NotNull ITurtleAccess turtle, @NotNull TurtleSide side) { if (turtle.getUpgrade(side) instanceof TurtleChatBoxUpgrade) { BlockEntity tile = turtle.getLevel().getBlockEntity(turtle.getPosition()); - if (tile instanceof TurtleBlockEntity tileTurtle) { + if (tile instanceof TileTurtle tileTurtle) { ServerComputer computer = tileTurtle.getServerComputer(); lastConsumedMessage = Events.traverseChatMessages(lastConsumedMessage, message -> computer.queueEvent("chat", new Object[]{message.username(), message.message(), message.uuid(), message.isHidden()})); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/create/BasinIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/create/BasinIntegration.java index 2cf6ec50b..c5501c67f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/create/BasinIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/create/BasinIntegration.java @@ -1,6 +1,6 @@ package de.srendi.advancedperipherals.common.addons.create; -import com.simibubi.create.content.contraptions.processing.BasinTileEntity; +import com.simibubi.create.content.processing.basin.BasinBlockEntity; import dan200.computercraft.api.lua.LuaFunction; import de.srendi.advancedperipherals.common.util.LuaConverter; import de.srendi.advancedperipherals.lib.peripherals.BlockEntityIntegrationPeripheral; @@ -14,7 +14,7 @@ import java.util.*; -public class BasinIntegration extends BlockEntityIntegrationPeripheral { +public class BasinIntegration extends BlockEntityIntegrationPeripheral { public BasinIntegration(BlockEntity entity) { super(entity); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/create/BlazeBurnerIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/create/BlazeBurnerIntegration.java index 8cc4526bc..88bde5dca 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/create/BlazeBurnerIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/create/BlazeBurnerIntegration.java @@ -1,6 +1,6 @@ package de.srendi.advancedperipherals.common.addons.create; -import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerTileEntity; +import com.simibubi.create.content.processing.burner.BlazeBurnerBlockEntity; import dan200.computercraft.api.lua.LuaFunction; import de.srendi.advancedperipherals.lib.peripherals.BlockEntityIntegrationPeripheral; import net.minecraft.world.level.block.entity.BlockEntity; @@ -9,7 +9,7 @@ import java.util.HashMap; import java.util.Map; -public class BlazeBurnerIntegration extends BlockEntityIntegrationPeripheral { +public class BlazeBurnerIntegration extends BlockEntityIntegrationPeripheral { public BlazeBurnerIntegration(BlockEntity entity) { super(entity); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/create/FluidTankIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/create/FluidTankIntegration.java index e123b0ee3..04e99f2ba 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/create/FluidTankIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/create/FluidTankIntegration.java @@ -1,6 +1,6 @@ package de.srendi.advancedperipherals.common.addons.create; -import com.simibubi.create.content.contraptions.fluids.tank.FluidTankTileEntity; +import com.simibubi.create.content.fluids.tank.FluidTankBlockEntity; import dan200.computercraft.api.lua.LuaFunction; import de.srendi.advancedperipherals.lib.peripherals.BlockEntityIntegrationPeripheral; import net.minecraft.world.level.block.entity.BlockEntity; @@ -9,7 +9,7 @@ import java.util.HashMap; import java.util.Map; -public class FluidTankIntegration extends BlockEntityIntegrationPeripheral { +public class FluidTankIntegration extends BlockEntityIntegrationPeripheral { public FluidTankIntegration(BlockEntity entity) { super(entity); @@ -24,10 +24,10 @@ public String getType() { @LuaFunction(mainThread = true) public final Map getInfo() { Map data = new HashMap<>(); - data.put("capacity", blockEntity.getControllerTE().getTankInventory().getCapacity()); - data.put("amount", blockEntity.getControllerTE().getTankInventory().getFluidAmount()); - data.put("fluid", blockEntity.getControllerTE().getTankInventory().getFluid().getFluid().builtInRegistryHolder().key().location().toString()); - data.put("isBoiler", blockEntity.getControllerTE().boiler.isActive()); + data.put("capacity", blockEntity.getControllerBE().getTankInventory().getCapacity()); + data.put("amount", blockEntity.getControllerBE().getTankInventory().getFluidAmount()); + data.put("fluid", blockEntity.getControllerBE().getTankInventory().getFluid().getFluid().builtInRegistryHolder().key().location().toString()); + data.put("isBoiler", blockEntity.getControllerBE().boiler.isActive()); return data; } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/create/Integration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/create/Integration.java index 95223dcb0..f16cb0a3a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/create/Integration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/create/Integration.java @@ -1,22 +1,20 @@ package de.srendi.advancedperipherals.common.addons.create; -import com.simibubi.create.content.contraptions.base.KineticTileEntity; -import com.simibubi.create.content.contraptions.components.mixer.MechanicalMixerTileEntity; -import com.simibubi.create.content.contraptions.fluids.tank.FluidTankTileEntity; -import com.simibubi.create.content.contraptions.processing.BasinTileEntity; -import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerTileEntity; -import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueBehaviour; +import com.simibubi.create.content.fluids.tank.FluidTankBlockEntity; +import com.simibubi.create.content.kinetics.mixer.MechanicalMixerBlockEntity; +import com.simibubi.create.content.processing.basin.BasinBlockEntity; +import com.simibubi.create.content.processing.burner.BlazeBurnerBlockEntity; import de.srendi.advancedperipherals.common.addons.computercraft.integrations.IntegrationPeripheralProvider; public class Integration implements Runnable { @Override public void run() { - IntegrationPeripheralProvider.registerBlockEntityIntegration(BlazeBurnerIntegration::new, BlazeBurnerTileEntity.class); - IntegrationPeripheralProvider.registerBlockEntityIntegration(FluidTankIntegration::new, FluidTankTileEntity.class); + IntegrationPeripheralProvider.registerBlockEntityIntegration(BlazeBurnerIntegration::new, BlazeBurnerBlockEntity.class); + IntegrationPeripheralProvider.registerBlockEntityIntegration(FluidTankIntegration::new, FluidTankBlockEntity.class); // Disable until verified that it does not clash with the existing create CC integration - IntegrationPeripheralProvider.registerBlockEntityIntegration(ScrollValueBehaviourIntegration::new, KineticTileEntity.class, tile -> tile.getBehaviour(ScrollValueBehaviour.TYPE) != null, 10); - IntegrationPeripheralProvider.registerBlockEntityIntegration(BasinIntegration::new, BasinTileEntity.class); - IntegrationPeripheralProvider.registerBlockEntityIntegration(MechanicalMixerIntegration::new, MechanicalMixerTileEntity.class); + //IntegrationPeripheralProvider.registerBlockEntityIntegration(ScrollValueBehaviourIntegration::new, KineticBlockEntity.class, tile -> tile.getBehaviour(ScrollValueBehaviour.TYPE) != null, 10); + IntegrationPeripheralProvider.registerBlockEntityIntegration(BasinIntegration::new, BasinBlockEntity.class); + IntegrationPeripheralProvider.registerBlockEntityIntegration(MechanicalMixerIntegration::new, MechanicalMixerBlockEntity.class); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/create/MechanicalMixerIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/create/MechanicalMixerIntegration.java index 8eece5f47..0c87f7763 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/create/MechanicalMixerIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/create/MechanicalMixerIntegration.java @@ -1,13 +1,13 @@ package de.srendi.advancedperipherals.common.addons.create; -import com.simibubi.create.content.contraptions.components.mixer.MechanicalMixerTileEntity; -import com.simibubi.create.content.contraptions.processing.BasinTileEntity; +import com.simibubi.create.content.kinetics.mixer.MechanicalMixerBlockEntity; +import com.simibubi.create.content.processing.basin.BasinBlockEntity; import dan200.computercraft.api.lua.LuaFunction; import de.srendi.advancedperipherals.lib.peripherals.BlockEntityIntegrationPeripheral; import net.minecraft.world.level.block.entity.BlockEntity; import org.jetbrains.annotations.NotNull; -public class MechanicalMixerIntegration extends BlockEntityIntegrationPeripheral { +public class MechanicalMixerIntegration extends BlockEntityIntegrationPeripheral { public MechanicalMixerIntegration(BlockEntity entity) { super(entity); @@ -28,6 +28,6 @@ public final boolean isRunning() { public final boolean hasBasin() { if (blockEntity.getLevel() == null) return false; BlockEntity basinTE = blockEntity.getLevel().getBlockEntity(blockEntity.getBlockPos().below(2)); - return basinTE instanceof BasinTileEntity; + return basinTE instanceof BasinBlockEntity; } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/create/ScrollValueBehaviourIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/create/ScrollValueBehaviourIntegration.java index c2817b401..32dbc4a1d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/create/ScrollValueBehaviourIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/create/ScrollValueBehaviourIntegration.java @@ -1,7 +1,7 @@ package de.srendi.advancedperipherals.common.addons.create; -import com.simibubi.create.content.contraptions.base.KineticTileEntity; -import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueBehaviour; +import com.simibubi.create.content.kinetics.base.KineticBlockEntity; +import com.simibubi.create.foundation.blockEntity.behaviour.scrollValue.ScrollValueBehaviour; import dan200.computercraft.api.lua.LuaFunction; import de.srendi.advancedperipherals.lib.peripherals.BlockEntityIntegrationPeripheral; import net.minecraft.world.level.block.entity.BlockEntity; @@ -10,7 +10,7 @@ /** * Integration for kinetic tile entities with scroll value behaviours like the speed controller or the creative motor */ -public class ScrollValueBehaviourIntegration extends BlockEntityIntegrationPeripheral { +public class ScrollValueBehaviourIntegration extends BlockEntityIntegrationPeripheral { public ScrollValueBehaviourIntegration(BlockEntity entity) { super(entity); diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java index fe36128b9..100ef7b95 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java @@ -96,13 +96,13 @@ public void handleTick(Level level, BlockState state, Bl @Override public AABB getRenderBoundingBox() { Direction direction = getBlockState().getValue(BaseBlock.ORIENTATION).front(); - return AABB.ofSize(getBlockPos().getCenter(), direction.getStepX() * currentDistance + 1, direction.getStepY() * currentDistance + 1, direction.getStepZ() * currentDistance + 1) + return AABB.ofSize(Vec3.atCenterOf(getBlockPos()), direction.getStepX() * currentDistance + 1, direction.getStepY() * currentDistance + 1, direction.getStepZ() * currentDistance + 1) .move(direction.getStepX() * currentDistance / 2, direction.getStepY() * currentDistance / 2, direction.getStepZ() * currentDistance / 2); } public double calculateDistance() { Direction direction = getBlockState().getValue(BaseBlock.ORIENTATION).front(); - Vec3 center = getBlockPos().getCenter(); + Vec3 center = Vec3.atCenterOf(getBlockPos()); Vec3 from = center.add(direction.getStepX() * 0.501, direction.getStepY() * 0.501, direction.getStepZ() * 0.501); Vec3 to = from.add(direction.getStepX() * maxRange, direction.getStepY() * maxRange, direction.getStepZ() * maxRange); HitResult result = getResult(to, from); @@ -125,7 +125,7 @@ private float calculateDistance(HitResult result, Vec3 center, Direction directi if (result.getType() != HitResult.Type.MISS) { if (result instanceof BlockHitResult blockHitResult) { BlockState resultBlock = getLevel().getBlockState(blockHitResult.getBlockPos()); - distance = distManhattan(blockHitResult.getBlockPos().getCenter(), center); + distance = distManhattan(Vec3.atCenterOf(blockHitResult.getBlockPos()), center); distance = amendDistance(resultBlock, direction, distance); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java b/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java index 6b0660aae..8a8bd7684 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java @@ -1,8 +1,9 @@ package de.srendi.advancedperipherals.common.container; +import dan200.computercraft.client.gui.widgets.ComputerSidebar; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ServerComputer; -import dan200.computercraft.shared.computer.inventory.AbstractComputerMenu; +import dan200.computercraft.shared.computer.inventory.ContainerComputerBase; import dan200.computercraft.shared.network.container.ComputerContainerData; import de.srendi.advancedperipherals.common.setup.APContainerTypes; import de.srendi.advancedperipherals.common.smartglasses.SlotType; @@ -17,10 +18,10 @@ import java.util.function.Predicate; -public class SmartGlassesContainer extends AbstractComputerMenu { +public class SmartGlassesContainer extends ContainerComputerBase { public static final int BORDER = 8; public static final int PLAYER_START_Y = 134; - public static final int PLAYER_START_X = SIDEBAR_WIDTH + BORDER; + public static final int PLAYER_START_X = ComputerSidebar.WIDTH + BORDER; public SmartGlassesContainer(int id, Predicate canUse, ServerComputer computer, Inventory playerInventory, IItemHandler inventory, ComputerContainerData data) { super(APContainerTypes.SMART_GLASSES_CONTAINER.get(), id, canUse, ComputerFamily.ADVANCED, computer, data); diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java b/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java index 888aecaf8..be546eda1 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java @@ -1,22 +1,14 @@ package de.srendi.advancedperipherals.common.data; import de.srendi.advancedperipherals.common.setup.APRegistration; -import net.minecraft.data.loot.BlockLootSubProvider; -import net.minecraft.world.flag.FeatureFlags; import net.minecraft.world.level.block.Block; import net.minecraftforge.registries.RegistryObject; import org.jetbrains.annotations.NotNull; -import java.util.Set; - -public class BlockLootTables extends BlockLootSubProvider { - - protected BlockLootTables() { - super(Set.of(), FeatureFlags.REGISTRY.allFlags()); - } +public class BlockLootTables extends net.minecraft.data.loot.BlockLoot { @Override - protected void generate() { + protected void addTables() { APRegistration.BLOCKS.getEntries().stream().map(RegistryObject::get).forEach(this::dropSelf); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTablesProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTablesProvider.java index 6e58534c6..9c9913860 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTablesProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTablesProvider.java @@ -1,32 +1,37 @@ package de.srendi.advancedperipherals.common.data; import com.google.common.collect.ImmutableList; -import net.minecraft.data.PackOutput; +import com.mojang.datafixers.util.Pair; +import net.minecraft.data.DataGenerator; import net.minecraft.data.loot.LootTableProvider; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.storage.loot.LootTable; import net.minecraft.world.level.storage.loot.LootTables; import net.minecraft.world.level.storage.loot.ValidationContext; +import net.minecraft.world.level.storage.loot.parameters.LootContextParamSet; import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets; -import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.Map; -import java.util.Set; +import java.util.function.BiConsumer; +import java.util.function.Consumer; +import java.util.function.Supplier; public class BlockLootTablesProvider extends LootTableProvider { - public BlockLootTablesProvider(PackOutput output) { - super(output, Set.of(), ImmutableList.of(new SubProviderEntry(BlockLootTables::new, LootContextParamSets.BLOCK))); + + public BlockLootTablesProvider(DataGenerator dataGeneratorIn) { + super(dataGeneratorIn); } @Override - public @NotNull List getTables() { - return ImmutableList.of(new SubProviderEntry(BlockLootTables::new, LootContextParamSets.BLOCK)); + protected List>>, LootContextParamSet>> getTables() { + return ImmutableList.of(Pair.of(BlockLootTables::new, LootContextParamSets.BLOCK)); + } @Override - protected void validate(Map map, @NotNull ValidationContext validationtracker) { + protected void validate(Map map, ValidationContext validationtracker) { map.forEach((id, table) -> LootTables.validate(validationtracker, id, table)); } -} +} \ No newline at end of file diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/BlockStatesAndModelsProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/BlockStatesAndModelsProvider.java index d4ff6ac16..762311d9d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/BlockStatesAndModelsProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/BlockStatesAndModelsProvider.java @@ -5,7 +5,7 @@ import de.srendi.advancedperipherals.common.setup.APBlocks; import net.minecraft.core.Direction; import net.minecraft.core.FrontAndTop; -import net.minecraft.data.PackOutput; +import net.minecraft.data.DataGenerator; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.Block; import net.minecraftforge.client.model.generators.*; @@ -14,7 +14,7 @@ public class BlockStatesAndModelsProvider extends BlockStateProvider { - public BlockStatesAndModelsProvider(PackOutput packOutput, ExistingFileHelper exFileHelper) { + public BlockStatesAndModelsProvider(DataGenerator packOutput, ExistingFileHelper exFileHelper) { super(packOutput, AdvancedPeripherals.MOD_ID, exFileHelper); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/BlockTagsProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/BlockTagsProvider.java index 935e96cc0..b34c879d5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/BlockTagsProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/BlockTagsProvider.java @@ -2,20 +2,18 @@ import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.blocks.base.IHarvestableBlock; -import net.minecraft.core.HolderLookup; -import net.minecraft.data.PackOutput; +import net.minecraft.core.Registry; +import net.minecraft.data.DataGenerator; import net.minecraft.data.tags.TagsProvider; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.Block; import net.minecraftforge.common.data.ExistingFileHelper; import net.minecraftforge.registries.DeferredRegister; -import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.RegistryObject; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.nio.file.Path; -import java.util.concurrent.CompletableFuture; public class BlockTagsProvider extends TagsProvider { /* @@ -25,27 +23,27 @@ public class BlockTagsProvider extends TagsProvider { @NotNull private final DeferredRegister blockRegistry; @NotNull - private final PackOutput packOutput; + private final DataGenerator generator; - protected BlockTagsProvider(PackOutput packOutput, CompletableFuture future, @Nullable ExistingFileHelper existingFileHelper, DeferredRegister registry) { - super(packOutput, ForgeRegistries.BLOCKS.getRegistryKey(), future, AdvancedPeripherals.MOD_ID, existingFileHelper); - this.packOutput = packOutput; - this.blockRegistry = registry; + public BlockTagsProvider(DataGenerator generator, @Nullable ExistingFileHelper existingFileHelper, @NotNull DeferredRegister blockRegistry) { + super(generator, Registry.BLOCK, AdvancedPeripherals.MOD_ID, existingFileHelper); + this.blockRegistry = blockRegistry; + this.generator = generator; } @Override - protected void addTags(@NotNull HolderLookup.Provider provider) { + protected void addTags() { blockRegistry.getEntries().stream().map(RegistryObject::get).forEach(block -> { if (!(block instanceof IHarvestableBlock harvesterBlock)) throw new IllegalArgumentException("For any block you should define harvester logic!"); - tag(harvesterBlock.getHarvestTag()).add(ForgeRegistries.BLOCKS.getResourceKey(block).get()); - tag(harvesterBlock.getToolTag()).add(ForgeRegistries.BLOCKS.getResourceKey(block).get()); + tag(harvesterBlock.getHarvestTag()).add(block); + tag(harvesterBlock.getToolTag()).add(block); }); } @Override protected Path getPath(ResourceLocation block) { - return this.packOutput.getOutputFolder().resolve("data/" + block.getNamespace() + "/tags/blocks/" + block.getPath() + ".json"); + return this.generator.getOutputFolder().resolve("data/" + block.getNamespace() + "/tags/blocks/" + block.getPath() + ".json"); } @NotNull @@ -53,4 +51,4 @@ protected Path getPath(ResourceLocation block) { public String getName() { return "Block tags"; } -} +} \ No newline at end of file diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/DataGenerators.java b/src/main/java/de/srendi/advancedperipherals/common/data/DataGenerators.java index c710ed587..b5b92dd20 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/DataGenerators.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/DataGenerators.java @@ -2,17 +2,12 @@ import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.setup.APRegistration; -import net.minecraft.Util; -import net.minecraft.core.HolderLookup; import net.minecraft.data.DataGenerator; -import net.minecraft.data.registries.VanillaRegistries; import net.minecraftforge.common.data.ExistingFileHelper; import net.minecraftforge.data.event.GatherDataEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; -import java.util.concurrent.CompletableFuture; - @Mod.EventBusSubscriber(modid = AdvancedPeripherals.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) public class DataGenerators { @@ -24,16 +19,14 @@ public static void genData(GatherDataEvent event) { DataGenerator generator = event.getGenerator(); ExistingFileHelper existingFileHelper = event.getExistingFileHelper(); - CompletableFuture completablefuture = CompletableFuture.supplyAsync(VanillaRegistries::createLookup, Util.backgroundExecutor()); - generator.addProvider(event.includeServer(), new BlockTagsProvider(generator.getPackOutput(), completablefuture, existingFileHelper, APRegistration.BLOCKS)); - generator.addProvider(event.includeServer(), new RecipesProvider(generator.getPackOutput())); - generator.addProvider(event.includeServer(), new BlockLootTablesProvider(generator.getPackOutput())); - generator.addProvider(event.includeServer(), new TurtleUpgradesProvider(generator.getPackOutput())); - generator.addProvider(event.includeServer(), new PocketUpgradesProvider(generator.getPackOutput())); - generator.addProvider(event.includeServer(), new PoiTypeProvider(generator.getPackOutput(), completablefuture, existingFileHelper)); - generator.addProvider(event.includeServer(), new BlockStatesAndModelsProvider(generator.getPackOutput(), existingFileHelper)); + generator.addProvider(event.includeServer(), new BlockTagsProvider(generator, existingFileHelper, APRegistration.BLOCKS)); + generator.addProvider(event.includeServer(), new RecipesProvider(generator)); + generator.addProvider(event.includeServer(), new BlockLootTablesProvider(generator)); + generator.addProvider(event.includeServer(), new TurtleUpgradesProvider(generator)); + generator.addProvider(event.includeServer(), new PocketUpgradesProvider(generator)); + generator.addProvider(event.includeServer(), new PoiTypeProvider(generator, existingFileHelper)); + generator.addProvider(event.includeServer(), new BlockStatesAndModelsProvider(generator, existingFileHelper)); - generator.addProvider(event.includeClient(), new EnUsLanguageProvider(generator.getPackOutput())); + generator.addProvider(event.includeClient(), new EnUsLanguageProvider(generator)); } - } diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java index e05c801d3..c9dfdcf33 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java @@ -7,7 +7,7 @@ import de.srendi.advancedperipherals.common.setup.APVillagers; import de.srendi.advancedperipherals.common.setup.CCRegistration; import net.minecraft.client.KeyMapping; -import net.minecraft.data.PackOutput; +import net.minecraft.data.DataGenerator; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.npc.VillagerProfession; import net.minecraft.world.item.Item; @@ -20,7 +20,7 @@ public class EnUsLanguageProvider extends LanguageProvider { - public EnUsLanguageProvider(PackOutput gen) { + public EnUsLanguageProvider(DataGenerator gen) { super(gen, AdvancedPeripherals.MOD_ID, "en_us"); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/PocketUpgradesProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/PocketUpgradesProvider.java index 5edcc58bc..f917329bb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/PocketUpgradesProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/PocketUpgradesProvider.java @@ -4,14 +4,14 @@ import dan200.computercraft.api.pocket.PocketUpgradeSerialiser; import de.srendi.advancedperipherals.common.setup.APBlocks; import de.srendi.advancedperipherals.common.setup.CCRegistration; -import net.minecraft.data.PackOutput; +import net.minecraft.data.DataGenerator; import org.jetbrains.annotations.NotNull; import java.util.function.Consumer; public class PocketUpgradesProvider extends PocketUpgradeDataProvider { - public PocketUpgradesProvider(PackOutput output) { + public PocketUpgradesProvider(DataGenerator output) { super(output); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/PoiTypeProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/PoiTypeProvider.java index fe33a4ae6..9549f1cc3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/PoiTypeProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/PoiTypeProvider.java @@ -2,8 +2,7 @@ import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.setup.APRegistration; -import net.minecraft.core.HolderLookup; -import net.minecraft.data.PackOutput; +import net.minecraft.data.DataGenerator; import net.minecraft.data.tags.PoiTypeTagsProvider; import net.minecraft.data.tags.TagsProvider; import net.minecraft.tags.PoiTypeTags; @@ -13,20 +12,16 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Objects; -import java.util.concurrent.CompletableFuture; - public class PoiTypeProvider extends PoiTypeTagsProvider { - - public PoiTypeProvider(PackOutput output, CompletableFuture future, @Nullable ExistingFileHelper existingFileHelper) { - super(output, future, AdvancedPeripherals.MOD_ID, existingFileHelper); + public PoiTypeProvider(DataGenerator pGenerator, @Nullable ExistingFileHelper existingFileHelper) { + super(pGenerator, AdvancedPeripherals.MOD_ID, existingFileHelper); } @Override - protected void addTags(HolderLookup.@NotNull Provider provider) { + protected void addTags() { TagsProvider.TagAppender appender = tag(PoiTypeTags.ACQUIRABLE_JOB_SITE); - APRegistration.POI_TYPES.getEntries().stream().map(RegistryObject::getKey).filter(Objects::nonNull).forEach(appender::add); + APRegistration.POI_TYPES.getEntries().stream().map(RegistryObject::getKey).forEach(appender::add); } @NotNull diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java index 876c98221..4e893db04 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java @@ -1,11 +1,14 @@ package de.srendi.advancedperipherals.common.data; -import dan200.computercraft.shared.ModRegistry; +import appeng.core.definitions.AEBlocks; +import com.refinedmods.refinedstorage.RSBlocks; +import com.refinedmods.refinedstorage.RSItems; +import dan200.computercraft.shared.Registry; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.setup.APBlocks; import de.srendi.advancedperipherals.common.setup.APItems; import de.srendi.advancedperipherals.common.util.RawValue; -import net.minecraft.data.PackOutput; +import net.minecraft.data.DataGenerator; import net.minecraft.data.recipes.*; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.ItemTags; @@ -27,81 +30,78 @@ public class RecipesProvider extends RecipeProvider implements IConditionBuilder { private static final Block CASING = APBlocks.PERIPHERAL_CASING.get(); + private static final String HAS_ITEM = "has_item"; - public RecipesProvider(PackOutput packOutput) { + public RecipesProvider(DataGenerator packOutput) { super(packOutput); } @Override - protected void buildRecipes(@NotNull Consumer consumer) { + protected void buildCraftingRecipes(@NotNull Consumer consumer) { addShapeless(consumer); addShaped(consumer); addSmithing(consumer); } private void addShapeless(@NotNull Consumer consumer) { - ShapelessRecipeBuilder.shapeless(RecipeCategory.REDSTONE, APItems.OVERPOWERED_WEAK_AUTOMATA_CORE.get()) + ShapelessRecipeBuilder.shapeless(APItems.OVERPOWERED_WEAK_AUTOMATA_CORE.get()) .requires(APItems.WEAK_AUTOMATA_CORE.get()) .requires(Items.NETHER_STAR) - .unlockedBy("has_item", has(APItems.WEAK_AUTOMATA_CORE.get())) + .unlockedBy(HAS_ITEM, has(APItems.WEAK_AUTOMATA_CORE.get())) .save(consumer); - ShapelessRecipeBuilder.shapeless(RecipeCategory.REDSTONE, APItems.OVERPOWERED_END_AUTOMATA_CORE.get()) + ShapelessRecipeBuilder.shapeless(APItems.OVERPOWERED_END_AUTOMATA_CORE.get()) .requires(APItems.END_AUTOMATA_CORE.get()) .requires(Items.NETHER_STAR) - .unlockedBy("has_item", has(APItems.END_AUTOMATA_CORE.get())) + .unlockedBy(HAS_ITEM, has(APItems.END_AUTOMATA_CORE.get())) .save(consumer); - ShapelessRecipeBuilder.shapeless(RecipeCategory.REDSTONE, APItems.OVERPOWERED_HUSBANDRY_AUTOMATA_CORE.get()) + ShapelessRecipeBuilder.shapeless(APItems.OVERPOWERED_HUSBANDRY_AUTOMATA_CORE.get()) .requires(APItems.HUSBANDRY_AUTOMATA_CORE.get()) .requires(Items.NETHER_STAR) - .unlockedBy("has_item", has(APItems.HUSBANDRY_AUTOMATA_CORE.get())) - .save(consumer); - } + .unlockedBy(HAS_ITEM, has(APItems.HUSBANDRY_AUTOMATA_CORE.get())) + .save(consumer); } private void addShaped(@NotNull Consumer consumer) { - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APItems.SMART_GLASSES.get()) + /*ShapedRecipeBuilder.shaped(APItems.AR_GOGGLES.get()) .define('E', Tags.Items.ENDER_PEARLS) .define('S', Tags.Items.RODS_WOODEN) .define('G', Tags.Items.GLASS_BLACK) - .define('C', ModRegistry.Items.COMPUTER_ADVANCED.get()) - .define('M', ModRegistry.Items.WIRELESS_MODEM_ADVANCED.get()) - .pattern("S S") - .pattern("GEG") - .pattern("M C") - .unlockedBy("has_item", has(Items.STICK)) - .save(consumer); + .pattern("GSG") + .pattern(" E ") + .unlockedBy(HAS_ITEM, has(Items.STICK)) + .save(consumer);*/ - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APBlocks.CHAT_BOX.get()) + ShapedRecipeBuilder.shaped(APBlocks.CHAT_BOX.get()) .define('P', ItemTags.LOGS) .define('A', CASING) .define('G', Tags.Items.INGOTS_GOLD) .pattern("PPP") .pattern("PAP") .pattern("PGP") - .unlockedBy("has_item", has(CASING)) + .unlockedBy(HAS_ITEM, has(CASING)) .save(consumer); - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APItems.CHUNK_CONTROLLER.get()) + ShapedRecipeBuilder.shaped(APItems.CHUNK_CONTROLLER.get()) .define('I', Tags.Items.INGOTS_IRON) .define('R', Tags.Items.DUSTS_REDSTONE) .define('A', Items.ENDER_EYE) .pattern("IRI") .pattern("RAR") .pattern("IRI") - .unlockedBy("has_item", has(Items.RESPAWN_ANCHOR)) + .unlockedBy(HAS_ITEM, has(Items.RESPAWN_ANCHOR)) .save(consumer); - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APItems.COMPUTER_TOOL.get()) + ShapedRecipeBuilder.shaped(APItems.COMPUTER_TOOL.get()) .define('I', Tags.Items.INGOTS_IRON) .define('B', Items.BLUE_TERRACOTTA) .pattern("I I") .pattern("IBI") .pattern(" B ") - .unlockedBy("has_item", has(Items.BLUE_TERRACOTTA)) + .unlockedBy(HAS_ITEM, has(Items.BLUE_TERRACOTTA)) .save(consumer); - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APBlocks.ENERGY_DETECTOR.get()) + ShapedRecipeBuilder.shaped(APBlocks.ENERGY_DETECTOR.get()) .define('B', Tags.Items.STORAGE_BLOCKS_REDSTONE) .define('R', Items.REDSTONE_TORCH) .define('C', Items.COMPARATOR) @@ -110,10 +110,10 @@ private void addShaped(@NotNull Consumer consumer) { .pattern("BRB") .pattern("CAC") .pattern("BGB") - .unlockedBy("has_item", has(CASING)) + .unlockedBy(HAS_ITEM, has(CASING)) .save(consumer); - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APBlocks.ENVIRONMENT_DETECTOR.get()) + ShapedRecipeBuilder.shaped(APBlocks.ENVIRONMENT_DETECTOR.get()) .define('W', ItemTags.WOOL) .define('S', ItemTags.SAPLINGS) .define('C', Tags.Items.CROPS) @@ -122,20 +122,20 @@ private void addShaped(@NotNull Consumer consumer) { .pattern("WSW") .pattern("LAL") .pattern("WCW") - .unlockedBy("has_item", has(CASING)) + .unlockedBy(HAS_ITEM, has(CASING)) .save(consumer); - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APBlocks.INVENTORY_MANAGER.get()) + ShapedRecipeBuilder.shaped(APBlocks.INVENTORY_MANAGER.get()) .define('I', Tags.Items.INGOTS_IRON) .define('C', Tags.Items.CHESTS) .define('A', CASING) .pattern("ICI") .pattern("CAC") .pattern("ICI") - .unlockedBy("has_item", has(CASING)) + .unlockedBy(HAS_ITEM, has(CASING)) .save(consumer); - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APItems.MEMORY_CARD.get()) + ShapedRecipeBuilder.shaped(APItems.MEMORY_CARD.get()) .define('I', Tags.Items.INGOTS_IRON) .define('W', Tags.Items.GLASS_WHITE) .define('O', Items.OBSERVER) @@ -143,64 +143,64 @@ private void addShaped(@NotNull Consumer consumer) { .pattern("IWI") .pattern("IOI") .pattern(" G ") - .unlockedBy("has_item", has(Items.OBSERVER)) + .unlockedBy(HAS_ITEM, has(Items.OBSERVER)) .save(consumer); - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APBlocks.PERIPHERAL_CASING.get()) + ShapedRecipeBuilder.shaped(APBlocks.PERIPHERAL_CASING.get()) .define('I', Tags.Items.INGOTS_IRON) .define('i', Items.IRON_BARS) .define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE) .pattern("IiI") .pattern("iRi") .pattern("IiI") - .unlockedBy("has_item", has(Items.REDSTONE_BLOCK)) + .unlockedBy(HAS_ITEM, has(Items.REDSTONE_BLOCK)) .save(consumer); - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APBlocks.PLAYER_DETECTOR.get()) + ShapedRecipeBuilder.shaped(APBlocks.PLAYER_DETECTOR.get()) .define('S', Items.SMOOTH_STONE) .define('A', CASING) .define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE) .pattern("SSS") .pattern("SAS") .pattern("SRS") - .unlockedBy("has_item", has(CASING)) + .unlockedBy(HAS_ITEM, has(CASING)) .save(consumer); - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APBlocks.REDSTONE_INTEGRATOR.get()) + ShapedRecipeBuilder.shaped(APBlocks.REDSTONE_INTEGRATOR.get()) .define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE) .define('A', CASING) .define('C', Items.COMPARATOR) .pattern("RCR") .pattern("CAC") .pattern("RCR") - .unlockedBy("has_item", has(CASING)) + .unlockedBy(HAS_ITEM, has(CASING)) .save(consumer); - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APBlocks.BLOCK_READER.get()) + ShapedRecipeBuilder.shaped(APBlocks.BLOCK_READER.get()) .define('O', Items.OBSERVER) .define('I', Tags.Items.INGOTS_IRON) - .define('M', ModRegistry.Blocks.WIRED_MODEM_FULL.get()) + .define('M', Registry.ModBlocks.WIRED_MODEM_FULL.get()) .define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE) .define('A', CASING) .pattern("IRI") .pattern("MAO") .pattern("IRI") - .unlockedBy("has_item", has(CASING)) + .unlockedBy(HAS_ITEM, has(CASING)) .save(consumer); - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APBlocks.GEO_SCANNER.get()) + ShapedRecipeBuilder.shaped(APBlocks.GEO_SCANNER.get()) .define('O', Items.OBSERVER) .define('D', Tags.Items.GEMS_DIAMOND) .define('C', CASING) .define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE) - .define('M', ModRegistry.Blocks.WIRED_MODEM_FULL.get()) + .define('M', Registry.ModBlocks.WIRED_MODEM_FULL.get()) .pattern("DMD") .pattern("DCD") .pattern("ROR") - .unlockedBy("has_item", has(CASING)) + .unlockedBy(HAS_ITEM, has(CASING)) .save(consumer); - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APBlocks.NBT_STORAGE.get()) + ShapedRecipeBuilder.shaped(APBlocks.NBT_STORAGE.get()) .define('C', Tags.Items.CHESTS) .define('A', CASING) .define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE) @@ -208,7 +208,7 @@ private void addShaped(@NotNull Consumer consumer) { .pattern("ICI") .pattern("CAC") .pattern("RCR") - .unlockedBy("has_item", has(CASING)) + .unlockedBy(HAS_ITEM, has(CASING)) .save(consumer); ConditionalRecipe.builder() @@ -216,29 +216,29 @@ private void addShaped(@NotNull Consumer consumer) { modLoaded("minecolonies") ) .addRecipe( - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APBlocks.COLONY_INTEGRATOR.get()) + ShapedRecipeBuilder.shaped(APBlocks.COLONY_INTEGRATOR.get()) .define('O', ItemTags.LOGS) .define('A', CASING) .define('R', Ingredient.fromValues(Stream.of(new RawValue(new ResourceLocation("minecolonies", "blockminecoloniesrack"))))) .pattern("ORO") .pattern(" A ") .pattern("ORO") - .unlockedBy("has_item", has(CASING))::save + .unlockedBy(HAS_ITEM, has(CASING))::save ).build(consumer, new ResourceLocation(AdvancedPeripherals.MOD_ID, "colony_integrator")); - /*ConditionalRecipe.builder() + ConditionalRecipe.builder() .addCondition( modLoaded("ae2") ) .addRecipe( - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APBlocks.ME_BRIDGE.get()) + ShapedRecipeBuilder.shaped(APBlocks.ME_BRIDGE.get()) .define('F', AEBlocks.FLUIX_BLOCK.asItem()) .define('A', CASING) .define('I', AEBlocks.INTERFACE.asItem()) .pattern("FIF") .pattern("IAI") .pattern("FIF") - .unlockedBy("has_item", has(CASING))::save + .unlockedBy(HAS_ITEM, has(CASING))::save ).build(consumer, new ResourceLocation(AdvancedPeripherals.MOD_ID, "me_bridge")); ConditionalRecipe.builder() @@ -246,17 +246,17 @@ private void addShaped(@NotNull Consumer consumer) { modLoaded("refinedstorage") ) .addRecipe( - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APBlocks.RS_BRIDGE.get()) + ShapedRecipeBuilder.shaped(APBlocks.RS_BRIDGE.get()) .define('Q', RSItems.QUARTZ_ENRICHED_IRON.get()) .define('A', CASING) .define('I', RSBlocks.INTERFACE.get()) .pattern("QIQ") .pattern("IAI") .pattern("QIQ") - .unlockedBy("has_item", has(CASING))::save + .unlockedBy(HAS_ITEM, has(CASING))::save ).build(consumer, new ResourceLocation(AdvancedPeripherals.MOD_ID, "rs_bridge")); -*/ - ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, APItems.WEAK_AUTOMATA_CORE.get()) + + ShapedRecipeBuilder.shaped(APItems.WEAK_AUTOMATA_CORE.get()) .define('A', CASING) .define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE) .define('S', Items.SOUL_LANTERN) @@ -265,13 +265,14 @@ private void addShaped(@NotNull Consumer consumer) { .pattern("RAR") .pattern("DSD") .pattern("RLR") - .unlockedBy("has_item", has(CASING)) + .unlockedBy(HAS_ITEM, has(CASING)) .save(consumer); + } private void addSmithing(@NotNull Consumer consumer) { UpgradeRecipeBuilder - .smithing(Ingredient.of(APItems.SMART_GLASSES.get()), Ingredient.of(Items.NETHERITE_INGOT), RecipeCategory.REDSTONE, APItems.SMART_GLASSES_NETHERITE.get()) + .smithing(Ingredient.of(APItems.SMART_GLASSES.get()), Ingredient.of(Items.NETHERITE_INGOT), APItems.SMART_GLASSES_NETHERITE.get()) .unlocks("has_item", has(Items.NETHERITE_INGOT)) .save(consumer, new ResourceLocation(AdvancedPeripherals.MOD_ID, "armor/" + APItems.SMART_GLASSES_NETHERITE.getKey().location().getPath())); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/TurtleUpgradesProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/TurtleUpgradesProvider.java index 9ca170b03..70ec6c177 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/TurtleUpgradesProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/TurtleUpgradesProvider.java @@ -5,14 +5,14 @@ import de.srendi.advancedperipherals.common.setup.APBlocks; import de.srendi.advancedperipherals.common.setup.APItems; import de.srendi.advancedperipherals.common.setup.CCRegistration; -import net.minecraft.data.PackOutput; +import net.minecraft.data.DataGenerator; import org.jetbrains.annotations.NotNull; import java.util.function.Consumer; public class TurtleUpgradesProvider extends TurtleUpgradeDataProvider { - public TurtleUpgradesProvider(PackOutput generator) { + public TurtleUpgradesProvider(DataGenerator generator) { super(generator); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java index dc5a5980e..c984ff4e6 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java @@ -1,15 +1,15 @@ package de.srendi.advancedperipherals.common.items; import com.google.common.base.Objects; +import dan200.computercraft.ComputerCraft; import dan200.computercraft.api.ComputerCraftAPI; -import dan200.computercraft.api.filesystem.Mount; +import dan200.computercraft.api.filesystem.IWritableMount; import dan200.computercraft.api.media.IMedia; import dan200.computercraft.core.computer.ComputerSide; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ServerComputerRegistry; import dan200.computercraft.shared.computer.core.ServerContext; import dan200.computercraft.shared.computer.items.IComputerItem; -import dan200.computercraft.shared.config.Config; import dan200.computercraft.shared.network.container.ComputerContainerData; import dan200.computercraft.shared.util.IDAssigner; import de.srendi.advancedperipherals.AdvancedPeripherals; @@ -188,11 +188,11 @@ public SmartGlassesComputer getOrCreateComputer(ServerLevel level, Entity entity if (computer == null) { int computerID = getComputerID(stack); if (computerID < 0) { - computerID = ComputerCraftAPI.createUniqueNumberedSaveDir(level.getServer(), IDAssigner.COMPUTER); + computerID = ComputerCraftAPI.createUniqueNumberedSaveDir(level, IDAssigner.COMPUTER); setComputerID(stack, computerID); } - computer = new SmartGlassesComputer(level, entity.blockPosition(), getComputerID(stack), getLabel(stack), getFamily()); + computer = new SmartGlassesComputer(level, getComputerID(stack), getLabel(stack), getFamily()); setInstanceID(stack, computer.register()); setSessionID(stack, registry.getSessionID()); @@ -237,10 +237,10 @@ public boolean setLabel(ItemStack stack, @Nullable String label) { @Nullable @Override - public Mount createDataMount(ItemStack stack, ServerLevel level) { + public IWritableMount createDataMount(@NotNull ItemStack stack, @NotNull Level level) { int id = getComputerID(stack); if (id >= 0) { - return ComputerCraftAPI.createSaveDirMount(level.getServer(), "computer/" + id, Config.computerSpaceLimit); + return ComputerCraftAPI.createSaveDirMount(level, "computer/" + id, ComputerCraft.computerSpaceLimit); } return null; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/network/DistanceDetectorSyncPacket.java b/src/main/java/de/srendi/advancedperipherals/common/network/DistanceDetectorSyncPacket.java index 267c8dad9..e8678202a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/network/DistanceDetectorSyncPacket.java +++ b/src/main/java/de/srendi/advancedperipherals/common/network/DistanceDetectorSyncPacket.java @@ -6,7 +6,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.core.BlockPos; -import net.minecraft.core.registries.Registries; +import net.minecraft.core.Registry; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceKey; import net.minecraft.world.level.Level; @@ -54,6 +54,6 @@ public void encode(FriendlyByteBuf buffer) { } public static DistanceDetectorSyncPacket decode(FriendlyByteBuf buffer) { - return new DistanceDetectorSyncPacket(buffer.readBlockPos(), buffer.readResourceKey(Registries.DIMENSION), buffer.readFloat(), buffer.readBoolean()); + return new DistanceDetectorSyncPacket(buffer.readBlockPos(), buffer.readResourceKey(Registry.DIMENSION_REGISTRY), buffer.readFloat(), buffer.readBoolean()); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APVillagers.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APVillagers.java index 3efecf50b..a91c83f7a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APVillagers.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APVillagers.java @@ -1,7 +1,7 @@ package de.srendi.advancedperipherals.common.setup; import com.google.common.collect.ImmutableSet; -import dan200.computercraft.shared.ModRegistry; +import dan200.computercraft.shared.Registry; import de.srendi.advancedperipherals.AdvancedPeripherals; import net.minecraft.sounds.SoundEvents; import net.minecraft.world.entity.ai.village.poi.PoiType; @@ -10,9 +10,9 @@ public class APVillagers { - public static final RegistryObject COMPUTER_SCIENTIST_POI = APRegistration.POI_TYPES.register("computer_scientist", () -> new PoiType(ImmutableSet.copyOf(ModRegistry.Blocks.COMPUTER_ADVANCED.get().getStateDefinition().getPossibleStates()), 1, 1)); + public static final RegistryObject COMPUTER_SCIENTIST_POI = APRegistration.POI_TYPES.register("computer_scientist", () -> new PoiType(ImmutableSet.copyOf(Registry.ModBlocks.COMPUTER_ADVANCED.get().getStateDefinition().getPossibleStates()), 1, 1)); - public static final RegistryObject COMPUTER_SCIENTIST = APRegistration.VILLAGER_PROFESSIONS.register("computer_scientist", () -> new VillagerProfession(AdvancedPeripherals.MOD_ID + ":computer_scientist", holder -> holder.is(COMPUTER_SCIENTIST_POI.getKey()), holder -> holder.is(COMPUTER_SCIENTIST_POI.getKey()), ImmutableSet.of(), ImmutableSet.of(ModRegistry.Blocks.COMPUTER_ADVANCED.get()), SoundEvents.VILLAGER_WORK_TOOLSMITH)); + public static final RegistryObject COMPUTER_SCIENTIST = APRegistration.VILLAGER_PROFESSIONS.register("computer_scientist", () -> new VillagerProfession(AdvancedPeripherals.MOD_ID + ":computer_scientist", holder -> holder.is(COMPUTER_SCIENTIST_POI.getKey()), holder -> holder.is(COMPUTER_SCIENTIST_POI.getKey()), ImmutableSet.of(), ImmutableSet.of(Registry.ModBlocks.COMPUTER_ADVANCED.get()), SoundEvents.VILLAGER_WORK_TOOLSMITH)); protected static void register() { } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java index 12e442003..bbddbc0a1 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java @@ -3,12 +3,11 @@ import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.pocket.IPocketAccess; import dan200.computercraft.api.pocket.IPocketUpgrade; -import dan200.computercraft.impl.PocketUpgrades; +import dan200.computercraft.shared.PocketUpgrades; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ServerComputer; import de.srendi.advancedperipherals.common.smartglasses.modules.IModule; import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleItem; -import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; @@ -38,8 +37,8 @@ public class SmartGlassesComputer extends ServerComputer implements IPocketAcces private final Set tracking = new HashSet<>(); private final Set modules = new HashSet<>(); - public SmartGlassesComputer(ServerLevel world, BlockPos position, int computerID, @Nullable String label, ComputerFamily family) { - super(world, position, computerID, label, family, 39, 13); + public SmartGlassesComputer(ServerLevel world, int computerID, @Nullable String label, ComputerFamily family) { + super(world, computerID, label, family, 39, 13); } @Nullable diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/FakePlayerProviderTurtle.java b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/FakePlayerProviderTurtle.java index 1923bdaaf..a008fe990 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/FakePlayerProviderTurtle.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/FakePlayerProviderTurtle.java @@ -2,7 +2,6 @@ import com.mojang.authlib.GameProfile; import dan200.computercraft.api.turtle.ITurtleAccess; -import dan200.computercraft.shared.util.InventoryUtil; import dan200.computercraft.shared.util.WorldUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -13,6 +12,8 @@ import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.ItemStack; +import net.minecraftforge.items.IItemHandlerModifiable; +import net.minecraftforge.items.ItemHandlerHelper; import java.util.WeakHashMap; import java.util.function.Function; @@ -79,19 +80,19 @@ public static void unload(APFakePlayer player, ITurtleAccess turtle) { } // Copy primary items into turtle inventory and then insert/drop the rest - Container turtleInventory = turtle.getInventory(); - int size = turtleInventory.getContainerSize(); + IItemHandlerModifiable turtleInventory = turtle.getItemHandler(); + int size = turtleInventory.getSlots(); int largerSize = playerInventory.getContainerSize(); playerInventory.selected = turtle.getSelectedSlot(); for (int i = 0; i < size; i++) { - turtleInventory.setItem(i, playerInventory.getItem(i)); + turtleInventory.setStackInSlot(i, playerInventory.getItem(i)); playerInventory.setItem(i, ItemStack.EMPTY); } for (int i = size; i < largerSize; i++) { ItemStack remaining = playerInventory.getItem(i); if (!remaining.isEmpty()) { - remaining = InventoryUtil.storeItemsFromOffset(turtleInventory, remaining, 0); + remaining = ItemHandlerHelper.insertItem(turtleInventory, remaining, false); if (!remaining.isEmpty()) { BlockPos position = turtle.getPosition(); WorldUtil.dropItemStack(remaining, turtle.getLevel(), position, turtle.getDirection().getOpposite()); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java index b09c91f58..1e398bff2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java @@ -5,7 +5,7 @@ import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.util.NBTUtil; import de.srendi.advancedperipherals.common.util.Pair; -import net.minecraft.core.registries.Registries; +import net.minecraft.core.Registry; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; import net.minecraft.resources.ResourceLocation; @@ -37,7 +37,7 @@ public static Pair parse(Map item) { try { String name = TableHelper.getStringField(item, "name"); if (name.startsWith("#")) { - fluidFilter.tag = TagKey.create(Registries.FLUID, new ResourceLocation(name.substring(1))); + fluidFilter.tag = TagKey.create(Registry.FLUID_REGISTRY, new ResourceLocation(name.substring(1))); } else if ((fluidFilter.fluid = ItemUtil.getRegistryEntry(name, ForgeRegistries.FLUIDS)) == null) { return Pair.of(null, "FLUID_NOT_FOUND"); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java index 4bf1ab614..174542f1c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java @@ -5,7 +5,7 @@ import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.util.NBTUtil; import de.srendi.advancedperipherals.common.util.Pair; -import net.minecraft.core.registries.Registries; +import net.minecraft.core.Registry; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; import net.minecraft.resources.ResourceLocation; @@ -33,13 +33,13 @@ private ItemFilter() { public static Pair parse(Map item) { ItemFilter itemFilter = empty(); // If the map is empty, return a filter without any filters - if (item.size() == 0) + if (item.isEmpty()) return Pair.of(itemFilter, null); if (item.containsKey("name")) { try { String name = TableHelper.getStringField(item, "name"); if (name.startsWith("#")) { - itemFilter.tag = TagKey.create(Registries.ITEM, new ResourceLocation(name.substring(1))); + itemFilter.tag = TagKey.create(Registry.ITEM_REGISTRY, new ResourceLocation(name.substring(1))); } else if ((itemFilter.item = ItemUtil.getRegistryEntry(name, ForgeRegistries.ITEMS)) == null) { return Pair.of(null, "ITEM_NOT_FOUND"); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemUtil.java index aa706d0b2..fbd61f7f2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemUtil.java @@ -1,6 +1,6 @@ package de.srendi.advancedperipherals.common.util.inventory; -import dan200.computercraft.shared.ModRegistry; +import dan200.computercraft.shared.Registry; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.util.StringUtil; import net.minecraft.ResourceLocationException; @@ -20,11 +20,11 @@ public class ItemUtil { - public static final Item TURTLE_NORMAL = ModRegistry.Items.TURTLE_NORMAL.get(); - public static final Item TURTLE_ADVANCED = ModRegistry.Items.TURTLE_ADVANCED.get(); + public static final Item TURTLE_NORMAL = Registry.ModItems.TURTLE_NORMAL.get(); + public static final Item TURTLE_ADVANCED = Registry.ModItems.TURTLE_ADVANCED.get(); - public static final Item POCKET_NORMAL = ModRegistry.Items.POCKET_COMPUTER_NORMAL.get(); - public static final Item POCKET_ADVANCED = ModRegistry.Items.POCKET_COMPUTER_ADVANCED.get(); + public static final Item POCKET_NORMAL = Registry.ModItems.POCKET_COMPUTER_NORMAL.get(); + public static final Item POCKET_ADVANCED = Registry.ModItems.POCKET_COMPUTER_ADVANCED.get(); public static T getRegistryEntry(String name, IForgeRegistry forgeRegistry) { ResourceLocation location; diff --git a/src/main/java/de/srendi/advancedperipherals/common/village/VillageStructures.java b/src/main/java/de/srendi/advancedperipherals/common/village/VillageStructures.java index af1b9c50a..8ee5518fa 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/village/VillageStructures.java +++ b/src/main/java/de/srendi/advancedperipherals/common/village/VillageStructures.java @@ -3,62 +3,49 @@ import com.mojang.datafixers.util.Pair; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.configuration.APConfig; -import net.minecraft.core.Holder; import net.minecraft.core.Registry; -import net.minecraft.core.registries.Registries; -import net.minecraft.resources.ResourceKey; +import net.minecraft.data.BuiltinRegistries; +import net.minecraft.data.worldgen.*; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.levelgen.structure.pools.SinglePoolElement; +import net.minecraft.util.RandomSource; import net.minecraft.world.level.levelgen.structure.pools.StructurePoolElement; import net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool; -import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessorList; -import net.minecraftforge.event.server.ServerAboutToStartEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; -import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; @Mod.EventBusSubscriber(modid = AdvancedPeripherals.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class VillageStructures { - // Adapted from Pneumaticcraft - private static void addPieceToPool(Registry templatePoolRegistry, Holder emptyProcessor, ResourceLocation poolRL, String nbtPieceRL, StructureTemplatePool.Projection projection, int weight) { - // Grab the pool we want to add to - StructureTemplatePool pool = templatePoolRegistry.get(poolRL); - if (pool == null) return; - - // Grabs the nbt piece and creates a SingleJigsawPiece of it that we can add to a structure's pool. - // Note: street pieces are a legacy_single_pool_piece type, houses are single_pool_piece - SinglePoolElement piece = poolRL.getPath().endsWith("streets") ? - SinglePoolElement.legacy(nbtPieceRL, emptyProcessor).apply(projection) : - SinglePoolElement.single(nbtPieceRL, emptyProcessor).apply(projection); - - // Weight is handled by how many times the entry appears in this list. - // We do not need to worry about immutability as this field is created using Lists.newArrayList(); which makes a mutable list. - for (int i = 0; i < weight; i++) { - pool.templates.add(piece); - } - // This list of pairs of pieces and weights is not used by vanilla by default but another mod may need it for efficiency. - // So let's add to this list for completeness. We need to make a copy of the array as it can be an immutable list. - List> listOfPieceEntries = new ArrayList<>(pool.rawTemplates); - listOfPieceEntries.add(new Pair<>(piece, weight)); - pool.rawTemplates = listOfPieceEntries; - } - - @SubscribeEvent - public static void addStructures(ServerAboutToStartEvent event) { + // Adapted from Pneumaticcraft + public static void init() { if (!APConfig.WORLD_CONFIG.enableVillagerStructures.get()) return; - - Holder emptyProcessor = event.getServer().registryAccess().registryOrThrow(Registries.PROCESSOR_LIST) - .getHolderOrThrow(ResourceKey.create(Registries.PROCESSOR_LIST, new ResourceLocation("minecraft:empty"))); - - Registry templatePoolRegistry = event.getServer().registryAccess().registryOrThrow(Registries.TEMPLATE_POOL); - + //Ensure the vanilla static init is done + PlainVillagePools.bootstrap(); + SavannaVillagePools.bootstrap(); + TaigaVillagePools.bootstrap(); + DesertVillagePools.bootstrap(); + SnowyVillagePools.bootstrap(); + //Add the scientist house to each village biome for (String biome : new String[]{"desert", "snowy", "plains", "savanna", "taiga"}) { AdvancedPeripherals.debug("Register generating scientist_" + biome + " village house"); - addPieceToPool(templatePoolRegistry, emptyProcessor, new ResourceLocation("village/" + biome + "/houses"), AdvancedPeripherals.MOD_ID + ":villages/scientist_" + biome, StructureTemplatePool.Projection.RIGID, APConfig.WORLD_CONFIG.villagerStructureWeight.get()); + addToPool(new ResourceLocation("village/" + biome + "/houses"), AdvancedPeripherals.MOD_ID + ":villages/scientist_" + biome, APConfig.WORLD_CONFIG.villagerStructureWeight.get()); + } + } + + private static void addToPool(ResourceLocation pool, String toAdd, int weight) { + StructureTemplatePool old = BuiltinRegistries.TEMPLATE_POOL.get(pool); + if (old == null) { + AdvancedPeripherals.debug("no jigsaw pool for " + pool + "? skipping villager house generation for it"); + return; } + List shuffled = old.getShuffledTemplates(RandomSource.createNewThreadLocalInstance()); + List> newPieces = shuffled.stream().map(p -> Pair.of(p, 1)).collect(Collectors.toList()); + StructurePoolElement newPiece = StructurePoolElement.legacy(toAdd).apply(StructureTemplatePool.Projection.RIGID); + newPieces.add(Pair.of(newPiece, weight)); + Registry.register(BuiltinRegistries.TEMPLATE_POOL, pool, new StructureTemplatePool(pool, old.getName(), newPieces)); + AdvancedPeripherals.debug("Finished registration for " + toAdd); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrades.java b/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrades.java index 0889d3167..f0ea18dd3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrades.java +++ b/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrades.java @@ -1,6 +1,6 @@ package de.srendi.advancedperipherals.common.village; -import dan200.computercraft.shared.ModRegistry; +import dan200.computercraft.shared.Registry; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.setup.APBlocks; import de.srendi.advancedperipherals.common.setup.APItems; @@ -22,7 +22,7 @@ public static void registerWanderingTrade(WandererTradesEvent event) { TradeBuilder.createTrade(event, APBlocks.PERIPHERAL_CASING.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 1, 1) .setMaxUses(8) .build(); - TradeBuilder.createTrade(event, ModRegistry.Blocks.TURTLE_ADVANCED.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 2, 1) + TradeBuilder.createTrade(event, Registry.ModBlocks.TURTLE_ADVANCED.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 2, 1) .setMaxUses(8) .build(); } @@ -36,7 +36,7 @@ public static void registerVillagerTrades(VillagerTradesEvent event) { .build(); TradeBuilder.createTrade(event, APBlocks.CHAT_BOX.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 2, 1) .build(); - TradeBuilder.createTrade(event, ModRegistry.Blocks.MONITOR_NORMAL.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 2, 1) + TradeBuilder.createTrade(event, Registry.ModBlocks.MONITOR_NORMAL.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 2, 1) .setItemAmount(2) .build(); TradeBuilder.createTrade(event, APBlocks.PERIPHERAL_CASING.get(), VillagerTrade.Type.EMERALD_FOR_ITEM, 1, 1) @@ -49,7 +49,7 @@ public static void registerVillagerTrades(VillagerTradesEvent event) { TradeBuilder.createTrade(event, APBlocks.REDSTONE_INTEGRATOR.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 2, 2) .setXp(3) .build(); - TradeBuilder.createTrade(event, ModRegistry.Blocks.COMPUTER_ADVANCED.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 3, 2) + TradeBuilder.createTrade(event, Registry.ModBlocks.COMPUTER_ADVANCED.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 3, 2) .setXp(4) .build(); @@ -69,7 +69,7 @@ public static void registerVillagerTrades(VillagerTradesEvent event) { .setMaxUses(1) .setXp(16) .build(); - TradeBuilder.createTrade(event, ModRegistry.Blocks.MONITOR_ADVANCED.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 6, 3) + TradeBuilder.createTrade(event, Registry.ModBlocks.MONITOR_ADVANCED.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 6, 3) .setXp(7) .setItemAmount(4) .build(); @@ -77,7 +77,7 @@ public static void registerVillagerTrades(VillagerTradesEvent event) { TradeBuilder.createTrade(event, APBlocks.ENERGY_DETECTOR.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 4, 4) .setXp(6) .build(); - TradeBuilder.createTrade(event, ModRegistry.Blocks.COMPUTER_ADVANCED.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 4, 4) + TradeBuilder.createTrade(event, Registry.ModBlocks.COMPUTER_ADVANCED.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 4, 4) .setXp(5) .setMaxUses(3) .build(); @@ -96,10 +96,10 @@ public static void registerVillagerTrades(VillagerTradesEvent event) { .setItemAmount(2) .setXp(4) .build(); - TradeBuilder.createTrade(event, ModRegistry.Blocks.SPEAKER.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 3, 5) + TradeBuilder.createTrade(event, Registry.ModBlocks.SPEAKER.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 3, 5) .setXp(6) .build(); - TradeBuilder.createTrade(event, ModRegistry.Blocks.WIRELESS_MODEM_ADVANCED.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 4, 5) + TradeBuilder.createTrade(event, Registry.ModBlocks.WIRELESS_MODEM_ADVANCED.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 4, 5) .setXp(8) .build(); From f1349b3cd70991a48b7488e70164e1c73699f5ee Mon Sep 17 00:00:00 2001 From: Deniz Date: Fri, 30 Jun 2023 23:41:56 +0200 Subject: [PATCH 045/228] Adapt to checkstyle rules --- .../common/data/BlockLootTablesProvider.java | 2 +- .../common/data/BlockTagsProvider.java | 2 +- .../advancedperipherals/common/data/RecipesProvider.java | 8 +++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTablesProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTablesProvider.java index 9c9913860..ffc964ddd 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTablesProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTablesProvider.java @@ -34,4 +34,4 @@ protected List map, ValidationContext validationtracker) { map.forEach((id, table) -> LootTables.validate(validationtracker, id, table)); } -} \ No newline at end of file +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/BlockTagsProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/BlockTagsProvider.java index b34c879d5..0ccd4f85e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/BlockTagsProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/BlockTagsProvider.java @@ -51,4 +51,4 @@ protected Path getPath(ResourceLocation block) { public String getName() { return "Block tags"; } -} \ No newline at end of file +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java index 4e893db04..58321dbd2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java @@ -60,17 +60,19 @@ private void addShapeless(@NotNull Consumer consumer) { .requires(APItems.HUSBANDRY_AUTOMATA_CORE.get()) .requires(Items.NETHER_STAR) .unlockedBy(HAS_ITEM, has(APItems.HUSBANDRY_AUTOMATA_CORE.get())) - .save(consumer); } + .save(consumer); + } private void addShaped(@NotNull Consumer consumer) { - /*ShapedRecipeBuilder.shaped(APItems.AR_GOGGLES.get()) + /*ShapedRecipeBuilder.shaped(APItems.AR_GOGGLES.get()) .define('E', Tags.Items.ENDER_PEARLS) .define('S', Tags.Items.RODS_WOODEN) .define('G', Tags.Items.GLASS_BLACK) .pattern("GSG") .pattern(" E ") .unlockedBy(HAS_ITEM, has(Items.STICK)) - .save(consumer);*/ + .save(consumer); + */ ShapedRecipeBuilder.shaped(APBlocks.CHAT_BOX.get()) .define('P', ItemTags.LOGS) From 0678a6b6e7fc0e90a9229bb90c128c6f481cc468 Mon Sep 17 00:00:00 2001 From: Deniz Date: Sat, 1 Jul 2023 00:40:57 +0200 Subject: [PATCH 046/228] Woopsy --- .../common/blocks/PlayerDetectorBlock.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/PlayerDetectorBlock.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/PlayerDetectorBlock.java index 5da7a86ff..fec9f22c5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/PlayerDetectorBlock.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/PlayerDetectorBlock.java @@ -4,7 +4,7 @@ import de.srendi.advancedperipherals.common.blocks.base.APBlockEntityBlock; import de.srendi.advancedperipherals.common.blocks.blockentities.PlayerDetectorEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; +import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; import net.minecraft.core.BlockPos; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; @@ -19,13 +19,13 @@ public class PlayerDetectorBlock extends APBlockEntityBlock { public PlayerDetectorBlock() { - super(BlockEntityTypes.PLAYER_DETECTOR, true); + super(APBlockEntityTypes.PLAYER_DETECTOR, true); } @Nullable @Override public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) { - return BlockEntityTypes.PLAYER_DETECTOR.get().create(pos, state); + return APBlockEntityTypes.PLAYER_DETECTOR.get().create(pos, state); } @Override From 2a96856b34999e6b0a7b43832c129395a646ae03 Mon Sep 17 00:00:00 2001 From: Deniz Date: Sat, 1 Jul 2023 00:56:25 +0200 Subject: [PATCH 047/228] Do some safety checks to satisfy sonar --- .../common/addons/refinedstorage/RefinedStorage.java | 4 ++-- .../common/items/SmartGlassesInterfaceItem.java | 2 +- .../advancedperipherals/common/items/SmartGlassesItem.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java index 75ff0a1e2..a316c965a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java @@ -86,8 +86,8 @@ public static FluidStack findFluidFromFilter(INetwork network, ICraftingManager return FluidStack.EMPTY; for (ICraftingPattern pattern : crafting.getPatterns()) { - if (pattern.getFluidOutputs().stream().anyMatch(filter::test)) - return pattern.getFluidOutputs().stream().filter(filter::test).findFirst().get().copy(); + Optional stack = pattern.getFluidOutputs().stream().filter(filter::test).findFirst(); + return stack.orElse(FluidStack.EMPTY); } return FluidStack.EMPTY; diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesInterfaceItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesInterfaceItem.java index cae4c81f4..1df0508ac 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesInterfaceItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesInterfaceItem.java @@ -55,7 +55,7 @@ public InteractionResultHolder use(@NotNull Level world, @NotNull Pla computer.turnOn(); LazyOptional itemHandler = glasses.getCapability(ForgeCapabilities.ITEM_HANDLER); - if (itemHandler.resolve().isEmpty()) { + if (!itemHandler.isPresent() || itemHandler.resolve().isEmpty()) { AdvancedPeripherals.debug("There was an issue with the item handler of the glasses while trying to open the gui"); return InteractionResultHolder.fail(player.getItemInHand(hand)); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java index c984ff4e6..6969588a2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java @@ -139,7 +139,7 @@ public InteractionResultHolder use(Level world, Player player, @NotNu computer.turnOn(); LazyOptional itemHandler = glasses.getCapability(ForgeCapabilities.ITEM_HANDLER); - if (itemHandler.resolve().isEmpty()) { + if (!itemHandler.isPresent() || itemHandler.resolve().isEmpty()) { AdvancedPeripherals.debug("There was an issue with the item handler of the glasses while trying to open the gui"); return InteractionResultHolder.sidedSuccess(player.getItemInHand(hand), world.isClientSide); } From bffd6791a2d26f8d7bfd82076ae0906c0234c1f9 Mon Sep 17 00:00:00 2001 From: Deniz Date: Sat, 1 Jul 2023 01:50:20 +0200 Subject: [PATCH 048/228] Fix creative tab Satisfy checkstyle --- build.gradle | 28 ++++----- .../advancedperipherals/APCreativeTab.java | 61 +++++++++++++++++++ .../AdvancedPeripherals.java | 12 +--- .../addons/refinedstorage/RefinedStorage.java | 2 +- .../items/SmartGlassesInterfaceItem.java | 4 +- 5 files changed, 79 insertions(+), 28 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/APCreativeTab.java diff --git a/build.gradle b/build.gradle index 06cd4211e..3ce4370b7 100644 --- a/build.gradle +++ b/build.gradle @@ -260,9 +260,9 @@ dependencies { implementation fg.deobf("org.squiddev:cc-tweaked-${minecraft_version}:${cc_version}") // Compile-time API required // Ae2 - compileOnly fg.deobf("appeng:appliedenergistics2-forge:${appliedenergistics_version}") + implementation fg.deobf("appeng:appliedenergistics2-forge:${appliedenergistics_version}") // Curios - compileOnly fg.deobf("top.theillusivec4.curios:curios-forge:${curios_version}:api") + implementation fg.deobf("top.theillusivec4.curios:curios-forge:${curios_version}:api") // Minimal requirements end // Extended requirements @@ -284,7 +284,7 @@ dependencies { //runtimeOnly fg.deobf("curse.maven:ae2things-609977:${ae2things_version}-sources") // Botania - implementation fg.deobf("vazkii.botania:Botania:${botania_version}") + compileOnly fg.deobf("vazkii.botania:Botania:${botania_version}") // Minecolonies // Change to compileOnly when running `runData` @@ -298,15 +298,15 @@ dependencies { runtimeOnly fg.deobf("vazkii.patchouli:Patchouli:${patchouli_version}") // Create - implementation fg.deobf("com.simibubi.create:create-${minecraft_version}:${create_version}:all") + compileOnly fg.deobf("com.simibubi.create:create-${minecraft_version}:${create_version}:all") //Removed until fully ported //testImplementation fg.deobf("site.siredvin.ttoolkit:ttoolkit-${minecraft_version}:${ttoolkit_version}") //Powah - implementation fg.deobf("curse.maven:powah-633483:${powah_version}") - implementation fg.deobf("me.shedaniel.cloth:cloth-config-forge:8.2.88") - implementation fg.deobf("dev.architectury:architectury-forge:6.2.43") + compileOnly fg.deobf("curse.maven:powah-633483:${powah_version}") + compileOnly fg.deobf("me.shedaniel.cloth:cloth-config-forge:8.2.88") + compileOnly fg.deobf("dev.architectury:architectury-forge:6.2.43") testImplementation "org.junit.jupiter:junit-jupiter-api:${junit_version}" testImplementation "org.junit.jupiter:junit-jupiter-params:${junit_version}" @@ -318,7 +318,7 @@ dependencies { testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junit_version}" // Testing stuff // JEI - implementation fg.deobf("mezz.jei:jei-${jei_version}") + compileOnly fg.deobf("mezz.jei:jei-${jei_version}") } @@ -341,7 +341,7 @@ compileTestModJava { dependsOn(compileJava) } -tasks.register('setupServer', Copy) { +task setupServer(type: Copy) { group "test server" description "Sets up the environment for the test server." @@ -377,10 +377,8 @@ test { } afterEvaluate { - tasks.withType(JavaCompile).tap { - configureEach { - options.compilerArgs << "-Xmaxerrs" << "2000" - } + tasks.withType(JavaCompile) { + options.compilerArgs << "-Xmaxerrs" << "2000" } } @@ -424,7 +422,8 @@ curseforge { } modrinth { - token = modrinthKey // This is the default. Remember to have the MODRINTH_TOKEN environment variable set or else this will fail, or set it to whatever you want - just make sure it stays private! + token = modrinthKey + // This is the default. Remember to have the MODRINTH_TOKEN environment variable set or else this will fail, or set it to whatever you want - just make sure it stays private! projectId = 'SOw6jD6x' // This can be the project ID or the slug. Either will work! versionNumber = "${minecraft_version}-${project.version}" versionName = "Advanced Peripherals ${minecraft_version} ${version}" @@ -461,6 +460,7 @@ publishing { } publications { gpr(MavenPublication) { + artifactId = "advancedperipherals" from(components.java) } } diff --git a/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java b/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java new file mode 100644 index 000000000..b9c021ebc --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java @@ -0,0 +1,61 @@ +package de.srendi.advancedperipherals; + +import de.srendi.advancedperipherals.common.setup.APBlocks; +import de.srendi.advancedperipherals.common.setup.APRegistration; +import de.srendi.advancedperipherals.common.setup.CCRegistration; +import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.ItemStack; +import net.minecraftforge.registries.RegistryObject; +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; +import java.util.Set; + +public class APCreativeTab extends CreativeModeTab { + public APCreativeTab() { + super("advancedperipheralstab"); + } + + @Override + @NotNull + public ItemStack makeIcon() { + return new ItemStack(APBlocks.CHAT_BOX.get()); + } + + @Override + public void fillItemList(@NotNull NonNullList pItems) { + APRegistration.ITEMS.getEntries().stream().map(RegistryObject::get).forEach(item -> pItems.add(new ItemStack(item))); + pItems.addAll(pocketUpgrade(CCRegistration.ID.COLONY_POCKET)); + pItems.addAll(pocketUpgrade(CCRegistration.ID.CHATTY_POCKET)); + pItems.addAll(pocketUpgrade(CCRegistration.ID.PLAYER_POCKET)); + pItems.addAll(pocketUpgrade(CCRegistration.ID.ENVIRONMENT_POCKET)); + pItems.addAll(pocketUpgrade(CCRegistration.ID.GEOSCANNER_POCKET)); + + pItems.addAll(turtleUpgrade(CCRegistration.ID.CHATTY_TURTLE)); + pItems.addAll(turtleUpgrade(CCRegistration.ID.CHUNKY_TURTLE)); + pItems.addAll(turtleUpgrade(CCRegistration.ID.COMPASS_TURTLE)); + pItems.addAll(turtleUpgrade(CCRegistration.ID.PLAYER_TURTLE)); + pItems.addAll(turtleUpgrade(CCRegistration.ID.ENVIRONMENT_TURTLE)); + pItems.addAll(turtleUpgrade(CCRegistration.ID.GEOSCANNER_TURTLE)); + + pItems.addAll(turtleUpgrade(CCRegistration.ID.WEAK_AUTOMATA)); + pItems.addAll(turtleUpgrade(CCRegistration.ID.OP_WEAK_AUTOMATA)); + pItems.addAll(turtleUpgrade(CCRegistration.ID.HUSBANDRY_AUTOMATA)); + pItems.addAll(turtleUpgrade(CCRegistration.ID.OP_HUSBANDRY_AUTOMATA)); + pItems.addAll(turtleUpgrade(CCRegistration.ID.END_AUTOMATA)); + pItems.addAll(turtleUpgrade(CCRegistration.ID.OP_END_AUTOMATA)); + } + + private static Collection pocketUpgrade(ResourceLocation pocketId) { + return Set.of(ItemUtil.makePocket(ItemUtil.POCKET_NORMAL, pocketId.toString()), + ItemUtil.makePocket(ItemUtil.POCKET_ADVANCED, pocketId.toString())); + } + + private static Collection turtleUpgrade(ResourceLocation pocketId) { + return Set.of(ItemUtil.makeTurtle(ItemUtil.TURTLE_NORMAL, pocketId.toString()), + ItemUtil.makeTurtle(ItemUtil.TURTLE_ADVANCED, pocketId.toString())); + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java index 1b6b30512..a009f1bf9 100644 --- a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java +++ b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java @@ -2,11 +2,8 @@ import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.network.PacketHandler; -import de.srendi.advancedperipherals.common.setup.APBlocks; import de.srendi.advancedperipherals.common.setup.APRegistration; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.CreativeModeTab; -import net.minecraft.world.item.ItemStack; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.ModLoadingContext; @@ -16,7 +13,6 @@ import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.jetbrains.annotations.NotNull; import java.util.Random; @@ -27,15 +23,9 @@ public class AdvancedPeripherals { public static final String NAME = "Advanced Peripherals"; public static final Logger LOGGER = LogManager.getLogger(NAME); public static final Random RANDOM = new Random(); - public static final CreativeModeTab TAB = new CreativeModeTab("advancedperipheralstab") { - @Override - @NotNull - public ItemStack makeIcon() { - return new ItemStack(APBlocks.CHAT_BOX.get()); - } + public static final APCreativeTab TAB = new APCreativeTab(); - }; public AdvancedPeripherals() { LOGGER.info("AdvancedPeripherals says hello!"); IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java index a316c965a..88c88f19c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java @@ -87,7 +87,7 @@ public static FluidStack findFluidFromFilter(INetwork network, ICraftingManager for (ICraftingPattern pattern : crafting.getPatterns()) { Optional stack = pattern.getFluidOutputs().stream().filter(filter::test).findFirst(); - return stack.orElse(FluidStack.EMPTY); + return stack.orElse(FluidStack.EMPTY); } return FluidStack.EMPTY; diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesInterfaceItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesInterfaceItem.java index 1df0508ac..a030b25e3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesInterfaceItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesInterfaceItem.java @@ -42,7 +42,7 @@ public InteractionResultHolder use(@NotNull Level world, @NotNull Pla if (APAddons.curiosLoaded) findGlasses = APAddons.getCurioGlasses(player); if (!findGlasses.is(APItems.SMART_GLASSES.get())) { player.displayClientMessage(Component.translatable("item.advancedperipherals.smartglasses.dontwear"), false); - return InteractionResultHolder.fail(findGlasses); + return super.use(world, player, hand); } } @@ -57,7 +57,7 @@ public InteractionResultHolder use(@NotNull Level world, @NotNull Pla LazyOptional itemHandler = glasses.getCapability(ForgeCapabilities.ITEM_HANDLER); if (!itemHandler.isPresent() || itemHandler.resolve().isEmpty()) { AdvancedPeripherals.debug("There was an issue with the item handler of the glasses while trying to open the gui"); - return InteractionResultHolder.fail(player.getItemInHand(hand)); + return super.use(world, player, hand); } NetworkHooks.openScreen((ServerPlayer) player, new SmartGlassesMenuProvider(computer, glasses, itemHandler.resolve().get()), bytes -> new ComputerContainerData(computer, glasses).toBytes(bytes)); From 61255d2716242fc0ad2dfb13aec543aba89efa9b Mon Sep 17 00:00:00 2001 From: Deniz Date: Sat, 1 Jul 2023 01:59:23 +0200 Subject: [PATCH 049/228] Fixing a bug which I made by mistake --- .../common/addons/refinedstorage/RefinedStorage.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java index 88c88f19c..59f17abf0 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java @@ -87,7 +87,8 @@ public static FluidStack findFluidFromFilter(INetwork network, ICraftingManager for (ICraftingPattern pattern : crafting.getPatterns()) { Optional stack = pattern.getFluidOutputs().stream().filter(filter::test).findFirst(); - return stack.orElse(FluidStack.EMPTY); + if (stack.isPresent()) + return stack.get().copy(); } return FluidStack.EMPTY; From 99d9b0b9cb2f30ccdbac8b91a3211e8d030df801 Mon Sep 17 00:00:00 2001 From: Deniz Date: Sat, 8 Jul 2023 03:11:17 +0200 Subject: [PATCH 050/228] Minor bug fixes and improvements for the smart glasses system Fixed that the entity of the SmartGlassesAccess is always null due to ignoring armor items when checking if the glasses are in the player's inventory Fixed that modules don't get loaded properly Fixed wrong slot texture if the peripherals tab is active Implement IPeripheralPlugin to the IModuleFunctions so we can easily add them to the glasses later --- gradle.properties | 4 +- .../client/screens/SmartGlassesScreen.java | 3 ++ .../common/items/SmartGlassesItem.java | 7 +++ .../smartglasses/SmartGlassesComputer.java | 52 +++++++++++++++---- .../smartglasses/SmartGlassesItemHandler.java | 3 +- .../common/smartglasses/modules/IModule.java | 2 +- .../modules/IModuleFunctions.java | 4 +- .../modules/ModulePeripheral.java | 5 +- .../overlay/OverlayGlassesFunctions.java | 14 +++++ .../modules/overlay/OverlayModule.java | 5 +- 10 files changed, 82 insertions(+), 17 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesFunctions.java diff --git a/gradle.properties b/gradle.properties index e99ab9f81..2407bac83 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ forge_version=43.2.14 mod_version=0.8r-DEV release_type=release mappings_channel=parchment -mappings_version=2022.09.18-1.19.2 +mappings_version=2022.11.20-1.19.2 jb_annotations=21.0.1 # Test dependencies @@ -19,7 +19,7 @@ kotlinx_coroutines_version=1.6.0-RC3 ttoolkit_version=0.1.3 # Mod dependencies -cc_version=1.101.2 +cc_version=1.101.3 curios_version=1.19.2-5.1.2.2 minecolonies_version=1.19.2-1.0.1410-ALPHA appliedenergistics_version=12.9.2 diff --git a/src/main/java/de/srendi/advancedperipherals/client/screens/SmartGlassesScreen.java b/src/main/java/de/srendi/advancedperipherals/client/screens/SmartGlassesScreen.java index 8e7d7cca1..9b4aa2346 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/screens/SmartGlassesScreen.java +++ b/src/main/java/de/srendi/advancedperipherals/client/screens/SmartGlassesScreen.java @@ -49,6 +49,9 @@ protected void renderBg(@NotNull PoseStack transform, float partialTicks, int mo RenderSystem.setShaderTexture(0, BACKGROUND); blit(transform, leftPos + ComputerSidebar.WIDTH, topPos, 0, 0, TEX_WIDTH, TEX_HEIGHT); + if (currentType == SlotType.PERIPHERALS) + blit(transform, leftPos + ComputerSidebar.WIDTH + 222, topPos + 183, 186, 183, 18, 18); + RenderSystem.setShaderTexture(0, SIDEBAR); ComputerSidebar.renderBackground(transform, leftPos, topPos + sidebarYOffset); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java index 6969588a2..5205041de 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java @@ -105,6 +105,13 @@ private boolean tick(ItemStack stack, Level world, Entity entity, SmartGlassesCo changed = true; computer.setEntity(entity); } + + ItemStack computerStack = computer.getStack(); + if (computerStack != stack) { + changed = true; + computer.setStack(stack); + } + return changed; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java index bbddbc0a1..76c5deae5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java @@ -13,11 +13,11 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraftforge.items.IItemHandler; +import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; import java.util.*; @@ -27,12 +27,16 @@ */ public class SmartGlassesComputer extends ServerComputer implements IPocketAccess { - private @Nullable Entity entity; - private final ItemStack stack = ItemStack.EMPTY; + @Nullable + private Entity entity; + private ItemStack stack = ItemStack.EMPTY; private final SmartGlassesAccess smartGlassesAccess = new SmartGlassesAccess(this); + @Nullable + private SmartGlassesItemHandler itemHandler; private int lightColour = -1; private boolean lightChanged = false; + private boolean isDirty = false; private final Set tracking = new HashSet<>(); private final Set modules = new HashSet<>(); @@ -44,13 +48,12 @@ public SmartGlassesComputer(ServerLevel world, int computerID, @Nullable String @Nullable @Override public Entity getEntity() { - if (entity == null || stack.isEmpty() || !entity.isAlive()) return null; + if (entity == null || stack.isEmpty() || !entity.isAlive()) + return null; if (entity instanceof Player player) { var inventory = player.getInventory(); - return inventory.items.contains(stack) || inventory.offhand.contains(stack) ? entity : null; - } else if (entity instanceof LivingEntity living) { - return living.getMainHandItem() == stack || living.getOffhandItem() == stack ? entity : null; + return inventory.items.contains(stack) || inventory.armor.contains(stack) || inventory.offhand.contains(stack) ? entity : null; } else if (entity instanceof ItemEntity itemEntity) { return itemEntity.getItem() == stack ? entity : null; } else { @@ -68,6 +71,14 @@ public void setColour(int colour) { // We don't have a color. } + public void setStack(ItemStack stack) { + this.stack = stack; + } + + public ItemStack getStack() { + return stack; + } + @Override public int getLight() { return lightColour; @@ -82,7 +93,20 @@ public void setLight(int colour) { lightChanged = true; } + public void setItemHandler(@Nullable SmartGlassesItemHandler itemHandler) { + this.itemHandler = itemHandler; + } + + public void markDirty() { + isDirty = true; + } + + public boolean isDirty() { + return isDirty; + } + @Override + @NotNull public CompoundTag getUpgradeNBTData() { return new CompoundTag(); } @@ -97,12 +121,13 @@ public void invalidatePeripheral() { } @Override + @NotNull public Map getUpgrades() { return Collections.emptyMap(); } public void updatePeripheralsAndModules(IItemHandler itemHandler) { - for (int slot = 0; slot < 5; slot++) { + for (int slot = 0; slot < 4; slot++) { ItemStack peripheralItem = itemHandler.getStackInSlot(slot); if (!peripheralItem.isEmpty()) { IPocketUpgrade upgrade = PocketUpgrades.instance().get(peripheralItem); @@ -114,7 +139,7 @@ public void updatePeripheralsAndModules(IItemHandler itemHandler) { } } modules.clear(); - for (int slot = 6; slot < 11; slot++) { + for (int slot = 4; slot < 11; slot++) { ItemStack peripheralItem = itemHandler.getStackInSlot(slot); if (!peripheralItem.isEmpty() && peripheralItem.getItem() instanceof IModuleItem module) { modules.add(module.getModule()); @@ -144,6 +169,11 @@ public void tickServer() { } modules.forEach(module -> module.tick(smartGlassesAccess)); + + if(isDirty()) + updatePeripheralsAndModules(itemHandler); + + isDirty = false; } public void setEntity(@Nullable Entity entity) { @@ -168,4 +198,8 @@ protected void onRemoved() { super.onRemoved(); } + @NotNull + public SmartGlassesAccess getSmartGlassesAccess() { + return smartGlassesAccess; + } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java index 381bba03a..fb3e19ac6 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java @@ -24,6 +24,7 @@ public SmartGlassesItemHandler(ItemStack stack, SmartGlassesComputer computer) { this.stack = stack; this.computer = computer; deserializeNBT(stack.getOrCreateTagElement("Items")); + computer.setItemHandler(this); } @Override @@ -124,7 +125,7 @@ public void setStackInSlot(int slot, @NotNull ItemStack stack) { public void setChanged() { stack.getOrCreateTag().put("Items", serializeNBT()); - computer.updatePeripheralsAndModules(this); + computer.markDirty(); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java index 2a1021807..4b254a952 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java @@ -12,7 +12,7 @@ public interface IModule { * * @return an object containing lua functions {@link dan200.computercraft.api.lua.LuaFunction} */ - IModuleFunctions getMethods(SmartGlassesAccess smartGlassesAccess); + IModuleFunctions getFunctions(SmartGlassesAccess smartGlassesAccess); void tick(SmartGlassesAccess smartGlassesAccess); diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModuleFunctions.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModuleFunctions.java index 6b873c4cb..3656500eb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModuleFunctions.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModuleFunctions.java @@ -1,10 +1,12 @@ package de.srendi.advancedperipherals.common.smartglasses.modules; +import de.srendi.advancedperipherals.lib.peripherals.IPeripheralPlugin; + /** * Used to define the available functions of the module. * Functions can be defined by creating final public methods annotated with the @{@link dan200.computercraft.api.lua.LuaFunction} annotation */ -public interface IModuleFunctions { +public interface IModuleFunctions extends IPeripheralPlugin { IModuleFunctions EMPTY = new IModuleFunctions() {}; diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java index 1fe4bb8a0..47d6e3081 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java @@ -13,6 +13,9 @@ public class ModulePeripheral extends BasePeripheral { public ModulePeripheral(SmartGlassesComputer computer) { super(PERIPHERAL_TYPE, new ModulePeripheralOwner(computer)); + getPeripheralOwner().getComputer().getModules().forEach(module -> + addPlugin(module.getFunctions(computer.getSmartGlassesAccess())) + ); } @Override @@ -20,7 +23,7 @@ public boolean isEnabled() { return true; } - @LuaFunction + @LuaFunction(mainThread = true) public final String[] getModules() { List modules = new ArrayList<>(getPeripheralOwner().getComputer().getModules().size()); getPeripheralOwner().getComputer().getModules().forEach(module -> modules.add(module.getName().toString())); diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesFunctions.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesFunctions.java new file mode 100644 index 000000000..fec953b13 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesFunctions.java @@ -0,0 +1,14 @@ +package de.srendi.advancedperipherals.common.smartglasses.modules.overlay; + +import dan200.computercraft.api.lua.LuaFunction; +import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleFunctions; + +public class OverlayGlassesFunctions implements IModuleFunctions { + + @LuaFunction + public final String test() { + return "Hello World! I'm an overlay module!"; + } + + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java index 2b34378e6..afbce8490 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java @@ -18,12 +18,13 @@ public ResourceLocation getName() { } @Override - public IModuleFunctions getMethods(SmartGlassesAccess smartGlassesAccess) { + public IModuleFunctions getFunctions(SmartGlassesAccess smartGlassesAccess) { return IModuleFunctions.EMPTY; } @Override public void tick(SmartGlassesAccess smartGlassesAccess) { - + if(smartGlassesAccess.getEntity().getLevel().getGameTime() % 20 == 0) + AdvancedPeripherals.LOGGER.info("I'm an overlay module! And I'm alive!"); } } From 7aa2617891fdf8f9502ccba572322738878a3821 Mon Sep 17 00:00:00 2001 From: Patricia Prehn Date: Mon, 10 Jul 2023 16:38:09 +0200 Subject: [PATCH 051/228] Fix some compiling and checkstyle issues. We still have some issues and bugs, not nothing too annoying --- .../AdvancedPeripherals.java | 11 ++++------ .../peripheral/MeBridgePeripheral.java | 14 ++---------- .../turtles/TurtleChatBoxUpgrade.java | 1 - .../blockentities/ColonyIntegratorEntity.java | 4 ++-- .../common/data/PocketUpgradesProvider.java | 10 ++++----- .../common/data/TurtleUpgradesProvider.java | 2 -- .../common/items/APBlockItem.java | 13 ----------- .../common/items/APItem.java | 14 ------------ .../common/setup/APBlockEntityTypes.java | 1 + .../common/setup/CCRegistration.java | 22 ++++--------------- .../common/setup/Villagers.java | 19 ---------------- 11 files changed, 18 insertions(+), 93 deletions(-) delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/setup/Villagers.java diff --git a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java index c6aa66bcc..6973f9954 100644 --- a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java +++ b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java @@ -1,12 +1,10 @@ package de.srendi.advancedperipherals; -import de.srendi.advancedperipherals.client.HudOverlayHandler; -import de.srendi.advancedperipherals.common.addons.APAddons; import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.setup.Blocks; -import de.srendi.advancedperipherals.common.setup.Registration; +import de.srendi.advancedperipherals.common.network.PacketHandler; +import de.srendi.advancedperipherals.common.setup.APBlocks; +import de.srendi.advancedperipherals.common.setup.APRegistration; import de.srendi.advancedperipherals.common.village.VillageStructures; -import de.srendi.advancedperipherals.network.MNetwork; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.ItemStack; @@ -14,7 +12,6 @@ import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import org.apache.logging.log4j.Level; @@ -36,7 +33,7 @@ public class AdvancedPeripherals { @Override @NotNull public ItemStack makeIcon() { - return new ItemStack(Blocks.CHAT_BOX.get()); + return new ItemStack(APBlocks.CHAT_BOX.get()); } }; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java index da75eefd2..b813d2678 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java @@ -468,7 +468,7 @@ public final MethodResult isItemCraftable(IArguments arguments) throws LuaExcept @LuaFunction(mainThread = true) public final MethodResult isFluidCrafting(IArguments arguments) throws LuaException { - if (!isConnected()) + if (!isAvailable()) return notConnected(); MEStorage monitor = AppEngApi.getMonitor(node); @@ -489,7 +489,7 @@ public final MethodResult isFluidCrafting(IArguments arguments) throws LuaExcept @LuaFunction(mainThread = true) public final MethodResult isFluidCraftable(IArguments arguments) throws LuaException { - if (!isConnected()) + if (!isAvailable()) return notConnected(); Pair filter = FluidFilter.parse(arguments.getTable(0)); @@ -526,16 +526,6 @@ public final MethodResult isItemCrafting(IArguments arguments) throws LuaExcepti return MethodResult.of(AppEngApi.isItemCrafting(monitor, grid, parsedFilter, craftingCPU)); } - @Override - public MethodResult isFluidCraftable(IArguments arguments) throws LuaException { - return null; - } - - @Override - public MethodResult isFluidCrafting(IArguments arguments) throws LuaException { - return null; - } - @LuaFunction(mainThread = true) public final MethodResult getCraftingCPUs() throws LuaException { if (!isAvailable()) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChatBoxUpgrade.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChatBoxUpgrade.java index 3474cef78..7a8f4d1bd 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChatBoxUpgrade.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChatBoxUpgrade.java @@ -4,7 +4,6 @@ import dan200.computercraft.api.turtle.TurtleSide; import dan200.computercraft.shared.computer.core.ServerComputer; import dan200.computercraft.shared.turtle.blocks.TileTurtle; -import dan200.computercraft.shared.turtle.blocks.TileTurtle; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.ChatBoxPeripheral; import de.srendi.advancedperipherals.common.events.Events; diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/ColonyIntegratorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/ColonyIntegratorEntity.java index 8c6504791..27e9d5e1f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/ColonyIntegratorEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/ColonyIntegratorEntity.java @@ -2,7 +2,7 @@ import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.ColonyPeripheral; import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; -import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; +import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; import net.minecraft.core.BlockPos; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.NotNull; @@ -10,7 +10,7 @@ public class ColonyIntegratorEntity extends PeripheralBlockEntity { public ColonyIntegratorEntity(BlockPos pos, BlockState state) { - super(BlockEntityTypes.COLONY_INTEGRATOR.get(), pos, state); + super(APBlockEntityTypes.COLONY_INTEGRATOR.get(), pos, state); } @NotNull diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/PocketUpgradesProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/PocketUpgradesProvider.java index 80b06bd23..385b75679 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/PocketUpgradesProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/PocketUpgradesProvider.java @@ -17,10 +17,10 @@ public PocketUpgradesProvider(DataGenerator output) { @Override protected void addUpgrades(@NotNull Consumer>> addUpgrade) { - simpleWithCustomItem(CCRegistration.ID.CHATTY_POCKET, CCRegistration.CHAT_BOX_POCKET.get(), Blocks.CHAT_BOX.get().asItem()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.PLAYER_POCKET, CCRegistration.PLAYER_DETECTOR_POCKET.get(), Blocks.PLAYER_DETECTOR.get().asItem()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.ENVIRONMENT_POCKET, CCRegistration.ENVIRONMENT_POCKET.get(), Blocks.ENVIRONMENT_DETECTOR.get().asItem()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.GEOSCANNER_POCKET, CCRegistration.GEO_SCANNER_POCKET.get(), Blocks.GEO_SCANNER.get().asItem()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.COLONY_POCKET, CCRegistration.COLONY_POCKET.get(), Blocks.COLONY_INTEGRATOR.get().asItem()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.CHATTY_POCKET, CCRegistration.CHAT_BOX_POCKET.get(), APBlocks.CHAT_BOX.get().asItem()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.PLAYER_POCKET, CCRegistration.PLAYER_DETECTOR_POCKET.get(), APBlocks.PLAYER_DETECTOR.get().asItem()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.ENVIRONMENT_POCKET, CCRegistration.ENVIRONMENT_POCKET.get(), APBlocks.ENVIRONMENT_DETECTOR.get().asItem()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.GEOSCANNER_POCKET, CCRegistration.GEO_SCANNER_POCKET.get(), APBlocks.GEO_SCANNER.get().asItem()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.COLONY_POCKET, CCRegistration.COLONY_POCKET.get(), APBlocks.COLONY_INTEGRATOR.get().asItem()).add(addUpgrade); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/TurtleUpgradesProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/TurtleUpgradesProvider.java index 5b832d83e..70ec6c177 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/TurtleUpgradesProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/TurtleUpgradesProvider.java @@ -6,8 +6,6 @@ import de.srendi.advancedperipherals.common.setup.APItems; import de.srendi.advancedperipherals.common.setup.CCRegistration; import net.minecraft.data.DataGenerator; -import de.srendi.advancedperipherals.common.setup.Items; -import net.minecraft.data.DataGenerator; import org.jetbrains.annotations.NotNull; import java.util.function.Consumer; diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/APBlockItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/APBlockItem.java index 1c94cbd7d..fbfc664f9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/APBlockItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/APBlockItem.java @@ -1,14 +1,7 @@ package de.srendi.advancedperipherals.common.items; import de.srendi.advancedperipherals.common.items.base.BaseBlockItem; -import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; -import net.minecraft.core.NonNullList; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.CreativeModeTab; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Block; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.function.Supplier; @@ -31,10 +24,4 @@ public boolean isEnabled() { return enabledSup.get(); } - @Override - public void fillItemCategory(@NotNull CreativeModeTab group, @NotNull NonNullList items) { - super.fillItemCategory(group, items); - if(allowedIn(group)) - ItemUtil.addComputerItemToTab(turtleID, pocketID, items); - } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/APItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/APItem.java index ed154599e..34ffcbeb5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/APItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/APItem.java @@ -1,13 +1,6 @@ package de.srendi.advancedperipherals.common.items; import de.srendi.advancedperipherals.common.items.base.BaseItem; -import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; -import net.minecraft.core.NonNullList; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.CreativeModeTab; -import net.minecraft.world.item.ItemStack; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.function.Supplier; @@ -30,11 +23,4 @@ public boolean isEnabled() { return enabledSup.get(); } - @Override - public void fillItemCategory(@NotNull CreativeModeTab group, @NotNull NonNullList items) { - super.fillItemCategory(group, items); - if(allowedIn(group)) - ItemUtil.addComputerItemToTab(turtleID, pocketID, items); - } - } diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java index 6dd40ce36..ab760488c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java @@ -23,6 +23,7 @@ protected static void register() { public static final RegistryObject> REDSTONE_INTEGRATOR = APRegistration.TILE_ENTITIES.register("redstone_integrator", () -> new BlockEntityType<>(RedstoneIntegratorEntity::new, Sets.newHashSet(APBlocks.REDSTONE_INTEGRATOR.get()), null)); public static final RegistryObject> BLOCK_READER = APRegistration.TILE_ENTITIES.register("block_reader", () -> new BlockEntityType<>(BlockReaderEntity::new, Sets.newHashSet(APBlocks.BLOCK_READER.get()), null)); public static final RegistryObject> GEO_SCANNER = APRegistration.TILE_ENTITIES.register("geo_scanner", () -> new BlockEntityType<>(GeoScannerEntity::new, Sets.newHashSet(APBlocks.GEO_SCANNER.get()), null)); + public static final RegistryObject> COLONY_INTEGRATOR = APRegistration.TILE_ENTITIES.register("colony_integrator", () -> new BlockEntityType<>(ColonyIntegratorEntity::new, Sets.newHashSet(APBlocks.COLONY_INTEGRATOR.get()), null)); public static final RegistryObject> NBT_STORAGE = APRegistration.TILE_ENTITIES.register("nbt_storage", () -> new BlockEntityType<>(NBTStorageEntity::new, Sets.newHashSet(APBlocks.NBT_STORAGE.get()), null)); public static final RegistryObject> DISTANCE_DETECTOR = APRegistration.TILE_ENTITIES.register("distance_detector", () -> new BlockEntityType<>(DistanceDetectorEntity::new, Sets.newHashSet(APBlocks.DISTANCE_DETECTOR.get()), null)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/CCRegistration.java b/src/main/java/de/srendi/advancedperipherals/common/setup/CCRegistration.java index 591860b75..11962445a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/CCRegistration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/CCRegistration.java @@ -5,23 +5,9 @@ import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.addons.computercraft.integrations.IntegrationPeripheralProvider; -import de.srendi.advancedperipherals.common.addons.computercraft.pocket.PocketChatBoxUpgrade; -import de.srendi.advancedperipherals.common.addons.computercraft.pocket.PocketColonyIntegratorUpgrade; -import de.srendi.advancedperipherals.common.addons.computercraft.pocket.PocketEnvironmentUpgrade; -import de.srendi.advancedperipherals.common.addons.computercraft.pocket.PocketGeoScannerUpgrade; -import de.srendi.advancedperipherals.common.addons.computercraft.pocket.PocketPlayerDetectorUpgrade; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.TurtleChatBoxUpgrade; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.TurtleChunkyUpgrade; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.TurtleCompassUpgrade; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.TurtleEnvironmentDetectorUpgrade; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.TurtleGeoScannerUpgrade; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.TurtlePlayerDetectorUpgrade; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.EndAutomata; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.HusbandryAutomata; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.OverpoweredEndAutomata; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.OverpoweredHusbandryAutomata; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.OverpoweredWeakAutomata; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.WeakAutomata; +import de.srendi.advancedperipherals.common.addons.computercraft.pocket.*; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.*; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.*; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.registries.RegistryObject; @@ -46,7 +32,7 @@ public class CCRegistration { public static final RegistryObject> PLAYER_DETECTOR_POCKET = APRegistration.POCKET_SERIALIZER.register(ID.PLAYER_POCKET.getPath(), () -> PocketUpgradeSerialiser.simpleWithCustomItem(PocketPlayerDetectorUpgrade::new)); public static final RegistryObject> ENVIRONMENT_POCKET = APRegistration.POCKET_SERIALIZER.register(ID.ENVIRONMENT_POCKET.getPath(), () -> PocketUpgradeSerialiser.simpleWithCustomItem(PocketEnvironmentUpgrade::new)); public static final RegistryObject> GEO_SCANNER_POCKET = APRegistration.POCKET_SERIALIZER.register(ID.GEOSCANNER_POCKET.getPath(), () -> PocketUpgradeSerialiser.simpleWithCustomItem(PocketGeoScannerUpgrade::new)); - public static final RegistryObject> COLONY_POCKET = Registration.POCKET_SERIALIZER.register(ID.COLONY_POCKET.getPath(), () -> PocketUpgradeSerialiser.simpleWithCustomItem(PocketColonyIntegratorUpgrade::new)); + public static final RegistryObject> COLONY_POCKET = APRegistration.POCKET_SERIALIZER.register(ID.COLONY_POCKET.getPath(), () -> PocketUpgradeSerialiser.simpleWithCustomItem(PocketColonyIntegratorUpgrade::new)); public static IntegrationPeripheralProvider integrationPeripheralProvider; diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/Villagers.java b/src/main/java/de/srendi/advancedperipherals/common/setup/Villagers.java deleted file mode 100644 index df00d9d8f..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/Villagers.java +++ /dev/null @@ -1,19 +0,0 @@ -package de.srendi.advancedperipherals.common.setup; - -import com.google.common.collect.ImmutableSet; -import dan200.computercraft.shared.Registry; -import de.srendi.advancedperipherals.AdvancedPeripherals; -import net.minecraft.sounds.SoundEvents; -import net.minecraft.world.entity.ai.village.poi.PoiType; -import net.minecraft.world.entity.npc.VillagerProfession; -import net.minecraftforge.registries.RegistryObject; - -public class Villagers { - - public static final RegistryObject COMPUTER_SCIENTIST_POI = Registration.POI_TYPES.register("computer_scientist", () -> new PoiType(ImmutableSet.copyOf(Registry.ModBlocks.COMPUTER_ADVANCED.get().getStateDefinition().getPossibleStates()), 1, 1)); - public static final RegistryObject COMPUTER_SCIENTIST = Registration.VILLAGER_PROFESSIONS.register("computer_scientist", () -> new VillagerProfession(AdvancedPeripherals.MOD_ID + ":computer_scientist", holder -> holder.is(COMPUTER_SCIENTIST_POI.getKey()), holder -> holder.is(COMPUTER_SCIENTIST_POI.getKey()), ImmutableSet.of(), ImmutableSet.of(Registry.ModBlocks.COMPUTER_ADVANCED.get()), SoundEvents.VILLAGER_WORK_TOOLSMITH)); - - public static void register() { - } - -} From 2704ee7fc4751a3341f4d782340e1d68244cbcb3 Mon Sep 17 00:00:00 2001 From: Patricia Prehn Date: Thu, 13 Jul 2023 10:48:12 +0200 Subject: [PATCH 052/228] Refactor imports, improve comment clarity and fix that `APAddons` wasn't initialized --- .../java/de/srendi/advancedperipherals/APCreativeTab.java | 8 ++++---- .../srendi/advancedperipherals/AdvancedPeripherals.java | 3 ++- .../srendi/advancedperipherals/common/util/CoordUtil.java | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java b/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java index dcdd0c566..52eba5e66 100644 --- a/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java +++ b/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java @@ -1,8 +1,8 @@ package de.srendi.advancedperipherals; -import de.srendi.advancedperipherals.common.setup.Blocks; +import de.srendi.advancedperipherals.common.setup.APBlocks; +import de.srendi.advancedperipherals.common.setup.APRegistration; import de.srendi.advancedperipherals.common.setup.CCRegistration; -import de.srendi.advancedperipherals.common.setup.Registration; import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; import net.minecraft.core.NonNullList; import net.minecraft.resources.ResourceLocation; @@ -22,7 +22,7 @@ public APCreativeTab() { @Override public void fillItemList(NonNullList items) { - Registration.ITEMS.getEntries().stream().map(RegistryObject::get).forEach(item -> items.add(new ItemStack(item))); + APRegistration.ITEMS.getEntries().stream().map(RegistryObject::get).forEach(item -> items.add(new ItemStack(item))); items.addAll(pocketUpgrade(CCRegistration.ID.COLONY_POCKET)); items.addAll(pocketUpgrade(CCRegistration.ID.CHATTY_POCKET)); items.addAll(pocketUpgrade(CCRegistration.ID.PLAYER_POCKET)); @@ -57,6 +57,6 @@ private static Collection turtleUpgrade(ResourceLocation pocketId) { @Override @NotNull public ItemStack makeIcon() { - return new ItemStack(Blocks.CHAT_BOX.get()); + return new ItemStack(APBlocks.CHAT_BOX.get()); } } diff --git a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java index 7580c3351..8edc827e7 100644 --- a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java +++ b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java @@ -1,8 +1,8 @@ package de.srendi.advancedperipherals; +import de.srendi.advancedperipherals.common.addons.APAddons; import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.network.PacketHandler; -import de.srendi.advancedperipherals.common.setup.APBlocks; import de.srendi.advancedperipherals.common.setup.APRegistration; import de.srendi.advancedperipherals.common.village.VillageStructures; import net.minecraft.resources.ResourceLocation; @@ -53,6 +53,7 @@ public static ResourceLocation getRL(String resource) { } public void commonSetup(FMLCommonSetupEvent event) { + APAddons.commonSetup(); event.enqueueWork(() -> { PacketHandler.init(); VillageStructures.init(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java index af4c3f493..ad3e3c71f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java @@ -18,7 +18,7 @@ public class CoordUtil { public static boolean isInRange(@Nullable BlockPos pos, @Nullable Level world, @Nullable Player player, int range) { - // There are rare cases where these are null. For example if a player detector pocket computer runs while not in a player inventory + // There are rare cases where these can be null. For example if a player detector pocket computer runs while not in a player inventory // Fixes https://github.com/SirEndii/AdvancedPeripherals/issues/356 if (pos == null || world == null || player == null) return false; From ebd9e14c4fc1b9249be1eeb9391781400b3f86cb Mon Sep 17 00:00:00 2001 From: Deniz Date: Sun, 23 Jul 2023 18:34:01 +0200 Subject: [PATCH 053/228] Remove `DEV` from the version since our pipeline does handle this automatically --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 4bd94dad1..f732335e0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ mod_id=advancedperipherals minecraft_version=1.19.2 forge_version=43.2.14 loader_version=43 -mod_version=0.8r-DEV +mod_version=0.8r release_type=release mappings_channel=parchment mappings_version=2022.11.20-1.19.2 From 4b420e29e7bab86632acc210e234e455e23441f2 Mon Sep 17 00:00:00 2001 From: Deniz Date: Sun, 23 Jul 2023 21:58:46 +0200 Subject: [PATCH 054/228] Change the loading of our APAddons class to static loading since the older variation was called too late which led to not functioning features --- .../de/srendi/advancedperipherals/AdvancedPeripherals.java | 2 +- .../srendi/advancedperipherals/common/addons/APAddons.java | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java index 8edc827e7..2381c515f 100644 --- a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java +++ b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java @@ -26,6 +26,7 @@ public class AdvancedPeripherals { public static final Logger LOGGER = LogManager.getLogger(NAME); public static final Random RANDOM = new Random(); public static final APCreativeTab TAB = new APCreativeTab(); + public static final APAddons ADDONS = new APAddons(); public AdvancedPeripherals() { LOGGER.info("AdvancedPeripherals says hello!"); @@ -53,7 +54,6 @@ public static ResourceLocation getRL(String resource) { } public void commonSetup(FMLCommonSetupEvent event) { - APAddons.commonSetup(); event.enqueueWork(() -> { PacketHandler.init(); VillageStructures.init(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java b/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java index c40223754..91a4fc573 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java @@ -31,10 +31,8 @@ public class APAddons { public static boolean appliedEnergisticsLoaded; public static boolean mekanismLoaded; - private APAddons() { - } - - public static void commonSetup() { + // Use static so these checks run as early as possible, so we can use them for our registries + static { ModList modList = ModList.get(); curiosLoaded = modList.isLoaded(CURIOS_MODID); refinedStorageLoaded = modList.isLoaded(REFINEDSTORAGE_MODID); From 98cb7121cb32486c5753ea630af17d1eae598d95 Mon Sep 17 00:00:00 2001 From: Deniz Date: Sat, 12 Aug 2023 04:09:51 +0200 Subject: [PATCH 055/228] Check the style --- .../common/items/SmartGlassesItem.java | 18 ++++++++++++------ .../smartglasses/SmartGlassesComputer.java | 9 ++++++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java index 5205041de..5015376a1 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java @@ -117,13 +117,15 @@ private boolean tick(ItemStack stack, Level world, Entity entity, SmartGlassesCo @Override public void inventoryTick(@NotNull ItemStack stack, Level world, @NotNull Entity entity, int slotNum, boolean selected) { - if (world.isClientSide) return; + if (world.isClientSide) + return; Container inventory = entity instanceof Player player ? player.getInventory() : null; SmartGlassesComputer computer = getOrCreateComputer((ServerLevel) world, entity, inventory, stack); computer.keepAlive(); var changed = tick(stack, world, entity, computer); - if (changed && inventory != null) inventory.setChanged(); + if (changed && inventory != null) + inventory.setChanged(); } @Override @@ -157,8 +159,10 @@ public InteractionResultHolder use(Level world, Player player, @NotNu public ItemStack create(int id, @Nullable String label) { ItemStack result = new ItemStack(this); - if (id >= 0) result.getOrCreateTag().putInt(NBT_ID, id); - if (label != null) result.setHoverName(Component.literal(label)); + if (id >= 0) + result.getOrCreateTag().putInt(NBT_ID, id); + if (label != null) + result.setHoverName(Component.literal(label)); return result; } @@ -208,9 +212,11 @@ public SmartGlassesComputer getOrCreateComputer(ServerLevel level, Entity entity computer.addAPI(new SmartGlassesAPI()); // Only turn on when initially creating the computer, rather than each tick. - if (isMarkedOn(stack) && entity instanceof Player) computer.turnOn(); + if (isMarkedOn(stack) && entity instanceof Player) + computer.turnOn(); - if (inventory != null) inventory.setChanged(); + if (inventory != null) + inventory.setChanged(); } computer.setLevel(level); return computer; diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java index 76c5deae5..a2fcbb9bf 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java @@ -88,7 +88,8 @@ public int getLight() { public void setLight(int colour) { if (colour < 0 || colour > 0xFFFFFF) colour = -1; - if (lightColour == colour) return; + if (lightColour == colour) + return; lightColour = colour; lightChanged = true; } @@ -113,7 +114,8 @@ public CompoundTag getUpgradeNBTData() { @Override public void updateUpgradeNBTData() { - if (entity instanceof Player player) player.getInventory().setChanged(); + if (entity instanceof Player player) + player.getInventory().setChanged(); } @Override @@ -164,7 +166,8 @@ public void tickServer() { // Broadcast the state to new players. List added = new ArrayList<>(); for (var player : getLevel().players()) { - if (tracking.add(player)) added.add(player); + if (tracking.add(player)) + added.add(player); } } From 382963d47a97b9b191c09b8b668c581254ceec93 Mon Sep 17 00:00:00 2001 From: Deniz Demiroglu Date: Mon, 18 Sep 2023 16:29:30 +0200 Subject: [PATCH 056/228] copy cat --- .../peripheral/MeBridgePeripheral.java | 68 ------------------- 1 file changed, 68 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java index 74a09cd3f..ffeb22eae 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java @@ -257,30 +257,6 @@ public final MethodResult exportItemToPeripheral(IComputerAccess computer, IArgu return exportToChest(arguments, inventory); } - @Override - public final MethodResult importFluid(IArguments arguments) throws LuaException { - IFluidHandler handler = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); - return importToME(arguments, handler); - } - - @Override - public final MethodResult exportFluid(@NotNull IArguments arguments) throws LuaException { - IFluidHandler handler = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); - return exportToTank(arguments, handler); - } - - @Override - public final MethodResult importFluidFromPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { - IFluidHandler handler = FluidUtil.getHandlerFromName(computer, arguments.getString(1)); - return importToME(arguments, handler); - } - - @Override - public final MethodResult exportFluidToPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { - IFluidHandler handler = FluidUtil.getHandlerFromName(computer, arguments.getString(1)); - return exportToTank(arguments, handler); - } - @Override public MethodResult getPattern(IArguments arguments) throws LuaException { return null; @@ -549,50 +525,6 @@ public final MethodResult importFluidFromPeripheral(IComputerAccess computer, IA return importToME(arguments, handler); } - @LuaFunction(mainThread = true) - public final MethodResult exportItem(@NotNull IArguments arguments) throws LuaException { - if (!isConnected()) - return notConnected(); - - IItemHandler inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); - return exportToChest(arguments, inventory); - } - - @LuaFunction(mainThread = true) - public final MethodResult exportItemToPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { - if (!isConnected()) - return notConnected(); - - IItemHandler inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); - - if (inventory == null) - return MethodResult.of(0, "The target inventory does not exist. Make sure the bridge is exposed in the computer network. Reach out to our discord or our documentation for help."); - - return exportToChest(arguments, inventory); - } - - @LuaFunction(mainThread = true) - public final MethodResult importItem(IArguments arguments) throws LuaException { - if (!isConnected()) - return notConnected(); - - IItemHandler inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); - return importToME(arguments, inventory); - } - - @LuaFunction(mainThread = true) - public final MethodResult importItemFromPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { - if (!isConnected()) - return notConnected(); - - IItemHandler inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); - - if (inventory == null) - return MethodResult.of(0, "The target inventory does not exist. Make sure the bridge is exposed in the computer network. Reach out to our discord or our documentation for help."); - - return importToME(arguments, inventory); - } - @Override public final MethodResult isItemCrafting(IArguments arguments) throws LuaException { if (!isAvailable()) From 5551c2c19beccf85768bef236e64f2c5cb041687 Mon Sep 17 00:00:00 2001 From: Deniz Demiroglu Date: Mon, 25 Sep 2023 15:22:55 +0200 Subject: [PATCH 057/228] Runned datagen --- .../2db41954e490230d51b10affff25ee2ee27b8d5b | 2 +- .../5a761efb7472ef97566e41e81451930a004134bf | 2 +- ... 67cce32b1c3cbbcb1f646605f4914e3f196986c2} | 3 +- .../9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e | 80 +++++++++---------- .../ae219fa7c7d3297c14e454863eac3998a4eab78c | 2 +- .../b8526e444ae7356037f3a813274f6835d1f3dd16 | 4 +- .../c622617f6fabf890a00b9275cd5f643584a8a2c8 | 4 +- .../f95c7003282837dabaa33e3ffceec4e6865b5218 | 8 +- .../blockstates/ar_controller.json | 57 ------------- .../advancedperipherals/lang/en_us.json | 14 ++-- .../models/block/ar_controller.json | 8 -- .../block_reader.json | 0 .../chat_box.json | 0 .../chunk_controller.json | 0 .../computer_tool.json | 0 .../energy_detector.json | 0 .../environment_detector.json | 0 .../geo_scanner.json | 0 .../inventory_manager.json | 0 .../memory_card.json | 0 .../nbt_storage.json | 0 .../overpowered_end_automata_core.json | 0 .../overpowered_husbandry_automata_core.json | 0 .../overpowered_weak_automata_core.json | 0 .../peripheral_casing.json | 0 .../player_detector.json | 0 .../redstone_integrator.json | 0 .../weak_automata_core.json | 0 .../recipes/redstone/ar_controller.json | 34 -------- .../armor/smart_glasses_netherite.json | 34 -------- .../recipes/redstone/smart_glasses.json | 34 -------- .../loot_tables/blocks/ar_controller.json | 20 ----- .../recipes/ar_controller.json | 22 ----- .../armor/smart_glasses_netherite.json | 12 --- .../recipes/colony_integrator.json | 1 - .../recipes/me_bridge.json | 35 ++++++++ .../recipes/rs_bridge.json | 35 ++++++++ .../recipes/smart_glasses.json | 29 ------- .../forge/tags/blocks/needs_wood_tool.json | 3 +- .../tags/blocks/mineable/pickaxe.json | 1 - .../tags/blocks/needs_iron_tool.json | 2 - .../common/data/RecipesProvider.java | 2 +- 42 files changed, 131 insertions(+), 317 deletions(-) rename src/generated/resources/.cache/{59eb3dbb5f86130e09b3c62d89b9525ee01cf52d => 67cce32b1c3cbbcb1f646605f4914e3f196986c2} (91%) delete mode 100644 src/generated/resources/assets/advancedperipherals/blockstates/ar_controller.json delete mode 100644 src/generated/resources/assets/advancedperipherals/models/block/ar_controller.json rename src/generated/resources/data/advancedperipherals/advancements/recipes/{redstone => advancedperipheralstab}/block_reader.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{redstone => advancedperipheralstab}/chat_box.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{redstone => advancedperipheralstab}/chunk_controller.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{redstone => advancedperipheralstab}/computer_tool.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{redstone => advancedperipheralstab}/energy_detector.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{redstone => advancedperipheralstab}/environment_detector.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{redstone => advancedperipheralstab}/geo_scanner.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{redstone => advancedperipheralstab}/inventory_manager.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{redstone => advancedperipheralstab}/memory_card.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{redstone => advancedperipheralstab}/nbt_storage.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{redstone => advancedperipheralstab}/overpowered_end_automata_core.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{redstone => advancedperipheralstab}/overpowered_husbandry_automata_core.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{redstone => advancedperipheralstab}/overpowered_weak_automata_core.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{redstone => advancedperipheralstab}/peripheral_casing.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{redstone => advancedperipheralstab}/player_detector.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{redstone => advancedperipheralstab}/redstone_integrator.json (100%) rename src/generated/resources/data/advancedperipherals/advancements/recipes/{redstone => advancedperipheralstab}/weak_automata_core.json (100%) delete mode 100644 src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/ar_controller.json delete mode 100644 src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/armor/smart_glasses_netherite.json delete mode 100644 src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/smart_glasses.json delete mode 100644 src/generated/resources/data/advancedperipherals/loot_tables/blocks/ar_controller.json delete mode 100644 src/generated/resources/data/advancedperipherals/recipes/ar_controller.json delete mode 100644 src/generated/resources/data/advancedperipherals/recipes/armor/smart_glasses_netherite.json create mode 100644 src/generated/resources/data/advancedperipherals/recipes/me_bridge.json create mode 100644 src/generated/resources/data/advancedperipherals/recipes/rs_bridge.json delete mode 100644 src/generated/resources/data/advancedperipherals/recipes/smart_glasses.json diff --git a/src/generated/resources/.cache/2db41954e490230d51b10affff25ee2ee27b8d5b b/src/generated/resources/.cache/2db41954e490230d51b10affff25ee2ee27b8d5b index 601f02d7a..834374d4a 100644 --- a/src/generated/resources/.cache/2db41954e490230d51b10affff25ee2ee27b8d5b +++ b/src/generated/resources/.cache/2db41954e490230d51b10affff25ee2ee27b8d5b @@ -1,2 +1,2 @@ -// 1.19.3 2022-12-20T12:47:00.0699917 AP POI Type Tags +// 1.19.2 2023-09-25T15:21:21.7663044 AP POI Type Tags d3d6b837660a4e213f287ad9d11e12368b90cd8e data/minecraft/tags/point_of_interest_type/acquirable_job_site.json diff --git a/src/generated/resources/.cache/5a761efb7472ef97566e41e81451930a004134bf b/src/generated/resources/.cache/5a761efb7472ef97566e41e81451930a004134bf index bf74b4055..863bee0d1 100644 --- a/src/generated/resources/.cache/5a761efb7472ef97566e41e81451930a004134bf +++ b/src/generated/resources/.cache/5a761efb7472ef97566e41e81451930a004134bf @@ -1,4 +1,4 @@ -// 1.19.3 2022-12-20T12:47:00.0559511 Turtle Upgrades +// 1.19.2 2023-09-25T15:21:21.7927076 Turtle Upgrades b8f19ae0fb5bb898facc08e3787e0f96c8211881 data/advancedperipherals/computercraft/turtle_upgrades/chatty_turtle.json fe98c60e7d61139aacf2d0872873e610aac8a37b data/advancedperipherals/computercraft/turtle_upgrades/chunky_turtle.json ae619da638ad89d7302d832d6c09e2c87401c539 data/advancedperipherals/computercraft/turtle_upgrades/compass_turtle.json diff --git a/src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d b/src/generated/resources/.cache/67cce32b1c3cbbcb1f646605f4914e3f196986c2 similarity index 91% rename from src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d rename to src/generated/resources/.cache/67cce32b1c3cbbcb1f646605f4914e3f196986c2 index 6b4cf1780..5362386e5 100644 --- a/src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d +++ b/src/generated/resources/.cache/67cce32b1c3cbbcb1f646605f4914e3f196986c2 @@ -1,5 +1,4 @@ -// 1.19.3 2023-03-17T14:14:31.5837804 Loot Tables -fecb8d92386c87945125ce5e4266faeb8275b540 data/advancedperipherals/loot_tables/blocks/ar_controller.json +// 1.19.2 2023-09-25T15:21:21.7873091 LootTables d865e8ac35302c486faf5c7122569c554186186d data/advancedperipherals/loot_tables/blocks/block_reader.json a6f896cc3dbd8da12737825ec71e32970f54025c data/advancedperipherals/loot_tables/blocks/chat_box.json f50f506ae1987537f76be4c05a81689b25798f91 data/advancedperipherals/loot_tables/blocks/colony_integrator.json diff --git a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e index eda98d326..cc3692f50 100644 --- a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e +++ b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e @@ -1,42 +1,38 @@ -// 1.19.3 2023-03-17T14:14:31.5938615 Recipes -045608027e4a5ea2d7dee7f402346b8e69f21675 data/advancedperipherals/advancements/recipes/redstone/armor/smart_glasses_netherite.json -f472724394edd655a415d4af08c9a63509cc5098 data/advancedperipherals/advancements/recipes/redstone/ar_controller.json -db2dada2fdf42ca1bbf47f1eb075d1f9de89dfa8 data/advancedperipherals/advancements/recipes/redstone/block_reader.json -77c55e8500be4a344ca563a8bf7642257cdc7b8b data/advancedperipherals/advancements/recipes/redstone/chat_box.json -96208b06b0c3c125762cd517506a5ffb6b1d55ac data/advancedperipherals/advancements/recipes/redstone/chunk_controller.json -eb1d84b0b82fd6671876d0885746f9e3e15803e3 data/advancedperipherals/advancements/recipes/redstone/computer_tool.json -5a1e92ee63dce1cb74c56b7e70587a0c54132de4 data/advancedperipherals/advancements/recipes/redstone/energy_detector.json -34d04b885af7947279752129f1f6e107cdf3cf05 data/advancedperipherals/advancements/recipes/redstone/environment_detector.json -91af310c4f272e800172a7f7e717fa29fc35dc62 data/advancedperipherals/advancements/recipes/redstone/geo_scanner.json -65184f82a2fe743edc4db31c0c362c74d1e4df84 data/advancedperipherals/advancements/recipes/redstone/inventory_manager.json -e575414582eb367f0689a3a90fc75aca2d6cd2fc data/advancedperipherals/advancements/recipes/redstone/memory_card.json -cb79be6d0ee7890abb2238b53edd55fd2338ed81 data/advancedperipherals/advancements/recipes/redstone/nbt_storage.json -e2d8bd0a887eb42d05f460d6fee007b7bb4c533c data/advancedperipherals/advancements/recipes/redstone/overpowered_end_automata_core.json -1db7ed04f8af5413308160b03f5b21d5932195f5 data/advancedperipherals/advancements/recipes/redstone/overpowered_husbandry_automata_core.json -d3d8709f4fdb3d68613d751bba5b9a94b8842046 data/advancedperipherals/advancements/recipes/redstone/overpowered_weak_automata_core.json -d27c1267208fd9036c5c45f7f6cbd4f6f67b3845 data/advancedperipherals/advancements/recipes/redstone/peripheral_casing.json -d8870644bb7d48c5ae33dcea2afbcfa106729d7b data/advancedperipherals/advancements/recipes/redstone/player_detector.json -7acff70533792bd089a655f8f24cdea6995aac0c data/advancedperipherals/advancements/recipes/redstone/redstone_integrator.json -c0373a4597bfbd9b005cbe0a6289779ffd4053ea data/advancedperipherals/advancements/recipes/redstone/smart_glasses.json -fc0c3d99bec43318802f357083c7d98fde92567f data/advancedperipherals/advancements/recipes/redstone/weak_automata_core.json -66999fea36aa4113567753f104630f6490dda6ba data/advancedperipherals/recipes/armor/smart_glasses_netherite.json -37c811b8a2537af60e96cc4fda950538b8bd041d data/advancedperipherals/recipes/ar_controller.json -f8acf88364459d1b38a9ac0fc3a2e87821f98edf data/advancedperipherals/recipes/block_reader.json -b1f3b9f50e62e2f53b23ad14248cb91acb745c37 data/advancedperipherals/recipes/chat_box.json -3c6f45e5977b200c900a71bad4b531d2b7e1164c data/advancedperipherals/recipes/chunk_controller.json -6d66e5c84b0cad46dfa654107499b45adfaa840c data/advancedperipherals/recipes/colony_integrator.json -a39d46363291e5d98a8b96e17bfcfd44fbe3789d data/advancedperipherals/recipes/computer_tool.json -66d1e3ed636629a9a5f7e1a8b0b7d222f0300e00 data/advancedperipherals/recipes/energy_detector.json -85920e576d404f5ad78ba228f9d6cb9aed3d4962 data/advancedperipherals/recipes/environment_detector.json -4bf49ae496c60e5487c1e87013ef25e14bb13e3a data/advancedperipherals/recipes/geo_scanner.json -2eb633f159ac1b9feaffab383548f56b573f1519 data/advancedperipherals/recipes/inventory_manager.json -dbefebf13084fce55660cffabb955f25901a30f9 data/advancedperipherals/recipes/memory_card.json -fddcb2d34c37f4fd5834e077efd27f2cb6127c73 data/advancedperipherals/recipes/nbt_storage.json -afb8673c5643adbbf69a469776ac4cd908ab17e8 data/advancedperipherals/recipes/overpowered_end_automata_core.json -7c98974c9e5999b0186011ff7f910ae2b3cc76b6 data/advancedperipherals/recipes/overpowered_husbandry_automata_core.json -40110dc9c8616e5c9b30b087cfc2f9254c433025 data/advancedperipherals/recipes/overpowered_weak_automata_core.json -346dd97a088087077c157c29cb1ac7b25b0a0cef data/advancedperipherals/recipes/peripheral_casing.json -cba141d36a134a03ae91869abb91c9695bd92898 data/advancedperipherals/recipes/player_detector.json -d5a72afad727dd9814f4c8ef6b177a0db0bc9989 data/advancedperipherals/recipes/redstone_integrator.json -00937671ea7c33badf81e3f7a83350b41f5dc0f1 data/advancedperipherals/recipes/smart_glasses.json -a5cd6136f9d7f6271820656343f41a6ebb9cb9f0 data/advancedperipherals/recipes/weak_automata_core.json +// 1.19.2 2023-09-25T15:21:21.759303 Recipes +db2dada2fdf42ca1bbf47f1eb075d1f9de89dfa8 data/advancedperipherals/advancements/recipes/advancedperipheralstab/block_reader.json +77c55e8500be4a344ca563a8bf7642257cdc7b8b data/advancedperipherals/advancements/recipes/advancedperipheralstab/chat_box.json +96208b06b0c3c125762cd517506a5ffb6b1d55ac data/advancedperipherals/advancements/recipes/advancedperipheralstab/chunk_controller.json +eb1d84b0b82fd6671876d0885746f9e3e15803e3 data/advancedperipherals/advancements/recipes/advancedperipheralstab/computer_tool.json +5a1e92ee63dce1cb74c56b7e70587a0c54132de4 data/advancedperipherals/advancements/recipes/advancedperipheralstab/energy_detector.json +34d04b885af7947279752129f1f6e107cdf3cf05 data/advancedperipherals/advancements/recipes/advancedperipheralstab/environment_detector.json +91af310c4f272e800172a7f7e717fa29fc35dc62 data/advancedperipherals/advancements/recipes/advancedperipheralstab/geo_scanner.json +65184f82a2fe743edc4db31c0c362c74d1e4df84 data/advancedperipherals/advancements/recipes/advancedperipheralstab/inventory_manager.json +e575414582eb367f0689a3a90fc75aca2d6cd2fc data/advancedperipherals/advancements/recipes/advancedperipheralstab/memory_card.json +cb79be6d0ee7890abb2238b53edd55fd2338ed81 data/advancedperipherals/advancements/recipes/advancedperipheralstab/nbt_storage.json +e2d8bd0a887eb42d05f460d6fee007b7bb4c533c data/advancedperipherals/advancements/recipes/advancedperipheralstab/overpowered_end_automata_core.json +1db7ed04f8af5413308160b03f5b21d5932195f5 data/advancedperipherals/advancements/recipes/advancedperipheralstab/overpowered_husbandry_automata_core.json +d3d8709f4fdb3d68613d751bba5b9a94b8842046 data/advancedperipherals/advancements/recipes/advancedperipheralstab/overpowered_weak_automata_core.json +d27c1267208fd9036c5c45f7f6cbd4f6f67b3845 data/advancedperipherals/advancements/recipes/advancedperipheralstab/peripheral_casing.json +d8870644bb7d48c5ae33dcea2afbcfa106729d7b data/advancedperipherals/advancements/recipes/advancedperipheralstab/player_detector.json +7acff70533792bd089a655f8f24cdea6995aac0c data/advancedperipherals/advancements/recipes/advancedperipheralstab/redstone_integrator.json +fc0c3d99bec43318802f357083c7d98fde92567f data/advancedperipherals/advancements/recipes/advancedperipheralstab/weak_automata_core.json +b10b5cbcc668438001744d5b90d9838ab4d293cb data/advancedperipherals/recipes/block_reader.json +3c9618832fe0ac32cac0f04fbc5afad225418239 data/advancedperipherals/recipes/chat_box.json +a78adfcca4c7579b143aac5648a7eca9085c0dba data/advancedperipherals/recipes/chunk_controller.json +d4c090dc64185fab9b123fffeda6966308b6c3d0 data/advancedperipherals/recipes/colony_integrator.json +f1f468c732f8c802c27776d3fd7aac432bcac8e3 data/advancedperipherals/recipes/computer_tool.json +4f0d0427d8c8774e350e7cfd1767a9e4802f4ca1 data/advancedperipherals/recipes/energy_detector.json +55c257e4e8548d1453a7ab96c547d64c22b3e1d6 data/advancedperipherals/recipes/environment_detector.json +2ddf64c122165bcd3a277db8a1c7e96b4d510c67 data/advancedperipherals/recipes/geo_scanner.json +ebe70aa9fe80c5b962c13aa1fbadc32269ba81b9 data/advancedperipherals/recipes/inventory_manager.json +809bc6929cf5eab72648e8f1fb565b58749fec12 data/advancedperipherals/recipes/memory_card.json +82895838af6c6aea0c60e3a3fbf71073ab684167 data/advancedperipherals/recipes/me_bridge.json +8a73c4eb66e7a1cdc8e51d33466cf5a30da9270e data/advancedperipherals/recipes/nbt_storage.json +360432f30d61291066aa8c54692629f7a92e178d data/advancedperipherals/recipes/overpowered_end_automata_core.json +4ea6e90d13a61d90ad245539d20020ff9cb843e1 data/advancedperipherals/recipes/overpowered_husbandry_automata_core.json +6c4b197e7579a8868668be231ba36487a0e3626d data/advancedperipherals/recipes/overpowered_weak_automata_core.json +a91556eb09a2a8c57b323928a76095a4b17241b7 data/advancedperipherals/recipes/peripheral_casing.json +1d476bfb11dcf490cefa9916695d91aec0cc8a19 data/advancedperipherals/recipes/player_detector.json +110983bae78f033dc8b12fd04ba3b7edcf035237 data/advancedperipherals/recipes/redstone_integrator.json +4ba2670271ef2b7c8be861f6277ae24c307dac5b data/advancedperipherals/recipes/rs_bridge.json +7c783b341e783b22be4e40efbe3c88947e1902ec data/advancedperipherals/recipes/weak_automata_core.json diff --git a/src/generated/resources/.cache/ae219fa7c7d3297c14e454863eac3998a4eab78c b/src/generated/resources/.cache/ae219fa7c7d3297c14e454863eac3998a4eab78c index 43df559c6..920ac4b21 100644 --- a/src/generated/resources/.cache/ae219fa7c7d3297c14e454863eac3998a4eab78c +++ b/src/generated/resources/.cache/ae219fa7c7d3297c14e454863eac3998a4eab78c @@ -1,4 +1,4 @@ -// 1.19.3 2022-12-20T12:47:00.0789795 Pocket Computer Upgrades +// 1.19.2 2023-09-25T15:21:21.7823145 Pocket Computer Upgrades b672635324c0df354e587efc81d0b19a581eae2f data/advancedperipherals/computercraft/pocket_upgrades/chatty_pocket.json 30b8f663613c7ce77048fd69631afcc11a682276 data/advancedperipherals/computercraft/pocket_upgrades/colony_pocket.json d4647159c2f2693a9c5e8d12bf740635751d29a8 data/advancedperipherals/computercraft/pocket_upgrades/environment_pocket.json diff --git a/src/generated/resources/.cache/b8526e444ae7356037f3a813274f6835d1f3dd16 b/src/generated/resources/.cache/b8526e444ae7356037f3a813274f6835d1f3dd16 index 82b08d1a2..a31e71cd0 100644 --- a/src/generated/resources/.cache/b8526e444ae7356037f3a813274f6835d1f3dd16 +++ b/src/generated/resources/.cache/b8526e444ae7356037f3a813274f6835d1f3dd16 @@ -1,5 +1,4 @@ -// 1.19.3 2023-03-17T14:14:31.6028885 Block States: advancedperipherals -eedcacd50d047b9172b7ac55fd67d09beeca2704 assets/advancedperipherals/blockstates/ar_controller.json +// 1.19.2 2023-09-25T15:21:21.7763015 Block States: advancedperipherals 5e28ce1be9a6996d982641e5df1fa7162090b8cc assets/advancedperipherals/blockstates/block_reader.json f42bdde60f84fdb312f7cf3b2be461d9c11ebdc8 assets/advancedperipherals/blockstates/chat_box.json 1227aa092fcf1327547ace6ccc9db230e45891b0 assets/advancedperipherals/blockstates/colony_integrator.json @@ -13,7 +12,6 @@ d1fe6188b0b0ce8779cb9795a746177858cbaa41 assets/advancedperipherals/blockstates/ ff12c7217911184266589813a2c8f9b0d46cfd65 assets/advancedperipherals/blockstates/player_detector.json 726cf2599b0c765bcfacda88a1943be74f985877 assets/advancedperipherals/blockstates/redstone_integrator.json 6b176e8fdb048f7b6678bfbc1c4baf2bcfa67a1f assets/advancedperipherals/blockstates/rs_bridge.json -70a808a7b7b85897702622d682f3bf097e9f213a assets/advancedperipherals/models/block/ar_controller.json 544ff1ecb58622350b58940036b4b1908e1146da assets/advancedperipherals/models/block/block_reader.json b28693973b6bbbb61e0c1ffc59e8ca98d8bb7e97 assets/advancedperipherals/models/block/chat_box.json 8361da86b709e26f17374dfd46637940894a2212 assets/advancedperipherals/models/block/colony_integrator.json diff --git a/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 b/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 index 43ea3d5e6..0350a3d7c 100644 --- a/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 +++ b/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 @@ -1,2 +1,2 @@ -// 1.19.3 2023-03-17T14:31:56.1206942 Languages: en_us -7ef4e5276c1b6ed2dec8976a297a6d8c3f52e18f assets/advancedperipherals/lang/en_us.json +// 1.19.2 2023-09-25T15:21:21.7533003 Languages: en_us +e7e0fec72e3f82423dea2c37d1fef381865df701 assets/advancedperipherals/lang/en_us.json diff --git a/src/generated/resources/.cache/f95c7003282837dabaa33e3ffceec4e6865b5218 b/src/generated/resources/.cache/f95c7003282837dabaa33e3ffceec4e6865b5218 index b0f23c9e9..9609f52b0 100644 --- a/src/generated/resources/.cache/f95c7003282837dabaa33e3ffceec4e6865b5218 +++ b/src/generated/resources/.cache/f95c7003282837dabaa33e3ffceec4e6865b5218 @@ -1,4 +1,4 @@ -// 1.19.3 2022-12-20T12:47:00.0649699 Block tags -e1f71dcb4f9e7e36e29b0ad09d6520dc3adfa4a6 data/forge/tags/blocks/needs_wood_tool.json -f397bc09e95d0258b5ba711d5e1fb0b7da8419db data/minecraft/tags/blocks/mineable/pickaxe.json -055dd6291658fb34ab62ebf6e7223e11eb1aa052 data/minecraft/tags/blocks/needs_iron_tool.json +// 1.19.2 2023-09-25T15:21:21.7713005 Block tags +c4d65b1ce5b5b3ed603cbcc87cc47338be4406fe data/forge/tags/blocks/needs_wood_tool.json +ef4684e10e5054e8cfd515dffa4a98169d281078 data/minecraft/tags/blocks/mineable/pickaxe.json +26803b7d98247a3df6ee256ceb9509a2ad1ec2e5 data/minecraft/tags/blocks/needs_iron_tool.json diff --git a/src/generated/resources/assets/advancedperipherals/blockstates/ar_controller.json b/src/generated/resources/assets/advancedperipherals/blockstates/ar_controller.json deleted file mode 100644 index 0f5d903f9..000000000 --- a/src/generated/resources/assets/advancedperipherals/blockstates/ar_controller.json +++ /dev/null @@ -1,57 +0,0 @@ -{ - "variants": { - "orientation=down_east": { - "model": "advancedperipherals:block/ar_controller", - "x": 90, - "y": 90 - }, - "orientation=down_north": { - "model": "advancedperipherals:block/ar_controller", - "x": 90 - }, - "orientation=down_south": { - "model": "advancedperipherals:block/ar_controller", - "x": 90, - "y": 180 - }, - "orientation=down_west": { - "model": "advancedperipherals:block/ar_controller", - "x": 90, - "y": 270 - }, - "orientation=east_up": { - "model": "advancedperipherals:block/ar_controller", - "y": 90 - }, - "orientation=north_up": { - "model": "advancedperipherals:block/ar_controller" - }, - "orientation=south_up": { - "model": "advancedperipherals:block/ar_controller", - "y": 180 - }, - "orientation=up_east": { - "model": "advancedperipherals:block/ar_controller", - "x": 270, - "y": 90 - }, - "orientation=up_north": { - "model": "advancedperipherals:block/ar_controller", - "x": 270 - }, - "orientation=up_south": { - "model": "advancedperipherals:block/ar_controller", - "x": 270, - "y": 180 - }, - "orientation=up_west": { - "model": "advancedperipherals:block/ar_controller", - "x": 270, - "y": 270 - }, - "orientation=west_up": { - "model": "advancedperipherals:block/ar_controller", - "y": 270 - } - } -} \ No newline at end of file diff --git a/src/generated/resources/assets/advancedperipherals/lang/en_us.json b/src/generated/resources/assets/advancedperipherals/lang/en_us.json index 3f6944ddb..acbdd3c4c 100644 --- a/src/generated/resources/assets/advancedperipherals/lang/en_us.json +++ b/src/generated/resources/assets/advancedperipherals/lang/en_us.json @@ -16,7 +16,6 @@ "advancements.advancedperipherals.sense_toolkit.description": "Collect a geo scanner and environmental detector. There are no limits for observability!", "advancements.advancedperipherals.weak_automata_core": "First automata core", "advancements.advancedperipherals.weak_automata_core.description": "Does the afterlife exist in minecraft?", - "block.advancedperipherals.ar_controller": "Ar Controller", "block.advancedperipherals.block_reader": "Block Reader", "block.advancedperipherals.chat_box": "Chat Box", "block.advancedperipherals.colony_integrator": "Colony Integrator", @@ -30,7 +29,8 @@ "block.advancedperipherals.player_detector": "Player Detector", "block.advancedperipherals.redstone_integrator": "Redstone Integrator", "block.advancedperipherals.rs_bridge": "RS Bridge", - "entity.minecraft.villager.advancedperipherals.computer_scientist": "Computer Scientist", + "curios.identifier.glasses": "Glasses", + "entity.minecraft.villager.advancedperipherals.advancedperipherals:computer_scientist": "Computer Scientist", "item.advancedperipherals.chunk_controller": "Chunk Controller", "item.advancedperipherals.computer_tool": "Computer Tool", "item.advancedperipherals.end_automata_core": "End Automata Core", @@ -39,12 +39,15 @@ "item.advancedperipherals.overpowered_end_automata_core": "Overpowered End Automata Core", "item.advancedperipherals.overpowered_husbandry_automata_core": "Overpowered Husbandry Automata Core", "item.advancedperipherals.overpowered_weak_automata_core": "Overpowered Weak Automata Core", + "item.advancedperipherals.smart_glasses": "Smart Glasses", + "item.advancedperipherals.smart_glasses_interface": "Smart Glasses Interface", + "item.advancedperipherals.smart_glasses_netherite": "Netherite reinforced Smart Glasses", "item.advancedperipherals.tooltip.block_reader": "&7Reads nbt data of blocks to interact with blocks which do not have computer support.", "item.advancedperipherals.tooltip.chat_box": "&7Interacts with the ingame chat, can read and write messages.", "item.advancedperipherals.tooltip.chunk_controller": "&7A crafting ingredient for the Chunky Turtle.", "item.advancedperipherals.tooltip.colony_integrator": "&7Interacts with Minecolonies to read data about your colony and citizens.", "item.advancedperipherals.tooltip.computer_tool": "&7This tool was made to tune our blocks. But for now, it's just a blue useless wrench.", - "item.advancedperipherals.tooltip.disabled": "&cThis item is disabled in the config, so you can craft it, but it'll not have any functionality.", + "item.advancedperipherals.tooltip.disabled": "&cThis item is disabled in config, so you can craft it, but it'll not have any functionality.", "item.advancedperipherals.tooltip.end_automata_core": "&7Upgrade for turtles, that allows basic interaction with the world and teleportation in one dimension.", "item.advancedperipherals.tooltip.energy_detector": "&7Can detect energy flow and acts as a resistor.", "item.advancedperipherals.tooltip.environment_detector": "&7This peripheral interacts with the minecraft world.", @@ -58,14 +61,13 @@ "item.advancedperipherals.tooltip.overpowered_end_automata_core": "&7Improved version of the end automata core, that provides some overpowered uses! Be careful, the upgrade is very fragile.", "item.advancedperipherals.tooltip.overpowered_husbandry_automata_core": "&7Improved version of the husbandry automata core, that provides some overpowered uses! Be careful, the upgrade is very fragile.", "item.advancedperipherals.tooltip.overpowered_weak_automata_core": "&7Improved version of the weak automata core, that provides some overpowered uses! Be careful, the upgrade is very fragile.", - "item.advancedperipherals.tooltip.peripheral_casing": "&7An empty hull without the love it deserves. Used as a crafting ingredient", + "item.advancedperipherals.tooltip.peripheral_casing": "&7An empty hull without the love it deserves. Used as crafting ingredient", "item.advancedperipherals.tooltip.player_detector": "&7This peripheral can be used to interact with players, but don't be a stalker.", "item.advancedperipherals.tooltip.redstone_integrator": "&7This block is able to interact with redstone. Works exactly like the redstone api of an computer.", "item.advancedperipherals.tooltip.rs_bridge": "&7The RS Bridge interacts with Refined Storage to manage your items.", "item.advancedperipherals.tooltip.show_desc": "&b[&7%s&b] &7For Description", "item.advancedperipherals.tooltip.weak_automata_core": "&7Upgrade for turtles, which makes turtles more useful.", "item.advancedperipherals.weak_automata_core": "Weak Automata Core", - "itemGroup.advancedperipheralstab": "Advanced Peripherals", "keybind.advancedperipherals.category": "Advanced Peripherals", "keybind.advancedperipherals.description": "Show Description", "pocket.advancedperipherals.chatty_pocket": "Chatty", @@ -76,6 +78,8 @@ "text.advancedperipherals.added_player": "Added you to the memory card", "text.advancedperipherals.automata_core_feed_by_player": "You're trying to feed an entity to a soul, but your own body refuses to do this. Maybe something more mechanical can do this?", "text.advancedperipherals.removed_player": "Cleared the memory card", + "text.advancedperipherals.smart_glasses.modules": "Modules", + "text.advancedperipherals.smart_glasses.peripherals": "Peripherals", "turtle.advancedperipherals.chatty_turtle": "Chatty", "turtle.advancedperipherals.chunky_turtle": "Chunky", "turtle.advancedperipherals.compass_turtle": "Compass", diff --git a/src/generated/resources/assets/advancedperipherals/models/block/ar_controller.json b/src/generated/resources/assets/advancedperipherals/models/block/ar_controller.json deleted file mode 100644 index c03a25bba..000000000 --- a/src/generated/resources/assets/advancedperipherals/models/block/ar_controller.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "parent": "minecraft:block/cube_all", - "textures": { - "all": "advancedperipherals:block/ar_controller", - "north": "advancedperipherals:block/ar_controller_front", - "particle": "advancedperipherals:block/ar_controller_front" - } -} \ No newline at end of file diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/block_reader.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/block_reader.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/block_reader.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/block_reader.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/chat_box.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/chat_box.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/chat_box.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/chat_box.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/chunk_controller.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/chunk_controller.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/chunk_controller.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/chunk_controller.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/computer_tool.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/computer_tool.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/computer_tool.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/computer_tool.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/energy_detector.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/energy_detector.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/energy_detector.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/energy_detector.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/environment_detector.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/environment_detector.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/environment_detector.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/environment_detector.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/geo_scanner.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/geo_scanner.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/geo_scanner.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/geo_scanner.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/inventory_manager.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/inventory_manager.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/inventory_manager.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/inventory_manager.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/memory_card.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/memory_card.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/memory_card.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/memory_card.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/nbt_storage.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/nbt_storage.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/nbt_storage.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/nbt_storage.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/overpowered_end_automata_core.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/overpowered_end_automata_core.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/overpowered_end_automata_core.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/overpowered_end_automata_core.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/overpowered_husbandry_automata_core.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/overpowered_husbandry_automata_core.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/overpowered_husbandry_automata_core.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/overpowered_husbandry_automata_core.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/overpowered_weak_automata_core.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/overpowered_weak_automata_core.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/overpowered_weak_automata_core.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/overpowered_weak_automata_core.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/peripheral_casing.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/peripheral_casing.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/peripheral_casing.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/peripheral_casing.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/player_detector.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/player_detector.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/player_detector.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/player_detector.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/redstone_integrator.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/redstone_integrator.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/redstone_integrator.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/redstone_integrator.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/weak_automata_core.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/weak_automata_core.json similarity index 100% rename from src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/weak_automata_core.json rename to src/generated/resources/data/advancedperipherals/advancements/recipes/advancedperipheralstab/weak_automata_core.json diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/ar_controller.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/ar_controller.json deleted file mode 100644 index 9c94aad21..000000000 --- a/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/ar_controller.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "parent": "minecraft:recipes/root", - "criteria": { - "has_item": { - "conditions": { - "items": [ - { - "items": [ - "advancedperipherals:peripheral_casing" - ] - } - ] - }, - "trigger": "minecraft:inventory_changed" - }, - "has_the_recipe": { - "conditions": { - "recipe": "advancedperipherals:ar_controller" - }, - "trigger": "minecraft:recipe_unlocked" - } - }, - "requirements": [ - [ - "has_item", - "has_the_recipe" - ] - ], - "rewards": { - "recipes": [ - "advancedperipherals:ar_controller" - ] - } -} \ No newline at end of file diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/armor/smart_glasses_netherite.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/armor/smart_glasses_netherite.json deleted file mode 100644 index bb6e067ec..000000000 --- a/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/armor/smart_glasses_netherite.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "parent": "minecraft:recipes/root", - "criteria": { - "has_item": { - "conditions": { - "items": [ - { - "items": [ - "minecraft:netherite_ingot" - ] - } - ] - }, - "trigger": "minecraft:inventory_changed" - }, - "has_the_recipe": { - "conditions": { - "recipe": "advancedperipherals:armor/smart_glasses_netherite" - }, - "trigger": "minecraft:recipe_unlocked" - } - }, - "requirements": [ - [ - "has_item", - "has_the_recipe" - ] - ], - "rewards": { - "recipes": [ - "advancedperipherals:armor/smart_glasses_netherite" - ] - } -} \ No newline at end of file diff --git a/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/smart_glasses.json b/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/smart_glasses.json deleted file mode 100644 index 6d54b03bc..000000000 --- a/src/generated/resources/data/advancedperipherals/advancements/recipes/redstone/smart_glasses.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "parent": "minecraft:recipes/root", - "criteria": { - "has_item": { - "conditions": { - "items": [ - { - "items": [ - "minecraft:stick" - ] - } - ] - }, - "trigger": "minecraft:inventory_changed" - }, - "has_the_recipe": { - "conditions": { - "recipe": "advancedperipherals:smart_glasses" - }, - "trigger": "minecraft:recipe_unlocked" - } - }, - "requirements": [ - [ - "has_item", - "has_the_recipe" - ] - ], - "rewards": { - "recipes": [ - "advancedperipherals:smart_glasses" - ] - } -} \ No newline at end of file diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/ar_controller.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/ar_controller.json deleted file mode 100644 index 041d2aada..000000000 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/ar_controller.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "type": "minecraft:block", - "pools": [ - { - "bonus_rolls": 0.0, - "conditions": [ - { - "condition": "minecraft:survives_explosion" - } - ], - "entries": [ - { - "type": "minecraft:item", - "name": "advancedperipherals:ar_controller" - } - ], - "rolls": 1.0 - } - ] -} \ No newline at end of file diff --git a/src/generated/resources/data/advancedperipherals/recipes/ar_controller.json b/src/generated/resources/data/advancedperipherals/recipes/ar_controller.json deleted file mode 100644 index 15c46edfb..000000000 --- a/src/generated/resources/data/advancedperipherals/recipes/ar_controller.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "type": "minecraft:crafting_shaped", - "key": { - "C": { - "item": "advancedperipherals:peripheral_casing" - }, - "E": { - "tag": "forge:ender_pearls" - }, - "G": { - "item": "minecraft:smooth_stone" - } - }, - "pattern": [ - "GEG", - "ECE", - "GEG" - ], - "result": { - "item": "advancedperipherals:ar_controller" - } -} \ No newline at end of file diff --git a/src/generated/resources/data/advancedperipherals/recipes/armor/smart_glasses_netherite.json b/src/generated/resources/data/advancedperipherals/recipes/armor/smart_glasses_netherite.json deleted file mode 100644 index e46b01d51..000000000 --- a/src/generated/resources/data/advancedperipherals/recipes/armor/smart_glasses_netherite.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "type": "minecraft:smithing", - "addition": { - "item": "minecraft:netherite_ingot" - }, - "base": { - "item": "advancedperipherals:smart_glasses" - }, - "result": { - "item": "advancedperipherals:smart_glasses_netherite" - } -} \ No newline at end of file diff --git a/src/generated/resources/data/advancedperipherals/recipes/colony_integrator.json b/src/generated/resources/data/advancedperipherals/recipes/colony_integrator.json index 9839197d1..ee200a21d 100644 --- a/src/generated/resources/data/advancedperipherals/recipes/colony_integrator.json +++ b/src/generated/resources/data/advancedperipherals/recipes/colony_integrator.json @@ -10,7 +10,6 @@ ], "recipe": { "type": "minecraft:crafting_shaped", - "category": "redstone", "key": { "A": { "item": "advancedperipherals:peripheral_casing" diff --git a/src/generated/resources/data/advancedperipherals/recipes/me_bridge.json b/src/generated/resources/data/advancedperipherals/recipes/me_bridge.json new file mode 100644 index 000000000..0e0946063 --- /dev/null +++ b/src/generated/resources/data/advancedperipherals/recipes/me_bridge.json @@ -0,0 +1,35 @@ +{ + "type": "forge:conditional", + "recipes": [ + { + "conditions": [ + { + "type": "forge:mod_loaded", + "modid": "ae2" + } + ], + "recipe": { + "type": "minecraft:crafting_shaped", + "key": { + "A": { + "item": "advancedperipherals:peripheral_casing" + }, + "F": { + "item": "ae2:fluix_block" + }, + "I": { + "item": "ae2:interface" + } + }, + "pattern": [ + "FIF", + "IAI", + "FIF" + ], + "result": { + "item": "advancedperipherals:me_bridge" + } + } + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/advancedperipherals/recipes/rs_bridge.json b/src/generated/resources/data/advancedperipherals/recipes/rs_bridge.json new file mode 100644 index 000000000..f8c233104 --- /dev/null +++ b/src/generated/resources/data/advancedperipherals/recipes/rs_bridge.json @@ -0,0 +1,35 @@ +{ + "type": "forge:conditional", + "recipes": [ + { + "conditions": [ + { + "type": "forge:mod_loaded", + "modid": "refinedstorage" + } + ], + "recipe": { + "type": "minecraft:crafting_shaped", + "key": { + "A": { + "item": "advancedperipherals:peripheral_casing" + }, + "I": { + "item": "refinedstorage:interface" + }, + "Q": { + "item": "refinedstorage:quartz_enriched_iron" + } + }, + "pattern": [ + "QIQ", + "IAI", + "QIQ" + ], + "result": { + "item": "advancedperipherals:rs_bridge" + } + } + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/advancedperipherals/recipes/smart_glasses.json b/src/generated/resources/data/advancedperipherals/recipes/smart_glasses.json deleted file mode 100644 index daf33e9c3..000000000 --- a/src/generated/resources/data/advancedperipherals/recipes/smart_glasses.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "type": "minecraft:crafting_shaped", - "category": "redstone", - "key": { - "C": { - "item": "computercraft:computer_advanced" - }, - "E": { - "tag": "forge:ender_pearls" - }, - "G": { - "tag": "forge:glass/black" - }, - "M": { - "item": "computercraft:wireless_modem_advanced" - }, - "S": { - "tag": "forge:rods/wooden" - } - }, - "pattern": [ - "S S", - "GEG", - "M C" - ], - "result": { - "item": "advancedperipherals:smart_glasses" - } -} \ No newline at end of file diff --git a/src/generated/resources/data/forge/tags/blocks/needs_wood_tool.json b/src/generated/resources/data/forge/tags/blocks/needs_wood_tool.json index ffd23c4b9..0578bfe7e 100644 --- a/src/generated/resources/data/forge/tags/blocks/needs_wood_tool.json +++ b/src/generated/resources/data/forge/tags/blocks/needs_wood_tool.json @@ -1,5 +1,6 @@ { "values": [ - "advancedperipherals:peripheral_casing" + "advancedperipherals:peripheral_casing", + "advancedperipherals:colony_integrator" ] } \ No newline at end of file diff --git a/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json b/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json index 66d6c5726..8f9cf40b9 100644 --- a/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json +++ b/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json @@ -9,7 +9,6 @@ "advancedperipherals:fluid_detector", "advancedperipherals:gas_detector", "advancedperipherals:peripheral_casing", - "advancedperipherals:ar_controller", "advancedperipherals:inventory_manager", "advancedperipherals:redstone_integrator", "advancedperipherals:block_reader", diff --git a/src/generated/resources/data/minecraft/tags/blocks/needs_iron_tool.json b/src/generated/resources/data/minecraft/tags/blocks/needs_iron_tool.json index 2952ba4f1..76fb2b79d 100644 --- a/src/generated/resources/data/minecraft/tags/blocks/needs_iron_tool.json +++ b/src/generated/resources/data/minecraft/tags/blocks/needs_iron_tool.json @@ -8,12 +8,10 @@ "advancedperipherals:energy_detector", "advancedperipherals:fluid_detector", "advancedperipherals:gas_detector", - "advancedperipherals:ar_controller", "advancedperipherals:inventory_manager", "advancedperipherals:redstone_integrator", "advancedperipherals:block_reader", "advancedperipherals:geo_scanner", - "advancedperipherals:colony_integrator", "advancedperipherals:nbt_storage", "advancedperipherals:distance_detector" ] diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java index 58321dbd2..687886c93 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java @@ -40,7 +40,7 @@ public RecipesProvider(DataGenerator packOutput) { protected void buildCraftingRecipes(@NotNull Consumer consumer) { addShapeless(consumer); addShaped(consumer); - addSmithing(consumer); + //addSmithing(consumer); } private void addShapeless(@NotNull Consumer consumer) { From 59febbb148492e54bbfd369e91d384628027b80d Mon Sep 17 00:00:00 2001 From: Deniz Demiroglu Date: Tue, 26 Sep 2023 11:28:12 +0200 Subject: [PATCH 058/228] Fixed that peripherals remain in the glasses computer after removing them --- .../common/smartglasses/SmartGlassesComputer.java | 5 ++++- .../common/smartglasses/modules/ModulePeripheral.java | 7 +------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java index a2fcbb9bf..91f028f5b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java @@ -135,10 +135,13 @@ public void updatePeripheralsAndModules(IItemHandler itemHandler) { IPocketUpgrade upgrade = PocketUpgrades.instance().get(peripheralItem); if (upgrade != null) { IPeripheral peripheral = upgrade.createPeripheral(smartGlassesAccess); - if (peripheral != null) + if (peripheral != null) { setPeripheral(SmartGlassesSlot.indexToSide(slot), peripheral); + continue; + } } } + setPeripheral(SmartGlassesSlot.indexToSide(slot), null); } modules.clear(); for (int slot = 4; slot < 11; slot++) { diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java index 47d6e3081..94a5604ca 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java @@ -4,9 +4,6 @@ import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesComputer; import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; -import java.util.ArrayList; -import java.util.List; - public class ModulePeripheral extends BasePeripheral { public static final String PERIPHERAL_TYPE = "smartGlasses"; @@ -25,8 +22,6 @@ public boolean isEnabled() { @LuaFunction(mainThread = true) public final String[] getModules() { - List modules = new ArrayList<>(getPeripheralOwner().getComputer().getModules().size()); - getPeripheralOwner().getComputer().getModules().forEach(module -> modules.add(module.getName().toString())); - return modules.toArray(new String[0]); + return getPeripheralOwner().getComputer().getModules().stream().map(module -> module.getName().toString()).toArray(String[]::new); } } From 289503e3f92e942691ee21887c69c970da71398d Mon Sep 17 00:00:00 2001 From: Deniz Demiroglu Date: Tue, 26 Sep 2023 17:22:46 +0200 Subject: [PATCH 059/228] Cleanups, docs and a ui fix --- .../client/widgets/SmartGlassesSettingsSwitch.java | 2 +- .../common/smartglasses/SmartGlassesComputer.java | 11 ++++++----- .../common/smartglasses/modules/IModule.java | 6 ++++++ .../smartglasses/modules/overlay/OverlayModule.java | 5 ++++- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/client/widgets/SmartGlassesSettingsSwitch.java b/src/main/java/de/srendi/advancedperipherals/client/widgets/SmartGlassesSettingsSwitch.java index 60e382f20..3ee6e1fb1 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/widgets/SmartGlassesSettingsSwitch.java +++ b/src/main/java/de/srendi/advancedperipherals/client/widgets/SmartGlassesSettingsSwitch.java @@ -45,7 +45,7 @@ public void renderButton(@NotNull PoseStack pPoseStack, int pMouseX, int pMouseY protected void renderBg(@NotNull PoseStack pPoseStack, @NotNull Minecraft pMinecraft, int pMouseX, int pMouseY) { RenderSystem.setShaderTexture(0, BACKGROUND); if (isEnabled) { - blit(pPoseStack, this.x - 3, this.y, 45, 217, 23, 22); + blit(pPoseStack, this.x - 3, this.y, 45, 217, 24, 22); } else { blit(pPoseStack, this.x, this.y, 23, 217, 21, 22); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java index 91f028f5b..566e3ce3b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java @@ -20,7 +20,10 @@ import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; -import java.util.*; +import java.util.Collections; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; /** * Basically just a {@link dan200.computercraft.shared.pocket.core.PocketServerComputer} but with some changes @@ -167,16 +170,14 @@ public void tickServer() { tracking.addAll(getLevel().players()); } else { // Broadcast the state to new players. - List added = new ArrayList<>(); for (var player : getLevel().players()) { - if (tracking.add(player)) - added.add(player); + tracking.add(player); } } modules.forEach(module -> module.tick(smartGlassesAccess)); - if(isDirty()) + if (isDirty()) updatePeripheralsAndModules(itemHandler); isDirty = false; diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java index 4b254a952..178e03407 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java @@ -14,6 +14,12 @@ public interface IModule { */ IModuleFunctions getFunctions(SmartGlassesAccess smartGlassesAccess); + /** + * Classic tick function. + *

+ * Implementations should check if the entity is not null since the glasses can still tick without belonging to an entity + * @param smartGlassesAccess Contains access to the entity, the computer, the level or the upgrades + */ void tick(SmartGlassesAccess smartGlassesAccess); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java index afbce8490..083bc7e7a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java @@ -5,6 +5,8 @@ import de.srendi.advancedperipherals.common.smartglasses.modules.IModule; import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleFunctions; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.Entity; + /** * We want to support scripts which were made for the plethora classes. So we call this item the same as the overlay item from plethora @@ -24,7 +26,8 @@ public IModuleFunctions getFunctions(SmartGlassesAccess smartGlassesAccess) { @Override public void tick(SmartGlassesAccess smartGlassesAccess) { - if(smartGlassesAccess.getEntity().getLevel().getGameTime() % 20 == 0) + Entity entity = smartGlassesAccess.getEntity(); + if(entity != null && entity.getLevel().getGameTime() % 20 == 0) AdvancedPeripherals.LOGGER.info("I'm an overlay module! And I'm alive!"); } } From ebab16e6ce6a6dd8d743e87ca117191f377984e2 Mon Sep 17 00:00:00 2001 From: Deniz Demiroglu Date: Wed, 27 Sep 2023 10:48:15 +0200 Subject: [PATCH 060/228] Fixed smartglasses smithing recipe --- gradle.properties | 2 +- .../resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e | 4 +++- .../advancedperipherals/common/data/RecipesProvider.java | 2 +- .../advancedperipherals/common/items/SmartGlassesItem.java | 2 +- .../common/smartglasses/modules/overlay/OverlayModule.java | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/gradle.properties b/gradle.properties index 7d991f8b0..e094bec7b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ org.gradle.logging.level=info # Minecraft related mod_id=advancedperipherals minecraft_version=1.19.2 -forge_version=43.2.21 +forge_version=43.3.0 loader_version=43 mod_version=0.8r release_type=release diff --git a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e index cc3692f50..57b11e7d4 100644 --- a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e +++ b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e @@ -1,4 +1,5 @@ -// 1.19.2 2023-09-25T15:21:21.759303 Recipes +// 1.19.2 2023-09-27T10:45:57.2509102 Recipes +045608027e4a5ea2d7dee7f402346b8e69f21675 data/advancedperipherals/advancements/recipes/advancedperipheralstab/armor/smart_glasses_netherite.json db2dada2fdf42ca1bbf47f1eb075d1f9de89dfa8 data/advancedperipherals/advancements/recipes/advancedperipheralstab/block_reader.json 77c55e8500be4a344ca563a8bf7642257cdc7b8b data/advancedperipherals/advancements/recipes/advancedperipheralstab/chat_box.json 96208b06b0c3c125762cd517506a5ffb6b1d55ac data/advancedperipherals/advancements/recipes/advancedperipheralstab/chunk_controller.json @@ -16,6 +17,7 @@ d27c1267208fd9036c5c45f7f6cbd4f6f67b3845 data/advancedperipherals/advancements/r d8870644bb7d48c5ae33dcea2afbcfa106729d7b data/advancedperipherals/advancements/recipes/advancedperipheralstab/player_detector.json 7acff70533792bd089a655f8f24cdea6995aac0c data/advancedperipherals/advancements/recipes/advancedperipheralstab/redstone_integrator.json fc0c3d99bec43318802f357083c7d98fde92567f data/advancedperipherals/advancements/recipes/advancedperipheralstab/weak_automata_core.json +66999fea36aa4113567753f104630f6490dda6ba data/advancedperipherals/recipes/armor/smart_glasses_netherite.json b10b5cbcc668438001744d5b90d9838ab4d293cb data/advancedperipherals/recipes/block_reader.json 3c9618832fe0ac32cac0f04fbc5afad225418239 data/advancedperipherals/recipes/chat_box.json a78adfcca4c7579b143aac5648a7eca9085c0dba data/advancedperipherals/recipes/chunk_controller.json diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java index 687886c93..58321dbd2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java @@ -40,7 +40,7 @@ public RecipesProvider(DataGenerator packOutput) { protected void buildCraftingRecipes(@NotNull Consumer consumer) { addShapeless(consumer); addShaped(consumer); - //addSmithing(consumer); + addSmithing(consumer); } private void addShapeless(@NotNull Consumer consumer) { diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java index 5015376a1..69ec09a6b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java @@ -58,7 +58,7 @@ public class SmartGlassesItem extends ArmorItem implements IComputerItem, IMedia private static final String NBT_SESSION = "SessionId"; public SmartGlassesItem(ArmorMaterial material) { - super(material, EquipmentSlot.HEAD, new Properties().stacksTo(1)); + super(material, EquipmentSlot.HEAD, new Properties().stacksTo(1).tab(AdvancedPeripherals.TAB)); } @Nullable diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java index 083bc7e7a..12d675ae0 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java @@ -10,7 +10,7 @@ /** * We want to support scripts which were made for the plethora classes. So we call this item the same as the overlay item from plethora - * We'll also add the same functions + * We'll first add our own implementation for a rendering system and then add the API endpoints for plethora scripts */ public class OverlayModule implements IModule { From 1c61e275cbae81d30d50103bb46feb89d5b56c3c Mon Sep 17 00:00:00 2001 From: Deniz Demiroglu Date: Wed, 27 Sep 2023 16:58:33 +0200 Subject: [PATCH 061/228] Prototype for an object bases rendering system. Currently working on the server side of things --- gradle.properties | 2 +- .../common/items/SmartGlassesItem.java | 2 +- .../smartglasses/SmartGlassesComputer.java | 9 ++--- .../common/smartglasses/modules/IModule.java | 7 ++++ .../overlay/OverlayGlassesFunctions.java | 24 +++++++++++++ .../modules/overlay/OverlayModule.java | 32 +++++++++++++++-- .../modules/overlay/OverlayObject.java | 34 +++++++++++++++++++ .../smartglasses/modules/overlay/Panel.java | 12 +++++++ 8 files changed, 111 insertions(+), 11 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayObject.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/Panel.java diff --git a/gradle.properties b/gradle.properties index e094bec7b..f0f3fc6b2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,7 +17,7 @@ jb_annotations=21.0.1 junit_version=5.7.2 hamcrest_version=2.2 kotlin_version=1.8.0 -kotlinx_coroutines_version=1.6.0-RC3 +kotlinx_coroutines_version=1.7.3 ttoolkit_version=0.1.3 # Mod dependencies diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java index 69ec09a6b..1f90dd563 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java @@ -208,7 +208,6 @@ public SmartGlassesComputer getOrCreateComputer(ServerLevel level, Entity entity setInstanceID(stack, computer.register()); setSessionID(stack, registry.getSessionID()); - computer.setPeripheral(ComputerSide.BACK, new ModulePeripheral(computer)); computer.addAPI(new SmartGlassesAPI()); // Only turn on when initially creating the computer, rather than each tick. @@ -218,6 +217,7 @@ public SmartGlassesComputer getOrCreateComputer(ServerLevel level, Entity entity if (inventory != null) inventory.setChanged(); } + computer.setPeripheral(ComputerSide.BACK, new ModulePeripheral(computer)); computer.setLevel(level); return computer; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java index 566e3ce3b..aa9a4fe89 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java @@ -3,11 +3,13 @@ import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.pocket.IPocketAccess; import dan200.computercraft.api.pocket.IPocketUpgrade; +import dan200.computercraft.core.computer.ComputerSide; import dan200.computercraft.shared.PocketUpgrades; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ServerComputer; import de.srendi.advancedperipherals.common.smartglasses.modules.IModule; import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleItem; +import de.srendi.advancedperipherals.common.smartglasses.modules.ModulePeripheral; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; @@ -153,6 +155,7 @@ public void updatePeripheralsAndModules(IItemHandler itemHandler) { modules.add(module.getModule()); } } + setPeripheral(ComputerSide.BACK, new ModulePeripheral(this)); } @Override @@ -166,13 +169,7 @@ public void tickServer() { var sendState = hasOutputChanged() || lightChanged; lightChanged = false; if (sendState) { - // Broadcast the state to all players tracking.addAll(getLevel().players()); - } else { - // Broadcast the state to new players. - for (var player : getLevel().players()) { - tracking.add(player); - } } modules.forEach(module -> module.tick(smartGlassesAccess)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java index 178e03407..96be31142 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java @@ -22,4 +22,11 @@ public interface IModule { */ void tick(SmartGlassesAccess smartGlassesAccess); + /** + * ErrorConstants class contains constants for error messages. This is used for easier error handling for users. + */ + class ErrorConstants { + public static final String ALREADY_EXISTS = "ID_ALREADY_EXISTS"; + } + } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesFunctions.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesFunctions.java index fec953b13..99f861e61 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesFunctions.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesFunctions.java @@ -1,14 +1,38 @@ package de.srendi.advancedperipherals.common.smartglasses.modules.overlay; +import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.LuaFunction; +import dan200.computercraft.api.lua.MethodResult; +import de.srendi.advancedperipherals.common.smartglasses.modules.IModule; import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleFunctions; +import de.srendi.advancedperipherals.common.util.Pair; public class OverlayGlassesFunctions implements IModuleFunctions { + private final OverlayModule overlayModule; + + public OverlayGlassesFunctions(OverlayModule overlayModule) { + this.overlayModule = overlayModule; + } + @LuaFunction public final String test() { return "Hello World! I'm an overlay module!"; } + @LuaFunction + public final MethodResult createPanel(String id, IArguments arguments) { + Panel panel = new Panel(id, overlayModule); + Pair success = overlayModule.addObject(panel); + if(!success.getRight()) + return MethodResult.of(success.getLeft(), IModule.ErrorConstants.ALREADY_EXISTS); + + return MethodResult.of(success.getLeft(), "SUCCESS"); + } + + @LuaFunction + public final MethodResult getObjects(IArguments arguments) { + return MethodResult.of((Object) overlayModule.getObjects().stream().map(OverlayObject::getId).toArray(String[]::new)); + } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java index 12d675ae0..98f71bd41 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java @@ -4,8 +4,12 @@ import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesAccess; import de.srendi.advancedperipherals.common.smartglasses.modules.IModule; import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleFunctions; +import de.srendi.advancedperipherals.common.util.Pair; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.Entity; +import org.jetbrains.annotations.NotNull; + +import java.util.concurrent.CopyOnWriteArraySet; /** @@ -14,6 +18,8 @@ */ public class OverlayModule implements IModule { + private final CopyOnWriteArraySet objects = new CopyOnWriteArraySet<>(); + @Override public ResourceLocation getName() { return new ResourceLocation(AdvancedPeripherals.MOD_ID, "glasses"); @@ -21,13 +27,33 @@ public ResourceLocation getName() { @Override public IModuleFunctions getFunctions(SmartGlassesAccess smartGlassesAccess) { - return IModuleFunctions.EMPTY; + return new OverlayGlassesFunctions(this); } @Override - public void tick(SmartGlassesAccess smartGlassesAccess) { + public void tick(@NotNull SmartGlassesAccess smartGlassesAccess) { Entity entity = smartGlassesAccess.getEntity(); - if(entity != null && entity.getLevel().getGameTime() % 20 == 0) + if (entity != null && entity.getLevel().getGameTime() % 20 == 0) AdvancedPeripherals.LOGGER.info("I'm an overlay module! And I'm alive!"); } + + public CopyOnWriteArraySet getObjects() { + return objects; + } + + /** + * Adds an object to the module. If the object already exists, it will return the object and stop proceeding + * + * @param object The object which should be added + * @return A pair of the object and a boolean. The boolean is true if the object was added successfully and false if not. + * The object is the object which was added or the object which already exists(When not successful). + */ + public Pair addObject(OverlayObject object) { + for (OverlayObject overlayObject : objects) { + if (overlayObject.getId().equals(object.getId())) + return Pair.of(overlayObject, false); + } + objects.add(object); + return Pair.of(object, true); + } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayObject.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayObject.java new file mode 100644 index 000000000..db5849e66 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayObject.java @@ -0,0 +1,34 @@ +package de.srendi.advancedperipherals.common.smartglasses.modules.overlay; + +import dan200.computercraft.api.lua.LuaFunction; + +public abstract class OverlayObject { + + private boolean enabled = true; + private final String id; + private final OverlayModule module; + + public OverlayObject(String id, OverlayModule module) { + this.id = id; + this.module = module; + } + + @LuaFunction + public final String getId() { + return id; + } + + public OverlayModule getModule() { + return module; + } + + @LuaFunction + public final void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + @LuaFunction + public final boolean isEnabled() { + return enabled; + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/Panel.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/Panel.java new file mode 100644 index 000000000..8e2df35bf --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/Panel.java @@ -0,0 +1,12 @@ +package de.srendi.advancedperipherals.common.smartglasses.modules.overlay; + +/** + * A panel is the standard panel which can contain multiple render-able objects in it. + */ +public class Panel extends OverlayObject { + + public Panel(String id, OverlayModule module) { + super(id, module); + } + +} From c7289bcc2f4e222b0137272b13dfb4ba416b9216 Mon Sep 17 00:00:00 2001 From: Deniz Demiroglu Date: Wed, 27 Sep 2023 18:30:12 +0200 Subject: [PATCH 062/228] Implemented mapping functionality via reflections. We don't want to create a hell of arguments for functions but instead use a table with properties like our filters. But note that this is not final, I am aware of the security risks with this system --- .../AdvancedPeripherals.java | 5 +++ .../overlay/OverlayGlassesFunctions.java | 5 ++- .../modules/overlay/OverlayObject.java | 38 +++++++++++++++++++ .../smartglasses/modules/overlay/Panel.java | 6 ++- 4 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java index 2381c515f..44ebb8127 100644 --- a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java +++ b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java @@ -49,6 +49,11 @@ public static void debug(String message, Level level) { LOGGER.log(level, "[DEBUG] {}", message); } + public static void exception(String message, Exception exception) { + if (APConfig.GENERAL_CONFIG.enableDebugMode.get()) + LOGGER.error("[DEBUG]", exception); + } + public static ResourceLocation getRL(String resource) { return new ResourceLocation(MOD_ID, resource); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesFunctions.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesFunctions.java index 99f861e61..45b6babce 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesFunctions.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesFunctions.java @@ -1,6 +1,7 @@ package de.srendi.advancedperipherals.common.smartglasses.modules.overlay; import dan200.computercraft.api.lua.IArguments; +import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.lua.MethodResult; import de.srendi.advancedperipherals.common.smartglasses.modules.IModule; @@ -21,8 +22,8 @@ public final String test() { } @LuaFunction - public final MethodResult createPanel(String id, IArguments arguments) { - Panel panel = new Panel(id, overlayModule); + public final MethodResult createPanel(String id, IArguments arguments) throws LuaException { + Panel panel = new Panel(id, overlayModule, arguments); Pair success = overlayModule.addObject(panel); if(!success.getRight()) return MethodResult.of(success.getLeft(), IModule.ErrorConstants.ALREADY_EXISTS); diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayObject.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayObject.java index db5849e66..e056f54ff 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayObject.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayObject.java @@ -1,6 +1,15 @@ package de.srendi.advancedperipherals.common.smartglasses.modules.overlay; +import dan200.computercraft.api.lua.IArguments; +import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaFunction; +import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.common.configuration.APConfig; +import org.apache.commons.lang3.ArrayUtils; + +import java.lang.reflect.Field; +import java.util.Map; +import java.util.stream.Collectors; public abstract class OverlayObject { @@ -31,4 +40,33 @@ public final void setEnabled(boolean enabled) { public final boolean isEnabled() { return enabled; } + + public void mapProperties(IArguments arguments) throws LuaException { + try { + Map properties = arguments.getTable(1).entrySet().stream() + .filter(entry -> entry.getKey() instanceof String) + .collect(Collectors.toMap(entry -> (String) entry.getKey(), Map.Entry::getValue)); + + // Get the fields of this class and the proper child class like `Panel` + Field[] childFields = this.getClass().getDeclaredFields(); + Field[] superFields = this.getClass().getSuperclass().getDeclaredFields(); + + // Combine the fields into one array + Field[] allFields = ArrayUtils.addAll(childFields, superFields); + + for (Field field : allFields) { + if (properties.containsKey(field.getName())) { + // Make the field accessible + field.setAccessible(true); + + // Set the value of the field + field.set(this, properties.get(field.getName())); + } + } + } catch (LuaException | IllegalAccessException exception) { + if (APConfig.GENERAL_CONFIG.enableDebugMode.get()) + AdvancedPeripherals.exception("An error occurred while mapping properties.", exception); + throw new LuaException("An error occurred while mapping properties."); + } + } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/Panel.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/Panel.java index 8e2df35bf..ba711c652 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/Panel.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/Panel.java @@ -1,12 +1,16 @@ package de.srendi.advancedperipherals.common.smartglasses.modules.overlay; +import dan200.computercraft.api.lua.IArguments; +import dan200.computercraft.api.lua.LuaException; + /** * A panel is the standard panel which can contain multiple render-able objects in it. */ public class Panel extends OverlayObject { - public Panel(String id, OverlayModule module) { + public Panel(String id, OverlayModule module, IArguments arguments) throws LuaException { super(id, module); + mapProperties(arguments); } } From 11eec61eb4d4b92b545f09435ab80566d76fae1d Mon Sep 17 00:00:00 2001 From: Deniz Date: Thu, 28 Sep 2023 00:20:04 +0200 Subject: [PATCH 063/228] Starting to use annotations for our properties to improve safety. This is currently not a clean way, but I need to sync the project to another device... --- .../modules/overlay/ObjectProperty.java | 18 ++++++++ .../modules/overlay/OverlayObject.java | 44 ++++++++++++++----- .../smartglasses/modules/overlay/Panel.java | 5 +-- .../modules/overlay/RenderableObject.java | 38 ++++++++++++++++ .../en_us/entries/items/ar_goggles.json | 15 ------- .../entries/peripherals/ar_controller.json | 30 ------------- 6 files changed, 92 insertions(+), 58 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/ObjectProperty.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/RenderableObject.java delete mode 100644 src/main/resources/data/advancedperipherals/patchouli_books/manual/en_us/entries/items/ar_goggles.json delete mode 100644 src/main/resources/data/advancedperipherals/patchouli_books/manual/en_us/entries/peripherals/ar_controller.json diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/ObjectProperty.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/ObjectProperty.java new file mode 100644 index 000000000..8f433ab4e --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/ObjectProperty.java @@ -0,0 +1,18 @@ +package de.srendi.advancedperipherals.common.smartglasses.modules.overlay; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface ObjectProperty { + + int minInt() default Integer.MIN_VALUE; + + int maxInt() default Integer.MAX_VALUE; + + double maxDecimal() default Double.MAX_VALUE; + + double minDecimal() default Double.MIN_VALUE; + + int maxString() default Integer.MAX_VALUE; +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayObject.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayObject.java index e056f54ff..ad786fdf8 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayObject.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayObject.java @@ -5,21 +5,25 @@ import dan200.computercraft.api.lua.LuaFunction; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.configuration.APConfig; -import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.reflect.FieldUtils; +import org.apache.logging.log4j.Level; import java.lang.reflect.Field; import java.util.Map; import java.util.stream.Collectors; + public abstract class OverlayObject { + @ObjectProperty private boolean enabled = true; private final String id; private final OverlayModule module; - public OverlayObject(String id, OverlayModule module) { + public OverlayObject(String id, OverlayModule module, IArguments arguments) throws LuaException { this.id = id; this.module = module; + mapProperties(arguments); } @LuaFunction @@ -42,25 +46,45 @@ public final boolean isEnabled() { } public void mapProperties(IArguments arguments) throws LuaException { + if(arguments.optTable(1).isEmpty()) + return; + try { - Map properties = arguments.getTable(1).entrySet().stream() + + Map properties = arguments.optTable(1).get().entrySet().stream() .filter(entry -> entry.getKey() instanceof String) .collect(Collectors.toMap(entry -> (String) entry.getKey(), Map.Entry::getValue)); - // Get the fields of this class and the proper child class like `Panel` - Field[] childFields = this.getClass().getDeclaredFields(); - Field[] superFields = this.getClass().getSuperclass().getDeclaredFields(); - - // Combine the fields into one array - Field[] allFields = ArrayUtils.addAll(childFields, superFields); + Field[] allFields = FieldUtils.getAllFields(this.getClass()); for (Field field : allFields) { if (properties.containsKey(field.getName())) { + Object value = properties.get(field.getName()); + + Class type = field.getType(); + if (field.getAnnotation(ObjectProperty.class) == null) + AdvancedPeripherals.debug("The field " + field.getName() + " has no ObjectProperty annotation and can't be chaned.", Level.WARN); + + if ((type == Integer.class || type == int.class) && value instanceof Integer) { + int min = field.getAnnotation(ObjectProperty.class).minInt(); + int max = field.getAnnotation(ObjectProperty.class).maxInt(); + value = Math.min(Math.max((int) value, min), max); + } else if ((type == Double.class || type == double.class) && value instanceof Double) { + double min = field.getAnnotation(ObjectProperty.class).minDecimal(); + double max = field.getAnnotation(ObjectProperty.class).maxDecimal(); + value = Math.min(Math.max((double) value, min), max); + } else if (type == String.class && value instanceof String) { + int max = field.getAnnotation(ObjectProperty.class).maxString(); + value = ((String) value).substring(0, Math.min(((String) value).length(), max)); + } else { + throw new LuaException("The type " + field.getType() + " of " + field.getName() + " is not supported."); + } + // Make the field accessible field.setAccessible(true); // Set the value of the field - field.set(this, properties.get(field.getName())); + field.set(this, value); } } } catch (LuaException | IllegalAccessException exception) { diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/Panel.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/Panel.java index ba711c652..3a8bc6b12 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/Panel.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/Panel.java @@ -6,11 +6,10 @@ /** * A panel is the standard panel which can contain multiple render-able objects in it. */ -public class Panel extends OverlayObject { +public class Panel extends RenderableObject { public Panel(String id, OverlayModule module, IArguments arguments) throws LuaException { - super(id, module); - mapProperties(arguments); + super(id, module, arguments); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/RenderableObject.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/RenderableObject.java new file mode 100644 index 000000000..b3b12753f --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/RenderableObject.java @@ -0,0 +1,38 @@ +package de.srendi.advancedperipherals.common.smartglasses.modules.overlay; + +import dan200.computercraft.api.lua.IArguments; +import dan200.computercraft.api.lua.LuaException; +import dan200.computercraft.api.lua.LuaFunction; + +public abstract class RenderableObject extends OverlayObject { + + @ObjectProperty(minDecimal = 0, maxDecimal = 1) + public double opacity = 1; + + @ObjectProperty(minInt = 0, maxInt = 0xFFFFFF) + public int color = 0xFFFFFF; + + @LuaFunction + public double getOpacity() { + return opacity; + } + + @LuaFunction + public void setOpacity(double opacity) { + this.opacity = opacity; + } + + @LuaFunction + public int getColor() { + return color; + } + + @LuaFunction + public void setColor(int color) { + this.color = color; + } + + public RenderableObject(String id, OverlayModule module, IArguments arguments) throws LuaException { + super(id, module, arguments); + } +} diff --git a/src/main/resources/data/advancedperipherals/patchouli_books/manual/en_us/entries/items/ar_goggles.json b/src/main/resources/data/advancedperipherals/patchouli_books/manual/en_us/entries/items/ar_goggles.json deleted file mode 100644 index c7f47d5b3..000000000 --- a/src/main/resources/data/advancedperipherals/patchouli_books/manual/en_us/entries/items/ar_goggles.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "AR Goggles", - "icon": "advancedperipherals:ar_goggles", - "category": "advancedperipherals:items", - "pages": [ - { - "type": "text", - "text": "The AR Goggles can be used in combination with the $(9)$(l:peripherals/ar_controller)AR Controller$(/l)$() to have a customizable overlay wherever you go. Fun!$(p)Right click an AR Controller with your glasses to link them.$(p)For the full documentation please see the $(9)$(l:https://docs.intelligence-modding.de/items/ar_goggles/)official wiki page$(/l)$()!" - }, - { - "type": "crafting", - "recipe": "advancedperipherals:ar_goggles" - } - ] -} diff --git a/src/main/resources/data/advancedperipherals/patchouli_books/manual/en_us/entries/peripherals/ar_controller.json b/src/main/resources/data/advancedperipherals/patchouli_books/manual/en_us/entries/peripherals/ar_controller.json deleted file mode 100644 index 465610e71..000000000 --- a/src/main/resources/data/advancedperipherals/patchouli_books/manual/en_us/entries/peripherals/ar_controller.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "AR Controller", - "icon": "advancedperipherals:ar_controller", - "category": "advancedperipherals:peripherals", - "pages": [ - { - "type": "text", - "text": "The AR Controller is used to control your AR Goggles wirelessly. You can draw anything you wish into an overlay that will be visible as long as you're wearing the goggles.$(p)For the full documentation please see the $(9)$(l:https://docs.intelligence-modding.de/peripherals/ar_controller/)official wiki page$(/l)$()!" - }, - { - "type": "crafting", - "recipe": "advancedperipherals:ar_controller" - }, - { - "type": "multiblock", - "multiblock": { - "mapping": { - "0": "computercraft:computer_advanced", - "P": "advancedperipherals:ar_controller" - }, - "pattern": [ - [ - "0P" - ] - ] - }, - "text": "Connect your AR Controller to a computer to make use of it!" - } - ] -} From e5849b60288bbcfd11e2ae7e940b4f46f54ecc95 Mon Sep 17 00:00:00 2001 From: Deniz Demiroglu Date: Thu, 28 Sep 2023 15:07:47 +0200 Subject: [PATCH 064/228] Improve the way how we map the arguments retrieved from the lua endpoint to the fields of our class. We're now using an annotation based system to further improve security and implement optional range limits needed for some values. --- .github/FUNDING.yml | 3 +- .../modules/overlay/ObjectProperty.java | 20 +-- .../modules/overlay/OverlayModule.java | 3 +- .../modules/overlay/OverlayObject.java | 124 ++++++++++++++---- .../modules/overlay/RenderableObject.java | 7 +- .../propertyTypes/BooleanProperty.java | 15 +++ .../overlay/propertyTypes/BooleanType.java | 20 +++ .../FixedPointNumberProperty.java | 18 +++ .../propertyTypes/FixedPointNumberType.java | 34 +++++ .../propertyTypes/FloatingNumberProperty.java | 18 +++ .../propertyTypes/FloatingNumberType.java | 29 ++++ .../overlay/propertyTypes/PropertyType.java | 31 +++++ .../common/util/StringUtil.java | 7 + 13 files changed, 288 insertions(+), 41 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/BooleanProperty.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/BooleanType.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FixedPointNumberProperty.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FixedPointNumberType.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FloatingNumberProperty.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FloatingNumberType.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/PropertyType.java diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 4cd1fe88c..66d7109fd 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1 +1,2 @@ -patreon: srendi +ko_fi: srendi +github: SirEndii \ No newline at end of file diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/ObjectProperty.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/ObjectProperty.java index 8f433ab4e..4f332efd5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/ObjectProperty.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/ObjectProperty.java @@ -1,18 +1,22 @@ package de.srendi.advancedperipherals.common.smartglasses.modules.overlay; +import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertyTypes.PropertyType; + +import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +/** + * This annotation is used to mark a field as a property. It is used for the properties of lua objects. + * Fields annotated with @ObjectProperty will be accessible in lua via the arguments/the filter table for the specific object. + * @see PropertyType + * @see OverlayObject + */ @Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.ANNOTATION_TYPE) public @interface ObjectProperty { - int minInt() default Integer.MIN_VALUE; - - int maxInt() default Integer.MAX_VALUE; - - double maxDecimal() default Double.MAX_VALUE; - - double minDecimal() default Double.MIN_VALUE; + Class> type(); - int maxString() default Integer.MAX_VALUE; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java index 98f71bd41..d22aa71ce 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java @@ -6,7 +6,6 @@ import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleFunctions; import de.srendi.advancedperipherals.common.util.Pair; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.Entity; import org.jetbrains.annotations.NotNull; import java.util.concurrent.CopyOnWriteArraySet; @@ -32,9 +31,11 @@ public IModuleFunctions getFunctions(SmartGlassesAccess smartGlassesAccess) { @Override public void tick(@NotNull SmartGlassesAccess smartGlassesAccess) { + /* Entity entity = smartGlassesAccess.getEntity(); if (entity != null && entity.getLevel().getGameTime() % 20 == 0) AdvancedPeripherals.LOGGER.info("I'm an overlay module! And I'm alive!"); + */ } public CopyOnWriteArraySet getObjects() { diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayObject.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayObject.java index ad786fdf8..961c60243 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayObject.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayObject.java @@ -5,9 +5,13 @@ import dan200.computercraft.api.lua.LuaFunction; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.configuration.APConfig; +import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertyTypes.BooleanProperty; +import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertyTypes.PropertyType; +import de.srendi.advancedperipherals.common.util.StringUtil; import org.apache.commons.lang3.reflect.FieldUtils; import org.apache.logging.log4j.Level; +import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.util.Map; import java.util.stream.Collectors; @@ -15,15 +19,15 @@ public abstract class OverlayObject { - @ObjectProperty + @BooleanProperty private boolean enabled = true; + private final String id; private final OverlayModule module; - public OverlayObject(String id, OverlayModule module, IArguments arguments) throws LuaException { + public OverlayObject(String id, OverlayModule module, IArguments arguments) { this.id = id; this.module = module; - mapProperties(arguments); } @LuaFunction @@ -45,12 +49,29 @@ public final boolean isEnabled() { return enabled; } - public void mapProperties(IArguments arguments) throws LuaException { - if(arguments.optTable(1).isEmpty()) + /** + * Maps properties from the provided arguments to the fields of this class. + *

+ * This method uses Java Reflection to map properties from IArguments to the fields of the classes. + * It only maps properties that have the annotation {@link ObjectProperty}. If a field does not have this annotation, + * a warning message is logged and the method returns. + *

+ * If a property is valid, its value is cast to the field type and set as the new value of the field. + * If a property is not valid, a warning message is logged and the method returns. + *

+ * If an error occurs during the mapping of properties, an exception message is logged and a LuaException is thrown. + * + * @param arguments the IArguments containing properties to be mapped + * @throws LuaException if an error occurs during the mapping of properties + * @see IArguments + * @see ObjectProperty + * @see PropertyType + */ + public void reflectivelyMapProperties(IArguments arguments) throws LuaException { + if (arguments.optTable(1).isEmpty()) return; try { - Map properties = arguments.optTable(1).get().entrySet().stream() .filter(entry -> entry.getKey() instanceof String) .collect(Collectors.toMap(entry -> (String) entry.getKey(), Map.Entry::getValue)); @@ -59,32 +80,43 @@ public void mapProperties(IArguments arguments) throws LuaException { for (Field field : allFields) { if (properties.containsKey(field.getName())) { - Object value = properties.get(field.getName()); - - Class type = field.getType(); - if (field.getAnnotation(ObjectProperty.class) == null) - AdvancedPeripherals.debug("The field " + field.getName() + " has no ObjectProperty annotation and can't be chaned.", Level.WARN); - - if ((type == Integer.class || type == int.class) && value instanceof Integer) { - int min = field.getAnnotation(ObjectProperty.class).minInt(); - int max = field.getAnnotation(ObjectProperty.class).maxInt(); - value = Math.min(Math.max((int) value, min), max); - } else if ((type == Double.class || type == double.class) && value instanceof Double) { - double min = field.getAnnotation(ObjectProperty.class).minDecimal(); - double max = field.getAnnotation(ObjectProperty.class).maxDecimal(); - value = Math.min(Math.max((double) value, min), max); - } else if (type == String.class && value instanceof String) { - int max = field.getAnnotation(ObjectProperty.class).maxString(); - value = ((String) value).substring(0, Math.min(((String) value).length(), max)); - } else { - throw new LuaException("The type " + field.getType() + " of " + field.getName() + " is not supported."); + var value = properties.get(field.getName()); + + Annotation[] fieldProperties = field.getAnnotations(); + ObjectProperty objectProperty = null; + Annotation propertyAnnotation = null; + + for (Annotation annotation : fieldProperties) { + objectProperty = annotation.annotationType().getAnnotation(ObjectProperty.class); + if (objectProperty != null) { + propertyAnnotation = annotation; + break; + } + } + + if (objectProperty == null) { + AdvancedPeripherals.debug("The field " + field.getName() + " has no ObjectProperty annotation and can't be changed.", Level.WARN); + return; } - // Make the field accessible - field.setAccessible(true); + PropertyType propertyType = PropertyType.of(objectProperty); + if (propertyType != null) { + value = castValueToFieldType(field, value); + if (propertyType.checkIsValid(value)) { + propertyType.init(propertyAnnotation); + value = propertyType.mapValue(value); + + // Make the field accessible + field.setAccessible(true); + + // Set the value of the field + field.set(this, castValueToFieldType(field, value)); - // Set the value of the field - field.set(this, value); + } else { + AdvancedPeripherals.debug("The value " + value + " is not valid for the field " + field.getName() + ".", Level.WARN); + return; + } + } } } } catch (LuaException | IllegalAccessException exception) { @@ -93,4 +125,38 @@ public void mapProperties(IArguments arguments) throws LuaException { throw new LuaException("An error occurred while mapping properties."); } } + + /** + * Casts the given value to the type of the provided field. + * Can be overwritten if the desired casting is not supported. + * + * @param field the field object representing the type to cast to + * @param value the value to be casted + * @return the casted value + */ + public Object castValueToFieldType(Field field, Object value) { + Class fieldType = field.getType(); + + if (fieldType.isAssignableFrom(value.getClass())) { + return value; + } else if (fieldType.equals(Integer.TYPE)) { + return Integer.valueOf(StringUtil.removeFloatingPoints(value.toString())); + } else if (fieldType.equals(Double.TYPE)) { + return Double.valueOf(value.toString()); + } else if (fieldType.equals(Boolean.TYPE)) { + return Boolean.valueOf(value.toString()); + } else if (fieldType.equals(Long.TYPE)) { + return Long.valueOf(StringUtil.removeFloatingPoints(value.toString())); + } else if (fieldType.equals(Short.TYPE)) { + return Short.valueOf(StringUtil.removeFloatingPoints(value.toString())); + } else if (fieldType.equals(Byte.TYPE)) { + return Byte.valueOf(StringUtil.removeFloatingPoints(value.toString())); + } else if (fieldType.equals(Float.TYPE)) { + return Float.valueOf(value.toString()); + } else { + AdvancedPeripherals.debug("The field type " + fieldType.getName() + " is not supported for the value " + value + ".", Level.WARN); + } + return value; + } + } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/RenderableObject.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/RenderableObject.java index b3b12753f..75d42d018 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/RenderableObject.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/RenderableObject.java @@ -3,13 +3,15 @@ import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaFunction; +import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertyTypes.FixedPointNumberProperty; +import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertyTypes.FloatingNumberProperty; public abstract class RenderableObject extends OverlayObject { - @ObjectProperty(minDecimal = 0, maxDecimal = 1) + @FloatingNumberProperty(min = 0, max = 1) public double opacity = 1; - @ObjectProperty(minInt = 0, maxInt = 0xFFFFFF) + @FixedPointNumberProperty(min = 0, max = 0xFFFFFF) public int color = 0xFFFFFF; @LuaFunction @@ -34,5 +36,6 @@ public void setColor(int color) { public RenderableObject(String id, OverlayModule module, IArguments arguments) throws LuaException { super(id, module, arguments); + reflectivelyMapProperties(arguments); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/BooleanProperty.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/BooleanProperty.java new file mode 100644 index 000000000..dc082c9d8 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/BooleanProperty.java @@ -0,0 +1,15 @@ +package de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertyTypes; + +import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.ObjectProperty; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +@ObjectProperty(type = BooleanType.class) +public @interface BooleanProperty { + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/BooleanType.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/BooleanType.java new file mode 100644 index 000000000..25ab0f531 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/BooleanType.java @@ -0,0 +1,20 @@ +package de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertyTypes; + +public class BooleanType implements PropertyType { + + @Override + public boolean checkIsValid(Object type) { + return type instanceof Boolean; + } + + @Override + public Boolean mapValue(Object type) { + return (Boolean) type; + } + + @Override + public void init(Object property) { + // Nothing to init here, we don't have any filters for booleans + } +} + diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FixedPointNumberProperty.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FixedPointNumberProperty.java new file mode 100644 index 000000000..a65635363 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FixedPointNumberProperty.java @@ -0,0 +1,18 @@ +package de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertyTypes; + +import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.ObjectProperty; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +@ObjectProperty(type = FixedPointNumberType.class) +public @interface FixedPointNumberProperty { + + long min() default Long.MIN_VALUE; + long max() default Long.MAX_VALUE; + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FixedPointNumberType.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FixedPointNumberType.java new file mode 100644 index 000000000..04bf3bde7 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FixedPointNumberType.java @@ -0,0 +1,34 @@ +package de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertyTypes; + +import de.srendi.advancedperipherals.AdvancedPeripherals; + +public class FixedPointNumberType implements PropertyType { + + public long min; + public long max; + + @Override + public boolean checkIsValid(Object type) { + return type instanceof Long || type instanceof Integer || type instanceof Short || type instanceof Byte; + } + + @Override + public Number mapValue(Object type) { + if (type instanceof Long) + return Math.min(Math.max((long) type, min), max); + if (type instanceof Integer) + return Math.min(Math.max((int) type, (int) min), (int) max); + if (type instanceof Short) + return Math.min(Math.max((short) type, (short) min), (short) max); + return Math.min(Math.max((byte) type, (byte) min), (byte) max); + } + + @Override + public void init(Object property) { + FixedPointNumberProperty decimalProperty = (FixedPointNumberProperty) property; + min = decimalProperty.min(); + max = decimalProperty.max(); + AdvancedPeripherals.debug("Initialized number property with min " + min + " and max " + max); + } +} + diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FloatingNumberProperty.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FloatingNumberProperty.java new file mode 100644 index 000000000..e377472f3 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FloatingNumberProperty.java @@ -0,0 +1,18 @@ +package de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertyTypes; + +import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.ObjectProperty; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +@ObjectProperty(type = FloatingNumberType.class) +public @interface FloatingNumberProperty { + + double min() default Double.MIN_VALUE; + double max() default Double.MAX_VALUE; + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FloatingNumberType.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FloatingNumberType.java new file mode 100644 index 000000000..05d6eb8df --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FloatingNumberType.java @@ -0,0 +1,29 @@ +package de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertyTypes; + +import de.srendi.advancedperipherals.AdvancedPeripherals; + +public class FloatingNumberType implements PropertyType { + + public double min; + public double max; + + @Override + public boolean checkIsValid(Object type) { + return type instanceof Float || type instanceof Double; + } + + @Override + public Number mapValue(Object type) { + AdvancedPeripherals.debug("Mapping value " + type + " to " + Math.min(Math.max((double) type, min), max)); + return Math.min(Math.max((double) type, min), max); + } + + @Override + public void init(Object property) { + FloatingNumberProperty decimalProperty = (FloatingNumberProperty) property; + min = decimalProperty.min(); + max = decimalProperty.max(); + AdvancedPeripherals.debug("Initialized decimal property with min " + min + " and max " + max); + } +} + diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/PropertyType.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/PropertyType.java new file mode 100644 index 000000000..bd29944ba --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/PropertyType.java @@ -0,0 +1,31 @@ +package de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertyTypes; + +import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.ObjectProperty; + +import java.lang.reflect.InvocationTargetException; + +/** + * This interface represents a property type. It is used to check if a value is valid for the property and to map the value to the correct type. + * + * @param the type of the property value + * @see ObjectProperty + */ +public interface PropertyType { + + boolean checkIsValid(Object type); + + T mapValue(Object type); + + static PropertyType of(ObjectProperty property) { + try { + return property.type().getDeclaredConstructor().newInstance(); + } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException exception) { + AdvancedPeripherals.exception("An error occurred while trying to create the property type", exception); + } + return null; + } + + void init(Object property); + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/StringUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/StringUtil.java index bc586425d..dcf2ab95a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/StringUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/StringUtil.java @@ -12,4 +12,11 @@ public static String toHexString(byte[] bytes) { } return new String(hexChars); } + + public static String removeFloatingPoints(String number) { + if (number.contains(".")) { + return number.substring(0, number.indexOf(".")); + } + return number; + } } From ee2ab274f36ea6f3478c5dff84fe427e966e5dc7 Mon Sep 17 00:00:00 2001 From: Deniz Demiroglu Date: Thu, 28 Sep 2023 17:38:22 +0200 Subject: [PATCH 065/228] swoosh --- .../common/blocks/blockentities/DistanceDetectorEntity.java | 2 +- .../advancedperipherals/common/network/PacketHandler.java | 1 + .../network/{ => toclient}/DistanceDetectorSyncPacket.java | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) rename src/main/java/de/srendi/advancedperipherals/common/network/{ => toclient}/DistanceDetectorSyncPacket.java (97%) diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java index 707039e7c..94c8b11d9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java @@ -4,8 +4,8 @@ import de.srendi.advancedperipherals.common.blocks.base.BaseBlock; import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.network.DistanceDetectorSyncPacket; import de.srendi.advancedperipherals.common.network.PacketHandler; +import de.srendi.advancedperipherals.common.network.toclient.DistanceDetectorSyncPacket; import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; import de.srendi.advancedperipherals.common.util.HitResultUtil; import net.minecraft.core.BlockPos; diff --git a/src/main/java/de/srendi/advancedperipherals/common/network/PacketHandler.java b/src/main/java/de/srendi/advancedperipherals/common/network/PacketHandler.java index 5928489a6..46b508489 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/network/PacketHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/network/PacketHandler.java @@ -2,6 +2,7 @@ import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.network.base.IPacket; +import de.srendi.advancedperipherals.common.network.toclient.DistanceDetectorSyncPacket; import net.minecraft.core.BlockPos; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; diff --git a/src/main/java/de/srendi/advancedperipherals/common/network/DistanceDetectorSyncPacket.java b/src/main/java/de/srendi/advancedperipherals/common/network/toclient/DistanceDetectorSyncPacket.java similarity index 97% rename from src/main/java/de/srendi/advancedperipherals/common/network/DistanceDetectorSyncPacket.java rename to src/main/java/de/srendi/advancedperipherals/common/network/toclient/DistanceDetectorSyncPacket.java index e8678202a..484ec7520 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/network/DistanceDetectorSyncPacket.java +++ b/src/main/java/de/srendi/advancedperipherals/common/network/toclient/DistanceDetectorSyncPacket.java @@ -1,4 +1,4 @@ -package de.srendi.advancedperipherals.common.network; +package de.srendi.advancedperipherals.common.network.toclient; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.blocks.blockentities.DistanceDetectorEntity; From 79f5c86a6dae756149ffece05d81da2a28ca923e Mon Sep 17 00:00:00 2001 From: Deniz Demiroglu Date: Mon, 2 Oct 2023 16:27:36 +0200 Subject: [PATCH 066/228] Trying a way to sync the overlay objects to the client of a player. Actual synchronisation isn't implemented, this is just a prototype --- .../AdvancedPeripherals.java | 3 +- .../smartglasses/SmartGlassesComputer.java | 2 +- .../smartglasses/modules/IModuleItem.java | 4 +- .../overlay/OverlayGlassesFunctions.java | 3 ++ .../modules/overlay/OverlayGlassesItem.java | 5 +- .../modules/overlay/OverlayModule.java | 11 ++++- .../modules/overlay/OverlayObject.java | 40 ++++++++++++++-- .../smartglasses/modules/overlay/Panel.java | 46 +++++++++++++++++++ .../modules/overlay/RenderableObject.java | 6 +++ 9 files changed, 110 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java index 44ebb8127..a52cf0fa7 100644 --- a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java +++ b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java @@ -50,8 +50,9 @@ public static void debug(String message, Level level) { } public static void exception(String message, Exception exception) { - if (APConfig.GENERAL_CONFIG.enableDebugMode.get()) + if (APConfig.GENERAL_CONFIG.enableDebugMode.get()) { LOGGER.error("[DEBUG]", exception); + } } public static ResourceLocation getRL(String resource) { diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java index aa9a4fe89..bf7db8eff 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java @@ -152,7 +152,7 @@ public void updatePeripheralsAndModules(IItemHandler itemHandler) { for (int slot = 4; slot < 11; slot++) { ItemStack peripheralItem = itemHandler.getStackInSlot(slot); if (!peripheralItem.isEmpty() && peripheralItem.getItem() instanceof IModuleItem module) { - modules.add(module.getModule()); + modules.add(module.getModule(smartGlassesAccess)); } } setPeripheral(ComputerSide.BACK, new ModulePeripheral(this)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModuleItem.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModuleItem.java index 748063fef..2854d509c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModuleItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModuleItem.java @@ -1,7 +1,9 @@ package de.srendi.advancedperipherals.common.smartglasses.modules; +import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesAccess; + public interface IModuleItem { - IModule getModule(); + IModule getModule(SmartGlassesAccess access); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesFunctions.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesFunctions.java index 45b6babce..2ad26b3a8 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesFunctions.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesFunctions.java @@ -4,6 +4,7 @@ import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.lua.MethodResult; +import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesAccess; import de.srendi.advancedperipherals.common.smartglasses.modules.IModule; import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleFunctions; import de.srendi.advancedperipherals.common.util.Pair; @@ -11,9 +12,11 @@ public class OverlayGlassesFunctions implements IModuleFunctions { private final OverlayModule overlayModule; + private final SmartGlassesAccess access; public OverlayGlassesFunctions(OverlayModule overlayModule) { this.overlayModule = overlayModule; + this.access = overlayModule.access; } @LuaFunction diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesItem.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesItem.java index d0c743865..ca71eae2f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesItem.java @@ -1,6 +1,7 @@ package de.srendi.advancedperipherals.common.smartglasses.modules.overlay; import de.srendi.advancedperipherals.common.items.base.BaseItem; +import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesAccess; import de.srendi.advancedperipherals.common.smartglasses.modules.IModule; import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleItem; @@ -12,7 +13,7 @@ public boolean isEnabled() { } @Override - public IModule getModule() { - return new OverlayModule(); + public IModule getModule(SmartGlassesAccess smartGlassesAccess) { + return new OverlayModule(smartGlassesAccess); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java index d22aa71ce..9164f4d5e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java @@ -17,7 +17,12 @@ */ public class OverlayModule implements IModule { - private final CopyOnWriteArraySet objects = new CopyOnWriteArraySet<>(); + public final CopyOnWriteArraySet objects = new CopyOnWriteArraySet<>(); + public final SmartGlassesAccess access; + + public OverlayModule(SmartGlassesAccess access) { + this.access = access; + } @Override public ResourceLocation getName() { @@ -38,6 +43,10 @@ public void tick(@NotNull SmartGlassesAccess smartGlassesAccess) { */ } + public SmartGlassesAccess getAccess() { + return access; + } + public CopyOnWriteArraySet getObjects() { return objects; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayObject.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayObject.java index 961c60243..ff584021d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayObject.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayObject.java @@ -4,16 +4,20 @@ import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaFunction; import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertyTypes.BooleanProperty; import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertyTypes.PropertyType; import de.srendi.advancedperipherals.common.util.StringUtil; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraftforge.network.NetworkEvent; import org.apache.commons.lang3.reflect.FieldUtils; import org.apache.logging.log4j.Level; import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.util.Map; +import java.util.UUID; import java.util.stream.Collectors; @@ -23,13 +27,22 @@ public abstract class OverlayObject { private boolean enabled = true; private final String id; - private final OverlayModule module; + private OverlayModule module; + private UUID player; public OverlayObject(String id, OverlayModule module, IArguments arguments) { this.id = id; this.module = module; } + /** + * For clientside initialization + */ + public OverlayObject(String id, UUID player) { + this.id = id; + this.player = player; + } + @LuaFunction public final String getId() { return id; @@ -39,6 +52,10 @@ public OverlayModule getModule() { return module; } + public UUID getPlayer() { + return player; + } + @LuaFunction public final void setEnabled(boolean enabled) { this.enabled = enabled; @@ -120,8 +137,7 @@ public void reflectivelyMapProperties(IArguments arguments) throws LuaException } } } catch (LuaException | IllegalAccessException exception) { - if (APConfig.GENERAL_CONFIG.enableDebugMode.get()) - AdvancedPeripherals.exception("An error occurred while mapping properties.", exception); + AdvancedPeripherals.exception("An error occurred while mapping properties.", exception); throw new LuaException("An error occurred while mapping properties."); } } @@ -159,4 +175,20 @@ public Object castValueToFieldType(Field field, Object value) { return value; } + protected void handle(NetworkEvent.Context context) { + + } + + protected void encode(FriendlyByteBuf buffer) { + buffer.writeUtf(id); + Entity entity = module.getAccess().getEntity(); + if(entity instanceof Player player) { + buffer.writeBoolean(true); + buffer.writeUUID(player.getUUID()); + } else { + // Should theoretically never happen. But better safe than sorry + buffer.writeBoolean(false); + } + } + } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/Panel.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/Panel.java index 3a8bc6b12..562c07f10 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/Panel.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/Panel.java @@ -2,6 +2,12 @@ import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.LuaException; +import de.srendi.advancedperipherals.AdvancedPeripherals; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraftforge.network.NetworkEvent; +import org.jetbrains.annotations.Nullable; + +import java.util.UUID; /** * A panel is the standard panel which can contain multiple render-able objects in it. @@ -12,4 +18,44 @@ public Panel(String id, OverlayModule module, IArguments arguments) throws LuaEx super(id, module, arguments); } + /** + * constructor for the client side initialization + * + * @param id id of the object + * @param player the target player + */ + public Panel(String id, UUID player) { + super(id, player); + } + + @Override + protected void encode(FriendlyByteBuf buffer) { + super.encode(buffer); + buffer.writeInt(color); + buffer.writeDouble(opacity); + } + + @Nullable + public static Panel decode(FriendlyByteBuf buffer) { + String id = buffer.readUtf(); + boolean hasValidUUID = buffer.readBoolean(); + if (!hasValidUUID) { + AdvancedPeripherals.exception("Tried to decode a buffer for an OverlayObject but without a valid player as target.", new IllegalArgumentException()); + return null; + } + UUID player = buffer.readUUID(); + int color = buffer.readInt(); + double opacity = buffer.readDouble(); + + Panel clientPanel = new Panel(id, player); + clientPanel.color = color; + clientPanel.opacity = opacity; + + return clientPanel; + } + + @Override + protected void handle(NetworkEvent.Context context) { + super.handle(context); + } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/RenderableObject.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/RenderableObject.java index 75d42d018..01cad70a2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/RenderableObject.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/RenderableObject.java @@ -6,6 +6,8 @@ import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertyTypes.FixedPointNumberProperty; import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertyTypes.FloatingNumberProperty; +import java.util.UUID; + public abstract class RenderableObject extends OverlayObject { @FloatingNumberProperty(min = 0, max = 1) @@ -38,4 +40,8 @@ public RenderableObject(String id, OverlayModule module, IArguments arguments) t super(id, module, arguments); reflectivelyMapProperties(arguments); } + + public RenderableObject(String id, UUID player) { + super(id, player); + } } From 03c3a40ec12f50ae008e5f4b86c8ce15efbc29d8 Mon Sep 17 00:00:00 2001 From: Deniz Date: Tue, 3 Oct 2023 01:47:15 +0200 Subject: [PATCH 067/228] Move to snake_case peripheral names to better fit with CC:T's standards --- .../common/addons/botania/ManaFlowerIntegration.java | 2 +- .../common/addons/botania/ManaPoolIntegration.java | 2 +- .../common/addons/botania/SpreaderIntegration.java | 2 +- .../addons/computercraft/peripheral/BlockReaderPeripheral.java | 2 +- .../addons/computercraft/peripheral/ChatBoxPeripheral.java | 2 +- .../addons/computercraft/peripheral/ColonyPeripheral.java | 2 +- .../computercraft/peripheral/DistanceDetectorPeripheral.java | 2 +- .../computercraft/peripheral/EnergyDetectorPeripheral.java | 2 +- .../computercraft/peripheral/EnvironmentDetectorPeripheral.java | 2 +- .../computercraft/peripheral/FluidDetectorPeripheral.java | 2 +- .../addons/computercraft/peripheral/GasDetectorPeripheral.java | 2 +- .../addons/computercraft/peripheral/GeoScannerPeripheral.java | 2 +- .../computercraft/peripheral/InventoryManagerPeripheral.java | 2 +- .../addons/computercraft/peripheral/MeBridgePeripheral.java | 2 +- .../addons/computercraft/peripheral/NBTStoragePeripheral.java | 2 +- .../computercraft/peripheral/PlayerDetectorPeripheral.java | 2 +- .../computercraft/peripheral/RedstoneIntegratorPeripheral.java | 2 +- .../addons/computercraft/peripheral/RsBridgePeripheral.java | 2 +- .../peripheral/metaphysics/EndAutomataCorePeripheral.java | 2 +- .../peripheral/metaphysics/HusbandryAutomataCorePeripheral.java | 2 +- .../metaphysics/OverpoweredEndAutomataCorePeripheral.java | 2 +- .../metaphysics/OverpoweredHusbandryAutomataCorePeripheral.java | 2 +- .../metaphysics/OverpoweredWeakAutomataCorePeripheral.java | 2 +- .../peripheral/metaphysics/WeakAutomataCorePeripheral.java | 2 +- .../common/addons/create/BlazeBurnerIntegration.java | 2 +- .../common/addons/create/FluidTankIntegration.java | 2 +- .../common/addons/create/MechanicalMixerIntegration.java | 2 +- .../common/addons/create/ScrollValueBehaviourIntegration.java | 2 +- .../common/addons/powah/EnderCellIntegration.java | 2 +- .../common/addons/powah/EnergyCellIntegration.java | 2 +- .../common/addons/powah/ReactorIntegration.java | 2 +- .../common/addons/powah/SolarPanelIntegration.java | 2 +- 32 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaFlowerIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaFlowerIntegration.java index 4a18763bd..fb3c8e1c2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaFlowerIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaFlowerIntegration.java @@ -15,7 +15,7 @@ public ManaFlowerIntegration(BlockEntity entity) { @NotNull @Override public String getType() { - return "manaFlower"; + return "mana_flower"; } @LuaFunction(mainThread = true) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaPoolIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaPoolIntegration.java index cea44bbe9..2d2fb83c9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaPoolIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaPoolIntegration.java @@ -15,7 +15,7 @@ public ManaPoolIntegration(BlockEntity entity) { @NotNull @Override public String getType() { - return "manaPool"; + return "mana_pool"; } @LuaFunction(mainThread = true) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/botania/SpreaderIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/botania/SpreaderIntegration.java index e0ea451f9..d615db44f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/botania/SpreaderIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/botania/SpreaderIntegration.java @@ -16,7 +16,7 @@ public SpreaderIntegration(BlockEntity entity) { @NotNull @Override public String getType() { - return "manaSpreader"; + return "mana_spreader"; } @LuaFunction(mainThread = true) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/BlockReaderPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/BlockReaderPeripheral.java index c56de4466..a44d40593 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/BlockReaderPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/BlockReaderPeripheral.java @@ -13,7 +13,7 @@ public class BlockReaderPeripheral extends BasePeripheral> { - public static final String PERIPHERAL_TYPE = "blockReader"; + public static final String PERIPHERAL_TYPE = "block_reader"; public BlockReaderPeripheral(BlockReaderEntity tileEntity) { super(PERIPHERAL_TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java index ee9f20d6b..d9beed7e1 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java @@ -33,7 +33,7 @@ public class ChatBoxPeripheral extends BasePeripheral { - public static final String PERIPHERAL_TYPE = "chatBox"; + public static final String PERIPHERAL_TYPE = "chat_box"; protected ChatBoxPeripheral(IPeripheralOwner owner) { super(PERIPHERAL_TYPE, owner); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ColonyPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ColonyPeripheral.java index 5a689c538..d322dcdd0 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ColonyPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ColonyPeripheral.java @@ -37,7 +37,7 @@ public class ColonyPeripheral extends BasePeripheral { - public static final String PERIPHERAL_TYPE = "colonyIntegrator"; + public static final String PERIPHERAL_TYPE = "colony_integrator"; protected boolean hasPermission = true; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java index 65d8579c7..af1045e4c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java @@ -8,7 +8,7 @@ public class DistanceDetectorPeripheral extends BasePeripheral> { - public static final String PERIPHERAL_TYPE = "distanceDetector"; + public static final String PERIPHERAL_TYPE = "distance_detector"; public DistanceDetectorPeripheral(DistanceDetectorEntity tileEntity) { super(PERIPHERAL_TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/EnergyDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/EnergyDetectorPeripheral.java index 8b0e016f2..0898fb611 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/EnergyDetectorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/EnergyDetectorPeripheral.java @@ -8,7 +8,7 @@ public class EnergyDetectorPeripheral extends BasePeripheral> { - public static final String PERIPHERAL_TYPE = "energyDetector"; + public static final String PERIPHERAL_TYPE = "energy_detector"; public EnergyDetectorPeripheral(EnergyDetectorEntity tileEntity) { super(PERIPHERAL_TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/EnvironmentDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/EnvironmentDetectorPeripheral.java index e2c9caff3..0054a4d45 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/EnvironmentDetectorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/EnvironmentDetectorPeripheral.java @@ -45,7 +45,7 @@ public class EnvironmentDetectorPeripheral extends BasePeripheral { - public static final String PERIPHERAL_TYPE = "environmentDetector"; + public static final String PERIPHERAL_TYPE = "environment_detector"; private static final List> PERIPHERAL_PLUGINS = new LinkedList<>(); protected EnvironmentDetectorPeripheral(IPeripheralOwner owner) { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/FluidDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/FluidDetectorPeripheral.java index 740b18f98..c54dde612 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/FluidDetectorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/FluidDetectorPeripheral.java @@ -9,7 +9,7 @@ public class FluidDetectorPeripheral extends BasePeripheral> { - public static final String TYPE = "fluidDetector"; + public static final String TYPE = "fluid_detector"; public FluidDetectorPeripheral(FluidDetectorEntity tileEntity) { super(TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/GasDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/GasDetectorPeripheral.java index d344acaf4..fd94811e3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/GasDetectorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/GasDetectorPeripheral.java @@ -8,7 +8,7 @@ public class GasDetectorPeripheral extends BasePeripheral> { - public static final String TYPE = "gasDetector"; + public static final String TYPE = "gas_detector"; public GasDetectorPeripheral(GasDetectorEntity tileEntity) { super(TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/GeoScannerPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/GeoScannerPeripheral.java index 438815585..c94496149 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/GeoScannerPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/GeoScannerPeripheral.java @@ -41,7 +41,7 @@ public class GeoScannerPeripheral extends BasePeripheral { Highly inspired by https://github.com/SquidDev-CC/plethora/ BlockScanner */ - public static final String PERIPHERAL_TYPE = "geoScanner"; + public static final String PERIPHERAL_TYPE = "geo_scanner"; protected GeoScannerPeripheral(IPeripheralOwner owner) { super(PERIPHERAL_TYPE, owner); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java index a94629300..002cc5fe4 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java @@ -29,7 +29,7 @@ public class InventoryManagerPeripheral extends BasePeripheral> { - public static final String PERIPHERAL_TYPE = "inventoryManager"; + public static final String PERIPHERAL_TYPE = "inventory_manager"; public InventoryManagerPeripheral(InventoryManagerEntity tileEntity) { super(PERIPHERAL_TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java index ffeb22eae..09390e22d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java @@ -34,7 +34,7 @@ public class MeBridgePeripheral extends BasePeripheral> implements IStoragePeripheral { - public static final String PERIPHERAL_TYPE = "meBridge"; + public static final String PERIPHERAL_TYPE = "me_bridge"; private final MeBridgeEntity tile; private IGridNode node; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/NBTStoragePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/NBTStoragePeripheral.java index 5e327d1f6..957594180 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/NBTStoragePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/NBTStoragePeripheral.java @@ -18,7 +18,7 @@ public class NBTStoragePeripheral extends BasePeripheral> { - public static final String PERIPHERAL_TYPE = "nbtStorage"; + public static final String PERIPHERAL_TYPE = "nbt_storage"; public NBTStoragePeripheral(NBTStorageEntity tileEntity) { super(PERIPHERAL_TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/PlayerDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/PlayerDetectorPeripheral.java index 737ddbbc1..fdeee939c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/PlayerDetectorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/PlayerDetectorPeripheral.java @@ -26,7 +26,7 @@ public class PlayerDetectorPeripheral extends BasePeripheral { - public static final String PERIPHERAL_TYPE = "playerDetector"; + public static final String PERIPHERAL_TYPE = "player_detector"; private static final int MAX_RANGE = APConfig.PERIPHERALS_CONFIG.playerDetMaxRange.get(); public PlayerDetectorPeripheral(PeripheralBlockEntity tileEntity) { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RedstoneIntegratorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RedstoneIntegratorPeripheral.java index ec70aa47c..b3d181a4c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RedstoneIntegratorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RedstoneIntegratorPeripheral.java @@ -10,7 +10,7 @@ public class RedstoneIntegratorPeripheral extends BasePeripheral> { - public static final String PERIPHERAL_TYPE = "redstoneIntegrator"; + public static final String PERIPHERAL_TYPE = "redstone_integrator"; public RedstoneIntegratorPeripheral(RedstoneIntegratorEntity tileEntity) { super(PERIPHERAL_TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java index 5dba42066..a158e8cf0 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java @@ -31,7 +31,7 @@ public class RsBridgePeripheral extends BasePeripheral> implements IStoragePeripheral { - public static final String PERIPHERAL_TYPE = "rsBridge"; + public static final String PERIPHERAL_TYPE = "rs_bridge"; public RsBridgePeripheral(RsBridgeEntity tileEntity) { super(PERIPHERAL_TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/EndAutomataCorePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/EndAutomataCorePeripheral.java index 90f6ceda7..bb50f1d60 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/EndAutomataCorePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/EndAutomataCorePeripheral.java @@ -10,7 +10,7 @@ public class EndAutomataCorePeripheral extends WeakAutomataCorePeripheral { - public static final String TYPE = "endAutomata"; + public static final String TYPE = "end_automata"; public EndAutomataCorePeripheral(ITurtleAccess turtle, TurtleSide side) { this(TYPE, turtle, side, AutomataCoreTier.TIER2); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/HusbandryAutomataCorePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/HusbandryAutomataCorePeripheral.java index baba65bfd..ba89f1629 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/HusbandryAutomataCorePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/HusbandryAutomataCorePeripheral.java @@ -14,7 +14,7 @@ import java.util.function.Predicate; public class HusbandryAutomataCorePeripheral extends WeakAutomataCorePeripheral { - public static final String TYPE = "husbandryAutomata"; + public static final String TYPE = "husbandry_automata"; private static final Predicate isAnimal = entity1 -> entity1.getType().getCategory().isFriendly(); private static final Predicate isLivingEntity = LivingEntity.class::isInstance; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredEndAutomataCorePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredEndAutomataCorePeripheral.java index 40a991573..392dcfaf2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredEndAutomataCorePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredEndAutomataCorePeripheral.java @@ -8,7 +8,7 @@ public class OverpoweredEndAutomataCorePeripheral extends EndAutomataCorePeripheral { - public static final String TYPE = "overpoweredEndAutomata"; + public static final String TYPE = "overpowered_end_automata"; public OverpoweredEndAutomataCorePeripheral(ITurtleAccess turtle, TurtleSide side) { super(TYPE, turtle, side, AutomataCoreTier.OVERPOWERED_TIER2); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredHusbandryAutomataCorePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredHusbandryAutomataCorePeripheral.java index 1a8bd8b68..220e9ce49 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredHusbandryAutomataCorePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredHusbandryAutomataCorePeripheral.java @@ -8,7 +8,7 @@ public class OverpoweredHusbandryAutomataCorePeripheral extends HusbandryAutomataCorePeripheral { - public static final String TYPE = "overpoweredHusbandryAutomata"; + public static final String TYPE = "overpowered_husbandry_automata"; public OverpoweredHusbandryAutomataCorePeripheral(ITurtleAccess turtle, TurtleSide side) { super(TYPE, turtle, side, AutomataCoreTier.OVERPOWERED_TIER2); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredWeakAutomataCorePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredWeakAutomataCorePeripheral.java index b902c81d0..1b19eb40e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredWeakAutomataCorePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredWeakAutomataCorePeripheral.java @@ -8,7 +8,7 @@ public class OverpoweredWeakAutomataCorePeripheral extends WeakAutomataCorePeripheral { - public static final String TYPE = "overpoweredWeakAutomata"; + public static final String TYPE = "overpowered_weak_automata"; public OverpoweredWeakAutomataCorePeripheral(ITurtleAccess turtle, TurtleSide side) { super(TYPE, turtle, side, AutomataCoreTier.OVERPOWERED_TIER1); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/WeakAutomataCorePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/WeakAutomataCorePeripheral.java index 1d06638da..64bd72511 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/WeakAutomataCorePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/WeakAutomataCorePeripheral.java @@ -9,7 +9,7 @@ import de.srendi.advancedperipherals.lib.peripherals.AutomataCorePeripheral; public class WeakAutomataCorePeripheral extends AutomataCorePeripheral { - public static final String TYPE = "weakAutomata"; + public static final String TYPE = "weak_automata"; public WeakAutomataCorePeripheral(ITurtleAccess turtle, TurtleSide side) { this(TYPE, turtle, side, AutomataCoreTier.TIER1); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/create/BlazeBurnerIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/create/BlazeBurnerIntegration.java index 88bde5dca..eb45e1f28 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/create/BlazeBurnerIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/create/BlazeBurnerIntegration.java @@ -18,7 +18,7 @@ public BlazeBurnerIntegration(BlockEntity entity) { @NotNull @Override public String getType() { - return "blazeBurner"; + return "blaze_burner"; } @LuaFunction(mainThread = true) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/create/FluidTankIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/create/FluidTankIntegration.java index e8d4b0779..cc59643e2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/create/FluidTankIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/create/FluidTankIntegration.java @@ -19,7 +19,7 @@ public FluidTankIntegration(BlockEntity entity) { @NotNull @Override public String getType() { - return "fluidTank"; + return "fluid_tank"; } @LuaFunction(mainThread = true) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/create/MechanicalMixerIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/create/MechanicalMixerIntegration.java index 0c87f7763..91140fd47 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/create/MechanicalMixerIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/create/MechanicalMixerIntegration.java @@ -16,7 +16,7 @@ public MechanicalMixerIntegration(BlockEntity entity) { @NotNull @Override public String getType() { - return "mechanicalMixer"; + return "mechanical_mixer"; } @LuaFunction(mainThread = true) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/create/ScrollValueBehaviourIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/create/ScrollValueBehaviourIntegration.java index 32dbc4a1d..81e58614b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/create/ScrollValueBehaviourIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/create/ScrollValueBehaviourIntegration.java @@ -19,7 +19,7 @@ public ScrollValueBehaviourIntegration(BlockEntity entity) { @NotNull @Override public String getType() { - return "scrollBehaviourEntity"; + return "scroll_behaviour_entity"; } @LuaFunction(mainThread = true) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/EnderCellIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/EnderCellIntegration.java index cee6df8b1..b6e2dcf76 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/EnderCellIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/EnderCellIntegration.java @@ -14,7 +14,7 @@ protected EnderCellIntegration(BlockEntity entity) { @NotNull @Override public String getType() { - return "enderCell"; + return "ender_cell"; } @LuaFunction(mainThread = true) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/EnergyCellIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/EnergyCellIntegration.java index c437e31a6..043b29f81 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/EnergyCellIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/EnergyCellIntegration.java @@ -14,7 +14,7 @@ protected EnergyCellIntegration(BlockEntity entity) { @NotNull @Override public String getType() { - return "energyCell"; + return "energy_cell"; } @LuaFunction(mainThread = true) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/ReactorIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/ReactorIntegration.java index d8f1a9db8..08f51db5e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/ReactorIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/ReactorIntegration.java @@ -15,7 +15,7 @@ protected ReactorIntegration(BlockEntity entity) { @Override @NotNull public String getType() { - return "uraniniteReactor"; + return "uraninite_reactor"; } @LuaFunction(mainThread = true) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/SolarPanelIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/SolarPanelIntegration.java index 238ce5999..c921ae00a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/SolarPanelIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/SolarPanelIntegration.java @@ -14,7 +14,7 @@ protected SolarPanelIntegration(BlockEntity entity) { @NotNull @Override public String getType() { - return "solarPanel"; + return "solar_panel"; } @LuaFunction(mainThread = true) From b53a7773d821b77e4ad8f12b7d0c3096bf114b48 Mon Sep 17 00:00:00 2001 From: Deniz Demiroglu Date: Wed, 4 Oct 2023 15:32:39 +0200 Subject: [PATCH 068/228] Remove our `to/fromPeripheral` functions and add the logic for peripheral based storages directly to the `impport` and `export` functions Needs to be documented --- .../peripheral/MeBridgePeripheral.java | 83 +++++++++--------- .../peripheral/RsBridgePeripheral.java | 84 ++++++++++--------- ...ral.java => IStorageSystemPeripheral.java} | 22 ++--- 3 files changed, 92 insertions(+), 97 deletions(-) rename src/main/java/de/srendi/advancedperipherals/common/util/inventory/{IStoragePeripheral.java => IStorageSystemPeripheral.java} (80%) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java index 09390e22d..595a9540c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java @@ -12,6 +12,7 @@ import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.lua.MethodResult; import dan200.computercraft.api.peripheral.IComputerAccess; +import dan200.computercraft.core.computer.ComputerSide; import de.srendi.advancedperipherals.common.addons.appliedenergistics.AppEngApi; import de.srendi.advancedperipherals.common.addons.appliedenergistics.CraftJob; import de.srendi.advancedperipherals.common.addons.appliedenergistics.MeFluidHandler; @@ -23,6 +24,7 @@ import de.srendi.advancedperipherals.common.util.ServerWorker; import de.srendi.advancedperipherals.common.util.inventory.*; import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; +import net.minecraft.core.Direction; import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.items.IItemHandler; import org.jetbrains.annotations.NotNull; @@ -31,8 +33,9 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.Locale; -public class MeBridgePeripheral extends BasePeripheral> implements IStoragePeripheral { +public class MeBridgePeripheral extends BasePeripheral> implements IStorageSystemPeripheral { public static final String PERIPHERAL_TYPE = "me_bridge"; private final MeBridgeEntity tile; @@ -222,38 +225,36 @@ public final MethodResult listCells() { } @Override - public final MethodResult importItem(IArguments arguments) throws LuaException { + public final MethodResult importItem(IComputerAccess computer, IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); - IItemHandler inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); - return importToME(arguments, inventory); - } + String side = arguments.getString(1); + IItemHandler inventory; - @Override - public final MethodResult exportItem(@NotNull IArguments arguments) throws LuaException { - if (!isAvailable()) - return notConnected(); + if (Direction.byName(side.toUpperCase(Locale.ROOT)) == null && ComputerSide.valueOfInsensitive(side.toUpperCase(Locale.ROOT)) == null) { + inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); + } else { + inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); + } - IItemHandler inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); - return exportToChest(arguments, inventory); + return importToME(arguments, inventory); } @Override - public final MethodResult importItemFromPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { + public final MethodResult exportItem(IComputerAccess computer, @NotNull IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); - IItemHandler inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); - return importToME(arguments, inventory); - } + String side = arguments.getString(1); + IItemHandler inventory; - @Override - public final MethodResult exportItemToPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { - if (!isAvailable()) - return notConnected(); + if (Direction.byName(side.toUpperCase(Locale.ROOT)) == null && ComputerSide.valueOfInsensitive(side.toUpperCase(Locale.ROOT)) == null) { + inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); + } else { + inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); + } - IItemHandler inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); return exportToChest(arguments, inventory); } @@ -493,36 +494,38 @@ public final MethodResult isFluidCraftable(IArguments arguments) throws LuaExcep return MethodResult.of(getCraftingService().isCraftable(fluid)); } - @LuaFunction(mainThread = true) - public final MethodResult exportFluid(@NotNull IArguments arguments) throws LuaException { - IFluidHandler handler = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); - return exportToTank(arguments, handler); - } + @Override + public final MethodResult exportFluid(IComputerAccess computer, IArguments arguments) throws LuaException { + String side = arguments.getString(1); + IFluidHandler fluidHandler; - @LuaFunction(mainThread = true) - public final MethodResult exportFluidToPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { - IFluidHandler handler = FluidUtil.getHandlerFromName(computer, arguments.getString(1)); + if (Direction.byName(side.toUpperCase(Locale.ROOT)) == null && ComputerSide.valueOfInsensitive(side.toUpperCase(Locale.ROOT)) == null) { + fluidHandler = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); + } else { + fluidHandler = FluidUtil.getHandlerFromName(computer, arguments.getString(1)); + } - if (handler == null) + if (fluidHandler == null) return MethodResult.of(0, "The target tank does not exist. Make sure the bridge is exposed in the computer network. Reach out to our discord or our documentation for help."); - return exportToTank(arguments, handler); + return exportToTank(arguments, fluidHandler); } - @LuaFunction(mainThread = true) - public final MethodResult importFluid(IArguments arguments) throws LuaException { - IFluidHandler handler = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); - return importToME(arguments, handler); - } + @Override + public final MethodResult importFluid(IComputerAccess computer, IArguments arguments) throws LuaException { + String side = arguments.getString(1); + IFluidHandler fluidHandler; - @LuaFunction(mainThread = true) - public final MethodResult importFluidFromPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { - IFluidHandler handler = FluidUtil.getHandlerFromName(computer, arguments.getString(1)); + if (Direction.byName(side.toUpperCase(Locale.ROOT)) == null && ComputerSide.valueOfInsensitive(side.toUpperCase(Locale.ROOT)) == null) { + fluidHandler = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); + } else { + fluidHandler = FluidUtil.getHandlerFromName(computer, arguments.getString(1)); + } - if (handler == null) + if (fluidHandler == null) return MethodResult.of(0, "The target tank does not exist. Make sure the bridge is exposed in the computer network. Reach out to our discord or our documentation for help."); - return importToME(arguments, handler); + return importToME(arguments, fluidHandler); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java index a158e8cf0..e33e3a76f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java @@ -8,6 +8,7 @@ import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.MethodResult; import dan200.computercraft.api.peripheral.IComputerAccess; +import dan200.computercraft.core.computer.ComputerSide; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner; import de.srendi.advancedperipherals.common.addons.refinedstorage.RefinedStorage; @@ -19,6 +20,7 @@ import de.srendi.advancedperipherals.common.util.Pair; import de.srendi.advancedperipherals.common.util.inventory.*; import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; +import net.minecraft.core.Direction; import net.minecraft.world.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.capability.IFluidHandler; @@ -28,8 +30,9 @@ import java.util.ArrayList; import java.util.List; +import java.util.Locale; -public class RsBridgePeripheral extends BasePeripheral> implements IStoragePeripheral { +public class RsBridgePeripheral extends BasePeripheral> implements IStorageSystemPeripheral { public static final String PERIPHERAL_TYPE = "rs_bridge"; @@ -278,77 +281,78 @@ protected MethodResult importToSystem(@NotNull IArguments arguments, @Nullable I } @Override - public final MethodResult exportItem(@NotNull IArguments arguments) throws LuaException { + public final MethodResult exportItem(IComputerAccess computer, IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); - IItemHandler inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); - return exportToChest(arguments, inventory); - } + String side = arguments.getString(1); + IItemHandler inventory; - @Override - public final MethodResult exportItemToPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { - if (!isAvailable()) - return notConnected(); + if (Direction.byName(side.toUpperCase(Locale.ROOT)) == null && ComputerSide.valueOfInsensitive(side.toUpperCase(Locale.ROOT)) == null) { + inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); + } else { + inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); + } - IItemHandler inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); return exportToChest(arguments, inventory); } @Override - public final MethodResult importItem(IArguments arguments) throws LuaException { + public final MethodResult importItem(IComputerAccess computer, IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); - IItemHandler inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); - return importToSystem(arguments, inventory); - } + String side = arguments.getString(1); + IItemHandler inventory; - @Override - public final MethodResult importItemFromPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { - if (!isAvailable()) - return notConnected(); + if (Direction.byName(side.toUpperCase(Locale.ROOT)) == null && ComputerSide.valueOfInsensitive(side.toUpperCase(Locale.ROOT)) == null) { + inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); + } else { + inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); + } - IItemHandler inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); return importToSystem(arguments, inventory); } @Override - public final MethodResult exportFluid(@NotNull IArguments arguments) throws LuaException { + public final MethodResult exportFluid(IComputerAccess computer, IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); - IFluidHandler inventory = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); - return exportToTank(arguments, inventory); - } + String side = arguments.getString(1); + IFluidHandler fluidHandler; - @Override - public final MethodResult exportFluidToPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { - if (!isAvailable()) - return notConnected(); + if (Direction.byName(side.toUpperCase(Locale.ROOT)) == null && ComputerSide.valueOfInsensitive(side.toUpperCase(Locale.ROOT)) == null) { + fluidHandler = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); + } else { + fluidHandler = FluidUtil.getHandlerFromName(computer, arguments.getString(1)); + } + + if (fluidHandler == null) + return MethodResult.of(0, "The target tank does not exist. Make sure the bridge is exposed in the computer network. Reach out to our discord or our documentation for help."); - IFluidHandler inventory = FluidUtil.getHandlerFromName(computer, arguments.getString(1)); - return exportToTank(arguments, inventory); + return exportToTank(arguments, fluidHandler); } @Override - public final MethodResult importFluid(IArguments arguments) throws LuaException { + public final MethodResult importFluid(IComputerAccess computer, IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); - IFluidHandler inventory = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); - return importToSystem(arguments, inventory); - } + String side = arguments.getString(1); + IFluidHandler fluidHandler; - @Override - public final MethodResult importFluidFromPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { - if (!isAvailable()) - return notConnected(); + if (Direction.byName(side.toUpperCase(Locale.ROOT)) == null && ComputerSide.valueOfInsensitive(side.toUpperCase(Locale.ROOT)) == null) { + fluidHandler = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); + } else { + fluidHandler = FluidUtil.getHandlerFromName(computer, arguments.getString(1)); + } - IFluidHandler inventory = FluidUtil.getHandlerFromName(computer, arguments.getString(1)); - return importToSystem(arguments, inventory); - } + if (fluidHandler == null) + return MethodResult.of(0, "The target tank does not exist. Make sure the bridge is exposed in the computer network. Reach out to our discord or our documentation for help."); + return importToSystem(arguments, fluidHandler); + } @Override public final MethodResult getItem(IArguments arguments) throws LuaException { if (!isAvailable()) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStoragePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java similarity index 80% rename from src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStoragePeripheral.java rename to src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java index c1c45d3e5..a7f907092 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStoragePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java @@ -14,7 +14,7 @@ * In case there is a new mod which adds new ways to store and craft items, this ensures that the new peripheral * has the same functions as the other ones */ -public interface IStoragePeripheral { +public interface IStorageSystemPeripheral { @LuaFunction(mainThread = true) MethodResult isConnected(); @@ -44,28 +44,16 @@ public interface IStoragePeripheral { MethodResult listCells(); @LuaFunction(mainThread = true) - MethodResult importItem(IArguments arguments) throws LuaException; + MethodResult importItem(IComputerAccess computer, IArguments arguments) throws LuaException; @LuaFunction(mainThread = true) - MethodResult exportItem(IArguments arguments) throws LuaException; + MethodResult exportItem(IComputerAccess computer, IArguments arguments) throws LuaException; @LuaFunction(mainThread = true) - MethodResult importItemFromPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException; + MethodResult importFluid(IComputerAccess computer, IArguments arguments) throws LuaException; @LuaFunction(mainThread = true) - MethodResult exportItemToPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException; - - @LuaFunction(mainThread = true) - MethodResult importFluid(IArguments arguments) throws LuaException; - - @LuaFunction(mainThread = true) - MethodResult exportFluid(IArguments arguments) throws LuaException; - - @LuaFunction(mainThread = true) - MethodResult importFluidFromPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException; - - @LuaFunction(mainThread = true) - MethodResult exportFluidToPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException; + MethodResult exportFluid(IComputerAccess computer, IArguments arguments) throws LuaException; @LuaFunction(mainThread = true) MethodResult getPattern(IArguments arguments) throws LuaException; From 2a4b63cd45481269728fd2a53204d4c07096bb6d Mon Sep 17 00:00:00 2001 From: Srendi Date: Sun, 8 Oct 2023 02:09:39 +0200 Subject: [PATCH 069/228] Don't check dependency licenses --- qodana.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qodana.yaml b/qodana.yaml index dfc5cbb26..f2df31528 100644 --- a/qodana.yaml +++ b/qodana.yaml @@ -16,7 +16,8 @@ exclude: - src/test/resources/* - src/testMod/resources/* - src/server-files/resources/* -include: - name: CheckDependencyLicenses + +include: - name: TrivialIf - name: NullableProblems \ No newline at end of file From 3a195041ec80f3d666a40f2b72814040f06f6537 Mon Sep 17 00:00:00 2001 From: Srendi Date: Sun, 5 Nov 2023 15:50:37 +0100 Subject: [PATCH 070/228] Fixed the colony integrator --- build.gradle | 7 ++++++- .../srendi/advancedperipherals/common/setup/APBlocks.java | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 2fdad43bd..c6e11dabf 100644 --- a/build.gradle +++ b/build.gradle @@ -285,12 +285,17 @@ dependencies { implementation fg.deobf("vazkii.botania:Botania:${botania_version}") // Minecolonies - // Change to compileOnly when running `runData` compileOnly fg.deobf("com.ldtteam:minecolonies:${minecolonies_version}") compileOnly fg.deobf("com.ldtteam:structurize:${structurize_version}") compileOnly fg.deobf("com.ldtteam:multipiston:${multipiston_version}") compileOnly fg.deobf("com.ldtteam:domum_ornamentum:${domumornamentum_version}:universal") compileOnly fg.deobf("com.ldtteam:blockui:${blockui_version}") + // Uncomment the next 5 lines when using `runData` + runtimeOnly fg.deobf("com.ldtteam:minecolonies:${minecolonies_version}") + runtimeOnly fg.deobf("com.ldtteam:structurize:${structurize_version}") + runtimeOnly fg.deobf("com.ldtteam:multipiston:${multipiston_version}") + runtimeOnly fg.deobf("com.ldtteam:domum_ornamentum:${domumornamentum_version}:universal") + runtimeOnly fg.deobf("com.ldtteam:blockui:${blockui_version}") //Patchouli runtimeOnly fg.deobf("vazkii.patchouli:Patchouli:${patchouli_version}") diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java index 304d97012..1b0b670eb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java @@ -1,5 +1,6 @@ package de.srendi.advancedperipherals.common.setup; +import de.srendi.advancedperipherals.common.addons.APAddons; import de.srendi.advancedperipherals.common.blocks.PlayerDetectorBlock; import de.srendi.advancedperipherals.common.blocks.RedstoneIntegratorBlock; import de.srendi.advancedperipherals.common.blocks.base.APBlockEntityBlock; @@ -37,7 +38,7 @@ protected static void register() { public static final RegistryObject REDSTONE_INTEGRATOR = register("redstone_integrator", RedstoneIntegratorBlock::new, () -> new APBlockItem(APBlocks.REDSTONE_INTEGRATOR.get(), APConfig.PERIPHERALS_CONFIG.enableRedstoneIntegrator)); public static final RegistryObject BLOCK_READER = register("block_reader", () -> new APBlockEntityBlock<>(APBlockEntityTypes.BLOCK_READER, true), () -> new APBlockItem(APBlocks.BLOCK_READER.get(), APConfig.PERIPHERALS_CONFIG.enableBlockReader)); public static final RegistryObject GEO_SCANNER = register("geo_scanner", () -> new APBlockEntityBlock<>(APBlockEntityTypes.GEO_SCANNER, false), () -> new APBlockItem(APBlocks.GEO_SCANNER.get(), APConfig.PERIPHERALS_CONFIG.enableGeoScanner)); - public static final RegistryObject COLONY_INTEGRATOR = register("colony_integrator", BaseBlock::new, () -> new APBlockItem(APBlocks.COLONY_INTEGRATOR.get(), APConfig.PERIPHERALS_CONFIG.enableColonyIntegrator)); + public static final RegistryObject COLONY_INTEGRATOR = register("colony_integrator", () -> new APBlockEntityBlock<>(APBlockEntityTypes.COLONY_INTEGRATOR, false), () -> new APBlockItem(APBlocks.COLONY_INTEGRATOR.get(), APConfig.PERIPHERALS_CONFIG.enableColonyIntegrator)); public static final RegistryObject NBT_STORAGE = register("nbt_storage", () -> new APBlockEntityBlock<>(APBlockEntityTypes.NBT_STORAGE, false), () -> new APBlockItem(APBlocks.NBT_STORAGE.get(), APConfig.PERIPHERALS_CONFIG.enableNBTStorage)); public static final RegistryObject DISTANCE_DETECTOR = register("distance_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.DISTANCE_DETECTOR, BlockBehaviour.Properties.of(Material.METAL).noOcclusion(), true), () -> new APBlockItem(APBlocks.DISTANCE_DETECTOR.get(), APConfig.PERIPHERALS_CONFIG.enableNBTStorage)); From b0a24ebec4ef7119f0819979554596cbbcacfef4 Mon Sep 17 00:00:00 2001 From: Srendi Date: Sun, 5 Nov 2023 16:01:24 +0100 Subject: [PATCH 071/228] Add missing applied mekanistics to the build.gradle --- build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build.gradle b/build.gradle index c6e11dabf..853b39aa7 100644 --- a/build.gradle +++ b/build.gradle @@ -253,6 +253,10 @@ dependencies { // Compile-time API required // Ae2 implementation fg.deobf("appeng:appliedenergistics2-forge:${appliedenergistics_version}") + + // Applied Mekanistics + implementation fg.deobf("curse.maven:applied-mekanistics-574300:${appliedmekanistics_version}") + // Curios implementation fg.deobf("top.theillusivec4.curios:curios-forge:${curios_version}:api") // Minimal requirements end From 5bab2e92d0bd2a6885e443e15c8540cd8bd7ae40 Mon Sep 17 00:00:00 2001 From: Deniz Demiroglu Date: Fri, 15 Dec 2023 16:48:19 +0100 Subject: [PATCH 072/228] Start to implement more of the RS Bridge and ME Bridge IStorageSystemPeripheral functions. Also started adding better pattern support for both. WIP commit, commited due to device change --- .../addons/appliedenergistics/AppEngApi.java | 31 ++++++++- .../peripheral/ColonyPeripheral.java | 2 +- .../InventoryManagerPeripheral.java | 8 ++- .../peripheral/MeBridgePeripheral.java | 57 +++++++++++++--- .../peripheral/RsBridgePeripheral.java | 2 +- .../plugins/AutomataItemSuckPlugin.java | 2 +- .../addons/create/BasinIntegration.java | 14 ++-- .../addons/minecolonies/MineColonies.java | 6 +- .../addons/refinedstorage/RefinedStorage.java | 66 +++++++++---------- .../common/util/LuaConverter.java | 35 ++++++++-- .../common/util/inventory/FluidFilter.java | 2 +- .../common/util/inventory/GenericFilter.java | 16 +++++ .../inventory/IStorageSystemPeripheral.java | 2 +- .../common/util/inventory/ItemFilter.java | 2 +- 14 files changed, 174 insertions(+), 71 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java index 37cf6faf2..c85e1119c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java @@ -1,9 +1,11 @@ package de.srendi.advancedperipherals.common.addons.appliedenergistics; +import appeng.api.crafting.IPatternDetails; import appeng.api.inventories.InternalInventory; import appeng.api.networking.IGridNode; import appeng.api.networking.crafting.CraftingJobStatus; import appeng.api.networking.crafting.ICraftingCPU; +import appeng.api.networking.crafting.ICraftingProvider; import appeng.api.networking.crafting.ICraftingService; import appeng.api.networking.storage.IStorageService; import appeng.api.stacks.*; @@ -39,6 +41,7 @@ import org.jetbrains.annotations.Nullable; import java.util.*; +import java.util.stream.Collectors; public class AppEngApi { @@ -119,7 +122,7 @@ public static List listFluids(MEStorage monitor, ICraftingService servic return items; } - public static List listGases(MEStorage monitor, ICraftingService service, int flag) { + public static List listGases(MEStorage monitor, ICraftingService service) { List items = new ArrayList<>(); for (Object2LongMap.Entry aeKey : monitor.getAvailableStacks()) { if (APAddons.appMekLoaded && aeKey.getKey() instanceof MekanismKey itemKey) { @@ -129,6 +132,10 @@ public static List listGases(MEStorage monitor, ICraftingService service return items; } + public static List listPatterns(ICraftingProvider manager) { + return manager.getAvailablePatterns().stream().map(AppEngApi::getObjectFromPattern).collect(Collectors.toList()); + } + public static Map getObjectFromStack(Pair stack, @Nullable ICraftingService service) { if (stack.getRight() == null) return Collections.emptyMap(); @@ -182,6 +189,26 @@ private static Map getObjectFromGasStack(Pair return map; } + public static Map getObjectFromPattern(IPatternDetails pattern) { + Map map = new HashMap<>(); + + map.put("inputs", Arrays.stream(pattern.getInputs()).map(AppEngApi::getObjectFromPatternInput)); + map.put("outputs", Arrays.stream(pattern.getOutputs()).map(AppEngApi::getObjectFromGenericStack)); + map.put("primaryOutput", getObjectFromGenericStack(pattern.getPrimaryOutput())); + return map; + } + + public static Map getObjectFromPatternInput(IPatternDetails.IInput patternInput) { + Map map = new HashMap<>(); + map.put("primaryInput", getObjectFromGenericStack(patternInput.getPossibleInputs()[0])); + map.put("possibleInputs", + Arrays.stream(Arrays.copyOfRange(patternInput.getPossibleInputs(), 1, patternInput.getPossibleInputs().length)) + .map(AppEngApi::getObjectFromGenericStack)); + map.put("multiplier", patternInput.getMultiplier()); + map.put("remaining", patternInput.getRemainingKey(patternInput.getPossibleInputs()[0].what())); + return map; + } + public static Map getObjectFromCPU(ICraftingCPU cpu) { Map map = new HashMap<>(); long storage = cpu.getAvailableStorage(); @@ -500,7 +527,7 @@ public static long getUsedFluidStorage(IGridNode node) { KeyCounter keyCounter = bus.getInternalHandler().getAvailableStacks(); for (Object2LongMap.Entry aeKey : keyCounter) { - if (aeKey.getKey() instanceof AEFluidKey fluidKey) { + if (aeKey.getKey() instanceof AEFluidKey) { used += aeKey.getLongValue(); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ColonyPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ColonyPeripheral.java index d322dcdd0..ae97a5c6b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ColonyPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ColonyPeripheral.java @@ -272,7 +272,7 @@ public final Object getRequests() throws LuaException { map.put("state", request.getState().toString()); map.put("count", deliverableRequest.getCount()); map.put("minCount", deliverableRequest.getMinimumCount()); - map.put("items", request.getDisplayStacks().stream().map(LuaConverter::stackToObject).collect(Collectors.toList())); + map.put("items", request.getDisplayStacks().stream().map(LuaConverter::itemStackToObject).collect(Collectors.toList())); map.put("target", request.getRequester().getRequesterDisplayName(requestManager, request).getString()); result.add(map); }); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java index f2baf3cba..0f335c0b8 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java @@ -25,7 +25,9 @@ import net.minecraftforge.items.wrapper.PlayerOffhandInvWrapper; import org.jetbrains.annotations.NotNull; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; public class InventoryManagerPeripheral extends BasePeripheral> { @@ -185,12 +187,12 @@ public final int getFreeSlot() throws LuaException { @LuaFunction(mainThread = true) public final Map getItemInHand() throws LuaException { - return LuaConverter.stackToObject(getOwnerPlayer().getMainHandItem()); + return LuaConverter.itemStackToObject(getOwnerPlayer().getMainHandItem()); } @LuaFunction(mainThread = true) public final Map getItemInOffHand() throws LuaException { - return LuaConverter.stackToObject(getOwnerPlayer().getOffhandItem()); + return LuaConverter.itemStackToObject(getOwnerPlayer().getOffhandItem()); } private Player getOwnerPlayer() throws LuaException { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java index e1549a06c..703b78e9b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java @@ -3,6 +3,7 @@ import appeng.api.networking.IGridNode; import appeng.api.networking.IManagedGridNode; import appeng.api.networking.crafting.ICraftingCPU; +import appeng.api.networking.crafting.ICraftingProvider; import appeng.api.networking.crafting.ICraftingService; import appeng.api.stacks.AEFluidKey; import appeng.api.stacks.AEItemKey; @@ -30,10 +31,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; +import java.util.*; public class MeBridgePeripheral extends BasePeripheral> implements IStorageSystemPeripheral { @@ -181,7 +179,18 @@ public final MethodResult getItem(IArguments arguments) throws LuaException { @Override public MethodResult getFluid(IArguments arguments) throws LuaException { - return null; + if (!isAvailable()) + return notConnected(); + + Pair filter = FluidFilter.parse(arguments.getTable(0)); + if (filter.rightPresent()) + return MethodResult.of(null, filter.getRight()); + + FluidFilter parsedFilter = filter.getLeft(); + if (parsedFilter.isEmpty()) + return MethodResult.of(null, "EMPTY_FILTER"); + + return MethodResult.of(AppEngApi.findAEFluidFromFilter(AppEngApi.getMonitor(node), getCraftingService(), parsedFilter)); } @Override @@ -258,14 +267,44 @@ public final MethodResult exportItem(IComputerAccess computer, @NotNull IArgumen return exportToChest(arguments, inventory); } + //TODO: How do we want to filter? By inputs or outputs, or maybe both? What if there are multiple patterns with the same output/input @Override - public MethodResult getPattern(IArguments arguments) throws LuaException { + public MethodResult getFilteredPatterns(IArguments arguments) throws LuaException { + if (!isAvailable()) + return notConnected(); + + Map filterTable; + try { + Optional> optionalTable = arguments.optTable(0); + if (optionalTable.isEmpty()) + return MethodResult.of(null, "EMPTY_INPUT"); + // Expected input is a table with either an input table, an output table or both to filter for both + filterTable = optionalTable.get(); + } catch (LuaException e) { + return MethodResult.of(null, "NO_TABLE"); + } + + boolean hasInputFilter = filterTable.containsKey("input"); + boolean hasOutputFilter = filterTable.containsKey("output"); + + + if (hasInputFilter) + return null; + return null; } @Override public MethodResult getPatterns() { - return null; + if (!isAvailable()) + return notConnected(); + + ICraftingProvider provider = node.getService(ICraftingProvider.class); + + if (provider == null) + return MethodResult.of(null, "NO_CRAFTING_PROVIDER"); + + return MethodResult.of(AppEngApi.listPatterns(provider)); } @Override @@ -455,7 +494,7 @@ public final MethodResult isItemCraftable(IArguments arguments) throws LuaExcept return MethodResult.of(getCraftingService().isCraftable(item)); } - @LuaFunction(mainThread = true) + @Override public final MethodResult isFluidCrafting(IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -476,7 +515,7 @@ public final MethodResult isFluidCrafting(IArguments arguments) throws LuaExcept return MethodResult.of(AppEngApi.isFluidCrafting(monitor, grid, parsedFilter, craftingCPU)); } - @LuaFunction(mainThread = true) + @Override public final MethodResult isFluidCraftable(IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java index b90d697ff..9b1bf96e4 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java @@ -210,7 +210,7 @@ public final MethodResult getStoredEnergy() { } @Override - public final MethodResult getPattern(IArguments arguments) throws LuaException { + public final MethodResult getFilteredPatterns(IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataItemSuckPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataItemSuckPlugin.java index bcc87f781..796e8f386 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataItemSuckPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataItemSuckPlugin.java @@ -84,7 +84,7 @@ public final MethodResult scanItems() { int index = 1; for (ItemEntity item : items) { ItemStack stack = item.getItem(); - Map itemData = LuaConverter.stackToObject(stack); + Map itemData = LuaConverter.itemStackToObject(stack); itemData.put("entityID", item.getId()); data.put(index, itemData); index++; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/create/BasinIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/create/BasinIntegration.java index fd94787a9..04c9711b2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/create/BasinIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/create/BasinIntegration.java @@ -6,17 +6,13 @@ import de.srendi.advancedperipherals.lib.peripherals.BlockEntityIntegrationPeripheral; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.capability.IFluidHandler; +import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.registries.ForgeRegistries; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; public class BasinIntegration extends BlockEntityIntegrationPeripheral { @@ -68,7 +64,7 @@ public final List getOutputFluids() { @LuaFunction(mainThread = true) public final Map getFilter() { - return LuaConverter.stackToObject(blockEntity.getFilter().getFilter()); + return LuaConverter.itemStackToObject(blockEntity.getFilter().getFilter()); } @LuaFunction(mainThread = true) @@ -78,7 +74,7 @@ public final List getInventory() { IItemHandler handler = handlerOptional.get(); List items = new ArrayList<>(); for (int slot = 0; slot < handler.getSlots(); slot++) { - items.add(LuaConverter.stackToObject(handler.getStackInSlot(slot))); + items.add(LuaConverter.itemStackToObject(handler.getStackInSlot(slot))); } return items; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/minecolonies/MineColonies.java b/src/main/java/de/srendi/advancedperipherals/common/addons/minecolonies/MineColonies.java index cf217b6e0..b69291b3e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/minecolonies/MineColonies.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/minecolonies/MineColonies.java @@ -106,7 +106,7 @@ public static Object visitorToObject(IVisitorData visitor) { map.put("saturation", visitor.getSaturation()); map.put("happiness", visitor.getCitizenHappinessHandler().getHappiness(visitor.getColony(), visitor)); map.put("skills", skillsToObject(visitor.getCitizenSkillHandler().getSkills())); - map.put("recruitCost", LuaConverter.stackToObject(visitor.getRecruitCost())); + map.put("recruitCost", LuaConverter.itemStackToObject(visitor.getRecruitCost())); return map; } @@ -276,7 +276,7 @@ public static List getResearch(ResourceLocation branch, List> cost = new ArrayList<>(); for (ItemStorage item : research.getCostList()) - cost.add(LuaConverter.stackToObject(item.getItemStack(), item.getAmount())); + cost.add(LuaConverter.itemStackToObject(item.getItemStack(), item.getAmount())); List> requirements = new ArrayList<>(); for (IResearchRequirement requirement : research.getResearchRequirement()) { @@ -338,7 +338,7 @@ public static Object builderResourcesToObject(IColony colony, BlockPos pos) { Map map = new HashMap<>(); ItemStack stack = resource.getItemStack().copy(); - map.put("item", LuaConverter.stackToObject(stack)); + map.put("item", LuaConverter.itemStackToObject(stack)); map.put("displayName", resource.getName()); map.put("available", resource.getAvailable()); map.put("delivering", resource.getAmountInDelivery()); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java index c92a28a65..2a102e1ea 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java @@ -18,20 +18,14 @@ import de.srendi.advancedperipherals.common.util.inventory.FluidFilter; import de.srendi.advancedperipherals.common.util.inventory.ItemFilter; import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; -import net.minecraft.core.NonNullList; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.TagKey; -import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.material.Fluid; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.registries.ForgeRegistries; import org.jetbrains.annotations.Nullable; import java.util.*; -import java.util.function.Supplier; -import java.util.stream.Stream; +import java.util.stream.Collectors; public class RefinedStorage { @@ -160,35 +154,43 @@ public static long getMaxFluidExternalStorage(INetwork network) { } public static Object getObjectFromPattern(ICraftingPattern pattern, INetwork network) { - if (pattern == null) return null; + if (pattern == null) + return null; + Map map = new HashMap<>(); - List outputsList = pattern.getOutputs(); - List outputs = new ArrayList<>(); - for (ItemStack itemStack : outputsList) - outputs.add(getObjectFromStack(itemStack.copy(), network)); - - map.put("outputs", outputs); - - List> inputList = pattern.getInputs(); - List inputs = new ArrayList<>(); - for (List singleInputList : inputList) { - List inputs1 = new ArrayList<>(); - for (ItemStack stack : singleInputList) - inputs1.add(getObjectFromStack(stack.copy(), network)); - inputs.add(inputs1); - } + map.put("outputs", pattern.getOutputs().stream().map(stack -> getObjectFromStack(stack.copy(), network)).toList()); + map.put("fluidOutputs", pattern.getFluidOutputs().stream().map(stack -> getObjectFromFluid(stack.copy(), network)).toList()); + + List>> inputs = pattern.getInputs().stream() + .map(singleInputList -> singleInputList.stream() + .map(stack -> getObjectFromStack(stack.copy(), network)) + .collect(Collectors.toList())) + .collect(Collectors.toList()); + + List>> fluidInputs = pattern.getInputs().stream() + .map(singleInputList -> singleInputList.stream() + .map(stack -> getObjectFromStack(stack.copy(), network)) + .collect(Collectors.toList())) + .collect(Collectors.toList()); List byproducts = new ArrayList<>(); if (!pattern.isProcessing()) { - List byproductsList = pattern.getByproducts(); - for (ItemStack stack : byproductsList) - byproducts.add(getObjectFromStack(stack.copy(), network)); + byproducts = pattern.getByproducts().stream() + .map(stack -> getObjectFromStack(stack.copy(), network)) + .collect(Collectors.toList()); } + map.put("fluidInputs", fluidInputs); map.put("inputs", inputs); - map.put("outputs", outputs); map.put("byproducts", byproducts); map.put("processing", pattern.isProcessing()); + Map container = new HashMap<>(); + map.put("name", pattern.getContainer().getName().getString()); + map.put("position", LuaConverter.posToObject(pattern.getContainer().getPosition())); + + map.put("container", container); + map.put("isValid", pattern.isValid()); + map.put("errorMessage", pattern.getErrorMessage() == null ? "" : pattern.getErrorMessage().getString()); return map; } @@ -196,16 +198,13 @@ public static Map getObjectFromStack(@Nullable ItemStack itemSta if (itemStack == null) return Collections.emptyMap(); - Map map = new HashMap<>(); + Map map = LuaConverter.itemToObject(itemStack.getItem()); CompoundTag nbt = itemStack.getTag(); - Supplier>> tags = () -> itemStack.getItem().builtInRegistryHolder().tags(); map.put("fingerprint", ItemUtil.getFingerprint(itemStack)); - map.put("name", ItemUtil.getRegistryKey(itemStack.getItem()).toString()); map.put("amount", itemStack.getCount()); map.put("displayName", itemStack.getDisplayName().getString()); map.put("isCraftable", isItemCraftable(network, itemStack)); map.put("nbt", nbt == null ? null : NBTUtil.toLua(nbt)); - map.put("tags", tags.get().findAny().isEmpty() ? null : LuaConverter.tagsToList(tags)); return map; } @@ -214,13 +213,10 @@ public static Map getObjectFromFluid(@Nullable FluidStack fluidS if (fluidStack == null) return Collections.emptyMap(); - Map map = new HashMap<>(); - Supplier>> tags = () -> fluidStack.getFluid().builtInRegistryHolder().tags(); - map.put("name", ForgeRegistries.FLUIDS.getKey(fluidStack.getFluid()).toString()); + Map map = LuaConverter.fluidToObject(fluidStack.getFluid()); map.put("amount", fluidStack.getAmount()); map.put("displayName", fluidStack.getDisplayName().getString()); map.put("isCraftable", isFluidCraftable(network, fluidStack)); - map.put("tags", tags.get().findAny().isEmpty() ? null : LuaConverter.tagsToList(tags)); return map; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java b/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java index a2f6c4c71..18cce9c5b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java @@ -3,6 +3,7 @@ import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.shared.util.NBTUtil; import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.InventoryManagerPeripheral; +import de.srendi.advancedperipherals.common.util.inventory.FluidUtil; import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; @@ -11,7 +12,10 @@ import net.minecraft.world.entity.animal.Animal; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.material.Fluid; import net.minecraftforge.common.IForgeShearable; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidType; import org.jetbrains.annotations.NotNull; import java.util.Collections; @@ -66,7 +70,7 @@ public static Object posToObject(BlockPos pos) { return map; } - public static Map stackToObject(@NotNull ItemStack stack) { + public static Map itemStackToObject(@NotNull ItemStack stack) { if (stack.isEmpty()) return new HashMap<>(); Map map = itemToObject(stack.getItem()); CompoundTag nbt = stack.copy().getOrCreateTag(); @@ -78,10 +82,21 @@ public static Map stackToObject(@NotNull ItemStack stack) { return map; } - public static Map stackToObject(@NotNull ItemStack itemStack, int amount) { + public static Map fluidStackToObject(@NotNull FluidStack stack) { + if (stack.isEmpty()) return new HashMap<>(); + Map map = fluidToObject(stack.getFluid()); + CompoundTag nbt = stack.copy().getOrCreateTag(); + map.put("count", stack.getAmount()); + map.put("displayName", stack.getDisplayName().getString()); + map.put("nbt", NBTUtil.toLua(nbt)); + map.put("fingerprint", FluidUtil.getFingerprint(stack)); + return map; + } + + public static Map itemStackToObject(@NotNull ItemStack itemStack, int amount) { ItemStack stack = itemStack.copy(); stack.setCount(amount); - return stackToObject(stack); + return itemStackToObject(stack); } /** @@ -94,7 +109,7 @@ public static Map stackToObject(@NotNull ItemStack itemStack, in */ public static Map stackToObjectWithSlot(@NotNull ItemStack stack, int slot) { if (stack.isEmpty()) return new HashMap<>(); - Map map = stackToObject(stack); + Map map = itemStackToObject(stack); map.put("slot", slot); return map; } @@ -106,6 +121,18 @@ public static Map itemToObject(@NotNull Item item) { return map; } + public static Map fluidToObject(@NotNull Fluid fluid) { + Map map = new HashMap<>(); + FluidType fluidType = fluid.getFluidType(); + map.put("tags", tagsToList(() -> fluid.builtInRegistryHolder().tags())); + map.put("name", FluidUtil.getRegistryKey(fluid).toString()); + map.put("density", fluidType.getDensity()); + map.put("lightLevel", fluidType.getLightLevel()); + map.put("temperature", fluidType.getTemperature()); + map.put("viscosity", fluidType.getViscosity()); + return map; + } + public static List tagsToList(@NotNull Supplier>> tags) { if (tags.get().findAny().isEmpty()) return Collections.emptyList(); return tags.get().map(LuaConverter::tagToString).toList(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java index faad46a1f..29b13f06c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java @@ -17,7 +17,7 @@ import java.util.Map; -public class FluidFilter { +public class FluidFilter extends GenericFilter { private Fluid fluid = Fluids.EMPTY; private TagKey tag = null; diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java new file mode 100644 index 000000000..bdde14a37 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java @@ -0,0 +1,16 @@ +package de.srendi.advancedperipherals.common.util.inventory; + +import de.srendi.advancedperipherals.common.util.Pair; + +import java.util.Map; + +public abstract class GenericFilter { + + // TODO: Imagine we want to filter for an object which can either a item, a fluid or maybe a chemical from mekanism + // This function should first check if the `name` key can be found in any of the registries and then return the + // right filter according to the registry type which could be an item or a chemical + public static Pair parseGeneric(Map rawFilter) { + return Pair.of(null, null); + } + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java index a7f907092..ff42f6ce3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java @@ -56,7 +56,7 @@ public interface IStorageSystemPeripheral { MethodResult exportFluid(IComputerAccess computer, IArguments arguments) throws LuaException; @LuaFunction(mainThread = true) - MethodResult getPattern(IArguments arguments) throws LuaException; + MethodResult getFilteredPatterns(IArguments arguments) throws LuaException; @LuaFunction(mainThread = true) MethodResult getPatterns(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java index bd943c892..9bc0a7b49 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java @@ -17,7 +17,7 @@ import java.util.Map; -public class ItemFilter { +public class ItemFilter extends GenericFilter { private Item item = Items.AIR; private TagKey tag = null; From 4005a4857c132e4409a3bd8c0cfeca419b0356f5 Mon Sep 17 00:00:00 2001 From: Srendi Date: Sat, 16 Dec 2023 03:29:58 +0100 Subject: [PATCH 073/228] Implement pattern filtering for the me bridge --- .../addons/appliedenergistics/AppEngApi.java | 40 ++++++++++++++ .../peripheral/MeBridgePeripheral.java | 35 ++++++++++-- .../common/setup/APBlocks.java | 1 - .../common/util/inventory/FluidFilter.java | 10 ++++ .../common/util/inventory/GenericFilter.java | 54 +++++++++++++++++-- .../common/util/inventory/ItemFilter.java | 10 ++++ 6 files changed, 140 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java index c85e1119c..8b2ec2bf5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java @@ -22,6 +22,7 @@ import de.srendi.advancedperipherals.common.util.LuaConverter; import de.srendi.advancedperipherals.common.util.Pair; import de.srendi.advancedperipherals.common.util.inventory.FluidFilter; +import de.srendi.advancedperipherals.common.util.inventory.GenericFilter; import de.srendi.advancedperipherals.common.util.inventory.ItemFilter; import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; import io.github.projectet.ae2things.item.DISKDrive; @@ -87,6 +88,45 @@ public static Pair findAEFluidFromFilter(MEStorage monitor, @N return null; } + public static Pair findPatternFromFilters(ICraftingProvider provider, GenericFilter inputFilter, GenericFilter outputFilter) { + for (IPatternDetails pattern : provider.getAvailablePatterns()) { + if (pattern.getInputs().length == 0) + continue; + if (pattern.getOutputs().length == 0) + continue; + + boolean inputMatch = false; + boolean outputMatch = false; + + if(!inputFilter.isEmpty()) { + for (IPatternDetails.IInput input : pattern.getInputs()) { + if (inputFilter.test(input.getPossibleInputs()[0])) { + inputMatch = true; + break; + } + } + } else { + inputMatch = true; + } + + if(!outputFilter.isEmpty()) { + for (GenericStack output : pattern.getOutputs()) { + if (outputFilter.test(output)) { + outputMatch = true; + break; + } + } + } else { + outputMatch = true; + } + + if (inputMatch && outputMatch) + return Pair.of(pattern, null); + } + + return Pair.of(null, "NO_PATTERN_FOUND"); + } + public static List listStacks(MEStorage monitor, ICraftingService service, int flag) { List items = new ArrayList<>(); KeyCounter keyCounter = monitor.getAvailableStacks(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java index 703b78e9b..66c80bb97 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java @@ -1,5 +1,6 @@ package de.srendi.advancedperipherals.common.addons.computercraft.peripheral; +import appeng.api.crafting.IPatternDetails; import appeng.api.networking.IGridNode; import appeng.api.networking.IManagedGridNode; import appeng.api.networking.crafting.ICraftingCPU; @@ -13,6 +14,7 @@ import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.lua.MethodResult; import dan200.computercraft.api.peripheral.IComputerAccess; +import dan200.computercraft.core.apis.TableHelper; import dan200.computercraft.core.computer.ComputerSide; import de.srendi.advancedperipherals.common.addons.appliedenergistics.AppEngApi; import de.srendi.advancedperipherals.common.addons.appliedenergistics.CraftJob; @@ -273,12 +275,12 @@ public MethodResult getFilteredPatterns(IArguments arguments) throws LuaExceptio if (!isAvailable()) return notConnected(); + // Expected input is a table with either an input table, an output table or both to filter for both Map filterTable; try { Optional> optionalTable = arguments.optTable(0); if (optionalTable.isEmpty()) return MethodResult.of(null, "EMPTY_INPUT"); - // Expected input is a table with either an input table, an output table or both to filter for both filterTable = optionalTable.get(); } catch (LuaException e) { return MethodResult.of(null, "NO_TABLE"); @@ -286,12 +288,37 @@ public MethodResult getFilteredPatterns(IArguments arguments) throws LuaExceptio boolean hasInputFilter = filterTable.containsKey("input"); boolean hasOutputFilter = filterTable.containsKey("output"); + boolean hasAnyFilter = hasInputFilter || hasOutputFilter; + // If the player tries to filter for nothing, return nothing. + if (!hasAnyFilter) + return MethodResult.of(null, "NO_FILTER"); - if (hasInputFilter) - return null; + GenericFilter inputFilter = GenericFilter.empty(); + GenericFilter outputFilter = GenericFilter.empty(); - return null; + if (hasInputFilter) { + Map inputFilterTable = TableHelper.getTableField(filterTable, "input"); + + inputFilter = GenericFilter.parseGeneric(inputFilterTable).getLeft(); + } + if (hasOutputFilter) { + Map outputFilterTable = TableHelper.getTableField(filterTable, "output"); + + outputFilter = GenericFilter.parseGeneric(outputFilterTable).getLeft(); + } + + ICraftingProvider provider = node.getService(ICraftingProvider.class); + + if (provider == null) + return MethodResult.of(null, "NO_CRAFTING_PROVIDER"); + + Pair pattern = AppEngApi.findPatternFromFilters(provider, inputFilter, outputFilter); + + if (pattern.getRight() != null) + return MethodResult.of(null, pattern.getRight()); + + return MethodResult.of(AppEngApi.getObjectFromPattern(pattern.getLeft())); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java index 1b0b670eb..aab4cdd0b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java @@ -1,6 +1,5 @@ package de.srendi.advancedperipherals.common.setup; -import de.srendi.advancedperipherals.common.addons.APAddons; import de.srendi.advancedperipherals.common.blocks.PlayerDetectorBlock; import de.srendi.advancedperipherals.common.blocks.RedstoneIntegratorBlock; import de.srendi.advancedperipherals.common.blocks.base.APBlockEntityBlock; diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java index 29b13f06c..da7510ba0 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java @@ -1,5 +1,7 @@ package de.srendi.advancedperipherals.common.util.inventory; +import appeng.api.stacks.AEFluidKey; +import appeng.api.stacks.GenericStack; import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.core.apis.TableHelper; import de.srendi.advancedperipherals.AdvancedPeripherals; @@ -97,6 +99,14 @@ public FluidFilter setCount(int count) { return this; } + @Override + public boolean test(GenericStack genericStack) { + if (genericStack.what() instanceof AEFluidKey aeFluidKey) { + return test(aeFluidKey.toStack(1)); + } + return false; + } + public boolean test(FluidStack stack) { if (!fingerprint.isEmpty()) { String testFingerprint = FluidUtil.getFingerprint(stack); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java index bdde14a37..2a5f88010 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java @@ -1,16 +1,60 @@ package de.srendi.advancedperipherals.common.util.inventory; +import appeng.api.stacks.GenericStack; import de.srendi.advancedperipherals.common.util.Pair; +import net.minecraftforge.registries.ForgeRegistries; import java.util.Map; public abstract class GenericFilter { - // TODO: Imagine we want to filter for an object which can either a item, a fluid or maybe a chemical from mekanism - // This function should first check if the `name` key can be found in any of the registries and then return the - // right filter according to the registry type which could be an item or a chemical - public static Pair parseGeneric(Map rawFilter) { - return Pair.of(null, null); + /** + * Try to parse a raw filter table to any existing filter type. Could be a fluid filter, an item filter, maybe something else + * in the future. + *

+ * If the function can't find a valid type for the given name/resource location, it will return an empty filter with + * a proper error message. + * + * @param rawFilter The raw filter, which is a map of strings and objects + * @return A pair of the parsed filter and an error message, if there is one + */ + public static Pair parseGeneric(Map rawFilter) { + if (!rawFilter.containsKey("name")) { + // If the filter does not contain a name, which should never happen, but players are players, we will just + // give the ItemFilter the task to parse the filter + return ItemFilter.parse(rawFilter); + } + String name = rawFilter.get("name").toString(); + + // Let's check in which registry this thing is + if (ItemUtil.getRegistryEntry(name, ForgeRegistries.ITEMS) != null) { + return ItemFilter.parse(rawFilter); + } else if (ItemUtil.getRegistryEntry(name, ForgeRegistries.FLUIDS) != null) { + return FluidFilter.parse(rawFilter); + // TODO: Add chemical filter support + } else { + // If the name is in neither of the registries, we will just return an empty filter + return Pair.of(empty(), "NO_VALID_FILTER_TYPE"); + } + + } + + public abstract boolean isEmpty(); + + public abstract boolean test(GenericStack genericStack); + + public static GenericFilter empty() { + return new GenericFilter() { + @Override + public boolean isEmpty() { + return true; + } + + @Override + public boolean test(GenericStack genericStack) { + return false; + } + }; } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java index 9bc0a7b49..cfc9d4892 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java @@ -1,5 +1,7 @@ package de.srendi.advancedperipherals.common.util.inventory; +import appeng.api.stacks.AEItemKey; +import appeng.api.stacks.GenericStack; import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.core.apis.TableHelper; import de.srendi.advancedperipherals.AdvancedPeripherals; @@ -112,6 +114,14 @@ public ItemStack toItemStack() { return result; } + @Override + public boolean test(GenericStack genericStack) { + if (genericStack.what() instanceof AEItemKey aeItemKey) { + return test(aeItemKey.toStack()); + } + return false; + } + public boolean test(ItemStack stack) { if (!fingerprint.isEmpty()) { String testFingerprint = ItemUtil.getFingerprint(stack); From 09a18748f1f0b40a9e11c5d3971c61d243f3dc18 Mon Sep 17 00:00:00 2001 From: Deniz Demiroglu Date: Mon, 18 Dec 2023 18:30:59 +0100 Subject: [PATCH 074/228] Fixed pattern listing. AE2 does not offer a way to get all patterns of the system. To solve this, we probe over all connected nodes in the system and check if they have patterns. This is adapted from the PatternAccessTerminal which does the same --- .../addons/appliedenergistics/AppEngApi.java | 49 ++++++++++--- .../peripheral/MeBridgePeripheral.java | 55 +++++++++++---- .../peripheral/RsBridgePeripheral.java | 5 ++ .../common/util/inventory/GenericFilter.java | 13 +++- .../inventory/IStorageSystemPeripheral.java | 69 +++++++++---------- 5 files changed, 129 insertions(+), 62 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java index 8b2ec2bf5..b64812160 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java @@ -2,10 +2,10 @@ import appeng.api.crafting.IPatternDetails; import appeng.api.inventories.InternalInventory; +import appeng.api.networking.IGrid; import appeng.api.networking.IGridNode; import appeng.api.networking.crafting.CraftingJobStatus; import appeng.api.networking.crafting.ICraftingCPU; -import appeng.api.networking.crafting.ICraftingProvider; import appeng.api.networking.crafting.ICraftingService; import appeng.api.networking.storage.IStorageService; import appeng.api.stacks.*; @@ -13,6 +13,8 @@ import appeng.api.storage.IStorageProvider; import appeng.api.storage.MEStorage; import appeng.blockentity.storage.DriveBlockEntity; +import appeng.crafting.pattern.EncodedPatternItem; +import appeng.helpers.iface.PatternContainer; import appeng.items.storage.BasicStorageCell; import appeng.parts.storagebus.StorageBusPart; import com.the9grounds.aeadditions.item.storage.SuperStorageCell; @@ -31,6 +33,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.util.LazyOptional; @@ -38,7 +41,6 @@ import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.registries.ForgeRegistries; -import org.apache.logging.log4j.Level; import org.jetbrains.annotations.Nullable; import java.util.*; @@ -88,8 +90,8 @@ public static Pair findAEFluidFromFilter(MEStorage monitor, @N return null; } - public static Pair findPatternFromFilters(ICraftingProvider provider, GenericFilter inputFilter, GenericFilter outputFilter) { - for (IPatternDetails pattern : provider.getAvailablePatterns()) { + public static Pair findPatternFromFilters(IGrid grid, Level level, GenericFilter inputFilter, GenericFilter outputFilter) { + for (IPatternDetails pattern : getPatterns(grid, level)) { if (pattern.getInputs().length == 0) continue; if (pattern.getOutputs().length == 0) @@ -98,7 +100,7 @@ public static Pair findPatternFromFilters(ICraftingProv boolean inputMatch = false; boolean outputMatch = false; - if(!inputFilter.isEmpty()) { + if (inputFilter != null) { for (IPatternDetails.IInput input : pattern.getInputs()) { if (inputFilter.test(input.getPossibleInputs()[0])) { inputMatch = true; @@ -109,7 +111,7 @@ public static Pair findPatternFromFilters(ICraftingProv inputMatch = true; } - if(!outputFilter.isEmpty()) { + if (outputFilter != null) { for (GenericStack output : pattern.getOutputs()) { if (outputFilter.test(output)) { outputMatch = true; @@ -172,8 +174,37 @@ public static List listGases(MEStorage monitor, ICraftingService service return items; } - public static List listPatterns(ICraftingProvider manager) { - return manager.getAvailablePatterns().stream().map(AppEngApi::getObjectFromPattern).collect(Collectors.toList()); + public static List getPatterns(IGrid grid, Level level) { + List patterns = new ArrayList<>(); + for (var machineClass : grid.getMachineClasses()) { + var containerClass = tryCastMachineToContainer(machineClass); + if (containerClass == null) + continue; + + for (var container : grid.getActiveMachines(containerClass)) { + for (ItemStack patternItem : container.getTerminalPatternInventory()) { + if (patternItem.getItem() instanceof EncodedPatternItem item) { + IPatternDetails patternDetails = item.decode(patternItem, level, false); + if (patternDetails == null) + continue; + + patterns.add(patternDetails); + } + } + } + } + return patterns; + } + + public static List listPatterns(IGrid grid, Level level) { + return getPatterns(grid, level).stream().map(AppEngApi::getObjectFromPattern).collect(Collectors.toList()); + } + + private static Class tryCastMachineToContainer(Class machineClass) { + if (PatternContainer.class.isAssignableFrom(machineClass)) { + return machineClass.asSubclass(PatternContainer.class); + } + return null; } public static Map getObjectFromStack(Pair stack, @Nullable ICraftingService service) { @@ -186,7 +217,7 @@ public static Map getObjectFromStack(Pair inputFilterTable = TableHelper.getTableField(filterTable, "input"); @@ -308,12 +319,8 @@ public MethodResult getFilteredPatterns(IArguments arguments) throws LuaExceptio outputFilter = GenericFilter.parseGeneric(outputFilterTable).getLeft(); } - ICraftingProvider provider = node.getService(ICraftingProvider.class); - - if (provider == null) - return MethodResult.of(null, "NO_CRAFTING_PROVIDER"); - Pair pattern = AppEngApi.findPatternFromFilters(provider, inputFilter, outputFilter); + Pair pattern = AppEngApi.findPatternFromFilters(node.getGrid(), getLevel(), inputFilter, outputFilter); if (pattern.getRight() != null) return MethodResult.of(null, pattern.getRight()); @@ -322,19 +329,16 @@ public MethodResult getFilteredPatterns(IArguments arguments) throws LuaExceptio } @Override + @LuaFunction(mainThread = true) public MethodResult getPatterns() { if (!isAvailable()) return notConnected(); - ICraftingProvider provider = node.getService(ICraftingProvider.class); - - if (provider == null) - return MethodResult.of(null, "NO_CRAFTING_PROVIDER"); - - return MethodResult.of(AppEngApi.listPatterns(provider)); + return MethodResult.of(AppEngApi.listPatterns(node.getGrid(), getLevel())); } @Override + @LuaFunction(mainThread = true) public final MethodResult getStoredEnergy() { if (!isAvailable()) return notConnected(); @@ -343,6 +347,7 @@ public final MethodResult getStoredEnergy() { } @Override + @LuaFunction(mainThread = true) public final MethodResult getEnergyCapacity() { if (!isAvailable()) return notConnected(); @@ -351,6 +356,7 @@ public final MethodResult getEnergyCapacity() { } @Override + @LuaFunction(mainThread = true) public final MethodResult getEnergyUsage() { if (!isAvailable()) return notConnected(); @@ -358,6 +364,7 @@ public final MethodResult getEnergyUsage() { return MethodResult.of(node.getGrid().getEnergyService().getAvgPowerUsage()); } + @Override @LuaFunction(mainThread = true) public final MethodResult getAvgPowerInjection() { if (!isAvailable()) @@ -367,17 +374,20 @@ public final MethodResult getAvgPowerInjection() { } @Override + @LuaFunction(mainThread = true) public MethodResult getTotalExternItemStorage() { return null; } @Override + @LuaFunction(mainThread = true) public MethodResult getTotalExternFluidStorage() { return null; } @Override + @LuaFunction(mainThread = true) public final MethodResult getTotalItemStorage() { if (!isAvailable()) return notConnected(); @@ -386,6 +396,7 @@ public final MethodResult getTotalItemStorage() { } @Override + @LuaFunction(mainThread = true) public final MethodResult getTotalFluidStorage() { if (!isAvailable()) return notConnected(); @@ -394,16 +405,19 @@ public final MethodResult getTotalFluidStorage() { } @Override + @LuaFunction(mainThread = true) public MethodResult getUsedExternItemStorage() { return null; } @Override + @LuaFunction(mainThread = true) public MethodResult getUsedExternFluidStorage() { return null; } @Override + @LuaFunction(mainThread = true) public final MethodResult getUsedItemStorage() { if (!isAvailable()) return notConnected(); @@ -412,6 +426,7 @@ public final MethodResult getUsedItemStorage() { } @Override + @LuaFunction(mainThread = true) public final MethodResult getUsedFluidStorage() { if (!isAvailable()) return notConnected(); @@ -420,16 +435,19 @@ public final MethodResult getUsedFluidStorage() { } @Override + @LuaFunction(mainThread = true) public MethodResult getAvailableExternItemStorage() { return null; } @Override + @LuaFunction(mainThread = true) public MethodResult getAvailableExternFluidStorage() { return null; } @Override + @LuaFunction(mainThread = true) public final MethodResult getAvailableItemStorage() { if (!isAvailable()) return notConnected(); @@ -438,6 +456,7 @@ public final MethodResult getAvailableItemStorage() { } @Override + @LuaFunction(mainThread = true) public final MethodResult getAvailableFluidStorage() { if (!isAvailable()) return notConnected(); @@ -446,6 +465,7 @@ public final MethodResult getAvailableFluidStorage() { } @Override + @LuaFunction(mainThread = true) public final MethodResult craftItem(IComputerAccess computer, IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -475,6 +495,7 @@ public final MethodResult craftItem(IComputerAccess computer, IArguments argumen } @Override + @LuaFunction(mainThread = true) public final MethodResult craftFluid(IComputerAccess computer, IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -504,6 +525,7 @@ public final MethodResult craftFluid(IComputerAccess computer, IArguments argume } @Override + @LuaFunction(mainThread = true) public final MethodResult isItemCraftable(IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -522,6 +544,7 @@ public final MethodResult isItemCraftable(IArguments arguments) throws LuaExcept } @Override + @LuaFunction(mainThread = true) public final MethodResult isFluidCrafting(IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -543,6 +566,7 @@ public final MethodResult isFluidCrafting(IArguments arguments) throws LuaExcept } @Override + @LuaFunction(mainThread = true) public final MethodResult isFluidCraftable(IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -561,6 +585,7 @@ public final MethodResult isFluidCraftable(IArguments arguments) throws LuaExcep } @Override + @LuaFunction(mainThread = true) public final MethodResult exportFluid(IComputerAccess computer, IArguments arguments) throws LuaException { String side = arguments.getString(1); IFluidHandler fluidHandler; @@ -578,6 +603,7 @@ public final MethodResult exportFluid(IComputerAccess computer, IArguments argum } @Override + @LuaFunction(mainThread = true) public final MethodResult importFluid(IComputerAccess computer, IArguments arguments) throws LuaException { String side = arguments.getString(1); IFluidHandler fluidHandler; @@ -595,6 +621,7 @@ public final MethodResult importFluid(IComputerAccess computer, IArguments argum } @Override + @LuaFunction(mainThread = true) public final MethodResult isItemCrafting(IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java index 9b1bf96e4..a3447db34 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java @@ -209,6 +209,11 @@ public final MethodResult getStoredEnergy() { return MethodResult.of(getNetwork().getEnergyStorage().getEnergyStored()); } + @Override + public MethodResult getAvgPowerInjection() { + return null; + } + @Override public final MethodResult getFilteredPatterns(IArguments arguments) throws LuaException { if (!isAvailable()) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java index 2a5f88010..64d148419 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java @@ -19,8 +19,18 @@ public abstract class GenericFilter { * @return A pair of the parsed filter and an error message, if there is one */ public static Pair parseGeneric(Map rawFilter) { + // TODO: Add chemical filter support + if (!rawFilter.containsKey("name")) { - // If the filter does not contain a name, which should never happen, but players are players, we will just + if (rawFilter.containsKey("type") && rawFilter.get("type") instanceof String type) { + switch (type) { + case "item": + return ItemFilter.parse(rawFilter); + case "fluid": + return FluidFilter.parse(rawFilter); + } + } + // If the filter does not contain a name or a type, which should never happen, but players are players, we will just // give the ItemFilter the task to parse the filter return ItemFilter.parse(rawFilter); } @@ -31,7 +41,6 @@ public static Pair parseGeneric(Map rawFi return ItemFilter.parse(rawFilter); } else if (ItemUtil.getRegistryEntry(name, ForgeRegistries.FLUIDS) != null) { return FluidFilter.parse(rawFilter); - // TODO: Add chemical filter support } else { // If the name is in neither of the registries, we will just return an empty filter return Pair.of(empty(), "NO_VALID_FILTER_TYPE"); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java index ff42f6ce3..fb4b0eba6 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java @@ -2,7 +2,6 @@ import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.LuaException; -import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.lua.MethodResult; import dan200.computercraft.api.peripheral.IComputerAccess; @@ -13,115 +12,111 @@ * This ensures that these both bridges use the same methods. This makes it easier to support both in the same script * In case there is a new mod which adds new ways to store and craft items, this ensures that the new peripheral * has the same functions as the other ones + *

+ * Implementation needs to override {@link dan200.computercraft.api.lua.LuaFunction} */ public interface IStorageSystemPeripheral { - @LuaFunction(mainThread = true) MethodResult isConnected(); - @LuaFunction(mainThread = true) MethodResult isOnline(); - @LuaFunction(mainThread = true) MethodResult getItem(IArguments arguments) throws LuaException; - @LuaFunction(mainThread = true) MethodResult getFluid(IArguments arguments) throws LuaException; - @LuaFunction(mainThread = true) MethodResult listItems(); - @LuaFunction(mainThread = true) MethodResult listFluids(); - @LuaFunction(mainThread = true) + MethodResult listCraftableItems(); - @LuaFunction(mainThread = true) + MethodResult listCraftableFluids(); - @LuaFunction MethodResult listCells(); - @LuaFunction(mainThread = true) + MethodResult importItem(IComputerAccess computer, IArguments arguments) throws LuaException; - @LuaFunction(mainThread = true) + MethodResult exportItem(IComputerAccess computer, IArguments arguments) throws LuaException; - @LuaFunction(mainThread = true) + MethodResult importFluid(IComputerAccess computer, IArguments arguments) throws LuaException; - @LuaFunction(mainThread = true) + MethodResult exportFluid(IComputerAccess computer, IArguments arguments) throws LuaException; - @LuaFunction(mainThread = true) + MethodResult getFilteredPatterns(IArguments arguments) throws LuaException; - @LuaFunction(mainThread = true) + MethodResult getPatterns(); - @LuaFunction(mainThread = true) + MethodResult getStoredEnergy(); - @LuaFunction(mainThread = true) + MethodResult getEnergyCapacity(); - @LuaFunction(mainThread = true) + MethodResult getEnergyUsage(); - @LuaFunction(mainThread = true) + MethodResult getAvgPowerInjection(); + MethodResult getTotalExternItemStorage(); - @LuaFunction(mainThread = true) + MethodResult getTotalExternFluidStorage(); - @LuaFunction(mainThread = true) + MethodResult getTotalItemStorage(); - @LuaFunction(mainThread = true) + MethodResult getTotalFluidStorage(); - @LuaFunction(mainThread = true) + MethodResult getUsedExternItemStorage(); - @LuaFunction(mainThread = true) + MethodResult getUsedExternFluidStorage(); - @LuaFunction(mainThread = true) + MethodResult getUsedItemStorage(); - @LuaFunction(mainThread = true) + MethodResult getUsedFluidStorage(); - @LuaFunction(mainThread = true) + MethodResult getAvailableExternItemStorage(); - @LuaFunction(mainThread = true) + MethodResult getAvailableExternFluidStorage(); - @LuaFunction(mainThread = true) + MethodResult getAvailableItemStorage(); - @LuaFunction(mainThread = true) + MethodResult getAvailableFluidStorage(); - @LuaFunction(mainThread = true) + MethodResult craftItem(IComputerAccess computer, IArguments arguments) throws LuaException; - @LuaFunction(mainThread = true) + MethodResult craftFluid(IComputerAccess computer, IArguments arguments) throws LuaException; - @LuaFunction(mainThread = true) + MethodResult isItemCraftable(IArguments arguments) throws LuaException; - @LuaFunction(mainThread = true) + MethodResult isItemCrafting(IArguments arguments) throws LuaException; - @LuaFunction(mainThread = true) + MethodResult isFluidCraftable(IArguments arguments) throws LuaException; - @LuaFunction(mainThread = true) + MethodResult isFluidCrafting(IArguments arguments) throws LuaException; } From 1154d8aa3395528e20757debfca14c61b034a562 Mon Sep 17 00:00:00 2001 From: Srendi Date: Thu, 21 Dec 2023 01:51:42 +0100 Subject: [PATCH 075/228] Improve and extend the functionality of the ME Bridge by implementing the handling of external fluid and item storage. This includes the capability to get the total, used, and available external storage for both fluid and item elements. --- .../addons/appliedenergistics/AppEngApi.java | 166 +++++++++++------- .../peripheral/MeBridgePeripheral.java | 31 +++- 2 files changed, 129 insertions(+), 68 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java index b64812160..314239ece 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java @@ -90,7 +90,18 @@ public static Pair findAEFluidFromFilter(MEStorage monitor, @N return null; } - public static Pair findPatternFromFilters(IGrid grid, Level level, GenericFilter inputFilter, GenericFilter outputFilter) { + /** + * Finds a pattern from filters. + * + * @param grid The grid to search patterns from. + * @param level The level of the grid. + * @param inputFilter The input filter to apply, can be null to ignore input filter. + * @param outputFilter The output filter to apply, can be null to ignore output filter. + * @return A Pair object containing the matched pattern and an error message if no pattern is found. + * The pattern can be null if no pattern is found. + * The error message is "NO_PATTERN_FOUND" if no pattern is found. + */ + public static Pair findPatternFromFilters(IGrid grid, Level level, @Nullable GenericFilter inputFilter, @Nullable GenericFilter outputFilter) { for (IPatternDetails pattern : getPatterns(grid, level)) { if (pattern.getInputs().length == 0) continue; @@ -101,10 +112,13 @@ public static Pair findPatternFromFilters(IGrid grid, L boolean outputMatch = false; if (inputFilter != null) { + outerLoop: for (IPatternDetails.IInput input : pattern.getInputs()) { - if (inputFilter.test(input.getPossibleInputs()[0])) { - inputMatch = true; - break; + for (GenericStack possibleInput : input.getPossibleInputs()) { + if (inputFilter.test(possibleInput)) { + inputMatch = true; + break outerLoop; + } } } } else { @@ -263,8 +277,8 @@ private static Map getObjectFromGasStack(Pair public static Map getObjectFromPattern(IPatternDetails pattern) { Map map = new HashMap<>(); - map.put("inputs", Arrays.stream(pattern.getInputs()).map(AppEngApi::getObjectFromPatternInput)); - map.put("outputs", Arrays.stream(pattern.getOutputs()).map(AppEngApi::getObjectFromGenericStack)); + map.put("inputs", Arrays.stream(pattern.getInputs()).map(AppEngApi::getObjectFromPatternInput).collect(Collectors.toList())); + map.put("outputs", Arrays.stream(pattern.getOutputs()).map(AppEngApi::getObjectFromGenericStack).collect(Collectors.toList())); map.put("primaryOutput", getObjectFromGenericStack(pattern.getPrimaryOutput())); return map; } @@ -393,13 +407,35 @@ public static boolean isFluidCrafting(MEStorage monitor, ICraftingService grid, return false; } - public static long getTotalItemStorage(IGridNode node) { + public static long getTotalExternalItemStorage(IGridNode node) { long total = 0; - Iterator iterator = node.getGrid().getMachineNodes(DriveBlockEntity.class).iterator(); + for (IGridNode iGridNode : node.getGrid().getMachineNodes(StorageBusPart.class)) { + StorageBusPart bus = (StorageBusPart) iGridNode.getService(IStorageProvider.class); + Level level = bus.getLevel(); + BlockPos connectedInventoryPos = bus.getHost().getBlockEntity().getBlockPos().relative(bus.getSide()); + BlockEntity connectedInventoryEntity = level.getBlockEntity(connectedInventoryPos); - while (iterator.hasNext()) { - DriveBlockEntity entity = (DriveBlockEntity) iterator.next().getService(IStorageProvider.class); + if (connectedInventoryEntity == null) + continue; + + LazyOptional itemHandler = connectedInventoryEntity.getCapability(ForgeCapabilities.ITEM_HANDLER); + if (itemHandler.isPresent()) { + IItemHandler handler = itemHandler.orElse(null); + for (int i = 0; i < handler.getSlots(); i++) { + total += handler.getSlotLimit(i); + } + } + } + + return total; + } + + public static long getTotalItemStorage(IGridNode node) { + long total = 0; + + for (IGridNode iGridNode : node.getGrid().getMachineNodes(DriveBlockEntity.class)) { + DriveBlockEntity entity = (DriveBlockEntity) iGridNode.getService(IStorageProvider.class); if (entity == null) continue; @@ -420,24 +456,33 @@ public static long getTotalItemStorage(IGridNode node) { total += disk.getBytes(null); } } else if (APAddons.aeAdditionsLoaded && (stack.getItem() instanceof SuperStorageCell superStorageCell)) { - total += superStorageCell.getKiloBytes() * 1024; + total += superStorageCell.getKiloBytes() * 1024L; } } } - iterator = node.getGrid().getMachineNodes(StorageBusPart.class).iterator(); + total += getTotalExternalItemStorage(node); - while (iterator.hasNext()) { - StorageBusPart bus = (StorageBusPart) iterator.next().getService(IStorageProvider.class); - net.minecraft.world.level.Level level = bus.getLevel(); + return total; + } + + public static long getTotalExternalFluidStorage(IGridNode node) { + long total = 0; + + for (IGridNode iGridNode : node.getGrid().getMachineNodes(StorageBusPart.class)) { + StorageBusPart bus = (StorageBusPart) iGridNode.getService(IStorageProvider.class); + Level level = bus.getLevel(); BlockPos connectedInventoryPos = bus.getHost().getBlockEntity().getBlockPos().relative(bus.getSide()); BlockEntity connectedInventoryEntity = level.getBlockEntity(connectedInventoryPos); - LazyOptional itemHandler = connectedInventoryEntity.getCapability(ForgeCapabilities.ITEM_HANDLER); - if (itemHandler.isPresent()) { - IItemHandler handler = itemHandler.orElse(null); - for (int i = 0; i < handler.getSlots(); i++) { - total += handler.getSlotLimit(i); + if (connectedInventoryEntity == null) + continue; + + LazyOptional fluidHandler = connectedInventoryEntity.getCapability(ForgeCapabilities.FLUID_HANDLER); + if (fluidHandler.isPresent()) { + IFluidHandler handler = fluidHandler.orElse(null); + for (int i = 0; i < handler.getTanks(); i++) { + total += handler.getTankCapacity(i); } } } @@ -448,10 +493,8 @@ public static long getTotalItemStorage(IGridNode node) { public static long getTotalFluidStorage(IGridNode node) { long total = 0; - Iterator iterator = node.getGrid().getMachineNodes(DriveBlockEntity.class).iterator(); - - while (iterator.hasNext()) { - DriveBlockEntity entity = (DriveBlockEntity) iterator.next().getService(IStorageProvider.class); + for (IGridNode iGridNode : node.getGrid().getMachineNodes(DriveBlockEntity.class)) { + DriveBlockEntity entity = (DriveBlockEntity) iGridNode.getService(IStorageProvider.class); if (entity == null) continue; @@ -468,38 +511,38 @@ public static long getTotalFluidStorage(IGridNode node) { total += cell.getBytes(null); } } else if (APAddons.aeAdditionsLoaded && stack.getItem() instanceof SuperStorageCell superStorageCell) { - total += superStorageCell.getKiloBytes() * 1024; + total += superStorageCell.getKiloBytes() * 1024L; } } } - iterator = node.getGrid().getMachineNodes(StorageBusPart.class).iterator(); + total += getTotalExternalFluidStorage(node); - while (iterator.hasNext()) { - StorageBusPart bus = (StorageBusPart) iterator.next().getService(IStorageProvider.class); - net.minecraft.world.level.Level level = bus.getLevel(); - BlockPos connectedInventoryPos = bus.getHost().getBlockEntity().getBlockPos().relative(bus.getSide()); - BlockEntity connectedInventoryEntity = level.getBlockEntity(connectedInventoryPos); + return total; + } - LazyOptional fluidHandler = connectedInventoryEntity.getCapability(ForgeCapabilities.FLUID_HANDLER); - if (fluidHandler.isPresent()) { - IFluidHandler handler = fluidHandler.orElse(null); - for (int i = 0; i < handler.getTanks(); i++) { - total += handler.getTankCapacity(i); + public static long getUsedExternalItemStorage(IGridNode node) { + long used = 0; + + for (IGridNode iGridNode : node.getGrid().getMachineNodes(StorageBusPart.class)) { + StorageBusPart bus = (StorageBusPart) iGridNode.getService(IStorageProvider.class); + KeyCounter keyCounter = bus.getInternalHandler().getAvailableStacks(); + + for (Object2LongMap.Entry aeKey : keyCounter) { + if (aeKey.getKey() instanceof AEItemKey) { + used += aeKey.getLongValue(); } } } - return total; + return used; } public static long getUsedItemStorage(IGridNode node) { long used = 0; - Iterator iterator = node.getGrid().getMachineNodes(DriveBlockEntity.class).iterator(); - - while (iterator.hasNext()) { - DriveBlockEntity entity = (DriveBlockEntity) iterator.next().getService(IStorageProvider.class); + for (IGridNode iGridNode : node.getGrid().getMachineNodes(DriveBlockEntity.class)) { + DriveBlockEntity entity = (DriveBlockEntity) iGridNode.getService(IStorageProvider.class); if (entity == null) continue; @@ -539,14 +582,20 @@ public static long getUsedItemStorage(IGridNode node) { } } - iterator = node.getGrid().getMachineNodes(StorageBusPart.class).iterator(); + used += getUsedExternalItemStorage(node); - while (iterator.hasNext()) { - StorageBusPart bus = (StorageBusPart) iterator.next().getService(IStorageProvider.class); + return used; + } + + public static long getUsedExternalFluidStorage(IGridNode node) { + long used = 0; + + for (IGridNode iGridNode : node.getGrid().getMachineNodes(StorageBusPart.class)) { + StorageBusPart bus = (StorageBusPart) iGridNode.getService(IStorageProvider.class); KeyCounter keyCounter = bus.getInternalHandler().getAvailableStacks(); for (Object2LongMap.Entry aeKey : keyCounter) { - if (aeKey.getKey() instanceof AEItemKey) { + if (aeKey.getKey() instanceof AEFluidKey) { used += aeKey.getLongValue(); } } @@ -558,10 +607,8 @@ public static long getUsedItemStorage(IGridNode node) { public static long getUsedFluidStorage(IGridNode node) { long used = 0; - Iterator iterator = node.getGrid().getMachineNodes(DriveBlockEntity.class).iterator(); - - while (iterator.hasNext()) { - DriveBlockEntity entity = (DriveBlockEntity) iterator.next().getService(IStorageProvider.class); + for (IGridNode iGridNode : node.getGrid().getMachineNodes(DriveBlockEntity.class)) { + DriveBlockEntity entity = (DriveBlockEntity) iGridNode.getService(IStorageProvider.class); if (entity == null) continue; @@ -591,18 +638,7 @@ public static long getUsedFluidStorage(IGridNode node) { } } - iterator = node.getGrid().getMachineNodes(StorageBusPart.class).iterator(); - - while (iterator.hasNext()) { - StorageBusPart bus = (StorageBusPart) iterator.next().getService(IStorageProvider.class); - KeyCounter keyCounter = bus.getInternalHandler().getAvailableStacks(); - - for (Object2LongMap.Entry aeKey : keyCounter) { - if (aeKey.getKey() instanceof AEFluidKey) { - used += aeKey.getLongValue(); - } - } - } + used += getUsedExternalFluidStorage(node); return used; } @@ -615,6 +651,14 @@ public static long getAvailableFluidStorage(IGridNode node) { return getTotalFluidStorage(node) - getUsedFluidStorage(node); } + public static long getAvailableExternalItemStorage(IGridNode node) { + return getTotalExternalItemStorage(node) - getUsedExternalItemStorage(node); + } + + public static long getAvailableExternalFluidStorage(IGridNode node) { + return getTotalExternalFluidStorage(node) - getUsedExternalFluidStorage(node); + } + public static List listCells(IGridNode node) { List items = new ArrayList<>(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java index 75bf5ba53..48ead86bc 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java @@ -376,13 +376,19 @@ public final MethodResult getAvgPowerInjection() { @Override @LuaFunction(mainThread = true) public MethodResult getTotalExternItemStorage() { - return null; + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(AppEngApi.getTotalExternalItemStorage(node)); } @Override @LuaFunction(mainThread = true) public MethodResult getTotalExternFluidStorage() { - return null; + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(AppEngApi.getTotalExternalFluidStorage(node)); } @@ -407,13 +413,19 @@ public final MethodResult getTotalFluidStorage() { @Override @LuaFunction(mainThread = true) public MethodResult getUsedExternItemStorage() { - return null; + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(AppEngApi.getUsedExternalFluidStorage(node)); } @Override @LuaFunction(mainThread = true) public MethodResult getUsedExternFluidStorage() { - return null; + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(AppEngApi.getUsedExternalFluidStorage(node)); } @Override @@ -437,13 +449,18 @@ public final MethodResult getUsedFluidStorage() { @Override @LuaFunction(mainThread = true) public MethodResult getAvailableExternItemStorage() { - return null; - } + if (!isAvailable()) + return notConnected(); + return MethodResult.of(AppEngApi.getAvailableExternalItemStorage(node)); + } @Override @LuaFunction(mainThread = true) public MethodResult getAvailableExternFluidStorage() { - return null; + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(AppEngApi.getAvailableExternalFluidStorage(node)); } @Override From c5eccc79baae1b08b643b256aa4938bc6d3cbe48 Mon Sep 17 00:00:00 2001 From: Srendi Date: Thu, 21 Dec 2023 02:54:31 +0100 Subject: [PATCH 076/228] Implement mekanism chemical integration to the ME Bridge --- .../addons/appliedenergistics/AppEngApi.java | 252 ++++++++++++++---- .../peripheral/MeBridgePeripheral.java | 48 ++++ .../addons/mekanism/MekanismCapabilities.java | 10 + 3 files changed, 260 insertions(+), 50 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java index 314239ece..a02672aae 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java @@ -16,11 +16,14 @@ import appeng.crafting.pattern.EncodedPatternItem; import appeng.helpers.iface.PatternContainer; import appeng.items.storage.BasicStorageCell; +import appeng.me.cells.BasicCellHandler; +import appeng.me.cells.BasicCellInventory; import appeng.parts.storagebus.StorageBusPart; import com.the9grounds.aeadditions.item.storage.SuperStorageCell; import dan200.computercraft.shared.util.NBTUtil; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.addons.APAddons; +import de.srendi.advancedperipherals.common.addons.mekanism.MekanismCapabilities; import de.srendi.advancedperipherals.common.util.LuaConverter; import de.srendi.advancedperipherals.common.util.Pair; import de.srendi.advancedperipherals.common.util.inventory.FluidFilter; @@ -30,6 +33,14 @@ import io.github.projectet.ae2things.item.DISKDrive; import it.unimi.dsi.fastutil.objects.Object2LongMap; import me.ramidzkh.mekae2.ae2.MekanismKey; +import me.ramidzkh.mekae2.ae2.MekanismKeyType; +import me.ramidzkh.mekae2.item.ChemicalStorageCell; +import mekanism.api.chemical.IChemicalHandler; +import mekanism.api.chemical.gas.IGasHandler; +import mekanism.api.chemical.infuse.IInfusionHandler; +import mekanism.api.chemical.pigment.IPigmentHandler; +import mekanism.api.chemical.slurry.ISlurryHandler; +import mekanism.common.tile.TileEntityChemicalTank; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.item.ItemStack; @@ -407,6 +418,9 @@ public static boolean isFluidCrafting(MEStorage monitor, ICraftingService grid, return false; } + /// External Storage + /// Total + public static long getTotalExternalItemStorage(IGridNode node) { long total = 0; @@ -431,6 +445,109 @@ public static long getTotalExternalItemStorage(IGridNode node) { return total; } + public static long getTotalExternalFluidStorage(IGridNode node) { + long total = 0; + + for (IGridNode iGridNode : node.getGrid().getMachineNodes(StorageBusPart.class)) { + StorageBusPart bus = (StorageBusPart) iGridNode.getService(IStorageProvider.class); + Level level = bus.getLevel(); + BlockPos connectedInventoryPos = bus.getHost().getBlockEntity().getBlockPos().relative(bus.getSide()); + BlockEntity connectedInventoryEntity = level.getBlockEntity(connectedInventoryPos); + + if (connectedInventoryEntity == null) + continue; + + LazyOptional fluidHandler = connectedInventoryEntity.getCapability(ForgeCapabilities.FLUID_HANDLER); + if (fluidHandler.isPresent()) { + IFluidHandler handler = fluidHandler.orElse(null); + for (int i = 0; i < handler.getTanks(); i++) { + total += handler.getTankCapacity(i); + } + } + } + + return total; + } + + public static long getTotalExternalChemicalStorage(IGridNode node) { + long total = 0; + + if (!APAddons.appMekLoaded) + return 0; + + for (IGridNode iGridNode : node.getGrid().getMachineNodes(StorageBusPart.class)) { + StorageBusPart bus = (StorageBusPart) iGridNode.getService(IStorageProvider.class); + Level level = bus.getLevel(); + BlockPos connectedInventoryPos = bus.getHost().getBlockEntity().getBlockPos().relative(bus.getSide()); + BlockEntity connectedInventoryEntity = level.getBlockEntity(connectedInventoryPos); + + if (connectedInventoryEntity == null) + continue; + + if (connectedInventoryEntity instanceof TileEntityChemicalTank tank) { + total += tank.getChemicalTank().getTankFromCurrent(tank.getChemicalTank().getCurrent()).getCapacity(); + } + } + + return total; + } + + /// Used + + public static long getUsedExternalItemStorage(IGridNode node) { + long used = 0; + + for (IGridNode iGridNode : node.getGrid().getMachineNodes(StorageBusPart.class)) { + StorageBusPart bus = (StorageBusPart) iGridNode.getService(IStorageProvider.class); + KeyCounter keyCounter = bus.getInternalHandler().getAvailableStacks(); + + for (Object2LongMap.Entry aeKey : keyCounter) { + if (aeKey.getKey() instanceof AEItemKey) { + used += aeKey.getLongValue(); + } + } + } + + return used; + } + + public static long getUsedExternalFluidStorage(IGridNode node) { + long used = 0; + + for (IGridNode iGridNode : node.getGrid().getMachineNodes(StorageBusPart.class)) { + StorageBusPart bus = (StorageBusPart) iGridNode.getService(IStorageProvider.class); + KeyCounter keyCounter = bus.getInternalHandler().getAvailableStacks(); + + for (Object2LongMap.Entry aeKey : keyCounter) { + if (aeKey.getKey() instanceof AEFluidKey) { + used += aeKey.getLongValue(); + } + } + } + + return used; + } + + public static long getUsedExternalChemicalStorage(IGridNode node) { + long used = 0; + + for (IGridNode iGridNode : node.getGrid().getMachineNodes(StorageBusPart.class)) { + StorageBusPart bus = (StorageBusPart) iGridNode.getService(IStorageProvider.class); + KeyCounter keyCounter = bus.getInternalHandler().getAvailableStacks(); + + for (Object2LongMap.Entry aeKey : keyCounter) { + if (aeKey.getKey() instanceof MekanismKey) { + used += aeKey.getLongValue(); + } + } + } + + return used; + } + + /// Internal Storage + /// Total + public static long getTotalItemStorage(IGridNode node) { long total = 0; @@ -466,30 +583,6 @@ public static long getTotalItemStorage(IGridNode node) { return total; } - public static long getTotalExternalFluidStorage(IGridNode node) { - long total = 0; - - for (IGridNode iGridNode : node.getGrid().getMachineNodes(StorageBusPart.class)) { - StorageBusPart bus = (StorageBusPart) iGridNode.getService(IStorageProvider.class); - Level level = bus.getLevel(); - BlockPos connectedInventoryPos = bus.getHost().getBlockEntity().getBlockPos().relative(bus.getSide()); - BlockEntity connectedInventoryEntity = level.getBlockEntity(connectedInventoryPos); - - if (connectedInventoryEntity == null) - continue; - - LazyOptional fluidHandler = connectedInventoryEntity.getCapability(ForgeCapabilities.FLUID_HANDLER); - if (fluidHandler.isPresent()) { - IFluidHandler handler = fluidHandler.orElse(null); - for (int i = 0; i < handler.getTanks(); i++) { - total += handler.getTankCapacity(i); - } - } - } - - return total; - } - public static long getTotalFluidStorage(IGridNode node) { long total = 0; @@ -521,23 +614,37 @@ public static long getTotalFluidStorage(IGridNode node) { return total; } - public static long getUsedExternalItemStorage(IGridNode node) { - long used = 0; + public static long getTotalChemicalStorage(IGridNode node) { + long total = 0; - for (IGridNode iGridNode : node.getGrid().getMachineNodes(StorageBusPart.class)) { - StorageBusPart bus = (StorageBusPart) iGridNode.getService(IStorageProvider.class); - KeyCounter keyCounter = bus.getInternalHandler().getAvailableStacks(); + for (IGridNode iGridNode : node.getGrid().getMachineNodes(DriveBlockEntity.class)) { + DriveBlockEntity entity = (DriveBlockEntity) iGridNode.getService(IStorageProvider.class); + if (entity == null) + continue; - for (Object2LongMap.Entry aeKey : keyCounter) { - if (aeKey.getKey() instanceof AEItemKey) { - used += aeKey.getLongValue(); + InternalInventory inventory = entity.getInternalInventory(); + + for (int i = 0; i < inventory.size(); i++) { + ItemStack stack = inventory.getStackInSlot(i); + + if (stack.isEmpty()) + continue; + + if (stack.getItem() instanceof ChemicalStorageCell cell) { + if (cell.getKeyType() instanceof MekanismKeyType) { + total += (long) cell.getBytes(null) * MekanismKeyType.TYPE.getAmountPerByte(); + } } } } - return used; + total += getTotalExternalChemicalStorage(node); + + return total; } + /// Used + public static long getUsedItemStorage(IGridNode node) { long used = 0; @@ -587,23 +694,6 @@ public static long getUsedItemStorage(IGridNode node) { return used; } - public static long getUsedExternalFluidStorage(IGridNode node) { - long used = 0; - - for (IGridNode iGridNode : node.getGrid().getMachineNodes(StorageBusPart.class)) { - StorageBusPart bus = (StorageBusPart) iGridNode.getService(IStorageProvider.class); - KeyCounter keyCounter = bus.getInternalHandler().getAvailableStacks(); - - for (Object2LongMap.Entry aeKey : keyCounter) { - if (aeKey.getKey() instanceof AEFluidKey) { - used += aeKey.getLongValue(); - } - } - } - - return used; - } - public static long getUsedFluidStorage(IGridNode node) { long used = 0; @@ -643,22 +733,84 @@ public static long getUsedFluidStorage(IGridNode node) { return used; } + public static long getUsedChemicalStorage(IGridNode node) { + long used = 0; + + for (IGridNode iGridNode : node.getGrid().getMachineNodes(DriveBlockEntity.class)) { + DriveBlockEntity entity = (DriveBlockEntity) iGridNode.getService(IStorageProvider.class); + if (entity == null) + continue; + + InternalInventory inventory = entity.getInternalInventory(); + + for (int i = 0; i < inventory.size(); i++) { + ItemStack stack = inventory.getStackInSlot(i); + + if (stack.getItem() instanceof ChemicalStorageCell ) { + BasicCellInventory cellInventory = BasicCellHandler.INSTANCE.getCellInventory(stack, null); + + used = cellInventory.getUsedBytes() / MekanismKeyType.TYPE.getAmountPerByte(); + } + } + } + + used += getUsedExternalChemicalStorage(node); + + return used; + } + + /// Available Storage + + /** + * Calculates the available item storage on a given grid node. + * It subtracts the used item storage from the total item storage. + * + * @param node The grid node to calculate the available item storage for. + * @return The available item storage in bytes. + */ public static long getAvailableItemStorage(IGridNode node) { return getTotalItemStorage(node) - getUsedItemStorage(node); } + /** + * Calculates the available fluid storage in a given grid node. + * + * @param node The grid node to calculate the available fluid storage for. + * @return The available fluid storage in bytes. + */ public static long getAvailableFluidStorage(IGridNode node) { return getTotalFluidStorage(node) - getUsedFluidStorage(node); } + public static long getAvailableChemicalStorage(IGridNode node) { + return getTotalChemicalStorage(node) - getUsedChemicalStorage(node); + } + + /** + * Calculates the available external item storage of a given grid node. + * + * @param node The grid node for which to calculate the available external item storage. + * @return The available external item storage. + */ public static long getAvailableExternalItemStorage(IGridNode node) { return getTotalExternalItemStorage(node) - getUsedExternalItemStorage(node); } + /** + * Calculates the available external fluid storage on a given grid node by subtracting the used external fluid storage + * from the total external fluid storage. + * + * @param node The grid node on which to calculate the available external fluid storage. + * @return The available external fluid storage on the grid node. + */ public static long getAvailableExternalFluidStorage(IGridNode node) { return getTotalExternalFluidStorage(node) - getUsedExternalFluidStorage(node); } + public static long getAvailableExternalChemicalStorage(IGridNode node) { + return getTotalExternalChemicalStorage(node) - getUsedExternalChemicalStorage(node); + } + public static List listCells(IGridNode node) { List items = new ArrayList<>(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java index 48ead86bc..7fa4928a8 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java @@ -391,6 +391,13 @@ public MethodResult getTotalExternFluidStorage() { return MethodResult.of(AppEngApi.getTotalExternalFluidStorage(node)); } + @LuaFunction(mainThread = true) + public MethodResult getTotalExternChemicalStorage() { + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(AppEngApi.getTotalExternalChemicalStorage(node)); + } @Override @LuaFunction(mainThread = true) @@ -410,6 +417,14 @@ public final MethodResult getTotalFluidStorage() { return MethodResult.of(AppEngApi.getTotalFluidStorage(node)); } + @LuaFunction(mainThread = true) + public MethodResult getTotalChemicalStorage() { + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(AppEngApi.getTotalChemicalStorage(node)); + } + @Override @LuaFunction(mainThread = true) public MethodResult getUsedExternItemStorage() { @@ -428,6 +443,14 @@ public MethodResult getUsedExternFluidStorage() { return MethodResult.of(AppEngApi.getUsedExternalFluidStorage(node)); } + @LuaFunction(mainThread = true) + public MethodResult getUsedExternChemicalStorage() { + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(AppEngApi.getUsedExternalChemicalStorage(node)); + } + @Override @LuaFunction(mainThread = true) public final MethodResult getUsedItemStorage() { @@ -446,6 +469,14 @@ public final MethodResult getUsedFluidStorage() { return MethodResult.of(AppEngApi.getUsedFluidStorage(node)); } + @LuaFunction(mainThread = true) + public MethodResult getUsedChemicalStorage() { + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(AppEngApi.getUsedChemicalStorage(node)); + } + @Override @LuaFunction(mainThread = true) public MethodResult getAvailableExternItemStorage() { @@ -454,6 +485,7 @@ public MethodResult getAvailableExternItemStorage() { return MethodResult.of(AppEngApi.getAvailableExternalItemStorage(node)); } + @Override @LuaFunction(mainThread = true) public MethodResult getAvailableExternFluidStorage() { @@ -463,6 +495,14 @@ public MethodResult getAvailableExternFluidStorage() { return MethodResult.of(AppEngApi.getAvailableExternalFluidStorage(node)); } + @LuaFunction(mainThread = true) + public MethodResult getAvailableExternChemicalStorage() { + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(AppEngApi.getAvailableExternalChemicalStorage(node)); + } + @Override @LuaFunction(mainThread = true) public final MethodResult getAvailableItemStorage() { @@ -481,6 +521,14 @@ public final MethodResult getAvailableFluidStorage() { return MethodResult.of(AppEngApi.getAvailableFluidStorage(node)); } + @LuaFunction(mainThread = true) + public MethodResult getAvailableChemicalStorage() { + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(AppEngApi.getAvailableChemicalStorage(node)); + } + @Override @LuaFunction(mainThread = true) public final MethodResult craftItem(IComputerAccess computer, IArguments arguments) throws LuaException { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/MekanismCapabilities.java b/src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/MekanismCapabilities.java index 69371ca95..a61029c8f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/MekanismCapabilities.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/MekanismCapabilities.java @@ -1,6 +1,9 @@ package de.srendi.advancedperipherals.common.addons.mekanism; import mekanism.api.chemical.gas.IGasHandler; +import mekanism.api.chemical.infuse.IInfusionHandler; +import mekanism.api.chemical.pigment.IPigmentHandler; +import mekanism.api.chemical.slurry.ISlurryHandler; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.CapabilityToken; @@ -10,5 +13,12 @@ public class MekanismCapabilities { public static final Capability GAS_HANDLER = get(new CapabilityToken<>() { }); + public static final Capability SLURRY_HANDLER = get(new CapabilityToken<>() { + }); + public static final Capability PIGMENT_HANDLER = get(new CapabilityToken<>() { + }); + public static final Capability INFUSION_HANDLER = get(new CapabilityToken<>() { + }); + } From 8e30dd603a1c28509a763e82735cad6c479684dd Mon Sep 17 00:00:00 2001 From: Srendi Date: Thu, 21 Dec 2023 03:03:31 +0100 Subject: [PATCH 077/228] Some cleanup --- .../addons/appliedenergistics/AppEngApi.java | 8 +-- .../addons/mekanism/MekanismCapabilities.java | 9 --- .../inventory/IStorageSystemPeripheral.java | 56 +++++++++---------- 3 files changed, 29 insertions(+), 44 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java index a02672aae..fee44091c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java @@ -23,7 +23,6 @@ import dan200.computercraft.shared.util.NBTUtil; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.addons.APAddons; -import de.srendi.advancedperipherals.common.addons.mekanism.MekanismCapabilities; import de.srendi.advancedperipherals.common.util.LuaConverter; import de.srendi.advancedperipherals.common.util.Pair; import de.srendi.advancedperipherals.common.util.inventory.FluidFilter; @@ -35,11 +34,6 @@ import me.ramidzkh.mekae2.ae2.MekanismKey; import me.ramidzkh.mekae2.ae2.MekanismKeyType; import me.ramidzkh.mekae2.item.ChemicalStorageCell; -import mekanism.api.chemical.IChemicalHandler; -import mekanism.api.chemical.gas.IGasHandler; -import mekanism.api.chemical.infuse.IInfusionHandler; -import mekanism.api.chemical.pigment.IPigmentHandler; -import mekanism.api.chemical.slurry.ISlurryHandler; import mekanism.common.tile.TileEntityChemicalTank; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; @@ -746,7 +740,7 @@ public static long getUsedChemicalStorage(IGridNode node) { for (int i = 0; i < inventory.size(); i++) { ItemStack stack = inventory.getStackInSlot(i); - if (stack.getItem() instanceof ChemicalStorageCell ) { + if (stack.getItem() instanceof ChemicalStorageCell) { BasicCellInventory cellInventory = BasicCellHandler.INSTANCE.getCellInventory(stack, null); used = cellInventory.getUsedBytes() / MekanismKeyType.TYPE.getAmountPerByte(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/MekanismCapabilities.java b/src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/MekanismCapabilities.java index a61029c8f..858a11b3d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/MekanismCapabilities.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/MekanismCapabilities.java @@ -1,9 +1,6 @@ package de.srendi.advancedperipherals.common.addons.mekanism; import mekanism.api.chemical.gas.IGasHandler; -import mekanism.api.chemical.infuse.IInfusionHandler; -import mekanism.api.chemical.pigment.IPigmentHandler; -import mekanism.api.chemical.slurry.ISlurryHandler; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.CapabilityToken; @@ -13,12 +10,6 @@ public class MekanismCapabilities { public static final Capability GAS_HANDLER = get(new CapabilityToken<>() { }); - public static final Capability SLURRY_HANDLER = get(new CapabilityToken<>() { - }); - public static final Capability PIGMENT_HANDLER = get(new CapabilityToken<>() { - }); - public static final Capability INFUSION_HANDLER = get(new CapabilityToken<>() { - }); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java index fb4b0eba6..e4c721d30 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java @@ -29,94 +29,94 @@ public interface IStorageSystemPeripheral { MethodResult listFluids(); - + MethodResult listCraftableItems(); - + MethodResult listCraftableFluids(); MethodResult listCells(); - + MethodResult importItem(IComputerAccess computer, IArguments arguments) throws LuaException; - + MethodResult exportItem(IComputerAccess computer, IArguments arguments) throws LuaException; - + MethodResult importFluid(IComputerAccess computer, IArguments arguments) throws LuaException; - + MethodResult exportFluid(IComputerAccess computer, IArguments arguments) throws LuaException; - + MethodResult getFilteredPatterns(IArguments arguments) throws LuaException; - + MethodResult getPatterns(); - + MethodResult getStoredEnergy(); - + MethodResult getEnergyCapacity(); - + MethodResult getEnergyUsage(); MethodResult getAvgPowerInjection(); MethodResult getTotalExternItemStorage(); - + MethodResult getTotalExternFluidStorage(); - + MethodResult getTotalItemStorage(); - + MethodResult getTotalFluidStorage(); - + MethodResult getUsedExternItemStorage(); - + MethodResult getUsedExternFluidStorage(); - + MethodResult getUsedItemStorage(); - + MethodResult getUsedFluidStorage(); - + MethodResult getAvailableExternItemStorage(); - + MethodResult getAvailableExternFluidStorage(); - + MethodResult getAvailableItemStorage(); - + MethodResult getAvailableFluidStorage(); - + MethodResult craftItem(IComputerAccess computer, IArguments arguments) throws LuaException; - + MethodResult craftFluid(IComputerAccess computer, IArguments arguments) throws LuaException; - + MethodResult isItemCraftable(IArguments arguments) throws LuaException; - + MethodResult isItemCrafting(IArguments arguments) throws LuaException; - + MethodResult isFluidCraftable(IArguments arguments) throws LuaException; - + MethodResult isFluidCrafting(IArguments arguments) throws LuaException; } From 1f9d5da512eb2450e7174ca76767d25f52d2a09b Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 22 Dec 2023 19:34:11 +0100 Subject: [PATCH 078/228] [#539] Remove the external storage counters from the internal functions --- .../addons/appliedenergistics/AppEngApi.java | 37 ++++++++----------- .../peripheral/MeBridgePeripheral.java | 2 +- .../inventory/IStorageSystemPeripheral.java | 28 -------------- 3 files changed, 17 insertions(+), 50 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java index fee44091c..a022ee4c3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java @@ -34,6 +34,7 @@ import me.ramidzkh.mekae2.ae2.MekanismKey; import me.ramidzkh.mekae2.ae2.MekanismKeyType; import me.ramidzkh.mekae2.item.ChemicalStorageCell; +import mekanism.api.chemical.merged.MergedChemicalTank; import mekanism.common.tile.TileEntityChemicalTank; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; @@ -479,7 +480,8 @@ public static long getTotalExternalChemicalStorage(IGridNode node) { continue; if (connectedInventoryEntity instanceof TileEntityChemicalTank tank) { - total += tank.getChemicalTank().getTankFromCurrent(tank.getChemicalTank().getCurrent()).getCapacity(); + MergedChemicalTank.Current current = tank.getChemicalTank().getCurrent() == MergedChemicalTank.Current.EMPTY ? MergedChemicalTank.Current.GAS : tank.getChemicalTank().getCurrent(); + total += tank.getChemicalTank().getTankFromCurrent(current).getCapacity(); } } @@ -496,9 +498,8 @@ public static long getUsedExternalItemStorage(IGridNode node) { KeyCounter keyCounter = bus.getInternalHandler().getAvailableStacks(); for (Object2LongMap.Entry aeKey : keyCounter) { - if (aeKey.getKey() instanceof AEItemKey) { + if (aeKey.getKey() instanceof AEItemKey) used += aeKey.getLongValue(); - } } } @@ -513,9 +514,8 @@ public static long getUsedExternalFluidStorage(IGridNode node) { KeyCounter keyCounter = bus.getInternalHandler().getAvailableStacks(); for (Object2LongMap.Entry aeKey : keyCounter) { - if (aeKey.getKey() instanceof AEFluidKey) { + if (aeKey.getKey() instanceof AEFluidKey) used += aeKey.getLongValue(); - } } } @@ -525,14 +525,16 @@ public static long getUsedExternalFluidStorage(IGridNode node) { public static long getUsedExternalChemicalStorage(IGridNode node) { long used = 0; + if (!APAddons.appMekLoaded) + return 0; + for (IGridNode iGridNode : node.getGrid().getMachineNodes(StorageBusPart.class)) { StorageBusPart bus = (StorageBusPart) iGridNode.getService(IStorageProvider.class); KeyCounter keyCounter = bus.getInternalHandler().getAvailableStacks(); for (Object2LongMap.Entry aeKey : keyCounter) { - if (aeKey.getKey() instanceof MekanismKey) { + if (aeKey.getKey() instanceof MekanismKey) used += aeKey.getLongValue(); - } } } @@ -571,9 +573,6 @@ public static long getTotalItemStorage(IGridNode node) { } } } - - total += getTotalExternalItemStorage(node); - return total; } @@ -603,14 +602,15 @@ public static long getTotalFluidStorage(IGridNode node) { } } - total += getTotalExternalFluidStorage(node); - return total; } public static long getTotalChemicalStorage(IGridNode node) { long total = 0; + if (!APAddons.appMekLoaded) + return 0; + for (IGridNode iGridNode : node.getGrid().getMachineNodes(DriveBlockEntity.class)) { DriveBlockEntity entity = (DriveBlockEntity) iGridNode.getService(IStorageProvider.class); if (entity == null) @@ -626,14 +626,12 @@ public static long getTotalChemicalStorage(IGridNode node) { if (stack.getItem() instanceof ChemicalStorageCell cell) { if (cell.getKeyType() instanceof MekanismKeyType) { - total += (long) cell.getBytes(null) * MekanismKeyType.TYPE.getAmountPerByte(); + total += cell.getBytes(null); } } } } - total += getTotalExternalChemicalStorage(node); - return total; } @@ -683,8 +681,6 @@ public static long getUsedItemStorage(IGridNode node) { } } - used += getUsedExternalItemStorage(node); - return used; } @@ -722,14 +718,15 @@ public static long getUsedFluidStorage(IGridNode node) { } } - used += getUsedExternalFluidStorage(node); - return used; } public static long getUsedChemicalStorage(IGridNode node) { long used = 0; + if (!APAddons.appMekLoaded) + return 0; + for (IGridNode iGridNode : node.getGrid().getMachineNodes(DriveBlockEntity.class)) { DriveBlockEntity entity = (DriveBlockEntity) iGridNode.getService(IStorageProvider.class); if (entity == null) @@ -748,8 +745,6 @@ public static long getUsedChemicalStorage(IGridNode node) { } } - used += getUsedExternalChemicalStorage(node); - return used; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java index 7fa4928a8..2eda0ef9a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java @@ -431,7 +431,7 @@ public MethodResult getUsedExternItemStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(AppEngApi.getUsedExternalFluidStorage(node)); + return MethodResult.of(AppEngApi.getUsedExternalItemStorage(node)); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java index e4c721d30..3bc4622ef 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java @@ -29,94 +29,66 @@ public interface IStorageSystemPeripheral { MethodResult listFluids(); - MethodResult listCraftableItems(); - MethodResult listCraftableFluids(); MethodResult listCells(); - MethodResult importItem(IComputerAccess computer, IArguments arguments) throws LuaException; - MethodResult exportItem(IComputerAccess computer, IArguments arguments) throws LuaException; - MethodResult importFluid(IComputerAccess computer, IArguments arguments) throws LuaException; - MethodResult exportFluid(IComputerAccess computer, IArguments arguments) throws LuaException; - MethodResult getFilteredPatterns(IArguments arguments) throws LuaException; - MethodResult getPatterns(); - MethodResult getStoredEnergy(); - MethodResult getEnergyCapacity(); - MethodResult getEnergyUsage(); MethodResult getAvgPowerInjection(); MethodResult getTotalExternItemStorage(); - MethodResult getTotalExternFluidStorage(); - MethodResult getTotalItemStorage(); - MethodResult getTotalFluidStorage(); - MethodResult getUsedExternItemStorage(); - MethodResult getUsedExternFluidStorage(); - MethodResult getUsedItemStorage(); - MethodResult getUsedFluidStorage(); - MethodResult getAvailableExternItemStorage(); - MethodResult getAvailableExternFluidStorage(); - MethodResult getAvailableItemStorage(); - MethodResult getAvailableFluidStorage(); - MethodResult craftItem(IComputerAccess computer, IArguments arguments) throws LuaException; - MethodResult craftFluid(IComputerAccess computer, IArguments arguments) throws LuaException; - MethodResult isItemCraftable(IArguments arguments) throws LuaException; - MethodResult isItemCrafting(IArguments arguments) throws LuaException; - MethodResult isFluidCraftable(IArguments arguments) throws LuaException; - MethodResult isFluidCrafting(IArguments arguments) throws LuaException; } From 5bfe290140d006fc04c7ae2d7dc47340b3f35419 Mon Sep 17 00:00:00 2001 From: Srendi Date: Sun, 24 Dec 2023 05:18:04 +0100 Subject: [PATCH 079/228] Add Drives and Cells support to the ME Bridge --- gradle.properties | 2 +- .../addons/appliedenergistics/AppEngApi.java | 86 ++++++++++++++----- .../peripheral/MeBridgePeripheral.java | 9 ++ .../peripheral/RsBridgePeripheral.java | 84 ++++++++++++++---- .../inventory/IStorageSystemPeripheral.java | 2 + 5 files changed, 143 insertions(+), 40 deletions(-) diff --git a/gradle.properties b/gradle.properties index 40a8d0c28..200bd3808 100644 --- a/gradle.properties +++ b/gradle.properties @@ -26,7 +26,7 @@ curios_version=1.19.2-5.1.4.1 minecolonies_version=1.19.2-1.1.36-BETA appliedenergistics_version=12.9.5 patchouli_version=1.19.2-77 -refinedstorage_version=1.11.6 +refinedstorage_version=1.11.7 botania_version=1.19.2-440-FORGE create_version=0.5.1.b-30 mekanism_version=1.19.2-10.3.9.13 diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java index a022ee4c3..4f72fd740 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java @@ -220,6 +220,22 @@ public static List listPatterns(IGrid grid, Level level) { return getPatterns(grid, level).stream().map(AppEngApi::getObjectFromPattern).collect(Collectors.toList()); } + public static List listDrives(IGrid grid) { + List drives = new ArrayList<>(); + + for(IGridNode node : grid.getMachineNodes(DriveBlockEntity.class)) { + DriveBlockEntity drive = (DriveBlockEntity) node.getService(IStorageProvider.class); + + // A normal drive has a cellCount of 10 + if(drive == null || drive.getCellCount() != 10) + continue; + + drives.add(getObjectFromDrive(drive)); + } + + return drives; + } + private static Class tryCastMachineToContainer(Class machineClass) { if (PatternContainer.class.isAssignableFrom(machineClass)) { return machineClass.asSubclass(PatternContainer.class); @@ -241,6 +257,56 @@ public static Map getObjectFromStack(Pair getObjectFromDrive(DriveBlockEntity drive) { + Map map = new HashMap<>(); + + map.put("powered", drive.isPowered()); + + if(drive.getCellCount() != 10) + return map; + + List driveCells = new ArrayList<>(); + for (ItemStack item : drive.getInternalInventory()) { + if (item.getItem() instanceof BasicStorageCell cell) { + driveCells.add(getObjectFromCell(cell, item)); + } + } + + map.put("cells", driveCells); + map.put("priority", drive.getPriority()); + map.put("menuIcon", LuaConverter.itemToObject(drive.getMainMenuIcon().getItem())); + map.put("position", LuaConverter.posToObject(drive.getBlockPos())); + map.put("name", drive.getCustomInventoryName().getString()); + + return map; + } + + public static Map getObjectFromCell(BasicStorageCell cell, ItemStack cellItem) { + Map map = new HashMap<>(); + + map.put("item", LuaConverter.itemToObject(cellItem.getItem())); + map.put("type", cell.getKeyType().toString()); + map.put("bytes", cell.getBytes(cellItem)); + long numItemsInCell = cellItem.getTag().getLong("ic"); + + if (cellItem.getTag().contains("amts")) { + int bytesPerType = cell.getBytesPerType(null); + + int numOfType = cellItem.getTag().getLongArray("amts").length; + + map.put("bytesPerType", bytesPerType); + map.put("usedBytes", ((int) Math.ceil(((double) numItemsInCell) / 8)) + ((long) bytesPerType * numOfType)); + + } else { + map.put("usedBytes", numItemsInCell); + } + + map.put("totalTypes", cell.getTotalTypes(cellItem)); + map.put("fuzzyMode", cell.getFuzzyMode(cellItem)); + + return map; + } + private static Map getObjectFromItemStack(Pair stack, @Nullable ICraftingService craftingService) { Map map = new HashMap<>(); String displayName = stack.getRight().getDisplayName().getString(); @@ -832,26 +898,6 @@ public static List listCells(IGridNode node) { return items; } - private static Map getObjectFromCell(BasicStorageCell cell, ItemStack stack) { - Map map = new HashMap<>(); - - map.put("item", ItemUtil.getRegistryKey(stack.getItem()).toString()); - - String cellType = ""; - - if (cell.getKeyType().getClass().isAssignableFrom(AEKeyType.items().getClass())) { - cellType = "item"; - } else if (cell.getKeyType().getClass().isAssignableFrom(AEKeyType.fluids().getClass())) { - cellType = "fluid"; - } - - map.put("cellType", cellType); - map.put("bytesPerType", cell.getBytesPerType(null)); - map.put("totalBytes", cell.getBytes(null)); - - return map; - } - private static Map getObjectFromDisk(DISKDrive drive, ItemStack stack) { Map map = new HashMap<>(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java index 2eda0ef9a..272e79d47 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java @@ -243,6 +243,15 @@ public final MethodResult listCells() { return MethodResult.of(AppEngApi.listCells(node)); } + @Override + @LuaFunction(mainThread = true) + public MethodResult listDrives() { + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(AppEngApi.listDrives(node.getGrid())); + } + @Override @LuaFunction(mainThread = true) public final MethodResult importItem(IComputerAccess computer, IArguments arguments) throws LuaException { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java index a3447db34..35f54aef7 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java @@ -6,6 +6,7 @@ import com.refinedmods.refinedstorage.api.network.INetwork; import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.LuaException; +import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.lua.MethodResult; import dan200.computercraft.api.peripheral.IComputerAccess; import dan200.computercraft.core.computer.ComputerSide; @@ -57,22 +58,26 @@ private boolean isAvailable() { } @Override + public boolean isEnabled() { + return APConfig.PERIPHERALS_CONFIG.enableRSBridge.get(); + } + + @Override + @LuaFunction(mainThread = true) public final MethodResult isConnected() { return MethodResult.of(isAvailable()); } @Override - public MethodResult isOnline() { + @LuaFunction(mainThread = true) + public final MethodResult isOnline() { // Is there a more proper method? return MethodResult.of(getNode().isActive()); } - @Override - public boolean isEnabled() { - return APConfig.PERIPHERALS_CONFIG.enableRSBridge.get(); - } @Override + @LuaFunction(mainThread = true) public final MethodResult listItems() { if (!isAvailable()) return notConnected(); @@ -81,6 +86,7 @@ public final MethodResult listItems() { } @Override + @LuaFunction(mainThread = true) public final MethodResult listCraftableItems() { if (!isAvailable()) return notConnected(); @@ -91,6 +97,7 @@ public final MethodResult listCraftableItems() { } @Override + @LuaFunction(mainThread = true) public final MethodResult listCraftableFluids() { if (!isAvailable()) return notConnected(); @@ -101,11 +108,19 @@ public final MethodResult listCraftableFluids() { } @Override - public MethodResult listCells() { + @LuaFunction(mainThread = true) + public final MethodResult listCells() { return null; } @Override + @LuaFunction(mainThread = true) + public final MethodResult listDrives() { + return null; + } + + @Override + @LuaFunction(mainThread = true) public final MethodResult getTotalItemStorage() { if (!isAvailable()) return notConnected(); @@ -114,6 +129,7 @@ public final MethodResult getTotalItemStorage() { } @Override + @LuaFunction(mainThread = true) public final MethodResult getTotalFluidStorage() { if (!isAvailable()) return notConnected(); @@ -122,46 +138,55 @@ public final MethodResult getTotalFluidStorage() { } @Override - public MethodResult getUsedExternItemStorage() { + @LuaFunction(mainThread = true) + public final MethodResult getUsedExternItemStorage() { return null; } @Override - public MethodResult getUsedExternFluidStorage() { + @LuaFunction(mainThread = true) + public final MethodResult getUsedExternFluidStorage() { return null; } @Override - public MethodResult getUsedItemStorage() { + @LuaFunction(mainThread = true) + public final MethodResult getUsedItemStorage() { return null; } @Override - public MethodResult getUsedFluidStorage() { + @LuaFunction(mainThread = true) + public final MethodResult getUsedFluidStorage() { return null; } @Override - public MethodResult getAvailableExternItemStorage() { + @LuaFunction(mainThread = true) + public final MethodResult getAvailableExternItemStorage() { return null; } @Override - public MethodResult getAvailableExternFluidStorage() { + @LuaFunction(mainThread = true) + public final MethodResult getAvailableExternFluidStorage() { return null; } @Override - public MethodResult getAvailableItemStorage() { + @LuaFunction(mainThread = true) + public final MethodResult getAvailableItemStorage() { return null; } @Override - public MethodResult getAvailableFluidStorage() { + @LuaFunction(mainThread = true) + public final MethodResult getAvailableFluidStorage() { return null; } @Override + @LuaFunction(mainThread = true) public final MethodResult getTotalExternItemStorage() { if (!isAvailable()) return notConnected(); @@ -170,6 +195,7 @@ public final MethodResult getTotalExternItemStorage() { } @Override + @LuaFunction(mainThread = true) public final MethodResult getTotalExternFluidStorage() { if (!isAvailable()) return notConnected(); @@ -178,6 +204,7 @@ public final MethodResult getTotalExternFluidStorage() { } @Override + @LuaFunction(mainThread = true) public final MethodResult listFluids() { if (!isAvailable()) return notConnected(); @@ -186,6 +213,7 @@ public final MethodResult listFluids() { } @Override + @LuaFunction(mainThread = true) public final MethodResult getEnergyUsage() { if (!isAvailable()) return notConnected(); @@ -194,6 +222,7 @@ public final MethodResult getEnergyUsage() { } @Override + @LuaFunction(mainThread = true) public final MethodResult getEnergyCapacity() { if (!isAvailable()) return notConnected(); @@ -202,6 +231,7 @@ public final MethodResult getEnergyCapacity() { } @Override + @LuaFunction(mainThread = true) public final MethodResult getStoredEnergy() { if (!isAvailable()) return notConnected(); @@ -210,11 +240,13 @@ public final MethodResult getStoredEnergy() { } @Override - public MethodResult getAvgPowerInjection() { + @LuaFunction(mainThread = true) + public final MethodResult getAvgPowerInjection() { return null; } @Override + @LuaFunction(mainThread = true) public final MethodResult getFilteredPatterns(IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -233,7 +265,8 @@ public final MethodResult getFilteredPatterns(IArguments arguments) throws LuaEx } @Override - public MethodResult getPatterns() { + @LuaFunction(mainThread = true) + public final MethodResult getPatterns() { return null; } @@ -286,6 +319,7 @@ protected MethodResult importToSystem(@NotNull IArguments arguments, @Nullable I } @Override + @LuaFunction(mainThread = true) public final MethodResult exportItem(IComputerAccess computer, IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -303,6 +337,7 @@ public final MethodResult exportItem(IComputerAccess computer, IArguments argume } @Override + @LuaFunction(mainThread = true) public final MethodResult importItem(IComputerAccess computer, IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -320,6 +355,7 @@ public final MethodResult importItem(IComputerAccess computer, IArguments argume } @Override + @LuaFunction(mainThread = true) public final MethodResult exportFluid(IComputerAccess computer, IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -340,6 +376,7 @@ public final MethodResult exportFluid(IComputerAccess computer, IArguments argum } @Override + @LuaFunction(mainThread = true) public final MethodResult importFluid(IComputerAccess computer, IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -358,7 +395,9 @@ public final MethodResult importFluid(IComputerAccess computer, IArguments argum return importToSystem(arguments, fluidHandler); } + @Override + @LuaFunction(mainThread = true) public final MethodResult getItem(IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -371,11 +410,13 @@ public final MethodResult getItem(IArguments arguments) throws LuaException { } @Override - public MethodResult getFluid(IArguments arguments) throws LuaException { + @LuaFunction(mainThread = true) + public final MethodResult getFluid(IArguments arguments) throws LuaException { return null; } @Override + @LuaFunction(mainThread = true) public final MethodResult craftItem(IComputerAccess computerAccess, IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -398,6 +439,7 @@ public final MethodResult craftItem(IComputerAccess computerAccess, IArguments a } @Override + @LuaFunction(mainThread = true) public final MethodResult craftFluid(IComputerAccess computerAccess, IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -419,6 +461,7 @@ public final MethodResult craftFluid(IComputerAccess computerAccess, IArguments } @Override + @LuaFunction(mainThread = true) public final MethodResult isItemCrafting(IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -439,16 +482,19 @@ public final MethodResult isItemCrafting(IArguments arguments) throws LuaExcepti } @Override - public MethodResult isFluidCraftable(IArguments arguments) throws LuaException { + @LuaFunction(mainThread = true) + public final MethodResult isFluidCraftable(IArguments arguments) throws LuaException { return null; } @Override - public MethodResult isFluidCrafting(IArguments arguments) throws LuaException { + @LuaFunction(mainThread = true) + public final MethodResult isFluidCrafting(IArguments arguments) throws LuaException { return null; } @Override + @LuaFunction(mainThread = true) public final MethodResult isItemCraftable(IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java index 3bc4622ef..3cb8cf3e9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java @@ -35,6 +35,8 @@ public interface IStorageSystemPeripheral { MethodResult listCells(); + MethodResult listDrives(); + MethodResult importItem(IComputerAccess computer, IArguments arguments) throws LuaException; MethodResult exportItem(IComputerAccess computer, IArguments arguments) throws LuaException; From ab7cdd81bda2142dfe82d64e0908375c09f15118 Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 25 Dec 2023 00:39:34 +0100 Subject: [PATCH 080/228] use the BasicCellInventory class instead of trying to get the information we need out of the item tag. Add a `usedBytes` and `totalBytes` field to the drive's object --- .../addons/appliedenergistics/AppEngApi.java | 54 ++++++++----------- 1 file changed, 21 insertions(+), 33 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java index 4f72fd740..fb98f2337 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java @@ -223,11 +223,11 @@ public static List listPatterns(IGrid grid, Level level) { public static List listDrives(IGrid grid) { List drives = new ArrayList<>(); - for(IGridNode node : grid.getMachineNodes(DriveBlockEntity.class)) { + for (IGridNode node : grid.getMachineNodes(DriveBlockEntity.class)) { DriveBlockEntity drive = (DriveBlockEntity) node.getService(IStorageProvider.class); // A normal drive has a cellCount of 10 - if(drive == null || drive.getCellCount() != 10) + if (drive == null || drive.getCellCount() != 10) continue; drives.add(getObjectFromDrive(drive)); @@ -237,9 +237,9 @@ public static List listDrives(IGrid grid) { } private static Class tryCastMachineToContainer(Class machineClass) { - if (PatternContainer.class.isAssignableFrom(machineClass)) { + if (PatternContainer.class.isAssignableFrom(machineClass)) return machineClass.asSubclass(PatternContainer.class); - } + return null; } @@ -262,16 +262,25 @@ public static Map getObjectFromDrive(DriveBlockEntity drive) { map.put("powered", drive.isPowered()); - if(drive.getCellCount() != 10) + long totalBytes = 0; + long usedBytes = 0; + + if (drive.getCellCount() != 10) return map; List driveCells = new ArrayList<>(); for (ItemStack item : drive.getInternalInventory()) { if (item.getItem() instanceof BasicStorageCell cell) { + BasicCellInventory cellInventory = BasicCellHandler.INSTANCE.getCellInventory(item, null); + totalBytes += cellInventory.getTotalBytes(); + usedBytes += cellInventory.getUsedBytes(); + driveCells.add(getObjectFromCell(cell, item)); } } + map.put("usedBytes", usedBytes); + map.put("totalBytes", totalBytes); map.put("cells", driveCells); map.put("priority", drive.getPriority()); map.put("menuIcon", LuaConverter.itemToObject(drive.getMainMenuIcon().getItem())); @@ -283,24 +292,13 @@ public static Map getObjectFromDrive(DriveBlockEntity drive) { public static Map getObjectFromCell(BasicStorageCell cell, ItemStack cellItem) { Map map = new HashMap<>(); + BasicCellInventory cellInventory = BasicCellHandler.INSTANCE.getCellInventory(cellItem, null); map.put("item", LuaConverter.itemToObject(cellItem.getItem())); map.put("type", cell.getKeyType().toString()); map.put("bytes", cell.getBytes(cellItem)); - long numItemsInCell = cellItem.getTag().getLong("ic"); - - if (cellItem.getTag().contains("amts")) { - int bytesPerType = cell.getBytesPerType(null); - - int numOfType = cellItem.getTag().getLongArray("amts").length; - - map.put("bytesPerType", bytesPerType); - map.put("usedBytes", ((int) Math.ceil(((double) numItemsInCell) / 8)) + ((long) bytesPerType * numOfType)); - - } else { - map.put("usedBytes", numItemsInCell); - } - + map.put("bytesPerType", cell.getBytesPerType(cellItem)); + map.put("usedBytes", cellInventory.getUsedBytes()); map.put("totalTypes", cell.getTotalTypes(cellItem)); map.put("fuzzyMode", cell.getFuzzyMode(cellItem)); @@ -720,15 +718,10 @@ public static long getUsedItemStorage(IGridNode node) { continue; if (stack.getItem() instanceof BasicStorageCell cell) { - int bytesPerType = cell.getBytesPerType(null); - if (cell.getKeyType().getClass().isAssignableFrom(AEKeyType.items().getClass())) { - if (stack.getTag() == null) - continue; - int numOfType = stack.getTag().getLongArray("amts").length; - long numItemsInCell = stack.getTag().getLong("ic"); + BasicCellInventory cellInventory = BasicCellHandler.INSTANCE.getCellInventory(stack, null); - used += ((int) Math.ceil(((double) numItemsInCell) / 8)) + ((long) bytesPerType * numOfType); + used += cellInventory.getUsedBytes(); } } else if (APAddons.aeThingsLoaded && stack.getItem() instanceof DISKDrive disk) { if (disk.getKeyType().toString().equals("ae2:i")) { @@ -764,15 +757,10 @@ public static long getUsedFluidStorage(IGridNode node) { ItemStack stack = inventory.getStackInSlot(i); if (stack.getItem() instanceof BasicStorageCell cell) { - int bytesPerType = cell.getBytesPerType(null); - if (cell.getKeyType().getClass().isAssignableFrom(AEKeyType.fluids().getClass())) { - if (stack.getTag() == null) - continue; - int numOfType = stack.getTag().getLongArray("amts").length; - long numBucketsInCell = stack.getTag().getLong("ic") / 1000; + BasicCellInventory cellInventory = BasicCellHandler.INSTANCE.getCellInventory(stack, null); - used += ((int) Math.ceil(((double) numBucketsInCell) / 8)) + ((long) bytesPerType * numOfType); + used += cellInventory.getUsedBytes(); } } else if (APAddons.aeAdditionsLoaded && stack.getItem() instanceof SuperStorageCell superStorageCell) { if (stack.getTag() == null) From a36cbad836f62aeeedc2eb0f2f493e07765de972 Mon Sep 17 00:00:00 2001 From: Srendi Date: Tue, 26 Dec 2023 02:54:21 +0100 Subject: [PATCH 081/228] [#51] Start an implementation for `getCraftingTasks` and `cancelCraftingTasks` --- .../computercraft/peripheral/MeBridgePeripheral.java | 10 ++++++++++ .../computercraft/peripheral/RsBridgePeripheral.java | 10 ++++++++++ .../util/inventory/IStorageSystemPeripheral.java | 4 ++++ 3 files changed, 24 insertions(+) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java index 272e79d47..7b7c8e5c5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java @@ -598,6 +598,16 @@ public final MethodResult craftFluid(IComputerAccess computer, IArguments argume return MethodResult.of(true); } + @Override + public MethodResult getCraftingTasks() { + return null; + } + + @Override + public MethodResult cancelCraftingTasks(IArguments arguments) throws LuaException { + return null; + } + @Override @LuaFunction(mainThread = true) public final MethodResult isItemCraftable(IArguments arguments) throws LuaException { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java index 35f54aef7..b1a3c6606 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java @@ -460,6 +460,16 @@ public final MethodResult craftFluid(IComputerAccess computerAccess, IArguments return MethodResult.of(type == CalculationResultType.OK); } + @Override + public MethodResult getCraftingTasks() { + return null; + } + + @Override + public MethodResult cancelCraftingTasks(IArguments arguments) throws LuaException { + return null; + } + @Override @LuaFunction(mainThread = true) public final MethodResult isItemCrafting(IArguments arguments) throws LuaException { diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java index 3cb8cf3e9..39b4fd114 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java @@ -83,6 +83,10 @@ public interface IStorageSystemPeripheral { MethodResult craftItem(IComputerAccess computer, IArguments arguments) throws LuaException; + MethodResult getCraftingTasks(); + + MethodResult cancelCraftingTasks(IArguments arguments) throws LuaException; + MethodResult craftFluid(IComputerAccess computer, IArguments arguments) throws LuaException; MethodResult isItemCraftable(IArguments arguments) throws LuaException; From ff2c69eabb8ac813de1e381b997a4430a2eb7020 Mon Sep 17 00:00:00 2001 From: Einhornyordle Date: Thu, 21 Dec 2023 23:09:06 +0100 Subject: [PATCH 082/228] Set lua function to use the main tread. --- .../dimstorage/DimChestIntegration.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/addons/dimstorage/DimChestIntegration.java diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/dimstorage/DimChestIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/dimstorage/DimChestIntegration.java new file mode 100644 index 000000000..037775037 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/dimstorage/DimChestIntegration.java @@ -0,0 +1,55 @@ +package de.srendi.advancedperipherals.common.addons.dimstorage; + +import dan200.computercraft.api.lua.LuaFunction; +import de.srendi.advancedperipherals.lib.peripherals.BlockEntityIntegrationPeripheral; +import edivad.dimstorage.api.Frequency; +import edivad.dimstorage.blockentities.BlockEntityDimChest; +import net.minecraft.world.level.block.entity.BlockEntity; +import org.jetbrains.annotations.NotNull; + +import java.util.UUID; + +public class DimChestIntegration extends BlockEntityIntegrationPeripheral { + + protected DimChestIntegration(BlockEntity entity) { + super(entity); + } + + @NotNull + @Override + public String getType() { + return "dimChest"; + } + + @LuaFunction(mainThread = true) + public final String getOwnerUUID() { + UUID uuid = blockEntity.getFrequency().getOwnerUUID(); + if (uuid == null) + return null; + return uuid.toString(); + } + + @LuaFunction(mainThread = true) + public final String getOwner() { + return blockEntity.getFrequency().getOwner(); + } + + @LuaFunction(mainThread = true) + public final boolean hasOwner() { + return blockEntity.getFrequency().hasOwner(); + } + + @LuaFunction(mainThread = true) + public final int getChannel() { + return blockEntity.getFrequency().getChannel(); + } + + @LuaFunction(mainThread = true) + public final boolean setChannel(int channel) { + Frequency fre = blockEntity.getFrequency(); + if (fre.hasOwner()) return false; + fre.setChannel(channel); + blockEntity.setFrequency(fre); + return true; + } +} From e031f32579c576f7895272a142ca8b323152dd07 Mon Sep 17 00:00:00 2001 From: Einhornyordle Date: Thu, 21 Dec 2023 22:43:27 +0100 Subject: [PATCH 083/228] Add peripheral functions for the Dim Chest of the Dimensional Storage mod. Also add Jade for better testing purposes. --- build.gradle | 8 ++++++++ gradle.properties | 9 +++++++-- .../integrations/IntegrationPeripheralProvider.java | 2 +- .../common/addons/dimstorage/Integration.java | 12 ++++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/addons/dimstorage/Integration.java diff --git a/build.gradle b/build.gradle index 60470604c..a65a67f4b 100644 --- a/build.gradle +++ b/build.gradle @@ -314,6 +314,12 @@ dependencies { // Create compileOnly fg.deobf("com.simibubi.create:create-${minecraft_version}:${create_version}:all") + //DimStorage + compileOnly fg.deobf("curse.maven:dimstorage-353882:${dimstorage_version}") + runtimeOnly fg.deobf("curse.maven:dimstorage-353882:${dimstorage_version}") + compileOnly fg.deobf("curse.maven:edivadlib-638508:${edivadlib_version}") + runtimeOnly fg.deobf("curse.maven:edivadlib-638508:${edivadlib_version}") + //Removed until fully ported //testImplementation fg.deobf("site.siredvin.ttoolkit:ttoolkit-${minecraft_version}:${ttoolkit_version}") @@ -335,6 +341,8 @@ dependencies { // Testing stuff // JEI compileOnly fg.deobf("mezz.jei:jei-${jei_version}") + // Jade + implementation fg.deobf("curse.maven:jade-324717:${jade_version}") } diff --git a/gradle.properties b/gradle.properties index 200bd3808..dba25c430 100644 --- a/gradle.properties +++ b/gradle.properties @@ -24,7 +24,7 @@ ttoolkit_version=0.1.3 cc_version=1.101.3 curios_version=1.19.2-5.1.4.1 minecolonies_version=1.19.2-1.1.36-BETA -appliedenergistics_version=12.9.5 +appliedenergistics_version=12.9.8 patchouli_version=1.19.2-77 refinedstorage_version=1.11.7 botania_version=1.19.2-440-FORGE @@ -35,6 +35,7 @@ powah_version=4183078 ae2additions_version=4646599 kotlinforforge_version=3.12.0 appliedmekanistics_version=4734608 +dimstorage_version=3927875 # Mod dependencies which are needed for other mods # For minecolonies @@ -43,5 +44,9 @@ domumornamentum_version=1.19-1.0.83-ALPHA blockui_version=1.19-0.0.69-ALPHA multipiston_version=1.19.2-1.2.21-ALPHA +# For DimStorage +edivadlib_version=3927847 + # Mod dependencies for testing stuff(Only used in the dev environment) -jei_version=1.19.2-forge:11.6.0.1016 \ No newline at end of file +jei_version=1.19.2-forge:11.6.0.1016 +jade_version=4914105 \ No newline at end of file diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/IntegrationPeripheralProvider.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/IntegrationPeripheralProvider.java index f5c2fef95..2d9ccb553 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/IntegrationPeripheralProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/IntegrationPeripheralProvider.java @@ -23,7 +23,7 @@ public class IntegrationPeripheralProvider implements IPeripheralProvider { - private static final String[] SUPPORTED_MODS = new String[]{"botania", "create", "mekanism", "powah"}; + private static final String[] SUPPORTED_MODS = new String[]{"botania", "create", "mekanism", "powah", "dimstorage"}; private static final PriorityQueue integrations = new PriorityQueue<>(Comparator.comparingInt(IPeripheralIntegration::getPriority)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/dimstorage/Integration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/dimstorage/Integration.java new file mode 100644 index 000000000..a74e46b62 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/dimstorage/Integration.java @@ -0,0 +1,12 @@ +package de.srendi.advancedperipherals.common.addons.dimstorage; + +import de.srendi.advancedperipherals.common.addons.computercraft.integrations.IntegrationPeripheralProvider; +import edivad.dimstorage.blockentities.BlockEntityDimChest; + +public class Integration implements Runnable { + + @Override + public void run() { + IntegrationPeripheralProvider.registerBlockEntityIntegration(DimChestIntegration::new, BlockEntityDimChest.class); + } +} From 491b3dacbf4f39c38ae5adb2da29a047ce32c9e8 Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 15 Jan 2024 19:28:50 +0100 Subject: [PATCH 084/228] Implement prototype of `cancelCraftingTasks` to the ME Bridge --- gradle.properties | 2 +- .../client/ItemPropertiesRegistry.java | 1 - .../addons/appliedenergistics/AppEngApi.java | 32 +++++++-- .../peripheral/MeBridgePeripheral.java | 69 ++++++++++++------- 4 files changed, 72 insertions(+), 32 deletions(-) diff --git a/gradle.properties b/gradle.properties index 200bd3808..f9453ca92 100644 --- a/gradle.properties +++ b/gradle.properties @@ -24,7 +24,7 @@ ttoolkit_version=0.1.3 cc_version=1.101.3 curios_version=1.19.2-5.1.4.1 minecolonies_version=1.19.2-1.1.36-BETA -appliedenergistics_version=12.9.5 +appliedenergistics_version=12.9.8 patchouli_version=1.19.2-77 refinedstorage_version=1.11.7 botania_version=1.19.2-440-FORGE diff --git a/src/main/java/de/srendi/advancedperipherals/client/ItemPropertiesRegistry.java b/src/main/java/de/srendi/advancedperipherals/client/ItemPropertiesRegistry.java index 7fa4aa3b7..00ef43539 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/ItemPropertiesRegistry.java +++ b/src/main/java/de/srendi/advancedperipherals/client/ItemPropertiesRegistry.java @@ -10,7 +10,6 @@ public class ItemPropertiesRegistry { public static void register() { ItemProperties.register(APItems.MEMORY_CARD.get(), new ResourceLocation(AdvancedPeripherals.MOD_ID, "bounded"), (stack, level, entity, seed) -> { boolean bounded = stack.getOrCreateTag().contains("owner"); - return bounded ? 1 : 0; }); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java index fb98f2337..e5adec170 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java @@ -149,6 +149,7 @@ public static Pair findPatternFromFilters(IGrid grid, L return Pair.of(null, "NO_PATTERN_FOUND"); } + public static List listStacks(MEStorage monitor, ICraftingService service, int flag) { List items = new ArrayList<>(); KeyCounter keyCounter = monitor.getAvailableStacks(); @@ -300,7 +301,7 @@ public static Map getObjectFromCell(BasicStorageCell cell, ItemS map.put("bytesPerType", cell.getBytesPerType(cellItem)); map.put("usedBytes", cellInventory.getUsedBytes()); map.put("totalTypes", cell.getTotalTypes(cellItem)); - map.put("fuzzyMode", cell.getFuzzyMode(cellItem)); + map.put("fuzzyMode", cell.getFuzzyMode(cellItem).toString()); return map; } @@ -364,7 +365,7 @@ public static Map getObjectFromPatternInput(IPatternDetails.IInp return map; } - public static Map getObjectFromCPU(ICraftingCPU cpu) { + public static Map getObjectFromCPU(ICraftingCPU cpu, boolean recursive) { Map map = new HashMap<>(); long storage = cpu.getAvailableStorage(); int coProcessors = cpu.getCoProcessors(); @@ -372,18 +373,22 @@ public static Map getObjectFromCPU(ICraftingCPU cpu) { map.put("storage", storage); map.put("coProcessors", coProcessors); map.put("isBusy", isBusy); - map.put("craftingJob", cpu.getJobStatus() != null ? getObjectFromJob(cpu.getJobStatus()) : null); + if (!recursive) + map.put("craftingJob", cpu.getJobStatus() != null ? getObjectFromJob(cpu.getJobStatus(), null) : null); map.put("name", cpu.getName() != null ? cpu.getName().getString() : "Unnamed"); return map; } - public static Map getObjectFromJob(CraftingJobStatus job) { + public static Map getObjectFromJob(CraftingJobStatus job, @Nullable ICraftingCPU cpu) { Map map = new HashMap<>(); map.put("storage", getObjectFromGenericStack(job.crafting())); map.put("elapsedTimeNanos", job.elapsedTimeNanos()); map.put("totalItem", job.totalItems()); map.put("progress", job.progress()); + if (cpu != null) + map.put("cpu", getObjectFromCPU(cpu, true)); + return map; } @@ -854,6 +859,25 @@ public static long getAvailableExternalChemicalStorage(IGridNode node) { return getTotalExternalChemicalStorage(node) - getUsedExternalChemicalStorage(node); } + public static ICraftingCPU getCraftingCPU(IGridNode node, String cpuName) { + if (cpuName.isEmpty()) return null; + ICraftingService grid = node.getGrid().getService(ICraftingService.class); + if (grid == null) return null; + + Iterator iterator = grid.getCpus().iterator(); + if (!iterator.hasNext()) return null; + + while (iterator.hasNext()) { + ICraftingCPU cpu = iterator.next(); + + if (cpu.getName() != null && cpu.getName().getString().equals(cpuName)) { + return cpu; + } + } + + return null; + } + public static List listCells(IGridNode node) { List items = new ArrayList<>(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java index 7b7c8e5c5..98992cb0d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java @@ -288,7 +288,6 @@ public final MethodResult exportItem(IComputerAccess computer, @NotNull IArgumen return exportToChest(arguments, inventory); } - //TODO: How do we want to filter? By inputs or outputs, or maybe both? What if there are multiple patterns with the same output/input @Override @LuaFunction(mainThread = true) public MethodResult getFilteredPatterns(IArguments arguments) throws LuaException { @@ -553,7 +552,7 @@ public final MethodResult craftItem(IComputerAccess computer, IArguments argumen return MethodResult.of(false, "EMPTY_FILTER"); String cpuName = arguments.optString(1, ""); - ICraftingCPU target = getCraftingCPU(cpuName); + ICraftingCPU target = AppEngApi.getCraftingCPU(node, cpuName); if (!cpuName.isEmpty() && target == null) return MethodResult.of(false, "CPU " + cpuName + " does not exists"); @@ -583,7 +582,7 @@ public final MethodResult craftFluid(IComputerAccess computer, IArguments argume return MethodResult.of(false, "EMPTY_FILTER"); String cpuName = arguments.optString(1, ""); - ICraftingCPU target = getCraftingCPU(cpuName); + ICraftingCPU target = AppEngApi.getCraftingCPU(node, cpuName); if (!cpuName.isEmpty() && target == null) return MethodResult.of(false, "CPU " + cpuName + " does not exists"); @@ -600,11 +599,48 @@ public final MethodResult craftFluid(IComputerAccess computer, IArguments argume @Override public MethodResult getCraftingTasks() { - return null; + if (!isAvailable()) + return notConnected(); + + ICraftingService craftingGrid = node.getGrid().getService(ICraftingService.class); + + List jobs = new ArrayList<>(); + + for (ICraftingCPU cpu : craftingGrid.getCpus()) { + if (cpu.getJobStatus() != null) + jobs.add(AppEngApi.getObjectFromJob(cpu.getJobStatus(), cpu)); + } + return MethodResult.of(jobs); } @Override public MethodResult cancelCraftingTasks(IArguments arguments) throws LuaException { + if (!isAvailable()) + return notConnected(); + + ICraftingService craftingGrid = node.getGrid().getService(ICraftingService.class); + + Map filterTable; + try { + Optional> optionalTable = arguments.optTable(0); + if (optionalTable.isEmpty()) + return MethodResult.of(null, "EMPTY_INPUT"); + filterTable = optionalTable.get(); + } catch (LuaException e) { + return MethodResult.of(null, "NO_TABLE"); + } + + Pair filter = GenericFilter.parseGeneric(filterTable); + if (filter.getRight() != null) + return MethodResult.of(null, filter.getRight()); + + //TODO: See https://github.com/AppliedEnergistics/Applied-Energistics-2/issues/7560 + /* + for (ICraftingCPU cpu : craftingGrid.getCpus()) { + if (cpu.getJobStatus() != null) { + } + } + */ return null; } @@ -644,7 +680,7 @@ public final MethodResult isFluidCrafting(IArguments arguments) throws LuaExcept if (parsedFilter.isEmpty()) return MethodResult.of(false, "EMPTY_FILTER"); String cpuName = arguments.optString(1, ""); - ICraftingCPU craftingCPU = getCraftingCPU(cpuName); + ICraftingCPU craftingCPU = AppEngApi.getCraftingCPU(node, cpuName); return MethodResult.of(AppEngApi.isFluidCrafting(monitor, grid, parsedFilter, craftingCPU)); } @@ -721,7 +757,7 @@ public final MethodResult isItemCrafting(IArguments arguments) throws LuaExcepti if (parsedFilter.isEmpty()) return MethodResult.of(false, "EMPTY_FILTER"); String cpuName = arguments.optString(1, ""); - ICraftingCPU craftingCPU = getCraftingCPU(cpuName); + ICraftingCPU craftingCPU = AppEngApi.getCraftingCPU(node, cpuName); return MethodResult.of(AppEngApi.isItemCrafting(monitor, grid, parsedFilter, craftingCPU)); } @@ -735,28 +771,9 @@ public final MethodResult getCraftingCPUs() throws LuaException { List map = new ArrayList<>(); for (ICraftingCPU iCraftingCPU : grid.getCpus()) { - Object cpu = AppEngApi.getObjectFromCPU(iCraftingCPU); + Object cpu = AppEngApi.getObjectFromCPU(iCraftingCPU, false); map.add(cpu); } return MethodResult.of(map); } - - public final ICraftingCPU getCraftingCPU(String cpuName) { - if (cpuName.isEmpty()) return null; - ICraftingService grid = node.getGrid().getService(ICraftingService.class); - if (grid == null) return null; - - Iterator iterator = grid.getCpus().iterator(); - if (!iterator.hasNext()) return null; - - while (iterator.hasNext()) { - ICraftingCPU cpu = iterator.next(); - - if (cpu.getName() != null && cpu.getName().getString().equals(cpuName)) { - return cpu; - } - } - - return null; - } } From ca99ea2889803e9d1ebfd4986f4835bf7b2a1b7c Mon Sep 17 00:00:00 2001 From: Srendi Date: Tue, 20 Feb 2024 00:13:00 +0100 Subject: [PATCH 085/228] [#13] Add a hotkey module This is currently not server side safe and does only work in single player --- .../client/KeyBindings.java | 2 + .../common/setup/APItems.java | 3 ++ .../smartglasses/SmartGlassesAccess.java | 4 ++ .../common/smartglasses/modules/IModule.java | 4 ++ .../modules/ModulePeripheral.java | 9 +++-- .../modules/hotkey/HotkeyModule.java | 38 +++++++++++++++++++ .../modules/hotkey/HotkeyModuleItem.java | 19 ++++++++++ 7 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModule.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModuleItem.java diff --git a/src/main/java/de/srendi/advancedperipherals/client/KeyBindings.java b/src/main/java/de/srendi/advancedperipherals/client/KeyBindings.java index 2cbd46438..37cea5f0d 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/KeyBindings.java +++ b/src/main/java/de/srendi/advancedperipherals/client/KeyBindings.java @@ -7,9 +7,11 @@ public class KeyBindings { public static final KeyMapping DESCRIPTION_KEYBINDING = new KeyMapping("keybind.advancedperipherals.description", GLFW.GLFW_KEY_LEFT_CONTROL, "keybind.advancedperipherals.category"); + public static final KeyMapping GLASSES_HOTKEY_KEYBINDING = new KeyMapping("keybind.advancedperipherals.glasses_hotkey", GLFW.GLFW_KEY_G, "keybind.advancedperipherals.category"); public static void register(RegisterKeyMappingsEvent event) { event.register(DESCRIPTION_KEYBINDING); + event.register(GLASSES_HOTKEY_KEYBINDING); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java index fea0fdebe..690822a62 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java @@ -1,8 +1,10 @@ package de.srendi.advancedperipherals.common.setup; +import appeng.client.Hotkeys; import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.items.*; import de.srendi.advancedperipherals.common.items.base.SmartGlassesMaterials; +import de.srendi.advancedperipherals.common.smartglasses.modules.hotkey.HotkeyModuleItem; import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.OverlayGlassesItem; import net.minecraft.world.item.Item; import net.minecraftforge.registries.RegistryObject; @@ -14,6 +16,7 @@ public class APItems { public static final RegistryObject SMART_GLASSES_NETHERITE = APRegistration.ITEMS.register("smart_glasses_netherite", () -> new SmartGlassesItem(SmartGlassesMaterials.NETHERITE)); public static final RegistryObject SMART_GLASSES_INTERFACE = APRegistration.ITEMS.register("smart_glasses_interface", SmartGlassesInterfaceItem::new); public static final RegistryObject OVERLAY_GLASSES = APRegistration.ITEMS.register("overlayglasses", OverlayGlassesItem::new); + public static final RegistryObject HOTKEY_MODULE = APRegistration.ITEMS.register("hotkeymodule", HotkeyModuleItem::new); public static final RegistryObject COMPUTER_TOOL = APRegistration.ITEMS.register("computer_tool", () -> new APItem(new Item.Properties().stacksTo(1), () -> true)); public static final RegistryObject MEMORY_CARD = APRegistration.ITEMS.register("memory_card", MemoryCardItem::new); public static final RegistryObject END_AUTOMATA_CORE = APRegistration.ITEMS.register("end_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableEndAutomataCore)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesAccess.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesAccess.java index 85b8c21aa..316c7a715 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesAccess.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesAccess.java @@ -60,4 +60,8 @@ public void invalidatePeripheral() { public Map getUpgrades() { return computer.getUpgrades(); } + + public SmartGlassesComputer getComputer() { + return computer; + } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java index 96be31142..f7b7bfd9a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java @@ -2,6 +2,7 @@ import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesAccess; import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.Nullable; public interface IModule { @@ -9,9 +10,12 @@ public interface IModule { /** * Used to define the available functions of the module. This method only gets called once when indexing the modules + *

+ * Return null if the module does not have any functions * * @return an object containing lua functions {@link dan200.computercraft.api.lua.LuaFunction} */ + @Nullable IModuleFunctions getFunctions(SmartGlassesAccess smartGlassesAccess); /** diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java index 94a5604ca..08e458f17 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java @@ -10,9 +10,12 @@ public class ModulePeripheral extends BasePeripheral { public ModulePeripheral(SmartGlassesComputer computer) { super(PERIPHERAL_TYPE, new ModulePeripheralOwner(computer)); - getPeripheralOwner().getComputer().getModules().forEach(module -> - addPlugin(module.getFunctions(computer.getSmartGlassesAccess())) - ); + getPeripheralOwner().getComputer().getModules().forEach(module -> { + IModuleFunctions functions = module.getFunctions(computer.getSmartGlassesAccess()); + + if (functions != null) + addPlugin(functions); + }); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModule.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModule.java new file mode 100644 index 000000000..9510428ee --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModule.java @@ -0,0 +1,38 @@ +package de.srendi.advancedperipherals.common.smartglasses.modules.hotkey; + +import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.client.KeyBindings; +import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesAccess; +import de.srendi.advancedperipherals.common.smartglasses.modules.IModule; +import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleFunctions; +import de.srendi.advancedperipherals.common.util.KeybindUtil; +import net.minecraft.resources.ResourceLocation; + +public class HotkeyModule implements IModule { + + private int keyPressDuration = 0; + + @Override + public ResourceLocation getName() { + return new ResourceLocation(AdvancedPeripherals.MOD_ID, "hotkey"); + } + + @Override + public IModuleFunctions getFunctions(SmartGlassesAccess smartGlassesAccess) { + return null; + } + + @Override + public void tick(SmartGlassesAccess smartGlassesAccess) { + if (KeybindUtil.isKeyPressed(KeyBindings.GLASSES_HOTKEY_KEYBINDING)) { + // Add another 50ms to the duration, one tick + keyPressDuration = keyPressDuration + 50; + } else if(keyPressDuration > 0) { + // If the key is not pressed, but the duration is greater than 0, we can assume that the key was pressed + // We can now post the event + String keyBind = KeyBindings.GLASSES_HOTKEY_KEYBINDING.getKey().getName(); + smartGlassesAccess.getComputer().queueEvent("glassesKeyPressed", new Object[]{keyBind, keyPressDuration}); + keyPressDuration = 0; + } + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModuleItem.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModuleItem.java new file mode 100644 index 000000000..be13ac660 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModuleItem.java @@ -0,0 +1,19 @@ +package de.srendi.advancedperipherals.common.smartglasses.modules.hotkey; + +import de.srendi.advancedperipherals.common.items.base.BaseItem; +import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesAccess; +import de.srendi.advancedperipherals.common.smartglasses.modules.IModule; +import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleItem; + +public class HotkeyModuleItem extends BaseItem implements IModuleItem { + + @Override + public boolean isEnabled() { + return true; + } + + @Override + public IModule getModule(SmartGlassesAccess access) { + return new HotkeyModule(); + } +} From 596200c454040b75768ac2295d5a838fb9048e54 Mon Sep 17 00:00:00 2001 From: Srendi Date: Tue, 20 Feb 2024 18:05:07 +0100 Subject: [PATCH 086/228] [AP-Features-13](https://github.com/IntelligenceModding/Advanced-Peripherals-Features/issues/13) Fixed hotkey module not working on servers --- .../common/network/PacketHandler.java | 2 + .../network/toserver/GlassesHotkeyPacket.java | 55 +++++++++++++++++++ .../common/smartglasses/modules/IModule.java | 2 +- .../modules/hotkey/HotkeyModule.java | 15 ----- .../modules/hotkey/HotkeyModuleItem.java | 37 +++++++++++++ 5 files changed, 95 insertions(+), 16 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/network/toserver/GlassesHotkeyPacket.java diff --git a/src/main/java/de/srendi/advancedperipherals/common/network/PacketHandler.java b/src/main/java/de/srendi/advancedperipherals/common/network/PacketHandler.java index 4dd218f3d..77bbd1fb9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/network/PacketHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/network/PacketHandler.java @@ -4,6 +4,7 @@ import de.srendi.advancedperipherals.common.network.base.IPacket; import de.srendi.advancedperipherals.common.network.toclient.DistanceDetectorSyncPacket; import de.srendi.advancedperipherals.common.network.toclient.ToastToClientPacket; +import de.srendi.advancedperipherals.common.network.toserver.GlassesHotkeyPacket; import net.minecraft.core.BlockPos; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; @@ -34,6 +35,7 @@ public class PacketHandler { public static void init() { registerServerToClient(DistanceDetectorSyncPacket.class, DistanceDetectorSyncPacket::decode); registerServerToClient(ToastToClientPacket.class, ToastToClientPacket::decode); + registerClientToServer(GlassesHotkeyPacket.class, GlassesHotkeyPacket::decode); } public static void registerServerToClient(Class packet, Function decode) { diff --git a/src/main/java/de/srendi/advancedperipherals/common/network/toserver/GlassesHotkeyPacket.java b/src/main/java/de/srendi/advancedperipherals/common/network/toserver/GlassesHotkeyPacket.java new file mode 100644 index 000000000..c6f5506ed --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/network/toserver/GlassesHotkeyPacket.java @@ -0,0 +1,55 @@ +package de.srendi.advancedperipherals.common.network.toserver; + +import de.srendi.advancedperipherals.common.items.SmartGlassesItem; +import de.srendi.advancedperipherals.common.network.base.IPacket; +import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesComputer; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.ItemStack; +import net.minecraftforge.network.NetworkEvent; +import net.minecraftforge.server.ServerLifecycleHooks; + +import java.util.UUID; + +public class GlassesHotkeyPacket implements IPacket { + + private final UUID player; + private final String keyBind; + private final int keyPressDuration; + + public GlassesHotkeyPacket(UUID player, String keyBind, int keyPressDuration) { + this.player = player; + this.keyBind = keyBind; + this.keyPressDuration = keyPressDuration; + } + + @Override + public void handle(NetworkEvent.Context context) { + MinecraftServer server = ServerLifecycleHooks.getCurrentServer(); + + ServerPlayer serverPlayer = server.getPlayerList().getPlayer(player); + if (serverPlayer == null) + return; + + for (ItemStack stack : serverPlayer.getAllSlots()) { + if (stack.getItem() instanceof SmartGlassesItem) { + SmartGlassesComputer computer = SmartGlassesItem.getServerComputer(server, stack); + + if (computer != null) + computer.queueEvent("glassesKeyPressed", new Object[]{keyBind, keyPressDuration}); + } + } + } + + @Override + public void encode(FriendlyByteBuf buffer) { + buffer.writeUUID(player); + buffer.writeUtf(keyBind); + buffer.writeInt(keyPressDuration); + } + + public static GlassesHotkeyPacket decode(FriendlyByteBuf buffer) { + return new GlassesHotkeyPacket(buffer.readUUID(), buffer.readUtf(), buffer.readInt()); + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java index f7b7bfd9a..da070b9a9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java @@ -24,7 +24,7 @@ public interface IModule { * Implementations should check if the entity is not null since the glasses can still tick without belonging to an entity * @param smartGlassesAccess Contains access to the entity, the computer, the level or the upgrades */ - void tick(SmartGlassesAccess smartGlassesAccess); + default void tick(SmartGlassesAccess smartGlassesAccess) {}; /** * ErrorConstants class contains constants for error messages. This is used for easier error handling for users. diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModule.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModule.java index 9510428ee..ea623ace8 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModule.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModule.java @@ -1,11 +1,9 @@ package de.srendi.advancedperipherals.common.smartglasses.modules.hotkey; import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.client.KeyBindings; import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesAccess; import de.srendi.advancedperipherals.common.smartglasses.modules.IModule; import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleFunctions; -import de.srendi.advancedperipherals.common.util.KeybindUtil; import net.minecraft.resources.ResourceLocation; public class HotkeyModule implements IModule { @@ -22,17 +20,4 @@ public IModuleFunctions getFunctions(SmartGlassesAccess smartGlassesAccess) { return null; } - @Override - public void tick(SmartGlassesAccess smartGlassesAccess) { - if (KeybindUtil.isKeyPressed(KeyBindings.GLASSES_HOTKEY_KEYBINDING)) { - // Add another 50ms to the duration, one tick - keyPressDuration = keyPressDuration + 50; - } else if(keyPressDuration > 0) { - // If the key is not pressed, but the duration is greater than 0, we can assume that the key was pressed - // We can now post the event - String keyBind = KeyBindings.GLASSES_HOTKEY_KEYBINDING.getKey().getName(); - smartGlassesAccess.getComputer().queueEvent("glassesKeyPressed", new Object[]{keyBind, keyPressDuration}); - keyPressDuration = 0; - } - } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModuleItem.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModuleItem.java index be13ac660..90d80a6d5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModuleItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModuleItem.java @@ -1,9 +1,18 @@ package de.srendi.advancedperipherals.common.smartglasses.modules.hotkey; +import de.srendi.advancedperipherals.client.KeyBindings; import de.srendi.advancedperipherals.common.items.base.BaseItem; +import de.srendi.advancedperipherals.common.network.PacketHandler; +import de.srendi.advancedperipherals.common.network.toserver.GlassesHotkeyPacket; import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesAccess; import de.srendi.advancedperipherals.common.smartglasses.modules.IModule; import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleItem; +import de.srendi.advancedperipherals.common.util.KeybindUtil; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import org.jetbrains.annotations.NotNull; public class HotkeyModuleItem extends BaseItem implements IModuleItem { @@ -16,4 +25,32 @@ public boolean isEnabled() { public IModule getModule(SmartGlassesAccess access) { return new HotkeyModule(); } + + @Override + public void inventoryTick(@NotNull ItemStack stack, Level level, @NotNull Entity entity, int slot, boolean isSelected) { + if (!level.isClientSide) + return; + + if (!(entity instanceof Player player)) + return; + + if (KeybindUtil.isKeyPressed(KeyBindings.GLASSES_HOTKEY_KEYBINDING)) { + // Add another 50ms to the duration, one tick + setKeyPressDuration(stack, getKeyPressDuration(stack) + 50); + } else if(getKeyPressDuration(stack) > 0) { + // If the key is not pressed, but the duration is greater than 0, we can assume that the key was pressed + // We can now post the event + String keyBind = KeyBindings.GLASSES_HOTKEY_KEYBINDING.getKey().getName(); + PacketHandler.sendToServer(new GlassesHotkeyPacket(player.getUUID(), keyBind, getKeyPressDuration(stack))); + setKeyPressDuration(stack, 0); + } + } + + public static int getKeyPressDuration(ItemStack stack) { + return stack.copy().getOrCreateTag().getInt("KEY_PRESS_DURATION"); + } + + public static void setKeyPressDuration(ItemStack stack, int keyPressDuration) { + stack.getOrCreateTag().putInt("KEY_PRESS_DURATION", keyPressDuration); + } } From 285695d6c31c3d3bdebdee17804ae606b7e67144 Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 23 Feb 2024 18:00:56 +0100 Subject: [PATCH 087/228] Fixed the smart glasses ui when playing on servers --- .../common/items/SmartGlassesItem.java | 2 ++ .../common/smartglasses/SmartGlassesItemHandler.java | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java index 1f90dd563..d00b2a6ca 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java @@ -224,6 +224,8 @@ public SmartGlassesComputer getOrCreateComputer(ServerLevel level, Entity entity @Nullable public static SmartGlassesComputer getServerComputer(MinecraftServer server, ItemStack stack) { + if (server == null) + return null; return (SmartGlassesComputer) ServerContext.get(server).registry().get(getSessionID(stack), getInstanceID(stack)); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java index fb3e19ac6..3d8846a60 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java @@ -9,6 +9,7 @@ import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.ItemHandlerHelper; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.annotation.Nonnull; @@ -18,13 +19,16 @@ public class SmartGlassesItemHandler implements IItemHandlerModifiable, INBTSeri private final NonNullList items = NonNullList.withSize(SLOTS, ItemStack.EMPTY); private final ItemStack stack; + @Nullable private final SmartGlassesComputer computer; - public SmartGlassesItemHandler(ItemStack stack, SmartGlassesComputer computer) { + public SmartGlassesItemHandler(ItemStack stack,@Nullable SmartGlassesComputer computer) { this.stack = stack; this.computer = computer; deserializeNBT(stack.getOrCreateTagElement("Items")); - computer.setItemHandler(this); + + if(computer != null) + computer.setItemHandler(this); } @Override @@ -125,7 +129,8 @@ public void setStackInSlot(int slot, @NotNull ItemStack stack) { public void setChanged() { stack.getOrCreateTag().put("Items", serializeNBT()); - computer.markDirty(); + if (computer != null) + computer.markDirty(); } @Override From a1b7f53ce9e1d19a0151e0fce29ea5b88238e18f Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 18 Mar 2024 15:40:32 +0100 Subject: [PATCH 088/228] Add the ability for the modules to inventory tick and fix double queued `glassesKeyPressed` event --- .../common/items/SmartGlassesItem.java | 15 +++++++++++++- .../modules/hotkey/HotkeyModule.java | 2 -- .../modules/hotkey/HotkeyModuleItem.java | 20 ++++++++++--------- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java index d00b2a6ca..880568931 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java @@ -17,6 +17,7 @@ import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesComputer; import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesItemHandler; import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesMenuProvider; +import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleItem; import de.srendi.advancedperipherals.common.smartglasses.modules.ModulePeripheral; import net.minecraft.ChatFormatting; import net.minecraft.core.Direction; @@ -116,7 +117,19 @@ private boolean tick(ItemStack stack, Level world, Entity entity, SmartGlassesCo } @Override - public void inventoryTick(@NotNull ItemStack stack, Level world, @NotNull Entity entity, int slotNum, boolean selected) { + public void inventoryTick(@NotNull ItemStack stack, @NotNull Level world, @NotNull Entity entity, int slotNum, boolean selected) { + LazyOptional itemHandler = stack.getCapability(ForgeCapabilities.ITEM_HANDLER); + if(itemHandler.isPresent()) { + itemHandler.resolve().ifPresent(iItemHandler -> { + for(int slot = 0; slot < iItemHandler.getSlots(); slot++) { + ItemStack itemStack = iItemHandler.getStackInSlot(slot); + if(itemStack.getItem() instanceof IModuleItem) { + itemStack.inventoryTick(world, entity, slot, selected); + } + } + }); + } + if (world.isClientSide) return; Container inventory = entity instanceof Player player ? player.getInventory() : null; diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModule.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModule.java index ea623ace8..8f209da92 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModule.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModule.java @@ -8,8 +8,6 @@ public class HotkeyModule implements IModule { - private int keyPressDuration = 0; - @Override public ResourceLocation getName() { return new ResourceLocation(AdvancedPeripherals.MOD_ID, "hotkey"); diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModuleItem.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModuleItem.java index 90d80a6d5..c6b757b59 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModuleItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModuleItem.java @@ -16,6 +16,8 @@ public class HotkeyModuleItem extends BaseItem implements IModuleItem { + private static final String KEY_PRESS_DURATION_NBT = "KeyPressDuration"; + @Override public boolean isEnabled() { return true; @@ -27,11 +29,8 @@ public IModule getModule(SmartGlassesAccess access) { } @Override - public void inventoryTick(@NotNull ItemStack stack, Level level, @NotNull Entity entity, int slot, boolean isSelected) { - if (!level.isClientSide) - return; - - if (!(entity instanceof Player player)) + public void inventoryTick(@NotNull ItemStack stack, @NotNull Level level, @NotNull Entity entity, int slot, boolean isSelected) { + if (level.isClientSide() || !(entity instanceof Player player)) return; if (KeybindUtil.isKeyPressed(KeyBindings.GLASSES_HOTKEY_KEYBINDING)) { @@ -40,17 +39,20 @@ public void inventoryTick(@NotNull ItemStack stack, Level level, @NotNull Entity } else if(getKeyPressDuration(stack) > 0) { // If the key is not pressed, but the duration is greater than 0, we can assume that the key was pressed // We can now post the event - String keyBind = KeyBindings.GLASSES_HOTKEY_KEYBINDING.getKey().getName(); - PacketHandler.sendToServer(new GlassesHotkeyPacket(player.getUUID(), keyBind, getKeyPressDuration(stack))); + + int duration = getKeyPressDuration(stack); setKeyPressDuration(stack, 0); + + String keyBind = KeyBindings.GLASSES_HOTKEY_KEYBINDING.getKey().getName(); + PacketHandler.sendToServer(new GlassesHotkeyPacket(player.getUUID(), keyBind, duration)); } } public static int getKeyPressDuration(ItemStack stack) { - return stack.copy().getOrCreateTag().getInt("KEY_PRESS_DURATION"); + return stack.copy().getOrCreateTag().getInt(KEY_PRESS_DURATION_NBT); } public static void setKeyPressDuration(ItemStack stack, int keyPressDuration) { - stack.getOrCreateTag().putInt("KEY_PRESS_DURATION", keyPressDuration); + stack.getOrCreateTag().putInt(KEY_PRESS_DURATION_NBT, keyPressDuration); } } From 44165e209434179adecfbe8dbe6314ea2ab90ebb Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 18 Mar 2024 15:56:45 +0100 Subject: [PATCH 089/228] `!` --- .../common/smartglasses/modules/hotkey/HotkeyModuleItem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModuleItem.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModuleItem.java index c6b757b59..a21f2a7db 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModuleItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModuleItem.java @@ -30,7 +30,7 @@ public IModule getModule(SmartGlassesAccess access) { @Override public void inventoryTick(@NotNull ItemStack stack, @NotNull Level level, @NotNull Entity entity, int slot, boolean isSelected) { - if (level.isClientSide() || !(entity instanceof Player player)) + if (!level.isClientSide() || !(entity instanceof Player player)) return; if (KeybindUtil.isKeyPressed(KeyBindings.GLASSES_HOTKEY_KEYBINDING)) { From a3ebf19a50a8100fdb72bd0c65be7055f5c6513d Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 18 Mar 2024 17:48:34 +0100 Subject: [PATCH 090/228] Add a night vision module to the smart glasses Add a `onUnequipped` function to the IModule interface Switch to a slot based module system to better track module changes --- .../common/items/SmartGlassesItem.java | 17 ++++--- .../common/setup/APItems.java | 2 + .../smartglasses/SmartGlassesComputer.java | 22 +++++---- .../common/smartglasses/modules/IModule.java | 2 + .../smartglasses/modules/IModuleItem.java | 17 ++++++- .../modules/ModulePeripheral.java | 4 +- .../modules/hotkey/HotkeyModule.java | 2 +- .../modules/hotkey/HotkeyModuleItem.java | 2 +- .../nightvision/NightVisionFunctions.java | 24 ++++++++++ .../nightvision/NightVisionModule.java | 48 +++++++++++++++++++ .../nightvision/NightVisionModuleItem.java | 40 ++++++++++++++++ .../modules/overlay/OverlayGlassesItem.java | 2 +- .../modules/overlay/OverlayModule.java | 2 +- 13 files changed, 162 insertions(+), 22 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/nightvision/NightVisionFunctions.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/nightvision/NightVisionModule.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/nightvision/NightVisionModuleItem.java diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java index 880568931..35ac3cbf7 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java @@ -13,10 +13,8 @@ import dan200.computercraft.shared.network.container.ComputerContainerData; import dan200.computercraft.shared.util.IDAssigner; import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesAPI; -import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesComputer; -import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesItemHandler; -import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesMenuProvider; +import de.srendi.advancedperipherals.common.smartglasses.*; +import de.srendi.advancedperipherals.common.smartglasses.modules.IModule; import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleItem; import de.srendi.advancedperipherals.common.smartglasses.modules.ModulePeripheral; import net.minecraft.ChatFormatting; @@ -123,8 +121,15 @@ public void inventoryTick(@NotNull ItemStack stack, @NotNull Level world, @NotNu itemHandler.resolve().ifPresent(iItemHandler -> { for(int slot = 0; slot < iItemHandler.getSlots(); slot++) { ItemStack itemStack = iItemHandler.getStackInSlot(slot); - if(itemStack.getItem() instanceof IModuleItem) { - itemStack.inventoryTick(world, entity, slot, selected); + if(itemStack.getItem() instanceof IModuleItem iModuleItem) { + SmartGlassesAccess glassesAccess = null; + IModule module = null; + if (!world.isClientSide) { + SmartGlassesComputer computer = getOrCreateComputer((ServerLevel) world, entity, entity instanceof Player player ? player.getInventory() : null, stack); + module = computer.getModules().get(slot); + glassesAccess = computer.getSmartGlassesAccess(); + } + iModuleItem.inventoryTick(itemStack, world, entity, slot, selected, glassesAccess, module); } } }); diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java index 690822a62..109668818 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java @@ -5,6 +5,7 @@ import de.srendi.advancedperipherals.common.items.*; import de.srendi.advancedperipherals.common.items.base.SmartGlassesMaterials; import de.srendi.advancedperipherals.common.smartglasses.modules.hotkey.HotkeyModuleItem; +import de.srendi.advancedperipherals.common.smartglasses.modules.nightvision.NightVisionModuleItem; import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.OverlayGlassesItem; import net.minecraft.world.item.Item; import net.minecraftforge.registries.RegistryObject; @@ -17,6 +18,7 @@ public class APItems { public static final RegistryObject SMART_GLASSES_INTERFACE = APRegistration.ITEMS.register("smart_glasses_interface", SmartGlassesInterfaceItem::new); public static final RegistryObject OVERLAY_GLASSES = APRegistration.ITEMS.register("overlayglasses", OverlayGlassesItem::new); public static final RegistryObject HOTKEY_MODULE = APRegistration.ITEMS.register("hotkeymodule", HotkeyModuleItem::new); + public static final RegistryObject NIGHT_VISION_MODULE = APRegistration.ITEMS.register("nightvisionmodule", NightVisionModuleItem::new); public static final RegistryObject COMPUTER_TOOL = APRegistration.ITEMS.register("computer_tool", () -> new APItem(new Item.Properties().stacksTo(1), () -> true)); public static final RegistryObject MEMORY_CARD = APRegistration.ITEMS.register("memory_card", MemoryCardItem::new); public static final RegistryObject END_AUTOMATA_CORE = APRegistration.ITEMS.register("end_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableEndAutomataCore)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java index bf7db8eff..21301b954 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java @@ -22,10 +22,7 @@ import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; -import java.util.Collections; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; +import java.util.*; /** * Basically just a {@link dan200.computercraft.shared.pocket.core.PocketServerComputer} but with some changes @@ -44,7 +41,7 @@ public class SmartGlassesComputer extends ServerComputer implements IPocketAcces private boolean isDirty = false; private final Set tracking = new HashSet<>(); - private final Set modules = new HashSet<>(); + private final Map modules = new HashMap<>(); public SmartGlassesComputer(ServerLevel world, int computerID, @Nullable String label, ComputerFamily family) { super(world, computerID, label, family, 39, 13); @@ -148,11 +145,18 @@ public void updatePeripheralsAndModules(IItemHandler itemHandler) { } setPeripheral(SmartGlassesSlot.indexToSide(slot), null); } - modules.clear(); for (int slot = 4; slot < 11; slot++) { ItemStack peripheralItem = itemHandler.getStackInSlot(slot); if (!peripheralItem.isEmpty() && peripheralItem.getItem() instanceof IModuleItem module) { - modules.add(module.getModule(smartGlassesAccess)); + if (modules.get(slot) != null && modules.get(slot).getName().equals(module.createModule(smartGlassesAccess).getName())) + continue; + + modules.put(slot, module.createModule(smartGlassesAccess)); + } else { + if (modules.get(slot) != null) { + modules.get(slot).onUnequipped(smartGlassesAccess); + modules.remove(slot); + } } } setPeripheral(ComputerSide.BACK, new ModulePeripheral(this)); @@ -172,7 +176,7 @@ public void tickServer() { tracking.addAll(getLevel().players()); } - modules.forEach(module -> module.tick(smartGlassesAccess)); + modules.values().forEach(module -> module.tick(smartGlassesAccess)); if (isDirty()) updatePeripheralsAndModules(itemHandler); @@ -184,7 +188,7 @@ public void setEntity(@Nullable Entity entity) { this.entity = entity; } - public Set getModules() { + public Map getModules() { return modules; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java index da070b9a9..10cdbc573 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java @@ -26,6 +26,8 @@ public interface IModule { */ default void tick(SmartGlassesAccess smartGlassesAccess) {}; + default void onUnequipped(SmartGlassesAccess smartGlassesAccess) {}; + /** * ErrorConstants class contains constants for error messages. This is used for easier error handling for users. */ diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModuleItem.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModuleItem.java index 2854d509c..bed3560a2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModuleItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModuleItem.java @@ -1,9 +1,24 @@ package de.srendi.advancedperipherals.common.smartglasses.modules; import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesAccess; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import org.jetbrains.annotations.Nullable; public interface IModuleItem { - IModule getModule(SmartGlassesAccess access); + IModule createModule(SmartGlassesAccess access); + + /** + * This method is called every tick the item is in the inventory of the smart glasses + * Runs on the client and server side + * + * @param access The access to the smart glasses - Null on the client side + * @param module The module - Null on the client side + */ + default void inventoryTick(ItemStack itemStack, Level level, Entity entity, int inventorySlot, boolean isCurrentItem, @Nullable SmartGlassesAccess access, @Nullable IModule module) { + + } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java index 08e458f17..133d1d38d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java @@ -10,7 +10,7 @@ public class ModulePeripheral extends BasePeripheral { public ModulePeripheral(SmartGlassesComputer computer) { super(PERIPHERAL_TYPE, new ModulePeripheralOwner(computer)); - getPeripheralOwner().getComputer().getModules().forEach(module -> { + getPeripheralOwner().getComputer().getModules().values().forEach(module -> { IModuleFunctions functions = module.getFunctions(computer.getSmartGlassesAccess()); if (functions != null) @@ -25,6 +25,6 @@ public boolean isEnabled() { @LuaFunction(mainThread = true) public final String[] getModules() { - return getPeripheralOwner().getComputer().getModules().stream().map(module -> module.getName().toString()).toArray(String[]::new); + return getPeripheralOwner().getComputer().getModules().values().stream().map(module -> module.getName().toString()).toArray(String[]::new); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModule.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModule.java index 8f209da92..c695a8334 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModule.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModule.java @@ -10,7 +10,7 @@ public class HotkeyModule implements IModule { @Override public ResourceLocation getName() { - return new ResourceLocation(AdvancedPeripherals.MOD_ID, "hotkey"); + return AdvancedPeripherals.getRL("hotkey"); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModuleItem.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModuleItem.java index a21f2a7db..c2817a9c2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModuleItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModuleItem.java @@ -24,7 +24,7 @@ public boolean isEnabled() { } @Override - public IModule getModule(SmartGlassesAccess access) { + public IModule createModule(SmartGlassesAccess access) { return new HotkeyModule(); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/nightvision/NightVisionFunctions.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/nightvision/NightVisionFunctions.java new file mode 100644 index 000000000..658ef1ba2 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/nightvision/NightVisionFunctions.java @@ -0,0 +1,24 @@ +package de.srendi.advancedperipherals.common.smartglasses.modules.nightvision; + +import dan200.computercraft.api.lua.LuaFunction; +import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleFunctions; + +public class NightVisionFunctions implements IModuleFunctions { + + private final NightVisionModule nightVisionModule; + + public NightVisionFunctions(NightVisionModule nightVisionModule) { + this.nightVisionModule = nightVisionModule; + } + + @LuaFunction(mainThread = true) + public final boolean isNightVisionEnabled() { + return nightVisionModule.isNightVisionEnabled(); + } + + @LuaFunction(mainThread = true) + public final void enableNightVision(boolean enable) { + nightVisionModule.enableNightVision(enable); + } + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/nightvision/NightVisionModule.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/nightvision/NightVisionModule.java new file mode 100644 index 000000000..b4818a0c9 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/nightvision/NightVisionModule.java @@ -0,0 +1,48 @@ +package de.srendi.advancedperipherals.common.smartglasses.modules.nightvision; + +import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesAccess; +import de.srendi.advancedperipherals.common.smartglasses.modules.IModule; +import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleFunctions; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.effect.MobEffects; +import net.minecraft.world.entity.player.Player; +import org.jetbrains.annotations.Nullable; + +public class NightVisionModule implements IModule { + + public boolean nightVisionEnabled = true; + + public NightVisionModule() { + + } + + @Override + public ResourceLocation getName() { + return AdvancedPeripherals.getRL("night_vision"); + } + + @Override + @Nullable + public IModuleFunctions getFunctions(SmartGlassesAccess smartGlassesAccess) { + return new NightVisionFunctions(this); + } + + @Override + public void onUnequipped(SmartGlassesAccess smartGlassesAccess) { + if (smartGlassesAccess.getEntity() != null) { + if (smartGlassesAccess.getEntity() instanceof Player player) { + player.removeEffect(MobEffects.NIGHT_VISION); + } + } + + } + + public boolean isNightVisionEnabled() { + return nightVisionEnabled; + } + + public void enableNightVision(boolean enable) { + nightVisionEnabled = enable; + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/nightvision/NightVisionModuleItem.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/nightvision/NightVisionModuleItem.java new file mode 100644 index 000000000..0e9c0257a --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/nightvision/NightVisionModuleItem.java @@ -0,0 +1,40 @@ +package de.srendi.advancedperipherals.common.smartglasses.modules.nightvision; + +import de.srendi.advancedperipherals.common.items.base.BaseItem; +import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesAccess; +import de.srendi.advancedperipherals.common.smartglasses.modules.IModule; +import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleItem; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.effect.MobEffects; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import org.jetbrains.annotations.Nullable; + +public class NightVisionModuleItem extends BaseItem implements IModuleItem { + + @Override + public boolean isEnabled() { + return true; + } + + @Override + public IModule createModule(SmartGlassesAccess access) { + return new NightVisionModule(); + } + + @Override + public void inventoryTick(ItemStack itemStack, Level level, Entity entity, int inventorySlot, boolean isCurrentItem, @Nullable SmartGlassesAccess access, @Nullable IModule module) { + if (level.isClientSide() || !(entity instanceof Player player)) + return; + + if (module instanceof NightVisionModule nightVisionModule) { + if (nightVisionModule.nightVisionEnabled) { + player.addEffect(new MobEffectInstance(MobEffects.NIGHT_VISION, Integer.MAX_VALUE)); + } else { + player.removeEffect(MobEffects.NIGHT_VISION); + } + } + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesItem.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesItem.java index ca71eae2f..20a3bd78b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesItem.java @@ -13,7 +13,7 @@ public boolean isEnabled() { } @Override - public IModule getModule(SmartGlassesAccess smartGlassesAccess) { + public IModule createModule(SmartGlassesAccess smartGlassesAccess) { return new OverlayModule(smartGlassesAccess); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java index 9164f4d5e..e7b5c9fe9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java @@ -26,7 +26,7 @@ public OverlayModule(SmartGlassesAccess access) { @Override public ResourceLocation getName() { - return new ResourceLocation(AdvancedPeripherals.MOD_ID, "glasses"); + return AdvancedPeripherals.getRL("glasses"); } @Override From d6cacfcaf558ef916ffdc58282a2ba10b81e0f6b Mon Sep 17 00:00:00 2001 From: Srendi Date: Sun, 31 Mar 2024 00:25:49 +0100 Subject: [PATCH 091/228] Adapt me functions to the internal api changes --- .../computercraft/peripheral/MeBridgePeripheral.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java index 98992cb0d..4ff64fa4b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java @@ -204,7 +204,7 @@ public final MethodResult listItems() { if (!isAvailable()) return notConnected(); - return MethodResult.of(AppEngApi.listStacks(AppEngApi.getMonitor(node), getCraftingService(), 0)); + return MethodResult.of(AppEngApi.listStacks(AppEngApi.getMonitor(node), getCraftingService())); } @Override @@ -213,7 +213,7 @@ public final MethodResult listFluids() { if (!isAvailable()) return notConnected(); - return MethodResult.of(AppEngApi.listFluids(AppEngApi.getMonitor(node), getCraftingService(), 0)); + return MethodResult.of(AppEngApi.listFluids(AppEngApi.getMonitor(node), getCraftingService())); } @Override @@ -222,7 +222,7 @@ public final MethodResult listCraftableItems() { if (!isAvailable()) return notConnected(); - return MethodResult.of(AppEngApi.listStacks(AppEngApi.getMonitor(node), getCraftingService(), 2)); + return MethodResult.of(AppEngApi.listCraftableStacks(AppEngApi.getMonitor(node), getCraftingService())); } @Override @@ -231,7 +231,7 @@ public final MethodResult listCraftableFluids() { if (!isAvailable()) return notConnected(); - return MethodResult.of(AppEngApi.listFluids(AppEngApi.getMonitor(node), getCraftingService(), 2)); + return MethodResult.of(AppEngApi.listCraftableStacks(AppEngApi.getMonitor(node), getCraftingService())); } @Override From 26af8c8516a634fecb10c11ea7af27fff19606c4 Mon Sep 17 00:00:00 2001 From: Srendi Date: Wed, 3 Apr 2024 10:57:39 +0200 Subject: [PATCH 092/228] Satisfy checkstyle --- .../de/srendi/advancedperipherals/common/setup/APItems.java | 1 - .../common/smartglasses/SmartGlassesItemHandler.java | 2 +- .../common/smartglasses/modules/IModule.java | 4 ++-- .../common/smartglasses/modules/ModulePeripheral.java | 1 - 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java index 109668818..985a406f8 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java @@ -1,6 +1,5 @@ package de.srendi.advancedperipherals.common.setup; -import appeng.client.Hotkeys; import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.items.*; import de.srendi.advancedperipherals.common.items.base.SmartGlassesMaterials; diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java index 3d8846a60..0cfa780a1 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java @@ -22,7 +22,7 @@ public class SmartGlassesItemHandler implements IItemHandlerModifiable, INBTSeri @Nullable private final SmartGlassesComputer computer; - public SmartGlassesItemHandler(ItemStack stack,@Nullable SmartGlassesComputer computer) { + public SmartGlassesItemHandler(ItemStack stack, @Nullable SmartGlassesComputer computer) { this.stack = stack; this.computer = computer; deserializeNBT(stack.getOrCreateTagElement("Items")); diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java index 10cdbc573..57376e535 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java @@ -24,9 +24,9 @@ public interface IModule { * Implementations should check if the entity is not null since the glasses can still tick without belonging to an entity * @param smartGlassesAccess Contains access to the entity, the computer, the level or the upgrades */ - default void tick(SmartGlassesAccess smartGlassesAccess) {}; + default void tick(SmartGlassesAccess smartGlassesAccess) {} - default void onUnequipped(SmartGlassesAccess smartGlassesAccess) {}; + default void onUnequipped(SmartGlassesAccess smartGlassesAccess) {} /** * ErrorConstants class contains constants for error messages. This is used for easier error handling for users. diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java index 133d1d38d..af3c3e237 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java @@ -12,7 +12,6 @@ public ModulePeripheral(SmartGlassesComputer computer) { super(PERIPHERAL_TYPE, new ModulePeripheralOwner(computer)); getPeripheralOwner().getComputer().getModules().values().forEach(module -> { IModuleFunctions functions = module.getFunctions(computer.getSmartGlassesAccess()); - if (functions != null) addPlugin(functions); }); From dd5ee5d0c8d6274d4024bf92d833051eb08811e9 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sat, 6 Apr 2024 13:29:18 -0600 Subject: [PATCH 093/228] start to fix chunky peripheral --- .../peripheral/ChunkyPeripheral.java | 10 +- .../common/util/ChunkManager.java | 174 ++++++++++-------- 2 files changed, 103 insertions(+), 81 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChunkyPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChunkyPeripheral.java index b244e3eb1..5eff10742 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChunkyPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChunkyPeripheral.java @@ -20,7 +20,7 @@ public class ChunkyPeripheral extends BasePeripheral { public static final String PERIPHERAL_TYPE = "chunky"; private static final String UUID_TAG = "uuid"; - private @Nullable ChunkPos loadedCentralChunk; + private @Nullable ChunkPos loadedCentralChunk = null; public ChunkyPeripheral(ITurtleAccess turtle, TurtleSide side) { super(PERIPHERAL_TYPE, new TurtlePeripheralOwner(turtle, side)); @@ -58,15 +58,15 @@ public void updateChunkState() { protected void setLoadedChunk(@Nullable ChunkPos newChunk, ChunkManager manager, ServerLevel level) { if (loadedCentralChunk != null) { manager.removeForceChunk(level, getUUID(), loadedCentralChunk); - //Should not be used - //level.setChunkForced(loadedChunk.x, loadedChunk.z, false); + // Should not be used + // level.setChunkForced(loadedChunk.x, loadedChunk.z, false); loadedCentralChunk = null; } if (newChunk != null) { loadedCentralChunk = newChunk; manager.addForceChunk(level, getUUID(), loadedCentralChunk); - //Should not be used - //level.setChunkForced(newChunk.x, newChunk.z, true); + // Should not be used + // level.setChunkForced(newChunk.x, newChunk.z, true); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java index dbd324dc8..f569ebab5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java @@ -9,7 +9,6 @@ import net.minecraftforge.common.world.ForgeChunkManager; import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.server.ServerStartedEvent; -import net.minecraftforge.event.server.ServerStoppingEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.server.ServerLifecycleHooks; @@ -46,11 +45,6 @@ public static ChunkManager load(@NotNull CompoundTag data) { return manager; } - @SubscribeEvent - public static void beforeServerStopped(ServerStoppingEvent event) { - ChunkManager.get(event.getServer().overworld()).stop(); - } - @SubscribeEvent public static void afterServerStarted(ServerStartedEvent event) { ChunkManager.get(event.getServer().overworld()).init(); @@ -59,8 +53,9 @@ public static void afterServerStarted(ServerStartedEvent event) { @SubscribeEvent public static void serverTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.END) { - tickCounter++; - if (tickCounter % (APConfig.PERIPHERALS_CONFIG.chunkLoadValidTime.get() / 2) == 0) { + tickCounter += 2; + if (tickCounter >= APConfig.PERIPHERALS_CONFIG.chunkLoadValidTime.get()) { + tickCounter = 0; ChunkManager.get(ServerLifecycleHooks.getCurrentServer().overworld()).cleanup(); } } @@ -68,16 +63,14 @@ public static void serverTick(TickEvent.ServerTickEvent event) { public synchronized boolean addForceChunk(ServerLevel level, UUID owner, ChunkPos pos) { AdvancedPeripherals.debug("Trying to load forced chunk cluster" + pos, Level.WARN); - if (forcedChunks.containsKey(owner)) return true; - forcedChunks.put(owner, new LoadChunkRecord(level.dimension().location().toString(), pos)); + if (forcedChunks.containsKey(owner)) + return true; + final int chunkRadius = APConfig.PERIPHERALS_CONFIG.chunkyTurtleRadius.get(); + forcedChunks.put(owner, new LoadChunkRecord(level.dimension().location().toString(), pos, chunkRadius)); setDirty(); - int chunkRadius = APConfig.PERIPHERALS_CONFIG.chunkyTurtleRadius.get(); - if (chunkRadius == 0) { - return ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, owner, pos.x, pos.z, true, true); - } boolean result = true; - for (int x = chunkRadius * -1; x < chunkRadius; x++) { - for (int z = chunkRadius * -1; z < chunkRadius; z++) { + for (int x = -chunkRadius; x <= chunkRadius; x++) { + for (int z = -chunkRadius; z <= chunkRadius; z++) { result &= ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, owner, pos.x + x, pos.z + z, true, true); } } @@ -85,27 +78,34 @@ public synchronized boolean addForceChunk(ServerLevel level, UUID owner, ChunkPo } public synchronized void touch(UUID owner) { - if (forcedChunks.containsKey(owner)) - forcedChunks.get(owner).touch(); + LoadChunkRecord forcedChunk = forcedChunks.get(owner); + if (forcedChunk) { + forcedChunk.touch(); + } } + // This method is kept for backward compatibility + // TODO: remove in next major version public synchronized boolean removeForceChunk(ServerLevel level, UUID owner, ChunkPos pos) { + return removeForceChunk(level, owner); + } + + public synchronized boolean removeForceChunk(ServerLevel level, UUID owner) { AdvancedPeripherals.debug("Trying to unload forced chunk cluster" + pos, Level.WARN); - if (!forcedChunks.containsKey(owner)) - return true; LoadChunkRecord chunkRecord = forcedChunks.get(owner); + if (chunkRecord == null) + return true; String dimensionName = level.dimension().location().toString(); - if (!chunkRecord.getDimensionName().equals(dimensionName)) + if (!chunkRecord.getDimensionName().equals(dimensionName)) throw new IllegalArgumentException(String.format("Incorrect dimension! Should be %s instead of %s", chunkRecord.getDimensionName(), dimensionName)); boolean result = true; - int chunkRadius = APConfig.PERIPHERALS_CONFIG.chunkyTurtleRadius.get(); - if (chunkRadius == 0) { - result = ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, owner, pos.x, pos.z, false, true); - } else { - for (int x = chunkRadius * -1; x < chunkRadius; x++) { - for (int z = chunkRadius * -1; z < chunkRadius; z++) { - result &= ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, owner, pos.x + x, pos.z + z, true, true); - } + final ChunkPos pos = chunkRecord.getPos(); + final int chunkRadius = chunkRecord.getRadius(); + for (int x = -chunkRadius; x <= chunkRadius; x++) { + for (int z = -chunkRadius; z <= chunkRadius; z++) { + // TODO: Must save chunk mark in a map or sth else. + // Because technically the chunk will be unforced anyway when two chunky turtle in the same chunk, and one left the other stay. + result &= ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, owner, pos.x + x, pos.z + z, false, true); } } if (result) { @@ -116,57 +116,56 @@ public synchronized boolean removeForceChunk(ServerLevel level, UUID owner, Chun } public synchronized void init() { - if (!initialized) { - AdvancedPeripherals.debug("Schedule chunk manager init", Level.WARN); - int chunkRadius = APConfig.PERIPHERALS_CONFIG.chunkyTurtleRadius.get(); - ServerLifecycleHooks.getCurrentServer().getAllLevels().forEach(level -> { - String dimensionName = level.dimension().location().toString(); - forcedChunks.entrySet().stream().filter(entry -> entry.getValue().getDimensionName().equals(dimensionName)).forEach(entry -> { - if (chunkRadius == 0) { - ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, entry.getKey(), entry.getValue().getPos().x, entry.getValue().getPos().z, true, true); - } - for (int x = chunkRadius * -1; x < chunkRadius; x++) { - for (int z = chunkRadius * -1; z < chunkRadius; z++) { - ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, entry.getKey(), entry.getValue().getPos().x + x, entry.getValue().getPos().z + z, true, true); - } - } - }); - }); - initialized = true; - } - } - - public synchronized void stop() { if (initialized) { - AdvancedPeripherals.debug("Schedule chunk manager stop", Level.WARN); - int chunkRadius = APConfig.PERIPHERALS_CONFIG.chunkyTurtleRadius.get(); - ServerLifecycleHooks.getCurrentServer().getAllLevels().forEach(level -> { - String dimensionName = level.dimension().location().toString(); - forcedChunks.entrySet().stream().filter(entry -> entry.getValue().getDimensionName().equals(dimensionName)).forEach(entry -> { - if (chunkRadius == 0) { - ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, entry.getKey(), entry.getValue().getPos().x, entry.getValue().getPos().z, false, true); - } - for (int x = chunkRadius * -1; x < chunkRadius; x++) { - for (int z = chunkRadius * -1; z < chunkRadius; z++) { - ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, entry.getKey(), entry.getValue().getPos().x + x, entry.getValue().getPos().z + z, false, true); - } - } - }); - }); - initialized = false; + return; } + initialized = true; + + AdvancedPeripherals.debug("Schedule chunk manager init", Level.WARN); + final int chunkRadius = APConfig.PERIPHERALS_CONFIG.chunkyTurtleRadius.get(); + final Map levels = getServerLevels(); + forcedChunks.forEach((uuid, value) -> { + String dimensionName = value.getDimensionName(); + ServerLevel level = levels.get(dimensionName); + if (level == null) { + return; + } + final ChunkPos pos = chunkRecord.getPos(); + final int loadedRadius = value.getRadius(); + if (loadedRadius > chunkRadius) { + // clean overflowed load radius + for (int x = chunkRadius + 1; x <= loadedRadius; x++) { + for (int z = chunkRadius + 1; z <= loadedRadius; z++) { + ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, uuid, pos.x + x, pos.z + z, false, true); + ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, uuid, pos.x + x, pos.z - z, false, true); + ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, uuid, pos.x - x, pos.z + z, false, true); + ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, uuid, pos.x - x, pos.z - z, false, true); + } + } + value.setRadius(chunkRadius); + } + for (int x = -chunkRadius; x <= chunkRadius; x++) { + for (int z = -chunkRadius; z <= chunkRadius; z++) { + ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, uuid, pos.x + x, pos.z + z, true, true); + } + } + }); } public synchronized void cleanup() { AdvancedPeripherals.debug("Schedule chunk manager cleanup", Level.WARN); - ServerLifecycleHooks.getCurrentServer().getAllLevels().forEach(level -> { - String dimensionName = level.dimension().location().toString(); - List purgeList = new ArrayList<>(); - forcedChunks.entrySet().stream().filter(entry -> entry.getValue().getDimensionName().equals(dimensionName) && !entry.getValue().isValid()).forEach(entry -> purgeList.add(entry.getKey())); - purgeList.forEach(uuid -> { - AdvancedPeripherals.debug(String.format("Purge forced chunk for %s", uuid), Level.WARN); - removeForceChunk(level, uuid, forcedChunks.get(uuid).getPos()); - }); + final Map levels = getServerLevels(); + forcedChunks.forEach((uuid, value) -> { + String dimensionName = value.getDimensionName(); + ServerLevel level = levels.get(dimensionName); + if (level == null) { + return; + } + if (value.isValid()) { + return; + } + AdvancedPeripherals.debug(String.format("Purge forced chunk for %s", uuid), Level.WARN); + removeForceChunk(level, uuid); }); } @@ -177,23 +176,37 @@ public synchronized void cleanup() { return data; } + private static final Map getServerLevels() { + Map levels = new HashMap<>(); + ServerLifecycleHooks.getCurrentServer().getAllLevels().forEach(level -> { + String dimensionName = level.dimension().location().toString(); + levels.put(dimensionName, level); + }); + return levels; + } + private static class LoadChunkRecord { private static final String POS_TAG = "pos"; private static final String DIMENSION_NAME_TAG = "dimensionName"; + private static final String RADIUS_TAG = "radius"; private final @NotNull String dimensionName; private final @NotNull ChunkPos pos; + private int radius; private long lastTouch; - LoadChunkRecord(@NotNull String dimensionName, @NotNull ChunkPos pos) { + LoadChunkRecord(@NotNull String dimensionName, @NotNull ChunkPos pos, int radius) { this.dimensionName = dimensionName; this.pos = pos; + this.radius = radius; this.lastTouch = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC); } public static LoadChunkRecord deserialize(@NotNull CompoundTag tag) { - return new LoadChunkRecord(tag.getString(DIMENSION_NAME_TAG), NBTUtil.chunkPosFromNBT(tag.getCompound(POS_TAG))); + Set keys = tag.getAllKeys(); + int radius = keys.contains(RADIUS_TAG) ? tag.getInt(RADIUS_TAG) : APConfig.PERIPHERALS_CONFIG.chunkyTurtleRadius.get(); + return new LoadChunkRecord(tag.getString(DIMENSION_NAME_TAG), NBTUtil.chunkPosFromNBT(tag.getCompound(POS_TAG)), radius); } public @NotNull ChunkPos getPos() { @@ -204,6 +217,14 @@ public static LoadChunkRecord deserialize(@NotNull CompoundTag tag) { return dimensionName; } + public int getRadius() { + return radius; + } + + public void setRadius(int radius) { + this.radius = radius + } + public void touch() { lastTouch = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC); } @@ -217,6 +238,7 @@ public boolean isValid() { CompoundTag tag = new CompoundTag(); tag.putString(DIMENSION_NAME_TAG, dimensionName); tag.put(POS_TAG, NBTUtil.toNBT(pos)); + tag.putInt(RADIUS_TAG, radius); return tag; } } From 8abc3b91c4c79693d328a2f356b0f2a726561351 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sat, 6 Apr 2024 17:59:18 -0600 Subject: [PATCH 094/228] setLoadedChunk when chunky peripheral is attaching --- .../peripheral/ChunkyPeripheral.java | 20 +++++++++---- .../turtles/TurtleChunkyUpgrade.java | 12 ++++++-- .../common/util/ChunkManager.java | 28 +++++++++++-------- 3 files changed, 41 insertions(+), 19 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChunkyPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChunkyPeripheral.java index 5eff10742..5aca2ff2b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChunkyPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChunkyPeripheral.java @@ -45,18 +45,19 @@ public boolean isEnabled() { } public void updateChunkState() { + // TODO: should find someway to update after turtle moved or while moving, but not every tick ServerLevel level = (ServerLevel) getLevel(); ChunkManager manager = ChunkManager.get(level); ChunkPos currentChunk = getChunkPos(); - if (loadedCentralChunk == null || !loadedCentralChunk.equals(currentChunk)) { - setLoadedChunk(currentChunk, manager, level); - } else { - manager.touch(getUUID()); - } + setLoadedChunk(currentChunk, manager, level); + manager.touch(getUUID()); } protected void setLoadedChunk(@Nullable ChunkPos newChunk, ChunkManager manager, ServerLevel level) { if (loadedCentralChunk != null) { + if (loadedCentralChunk.equals(newChunk)) { + return; + } manager.removeForceChunk(level, getUUID(), loadedCentralChunk); // Should not be used // level.setChunkForced(loadedChunk.x, loadedChunk.z, false); @@ -70,6 +71,15 @@ protected void setLoadedChunk(@Nullable ChunkPos newChunk, ChunkManager manager, } } + @Override + public void attach(IComputerAccess computer) { + super.attach(computer); + ServerLevel level = (ServerLevel) owner.getLevel(); + ChunkManager manager = ChunkManager.get(Objects.requireNonNull(level)); + ChunkPos currentChunk = getChunkPos(); + setLoadedChunk(currentChunk, manager, level); + } + @Override public void detach(@NotNull IComputerAccess computer) { super.detach(computer); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChunkyUpgrade.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChunkyUpgrade.java index aec241d37..fcefbb34f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChunkyUpgrade.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChunkyUpgrade.java @@ -12,6 +12,7 @@ import org.jetbrains.annotations.NotNull; public class TurtleChunkyUpgrade extends PeripheralTurtleUpgrade { + private int updateTick = 0; public TurtleChunkyUpgrade(ResourceLocation id, ItemStack stack) { super(id, stack); @@ -19,7 +20,7 @@ public TurtleChunkyUpgrade(ResourceLocation id, ItemStack stack) { @Override public ModelResourceLocation getLeftModel() { - return null; //Null, the turtle uses the chunk controller item model. See BaseTurtle.java + return null; // Null, the turtle uses the chunk controller item model. See BaseTurtle.java } @Override @@ -34,10 +35,15 @@ protected ChunkyPeripheral buildPeripheral(@NotNull ITurtleAccess turtle, @NotNu @Override public void update(@NotNull ITurtleAccess turtle, @NotNull TurtleSide side) { - //Add a chunk to the Chunk Manager every 10 ticks, if it's not already forced. - //The turtle can move, so we need to do that. + // Add a chunk to the Chunk Manager every 10 ticks, if it's not already forced. + // The turtle can move, so we need to do that. super.update(turtle, side); if (APConfig.PERIPHERALS_CONFIG.enableChunkyTurtle.get()) { + updateTick++; + if (updateTick < 10) { + // return; // TODO: turtle will stop work when crossing chunks if update every 10 ticks + } + updateTick = 0; IPeripheral peripheral = turtle.getPeripheral(side); if (peripheral instanceof ChunkyPeripheral chunkyPeripheral) { chunkyPeripheral.updateChunkState(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java index f569ebab5..08db17b37 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java @@ -61,6 +61,14 @@ public static void serverTick(TickEvent.ServerTickEvent event) { } } + private static boolean forceChunk(ServerLevel level, UUID owner, ChunkPos pos) { + return ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, owner, pos.x, pos.z, true, true); + } + + private static boolean unforceChunk(ServerLevel level, UUID owner, ChunkPos pos) { + return ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, owner, pos.x, pos.z, false, true); + } + public synchronized boolean addForceChunk(ServerLevel level, UUID owner, ChunkPos pos) { AdvancedPeripherals.debug("Trying to load forced chunk cluster" + pos, Level.WARN); if (forcedChunks.containsKey(owner)) @@ -71,7 +79,7 @@ public synchronized boolean addForceChunk(ServerLevel level, UUID owner, ChunkPo boolean result = true; for (int x = -chunkRadius; x <= chunkRadius; x++) { for (int z = -chunkRadius; z <= chunkRadius; z++) { - result &= ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, owner, pos.x + x, pos.z + z, true, true); + result &= forceChunk(level, owner, new ChunkPos(pos.x + x, pos.z + z)); } } return result; @@ -96,16 +104,14 @@ public synchronized boolean removeForceChunk(ServerLevel level, UUID owner) { if (chunkRecord == null) return true; String dimensionName = level.dimension().location().toString(); - if (!chunkRecord.getDimensionName().equals(dimensionName)) + if (!chunkRecord.getDimensionName().equals(dimensionName)) throw new IllegalArgumentException(String.format("Incorrect dimension! Should be %s instead of %s", chunkRecord.getDimensionName(), dimensionName)); boolean result = true; final ChunkPos pos = chunkRecord.getPos(); final int chunkRadius = chunkRecord.getRadius(); for (int x = -chunkRadius; x <= chunkRadius; x++) { for (int z = -chunkRadius; z <= chunkRadius; z++) { - // TODO: Must save chunk mark in a map or sth else. - // Because technically the chunk will be unforced anyway when two chunky turtle in the same chunk, and one left the other stay. - result &= ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, owner, pos.x + x, pos.z + z, false, true); + result &= unforceChunk(level, owner, new ChunkPos(pos.x + x, pos.z + z)); } } if (result) { @@ -136,17 +142,17 @@ public synchronized void init() { // clean overflowed load radius for (int x = chunkRadius + 1; x <= loadedRadius; x++) { for (int z = chunkRadius + 1; z <= loadedRadius; z++) { - ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, uuid, pos.x + x, pos.z + z, false, true); - ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, uuid, pos.x + x, pos.z - z, false, true); - ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, uuid, pos.x - x, pos.z + z, false, true); - ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, uuid, pos.x - x, pos.z - z, false, true); + unforceChunk(level, owner, new ChunkPos(pos.x + x, pos.z + z)); + unforceChunk(level, owner, new ChunkPos(pos.x + x, pos.z - z)); + unforceChunk(level, owner, new ChunkPos(pos.x - x, pos.z + z)); + unforceChunk(level, owner, new ChunkPos(pos.x - x, pos.z - z)); } } value.setRadius(chunkRadius); } for (int x = -chunkRadius; x <= chunkRadius; x++) { for (int z = -chunkRadius; z <= chunkRadius; z++) { - ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, uuid, pos.x + x, pos.z + z, true, true); + forceChunk(level, uuid, new ChunkPos(pos.x + x, pos.z + z)); } } }); @@ -222,7 +228,7 @@ public int getRadius() { } public void setRadius(int radius) { - this.radius = radius + this.radius = radius; } public void touch() { From a0a6bec294be775f7ee90d18e67ac94247e64ef7 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sun, 7 Apr 2024 05:01:59 -0600 Subject: [PATCH 095/228] fix some mistakes --- .../common/util/ChunkManager.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java index 08db17b37..36c46b6bc 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java @@ -87,7 +87,7 @@ public synchronized boolean addForceChunk(ServerLevel level, UUID owner, ChunkPo public synchronized void touch(UUID owner) { LoadChunkRecord forcedChunk = forcedChunks.get(owner); - if (forcedChunk) { + if (forcedChunk != null) { forcedChunk.touch(); } } @@ -99,7 +99,7 @@ public synchronized boolean removeForceChunk(ServerLevel level, UUID owner, Chun } public synchronized boolean removeForceChunk(ServerLevel level, UUID owner) { - AdvancedPeripherals.debug("Trying to unload forced chunk cluster" + pos, Level.WARN); + AdvancedPeripherals.debug("Attempting to unload forced chunk cluster" + owner, Level.WARN); LoadChunkRecord chunkRecord = forcedChunks.get(owner); if (chunkRecord == null) return true; @@ -109,6 +109,7 @@ public synchronized boolean removeForceChunk(ServerLevel level, UUID owner) { boolean result = true; final ChunkPos pos = chunkRecord.getPos(); final int chunkRadius = chunkRecord.getRadius(); + AdvancedPeripherals.debug("Trying to unload forced chunk cluster" + owner + " at " + pos + " with radius " + chunkRadius, Level.WARN); for (int x = -chunkRadius; x <= chunkRadius; x++) { for (int z = -chunkRadius; z <= chunkRadius; z++) { result &= unforceChunk(level, owner, new ChunkPos(pos.x + x, pos.z + z)); @@ -136,16 +137,16 @@ public synchronized void init() { if (level == null) { return; } - final ChunkPos pos = chunkRecord.getPos(); + final ChunkPos pos = value.getPos(); final int loadedRadius = value.getRadius(); if (loadedRadius > chunkRadius) { // clean overflowed load radius for (int x = chunkRadius + 1; x <= loadedRadius; x++) { for (int z = chunkRadius + 1; z <= loadedRadius; z++) { - unforceChunk(level, owner, new ChunkPos(pos.x + x, pos.z + z)); - unforceChunk(level, owner, new ChunkPos(pos.x + x, pos.z - z)); - unforceChunk(level, owner, new ChunkPos(pos.x - x, pos.z + z)); - unforceChunk(level, owner, new ChunkPos(pos.x - x, pos.z - z)); + unforceChunk(level, uuid, new ChunkPos(pos.x + x, pos.z + z)); + unforceChunk(level, uuid, new ChunkPos(pos.x + x, pos.z - z)); + unforceChunk(level, uuid, new ChunkPos(pos.x - x, pos.z + z)); + unforceChunk(level, uuid, new ChunkPos(pos.x - x, pos.z - z)); } } value.setRadius(chunkRadius); From b3e55bbe946ad46d8b03e040a3ec4591ae7fc7af Mon Sep 17 00:00:00 2001 From: zyxkad Date: Wed, 10 Apr 2024 06:58:26 -0600 Subject: [PATCH 096/228] fix radius will not update if config changed from big to small --- .../common/util/ChunkManager.java | 44 ++++++++++++------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java index 36c46b6bc..693494d8e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java @@ -61,11 +61,11 @@ public static void serverTick(TickEvent.ServerTickEvent event) { } } - private static boolean forceChunk(ServerLevel level, UUID owner, ChunkPos pos) { + private static boolean forceChunk(UUID owner, ServerLevel level, ChunkPos pos) { return ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, owner, pos.x, pos.z, true, true); } - private static boolean unforceChunk(ServerLevel level, UUID owner, ChunkPos pos) { + private static boolean unforceChunk(UUID owner, ServerLevel level, ChunkPos pos) { return ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, owner, pos.x, pos.z, false, true); } @@ -79,7 +79,7 @@ public synchronized boolean addForceChunk(ServerLevel level, UUID owner, ChunkPo boolean result = true; for (int x = -chunkRadius; x <= chunkRadius; x++) { for (int z = -chunkRadius; z <= chunkRadius; z++) { - result &= forceChunk(level, owner, new ChunkPos(pos.x + x, pos.z + z)); + result &= forceChunk(owner, level, new ChunkPos(pos.x + x, pos.z + z)); } } return result; @@ -94,7 +94,8 @@ public synchronized void touch(UUID owner) { // This method is kept for backward compatibility // TODO: remove in next major version - public synchronized boolean removeForceChunk(ServerLevel level, UUID owner, ChunkPos pos) { + @Deprecated + public synchronized boolean removeForceChunk(ServerLevel level, UUID owner, ChunkPos _) { return removeForceChunk(level, owner); } @@ -109,10 +110,10 @@ public synchronized boolean removeForceChunk(ServerLevel level, UUID owner) { boolean result = true; final ChunkPos pos = chunkRecord.getPos(); final int chunkRadius = chunkRecord.getRadius(); - AdvancedPeripherals.debug("Trying to unload forced chunk cluster" + owner + " at " + pos + " with radius " + chunkRadius, Level.WARN); + AdvancedPeripherals.debug(String.format("Trying to unload forced chunk cluster %s at %s with radius %d", owner, pos, chunkRadius), Level.WARN); for (int x = -chunkRadius; x <= chunkRadius; x++) { for (int z = -chunkRadius; z <= chunkRadius; z++) { - result &= unforceChunk(level, owner, new ChunkPos(pos.x + x, pos.z + z)); + result &= unforceChunk(owner, level, new ChunkPos(pos.x + x, pos.z + z)); } } if (result) { @@ -143,17 +144,30 @@ public synchronized void init() { // clean overflowed load radius for (int x = chunkRadius + 1; x <= loadedRadius; x++) { for (int z = chunkRadius + 1; z <= loadedRadius; z++) { - unforceChunk(level, uuid, new ChunkPos(pos.x + x, pos.z + z)); - unforceChunk(level, uuid, new ChunkPos(pos.x + x, pos.z - z)); - unforceChunk(level, uuid, new ChunkPos(pos.x - x, pos.z + z)); - unforceChunk(level, uuid, new ChunkPos(pos.x - x, pos.z - z)); + unforceChunk(uuid, level, new ChunkPos(pos.x + x, pos.z + z)); + unforceChunk(uuid, level, new ChunkPos(pos.x + x, pos.z - z)); + unforceChunk(uuid, level, new ChunkPos(pos.x - x, pos.z + z)); + unforceChunk(uuid, level, new ChunkPos(pos.x - x, pos.z - z)); } } - value.setRadius(chunkRadius); } - for (int x = -chunkRadius; x <= chunkRadius; x++) { - for (int z = -chunkRadius; z <= chunkRadius; z++) { - forceChunk(level, uuid, new ChunkPos(pos.x + x, pos.z + z)); + value.setRadius(chunkRadius); + if (loadedRadius == -1) { // if it's coming from old version + // just force all + for (int x = -chunkRadius; x <= chunkRadius; x++) { + for (int z = -chunkRadius; z <= chunkRadius; z++) { + forceChunk(uuid, level, new ChunkPos(pos.x + x, pos.z + z)); + } + } + } else if (loadedRadius < chunkRadius) { + // otherwise, only do the changed part to save startup time (in case we have a lot chunky turtle) + for (int x = loadedRadius + 1; x <= chunkRadius; x++) { + for (int z = loadedRadius + 1; z <= chunkRadius; z++) { + forceChunk(uuid, level, new ChunkPos(pos.x + x, pos.z + z)); + forceChunk(uuid, level, new ChunkPos(pos.x + x, pos.z - z)); + forceChunk(uuid, level, new ChunkPos(pos.x - x, pos.z + z)); + forceChunk(uuid, level, new ChunkPos(pos.x - x, pos.z - z)); + } } } }); @@ -212,7 +226,7 @@ private static class LoadChunkRecord { public static LoadChunkRecord deserialize(@NotNull CompoundTag tag) { Set keys = tag.getAllKeys(); - int radius = keys.contains(RADIUS_TAG) ? tag.getInt(RADIUS_TAG) : APConfig.PERIPHERALS_CONFIG.chunkyTurtleRadius.get(); + int radius = keys.contains(RADIUS_TAG) ? tag.getInt(RADIUS_TAG) : -1; return new LoadChunkRecord(tag.getString(DIMENSION_NAME_TAG), NBTUtil.chunkPosFromNBT(tag.getCompound(POS_TAG)), radius); } From ffa998de88578f3e38f64e0e00706668b5dce952 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Wed, 10 Apr 2024 07:09:44 -0600 Subject: [PATCH 097/228] fix argument name --- .../de/srendi/advancedperipherals/common/util/ChunkManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java index 693494d8e..d324fd5bf 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java @@ -95,7 +95,7 @@ public synchronized void touch(UUID owner) { // This method is kept for backward compatibility // TODO: remove in next major version @Deprecated - public synchronized boolean removeForceChunk(ServerLevel level, UUID owner, ChunkPos _) { + public synchronized boolean removeForceChunk(ServerLevel level, UUID owner, ChunkPos pos) { return removeForceChunk(level, owner); } From 3fe2f3684d887f823b2050d3158a8b08379adf9f Mon Sep 17 00:00:00 2001 From: zyxkad Date: Wed, 10 Apr 2024 08:54:07 -0600 Subject: [PATCH 098/228] fix styles --- .../addons/computercraft/turtles/TurtleChunkyUpgrade.java | 4 ++-- .../srendi/advancedperipherals/common/util/ChunkManager.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChunkyUpgrade.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChunkyUpgrade.java index fcefbb34f..dc99dd5d2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChunkyUpgrade.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChunkyUpgrade.java @@ -40,8 +40,8 @@ public void update(@NotNull ITurtleAccess turtle, @NotNull TurtleSide side) { super.update(turtle, side); if (APConfig.PERIPHERALS_CONFIG.enableChunkyTurtle.get()) { updateTick++; - if (updateTick < 10) { - // return; // TODO: turtle will stop work when crossing chunks if update every 10 ticks + if (false && updateTick < 10) { + return; // TODO: turtle will stop work when crossing chunks if update every 10 ticks } updateTick = 0; IPeripheral peripheral = turtle.getPeripheral(side); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java index d324fd5bf..cdb6a4125 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java @@ -129,7 +129,7 @@ public synchronized void init() { } initialized = true; - AdvancedPeripherals.debug("Schedule chunk manager init", Level.WARN); + AdvancedPeripherals.debug("Schedule chunk manager init", Level.WARN); final int chunkRadius = APConfig.PERIPHERALS_CONFIG.chunkyTurtleRadius.get(); final Map levels = getServerLevels(); forcedChunks.forEach((uuid, value) -> { @@ -197,7 +197,7 @@ public synchronized void cleanup() { return data; } - private static final Map getServerLevels() { + private static Map getServerLevels() { Map levels = new HashMap<>(); ServerLifecycleHooks.getCurrentServer().getAllLevels().forEach(level -> { String dimensionName = level.dimension().location().toString(); From 8acbbe37423de5612faa54b858e74f9abb65bb0d Mon Sep 17 00:00:00 2001 From: zyxkad Date: Wed, 10 Apr 2024 10:22:53 -0600 Subject: [PATCH 099/228] fix style again --- .../addons/computercraft/turtles/TurtleChunkyUpgrade.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChunkyUpgrade.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChunkyUpgrade.java index dc99dd5d2..7e4d50404 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChunkyUpgrade.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChunkyUpgrade.java @@ -40,9 +40,10 @@ public void update(@NotNull ITurtleAccess turtle, @NotNull TurtleSide side) { super.update(turtle, side); if (APConfig.PERIPHERALS_CONFIG.enableChunkyTurtle.get()) { updateTick++; - if (false && updateTick < 10) { - return; // TODO: turtle will stop work when crossing chunks if update every 10 ticks - } + // TODO: turtle will stop work when crossing chunks if update every 10 ticks + // if (updateTick < 10) { + // return; + // } updateTick = 0; IPeripheral peripheral = turtle.getPeripheral(side); if (peripheral instanceof ChunkyPeripheral chunkyPeripheral) { From 3726da56cb862efbc345bdb4ef26611ad0ce9ae3 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Thu, 11 Apr 2024 12:17:00 -0600 Subject: [PATCH 100/228] synchronized when saving chunk data --- .../advancedperipherals/common/util/ChunkManager.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java index cdb6a4125..4b8dbb912 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java @@ -93,8 +93,9 @@ public synchronized void touch(UUID owner) { } // This method is kept for backward compatibility + // use removeForceChunk without the position argument instead // TODO: remove in next major version - @Deprecated + @Deprecated(forRemoval = true, since = "1.20.1-0.7.39") public synchronized boolean removeForceChunk(ServerLevel level, UUID owner, ChunkPos pos) { return removeForceChunk(level, owner); } @@ -160,7 +161,7 @@ public synchronized void init() { } } } else if (loadedRadius < chunkRadius) { - // otherwise, only do the changed part to save startup time (in case we have a lot chunky turtle) + // otherwise, only do the changed part to reduce startup time (in case we have a lot chunky turtle) for (int x = loadedRadius + 1; x <= chunkRadius; x++) { for (int z = loadedRadius + 1; z <= chunkRadius; z++) { forceChunk(uuid, level, new ChunkPos(pos.x + x, pos.z + z)); @@ -191,7 +192,7 @@ public synchronized void cleanup() { } @Override - public @NotNull CompoundTag save(@NotNull CompoundTag data) { + public synchronized @NotNull CompoundTag save(@NotNull CompoundTag data) { CompoundTag forcedChunksTag = new CompoundTag(); forcedChunks.forEach((key, value) -> forcedChunksTag.put(key.toString(), value.serialize())); return data; From e45127eb23057fcfe7ef3fa73438a00ee51a4800 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Fri, 12 Apr 2024 14:43:33 -0600 Subject: [PATCH 101/228] put forcedChunksTag into the data that is going to be saved and fix ConcurrencyModification when removing record during forEach the map --- .../peripheral/ChunkyPeripheral.java | 13 ++++-- .../common/util/ChunkManager.java | 45 +++++++++++++------ 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChunkyPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChunkyPeripheral.java index 5aca2ff2b..94829b12f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChunkyPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChunkyPeripheral.java @@ -58,7 +58,7 @@ protected void setLoadedChunk(@Nullable ChunkPos newChunk, ChunkManager manager, if (loadedCentralChunk.equals(newChunk)) { return; } - manager.removeForceChunk(level, getUUID(), loadedCentralChunk); + manager.removeForceChunk(level, getUUID()); // Should not be used // level.setChunkForced(loadedChunk.x, loadedChunk.z, false); loadedCentralChunk = null; @@ -83,8 +83,13 @@ public void attach(IComputerAccess computer) { @Override public void detach(@NotNull IComputerAccess computer) { super.detach(computer); - ServerLevel level = (ServerLevel) owner.getLevel(); - ChunkManager manager = ChunkManager.get(Objects.requireNonNull(level)); - setLoadedChunk(null, manager, level); + // Should not remove the loaded chunk when detaching, + // because CC:T will detach all peripherals before server stopped. + // So the chunk record will never be saved if we removed the chunk record when detaching. + // The records will be automatically removed by the ChunkManager if they have not been touched a while ago. + + // ServerLevel level = (ServerLevel) owner.getLevel(); + // ChunkManager manager = ChunkManager.get(Objects.requireNonNull(level)); + // setLoadedChunk(null, manager, level); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java index 4b8dbb912..fa4d38b47 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java @@ -39,6 +39,7 @@ public ChunkManager() { public static ChunkManager load(@NotNull CompoundTag data) { ChunkManager manager = new ChunkManager(); CompoundTag forcedData = data.getCompound(FORCED_CHUNKS_TAG); + AdvancedPeripherals.debug("Loading chunk manager from NBT " + data, Level.WARN); for (String key : forcedData.getAllKeys()) { manager.forcedChunks.put(UUID.fromString(key), LoadChunkRecord.deserialize(forcedData.getCompound(key))); } @@ -70,7 +71,7 @@ private static boolean unforceChunk(UUID owner, ServerLevel level, ChunkPos pos) } public synchronized boolean addForceChunk(ServerLevel level, UUID owner, ChunkPos pos) { - AdvancedPeripherals.debug("Trying to load forced chunk cluster" + pos, Level.WARN); + AdvancedPeripherals.debug("Trying to load forced chunk cluster " + pos, Level.WARN); if (forcedChunks.containsKey(owner)) return true; final int chunkRadius = APConfig.PERIPHERALS_CONFIG.chunkyTurtleRadius.get(); @@ -101,13 +102,22 @@ public synchronized boolean removeForceChunk(ServerLevel level, UUID owner, Chun } public synchronized boolean removeForceChunk(ServerLevel level, UUID owner) { - AdvancedPeripherals.debug("Attempting to unload forced chunk cluster" + owner, Level.WARN); + AdvancedPeripherals.debug("Attempting to unload forced chunk cluster " + owner, Level.WARN); LoadChunkRecord chunkRecord = forcedChunks.get(owner); if (chunkRecord == null) return true; String dimensionName = level.dimension().location().toString(); if (!chunkRecord.getDimensionName().equals(dimensionName)) throw new IllegalArgumentException(String.format("Incorrect dimension! Should be %s instead of %s", chunkRecord.getDimensionName(), dimensionName)); + boolean result = unforceChunkRecord(level, owner, chunkRecord); + if (result) { + forcedChunks.remove(owner); + setDirty(); + } + return result; + } + + public synchronized boolean unforceChunkRecord(ServerLevel level, UUID owner, LoadChunkRecord chunkRecord) { boolean result = true; final ChunkPos pos = chunkRecord.getPos(); final int chunkRadius = chunkRecord.getRadius(); @@ -117,10 +127,6 @@ public synchronized boolean removeForceChunk(ServerLevel level, UUID owner) { result &= unforceChunk(owner, level, new ChunkPos(pos.x + x, pos.z + z)); } } - if (result) { - forcedChunks.remove(owner); - setDirty(); - } return result; } @@ -130,17 +136,19 @@ public synchronized void init() { } initialized = true; - AdvancedPeripherals.debug("Schedule chunk manager init", Level.WARN); + AdvancedPeripherals.debug("Schedule chunk manager init, forcedChunks = " + forcedChunks.size(), Level.WARN); final int chunkRadius = APConfig.PERIPHERALS_CONFIG.chunkyTurtleRadius.get(); final Map levels = getServerLevels(); forcedChunks.forEach((uuid, value) -> { String dimensionName = value.getDimensionName(); ServerLevel level = levels.get(dimensionName); if (level == null) { + AdvancedPeripherals.debug("Skipped not exists dimension " + dimensionName, Level.ERROR); return; } final ChunkPos pos = value.getPos(); final int loadedRadius = value.getRadius(); + AdvancedPeripherals.debug(String.format("Recorded chunk in %s at %s with radius %d", dimensionName, pos, loadedRadius), Level.INFO); if (loadedRadius > chunkRadius) { // clean overflowed load radius for (int x = chunkRadius + 1; x <= loadedRadius; x++) { @@ -177,24 +185,33 @@ public synchronized void init() { public synchronized void cleanup() { AdvancedPeripherals.debug("Schedule chunk manager cleanup", Level.WARN); final Map levels = getServerLevels(); - forcedChunks.forEach((uuid, value) -> { - String dimensionName = value.getDimensionName(); + final Iterator> iterator = forcedChunks.entrySet().iterator(); + while (iterator.hasNext()) { + final Map.Entry entry = iterator.next(); + UUID uuid = entry.getKey(); + LoadChunkRecord chunkRecord = entry.getValue(); + String dimensionName = chunkRecord.getDimensionName(); ServerLevel level = levels.get(dimensionName); if (level == null) { - return; + continue; } - if (value.isValid()) { - return; + if (chunkRecord.isValid()) { + continue; } AdvancedPeripherals.debug(String.format("Purge forced chunk for %s", uuid), Level.WARN); - removeForceChunk(level, uuid); - }); + unforceChunkRecord(level, uuid, chunkRecord); + iterator.remove(); + } } @Override public synchronized @NotNull CompoundTag save(@NotNull CompoundTag data) { + AdvancedPeripherals.debug("Schedule chunk manager save, forcedChunks = " + forcedChunks.size(), Level.WARN); CompoundTag forcedChunksTag = new CompoundTag(); forcedChunks.forEach((key, value) -> forcedChunksTag.put(key.toString(), value.serialize())); + // !!! DO NOT forget to put forcedChunksTag into data !!! + // It will not magically be saved 😅 + data.put(FORCED_CHUNKS_TAG, forcedChunksTag); return data; } From 20f61b56923c547d8a33237514380a7ec25e63cb Mon Sep 17 00:00:00 2001 From: zyxkad Date: Fri, 12 Apr 2024 22:35:04 -0600 Subject: [PATCH 102/228] check history record for equals before skip to add new record with same id --- .../common/util/ChunkManager.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java index fa4d38b47..991545c9b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java @@ -2,7 +2,10 @@ import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.configuration.APConfig; +import net.minecraft.core.registries.Registries; import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.saveddata.SavedData; @@ -72,8 +75,14 @@ private static boolean unforceChunk(UUID owner, ServerLevel level, ChunkPos pos) public synchronized boolean addForceChunk(ServerLevel level, UUID owner, ChunkPos pos) { AdvancedPeripherals.debug("Trying to load forced chunk cluster " + pos, Level.WARN); - if (forcedChunks.containsKey(owner)) - return true; + LoadChunkRecord oldRecord = forcedChunks.get(owner); + if (oldRecord != null) { + ServerLevel oldLevel = getServerLevel(oldRecord.getDimensionName()); + if (oldLevel == level && pos.equals(oldRecord.getPos())) { + return true; + } + unforceChunkRecord(owner, oldRecord, oldLevel); + } final int chunkRadius = APConfig.PERIPHERALS_CONFIG.chunkyTurtleRadius.get(); forcedChunks.put(owner, new LoadChunkRecord(level.dimension().location().toString(), pos, chunkRadius)); setDirty(); @@ -109,7 +118,7 @@ public synchronized boolean removeForceChunk(ServerLevel level, UUID owner) { String dimensionName = level.dimension().location().toString(); if (!chunkRecord.getDimensionName().equals(dimensionName)) throw new IllegalArgumentException(String.format("Incorrect dimension! Should be %s instead of %s", chunkRecord.getDimensionName(), dimensionName)); - boolean result = unforceChunkRecord(level, owner, chunkRecord); + boolean result = unforceChunkRecord(owner, chunkRecord, level); if (result) { forcedChunks.remove(owner); setDirty(); @@ -117,7 +126,7 @@ public synchronized boolean removeForceChunk(ServerLevel level, UUID owner) { return result; } - public synchronized boolean unforceChunkRecord(ServerLevel level, UUID owner, LoadChunkRecord chunkRecord) { + private synchronized boolean unforceChunkRecord(UUID owner, LoadChunkRecord chunkRecord, ServerLevel level) { boolean result = true; final ChunkPos pos = chunkRecord.getPos(); final int chunkRadius = chunkRecord.getRadius(); @@ -199,7 +208,7 @@ public synchronized void cleanup() { continue; } AdvancedPeripherals.debug(String.format("Purge forced chunk for %s", uuid), Level.WARN); - unforceChunkRecord(level, uuid, chunkRecord); + unforceChunkRecord(uuid, chunkRecord, level); iterator.remove(); } } @@ -224,6 +233,11 @@ private static Map getServerLevels() { return levels; } + private static ServerLevel getServerLevel(String name) { + ResourceKey key = ResourceKey.create(Registries.DIMENSION, new ResourceLocation(name)); + return ServerLifecycleHooks.getCurrentServer().getLevel(key); + } + private static class LoadChunkRecord { private static final String POS_TAG = "pos"; From 7c53ac6a461f85942d69923862b7076c1e69926d Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sat, 13 Apr 2024 13:12:19 -0600 Subject: [PATCH 103/228] setDirty after chunk radius updated --- .../common/util/ChunkManager.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java index 991545c9b..033c8435c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java @@ -158,7 +158,17 @@ public synchronized void init() { final ChunkPos pos = value.getPos(); final int loadedRadius = value.getRadius(); AdvancedPeripherals.debug(String.format("Recorded chunk in %s at %s with radius %d", dimensionName, pos, loadedRadius), Level.INFO); - if (loadedRadius > chunkRadius) { + if (loadedRadius == chunkRadius) { + return; + } + if (loadedRadius == -1) { + // if it's coming from old version, just force all + for (int x = -chunkRadius; x <= chunkRadius; x++) { + for (int z = -chunkRadius; z <= chunkRadius; z++) { + forceChunk(uuid, level, new ChunkPos(pos.x + x, pos.z + z)); + } + } + } else if (loadedRadius > chunkRadius) { // clean overflowed load radius for (int x = chunkRadius + 1; x <= loadedRadius; x++) { for (int z = chunkRadius + 1; z <= loadedRadius; z++) { @@ -168,15 +178,6 @@ public synchronized void init() { unforceChunk(uuid, level, new ChunkPos(pos.x - x, pos.z - z)); } } - } - value.setRadius(chunkRadius); - if (loadedRadius == -1) { // if it's coming from old version - // just force all - for (int x = -chunkRadius; x <= chunkRadius; x++) { - for (int z = -chunkRadius; z <= chunkRadius; z++) { - forceChunk(uuid, level, new ChunkPos(pos.x + x, pos.z + z)); - } - } } else if (loadedRadius < chunkRadius) { // otherwise, only do the changed part to reduce startup time (in case we have a lot chunky turtle) for (int x = loadedRadius + 1; x <= chunkRadius; x++) { @@ -188,6 +189,8 @@ public synchronized void init() { } } } + value.setRadius(chunkRadius); + setDirty(); }); } From e00b717dfd5e63811945632d726891c041270be2 Mon Sep 17 00:00:00 2001 From: Kevin Z Date: Sun, 14 Apr 2024 08:02:33 -0600 Subject: [PATCH 104/228] Fix NullPointerException when server ticking Signed-off-by: Kevin Z --- .../advancedperipherals/common/util/ServerWorker.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ServerWorker.java b/src/main/java/de/srendi/advancedperipherals/common/util/ServerWorker.java index 558fee12c..323c21bfd 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ServerWorker.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ServerWorker.java @@ -14,14 +14,19 @@ public class ServerWorker { private static final Queue callQueue = new ArrayDeque<>(); public static void add(final Runnable call) { - callQueue.add(call); + if (call != null) { + callQueue.add(call); + } } @SubscribeEvent public static void serverTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.END) { - while (!callQueue.isEmpty()) { + while (true) { final Runnable runnable = callQueue.poll(); + if (runnable == null) { + return; + } AdvancedPeripherals.debug("Running queued server worker call: " + runnable); runnable.run(); } From ed6a4785a7e93161af2a3e56872b98aed8e92a05 Mon Sep 17 00:00:00 2001 From: Kevin Z Date: Sun, 14 Apr 2024 08:37:26 -0600 Subject: [PATCH 105/228] use ConcurrentLinkedQueue instead of non-thread-safe ArrayDeque --- .../srendi/advancedperipherals/common/util/ServerWorker.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ServerWorker.java b/src/main/java/de/srendi/advancedperipherals/common/util/ServerWorker.java index 323c21bfd..a77bc0a02 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ServerWorker.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ServerWorker.java @@ -5,13 +5,13 @@ import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; -import java.util.ArrayDeque; import java.util.Queue; +import java.util.concurrent.ConcurrentLinkedQueue; @Mod.EventBusSubscriber(modid = AdvancedPeripherals.MOD_ID) public class ServerWorker { - private static final Queue callQueue = new ArrayDeque<>(); + private static final Queue callQueue = new ConcurrentLinkedQueue<>(); public static void add(final Runnable call) { if (call != null) { From 78976fc1ecd7cadb8cf80a378c34e222abe30738 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sun, 14 Apr 2024 09:53:00 -0600 Subject: [PATCH 106/228] add /forceload dump command --- .../common/commands/APCommands.java | 51 ++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java b/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java index 3acb4414c..87ab8af67 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java +++ b/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java @@ -1,8 +1,18 @@ package de.srendi.advancedperipherals.common.commands; import com.mojang.brigadier.exceptions.CommandSyntaxException; + +import dan200.computercraft.core.computer.Environment; +import dan200.computercraft.core.computer.ComputerSide; +import dan200.computercraft.shared.ModRegistry; +import dan200.computercraft.shared.command.text.TableBuilder; +import dan200.computercraft.shared.command.text.ChatHelpers; + import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.TurtleChunkyUpgrade; +import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.ChunkyPeripheral; import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; + import net.minecraft.ChatFormatting; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; @@ -17,10 +27,25 @@ @Mod.EventBusSubscriber(modid = AdvancedPeripherals.MOD_ID) public class APCommands { + public static final String ROOT_LITERAL = "advancedperipherals"; + public static final String FORCELOAD_LITERAL = "forceload"; + static final String FORCELOAD_HELP = + "/" + ROOT_LITERAL + " " + FORCELOAD_LITERAL + " help" + " : show this help message\n" + + "/" + ROOT_LITERAL + " " + FORCELOAD_LITERAL + " dump" + " : show all chunky turtles\n"; @SubscribeEvent public static void register(RegisterCommandsEvent event) { - event.getDispatcher().register(Commands.literal("advancedperipherals").then(Commands.literal("getHashItem").executes(context -> getHashItem(context.getSource())))); + event.getDispatcher().register(Commands.literal(ROOT_LITERAL) + .then(Commands.literal("getHashItem").executes(context -> getHashItem(context.getSource()))) + .then(Commands.literal(FORCELOAD_LITERAL) + .executes(context -> context.getSource().sendSuccess(() -> Component.literal(FORCELOAD_HELP), true)) + .then(Commands.literal("help") + .executes(context -> context.getSource().sendSuccess(() -> Component.literal(FORCELOAD_HELP), true))) + .then(Commands.literal("dump") + .requires(ModRegistry.Permissions.PERMISSION_DUMP) + .executes(context -> forceloadDump(context.getSource())) + ) + ); } private static int getHashItem(CommandSourceStack source) throws CommandSyntaxException { @@ -42,4 +67,28 @@ private static int getHashItem(CommandSourceStack source) throws CommandSyntaxEx .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("Copy"))))), true); return 1; } + + private static int forceloadDump(CommandSourceStack source) throws CommandSyntaxException { + TableBuilder table = new TableBuilder("All Chunky Turtles", "Computer", "Position"); + + List computers = new ArrayList<>(ServerContext.get(source.getServer()).registry().getComputers().stream().filter((computer) -> { + Environment env = computer.getComputer().getEnvionment(); + for (ComputerSide side : ComputerSide.values()) { + if (env.getPeripheral(side) instanceof ChunkyPeripheral) { + return true; + } + } + return false; + }).sorted((a, b) -> a.getID() - b.getID())); + + for (ServerComputer computer : computers) { + table.row( + computer.getID(), + ChatHelpers.position(computer.getPosition()) + ); + } + + table.display(source); + return computers.size(); + } } From 2ffdb0b87fb08737aa20d2b618e1af18877b7956 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sun, 14 Apr 2024 10:04:27 -0600 Subject: [PATCH 107/228] apply patch from https://github.com/IntelligenceModding/AdvancedPeripherals/pull/576.patch --- .../peripheral/ChunkyPeripheral.java | 43 ++-- .../turtles/TurtleChunkyUpgrade.java | 13 +- .../common/commands/APCommands.java | 51 +++- .../common/util/ChunkManager.java | 238 ++++++++++++------ 4 files changed, 247 insertions(+), 98 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChunkyPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChunkyPeripheral.java index b244e3eb1..94829b12f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChunkyPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChunkyPeripheral.java @@ -20,7 +20,7 @@ public class ChunkyPeripheral extends BasePeripheral { public static final String PERIPHERAL_TYPE = "chunky"; private static final String UUID_TAG = "uuid"; - private @Nullable ChunkPos loadedCentralChunk; + private @Nullable ChunkPos loadedCentralChunk = null; public ChunkyPeripheral(ITurtleAccess turtle, TurtleSide side) { super(PERIPHERAL_TYPE, new TurtlePeripheralOwner(turtle, side)); @@ -45,36 +45,51 @@ public boolean isEnabled() { } public void updateChunkState() { + // TODO: should find someway to update after turtle moved or while moving, but not every tick ServerLevel level = (ServerLevel) getLevel(); ChunkManager manager = ChunkManager.get(level); ChunkPos currentChunk = getChunkPos(); - if (loadedCentralChunk == null || !loadedCentralChunk.equals(currentChunk)) { - setLoadedChunk(currentChunk, manager, level); - } else { - manager.touch(getUUID()); - } + setLoadedChunk(currentChunk, manager, level); + manager.touch(getUUID()); } protected void setLoadedChunk(@Nullable ChunkPos newChunk, ChunkManager manager, ServerLevel level) { if (loadedCentralChunk != null) { - manager.removeForceChunk(level, getUUID(), loadedCentralChunk); - //Should not be used - //level.setChunkForced(loadedChunk.x, loadedChunk.z, false); + if (loadedCentralChunk.equals(newChunk)) { + return; + } + manager.removeForceChunk(level, getUUID()); + // Should not be used + // level.setChunkForced(loadedChunk.x, loadedChunk.z, false); loadedCentralChunk = null; } if (newChunk != null) { loadedCentralChunk = newChunk; manager.addForceChunk(level, getUUID(), loadedCentralChunk); - //Should not be used - //level.setChunkForced(newChunk.x, newChunk.z, true); + // Should not be used + // level.setChunkForced(newChunk.x, newChunk.z, true); } } @Override - public void detach(@NotNull IComputerAccess computer) { - super.detach(computer); + public void attach(IComputerAccess computer) { + super.attach(computer); ServerLevel level = (ServerLevel) owner.getLevel(); ChunkManager manager = ChunkManager.get(Objects.requireNonNull(level)); - setLoadedChunk(null, manager, level); + ChunkPos currentChunk = getChunkPos(); + setLoadedChunk(currentChunk, manager, level); + } + + @Override + public void detach(@NotNull IComputerAccess computer) { + super.detach(computer); + // Should not remove the loaded chunk when detaching, + // because CC:T will detach all peripherals before server stopped. + // So the chunk record will never be saved if we removed the chunk record when detaching. + // The records will be automatically removed by the ChunkManager if they have not been touched a while ago. + + // ServerLevel level = (ServerLevel) owner.getLevel(); + // ChunkManager manager = ChunkManager.get(Objects.requireNonNull(level)); + // setLoadedChunk(null, manager, level); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChunkyUpgrade.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChunkyUpgrade.java index aec241d37..7e4d50404 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChunkyUpgrade.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChunkyUpgrade.java @@ -12,6 +12,7 @@ import org.jetbrains.annotations.NotNull; public class TurtleChunkyUpgrade extends PeripheralTurtleUpgrade { + private int updateTick = 0; public TurtleChunkyUpgrade(ResourceLocation id, ItemStack stack) { super(id, stack); @@ -19,7 +20,7 @@ public TurtleChunkyUpgrade(ResourceLocation id, ItemStack stack) { @Override public ModelResourceLocation getLeftModel() { - return null; //Null, the turtle uses the chunk controller item model. See BaseTurtle.java + return null; // Null, the turtle uses the chunk controller item model. See BaseTurtle.java } @Override @@ -34,10 +35,16 @@ protected ChunkyPeripheral buildPeripheral(@NotNull ITurtleAccess turtle, @NotNu @Override public void update(@NotNull ITurtleAccess turtle, @NotNull TurtleSide side) { - //Add a chunk to the Chunk Manager every 10 ticks, if it's not already forced. - //The turtle can move, so we need to do that. + // Add a chunk to the Chunk Manager every 10 ticks, if it's not already forced. + // The turtle can move, so we need to do that. super.update(turtle, side); if (APConfig.PERIPHERALS_CONFIG.enableChunkyTurtle.get()) { + updateTick++; + // TODO: turtle will stop work when crossing chunks if update every 10 ticks + // if (updateTick < 10) { + // return; + // } + updateTick = 0; IPeripheral peripheral = turtle.getPeripheral(side); if (peripheral instanceof ChunkyPeripheral chunkyPeripheral) { chunkyPeripheral.updateChunkState(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java b/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java index cd606f38e..f2d61740d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java +++ b/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java @@ -1,8 +1,18 @@ package de.srendi.advancedperipherals.common.commands; import com.mojang.brigadier.exceptions.CommandSyntaxException; + +import dan200.computercraft.core.computer.Environment; +import dan200.computercraft.core.computer.ComputerSide; +import dan200.computercraft.shared.ModRegistry; +import dan200.computercraft.shared.command.text.TableBuilder; +import dan200.computercraft.shared.command.text.ChatHelpers; + import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.TurtleChunkyUpgrade; +import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.ChunkyPeripheral; import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; + import net.minecraft.ChatFormatting; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; @@ -17,10 +27,25 @@ @Mod.EventBusSubscriber(modid = AdvancedPeripherals.MOD_ID) public class APCommands { + public static final String ROOT_LITERAL = "advancedperipherals"; + public static final String FORCELOAD_LITERAL = "forceload"; + static final String FORCELOAD_HELP = + "/" + ROOT_LITERAL + " " + FORCELOAD_LITERAL + " help" + " : show this help message\n" + + "/" + ROOT_LITERAL + " " + FORCELOAD_LITERAL + " dump" + " : show all chunky turtles\n"; @SubscribeEvent public static void register(RegisterCommandsEvent event) { - event.getDispatcher().register(Commands.literal("advancedperipherals").then(Commands.literal("getHashItem").executes(context -> getHashItem(context.getSource())))); + event.getDispatcher().register(Commands.literal(ROOT_LITERAL) + .then(Commands.literal("getHashItem").executes(context -> getHashItem(context.getSource()))) + .then(Commands.literal(FORCELOAD_LITERAL) + .executes(context -> context.getSource().sendSuccess(() -> Component.literal(FORCELOAD_HELP), true)) + .then(Commands.literal("help") + .executes(context -> context.getSource().sendSuccess(() -> Component.literal(FORCELOAD_HELP), true))) + .then(Commands.literal("dump") + .requires(ModRegistry.Permissions.PERMISSION_DUMP) + .executes(context -> forceloadDump(context.getSource())) + ) + ); } private static int getHashItem(CommandSourceStack source) throws CommandSyntaxException { @@ -42,4 +67,28 @@ private static int getHashItem(CommandSourceStack source) throws CommandSyntaxEx .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("Copy"))))), true); return 1; } + + private static int forceloadDump(CommandSourceStack source) throws CommandSyntaxException { + TableBuilder table = new TableBuilder("All Chunky Turtles", "Computer", "Position"); + + List computers = new ArrayList<>(ServerContext.get(source.getServer()).registry().getComputers().stream().filter((computer) -> { + Environment env = computer.getComputer().getEnvionment(); + for (ComputerSide side : ComputerSide.values()) { + if (env.getPeripheral(side) instanceof ChunkyPeripheral) { + return true; + } + } + return false; + }).sorted((a, b) -> a.getID() - b.getID())); + + for (ServerComputer computer : computers) { + table.row( + computer.getID(), + ChatHelpers.position(computer.getPosition()) + ); + } + + table.display(source); + return computers.size(); + } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java index dbd324dc8..033c8435c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java @@ -2,14 +2,16 @@ import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.configuration.APConfig; +import net.minecraft.core.registries.Registries; import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.saveddata.SavedData; import net.minecraftforge.common.world.ForgeChunkManager; import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.server.ServerStartedEvent; -import net.minecraftforge.event.server.ServerStoppingEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.server.ServerLifecycleHooks; @@ -40,17 +42,13 @@ public ChunkManager() { public static ChunkManager load(@NotNull CompoundTag data) { ChunkManager manager = new ChunkManager(); CompoundTag forcedData = data.getCompound(FORCED_CHUNKS_TAG); + AdvancedPeripherals.debug("Loading chunk manager from NBT " + data, Level.WARN); for (String key : forcedData.getAllKeys()) { manager.forcedChunks.put(UUID.fromString(key), LoadChunkRecord.deserialize(forcedData.getCompound(key))); } return manager; } - @SubscribeEvent - public static void beforeServerStopped(ServerStoppingEvent event) { - ChunkManager.get(event.getServer().overworld()).stop(); - } - @SubscribeEvent public static void afterServerStarted(ServerStartedEvent event) { ChunkManager.get(event.getServer().overworld()).init(); @@ -59,55 +57,68 @@ public static void afterServerStarted(ServerStartedEvent event) { @SubscribeEvent public static void serverTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.END) { - tickCounter++; - if (tickCounter % (APConfig.PERIPHERALS_CONFIG.chunkLoadValidTime.get() / 2) == 0) { + tickCounter += 2; + if (tickCounter >= APConfig.PERIPHERALS_CONFIG.chunkLoadValidTime.get()) { + tickCounter = 0; ChunkManager.get(ServerLifecycleHooks.getCurrentServer().overworld()).cleanup(); } } } + private static boolean forceChunk(UUID owner, ServerLevel level, ChunkPos pos) { + return ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, owner, pos.x, pos.z, true, true); + } + + private static boolean unforceChunk(UUID owner, ServerLevel level, ChunkPos pos) { + return ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, owner, pos.x, pos.z, false, true); + } + public synchronized boolean addForceChunk(ServerLevel level, UUID owner, ChunkPos pos) { - AdvancedPeripherals.debug("Trying to load forced chunk cluster" + pos, Level.WARN); - if (forcedChunks.containsKey(owner)) return true; - forcedChunks.put(owner, new LoadChunkRecord(level.dimension().location().toString(), pos)); - setDirty(); - int chunkRadius = APConfig.PERIPHERALS_CONFIG.chunkyTurtleRadius.get(); - if (chunkRadius == 0) { - return ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, owner, pos.x, pos.z, true, true); + AdvancedPeripherals.debug("Trying to load forced chunk cluster " + pos, Level.WARN); + LoadChunkRecord oldRecord = forcedChunks.get(owner); + if (oldRecord != null) { + ServerLevel oldLevel = getServerLevel(oldRecord.getDimensionName()); + if (oldLevel == level && pos.equals(oldRecord.getPos())) { + return true; + } + unforceChunkRecord(owner, oldRecord, oldLevel); } + final int chunkRadius = APConfig.PERIPHERALS_CONFIG.chunkyTurtleRadius.get(); + forcedChunks.put(owner, new LoadChunkRecord(level.dimension().location().toString(), pos, chunkRadius)); + setDirty(); boolean result = true; - for (int x = chunkRadius * -1; x < chunkRadius; x++) { - for (int z = chunkRadius * -1; z < chunkRadius; z++) { - result &= ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, owner, pos.x + x, pos.z + z, true, true); + for (int x = -chunkRadius; x <= chunkRadius; x++) { + for (int z = -chunkRadius; z <= chunkRadius; z++) { + result &= forceChunk(owner, level, new ChunkPos(pos.x + x, pos.z + z)); } } return result; } public synchronized void touch(UUID owner) { - if (forcedChunks.containsKey(owner)) - forcedChunks.get(owner).touch(); + LoadChunkRecord forcedChunk = forcedChunks.get(owner); + if (forcedChunk != null) { + forcedChunk.touch(); + } } + // This method is kept for backward compatibility + // use removeForceChunk without the position argument instead + // TODO: remove in next major version + @Deprecated(forRemoval = true, since = "1.20.1-0.7.39") public synchronized boolean removeForceChunk(ServerLevel level, UUID owner, ChunkPos pos) { - AdvancedPeripherals.debug("Trying to unload forced chunk cluster" + pos, Level.WARN); - if (!forcedChunks.containsKey(owner)) - return true; + return removeForceChunk(level, owner); + } + + public synchronized boolean removeForceChunk(ServerLevel level, UUID owner) { + AdvancedPeripherals.debug("Attempting to unload forced chunk cluster " + owner, Level.WARN); LoadChunkRecord chunkRecord = forcedChunks.get(owner); + if (chunkRecord == null) + return true; String dimensionName = level.dimension().location().toString(); if (!chunkRecord.getDimensionName().equals(dimensionName)) throw new IllegalArgumentException(String.format("Incorrect dimension! Should be %s instead of %s", chunkRecord.getDimensionName(), dimensionName)); - boolean result = true; - int chunkRadius = APConfig.PERIPHERALS_CONFIG.chunkyTurtleRadius.get(); - if (chunkRadius == 0) { - result = ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, owner, pos.x, pos.z, false, true); - } else { - for (int x = chunkRadius * -1; x < chunkRadius; x++) { - for (int z = chunkRadius * -1; z < chunkRadius; z++) { - result &= ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, owner, pos.x + x, pos.z + z, true, true); - } - } - } + boolean result = unforceChunkRecord(owner, chunkRecord, level); if (result) { forcedChunks.remove(owner); setDirty(); @@ -115,85 +126,143 @@ public synchronized boolean removeForceChunk(ServerLevel level, UUID owner, Chun return result; } - public synchronized void init() { - if (!initialized) { - AdvancedPeripherals.debug("Schedule chunk manager init", Level.WARN); - int chunkRadius = APConfig.PERIPHERALS_CONFIG.chunkyTurtleRadius.get(); - ServerLifecycleHooks.getCurrentServer().getAllLevels().forEach(level -> { - String dimensionName = level.dimension().location().toString(); - forcedChunks.entrySet().stream().filter(entry -> entry.getValue().getDimensionName().equals(dimensionName)).forEach(entry -> { - if (chunkRadius == 0) { - ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, entry.getKey(), entry.getValue().getPos().x, entry.getValue().getPos().z, true, true); - } - for (int x = chunkRadius * -1; x < chunkRadius; x++) { - for (int z = chunkRadius * -1; z < chunkRadius; z++) { - ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, entry.getKey(), entry.getValue().getPos().x + x, entry.getValue().getPos().z + z, true, true); - } - } - }); - }); - initialized = true; + private synchronized boolean unforceChunkRecord(UUID owner, LoadChunkRecord chunkRecord, ServerLevel level) { + boolean result = true; + final ChunkPos pos = chunkRecord.getPos(); + final int chunkRadius = chunkRecord.getRadius(); + AdvancedPeripherals.debug(String.format("Trying to unload forced chunk cluster %s at %s with radius %d", owner, pos, chunkRadius), Level.WARN); + for (int x = -chunkRadius; x <= chunkRadius; x++) { + for (int z = -chunkRadius; z <= chunkRadius; z++) { + result &= unforceChunk(owner, level, new ChunkPos(pos.x + x, pos.z + z)); + } } + return result; } - public synchronized void stop() { + public synchronized void init() { if (initialized) { - AdvancedPeripherals.debug("Schedule chunk manager stop", Level.WARN); - int chunkRadius = APConfig.PERIPHERALS_CONFIG.chunkyTurtleRadius.get(); - ServerLifecycleHooks.getCurrentServer().getAllLevels().forEach(level -> { - String dimensionName = level.dimension().location().toString(); - forcedChunks.entrySet().stream().filter(entry -> entry.getValue().getDimensionName().equals(dimensionName)).forEach(entry -> { - if (chunkRadius == 0) { - ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, entry.getKey(), entry.getValue().getPos().x, entry.getValue().getPos().z, false, true); + return; + } + initialized = true; + + AdvancedPeripherals.debug("Schedule chunk manager init, forcedChunks = " + forcedChunks.size(), Level.WARN); + final int chunkRadius = APConfig.PERIPHERALS_CONFIG.chunkyTurtleRadius.get(); + final Map levels = getServerLevels(); + forcedChunks.forEach((uuid, value) -> { + String dimensionName = value.getDimensionName(); + ServerLevel level = levels.get(dimensionName); + if (level == null) { + AdvancedPeripherals.debug("Skipped not exists dimension " + dimensionName, Level.ERROR); + return; + } + final ChunkPos pos = value.getPos(); + final int loadedRadius = value.getRadius(); + AdvancedPeripherals.debug(String.format("Recorded chunk in %s at %s with radius %d", dimensionName, pos, loadedRadius), Level.INFO); + if (loadedRadius == chunkRadius) { + return; + } + if (loadedRadius == -1) { + // if it's coming from old version, just force all + for (int x = -chunkRadius; x <= chunkRadius; x++) { + for (int z = -chunkRadius; z <= chunkRadius; z++) { + forceChunk(uuid, level, new ChunkPos(pos.x + x, pos.z + z)); } - for (int x = chunkRadius * -1; x < chunkRadius; x++) { - for (int z = chunkRadius * -1; z < chunkRadius; z++) { - ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, entry.getKey(), entry.getValue().getPos().x + x, entry.getValue().getPos().z + z, false, true); - } + } + } else if (loadedRadius > chunkRadius) { + // clean overflowed load radius + for (int x = chunkRadius + 1; x <= loadedRadius; x++) { + for (int z = chunkRadius + 1; z <= loadedRadius; z++) { + unforceChunk(uuid, level, new ChunkPos(pos.x + x, pos.z + z)); + unforceChunk(uuid, level, new ChunkPos(pos.x + x, pos.z - z)); + unforceChunk(uuid, level, new ChunkPos(pos.x - x, pos.z + z)); + unforceChunk(uuid, level, new ChunkPos(pos.x - x, pos.z - z)); } - }); - }); - initialized = false; - } + } + } else if (loadedRadius < chunkRadius) { + // otherwise, only do the changed part to reduce startup time (in case we have a lot chunky turtle) + for (int x = loadedRadius + 1; x <= chunkRadius; x++) { + for (int z = loadedRadius + 1; z <= chunkRadius; z++) { + forceChunk(uuid, level, new ChunkPos(pos.x + x, pos.z + z)); + forceChunk(uuid, level, new ChunkPos(pos.x + x, pos.z - z)); + forceChunk(uuid, level, new ChunkPos(pos.x - x, pos.z + z)); + forceChunk(uuid, level, new ChunkPos(pos.x - x, pos.z - z)); + } + } + } + value.setRadius(chunkRadius); + setDirty(); + }); } public synchronized void cleanup() { AdvancedPeripherals.debug("Schedule chunk manager cleanup", Level.WARN); - ServerLifecycleHooks.getCurrentServer().getAllLevels().forEach(level -> { - String dimensionName = level.dimension().location().toString(); - List purgeList = new ArrayList<>(); - forcedChunks.entrySet().stream().filter(entry -> entry.getValue().getDimensionName().equals(dimensionName) && !entry.getValue().isValid()).forEach(entry -> purgeList.add(entry.getKey())); - purgeList.forEach(uuid -> { - AdvancedPeripherals.debug(String.format("Purge forced chunk for %s", uuid), Level.WARN); - removeForceChunk(level, uuid, forcedChunks.get(uuid).getPos()); - }); - }); + final Map levels = getServerLevels(); + final Iterator> iterator = forcedChunks.entrySet().iterator(); + while (iterator.hasNext()) { + final Map.Entry entry = iterator.next(); + UUID uuid = entry.getKey(); + LoadChunkRecord chunkRecord = entry.getValue(); + String dimensionName = chunkRecord.getDimensionName(); + ServerLevel level = levels.get(dimensionName); + if (level == null) { + continue; + } + if (chunkRecord.isValid()) { + continue; + } + AdvancedPeripherals.debug(String.format("Purge forced chunk for %s", uuid), Level.WARN); + unforceChunkRecord(uuid, chunkRecord, level); + iterator.remove(); + } } @Override - public @NotNull CompoundTag save(@NotNull CompoundTag data) { + public synchronized @NotNull CompoundTag save(@NotNull CompoundTag data) { + AdvancedPeripherals.debug("Schedule chunk manager save, forcedChunks = " + forcedChunks.size(), Level.WARN); CompoundTag forcedChunksTag = new CompoundTag(); forcedChunks.forEach((key, value) -> forcedChunksTag.put(key.toString(), value.serialize())); + // !!! DO NOT forget to put forcedChunksTag into data !!! + // It will not magically be saved 😅 + data.put(FORCED_CHUNKS_TAG, forcedChunksTag); return data; } + private static Map getServerLevels() { + Map levels = new HashMap<>(); + ServerLifecycleHooks.getCurrentServer().getAllLevels().forEach(level -> { + String dimensionName = level.dimension().location().toString(); + levels.put(dimensionName, level); + }); + return levels; + } + + private static ServerLevel getServerLevel(String name) { + ResourceKey key = ResourceKey.create(Registries.DIMENSION, new ResourceLocation(name)); + return ServerLifecycleHooks.getCurrentServer().getLevel(key); + } + private static class LoadChunkRecord { private static final String POS_TAG = "pos"; private static final String DIMENSION_NAME_TAG = "dimensionName"; + private static final String RADIUS_TAG = "radius"; private final @NotNull String dimensionName; private final @NotNull ChunkPos pos; + private int radius; private long lastTouch; - LoadChunkRecord(@NotNull String dimensionName, @NotNull ChunkPos pos) { + LoadChunkRecord(@NotNull String dimensionName, @NotNull ChunkPos pos, int radius) { this.dimensionName = dimensionName; this.pos = pos; + this.radius = radius; this.lastTouch = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC); } public static LoadChunkRecord deserialize(@NotNull CompoundTag tag) { - return new LoadChunkRecord(tag.getString(DIMENSION_NAME_TAG), NBTUtil.chunkPosFromNBT(tag.getCompound(POS_TAG))); + Set keys = tag.getAllKeys(); + int radius = keys.contains(RADIUS_TAG) ? tag.getInt(RADIUS_TAG) : -1; + return new LoadChunkRecord(tag.getString(DIMENSION_NAME_TAG), NBTUtil.chunkPosFromNBT(tag.getCompound(POS_TAG)), radius); } public @NotNull ChunkPos getPos() { @@ -204,6 +273,14 @@ public static LoadChunkRecord deserialize(@NotNull CompoundTag tag) { return dimensionName; } + public int getRadius() { + return radius; + } + + public void setRadius(int radius) { + this.radius = radius; + } + public void touch() { lastTouch = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC); } @@ -217,6 +294,7 @@ public boolean isValid() { CompoundTag tag = new CompoundTag(); tag.putString(DIMENSION_NAME_TAG, dimensionName); tag.put(POS_TAG, NBTUtil.toNBT(pos)); + tag.putInt(RADIUS_TAG, radius); return tag; } } From 186f7b4d7efe7856aa28ccaf5ef6ae8e364ea0a9 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sun, 14 Apr 2024 10:26:39 -0600 Subject: [PATCH 108/228] fix command --- .../common/commands/APCommands.java | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java b/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java index 87ab8af67..7ca0ebaed 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java +++ b/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java @@ -2,14 +2,15 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; -import dan200.computercraft.core.computer.Environment; import dan200.computercraft.core.computer.ComputerSide; +import dan200.computercraft.core.computer.Environment; import dan200.computercraft.shared.ModRegistry; -import dan200.computercraft.shared.command.text.TableBuilder; import dan200.computercraft.shared.command.text.ChatHelpers; +import dan200.computercraft.shared.command.text.TableBuilder; +import dan200.computercraft.shared.computer.core.ServerComputer; +import dan200.computercraft.shared.computer.core.ServerContext; import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.TurtleChunkyUpgrade; import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.ChunkyPeripheral; import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; @@ -38,12 +39,12 @@ public static void register(RegisterCommandsEvent event) { event.getDispatcher().register(Commands.literal(ROOT_LITERAL) .then(Commands.literal("getHashItem").executes(context -> getHashItem(context.getSource()))) .then(Commands.literal(FORCELOAD_LITERAL) - .executes(context -> context.getSource().sendSuccess(() -> Component.literal(FORCELOAD_HELP), true)) + .executes(context -> forceloadHelp(context.getSource())) .then(Commands.literal("help") - .executes(context -> context.getSource().sendSuccess(() -> Component.literal(FORCELOAD_HELP), true))) + .executes(context -> forceloadHelp(context.getSource()))) .then(Commands.literal("dump") .requires(ModRegistry.Permissions.PERMISSION_DUMP) - .executes(context -> forceloadDump(context.getSource())) + .executes(context -> forceloadDump(context.getSource()))) ) ); } @@ -68,27 +69,41 @@ private static int getHashItem(CommandSourceStack source) throws CommandSyntaxEx return 1; } + private static int forceloadHelp(CommandSourceStack source) throws CommandSyntaxException { + source.sendSuccess(() -> Component.literal(FORCELOAD_HELP), true); + return 1; + } + private static int forceloadDump(CommandSourceStack source) throws CommandSyntaxException { TableBuilder table = new TableBuilder("All Chunky Turtles", "Computer", "Position"); - List computers = new ArrayList<>(ServerContext.get(source.getServer()).registry().getComputers().stream().filter((computer) -> { - Environment env = computer.getComputer().getEnvionment(); + ServerComputer[] computers = ServerContext.get(source.getServer()).registry().getComputers().stream().filter((computer) -> { + Environment env = computer.getComputer().getEnvironment(); for (ComputerSide side : ComputerSide.values()) { if (env.getPeripheral(side) instanceof ChunkyPeripheral) { return true; } } return false; - }).sorted((a, b) -> a.getID() - b.getID())); + }).sorted((a, b) -> a.getID() - b.getID()).toArray(size -> new ServerComputer[size]); for (ServerComputer computer : computers) { table.row( - computer.getID(), + makeComputerDumpCommand(computer), ChatHelpers.position(computer.getPosition()) ); } table.display(source); - return computers.size(); + return computers.length; + } + + + private static Component makeComputerDumpCommand(ServerComputer computer) { + return ChatHelpers.link( + Component.literal("#" + computer.getID()), + String.format("/computercraft dump %d", computer.getID()), + Component.translatable("commands.computercraft.dump.action") + ); } } From 8e38957cb71e7b2af169b862675e13d9176a1dc1 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sun, 14 Apr 2024 10:32:04 -0600 Subject: [PATCH 109/228] apply patch https://github.com/IntelligenceModding/AdvancedPeripherals/commit/186f7b4d7efe7856aa28ccaf5ef6ae8e364ea0a9.patch --- .../common/commands/APCommands.java | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java b/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java index f2d61740d..5bf892915 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java +++ b/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java @@ -2,14 +2,15 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; -import dan200.computercraft.core.computer.Environment; import dan200.computercraft.core.computer.ComputerSide; +import dan200.computercraft.core.computer.Environment; import dan200.computercraft.shared.ModRegistry; -import dan200.computercraft.shared.command.text.TableBuilder; import dan200.computercraft.shared.command.text.ChatHelpers; +import dan200.computercraft.shared.command.text.TableBuilder; +import dan200.computercraft.shared.computer.core.ServerComputer; +import dan200.computercraft.shared.computer.core.ServerContext; import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.TurtleChunkyUpgrade; import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.ChunkyPeripheral; import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; @@ -38,12 +39,12 @@ public static void register(RegisterCommandsEvent event) { event.getDispatcher().register(Commands.literal(ROOT_LITERAL) .then(Commands.literal("getHashItem").executes(context -> getHashItem(context.getSource()))) .then(Commands.literal(FORCELOAD_LITERAL) - .executes(context -> context.getSource().sendSuccess(() -> Component.literal(FORCELOAD_HELP), true)) + .executes(context -> forceloadHelp(context.getSource())) .then(Commands.literal("help") - .executes(context -> context.getSource().sendSuccess(() -> Component.literal(FORCELOAD_HELP), true))) + .executes(context -> forceloadHelp(context.getSource()))) .then(Commands.literal("dump") .requires(ModRegistry.Permissions.PERMISSION_DUMP) - .executes(context -> forceloadDump(context.getSource())) + .executes(context -> forceloadDump(context.getSource()))) ) ); } @@ -68,27 +69,41 @@ private static int getHashItem(CommandSourceStack source) throws CommandSyntaxEx return 1; } + private static int forceloadHelp(CommandSourceStack source) throws CommandSyntaxException { + source.sendSuccess(() -> Component.literal(FORCELOAD_HELP), true); + return 1; + } + private static int forceloadDump(CommandSourceStack source) throws CommandSyntaxException { TableBuilder table = new TableBuilder("All Chunky Turtles", "Computer", "Position"); - List computers = new ArrayList<>(ServerContext.get(source.getServer()).registry().getComputers().stream().filter((computer) -> { - Environment env = computer.getComputer().getEnvionment(); + ServerComputer[] computers = ServerContext.get(source.getServer()).registry().getComputers().stream().filter((computer) -> { + Environment env = computer.getComputer().getEnvironment(); for (ComputerSide side : ComputerSide.values()) { if (env.getPeripheral(side) instanceof ChunkyPeripheral) { return true; } } return false; - }).sorted((a, b) -> a.getID() - b.getID())); + }).sorted((a, b) -> a.getID() - b.getID()).toArray(size -> new ServerComputer[size]); for (ServerComputer computer : computers) { table.row( - computer.getID(), + makeComputerDumpCommand(computer), ChatHelpers.position(computer.getPosition()) ); } table.display(source); - return computers.size(); + return computers.length; + } + + + private static Component makeComputerDumpCommand(ServerComputer computer) { + return ChatHelpers.link( + Component.literal("#" + computer.getID()), + String.format("/computercraft dump %d", computer.getID()), + Component.translatable("commands.computercraft.dump.action") + ); } } From 0b2509cdb245a87b757a81559376cd95bf3dafb1 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sun, 14 Apr 2024 10:38:54 -0600 Subject: [PATCH 110/228] update Deprecated tag verion --- .../de/srendi/advancedperipherals/common/util/ChunkManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java index 033c8435c..4b8a2bb73 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java @@ -105,7 +105,7 @@ public synchronized void touch(UUID owner) { // This method is kept for backward compatibility // use removeForceChunk without the position argument instead // TODO: remove in next major version - @Deprecated(forRemoval = true, since = "1.20.1-0.7.39") + @Deprecated(forRemoval = true, since = "1.19.2-0.7.36") public synchronized boolean removeForceChunk(ServerLevel level, UUID owner, ChunkPos pos) { return removeForceChunk(level, owner); } From f8d90223c07ffc6d9e6945fd57d3207e8d118aeb Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sun, 14 Apr 2024 16:43:04 -0600 Subject: [PATCH 111/228] switch APIs from 1.20.1 to 1.19.2 --- .../advancedperipherals/common/commands/APCommands.java | 6 +++--- .../advancedperipherals/common/util/ChunkManager.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java b/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java index 5bf892915..ea94ee805 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java +++ b/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java @@ -4,7 +4,7 @@ import dan200.computercraft.core.computer.ComputerSide; import dan200.computercraft.core.computer.Environment; -import dan200.computercraft.shared.ModRegistry; +import dan200.computercraft.shared.command.UserLevel; import dan200.computercraft.shared.command.text.ChatHelpers; import dan200.computercraft.shared.command.text.TableBuilder; import dan200.computercraft.shared.computer.core.ServerComputer; @@ -43,7 +43,7 @@ public static void register(RegisterCommandsEvent event) { .then(Commands.literal("help") .executes(context -> forceloadHelp(context.getSource()))) .then(Commands.literal("dump") - .requires(ModRegistry.Permissions.PERMISSION_DUMP) + .requires(UserLevel.OWNER_OP) .executes(context -> forceloadDump(context.getSource()))) ) ); @@ -70,7 +70,7 @@ private static int getHashItem(CommandSourceStack source) throws CommandSyntaxEx } private static int forceloadHelp(CommandSourceStack source) throws CommandSyntaxException { - source.sendSuccess(() -> Component.literal(FORCELOAD_HELP), true); + source.sendSuccess(Component.literal(FORCELOAD_HELP), true); return 1; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java index 4b8a2bb73..ea9294a30 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java @@ -2,7 +2,7 @@ import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.configuration.APConfig; -import net.minecraft.core.registries.Registries; +import net.minecraft.core.Registry; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; @@ -237,7 +237,7 @@ private static Map getServerLevels() { } private static ServerLevel getServerLevel(String name) { - ResourceKey key = ResourceKey.create(Registries.DIMENSION, new ResourceLocation(name)); + ResourceKey key = ResourceKey.create(Registry.DIMENSION_REGISTRY, new ResourceLocation(name)); return ServerLifecycleHooks.getCurrentServer().getLevel(key); } From 764a54d8251bbdcc0742389852efdd65a94b2d9c Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 15 Apr 2024 18:07:26 +0200 Subject: [PATCH 112/228] Initial work to support 1.20.4 Still needs a lot of work, but the gradle stuff is prepared for neo --- build.gradle | 277 +++++------------- gradle.properties | 13 +- gradle/wrapper/gradle-wrapper.jar | Bin 62076 -> 0 bytes gradle/wrapper/gradle-wrapper.properties | 3 +- settings.gradle | 9 +- .../advancedperipherals/APCreativeTab.java | 2 +- .../AdvancedPeripherals.java | 12 +- .../client/ClientRegistry.java | 12 +- .../client/KeyBindings.java | 2 +- .../common/addons/APAddons.java | 8 +- .../addons/appliedenergistics/AppEngApi.java | 12 +- .../appliedenergistics/MeFluidHandler.java | 2 +- .../IntegrationPeripheralProvider.java | 2 +- .../integrations/NoteBlockIntegration.java | 2 +- .../operations/AutomataCoreTier.java | 2 +- .../operations/SimpleFreeOperation.java | 2 +- .../operations/SingleOperation.java | 2 +- .../operations/SphereOperation.java | 2 +- .../owner/TileEntityFuelAbility.java | 2 +- .../peripheral/BlockReaderPeripheral.java | 2 +- .../peripheral/ChatBoxPeripheral.java | 2 +- .../peripheral/ColonyPeripheral.java | 2 +- .../EnvironmentDetectorPeripheral.java | 8 +- .../peripheral/GeoScannerPeripheral.java | 4 +- .../InventoryManagerPeripheral.java | 10 +- .../peripheral/MeBridgePeripheral.java | 4 +- .../peripheral/PlayerDetectorPeripheral.java | 2 +- .../peripheral/RsBridgePeripheral.java | 6 +- .../plugins/AutomataChargingPlugin.java | 2 +- .../plugins/AutomataItemSuckPlugin.java | 2 +- .../plugins/AutomataLookPlugin.java | 2 +- .../addons/create/BasinIntegration.java | 10 +- .../addons/create/FluidTankIntegration.java | 2 +- .../addons/minecolonies/MineColonies.java | 8 +- .../addons/refinedstorage/RefinedStorage.java | 4 +- .../addons/refinedstorage/RsFluidHandler.java | 2 +- .../blocks/base/APBlockEntityBlock.java | 2 +- .../common/blocks/base/BaseBlock.java | 2 +- .../blocks/base/BaseBlockEntityBlock.java | 2 +- .../blocks/base/PeripheralBlockEntity.java | 14 +- .../base/PoweredPeripheralBlockEntity.java | 10 +- .../blockentities/EnergyDetectorEntity.java | 10 +- .../blockentities/InventoryManagerEntity.java | 2 +- .../blocks/blockentities/RsBridgeEntity.java | 4 +- .../common/commands/APCommands.java | 7 +- .../common/configuration/APConfig.java | 10 +- .../common/configuration/GeneralConfig.java | 3 +- .../common/configuration/IAPConfig.java | 4 +- .../configuration/MetaphysicsConfig.java | 4 +- .../configuration/PeripheralsConfig.java | 4 +- .../common/configuration/WorldConfig.java | 4 +- .../container/InventoryManagerContainer.java | 2 +- .../common/container/base/BaseContainer.java | 6 +- .../container/base/BaseItemContainer.java | 6 +- .../container/base/SlotInputHandler.java | 4 +- .../common/data/BlockLootTables.java | 2 +- .../data/BlockStatesAndModelsProvider.java | 6 +- .../common/data/BlockTagsProvider.java | 8 +- .../common/data/DataGenerators.java | 8 +- .../common/data/EnUsLanguageProvider.java | 4 +- .../common/data/PoiTypeProvider.java | 4 +- .../common/data/RecipesProvider.java | 8 +- .../common/events/Events.java | 14 +- .../common/items/WeakAutomataCore.java | 4 +- .../common/items/base/BaseItem.java | 2 +- .../common/setup/BlockEntityTypes.java | 4 +- .../common/setup/Blocks.java | 4 +- .../common/setup/CCRegistration.java | 4 +- .../common/setup/ContainerTypes.java | 4 +- .../common/setup/CreativeTabs.java | 2 +- .../common/setup/Items.java | 2 +- .../common/setup/Registration.java | 8 +- .../common/setup/Villagers.java | 2 +- .../common/util/ChunkManager.java | 14 +- .../common/util/EnergyStorageProxy.java | 2 +- .../common/util/KeybindUtil.java | 2 +- .../common/util/LuaConverter.java | 2 +- .../common/util/Platform.java | 2 +- .../common/util/RawValue.java | 2 +- .../common/util/ServerWorker.java | 6 +- .../common/util/fakeplayer/APFakePlayer.java | 12 +- .../common/util/inventory/FluidFilter.java | 4 +- .../common/util/inventory/FluidUtil.java | 12 +- .../inventory/IStorageSystemFluidHandler.java | 4 +- .../inventory/IStorageSystemItemHandler.java | 2 +- .../common/util/inventory/InventoryUtil.java | 16 +- .../common/util/inventory/ItemFilter.java | 2 +- .../common/util/inventory/ItemUtil.java | 6 +- .../common/village/VillageStructures.java | 6 +- .../common/village/VillagerTrade.java | 4 +- .../common/village/VillagerTrades.java | 8 +- .../advancedperipherals/lib/LibConfig.java | 2 +- .../lib/misc/IConfigHandler.java | 2 +- .../lib/peripherals/IPeripheralPlugin.java | 2 +- .../network/APNetworking.java | 12 +- .../network/base/IPacket.java | 2 +- .../network/toclient/ToastToClientPacket.java | 4 +- 97 files changed, 317 insertions(+), 441 deletions(-) delete mode 100644 gradle/wrapper/gradle-wrapper.jar diff --git a/build.gradle b/build.gradle index 4020b9b72..d3b6b07ed 100644 --- a/build.gradle +++ b/build.gradle @@ -7,9 +7,8 @@ plugins { id 'net.darkhax.curseforgegradle' version '1.1.16' id 'org.jetbrains.changelog' version '1.2.1' id "com.modrinth.minotaur" version "2.+" - id "org.jetbrains.kotlin.jvm" version "1.6.10" - id 'net.neoforged.gradle' version '[6.0.18,6.2)' - id 'org.spongepowered.mixin' version '0.7.+' + //id "org.jetbrains.kotlin.jvm" version "1.6.10" + id 'net.neoforged.gradle.userdev' version '7.0.105' id "com.github.breadmoirai.github-release" version "2.5.2" id 'checkstyle' id 'java' @@ -18,8 +17,8 @@ plugins { java.toolchain.languageVersion = JavaLanguageVersion.of(17) wrapper { - gradleVersion = '8.4' - distributionType = Wrapper.DistributionType.ALL + gradleVersion = '8.6' + distributionType = Wrapper.DistributionType.BIN } def isSnapshotVersion = project.hasProperty('teamcityBuild') @@ -55,109 +54,54 @@ sourceSets { main.resources { srcDir 'src/generated/resources' } - testMod {} } -minecraft { +minecraft.accessTransformers.file rootProject.file('src/main/resources/META-INF/accesstransformer.cfg') - mappings channel: "${mappings_channel}", version: "${mappings_version}" - accessTransformer file('src/main/resources/META-INF/accesstransformer.cfg') - accessTransformer file('src/testMod/resources/META-INF/accesstransformer.cfg') +// Default run configurations. +// These can be tweaked, removed, or duplicated as needed. +runs { + // applies to all the run configs below + configureEach { + // Recommended logging data for a userdev environment + // The markers can be added/remove as needed separated by commas. + // "SCAN": For mods scan. + // "REGISTRIES": For firing of registry events. + // "REGISTRYDUMP": For getting the contents of all registries. + systemProperty 'forge.logging.markers', 'REGISTRIES' - runs { - client { - workingDirectory project.file('run') + // Recommended logging level for the console + // You can set various levels here. + // Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels + systemProperty 'forge.logging.console.level', 'debug' - property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' - property 'mixin.env.remapRefMap', 'true' - property 'mixin.env.refMapRemappingFile', "${buildDir}/createSrgToMcp/output.srg" - properties 'forge.logging.console.level': 'debug' - - mods { - advancedperipherals { - source sourceSets.main - } - } - if (project.hasProperty('mc_uuid')) { - args '--uuid', project.getProperty('mc_uuid') - } - if (project.hasProperty('mc_username')) { - args '--username', project.getProperty('mc_username') - } - if (project.hasProperty('mc_accessToken')) { - args '--accessToken', project.getProperty('mc_accessToken') - } - } - - server { - workingDirectory project.file('server') - - property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' - property 'mixin.env.remapRefMap', 'true' - property 'mixin.env.refMapRemappingFile', "${buildDir}/createSrgToMcp/output.srg" - property 'forge.logging.console.level', 'info' - - mods { - advancedperipherals { - source sourceSets.main - } - } - } - - data { - workingDirectory project.file('run') - - property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' - property 'mixin.env.remapRefMap', 'true' - property 'mixin.env.refMapRemappingFile', "${buildDir}/createSrgToMcp/output.srg" - property 'forge.logging.console.level', 'debug' - - args '--mod', 'advancedperipherals', '--all', - '--existing', file('src/main/resources').toString(), - '--existing', file('src/generated/resources').toString(), - '--output', file('src/generated/resources/') - - mods { - advancedperipherals { - source sourceSets.main - } - } - } - - testClient { - workingDirectory project.file('test-files/client') - parent runs.client + modSource project.sourceSets.main + } - mods { - aptest { - source sourceSets.testMod - } - } + client { + // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. + systemProperty 'forge.enabledGameTestNamespaces', project.mod_id + } - lazyToken('minecraft_classpath') { - (configurations.implementationExtra.copyRecursive().resolve()) - .collect { it.absolutePath } - .join(File.pathSeparator) - } - } + server { + systemProperty 'forge.enabledGameTestNamespaces', project.mod_id + programArgument '--nogui' + } - testServer { - workingDirectory project.file('test-files/server') - parent runs.server + // This run config launches GameTestServer and runs all registered gametests, then exits. + // By default, the server will crash when no gametests are provided. + // The gametest system is also enabled by default for other run configs under the /test command. + gameTestServer { + systemProperty 'forge.enabledGameTestNamespaces', project.mod_id + } - mods { - aptest { - source sourceSets.testMod - } - } + data { + // example of overriding the workingDirectory set in configureEach above, uncomment if you want to use it + // workingDirectory project.file('run-data') - lazyToken('minecraft_classpath') { - (configurations.implementationExtra.copyRecursive().resolve()) - .collect { it.absolutePath } - .join(File.pathSeparator) - } - } + // Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources. + programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath() } } @@ -263,76 +207,74 @@ dependencies { // Minimal requirements compileOnly "org.jetbrains:annotations:${jb_annotations}" - minecraft "net.neoforged:forge:${minecraft_version}-${neo_version}" - implementation fg.deobf("cc.tweaked:cc-tweaked-${minecraft_version}-forge:${cc_version}") + implementation "net.neoforged:neoforge:${neo_version}" + implementation "cc.tweaked:cc-tweaked-${minecraft_version}-forge:${cc_version}" // Compile-time API required // Ae2 - compileOnly fg.deobf("appeng:appliedenergistics2-forge:${appliedenergistics_version}") + compileOnly "appeng:appliedenergistics2-forge:${appliedenergistics_version}" // Curios - compileOnly fg.deobf("top.theillusivec4.curios:curios-forge:${curios_version}:api") + compileOnly "top.theillusivec4.curios:curios-forge:${curios_version}:api" // Minimal requirements end // Extended requirements // We don't use the api since we need a specific class from mekanism - compileOnly fg.deobf("mekanism:Mekanism:${mekanism_version}") - runtimeOnly fg.deobf("mekanism:Mekanism:${mekanism_version}") + compileOnly "mekanism:Mekanism:${mekanism_version}" + runtimeOnly "mekanism:Mekanism:${mekanism_version}" - // runtimeOnly fg.deobf("mekanism:Mekanism:${mekanism_version}")// core + // runtimeOnly "mekanism:Mekanism:${mekanism_version}"// core // Applied Energistics 2 - runtimeOnly fg.deobf("appeng:appliedenergistics2-forge:${appliedenergistics_version}") + runtimeOnly "appeng:appliedenergistics2-forge:${appliedenergistics_version}" // Applied Mekanistics - implementation fg.deobf("curse.maven:applied-mekanistics-574300:${appliedmekanistics_version}") + implementation "curse.maven:applied-mekanistics-574300:${appliedmekanistics_version}" // Curios - runtimeOnly fg.deobf("top.theillusivec4.curios:curios-forge:${curios_version}") + runtimeOnly "top.theillusivec4.curios:curios-forge:${curios_version}" // Refined Storage - implementation fg.deobf("com.refinedmods:refinedstorage:${refinedstorage_version}") { - transitive false - } + implementation "com.refinedmods:refinedstorage:${refinedstorage_version}" // AE2 Things - compileOnly fg.deobf("curse.maven:ae2things-609977:${ae2things_version}-sources") - runtimeOnly fg.deobf("curse.maven:ae2things-609977:${ae2things_version}-sources") + compileOnly "curse.maven:ae2things-609977:${ae2things_version}-sources" + runtimeOnly "curse.maven:ae2things-609977:${ae2things_version}-sources" // AE2 Additions - compileOnly fg.deobf("curse.maven:ae-additions-493962:${ae2additions_version}") - runtimeOnly fg.deobf("curse.maven:ae-additions-493962:${ae2additions_version}") + compileOnly "curse.maven:ae-additions-493962:${ae2additions_version}" + runtimeOnly "curse.maven:ae-additions-493962:${ae2additions_version}" - implementation fg.deobf("thedarkcolour:kotlinforforge:${kotlinforforge_version}") + //implementation "thedarkcolour:kotlinforforge:${kotlinforforge_version}" // Botania - compileOnly fg.deobf("vazkii.botania:Botania:${botania_version}") - runtimeOnly fg.deobf("vazkii.botania:Botania:${botania_version}") + compileOnly "vazkii.botania:Botania:${botania_version}" + runtimeOnly "vazkii.botania:Botania:${botania_version}" // Minecolonies // Remove/Comment this section if you want to use runData. - //runtimeOnly fg.deobf("com.ldtteam:minecolonies:${minecolonies_version}") - //runtimeOnly fg.deobf("com.ldtteam:structurize:${structurize_version}") - //runtimeOnly fg.deobf("com.ldtteam:domum_ornamentum:${domumornamentum_version}:universal") - //runtimeOnly fg.deobf("com.ldtteam:blockui:${blockui_version}") + //runtimeOnly "com.ldtteam:minecolonies:${minecolonies_version}" + //runtimeOnly "com.ldtteam:structurize:${structurize_version}" + //runtimeOnly "com.ldtteam:domum_ornamentum:${domumornamentum_version}:universal" + //runtimeOnly "com.ldtteam:blockui:${blockui_version}" - compileOnly fg.deobf("com.ldtteam:minecolonies:${minecolonies_version}") - compileOnly fg.deobf("com.ldtteam:structurize:${structurize_version}") - compileOnly fg.deobf("com.ldtteam:domum_ornamentum:${domumornamentum_version}:universal") - compileOnly fg.deobf("com.ldtteam:blockui:${blockui_version}") + compileOnly "com.ldtteam:minecolonies:${minecolonies_version}" + compileOnly "com.ldtteam:structurize:${structurize_version}" + compileOnly "com.ldtteam:domum_ornamentum:${domumornamentum_version}:universal" + compileOnly "com.ldtteam:blockui:${blockui_version}" //Patchouli - runtimeOnly fg.deobf("vazkii.patchouli:Patchouli:${patchouli_version}-FORGE") + runtimeOnly "vazkii.patchouli:Patchouli:${patchouli_version}-FORGE" // Create - compileOnly fg.deobf("com.simibubi.create:create-1.20.1:${create_version}:all") - runtimeOnly fg.deobf("com.simibubi.create:create-1.20.1:${create_version}:all") + compileOnly "com.simibubi.create:create-1.20.1:${create_version}:all" + runtimeOnly "com.simibubi.create:create-1.20.1:${create_version}:all" //Powah - implementation fg.deobf("curse.maven:powah-633483:${powah_version}") - implementation fg.deobf("me.shedaniel.cloth:cloth-config-forge:11.1.106") - implementation fg.deobf("dev.architectury:architectury-forge:9.1.10") + implementation "curse.maven:powah-633483:${powah_version}" + implementation "me.shedaniel.cloth:cloth-config-forge:11.1.106" + implementation "dev.architectury:architectury-forge:9.1.10" //Removed until fully ported - //testImplementation fg.deobf("site.siredvin.ttoolkit:ttoolkit-${minecraft_version}:${ttoolkit_version}") + //testImplementation "site.siredvin.ttoolkit:ttoolkit-${minecraft_version}:${ttoolkit_version}" testImplementation "org.junit.jupiter:junit-jupiter-api:${junit_version}" testImplementation "org.junit.jupiter:junit-jupiter-params:${junit_version}" @@ -344,11 +286,11 @@ dependencies { testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junit_version}" // Testing stuff // JEI - implementation fg.deobf("mezz.jei:jei-${jei_version}") + //implementation "mezz.jei:jei-${jei_version}" // Create Crafts & Additions - compileOnly fg.deobf("curse.maven:createaddition-439890:${createadditions_version}") - runtimeOnly fg.deobf("curse.maven:createaddition-439890:${createadditions_version}") + compileOnly "curse.maven:createaddition-439890:${createadditions_version}" + runtimeOnly "curse.maven:createaddition-439890:${createadditions_version}" } @@ -367,45 +309,6 @@ changelog { groups = [] } -compileTestModJava { - dependsOn(compileJava) -} - -task setupServer(type: Copy) { - group "test server" - description "Sets up the environment for the test server." - - from("src/testMod/server-files") { - include "eula.txt" - include "server.properties" - } - into "test-files/server" -} - -["Client", "Server"].forEach { name -> - tasks.register("test$name", JavaExec.class).configure { - it.group('In-game tests') - it.description("Runs tests on a temporary Minecraft instance.") - it.dependsOn(setupServer, "prepareRunTest$name", "cleanTest$name", 'compileTestModJava') - - JavaExec exec = tasks.getByName("runTest$name") - exec.copyTo(it) - it.setClasspath(exec.getClasspath()) - it.mainClass = exec.mainClass - it.setArgs(exec.getArgs()) - - it.systemProperty('forge.logging.console.level', 'debug') - it.systemProperty('ttoolkit.run', 'true') - } -} - -test { - useJUnitPlatform() - testLogging { - events "skipped", "failed" - } -} - afterEvaluate { tasks.withType(JavaCompile) { options.compilerArgs << "-Xmaxerrs" << "2000" @@ -425,8 +328,6 @@ jar { archiveFileName = "AdvancedPeripherals-${minecraft_version}-${mod_version}.jar" } -jar.finalizedBy('reobfJar') - tasks.withType(Checkstyle) { reports { xml.required = false @@ -461,22 +362,6 @@ tasks.named('processResources', ProcessResources).configure { } } -// Used to do some magic with teamcity -task commitAndPush() { - doLast { - def baseMessage = project.hasProperty('commitMessage') ? commitMessage : 'No commit message provided' - def message = baseMessage.replace("{version}", "${minecraft_version}-${version}") - - exec { - commandLine 'git', 'add', '.' - } - - exec { - commandLine 'git', 'commit', '-m', message - } - } -} - tasks.register('publishCurseForge', TaskPublishCurseForge, { task -> setGroup("publishing") setDescription("Upload Advanced Peripherals to CurseForge") @@ -504,7 +389,7 @@ tasks.register('publishCurseForge', TaskPublishCurseForge, { task -> addRequirement('cc-tweaked') - addModLoader("forge", "neoforge") + addModLoader("neoforge") releaseType = "${release_type}" } @@ -539,7 +424,7 @@ modrinth { versionType = release_type uploadFile = jar gameVersions = [minecraft_version] - loaders = ["forge", "neoforge"] + loaders = ["neoforge"] dependencies { required.project "cc-tweaked" } @@ -583,10 +468,8 @@ publishing { NodeList dependencies = asNode().dependencies NodeList allDeps = dependencies.'*' - //TODO: Needs to be changed in 1.20.2 since neoforge then changes the packages names. - // Remove forge deps allDeps. findAll() { Node el -> - el.artifactId.text() == 'forge' && el.groupId.text() == 'net.minecraftforge' + el.artifactId.text() == 'forge' && el.groupId.text() == 'net.neoforged' }.forEach() { Node el -> el.parent().remove(el) } diff --git a/gradle.properties b/gradle.properties index 1489af619..3aa711744 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,14 +4,13 @@ org.gradle.logging.level=info # Minecraft related mod_id=advancedperipherals -minecraft_version=1.20.1 -neo_version=47.1.99 -loader_version=47 +minecraft_version=1.20.4 +neo_version=20.4.231 +loader_version=20 mod_version=0.7.40r release_type=release -mappings_channel=official -#mappings_version=2022.11.27-1.19.2 -mappings_version=1.20.1 +neogradle.subsystems.parchment.minecraftVersion=1.20.4 +neogradle.subsystems.parchment.mappingsVersion=2024.04.14 jb_annotations=21.0.1 # Test dependencies @@ -22,7 +21,7 @@ kotlinx_coroutines_version=1.6.0-RC3 ttoolkit_version=0.1.3 # Mod dependencies -cc_version=1.110.0 +cc_version=1.110.2 curios_version=5.2.0+1.20.1 minecolonies_version=1.20.1-1.1.472-BETA appliedenergistics_version=15.0.9-beta diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index c1962a79e29d3e0ab67b14947c167a862655af9b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 62076 zcmb5VV{~QRw)Y#`wrv{~+qP{x72B%VwzFc}c2cp;N~)5ZbDrJayPv(!dGEd-##*zr z)#n-$y^sH|_dchh3@8{H5D*j;5D<{i*8l5IFJ|DjL!e)upfGNX(kojugZ3I`oH1PvW`wFW_ske0j@lB9bX zO;2)`y+|!@X(fZ1<2n!Qx*)_^Ai@Cv-dF&(vnudG?0CsddG_&Wtae(n|K59ew)6St z#dj7_(Cfwzh$H$5M!$UDd8=4>IQsD3xV=lXUq($;(h*$0^yd+b{qq63f0r_de#!o_ zXDngc>zy`uor)4A^2M#U*DC~i+dc<)Tb1Tv&~Ev@oM)5iJ4Sn#8iRw16XXuV50BS7 zdBL5Mefch(&^{luE{*5qtCZk$oFr3RH=H!c3wGR=HJ(yKc_re_X9pD` zJ;uxPzUfVpgU>DSq?J;I@a+10l0ONXPcDkiYcihREt5~T5Gb}sT0+6Q;AWHl`S5dV>lv%-p9l#xNNy7ZCr%cyqHY%TZ8Q4 zbp&#ov1*$#grNG#1vgfFOLJCaNG@K|2!W&HSh@3@Y%T?3YI75bJp!VP*$*!< z;(ffNS_;@RJ`=c7yX04!u3JP*<8jeqLHVJu#WV&v6wA!OYJS4h<_}^QI&97-;=ojW zQ-1t)7wnxG*5I%U4)9$wlv5Fr;cIizft@&N+32O%B{R1POm$oap@&f| zh+5J{>U6ftv|vAeKGc|zC=kO(+l7_cLpV}-D#oUltScw})N>~JOZLU_0{Ka2e1evz z{^a*ZrLr+JUj;)K&u2CoCAXLC2=fVScI(m_p~0FmF>>&3DHziouln?;sxW`NB}cSX z8?IsJB)Z=aYRz!X=yJn$kyOWK%rCYf-YarNqKzmWu$ZvkP12b4qH zhS9Q>j<}(*frr?z<%9hl*i^#@*O2q(Z^CN)c2c z>1B~D;@YpG?G!Yk+*yn4vM4sO-_!&m6+`k|3zd;8DJnxsBYtI;W3We+FN@|tQ5EW= z!VU>jtim0Mw#iaT8t_<+qKIEB-WwE04lBd%Letbml9N!?SLrEG$nmn7&W(W`VB@5S zaY=sEw2}i@F_1P4OtEw?xj4@D6>_e=m=797#hg}f*l^`AB|Y0# z9=)o|%TZFCY$SzgSjS|8AI-%J4x}J)!IMxY3_KYze`_I=c1nmrk@E8c9?MVRu)7+Ue79|)rBX7tVB7U|w4*h(;Gi3D9le49B38`wuv zp7{4X^p+K4*$@gU(Tq3K1a#3SmYhvI42)GzG4f|u zwQFT1n_=n|jpi=70-yE9LA+d*T8u z`=VmmXJ_f6WmZveZPct$Cgu^~gFiyL>Lnpj*6ee>*0pz=t$IJ}+rE zsf@>jlcG%Wx;Cp5x)YSVvB1$yyY1l&o zvwX=D7k)Dn;ciX?Z)Pn8$flC8#m`nB&(8?RSdBvr?>T9?E$U3uIX7T?$v4dWCa46 z+&`ot8ZTEgp7G+c52oHJ8nw5}a^dwb_l%MOh(ebVj9>_koQP^$2B~eUfSbw9RY$_< z&DDWf2LW;b0ZDOaZ&2^i^g+5uTd;GwO(-bbo|P^;CNL-%?9mRmxEw~5&z=X^Rvbo^WJW=n_%*7974RY}JhFv46> zd}`2|qkd;89l}R;i~9T)V-Q%K)O=yfVKNM4Gbacc7AOd>#^&W&)Xx!Uy5!BHnp9kh z`a(7MO6+Ren#>R^D0K)1sE{Bv>}s6Rb9MT14u!(NpZOe-?4V=>qZ>}uS)!y~;jEUK z&!U7Fj&{WdgU#L0%bM}SYXRtM5z!6M+kgaMKt%3FkjWYh=#QUpt$XX1!*XkpSq-pl zhMe{muh#knk{9_V3%qdDcWDv}v)m4t9 zQhv{;} zc{}#V^N3H>9mFM8`i`0p+fN@GqX+kl|M94$BK3J-X`Hyj8r!#x6Vt(PXjn?N)qedP z=o1T^#?1^a{;bZ&x`U{f?}TMo8ToN zkHj5v|}r}wDEi7I@)Gj+S1aE-GdnLN+$hw!=DzglMaj#{qjXi_dwpr|HL(gcCXwGLEmi|{4&4#OZ4ChceA zKVd4K!D>_N=_X;{poT~4Q+!Le+ZV>=H7v1*l%w`|`Dx8{)McN@NDlQyln&N3@bFpV z_1w~O4EH3fF@IzJ9kDk@7@QctFq8FbkbaH7K$iX=bV~o#gfh?2JD6lZf(XP>~DACF)fGFt)X%-h1yY~MJU{nA5 ze2zxWMs{YdX3q5XU*9hOH0!_S24DOBA5usB+Ws$6{|AMe*joJ?RxfV}*7AKN9V*~J zK+OMcE@bTD>TG1*yc?*qGqjBN8mgg@h1cJLDv)0!WRPIkC` zZrWXrceVw;fB%3`6kq=a!pq|hFIsQ%ZSlo~)D z|64!aCnw-?>}AG|*iOl44KVf8@|joXi&|)1rB;EQWgm+iHfVbgllP$f!$Wf42%NO5b(j9Bw6L z;0dpUUK$5GX4QbMlTmLM_jJt!ur`_0~$b#BB7FL*%XFf<b__1o)Ao3rlobbN8-(T!1d-bR8D3S0@d zLI!*GMb5s~Q<&sjd}lBb8Nr0>PqE6_!3!2d(KAWFxa{hm`@u|a(%#i(#f8{BP2wbs zt+N_slWF4IF_O|{w`c~)Xvh&R{Au~CFmW#0+}MBd2~X}t9lz6*E7uAD`@EBDe$>7W zzPUkJx<`f$0VA$=>R57^(K^h86>09?>_@M(R4q($!Ck6GG@pnu-x*exAx1jOv|>KH zjNfG5pwm`E-=ydcb+3BJwuU;V&OS=6yM^4Jq{%AVqnTTLwV`AorIDD}T&jWr8pB&j28fVtk_y*JRP^t@l*($UZ z6(B^-PBNZ+z!p?+e8@$&jCv^EWLb$WO=}Scr$6SM*&~B95El~;W_0(Bvoha|uQ1T< zO$%_oLAwf1bW*rKWmlD+@CP&$ObiDy=nh1b2ejz%LO9937N{LDe7gle4i!{}I$;&Y zkexJ9Ybr+lrCmKWg&}p=`2&Gf10orS?4$VrzWidT=*6{KzOGMo?KI0>GL0{iFWc;C z+LPq%VH5g}6V@-tg2m{C!-$fapJ9y}c$U}aUmS{9#0CM*8pC|sfer!)nG7Ji>mfRh z+~6CxNb>6eWKMHBz-w2{mLLwdA7dA-qfTu^A2yG1+9s5k zcF=le_UPYG&q!t5Zd_*E_P3Cf5T6821bO`daa`;DODm8Ih8k89=RN;-asHIigj`n=ux>*f!OC5#;X5i;Q z+V!GUy0|&Y_*8k_QRUA8$lHP;GJ3UUD08P|ALknng|YY13)}!!HW@0z$q+kCH%xet zlWf@BXQ=b=4}QO5eNnN~CzWBbHGUivG=`&eWK}beuV*;?zt=P#pM*eTuy3 zP}c#}AXJ0OIaqXji78l;YrP4sQe#^pOqwZUiiN6^0RCd#D271XCbEKpk`HI0IsN^s zES7YtU#7=8gTn#lkrc~6)R9u&SX6*Jk4GFX7){E)WE?pT8a-%6P+zS6o&A#ml{$WX zABFz#i7`DDlo{34)oo?bOa4Z_lNH>n;f0nbt$JfAl~;4QY@}NH!X|A$KgMmEsd^&Y zt;pi=>AID7ROQfr;MsMtClr5b0)xo|fwhc=qk33wQ|}$@?{}qXcmECh>#kUQ-If0$ zseb{Wf4VFGLNc*Rax#P8ko*=`MwaR-DQ8L8V8r=2N{Gaips2_^cS|oC$+yScRo*uF zUO|5=?Q?{p$inDpx*t#Xyo6=s?bbN}y>NNVxj9NZCdtwRI70jxvm3!5R7yiWjREEd zDUjrsZhS|P&|Ng5r+f^kA6BNN#|Se}_GF>P6sy^e8kBrgMv3#vk%m}9PCwUWJg-AD zFnZ=}lbi*mN-AOm zCs)r=*YQAA!`e#1N>aHF=bb*z*hXH#Wl$z^o}x##ZrUc=kh%OHWhp=7;?8%Xj||@V?1c ziWoaC$^&04;A|T)!Zd9sUzE&$ODyJaBpvqsw19Uiuq{i#VK1!htkdRWBnb z`{rat=nHArT%^R>u#CjjCkw-7%g53|&7z-;X+ewb?OLWiV|#nuc8mp*LuGSi3IP<<*Wyo9GKV7l0Noa4Jr0g3p_$ z*R9{qn=?IXC#WU>48-k5V2Oc_>P;4_)J@bo1|pf=%Rcbgk=5m)CJZ`caHBTm3%!Z9 z_?7LHr_BXbKKr=JD!%?KhwdYSdu8XxPoA{n8^%_lh5cjRHuCY9Zlpz8g+$f@bw@0V z+6DRMT9c|>1^3D|$Vzc(C?M~iZurGH2pXPT%F!JSaAMdO%!5o0uc&iqHx?ImcX6fI zCApkzc~OOnfzAd_+-DcMp&AOQxE_EsMqKM{%dRMI5`5CT&%mQO?-@F6tE*xL?aEGZ z8^wH@wRl`Izx4sDmU>}Ym{ybUm@F83qqZPD6nFm?t?(7>h*?`fw)L3t*l%*iw0Qu#?$5eq!Qc zpQvqgSxrd83NsdO@lL6#{%lsYXWen~d3p4fGBb7&5xqNYJ)yn84!e1PmPo7ChVd%4 zHUsV0Mh?VpzZD=A6%)Qrd~i7 z96*RPbid;BN{Wh?adeD_p8YU``kOrGkNox3D9~!K?w>#kFz!4lzOWR}puS(DmfjJD z`x0z|qB33*^0mZdM&6$|+T>fq>M%yoy(BEjuh9L0>{P&XJ3enGpoQRx`v6$txXt#c z0#N?b5%srj(4xmPvJxrlF3H%OMB!jvfy z;wx8RzU~lb?h_}@V=bh6p8PSb-dG|-T#A?`c&H2`_!u+uenIZe`6f~A7r)`9m8atC zt(b|6Eg#!Q*DfRU=Ix`#B_dK)nnJ_+>Q<1d7W)eynaVn`FNuN~%B;uO2}vXr5^zi2 z!ifIF5@Zlo0^h~8+ixFBGqtweFc`C~JkSq}&*a3C}L?b5Mh-bW=e)({F_g4O3 zb@SFTK3VD9QuFgFnK4Ve_pXc3{S$=+Z;;4+;*{H}Rc;845rP?DLK6G5Y-xdUKkA6E3Dz&5f{F^FjJQ(NSpZ8q-_!L3LL@H* zxbDF{gd^U3uD;)a)sJwAVi}7@%pRM&?5IaUH%+m{E)DlA_$IA1=&jr{KrhD5q&lTC zAa3c)A(K!{#nOvenH6XrR-y>*4M#DpTTOGQEO5Jr6kni9pDW`rvY*fs|ItV;CVITh z=`rxcH2nEJpkQ^(;1c^hfb8vGN;{{oR=qNyKtR1;J>CByul*+=`NydWnSWJR#I2lN zTvgnR|MBx*XFsfdA&;tr^dYaqRZp*2NwkAZE6kV@1f{76e56eUmGrZ>MDId)oqSWw z7d&r3qfazg+W2?bT}F)4jD6sWaw`_fXZGY&wnGm$FRPFL$HzVTH^MYBHWGCOk-89y zA+n+Q6EVSSCpgC~%uHfvyg@ufE^#u?JH?<73A}jj5iILz4Qqk5$+^U(SX(-qv5agK znUkfpke(KDn~dU0>gdKqjTkVk`0`9^0n_wzXO7R!0Thd@S;U`y)VVP&mOd-2 z(hT(|$=>4FY;CBY9#_lB$;|Wd$aOMT5O_3}DYXEHn&Jrc3`2JiB`b6X@EUOD zVl0S{ijm65@n^19T3l%>*;F(?3r3s?zY{thc4%AD30CeL_4{8x6&cN}zN3fE+x<9; zt2j1RRVy5j22-8U8a6$pyT+<`f+x2l$fd_{qEp_bfxfzu>ORJsXaJn4>U6oNJ#|~p z`*ZC&NPXl&=vq2{Ne79AkQncuxvbOG+28*2wU$R=GOmns3W@HE%^r)Fu%Utj=r9t` zd;SVOnA(=MXgnOzI2@3SGKHz8HN~Vpx&!Ea+Df~`*n@8O=0!b4m?7cE^K*~@fqv9q zF*uk#1@6Re_<^9eElgJD!nTA@K9C732tV~;B`hzZ321Ph=^BH?zXddiu{Du5*IPg} zqDM=QxjT!Rp|#Bkp$(mL)aar)f(dOAXUiw81pX0DC|Y4;>Vz>>DMshoips^8Frdv} zlTD=cKa48M>dR<>(YlLPOW%rokJZNF2gp8fwc8b2sN+i6&-pHr?$rj|uFgktK@jg~ zIFS(%=r|QJ=$kvm_~@n=ai1lA{7Z}i+zj&yzY+!t$iGUy|9jH#&oTNJ;JW-3n>DF+ z3aCOzqn|$X-Olu_p7brzn`uk1F*N4@=b=m;S_C?#hy{&NE#3HkATrg?enaVGT^$qIjvgc61y!T$9<1B@?_ibtDZ{G zeXInVr5?OD_nS_O|CK3|RzzMmu+8!#Zb8Ik;rkIAR%6?$pN@d<0dKD2c@k2quB%s( zQL^<_EM6ow8F6^wJN1QcPOm|ehA+dP(!>IX=Euz5qqIq}Y3;ibQtJnkDmZ8c8=Cf3 zu`mJ!Q6wI7EblC5RvP*@)j?}W=WxwCvF3*5Up_`3*a~z$`wHwCy)2risye=1mSp%p zu+tD6NAK3o@)4VBsM!@);qgsjgB$kkCZhaimHg&+k69~drbvRTacWKH;YCK(!rC?8 zP#cK5JPHSw;V;{Yji=55X~S+)%(8fuz}O>*F3)hR;STU`z6T1aM#Wd+FP(M5*@T1P z^06O;I20Sk!bxW<-O;E081KRdHZrtsGJflFRRFS zdi5w9OVDGSL3 zNrC7GVsGN=b;YH9jp8Z2$^!K@h=r-xV(aEH@#JicPy;A0k1>g1g^XeR`YV2HfmqXY zYbRwaxHvf}OlCAwHoVI&QBLr5R|THf?nAevV-=~V8;gCsX>jndvNOcFA+DI+zbh~# zZ7`qNk&w+_+Yp!}j;OYxIfx_{f0-ONc?mHCiCUak=>j>~>YR4#w# zuKz~UhT!L~GfW^CPqG8Lg)&Rc6y^{%3H7iLa%^l}cw_8UuG;8nn9)kbPGXS}p3!L_ zd#9~5CrH8xtUd?{d2y^PJg+z(xIfRU;`}^=OlehGN2=?}9yH$4Rag}*+AWotyxfCJ zHx=r7ZH>j2kV?%7WTtp+-HMa0)_*DBBmC{sd$)np&GEJ__kEd`xB5a2A z*J+yx>4o#ZxwA{;NjhU*1KT~=ZK~GAA;KZHDyBNTaWQ1+;tOFFthnD)DrCn`DjBZ% zk$N5B4^$`n^jNSOr=t(zi8TN4fpaccsb`zOPD~iY=UEK$0Y70bG{idLx@IL)7^(pL z{??Bnu=lDeguDrd%qW1)H)H`9otsOL-f4bSu};o9OXybo6J!Lek`a4ff>*O)BDT_g z<6@SrI|C9klY(>_PfA^qai7A_)VNE4c^ZjFcE$Isp>`e5fLc)rg@8Q_d^Uk24$2bn z9#}6kZ2ZxS9sI(RqT7?El2@B+($>eBQrNi_k#CDJ8D9}8$mmm z4oSKO^F$i+NG)-HE$O6s1--6EzJa?C{x=QgK&c=)b(Q9OVoAXYEEH20G|q$}Hue%~ zO3B^bF=t7t48sN zWh_zA`w~|){-!^g?6Mqf6ieV zFx~aPUOJGR=4{KsW7I?<=J2|lY`NTU=lt=%JE9H1vBpkcn=uq(q~=?iBt_-r(PLBM zP-0dxljJO>4Wq-;stY)CLB4q`-r*T$!K2o}?E-w_i>3_aEbA^MB7P5piwt1dI-6o!qWCy0 ztYy!x9arGTS?kabkkyv*yxvsPQ7Vx)twkS6z2T@kZ|kb8yjm+^$|sEBmvACeqbz)RmxkkDQX-A*K!YFziuhwb|ym>C$}U|J)4y z$(z#)GH%uV6{ec%Zy~AhK|+GtG8u@c884Nq%w`O^wv2#A(&xH@c5M`Vjk*SR_tJnq z0trB#aY)!EKW_}{#L3lph5ow=@|D5LzJYUFD6 z7XnUeo_V0DVSIKMFD_T0AqAO|#VFDc7c?c-Q%#u00F%!_TW1@JVnsfvm@_9HKWflBOUD~)RL``-!P;(bCON_4eVdduMO>?IrQ__*zE@7(OX zUtfH@AX*53&xJW*Pu9zcqxGiM>xol0I~QL5B%Toog3Jlenc^WbVgeBvV8C8AX^Vj& z^I}H})B=VboO%q1;aU5ACMh{yK4J;xlMc`jCnZR^!~LDs_MP&8;dd@4LDWw~*>#OT zeZHwdQWS!tt5MJQI~cw|Ka^b4c|qyd_ly(+Ql2m&AAw^ zQeSXDOOH!!mAgzAp0z)DD>6Xo``b6QwzUV@w%h}Yo>)a|xRi$jGuHQhJVA%>)PUvK zBQ!l0hq<3VZ*RnrDODP)>&iS^wf64C;MGqDvx>|p;35%6(u+IHoNbK z;Gb;TneFo*`zUKS6kwF*&b!U8e5m4YAo03a_e^!5BP42+r)LFhEy?_7U1IR<; z^0v|DhCYMSj<-;MtY%R@Fg;9Kky^pz_t2nJfKWfh5Eu@_l{^ph%1z{jkg5jQrkvD< z#vdK!nku*RrH~TdN~`wDs;d>XY1PH?O<4^U4lmA|wUW{Crrv#r%N>7k#{Gc44Fr|t z@UZP}Y-TrAmnEZ39A*@6;ccsR>)$A)S>$-Cj!=x$rz7IvjHIPM(TB+JFf{ehuIvY$ zsDAwREg*%|=>Hw$`us~RP&3{QJg%}RjJKS^mC_!U;E5u>`X`jW$}P`Mf}?7G7FX#{ zE(9u1SO;3q@ZhDL9O({-RD+SqqPX)`0l5IQu4q)49TUTkxR(czeT}4`WV~pV*KY&i zAl3~X%D2cPVD^B43*~&f%+Op)wl<&|D{;=SZwImydWL6@_RJjxP2g)s=dH)u9Npki zs~z9A+3fj0l?yu4N0^4aC5x)Osnm0qrhz@?nwG_`h(71P znbIewljU%T*cC=~NJy|)#hT+lx#^5MuDDnkaMb*Efw9eThXo|*WOQzJ*#3dmRWm@! zfuSc@#kY{Um^gBc^_Xdxnl!n&y&}R4yAbK&RMc+P^Ti;YIUh|C+K1|=Z^{nZ}}rxH*v{xR!i%qO~o zTr`WDE@k$M9o0r4YUFFeQO7xCu_Zgy)==;fCJ94M_rLAv&~NhfvcLWCoaGg2ao~3e zBG?Ms9B+efMkp}7BhmISGWmJsKI@a8b}4lLI48oWKY|8?zuuNc$lt5Npr+p7a#sWu zh!@2nnLBVJK!$S~>r2-pN||^w|fY`CT{TFnJy`B|e5;=+_v4l8O-fkN&UQbA4NKTyntd zqK{xEKh}U{NHoQUf!M=2(&w+eef77VtYr;xs%^cPfKLObyOV_9q<(%76-J%vR>w9!us-0c-~Y?_EVS%v!* z15s2s3eTs$Osz$JayyH|5nPAIPEX=U;r&p;K14G<1)bvn@?bM5kC{am|C5%hyxv}a z(DeSKI5ZfZ1*%dl8frIX2?);R^^~LuDOpNpk-2R8U1w92HmG1m&|j&J{EK=|p$;f9 z7Rs5|jr4r8k5El&qcuM+YRlKny%t+1CgqEWO>3;BSRZi(LA3U%Jm{@{y+A+w(gzA< z7dBq6a1sEWa4cD0W7=Ld9z0H7RI^Z7vl(bfA;72j?SWCo`#5mVC$l1Q2--%V)-uN* z9ha*s-AdfbDZ8R8*fpwjzx=WvOtmSzGFjC#X)hD%Caeo^OWjS(3h|d9_*U)l%{Ab8 zfv$yoP{OuUl@$(-sEVNt{*=qi5P=lpxWVuz2?I7Dc%BRc+NGNw+323^ z5BXGfS71oP^%apUo(Y#xkxE)y?>BFzEBZ}UBbr~R4$%b7h3iZu3S(|A;&HqBR{nK& z$;GApNnz=kNO^FL&nYcfpB7Qg;hGJPsCW44CbkG1@l9pn0`~oKy5S777uH)l{irK!ru|X+;4&0D;VE*Ii|<3P zUx#xUqvZT5kVQxsF#~MwKnv7;1pR^0;PW@$@T7I?s`_rD1EGUdSA5Q(C<>5SzE!vw z;{L&kKFM-MO>hy#-8z`sdVx})^(Dc-dw;k-h*9O2_YZw}|9^y-|8RQ`BWJUJL(Cer zP5Z@fNc>pTXABbTRY-B5*MphpZv6#i802giwV&SkFCR zGMETyUm(KJbh+&$8X*RB#+{surjr;8^REEt`2&Dubw3$mx>|~B5IKZJ`s_6fw zKAZx9&PwBqW1Oz0r0A4GtnZd7XTKViX2%kPfv+^X3|_}RrQ2e3l=KG_VyY`H?I5&CS+lAX5HbA%TD9u6&s#v!G> zzW9n4J%d5ye7x0y`*{KZvqyXUfMEE^ZIffzI=Hh|3J}^yx7eL=s+TPH(Q2GT-sJ~3 zI463C{(ag7-hS1ETtU;_&+49ABt5!A7CwLwe z=SoA8mYZIQeU;9txI=zcQVbuO%q@E)JI+6Q!3lMc=Gbj(ASg-{V27u>z2e8n;Nc*pf}AqKz1D>p9G#QA+7mqqrEjGfw+85Uyh!=tTFTv3|O z+)-kFe_8FF_EkTw!YzwK^Hi^_dV5x-Ob*UWmD-})qKj9@aE8g240nUh=g|j28^?v7 zHRTBo{0KGaWBbyX2+lx$wgXW{3aUab6Bhm1G1{jTC7ota*JM6t+qy)c5<@ zpc&(jVdTJf(q3xB=JotgF$X>cxh7k*(T`-V~AR+`%e?YOeALQ2Qud( zz35YizXt(aW3qndR}fTw1p()Ol4t!D1pitGNL95{SX4ywzh0SF;=!wf=?Q?_h6!f* zh7<+GFi)q|XBsvXZ^qVCY$LUa{5?!CgwY?EG;*)0ceFe&=A;!~o`ae}Z+6me#^sv- z1F6=WNd6>M(~ z+092z>?Clrcp)lYNQl9jN-JF6n&Y0mp7|I0dpPx+4*RRK+VQI~>en0Dc;Zfl+x z_e_b7s`t1_A`RP3$H}y7F9_na%D7EM+**G_Z0l_nwE+&d_kc35n$Fxkd4r=ltRZhh zr9zER8>j(EdV&Jgh(+i}ltESBK62m0nGH6tCBr90!4)-`HeBmz54p~QP#dsu%nb~W z7sS|(Iydi>C@6ZM(Us!jyIiszMkd)^u<1D+R@~O>HqZIW&kearPWmT>63%_t2B{_G zX{&a(gOYJx!Hq=!T$RZ&<8LDnxsmx9+TBL0gTk$|vz9O5GkK_Yx+55^R=2g!K}NJ3 zW?C;XQCHZl7H`K5^BF!Q5X2^Mj93&0l_O3Ea3!Ave|ixx+~bS@Iv18v2ctpSt4zO{ zp#7pj!AtDmti$T`e9{s^jf(ku&E|83JIJO5Qo9weT6g?@vX!{7)cNwymo1+u(YQ94 zopuz-L@|5=h8A!(g-MXgLJC0MA|CgQF8qlonnu#j z;uCeq9ny9QSD|p)9sp3ebgY3rk#y0DA(SHdh$DUm^?GI<>%e1?&}w(b zdip1;P2Z=1wM+$q=TgLP$}svd!vk+BZ@h<^4R=GS2+sri7Z*2f`9 z5_?i)xj?m#pSVchk-SR!2&uNhzEi+#5t1Z$o0PoLGz*pT64%+|Wa+rd5Z}60(j?X= z{NLjtgRb|W?CUADqOS@(*MA-l|E342NxRaxLTDqsOyfWWe%N(jjBh}G zm7WPel6jXijaTiNita+z(5GCO0NM=Melxud57PP^d_U## zbA;9iVi<@wr0DGB8=T9Ab#2K_#zi=$igyK48@;V|W`fg~7;+!q8)aCOo{HA@vpSy-4`^!ze6-~8|QE||hC{ICKllG9fbg_Y7v z$jn{00!ob3!@~-Z%!rSZ0JO#@>|3k10mLK0JRKP-Cc8UYFu>z93=Ab-r^oL2 zl`-&VBh#=-?{l1TatC;VweM^=M7-DUE>m+xO7Xi6vTEsReyLs8KJ+2GZ&rxw$d4IT zPXy6pu^4#e;;ZTsgmG+ZPx>piodegkx2n0}SM77+Y*j^~ICvp#2wj^BuqRY*&cjmL zcKp78aZt>e{3YBb4!J_2|K~A`lN=u&5j!byw`1itV(+Q_?RvV7&Z5XS1HF)L2v6ji z&kOEPmv+k_lSXb{$)of~(BkO^py&7oOzpjdG>vI1kcm_oPFHy38%D4&A4h_CSo#lX z2#oqMCTEP7UvUR3mwkPxbl8AMW(e{ARi@HCYLPSHE^L<1I}OgZD{I#YH#GKnpRmW3 z2jkz~Sa(D)f?V?$gNi?6)Y;Sm{&?~2p=0&BUl_(@hYeX8YjaRO=IqO7neK0RsSNdYjD zaw$g2sG(>JR=8Iz1SK4`*kqd_3-?;_BIcaaMd^}<@MYbYisWZm2C2|Np_l|8r9yM|JkUngSo@?wci(7&O9a z%|V(4C1c9pps0xxzPbXH=}QTxc2rr7fXk$9`a6TbWKPCz&p=VsB8^W96W=BsB|7bc zf(QR8&Ktj*iz)wK&mW`#V%4XTM&jWNnDF56O+2bo<3|NyUhQ%#OZE8$Uv2a@J>D%t zMVMiHh?es!Ex19q&6eC&L=XDU_BA&uR^^w>fpz2_`U87q_?N2y;!Z!bjoeKrzfC)} z?m^PM=(z{%n9K`p|7Bz$LuC7!>tFOuN74MFELm}OD9?%jpT>38J;=1Y-VWtZAscaI z_8jUZ#GwWz{JqvGEUmL?G#l5E=*m>`cY?m*XOc*yOCNtpuIGD+Z|kn4Xww=BLrNYS zGO=wQh}Gtr|7DGXLF%|`G>J~l{k^*{;S-Zhq|&HO7rC_r;o`gTB7)uMZ|WWIn@e0( zX$MccUMv3ABg^$%_lNrgU{EVi8O^UyGHPNRt%R!1#MQJn41aD|_93NsBQhP80yP<9 zG4(&0u7AtJJXLPcqzjv`S~5;Q|5TVGccN=Uzm}K{v)?f7W!230C<``9(64}D2raRU zAW5bp%}VEo{4Rko`bD%Ehf=0voW?-4Mk#d3_pXTF!-TyIt6U+({6OXWVAa;s-`Ta5 zTqx&8msH3+DLrVmQOTBOAj=uoxKYT3DS1^zBXM?1W+7gI!aQNPYfUl{3;PzS9*F7g zWJN8x?KjBDx^V&6iCY8o_gslO16=kh(|Gp)kz8qlQ`dzxQv;)V&t+B}wwdi~uBs4? zu~G|}y!`3;8#vIMUdyC7YEx6bb^1o}G!Jky4cN?BV9ejBfN<&!4M)L&lRKiuMS#3} z_B}Nkv+zzxhy{dYCW$oGC&J(Ty&7%=5B$sD0bkuPmj7g>|962`(Q{ZZMDv%YMuT^KweiRDvYTEop3IgFv#)(w>1 zSzH>J`q!LK)c(AK>&Ib)A{g`Fdykxqd`Yq@yB}E{gnQV$K!}RsgMGWqC3DKE(=!{}ekB3+(1?g}xF>^icEJbc z5bdxAPkW90atZT+&*7qoLqL#p=>t-(-lsnl2XMpZcYeW|o|a322&)yO_8p(&Sw{|b zn(tY$xn5yS$DD)UYS%sP?c|z>1dp!QUD)l;aW#`%qMtQJjE!s2z`+bTSZmLK7SvCR z=@I4|U^sCwZLQSfd*ACw9B@`1c1|&i^W_OD(570SDLK`MD0wTiR8|$7+%{cF&){$G zU~|$^Ed?TIxyw{1$e|D$050n8AjJvvOWhLtLHbSB|HIfjMp+gu>DraHZJRrdO53(= z+o-f{+qNog+qSLB%KY;5>Av6X(>-qYk3IIEwZ5~6a+P9lMpC^ z8CJ0q>rEpjlsxCvJm=kms@tlN4+sv}He`xkr`S}bGih4t`+#VEIt{1veE z{ZLtb_pSbcfcYPf4=T1+|BtR!x5|X#x2TZEEkUB6kslKAE;x)*0x~ES0kl4Dex4e- zT2P~|lT^vUnMp{7e4OExfxak0EE$Hcw;D$ehTV4a6hqxru0$|Mo``>*a5=1Ym0u>BDJKO|=TEWJ5jZu!W}t$Kv{1!q`4Sn7 zrxRQOt>^6}Iz@%gA3&=5r;Lp=N@WKW;>O!eGIj#J;&>+3va^~GXRHCY2}*g#9ULab zitCJt-OV0*D_Q3Q`p1_+GbPxRtV_T`jyATjax<;zZ?;S+VD}a(aN7j?4<~>BkHK7bO8_Vqfdq1#W&p~2H z&w-gJB4?;Q&pG9%8P(oOGZ#`!m>qAeE)SeL*t8KL|1oe;#+uOK6w&PqSDhw^9-&Fa zuEzbi!!7|YhlWhqmiUm!muO(F8-F7|r#5lU8d0+=;<`{$mS=AnAo4Zb^{%p}*gZL! zeE!#-zg0FWsSnablw!9$<&K(#z!XOW z;*BVx2_+H#`1b@>RtY@=KqD)63brP+`Cm$L1@ArAddNS1oP8UE$p05R=bvZoYz+^6 z<)!v7pRvi!u_-V?!d}XWQR1~0q(H3{d^4JGa=W#^Z<@TvI6J*lk!A zZ*UIKj*hyO#5akL*Bx6iPKvR3_2-^2mw|Rh-3O_SGN3V9GRo52Q;JnW{iTGqb9W99 z7_+F(Op6>~3P-?Q8LTZ-lwB}xh*@J2Ni5HhUI3`ct|*W#pqb>8i*TXOLn~GlYECIj zhLaa_rBH|1jgi(S%~31Xm{NB!30*mcsF_wgOY2N0XjG_`kFB+uQuJbBm3bIM$qhUyE&$_u$gb zpK_r{99svp3N3p4yHHS=#csK@j9ql*>j0X=+cD2dj<^Wiu@i>c_v zK|ovi7}@4sVB#bzq$n3`EgI?~xDmkCW=2&^tD5RuaSNHf@Y!5C(Is$hd6cuyoK|;d zO}w2AqJPS`Zq+(mc*^%6qe>1d&(n&~()6-ZATASNPsJ|XnxelLkz8r1x@c2XS)R*H(_B=IN>JeQUR;T=i3<^~;$<+8W*eRKWGt7c#>N`@;#!`kZ!P!&{9J1>_g8Zj zXEXxmA=^{8A|3=Au+LfxIWra)4p<}1LYd_$1KI0r3o~s1N(x#QYgvL4#2{z8`=mXy zQD#iJ0itk1d@Iy*DtXw)Wz!H@G2St?QZFz zVPkM%H8Cd2EZS?teQN*Ecnu|PrC!a7F_XX}AzfZl3fXfhBtc2-)zaC2eKx*{XdM~QUo4IwcGgVdW69 z1UrSAqqMALf^2|(I}hgo38l|Ur=-SC*^Bo5ej`hb;C$@3%NFxx5{cxXUMnTyaX{>~ zjL~xm;*`d08bG_K3-E+TI>#oqIN2=An(C6aJ*MrKlxj?-;G zICL$hi>`F%{xd%V{$NhisHSL~R>f!F7AWR&7b~TgLu6!3s#~8|VKIX)KtqTH5aZ8j zY?wY)XH~1_a3&>#j7N}0az+HZ;is;Zw(Am{MX}YhDTe(t{ZZ;TG}2qWYO+hdX}vp9 z@uIRR8g#y~-^E`Qyem(31{H0&V?GLdq9LEOb2(ea#e-$_`5Q{T%E?W(6 z(XbX*Ck%TQM;9V2LL}*Tf`yzai{0@pYMwBu%(I@wTY!;kMrzcfq0w?X`+y@0ah510 zQX5SU(I!*Fag4U6a7Lw%LL;L*PQ}2v2WwYF(lHx_Uz2ceI$mnZ7*eZ?RFO8UvKI0H z9Pq-mB`mEqn6n_W9(s~Jt_D~j!Ln9HA)P;owD-l~9FYszs)oEKShF9Zzcmnb8kZ7% zQ`>}ki1kwUO3j~ zEmh140sOkA9v>j@#56ymn_RnSF`p@9cO1XkQy6_Kog?0ivZDb`QWOX@tjMd@^Qr(p z!sFN=A)QZm!sTh(#q%O{Ovl{IxkF!&+A)w2@50=?a-+VuZt6On1;d4YtUDW{YNDN_ zG@_jZi1IlW8cck{uHg^g=H58lPQ^HwnybWy@@8iw%G! zwB9qVGt_?~M*nFAKd|{cGg+8`+w{j_^;nD>IrPf-S%YjBslSEDxgKH{5p)3LNr!lD z4ii)^%d&cCXIU7UK?^ZQwmD(RCd=?OxmY(Ko#+#CsTLT;p#A%{;t5YpHFWgl+@)N1 zZ5VDyB;+TN+g@u~{UrWrv)&#u~k$S&GeW)G{M#&Di)LdYk?{($Cq zZGMKeYW)aMtjmKgvF0Tg>Mmkf9IB#2tYmH-s%D_9y3{tfFmX1BSMtbe<(yqAyWX60 zzkgSgKb3c{QPG2MalYp`7mIrYg|Y<4Jk?XvJK)?|Ecr+)oNf}XLPuTZK%W>;<|r+% zTNViRI|{sf1v7CsWHvFrkQ$F7+FbqPQ#Bj7XX=#M(a~9^80}~l-DueX#;b}Ajn3VE z{BWI}$q{XcQ3g{(p>IOzFcAMDG0xL)H%wA)<(gl3I-oVhK~u_m=hAr&oeo|4lZbf} z+pe)c34Am<=z@5!2;_lwya;l?xV5&kWe}*5uBvckm(d|7R>&(iJNa6Y05SvlZcWBlE{{%2- z`86)Y5?H!**?{QbzGG~|k2O%eA8q=gxx-3}&Csf6<9BsiXC)T;x4YmbBIkNf;0Nd5 z%whM^!K+9zH>on_<&>Ws?^v-EyNE)}4g$Fk?Z#748e+GFp)QrQQETx@u6(1fk2!(W zWiCF~MomG*y4@Zk;h#2H8S@&@xwBIs|82R*^K(i*0MTE%Rz4rgO&$R zo9Neb;}_ulaCcdn3i17MO3NxzyJ=l;LU*N9ztBJ30j=+?6>N4{9YXg$m=^9@Cl9VY zbo^{yS@gU=)EpQ#;UIQBpf&zfCA;00H-ee=1+TRw@(h%W=)7WYSb5a%$UqNS@oI@= zDrq|+Y9e&SmZrH^iA>Of8(9~Cf-G(P^5Xb%dDgMMIl8gk6zdyh`D3OGNVV4P9X|EvIhplXDld8d z^YWtYUz@tpg*38Xys2?zj$F8%ivA47cGSl;hjD23#*62w3+fwxNE7M7zVK?x_`dBSgPK zWY_~wF~OEZi9|~CSH8}Xi>#8G73!QLCAh58W+KMJJC81{60?&~BM_0t-u|VsPBxn* zW7viEKwBBTsn_A{g@1!wnJ8@&h&d>!qAe+j_$$Vk;OJq`hrjzEE8Wjtm)Z>h=*M25 zOgETOM9-8xuuZ&^@rLObtcz>%iWe%!uGV09nUZ*nxJAY%&KAYGY}U1WChFik7HIw% zZP$3Bx|TG_`~19XV7kfi2GaBEhKap&)Q<9`aPs#^!kMjtPb|+-fX66z3^E)iwyXK7 z8)_p<)O{|i&!qxtgBvWXx8*69WO$5zACl++1qa;)0zlXf`eKWl!0zV&I`8?sG)OD2Vy?reNN<{eK+_ za4M;Hh%&IszR%)&gpgRCP}yheQ+l#AS-GnY81M!kzhWxIR?PW`G3G?} z$d%J28uQIuK@QxzGMKU_;r8P0+oIjM+k)&lZ39i#(ntY)*B$fdJnQ3Hw3Lsi8z&V+ zZly2}(Uzpt2aOubRjttzqrvinBFH4jrN)f0hy)tj4__UTwN)#1fj3-&dC_Vh7}ri* zfJ=oqLMJ-_<#rwVyN}_a-rFBe2>U;;1(7UKH!$L??zTbbzP#bvyg7OQBGQklJ~DgP zd<1?RJ<}8lWwSL)`jM53iG+}y2`_yUvC!JkMpbZyb&50V3sR~u+lok zT0uFRS-yx@8q4fPRZ%KIpLp8R#;2%c&Ra4p(GWRT4)qLaPNxa&?8!LRVdOUZ)2vrh zBSx&kB%#Y4!+>~)<&c>D$O}!$o{<1AB$M7-^`h!eW;c(3J~ztoOgy6Ek8Pwu5Y`Xion zFl9fb!k2`3uHPAbd(D^IZmwR5d8D$495nN2`Ue&`W;M-nlb8T-OVKt|fHk zBpjX$a(IR6*-swdNk@#}G?k6F-~c{AE0EWoZ?H|ZpkBxqU<0NUtvubJtwJ1mHV%9v?GdDw; zAyXZiD}f0Zdt-cl9(P1la+vQ$Er0~v}gYJVwQazv zH#+Z%2CIfOf90fNMGos|{zf&N`c0@x0N`tkFv|_9af3~<0z@mnf*e;%r*Fbuwl-IW z{}B3=(mJ#iwLIPiUP`J3SoP~#)6v;aRXJ)A-pD2?_2_CZ#}SAZ<#v7&Vk6{*i(~|5 z9v^nC`T6o`CN*n%&9+bopj^r|E(|pul;|q6m7Tx+U|UMjWK8o-lBSgc3ZF=rP{|l9 zc&R$4+-UG6i}c==!;I#8aDIbAvgLuB66CQLRoTMu~jdw`fPlKy@AKYWS-xyZzPg&JRAa@m-H43*+ne!8B7)HkQY4 zIh}NL4Q79a-`x;I_^>s$Z4J4-Ngq=XNWQ>yAUCoe&SMAYowP>r_O}S=V+3=3&(O=h zNJDYNs*R3Y{WLmBHc?mFEeA4`0Y`_CN%?8qbDvG2m}kMAiqCv`_BK z_6a@n`$#w6Csr@e2YsMx8udNWtNt=kcqDZdWZ-lGA$?1PA*f4?X*)hjn{sSo8!bHz zb&lGdAgBx@iTNPK#T_wy`KvOIZvTWqSHb=gWUCKXAiB5ckQI`1KkPx{{%1R*F2)Oc z(9p@yG{fRSWE*M9cdbrO^)8vQ2U`H6M>V$gK*rz!&f%@3t*d-r3mSW>D;wYxOhUul zk~~&ip5B$mZ~-F1orsq<|1bc3Zpw6)Ws5;4)HilsN;1tx;N6)tuePw& z==OlmaN*ybM&-V`yt|;vDz(_+UZ0m&&9#{9O|?0I|4j1YCMW;fXm}YT$0%EZ5^YEI z4i9WV*JBmEU{qz5O{#bs`R1wU%W$qKx?bC|e-iS&d*Qm7S=l~bMT{~m3iZl+PIXq{ zn-c~|l)*|NWLM%ysfTV-oR0AJ3O>=uB-vpld{V|cWFhI~sx>ciV9sPkC*3i0Gg_9G!=4ar*-W?D9)?EFL1=;O+W8}WGdp8TT!Fgv z{HKD`W>t(`Cds_qliEzuE!r{ihwEv1l5o~iqlgjAyGBi)$%zNvl~fSlg@M=C{TE;V zQkH`zS8b&!ut(m)%4n2E6MB>p*4(oV>+PT51#I{OXs9j1vo>9I<4CL1kv1aurV*AFZ^w_qfVL*G2rG@D2 zrs87oV3#mf8^E5hd_b$IXfH6vHe&lm@7On~Nkcq~YtE!}ad~?5*?X*>y`o;6Q9lkk zmf%TYonZM`{vJg$`lt@MXsg%*&zZZ0uUSse8o=!=bfr&DV)9Y6$c!2$NHyYAQf*Rs zk{^?gl9E z5Im8wlAsvQ6C2?DyG@95gUXZ3?pPijug25g;#(esF_~3uCj3~94}b*L>N2GSk%Qst z=w|Z>UX$m!ZOd(xV*2xvWjN&c5BVEdVZ0wvmk)I+YxnyK%l~caR=7uNQ=+cnNTLZ@&M!I$Mj-r{!P=; z`C2)D=VmvK8@T5S9JZoRtN!S*D_oqOxyy!q6Zk|~4aT|*iRN)fL)c>-yycR>-is0X zKrko-iZw(f(!}dEa?hef5yl%p0-v-8#8CX8!W#n2KNyT--^3hq6r&`)5Y@>}e^4h- zlPiDT^zt}Ynk&x@F8R&=)k8j$=N{w9qUcIc&)Qo9u4Y(Ae@9tA`3oglxjj6c{^pN( zQH+Uds2=9WKjH#KBIwrQI%bbs`mP=7V>rs$KG4|}>dxl_k!}3ZSKeEen4Iswt96GGw`E6^5Ov)VyyY}@itlj&sao|>Sb5 zeY+#1EK(}iaYI~EaHQkh7Uh>DnzcfIKv8ygx1Dv`8N8a6m+AcTa-f;17RiEed>?RT zk=dAksmFYPMV1vIS(Qc6tUO+`1jRZ}tcDP? zt)=7B?yK2RcAd1+Y!$K5*ds=SD;EEqCMG6+OqPoj{&8Y5IqP(&@zq@=A7+X|JBRi4 zMv!czlMPz)gt-St2VZwDD=w_S>gRpc-g zUd*J3>bXeZ?Psjohe;z7k|d<*T21PA1i)AOi8iMRwTBSCd0ses{)Q`9o&p9rsKeLaiY zluBw{1r_IFKR76YCAfl&_S1*(yFW8HM^T()&p#6y%{(j7Qu56^ZJx1LnN`-RTwimdnuo*M8N1ISl+$C-%=HLG-s} zc99>IXRG#FEWqSV9@GFW$V8!{>=lSO%v@X*pz*7()xb>=yz{E$3VE;e)_Ok@A*~El zV$sYm=}uNlUxV~6e<6LtYli1!^X!Ii$L~j4e{sI$tq_A(OkGquC$+>Rw3NFObV2Z)3Rt~Jr{oYGnZaFZ^g5TDZlg;gaeIP} z!7;T{(9h7mv{s@piF{-35L=Ea%kOp;^j|b5ZC#xvD^^n#vPH=)lopYz1n?Kt;vZmJ z!FP>Gs7=W{sva+aO9S}jh0vBs+|(B6Jf7t4F^jO3su;M13I{2rd8PJjQe1JyBUJ5v zcT%>D?8^Kp-70bP8*rulxlm)SySQhG$Pz*bo@mb5bvpLAEp${?r^2!Wl*6d7+0Hs_ zGPaC~w0E!bf1qFLDM@}zso7i~(``)H)zRgcExT_2#!YOPtBVN5Hf5~Ll3f~rWZ(UsJtM?O*cA1_W0)&qz%{bDoA}{$S&-r;0iIkIjbY~ zaAqH45I&ALpP=9Vof4OapFB`+_PLDd-0hMqCQq08>6G+C;9R~}Ug_nm?hhdkK$xpI zgXl24{4jq(!gPr2bGtq+hyd3%Fg%nofK`psHMs}EFh@}sdWCd!5NMs)eZg`ZlS#O0 zru6b8#NClS(25tXqnl{|Ax@RvzEG!+esNW-VRxba(f`}hGoqci$U(g30i}2w9`&z= zb8XjQLGN!REzGx)mg~RSBaU{KCPvQx8)|TNf|Oi8KWgv{7^tu}pZq|BS&S<53fC2K4Fw6>M^s$R$}LD*sUxdy6Pf5YKDbVet;P!bw5Al-8I1Nr(`SAubX5^D9hk6$agWpF}T#Bdf{b9-F#2WVO*5N zp+5uGgADy7m!hAcFz{-sS0kM7O)qq*rC!>W@St~^OW@R1wr{ajyYZq5H!T?P0e+)a zaQ%IL@X_`hzp~vRH0yUblo`#g`LMC%9}P;TGt+I7qNcBSe&tLGL4zqZqB!Bfl%SUa z6-J_XLrnm*WA`34&mF+&e1sPCP9=deazrM=Pc4Bn(nV;X%HG^4%Afv4CI~&l!Sjzb z{rHZ3od0!Al{}oBO>F*mOFAJrz>gX-vs!7>+_G%BB(ljWh$252j1h;9p~xVA=9_`P z5KoFiz96_QsTK%B&>MSXEYh`|U5PjX1(+4b#1PufXRJ*uZ*KWdth1<0 zsAmgjT%bowLyNDv7bTUGy|g~N34I-?lqxOUtFpTLSV6?o?<7-UFy*`-BEUsrdANh} zBWkDt2SAcGHRiqz)x!iVoB~&t?$yn6b#T=SP6Ou8lW=B>=>@ik93LaBL56ub`>Uo!>0@O8?e)$t(sgy$I z6tk3nS@yFFBC#aFf?!d_3;%>wHR;A3f2SP?Na8~$r5C1N(>-ME@HOpv4B|Ty7%jAv zR}GJwsiJZ5@H+D$^Cwj#0XA_(m^COZl8y7Vv(k=iav1=%QgBOVzeAiw zaDzzdrxzj%sE^c9_uM5D;$A_7)Ln}BvBx^=)fO+${ou%B*u$(IzVr-gH3=zL6La;G zu0Kzy5CLyNGoKRtK=G0-w|tnwI)puPDOakRzG(}R9fl7#<|oQEX;E#yCWVg95 z;NzWbyF&wGg_k+_4x4=z1GUcn6JrdX4nOVGaAQ8#^Ga>aFvajQN{!+9rgO-dHP zIp@%&ebVg}IqnRWwZRTNxLds+gz2@~VU(HI=?Epw>?yiEdZ>MjajqlO>2KDxA>)cj z2|k%dhh%d8SijIo1~20*5YT1eZTDkN2rc^zWr!2`5}f<2f%M_$to*3?Ok>e9$X>AV z2jYmfAd)s|(h?|B(XYrIfl=Wa_lBvk9R1KaP{90-z{xKi+&8=dI$W0+qzX|ZovWGOotP+vvYR(o=jo?k1=oG?%;pSqxcU* zWVGVMw?z__XQ9mnP!hziHC`ChGD{k#SqEn*ph6l46PZVkm>JF^Q{p&0=MKy_6apts z`}%_y+Tl_dSP(;Ja&sih$>qBH;bG;4;75)jUoVqw^}ee=ciV;0#t09AOhB^Py7`NC z-m+ybq1>_OO+V*Z>dhk}QFKA8V?9Mc4WSpzj{6IWfFpF7l^au#r7&^BK2Ac7vCkCn{m0uuN93Ee&rXfl1NBY4NnO9lFUp zY++C1I;_{#OH#TeP2Dp?l4KOF8ub?m6zE@XOB5Aiu$E~QNBM@;r+A5mF2W1-c7>ex zHiB=WJ&|`6wDq*+xv8UNLVUy4uW1OT>ey~Xgj@MMpS@wQbHAh>ysYvdl-1YH@&+Q! z075(Qd4C!V`9Q9jI4 zSt{HJRvZec>vaL_brKhQQwbpQd4_Lmmr0@1GdUeU-QcC{{8o=@nwwf>+dIKFVzPriGNX4VjHCa zTbL9w{Y2V87c2ofX%`(48A+4~mYTiFFl!e{3K^C_k%{&QTsgOd0*95KmWN)P}m zTRr{`f7@=v#+z_&fKYkQT!mJn{*crj%ZJz#(+c?>cD&2Lo~FFAWy&UG*Op^pV`BR^I|g?T>4l5;b|5OQ@t*?_Slp`*~Y3`&RfKD^1uLezIW(cE-Dq2z%I zBi8bWsz0857`6e!ahet}1>`9cYyIa{pe53Kl?8|Qg2RGrx@AlvG3HAL-^9c^1GW;)vQt8IK+ zM>!IW*~682A~MDlyCukldMd;8P|JCZ&oNL(;HZgJ>ie1PlaInK7C@Jg{3kMKYui?e!b`(&?t6PTb5UPrW-6DVU%^@^E`*y-Fd(p|`+JH&MzfEq;kikdse ziFOiDWH(D< zyV7Rxt^D0_N{v?O53N$a2gu%1pxbeK;&ua`ZkgSic~$+zvt~|1Yb=UfKJW2F7wC^evlPf(*El+#}ZBy0d4kbVJsK- z05>;>?HZO(YBF&v5tNv_WcI@O@LKFl*VO?L(!BAd!KbkVzo;v@~3v`-816GG?P zY+H3ujC>5=Am3RIZDdT#0G5A6xe`vGCNq88ZC1aVXafJkUlcYmHE^+Z{*S->ol%-O znm9R0TYTr2w*N8Vs#s-5=^w*{Y}qp5GG)Yt1oLNsH7y~N@>Eghms|K*Sdt_u!&I}$ z+GSdFTpbz%KH+?B%Ncy;C`uW6oWI46(tk>r|5|-K6)?O0d_neghUUOa9BXHP*>vi; z={&jIGMn-92HvInCMJcyXwHTJ42FZp&Wxu+9Rx;1x(EcIQwPUQ@YEQQ`bbMy4q3hP zNFoq~Qd0=|xS-R}k1Im3;8s{BnS!iaHIMLx)aITl)+)?Yt#fov|Eh>}dv@o6R{tG>uHsy&jGmWN5+*wAik|78(b?jtysPHC#e+Bzz~V zS3eEXv7!Qn4uWi!FS3B?afdD*{fr9>B~&tc671fi--V}~E4un;Q|PzZRwk-azprM$4AesvUb5`S`(5x#5VJ~4%ET6&%GR$}muHV-5lTsCi_R|6KM(g2PCD@|yOpKluT zakH!1V7nKN)?6JmC-zJoA#ciFux8!)ajiY%K#RtEg$gm1#oKUKX_Ms^%hvKWi|B=~ zLbl-L)-=`bfhl`>m!^sRR{}cP`Oim-{7}oz4p@>Y(FF5FUEOfMwO!ft6YytF`iZRq zfFr{!&0Efqa{1k|bZ4KLox;&V@ZW$997;+Ld8Yle91he{BfjRhjFTFv&^YuBr^&Pe zswA|Bn$vtifycN8Lxr`D7!Kygd7CuQyWqf}Q_PM}cX~S1$-6xUD%-jrSi24sBTFNz(Fy{QL2AmNbaVggWOhP;UY4D>S zqKr!UggZ9Pl9Nh_H;qI`-WoH{ceXj?m8y==MGY`AOJ7l0Uu z)>M%?dtaz2rjn1SW3k+p`1vs&lwb%msw8R!5nLS;upDSxViY98IIbxnh{}mRfEp=9 zbrPl>HEJeN7J=KnB6?dwEA6YMs~chHNG?pJsEj#&iUubdf3JJwu=C(t?JpE6xMyhA3e}SRhunDC zn-~83*9=mADUsk^sCc%&&G1q5T^HR9$P#2DejaG`Ui*z1hI#h7dwpIXg)C{8s< z%^#@uQRAg-$z&fmnYc$Duw63_Zopx|n{Bv*9Xau{a)2%?H<6D>kYY7_)e>OFT<6TT z0A}MQLgXbC2uf`;67`mhlcUhtXd)Kbc$PMm=|V}h;*_%vCw4L6r>3Vi)lE5`8hkSg zNGmW-BAOO)(W((6*e_tW&I>Nt9B$xynx|sj^ux~?q?J@F$L4;rnm_xy8E*JYwO-02u9_@@W0_2@?B@1J{y~Q39N3NX^t7#`=34Wh)X~sU&uZWgS1Z09%_k|EjA4w_QqPdY`oIdv$dJZ;(!k)#U8L+|y~gCzn+6WmFt#d{OUuKHqh1-uX_p*Af8pFYkYvKPKBxyid4KHc}H` z*KcyY;=@wzXYR{`d{6RYPhapShXIV?0cg_?ahZ7do)Ot#mxgXYJYx}<%E1pX;zqHd zf!c(onm{~#!O$2`VIXezECAHVd|`vyP)Uyt^-075X@NZDBaQt<>trA3nY-Dayki4S zZ^j6CCmx1r46`4G9794j-WC0&R9(G7kskS>=y${j-2;(BuIZTLDmAyWTG~`0)Bxqk zd{NkDe9ug|ms@0A>JVmB-IDuse9h?z9nw!U6tr7t-Lri5H`?TjpV~8(gZWFq4Vru4 z!86bDB;3lpV%{rZ`3gtmcRH1hjj!loI9jN>6stN6A*ujt!~s!2Q+U1(EFQEQb(h4E z6VKuRouEH`G6+8Qv2C)K@^;ldIuMVXdDDu}-!7FS8~k^&+}e9EXgx~)4V4~o6P^52 z)a|`J-fOirL^oK}tqD@pqBZi_;7N43%{IQ{v&G9^Y^1?SesL`;Z(dt!nn9Oj5Odde%opv&t zxJ><~b#m+^KV&b?R#)fRi;eyqAJ_0(nL*61yPkJGt;gZxSHY#t>ATnEl-E%q$E16% zZdQfvhm5B((y4E3Hk6cBdwGdDy?i5CqBlCVHZr-rI$B#>Tbi4}Gcvyg_~2=6O9D-8 zY2|tKrNzbVR$h57R?Pe+gUU_il}ZaWu|Az#QO@};=|(L-RVf0AIW zq#pO+RfM7tdV`9lI6g;{qABNId`fG%U9Va^ravVT^)CklDcx)YJKeJdGpM{W1v8jg z@&N+mR?BPB=K1}kNwXk_pj44sd>&^;d!Z~P>O78emE@Qp@&8PyB^^4^2f7e)gekMv z2aZNvP@;%i{+_~>jK7*2wQc6nseT^n6St9KG#1~Y@$~zR_=AcO2hF5lCoH|M&c{vR zSp(GRVVl=T*m~dIA;HvYm8HOdCkW&&4M~UDd^H)`p__!4k+6b)yG0Zcek8OLw$C^K z3-BbLiG_%qX|ZYpXJ$(c@aa7b4-*IQkDF}=gZSV`*ljP|5mWuHSCcf$5qqhZTv&P?I$z^>}qP(q!Aku2yA5vu38d8x*q{6-1`%PrE_r0-9Qo?a#7Zbz#iGI7K<(@k^|i4QJ1H z4jx?{rZbgV!me2VT72@nBjucoT zUM9;Y%TCoDop?Q5fEQ35bCYk7!;gH*;t9t-QHLXGmUF;|vm365#X)6b2Njsyf1h9JW#x$;@x5Nx2$K$Z-O3txa%;OEbOn6xBzd4n4v)Va=sj5 z%rb#j7{_??Tjb8(Hac<^&s^V{yO-BL*uSUk2;X4xt%NC8SjO-3?;Lzld{gM5A=9AV z)DBu-Z8rRvXXwSVDH|dL-3FODWhfe1C_iF``F05e{dl(MmS|W%k-j)!7(ARkV?6r~ zF=o42y+VapxdZn;GnzZfGu<6oG-gQ7j7Zvgo7Am@jYxC2FpS@I;Jb%EyaJDBQC(q% zKlZ}TVu!>;i3t~OAgl@QYy1X|T~D{HOyaS*Bh}A}S#a9MYS{XV{R-|niEB*W%GPW! zP^NU(L<}>Uab<;)#H)rYbnqt|dOK(-DCnY==%d~y(1*{D{Eo1cqIV8*iMfx&J*%yh zx=+WHjt0q2m*pLx8=--UqfM6ZWjkev>W-*}_*$Y(bikH`#-Gn#!6_ zIA&kxn;XYI;eN9yvqztK-a113A%97in5CL5Z&#VsQ4=fyf&3MeKu70)(x^z_uw*RG zo2Pv&+81u*DjMO6>Mrr7vKE2CONqR6C0(*;@4FBM;jPIiuTuhQ-0&C)JIzo_k>TaS zN_hB;_G=JJJvGGpB?uGgSeKaix~AkNtYky4P7GDTW6{rW{}V9K)Cn^vBYKe*OmP!; zohJs=l-0sv5&phSCi&8JSrokrKP$LVa!LbtlN#T^cedgH@ijt5T-Acxd9{fQY z4qsg1O{|U5Rzh_j;9QD(g*j+*=xULyi-FY|-mUXl7-2O`TYQny<@jSQ%^ye*VW_N< z4mmvhrDYBJ;QSoPvwgi<`7g*Pwg5ANA8i%Kum;<=i|4lwEdN+`)U3f2%bcRZRK!P z70kd~`b0vX=j20UM5rBO#$V~+grM)WRhmzb15ya^Vba{SlSB4Kn}zf#EmEEhGruj| zBn0T2n9G2_GZXnyHcFkUlzdRZEZ0m&bP-MxNr zd;kl7=@l^9TVrg;Y6J(%!p#NV*Lo}xV^Nz0#B*~XRk0K2hgu5;7R9}O=t+R(r_U%j z$`CgPL|7CPH&1cK5vnBo<1$P{WFp8#YUP%W)rS*a_s8kKE@5zdiAh*cjmLiiKVoWD z!y$@Cc5=Wj^VDr$!04FI#%pu6(a9 zM_FAE+?2tp2<$Sqp5VtADB>yY*cRR+{OeZ5g2zW=`>(tA~*-T)X|ahF{xQmypWp%2X{385+=0S|Jyf`XA-c7wAx`#5n2b-s*R>m zP30qtS8aUXa1%8KT8p{=(yEvm2Gvux5z22;isLuY5kN{IIGwYE1Pj);?AS@ex~FEt zQ`Gc|)o-eOyCams!|F0_;YF$nxcMl^+z0sSs@ry01hpsy3p<|xOliR zr-dxK0`DlAydK!br?|Xi(>buASy4@C8)ccRCJ3w;v&tA1WOCaieifLl#(J% zODPi5fr~ASdz$Hln~PVE6xekE{Xb286t(UtYhDWo8JWN6sNyRVkIvC$unIl8QMe@^ z;1c<0RO5~Jv@@gtDGPDOdqnECOurq@l02NC#N98-suyq_)k(`G=O`dJU8I8LcP!4z z8fkgqViqFbR+3IkwLa)^>Z@O{qxTLU63~^lod{@${q;-l?S|4Tq0)As-Gz!D(*P)Vf6wm6B8GGWi7B)Q^~T?sseZeI+}LyBAG!LRZn_ktDlht1j2ok@ljteyuNUkG67 zipkCx-7k(FZQhYjZ%T9X7`tO99$Wj~K`9r0IkWhPul`Q_t1YnVK=YI1dMc_b!FEU4 zkv=PGf{5$P#w{|m92tfVnsnfd%%KW;1a*cLmga4bSYl^*49M4cs+Fe>P!n=$G6hL6 z>IM&0+c(Nvr0I!5CGx7WK*Z3V^w0+QcF=hU0B4=+;=tn*+XDxKa;NB-z4O~I zf}TSb^Z;L_Og>!D1`;w@zf@GCqCUNY%N?IPmEkTco^}bX~BWM_Hamu05>#B zBh%QfUeHPu`MsYVQQ3hOT;HmP_C|nOl zjluk7vaSICyQ01h`^c)DWp>cxPjGEc6D^~2L79hyK_J#<9H#8o`&XM4=aB`@< z<|1oR6Djf))P1l2C{qSwa4u-&LDG{FLz#ym_@I+vo}D}#%;vNN%& zW&9||THv_^B!1Fo+$3A6hEAed$I-{a^6FVvwMtT~e%*&RvY5mj<@(-{y^xn6ZCYqNK|#v^xbWpy15YL18z#Y&5YwOnd!A*@>k^7CaX0~4*6QB{Bgh$KJqesFc(lSQ{iQAKY%Ge}2CeuFJ{4YmgrP(gpcH zXJQjSH^cw`Z0tV^axT&RkOBP2A~#fvmMFrL&mwdDn<*l3;3A425_lzHL`+6sT9LeY zu@TH0u4tj199jQBzz*~Up5)7=4OP%Ok{rxQYNb!hphAoW-BFJn>O=%ov*$ir?dIx% z56Y`>?(1YQ8Fc(D7pq2`9swz@*RIoTAvMT%CPbt;$P%eG(P%*ZMjklLoXqTE*Jg^T zlEQbMi@_E|ll_>pTJ!(-x41R}4sY<5A2VVQ^#4eE{imHt#NEi+#p#EBC2C=9B4A|n zqe03T*czDqQ-VxZ+jPQG!}!M0SlFm^@wTW?otBZ+q~xkk29u1i7Q|kaJ(9{AiP1`p zbEe5&!>V;1wnQ1-Qpyn2B5!S(lh=38hl6IilCC6n4|yz~q94S9_5+Od*$c)%r|)f~ z;^-lf=6POs>Ur4i-F>-wm;3(v7Y_itzt)*M!b~&oK%;re(p^>zS#QZ+Rt$T#Y%q1{ zx+?@~+FjR1MkGr~N`OYBSsVr}lcBZ+ij!0SY{^w((2&U*M`AcfSV9apro+J{>F&tX zT~e zMvsv$Q)AQl_~);g8OOt4plYESr8}9?T!yO(Wb?b~1n0^xVG;gAP}d}#%^9wqN7~F5 z!jWIpqxZ28LyT|UFH!u?V>F6&Hd~H|<(3w*o{Ps>G|4=z`Ws9oX5~)V=uc?Wmg6y< zJKnB4Opz^9v>vAI)ZLf2$pJdm>ZwOzCX@Yw0;-fqB}Ow+u`wglzwznQAP(xbs`fA7 zylmol=ea)g}&;8;)q0h7>xCJA+01w+RY`x`RO% z9g1`ypy?w-lF8e5xJXS4(I^=k1zA46V)=lkCv?k-3hR9q?oZPzwJl$yOHWeMc9wFuE6;SObNsmC4L6;eWPuAcfHoxd59gD7^Xsb$lS_@xI|S-gb? z*;u@#_|4vo*IUEL2Fxci+@yQY6<&t=oNcWTVtfi1Ltveqijf``a!Do0s5e#BEhn5C zBXCHZJY-?lZAEx>nv3k1lE=AN10vz!hpeUY9gy4Xuy940j#Rq^yH`H0W2SgXtn=X1 zV6cY>fVbQhGwQIaEG!O#p)aE8&{gAS z^oVa-0M`bG`0DE;mV)ATVNrt;?j-o*?Tdl=M&+WrW12B{+5Um)qKHd_HIv@xPE+;& zPI|zXfrErYzDD2mOhtrZLAQ zP#f9e!vqBSyoKZ#{n6R1MAW$n8wH~)P3L~CSeBrk4T0dzIp&g9^(_5zY*7$@l%%nL zG$Z}u8pu^Mw}%{_KDBaDjp$NWes|DGAn~WKg{Msbp*uPiH9V|tJ_pLQROQY?T0Pmt zs4^NBZbn7B^L%o#q!-`*+cicZS9Ycu+m)rDb98CJ+m1u}e5ccKwbc0|q)ICBEnLN# zV)8P1s;r@hE3sG2wID0@`M9XIn~hm+W1(scCZr^Vs)w4PKIW_qasyjbOBC`ixG8K$ z9xu^v(xNy4HV{wu2z-B87XG#yWu~B6@|*X#BhR!_jeF*DG@n_RupAvc{DsC3VCHT# za6Z&9k#<*y?O0UoK3MLlSX6wRh`q&E>DOZTG=zRxj0pR0c3vskjPOqkh9;o>a1>!P zxD|LU0qw6S4~iN8EIM2^$k72(=a6-Tk?%1uSj@0;u$0f*LhC%|mC`m`w#%W)IK zN_UvJkmzdP84ZV7CP|@k>j^ zPa%;PDu1TLyNvLQdo!i1XA|49nN}DuTho6=z>Vfduv@}mpM({Jh289V%W@9opFELb z?R}D#CqVew1@W=XY-SoMNul(J)zX(BFP?#@9x<&R!D1X&d|-P;VS5Gmd?Nvu$eRNM zG;u~o*~9&A2k&w}IX}@x>LMHv`ith+t6`uQGZP8JyVimg>d}n$0dDw$Av{?qU=vRq zU@e2worL8vTFtK@%pdbaGdUK*BEe$XE=pYxE_q{(hUR_Gzkn=c#==}ZS^C6fKBIfG z@hc);p+atn`3yrTY^x+<y`F0>p02jUL8cgLa|&yknDj;g73m&Sm&@ju91?uG*w?^d%Yap&d2Bp3v7KlQmh z(N<38o-iRk9*UV?wFirV>|46JqxOZ_o8xv_eJ1dv} zw&zDHZOU%`U{9ckU8DS$lB6J!B`JuThCnwKphODv`3bd?_=~tjNHstM>xoA53-p#F zLCVB^E`@r_D>yHLr10Sm4NRX8FQ+&zw)wt)VsPmLK|vLwB-}}jwEIE!5fLE;(~|DA ztMr8D0w^FPKp{trPYHXI7-;UJf;2+DOpHt%*qRgdWawy1qdsj%#7|aRSfRmaT=a1> zJ8U>fcn-W$l-~R3oikH+W$kRR&a$L!*HdKD_g}2eu*3p)twz`D+NbtVCD|-IQdJlFnZ0%@=!g`nRA(f!)EnC0 zm+420FOSRm?OJ;~8D2w5HD2m8iH|diz%%gCWR|EjYI^n7vRN@vcBrsyQ;zha15{uh zJ^HJ`lo+k&C~bcjhccoiB77-5=SS%s7UC*H!clrU$4QY@aPf<9 z0JGDeI(6S%|K-f@U#%SP`{>6NKP~I#&rSHBTUUvHn#ul4*A@BcRR`#yL%yfZj*$_% zAa$P%`!8xJp+N-Zy|yRT$gj#4->h+eV)-R6l}+)9_3lq*A6)zZ)bnogF9`5o!)ub3 zxCx|7GPCqJlnRVPb&!227Ok@-5N2Y6^j#uF6ihXjTRfbf&ZOP zVc$!`$ns;pPW_=n|8Kw4*2&qx+WMb9!DQ7lC1f@DZyr|zeQcC|B6ma*0}X%BSmFJ6 zeDNWGf=Pmmw5b{1)OZ6^CMK$kw2z*fqN+oup2J8E^)mHj?>nWhBIN|hm#Km4eMyL= zXRqzro9k7(ulJi5J^<`KHJAh-(@W=5x>9+YMFcx$6A5dP-5i6u!k*o-zD z37IkyZqjlNh*%-)rAQrCjJo)u9Hf9Yb1f3-#a=nY&M%a{t0g7w6>{AybZ9IY46i4+%^u zwq}TCN@~S>i7_2T>GdvrCkf&=-OvQV9V3$RR_Gk7$t}63L}Y6d_4l{3b#f9vup-7s z3yKz5)54OVLzH~Ty=HwVC=c$Tl=cvi1L?R>*#ki4t6pgqdB$sx6O(IIvYO8Q>&kq;c3Y-T?b z*6XAc?orv>?V7#vxmD7geKjf%v~%yjbp%^`%e>dw96!JAm4ybAJLo0+4=TB% zShgMl)@@lgdotD?C1Ok^o&hFRYfMbmlbfk677k%%Qy-BG3V9txEjZmK+QY5nlL2D$Wq~04&rwN`-ujpp)wUm5YQc}&tK#zUR zW?HbbHFfSDsT{Xh&RoKiGp)7WPX4 zD^3(}^!TS|hm?YC16YV59v9ir>ypihBLmr?LAY87PIHgRv*SS>FqZwNJKgf6hy8?9 zaGTxa*_r`ZhE|U9S*pn5Mngb7&%!as3%^ifE@zDvX`GP+=oz@p)rAl2KL}ZO1!-us zY`+7ln`|c!2=?tVsO{C}=``aibcdc1N#;c^$BfJr84=5DCy+OT4AB1BUWkDw1R$=FneVh*ajD&(j2IcWH8stMShVcMe zAi6d7p)>hgPJbcb(=NMw$Bo;gQ}3=hCQsi{6{2s~=ZEOizY(j{zYY-W8RiNjycv00 z8(JpE{}=CHx0ib3(nZgo776X=wBUbfk$y2r*}aNG@A0_zOa4k3?1EeH7Z43{@IP>{^M+M`M)0w*@Go z>kg~UfgP1{vH+IU(0p(VRVlLNMHN1C&3cFnp*}4d1a*kwHJL)rjf`Fi5z)#RGTr7E zOhWfTtQyCo&8_N(zIYEugQI}_k|2X(=dMA43Nt*e93&otv`ha-i;ACB$tIK% zRDOtU^1CD5>7?&Vbh<+cz)(CBM}@a)qZ^ld?uYfp3OjiZOCP7u6~H# zMU;=U=1&DQ9Qp|7j4qpN5Dr7sH(p^&Sqy|{uH)lIv3wk?xoVuN`ILg}HUCLs1Bp2^ za8&M?ZQVWFX>Rg4_i$C$U`89i6O(RmWQ4&O=?B6@6`a8fI)Q6q0t{&o%)|n7jN)7V z{S;u+{UzXnUJN}bCE&4u5wBxaFv7De0huAjhy#o~6NH&1X{OA4Y>v0$F-G*gZqFym zhTZ7~nfaMdN8I&2ri;fk*`LhES$vkyq-dBuRF!BC)q%;lt0`Z(*=Sl>uvU`LAvbyt zL1|M@Jas<@1hK!prK}$@&fbf70o7>3&CovCKi815v$6T7R&1GOG~R4pEu2B z%bxG{n`u$7ps(}Tt(P608J@{+>X(?=-j8CkF!T79c`1@E%?vOL%TYrMe1ozi<##IsIC1YRojP!gD%|+7|z^-Vj$a85gbmtB#unyoy%gw9m1yB z|L^-wylT%}=pNpq!QYz9zoV7>zM2g2d9lm{Q zP|dx3=De3NSNGuMWRdO_ctQJUud?_96HbrHiSKmp;{MHZhX#*L+^I11#r;grJ8_21 zt6b*wmCaAw(>A`ftjlL@vi06Z7xF<&xNOrTHrDeMHk*$$+pGK0p+|}H=Kgl{=naBy zclyQsRTraO4!uo})OTSp_x`^0jj7>|H=FOGnAbKT_LuSUiSd3QuCMq>sEhB=V63Nm zZxrtB0)U@x2A#VHqo2ab=pn~tu>kJ;TVASb_&ePAgVcic@>^YM?^LYRLr^O12>~45 z-EE?-Z$xjxsN92EaBi)~D~1OzRVH`o!)kYv7IIx??(B)>R|xa&(wmlU2gdV0+N+3% z7r$w5(L<|?@46ITJZS5koAELgVV_&KHj(9KG??A);@gL`s1th*c#t5>U(*+nb0+H% zOhJG5tth59%*>S~JIi%<0VAi;k>}&(Ojg!fyH0(fza!1kA~a}Vt{|3z{`Pt@VuYyB zFUt(kR$<`X_J&UQ%;ui2zob1!H{PL8X>>wbpGn~@&h__AfBit)4`D^#->1+Qn^MH9 zYD?%)Pa)D-xQzVGm!g)N$^_z`9)(>)gyQ+(7N@k4GO?~43wcE-|77;CPwPXHQcfcJ^I&IOOah zzL|dhoR*#m5sw{b&L=@<-30s9F|{@V05;4Wf6Z_1gpZnJ*SVN}3O7)-=yYuj2)O0d zX=I9TzzTK%QG&ujvS!F*aJ8eqt4|#VE;``yKqCx7#8QC7AmVn+zW9km3L5TN=R>{5 zLcW`6NKkTz`c{`-w!X9zMG;JZP|skLGs7qBHaWj7Ew!VR=`>n30NX)7j~-RbDmQ6b zHr)zVcn^~e2xqFCBG4P$ZCcRDml-&1^5fqN=CHgBVu1yTg32_N>tZ;N%h*TwOf^1lE#w1$yF$kXaP|V$2XuZ+3wH4Ws6%U;^iP|c6`#etHogQ+E@+~PZ1zdGAty6qTmBM z>!)Wfgq~%lD)m>avXMm)ReN}s9!T_>ic6xA|m7$(&n(Z&j} zHC=}~I(^-*PS2pc7%>)6w}F1il&p*0jX1z)jSvG%S{I3d9w$A|5;TS)4w81yzq5f8 zZVfF~`74m1KXQg|`OS>;FCgZw!AL;2PV{&8%~rG!;`eD=g!luE0k40GjIgjD!JSDNf$eW zZtPMF)&EH_#?IwVLEx&Tosh9K8Ln4Pb$`j2=><6MAezsQvhP#YNnw&cL>12xf)dPz z1tk;{SH6HDcbV0x(+5=2n;A->&iYDa5Zr9$&j?2iAz-(l1;#Vc3-ULyqRV9d0*psG7QHE! z*J=*^sKK?iTO$g*+j~C?QzzIu`6Z{2N-ANrd5*?o%x& z&WMin)$Wq%G!?{EH(2}A?Wx@ zn8|q7xPad4Gu>l^&SBl|mhUxp;S+Cb125`h5aBz9pM34$7n-GHGx*=yqAphZKkds7 z$=5Jnt*6&8@y80jNXm|>2IR<$D5frk;c2f5zLS5xe*^W>kkZa5R1+Am34;mo{Gr=Z zD=z8fgTHwx%)7hzjOo9*Cogbru8GgDzrE;3y%TR+u`|zz%c0Tyd8;#EQXdr4Rgx(2LPRzVI2FwsbXwnF;DP^fg zdYOd|zU&AqgCJ;R+?oSgEgZM`ZX>7&$A-j2m|Tcz4ictXoQkz6Tr<2zhOudU16k<7 zLdk&FCL>=a^>0gV@m#9SnMd)R$5&1mh8p2McnUbk;1|C;`7pPkYjf|o>|a6`x`z1O zt>8~Q%zHX%C=D2!;_1eo3qfbB4QQK^{ON_f*7XhLk{6sr2(KIVmax}fUtF-zHZiUd zHPb9jidV`dE;lsw?1uQH!b%MvPE|lh9-8R_z4^PC8{XAf?S73(n*FvYPoMES+LfOx zcjm4ZZOmKY>M2e${QBVT+XnBQ(oC0fAYcXi7+=}_!hS9m>Y%G@zxn3z#Pb;bJ~-kI zAHNmWgQJp$e8L-uKQ|c4B;#0BTsfRB+}pl7xe=2_1U7pahx5S$TVbRnU0oi1?Wh|A zR7ebg9TK1GgKa4@ic#q_*<;c8?CkjX zMMyq`J()_&(j-FZY7q%z6CN^a0%V{UL)jmrvEg{doZd?qIjgJ^UPr(QUs`68;qkdI zzj_XBQ|#K2U!5?fmIEtXX6^rFY;h4=Vx<-C(d;W6Bi_Xsg{ZJPL*K;I?5U$=V-BNP zn9pKiMc=hZNe**GZBw1kVs#-8c2ZRjol}}^V@^}BqY7c0=!mA;v0`d|(d;R-iT|GK z>zt>Tt3oV09%Y;^RM6=p9C-ys_a``HB_D-pnyX(CeA(GiJqx7xxFE52Y`j~iMv;sP z%jPmx#8p%5`flAU(b!c9XBvV+fygn`BP-C#lyRa;9%>YyW6~A_g?@2J+oY0HAg{qO znT4%ViCgw&eE=W8yt-0{cw`tMieWOG3wyNX#3a^qPhE8TH1?QhwhR~}Ic zZ^q$TF8$p0b0=L8aw&qaTjuAYPmr-6x;U*k*vRnOaBwb_( z5+ls5b(E!(71*l)M&(7ZEgBCtB{6Kh#ArV4u0iNnK!ml!nK5=3;9e76yD9oU4xTAK zPGsGkjtFMMY3pRP5u07;#af?b0C7u) zD^=9X@DRasHaf#c>4rF5GAT!Ggj0!7!z?Q-1_X6ZP2g|+?nVutp|rp}eFlKc8}Q&_ z17$NpDQvQolMWZfj0W0|WKm`nd_KXYH_#wRRzs1aRBYqo#feM}a?joONn30Z4Z9PG zg1c!_<52-9D53Wq4z8pUzGkEFm1@Ws(kp4}CO7csZ-7+b)^)M)(xo}_IpTLl7}5BmbBCI{4>rw>4c_gBQHtRd5Z=SW&6Qp2qMOjr3W+ZRmP;S(U+h=^BHKohhRp6Zgf zwt&$zQXhMm@kh1@SB%dIE*kFDZym3Mky$NRljX?}&JGK`PIV1C;Pf!JV{hb4y;Ju- zlpfEPUd+mV5XQH<#BRFhZ}>b#IdF?a?x;rBg-v)@fZpA?+J{3WZjbl3E zv(a&1=pGYPxP@K!6Qg5Vx=-jwc=BA{xL3+QWb&9~DGS1EFkIC+>55{dvY4LV@s5$C zKJmCjigp7?m27*GN_GROz}y+y5%iIj=*JTYccaFjvD&VN%ewfSp=0P zspdFfDqj?gs!N64cEy5uR~wD>af!1PE*xo{^a^8BPIL2=U>B!m2AM0Jf<8qWLoHxi zxQfkbbwkRXgJgLW_j{ZkCxHLBU{@D6T5u90UNs5P769Zei|C$@nA5$L$4ZvxQl1i? z8vLHg17}e{zM$=&h%8Swbfz7yw~X^N|7Chp1bC(oV72l#R8&%Ne5>F=7wR(dB; zkDX!%&fxS19JBjP<6H7+!dO`nPLvB~xn{aDh#^iHKP|A5UQlCG%v%x9@q1w2fa#&% za^UwHu!~(qrv99G%9_e4OBbJ-CkB*1M_?t6UXZ#}4JFDzB|x(1Z}ckuiY}${zj`eVo})!rN8Je z%h2CVJG1$K$2deXx^h8trLs~Han^e>_-M6@0o4C7d548|#mKtm@DvdVAX5ZzA8=*! zKq5C+cM9u)qJ%YBJ1UAcG}6Ji4=$piaZ(K@>1BiD;$R9bR*QP`dH2T=)dgW#f7U)S zZ~i#VYLOnUZt^~Iu3x8QPJaHVUxtRyipQ+tbmWKl14iW1!f6JSDvT$xt8>~7-1ZlJ zU|)Ab*lhvz-JO!$a}RBH9u8$=R)*qeD@iS@(px~OVvML-qqO5&Ujnhw1>G~**Ld{W zE+7h|!{rDZ#;ipZx4^Tcr9vnO)0>WFPzpFu*MYST(`GFzCq*@Gqse6VwDH#x?-{rs z+=dqd$W0*AuAEhzM@GC&!oZa1*lRsx>>mP>DNYigdm^A~xzo}=uV$w#iadO+!&q_~ zT>AsHXOEGsNyfcJt2V$rhGxaIcTEvZr7CMVEu=>l30N~52^71U^<_uw6h@v@`BA2! z)ViU+wF#^$=5o44TpOj?#eyq*+A&c0ghrt8%}SiK)FgLk-;-^+ zXt|1}1vcKAAuR|?L*a8;04p%!M~U2~UC-OJK)DMtBQ#+ZttJgDFNA4zchA*T)cN(E zmpIMLU*c*NrCSV^qdLXD751DsO`#V#K1BVX4qI-B3Rg(zcvlg^mgY^V3Q*5RRQ4-8 z_kAlUisma2SNEx47euK5Y#eu_-gwRW0}M90hEI}eIJ9aU?t11^jSCn4>e~XLSF7Y3 z7JF)1ZbS_P<$<#y(*u@w!jF4FW_f~bxzi%cgP~B1K5N6GFYSAf=D_s5XomU0G9I%Y zPWc{&MItPR#^Le)?zsRkQMmHx^Cnn&;TrPzRVG`wyNH*U;|r3^2NY(z0lwikP}cWF z`p%R@?dy*7H~0&3ST>L9)b7#kwg+|n0#E&-FNf+Z_t7tpa711FogBPV`S3MW_FMGQ zJ@8Z}qXR4-l%p76mvcH`{Fu(^O;8H2@#LZUH#9p6!EX$AEYV$c`s zkPimL3kv>y=WQ+?KIAuim``%cAeBhA6g8}p_*FBH(#{vKi)CIz_D)DFXPql*ccC}O zRW;+Y6V@=&*d6QJUbRxPX+-_24tc-hYHEFaP-IAj*|-P5%xbWujQvu#TF>xigr_r! znuu7b(!PyYX=O#>;+0cGRx>Sy39(3y=TCf_BZ$<%m#inup$>o(3dA1Byfsip8S975-iVe7UklFm|$4&kaJ!n66_k-7-k}Z_?){LQe&wTeJ^CR{u6p+U#4_iSZZ1wjB-1gVGNQqnkk*-wFLj(eK8Ut{waU zb1jwb2I?Wg&98jSQWom8c?2>BWt*!3WQ?>fB$KguB9_sStno%x=JXPEFrT|hh~Po2 zSPzu3IL10O?9U(3{X8OLN-!l6DJVtgr$yYXeAPh~%(FECDe;$mIY7R4Miv1GEFk9x zpw`}E5M)qTr60D^;a#OCd0xP*w8y+my1^l8Qd*V`wLoj)GFFj;;esW2PMO=sbas{yX6asXIJ$|LW< zts$A+JaxoM({kv+2d@#bhl?#V#FZn_=8tTTvup?Vq!p!46W{be)EP=VlYE|UzAU}) zz})UzJVWi;9br0k&5>}sqwa_`TP*c}^$9+q)Dks#qEVg>p)71sqKF-YLP@UF{(>lp7;CHAWK;K0TZ_+?>EtZKprfU@;52a1IU8HNx-mnoZrb8| zP8FPb#T$0VE+G-l508;d{DSfC6#dbp(j|^i^I3z9?Qmkr+(dw^w??h}WTN{_ls-GuE~lF;1Urgbtq|Ud_r>wecb@?{{z? zX>X$&Ud+(I(5}5d^>&Z2m+qy=h#vR*lS084ATwUWZLg6PX1Ft+YI`0iI)ynij}{4X zrQE!Mr1m^-?kw<|VT0mG+5J{!;j;zJT`?_=P*09n+=e``CN|7rC$u~Ksg7LSMS(Q~ z51!n1htcK0q7*K-*u0?c8ZlvPXcNwXmFe0Or2}}R@?j@{ECCNZ6va1tZ>|ZOgGZ1j z9?mRkeSK%{X4O>J$@hyFsD)7s67Uldb>O93wQQiV%-FfbEY_@q>1VUstIJs|QgB`o1z**F#s z^joAYN~5{EQ_wZ~R6-nEV#HsQbNU59dT;G zovb$}pb=LdR^{W2Nh~8yWfq*vC_DvJxM=)2N`5x+N6Sl`3{Wl@$*BYol#0^idTuM` zJ=prt$REkxn6%dimg%99{(Dt6D67sTUR6l1F@9&Z9<)XgWK#x zVohUH6>_xRuw1^V**+BCZ@dZj97T*67OBO>6UUivH`<@ray~ym^E?bO=vKqFfK3Kv z`RKxs4raHacB<(XAeH`@0G*K2@ill_U@m=icT@F{k1PU3j4VBde`ThtW8%Z~A>)45ARjQCDXbH}_rS^IxHGp#utBEj3W3KSAU+$6I4s~9OWueETo!J-f~+DV8< z+VMtdcQ?M+?S}kl&uImYiIUJ-K0-te7W4sdWpS6Fqs-I!Tj{8Qp6lMn$Zm8uU)s{X z8|O}HN%8sEl4em&qv{VBq{}$@cCG{B z5~3DY$WRYSkO~z=sxRct5^G5bPZW;LF)(zY)HREgpRrkYV@H3^BTD6u+bJE~$cqr< zw@Gb3^|n*kHZ%Vnu6~B7pB4iM0C4kDuk8Q1R^<(x%>|sCOl%CTe^N)K?Tiepg?|#m z94!og0*38u|67h%*!)SJhUdvFimsktaqp#im9IpH-$fQc79gi259qPkEZ)XU?2uWW zRg?$8`vl;V%-Tk+rwpTGaxy)h%3AmF^78<#i+Q6~M4#>J4`NNEEzy~xZ&O*9q%}@7 zs9XBO#vSKSM<-OjPIDzO9JiAYFWrK14Am{uZT=S3zaCu~K%kZo&u*=k9L#xi6vyaG zQFD76MOE&=c1G;7Zivp<%%fRq+@3wgZg>k@AYQf|*Qyzy$tqc20m?F5nGbG@V#gW` z8RMb2oBxgiqa?)_G6&-;L#(HCoaJrs_ED{IUZ^$~)+e#0iZT!AJDb2V{Sen*70TO& zyI`*~#ZdLFhYP_#DTuoqQ0OS6j0o15r{}O&YoT5wCp|x_dD{#Y;Y}0P1ta?2VEh4* ztrRN5tL6UvoH@M9L z=%FKpf@iSp2P>C(*o<-Ng4qF#A?i!AxjXLG8%Gm`$rZxw;ZqSvv5@@sZ|N*~do5fb zKWR)T_>`kxaS|MHFh`-`fc`C%=i@EFk$O&)*_OVrgP4MWsZkE2RJB(WC>w}him zb3KV>1I&nHP9};o8Kw-K$wF8`(R?UMzNB22kSIn#dEe|V-CuMw8I7|#`qSB6dpYg$ zoaDHj%zV6*;`u`VVdsTBKv&g75Q`68rdQU6O>_wkMT9d!z@)q2E)R3(j$*C4jp$Fo z2pE>*ih{4Xzh}W+5!Qw)#M*^E(0X-6-!%wj@4*^)8F=N*0Y5Or+>d= zhMNs@R~>R9;KmyP@I@bpU3&w?)jj0rGrb@q)P>wLVbz1!TZY$#+H-mK6B^0{vdvt0 zaJ0~7p%I#1PpPm1DvBzh7*UsCl^I5^`@XzPzbg+v3T_WyKN?TJ9J=57v^IUO`aQN} z@>Y>WIj+gT@-sobU-tW%L5GP(qY?Eep&I;@osY}O*3i1Ar?Sv|EI6S-pK_!~*A$K| zs-hHESqd`vv;zIzgv2ho5-hsIL5Ke~siJ(v0`Qm7W_Rms2rB67=p&HGRhA-)$p-BS zvXSmgGIGgeJMBcsgp=L8U3Ep$VPBFhvJ!3M5{pocGBS~iZj0({9Jt9nbC{Z$LVb%= zGqzRBjlqkAU{#sOX56})^QjX;jQ26M`poAFIZ#H31td9sQlgBBrfIYgDC9+kO~}s{ zb1i*{#{5tPWhv4pecAZygXG>?5xKx7iPXd?nR;QaIfhlhqNBaLDy>9Yd1Sf3P!s4~ zhfHaFGsIFy&ZM=6^qc>>V>o!zk%5Lk5BtS7oU=YfjWUN;c zrh$6Cyr%KC@QNTzTZvb)QXQkV)01MEY+EzC%CJx)Q&6MM={paB}Dp=qCn^eJ}5LeXG9Gqynt0ir>DvSIZ=i?*_xR3=% zppf1w51ypF2KL6ug zCm}eCi>&>xT;Idzh^PmtDWrU(&eC2hAt(nmd#?;W)*&4lb2Z2Ykv*XLNDEm`_1n3C z`l!wZwiF9b?mN@z?s~>v%hT01C{E3md6M5_Xi3fKD6s26Tt~Z>8|~Ao9ds!cF_Y1| zRG>!=TD0k0`|T*)oX!SlSt8g4Uh@nc(QosCoen@i*ZCSyh|IliliuhEw$8?4ZL9N2 zMQ%%S=3Tj_QilhHW@cSr1UYTtDem{A-ZxyCa$K9A%(!`X_?ieJzXbfERST|JxqmbL zHe!hSqYk|!=!$8CJ5>q}Pj63@Q#PO{gpVb+0-qHFM`j5x_s#~dxvy5u62vywq8upP z_)N)3n9cn7YEf2D8L}x0#_B_~>HT8;;8JC5q+}1gEyd%XqYvY?deQzwD1Lx{ghI3; zv?f;&6CY$H&dDL$k#)hb)5lIqUZ~oU!z)hMI!B9THhw?9!}ykqpFJ|hB?JjV9uwqb z3_70pMV^C7I<3Cg&yMi8JJ3V2gYTOMV=IopfZ#1o>&+j-mB-V${Ok(f?I3{+vR~zE_RR$?9xI~^% z53~ z&bCl+6UeKkUWJ-%mnK{9K>?(3BM3C`@xi}v8)q#;YJhMr5dWvMtAL7X``!bHv~(%m zH8d#Q4N6G~lEW}aGn9ZZNT?v9bV$emf)dg#ASDV?(nu+wpu!_X;(vL<<1zBo-~X&N z>keyizVGaP&c65DbIyEwFn2%(L`P424ZI3nFBA%w{yJ?E} zlwSKF;jIhs(!TFOdMUW|(=qHjr#U-k>`>1u1_yL5Gyy;7@WTOt_)nfIp{D9kwR8f0 z;^Fq=iF(&yd|z30&+I`FBM-P6ouHQ@96TkIe@9=pDDL#_zgXos)-ri5lX-&2D~DsI z4R>xVM$c&aFLgFjwq{1I;jpODOx|n*#@e2+Wgdkm(E(Fad_)peD`1^CJ2TpglmgoC)F(Z)F7y2rzzDU^4wvO{bzw{mzSs4tF;*qabKkC?D!j!tbF z4D_6zbqFVI>n@2-Qmg1BiDdD}>E(72)aMv1Y9duOxwlG|E!L(QmQ#j5vmN@a7v{zIt3qQSP?96^$ITE=h~sLn|N|v8YqmA~-0HWgcPHZ@!3Dzm2X{Bozc{qm>J`Ehp}`FQ%Ecbw%+|H8f`pykvo-%&0a z?&ZtJF*{#AYs8Z|z(IFI8sBiZs)L!C9#1W@;hEInZZZdPz2ZnmhoSP9VHQt7mzZUZ zhM!!5IJbe4Z@zEoMjKaxH&Px8p}1<0YmtWwcG@ZPY@*oQSteU zRy+W=Rs>sJ##v^8EJJt0=5---o<@^?fOEp=N<~xXvcf?$gXD0zVHziRMMmC#Mp3o ze(eT!dvjmXp9_C%pV_>{H=nsqYO)n1J?Ihi zjy7f00`|S<;)I!ZyUO{~#+wXX)z(BWsN|$7n9s}H%ZzE8YQv#vRTHjq@D%tYyfe=3)|7jYxRT#E16nFk&1jFC6CH5d4kiJCVq+%r_$Rec7=G!GuZ-0*$5N2GqXB(dqWPS1Um4{xgi2k=;eO_LDy&GR=Q!)bjKY{f!0yoc0Rol&!E`2BkI$5y4U^*k0=GyL-m8XJL%8prM%;fwyX9M^ zs48n3Oh#a>FVWI7dsm~*l0$^J)lxnfTTw~1ceZ73yNvNurwd`;+^1XuucaFN85M8? z$fNl!D9g*O>6IE^POaoDq`86Sw0t4%jIi`&*EEZI?wwOiEvH8(qpfyDvAe`4pWf7k z3-pFgeT{qtj)B!1ZamZ5g3z6Nd40P(%^Kf@#!uzbIk~8w`9wbhWc~1E|sw6-FsOqrhb2DLDwlaq@)Y zAi$KoA=Vyn=Yxqxtf7wu*$47Ht>WZi{AdeN79#9ws~CtE;~gC$q7T>*5yKK3VT)Q=sllRR}lBIGd17+bOu| zeUeUrMgF=Gjk-{epAyUd_KNgwZK_Pz=H$+{4~E_ZRa3IJpU~IZ5U4Z3l%u3{Ls~`H z(iysmm+!HBJTC-$EpHM9yrXUM^_FZ(3sdmsyZ6=lU8bb3V(WK>P0$l~#QA&NMj@OA z*OQ>^-s_D-bda022~!G!bTh7@FR>t!1r`Js1;4$(^_*hH-_pUPf5C}K-v$%i#KBB! zU{~a7)R>ix z#LA|<6v#rwKkB1JBLWkWu#M0#8i1J0e4dFDP3jrlFfxhkDs%Q~)e6e7fR$U?e$<{x zfZb0?UMsB|E}Fk)@|^{)_^L7O%rp1GRNig@bUX(^6}6HoGi8IXoSKpI1A(GV)uA=7 zOXG&KjZYVjYn6}2YV0yfnKsnpDlF)h$Gv--|6$BsWFg|IWnp|#sk}zOAb6Bb?vb@t zs^7=4IdiKE_rUT@rG!D4Zy zcnas#XT77V&%igMXY(lQS|)lgO{pN9!P-94KeZH_+PK5jESYCSPMN)=D(JIAVeB%D zI_>_lvD;pylkZ#Ral0IzC6ei$J$4NnGw(pnVd`&aaNT5mfq-4)aPjj(v;`VvJ6Xxjm@3DX+Kju z@9-h++s7x>idTEL zd)ptYy?P2$S*_DI;eMR0ZdAuS)~fGEZEguO&+3AwW@Sw$&KvgJr6aGK*Ar;0wx`lr z7V&!+9C7`VcV^t+Wj~AweOGQL!)0)serr$8Fez7kC(VSVRdjqpQuq964RW^2euIre zh10&Tv)|dj*CoRozrW<4y_+5}3EGRok+G7ODl3-CF1r?JYDdw&NbcVT=7ljq_K+8bMeG3uRw@3=cof?j+v+WaKI`WqwByf#7aFK3 z0+R34xQ-6nxQ&9xJKl}`C9FlUe1-h^i?5fr5kjot#MA-$%k106t>*gM+yF3m2X#=1tt07`cK)37dA^A4d8%6R>@0U-UZ~wSvzMlK$tlm~aK`%e8|quXyH`aLM0#Dcu%sqEsKV%i zVn_*W-Qbnl)h?RP>)$rZ5JL!*H;Z{ zk7(FB`lo~h&zB|S6j-Na;y$QM*rn^tkO{>#DWZN@IwJps3*Nm&ox0{{;=J~hvPb-* zvAOEPImrdq()yl~`j`Q;R1Y%CdLKKw*;gtNaM~WDO95YXsTjKCOdRD2Is@aVRTYFD zpS=_EB!@Ub&c*JmNMF=F+)Bq)52|=83IEG;M5(Ol*97!W(S-5X-5w&7->`1Pw-0Ml zpA>jaofnyPQTCzoIG}OK9j^nn>F>jC#$iSnJY8y6ue4nxs@3HtfNx01XVK7NcX#Cu z34g-z=0!7ip&@wI>>6ynJYyFTEgH6DA?b>~V%2s_@NPDza5&6cno!S(|85*74}6_M z%s1c4`B{lqMu``(4~Jk#_`^=tu36TgXPv_}{lhhyi(rrSM_uoVVNuZOuxCXom9|wg zNf&BtzX=hVi*4dG&1J!^QW;O%fQ$jVH=W74B8WR)*tM1{(@cHRqiS_W6R^h8uxd@zV>KNI zR(-LNNkLqh>e=CmL|q9sRHm#15%q$o7_GQMp8FLX-HGnJ<+(;k{Q%+Sk+!^mM+2#1y9+gG2IDZGt%;Cfk{+ zT5}^x=!i2$tnH_se6eC zkn;kK>%ICpo=X&=cSsbxQ|AjJ;5Ff;AyIj>$YA8cw*?W^Nn}S|1jrbf@Bd zr82I8KlOh4#5C0sw3oVvuC0NFPKH4S0$~F$U4JM1Im$B%%oGm_5$Lnr{#Pv}eL1k& zMP(pG$MI^8&!nYffq#$zJ^3GF|cC%2d4V@qKV#fu6u2O

k)oKu82Fu=RODzQrHPEC+Mz{hW(G7VuCl8g1ou-Ot!41bp_>OC1&@A_6e*hc)1X zMuDvzEZyB*fW1^+7dL0%ofr;-xT6B@0~|VazatI{60!X=po^uOr6UB$1POKmuI_&b zOL&O+w*!>`k+y%?Z|wm4$@_1|WC|pKM(F{k8TR$-4hs?i|GBc9)qa{vYq)~5qa(2N zsR?s}0Pp^ufVGEB8oE9VCFa0K$x0HSpem!tIyR69y0rnjg8cqjmWyz7*Kx3~X> z|BZX}Y;oVB1HX@l9_-y7dI*WgruY@?rC&64`}3W`ECA>O@Y#Q@JS<4WBF(QbwJqHM zt)fE#6jTSyZ^E8y0INaIf!omWjvS=@15`O%V2CKg+}z=M9##kLKRN0uJuK250bXVU zwzT&n@30^dzKnlL^us;wClg?CKWEtiEb#zhPVx{PxFQiwEPp^C53zN21EdZAz?3D& zC6fK|_!S5Mq&0z;xWGLEv}!zjfpRg_orp7|fXMx=uP!@X`yT@5(N_Hza}p5fBk&|)J7fZ`NQ9Nz@5xT? zi?iV$q+bG!2LZUpF)>Yl!u;DEHV3!i{ipcJm_8Gj@Dac%N3|SQVGqRhrJ;WOR|CtrwzPTW^&$A6!A$E)h7xohm>hA8p{PUZ~ z_&zeg@OL3PxPtzkfsNZAqXCZ8Is7yQ+plm~8;}|~DEkv&f@?q5hB*OGQYXuwVQOp0 z?QQ`6qyp|-$47wjuV74IE_x2I17$+grwMBE^25d<5!lYhnszuh|5Yk;RB+Uk*hk=m zu73=E^7ul{40{A^?Rg^fq0ZfZO@C1HupR*_d;J>lkFv6&x&}4N;t}1T@2}~AC^<3b zA}RxFPPZe5R{_6dIN9N-GT29Oa}RzA2ekKuEVZbuMOB?Xf**`N5&m}?)TjigdY(rF z?~+a=`0);TlDa1j)1G`AfW? zRl883QPq=w zbB|bHEx%_u*$t@Yl#Vc;y*?2W^|^NJ)DmioQFr~1&>MSBL_b(YIpGWdDm3bT=Mgm1 e+h0K+-~H6qzyuy}`;+tYAZFmzUSVSYum1yJqxCBQ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 309b4e18d..a80b22ce5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle index b8b50083c..f53b0b4cb 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,17 +6,10 @@ pluginManagement { name = 'NeoForged' url = 'https://maven.neoforged.net/releases' - content { - includeGroup("net.minecraftforge") - includeGroup("net.neoforged.gradle") - includeGroup("net.neoforged") - includeGroup("org.spongepowered.mixin") - includeGroup("org.spongepowered") - } } } } plugins { - id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0' + id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0' } \ No newline at end of file diff --git a/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java b/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java index 9a20520f8..cb9699333 100644 --- a/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java +++ b/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java @@ -8,7 +8,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.registries.RegistryObject; +import net.neoforged.registries.RegistryObject; import java.util.Collection; import java.util.Set; diff --git a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java index dea0499e0..c5834083c 100644 --- a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java +++ b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java @@ -6,12 +6,12 @@ import de.srendi.advancedperipherals.network.APNetworking; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.fml.ModLoadingContext; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import net.neoforged.common.MinecraftForge; +import net.neoforged.eventbus.api.IEventBus; +import net.neoforged.fml.ModLoadingContext; +import net.neoforged.fml.common.Mod; +import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; +import net.neoforged.fml.javafmlmod.FMLJavaModLoadingContext; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java b/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java index 160836009..fcdef9dfc 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java +++ b/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java @@ -9,12 +9,12 @@ import net.minecraft.client.gui.screens.MenuScreens; import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.client.event.ModelEvent; -import net.minecraftforge.client.event.RegisterKeyMappingsEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.client.event.ModelEvent; +import net.neoforged.client.event.RegisterKeyMappingsEvent; +import net.neoforged.eventbus.api.SubscribeEvent; +import net.neoforged.fml.common.Mod; +import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; @Mod.EventBusSubscriber(modid = AdvancedPeripherals.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD) public class ClientRegistry { diff --git a/src/main/java/de/srendi/advancedperipherals/client/KeyBindings.java b/src/main/java/de/srendi/advancedperipherals/client/KeyBindings.java index 2cbd46438..2b7e02b9f 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/KeyBindings.java +++ b/src/main/java/de/srendi/advancedperipherals/client/KeyBindings.java @@ -1,7 +1,7 @@ package de.srendi.advancedperipherals.client; import net.minecraft.client.KeyMapping; -import net.minecraftforge.client.event.RegisterKeyMappingsEvent; +import net.neoforged.client.event.RegisterKeyMappingsEvent; import org.lwjgl.glfw.GLFW; public class KeyBindings { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java b/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java index 9b658b344..65f78f4c0 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java @@ -2,10 +2,10 @@ import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.addons.refinedstorage.RefinedStorage; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.ModList; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent; +import net.neoforged.eventbus.api.SubscribeEvent; +import net.neoforged.fml.ModList; +import net.neoforged.fml.common.Mod; +import net.neoforged.fml.event.lifecycle.InterModEnqueueEvent; @Mod.EventBusSubscriber(modid = AdvancedPeripherals.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) public class APAddons { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java index 9f74a0711..ca90859a9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java @@ -30,12 +30,12 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.IFluidHandler; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.common.capabilities.ForgeCapabilities; +import net.neoforged.common.util.LazyOptional; +import net.neoforged.fluids.FluidStack; +import net.neoforged.fluids.capability.IFluidHandler; +import net.neoforged.items.IItemHandler; +import net.neoforged.registries.ForgeRegistries; import org.apache.logging.log4j.Level; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeFluidHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeFluidHandler.java index 8072a777d..4f8c4be33 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeFluidHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeFluidHandler.java @@ -7,7 +7,7 @@ import de.srendi.advancedperipherals.common.util.Pair; import de.srendi.advancedperipherals.common.util.inventory.FluidFilter; import de.srendi.advancedperipherals.common.util.inventory.IStorageSystemFluidHandler; -import net.minecraftforge.fluids.FluidStack; +import net.neoforged.fluids.FluidStack; import org.jetbrains.annotations.NotNull; /** diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/IntegrationPeripheralProvider.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/IntegrationPeripheralProvider.java index a5d8af260..29347b459 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/IntegrationPeripheralProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/IntegrationPeripheralProvider.java @@ -12,7 +12,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.NoteBlock; import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraftforge.common.util.LazyOptional; +import net.neoforged.common.util.LazyOptional; import org.jetbrains.annotations.NotNull; import java.util.Comparator; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/NoteBlockIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/NoteBlockIntegration.java index b0b5c83c7..9ed10d309 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/NoteBlockIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/NoteBlockIntegration.java @@ -24,7 +24,7 @@ public String getType() { @LuaFunction(mainThread = true) public final int changeNote() { BlockState state = world.getBlockState(pos); - int newNote = net.minecraftforge.common.ForgeHooks.onNoteChange(world, pos, state, state.getValue(NoteBlock.NOTE), state.cycle(NoteBlock.NOTE).getValue(NoteBlock.NOTE)); + int newNote = net.neoforged.common.ForgeHooks.onNoteChange(world, pos, state, state.getValue(NoteBlock.NOTE), state.cycle(NoteBlock.NOTE).getValue(NoteBlock.NOTE)); if (newNote == -1) return -1; state = state.setValue(NoteBlock.NOTE, newNote); world.setBlock(pos, state, 3); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/AutomataCoreTier.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/AutomataCoreTier.java index 2166839f8..877b34ae3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/AutomataCoreTier.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/AutomataCoreTier.java @@ -1,7 +1,7 @@ package de.srendi.advancedperipherals.common.addons.computercraft.operations; import de.srendi.advancedperipherals.lib.metaphysics.IAutomataCoreTier; -import net.minecraftforge.common.ForgeConfigSpec; +import net.neoforged.common.ForgeConfigSpec; public enum AutomataCoreTier implements IAutomataCoreTier { TIER1(2, 2), diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SimpleFreeOperation.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SimpleFreeOperation.java index b86b1aa39..c1f31e44c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SimpleFreeOperation.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SimpleFreeOperation.java @@ -1,7 +1,7 @@ package de.srendi.advancedperipherals.common.addons.computercraft.operations; import de.srendi.advancedperipherals.lib.peripherals.IPeripheralOperation; -import net.minecraftforge.common.ForgeConfigSpec; +import net.neoforged.common.ForgeConfigSpec; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SingleOperation.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SingleOperation.java index 08ebd3c6b..f23fdc1f3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SingleOperation.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SingleOperation.java @@ -1,7 +1,7 @@ package de.srendi.advancedperipherals.common.addons.computercraft.operations; import de.srendi.advancedperipherals.lib.peripherals.IPeripheralOperation; -import net.minecraftforge.common.ForgeConfigSpec; +import net.neoforged.common.ForgeConfigSpec; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SphereOperation.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SphereOperation.java index 147b06400..c3ff93a77 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SphereOperation.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SphereOperation.java @@ -2,7 +2,7 @@ import com.google.common.math.IntMath; import de.srendi.advancedperipherals.lib.peripherals.IPeripheralOperation; -import net.minecraftforge.common.ForgeConfigSpec; +import net.neoforged.common.ForgeConfigSpec; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/TileEntityFuelAbility.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/TileEntityFuelAbility.java index d6f279fb1..f09c01a1f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/TileEntityFuelAbility.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/TileEntityFuelAbility.java @@ -3,7 +3,7 @@ import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.lib.peripherals.IPeripheralTileEntity; import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraftforge.common.capabilities.ForgeCapabilities; +import net.neoforged.common.capabilities.ForgeCapabilities; import org.jetbrains.annotations.NotNull; public class TileEntityFuelAbility extends FuelAbility> { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/BlockReaderPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/BlockReaderPeripheral.java index 086fa4fe9..e71e67893 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/BlockReaderPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/BlockReaderPeripheral.java @@ -11,7 +11,7 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.Property; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.registries.ForgeRegistries; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java index 4c323d31c..d7c1d183a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java @@ -27,7 +27,7 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.level.Level; -import net.minecraftforge.server.ServerLifecycleHooks; +import net.neoforged.server.ServerLifecycleHooks; import org.jetbrains.annotations.NotNull; import java.util.Optional; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ColonyPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ColonyPeripheral.java index d1e29a9c2..75807cc71 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ColonyPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ColonyPeripheral.java @@ -30,7 +30,7 @@ import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.fml.ModList; +import net.neoforged.fml.ModList; import java.util.*; import java.util.stream.Collectors; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/EnvironmentDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/EnvironmentDetectorPeripheral.java index ef0b1817e..c853aa2d5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/EnvironmentDetectorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/EnvironmentDetectorPeripheral.java @@ -32,10 +32,10 @@ import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.levelgen.WorldgenRandom; import net.minecraft.world.phys.AABB; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.entity.player.SleepingTimeCheckEvent; -import net.minecraftforge.eventbus.api.Event; -import net.minecraftforge.server.ServerLifecycleHooks; +import net.neoforged.common.MinecraftForge; +import net.neoforged.event.entity.player.SleepingTimeCheckEvent; +import net.neoforged.eventbus.api.Event; +import net.neoforged.server.ServerLifecycleHooks; import org.jetbrains.annotations.NotNull; import java.util.*; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/GeoScannerPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/GeoScannerPeripheral.java index 438815585..510293e28 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/GeoScannerPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/GeoScannerPeripheral.java @@ -24,8 +24,8 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.LevelChunk; -import net.minecraftforge.common.Tags; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.common.Tags; +import net.neoforged.registries.ForgeRegistries; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java index 73e9213a6..7d760f676 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java @@ -18,11 +18,11 @@ import net.minecraft.world.item.ArmorItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.items.wrapper.PlayerArmorInvWrapper; -import net.minecraftforge.items.wrapper.PlayerInvWrapper; -import net.minecraftforge.items.wrapper.PlayerOffhandInvWrapper; +import net.neoforged.common.capabilities.ForgeCapabilities; +import net.neoforged.items.IItemHandler; +import net.neoforged.items.wrapper.PlayerArmorInvWrapper; +import net.neoforged.items.wrapper.PlayerInvWrapper; +import net.neoforged.items.wrapper.PlayerOffhandInvWrapper; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java index 731e451f4..dbfba5894 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java @@ -26,8 +26,8 @@ import de.srendi.advancedperipherals.common.util.inventory.InventoryUtil; import de.srendi.advancedperipherals.common.util.inventory.ItemFilter; import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; -import net.minecraftforge.fluids.capability.IFluidHandler; -import net.minecraftforge.items.IItemHandler; +import net.neoforged.fluids.capability.IFluidHandler; +import net.neoforged.items.IItemHandler; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/PlayerDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/PlayerDetectorPeripheral.java index 12d7dd184..8df785719 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/PlayerDetectorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/PlayerDetectorPeripheral.java @@ -21,7 +21,7 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; -import net.minecraftforge.server.ServerLifecycleHooks; +import net.neoforged.server.ServerLifecycleHooks; import java.util.*; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java index e298a59f3..897c4cf0b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java @@ -21,9 +21,9 @@ import de.srendi.advancedperipherals.common.util.inventory.*; import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.IFluidHandler; -import net.minecraftforge.items.IItemHandler; +import net.neoforged.fluids.FluidStack; +import net.neoforged.fluids.capability.IFluidHandler; +import net.neoforged.items.IItemHandler; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataChargingPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataChargingPlugin.java index 2ffdb4d43..4c4ffde45 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataChargingPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataChargingPlugin.java @@ -10,7 +10,7 @@ import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.lib.peripherals.AutomataCorePeripheral; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.common.capabilities.ForgeCapabilities; +import net.neoforged.common.capabilities.ForgeCapabilities; import org.jetbrains.annotations.NotNull; import java.util.Objects; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataItemSuckPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataItemSuckPlugin.java index bcc87f781..0c6d7a39c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataItemSuckPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataItemSuckPlugin.java @@ -14,7 +14,7 @@ import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.item.ItemStack; import net.minecraft.world.phys.AABB; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.registries.ForgeRegistries; import org.jetbrains.annotations.NotNull; import java.util.HashMap; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataLookPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataLookPlugin.java index c79019c53..22e30ba3d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataLookPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataLookPlugin.java @@ -10,7 +10,7 @@ import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.HitResult; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.registries.ForgeRegistries; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/create/BasinIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/create/BasinIntegration.java index cbb4dc46a..6c94a078b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/create/BasinIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/create/BasinIntegration.java @@ -4,11 +4,11 @@ import dan200.computercraft.api.lua.LuaFunction; import de.srendi.advancedperipherals.common.util.LuaConverter; import de.srendi.advancedperipherals.lib.peripherals.APGenericPeripheral; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.IFluidHandler; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.common.capabilities.ForgeCapabilities; +import net.neoforged.fluids.FluidStack; +import net.neoforged.fluids.capability.IFluidHandler; +import net.neoforged.items.IItemHandler; +import net.neoforged.registries.ForgeRegistries; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/create/FluidTankIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/create/FluidTankIntegration.java index 121283e5b..8c0599893 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/create/FluidTankIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/create/FluidTankIntegration.java @@ -3,7 +3,7 @@ import com.simibubi.create.content.fluids.tank.FluidTankBlockEntity; import dan200.computercraft.api.lua.LuaFunction; import de.srendi.advancedperipherals.lib.peripherals.APGenericPeripheral; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.registries.ForgeRegistries; import org.jetbrains.annotations.NotNull; import java.util.HashMap; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/minecolonies/MineColonies.java b/src/main/java/de/srendi/advancedperipherals/common/addons/minecolonies/MineColonies.java index b6dd3c2a1..bd1131707 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/minecolonies/MineColonies.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/minecolonies/MineColonies.java @@ -29,10 +29,10 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.server.command.TextComponentHelper; +import net.neoforged.common.capabilities.ForgeCapabilities; +import net.neoforged.common.util.LazyOptional; +import net.neoforged.items.IItemHandler; +import net.neoforged.server.command.TextComponentHelper; import java.util.ArrayList; import java.util.HashMap; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java index f32ea395b..5c7d4e6f8 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java @@ -25,8 +25,8 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.material.Fluid; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.fluids.FluidStack; +import net.neoforged.registries.ForgeRegistries; import org.jetbrains.annotations.Nullable; import java.util.*; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsFluidHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsFluidHandler.java index f945fb8b6..2a6d0029b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsFluidHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsFluidHandler.java @@ -5,7 +5,7 @@ import com.refinedmods.refinedstorage.api.util.IComparer; import de.srendi.advancedperipherals.common.util.inventory.FluidFilter; import de.srendi.advancedperipherals.common.util.inventory.IStorageSystemFluidHandler; -import net.minecraftforge.fluids.FluidStack; +import net.neoforged.fluids.FluidStack; import org.jetbrains.annotations.NotNull; public class RsFluidHandler implements IStorageSystemFluidHandler { diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/APBlockEntityBlock.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/APBlockEntityBlock.java index 8288b7ece..970ac65b8 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/APBlockEntityBlock.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/APBlockEntityBlock.java @@ -8,7 +8,7 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.registries.RegistryObject; +import net.neoforged.registries.RegistryObject; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlock.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlock.java index ed53d8151..23f881958 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlock.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlock.java @@ -10,7 +10,7 @@ import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.EnumProperty; -import net.minecraftforge.common.Tags; +import net.neoforged.common.Tags; import org.jetbrains.annotations.NotNull; public class BaseBlock extends Block implements IHarvestableBlock { diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlockEntityBlock.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlockEntityBlock.java index 4ca37d78f..bad9dde55 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlockEntityBlock.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlockEntityBlock.java @@ -18,7 +18,7 @@ import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; -import net.minecraftforge.network.NetworkHooks; +import net.neoforged.network.NetworkHooks; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PeripheralBlockEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PeripheralBlockEntity.java index 2b6d3ca8f..b87c8d838 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PeripheralBlockEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PeripheralBlockEntity.java @@ -21,13 +21,13 @@ import net.minecraft.world.level.block.entity.BaseContainerBlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.fluids.capability.IFluidHandler; -import net.minecraftforge.fluids.capability.templates.FluidTank; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.items.wrapper.SidedInvWrapper; +import net.neoforged.common.capabilities.Capability; +import net.neoforged.common.capabilities.ForgeCapabilities; +import net.neoforged.common.util.LazyOptional; +import net.neoforged.fluids.capability.IFluidHandler; +import net.neoforged.fluids.capability.templates.FluidTank; +import net.neoforged.items.IItemHandler; +import net.neoforged.items.wrapper.SidedInvWrapper; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PoweredPeripheralBlockEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PoweredPeripheralBlockEntity.java index bace719d3..a9ad907bc 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PoweredPeripheralBlockEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PoweredPeripheralBlockEntity.java @@ -7,11 +7,11 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.EnergyStorage; -import net.minecraftforge.energy.IEnergyStorage; +import net.neoforged.common.capabilities.Capability; +import net.neoforged.common.capabilities.ForgeCapabilities; +import net.neoforged.common.util.LazyOptional; +import net.neoforged.energy.EnergyStorage; +import net.neoforged.energy.IEnergyStorage; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnergyDetectorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnergyDetectorEntity.java index f8db556aa..4cdec5ab3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnergyDetectorEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnergyDetectorEntity.java @@ -13,11 +13,11 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.EnergyStorage; -import net.minecraftforge.energy.IEnergyStorage; +import net.neoforged.common.capabilities.Capability; +import net.neoforged.common.capabilities.ForgeCapabilities; +import net.neoforged.common.util.LazyOptional; +import net.neoforged.energy.EnergyStorage; +import net.neoforged.energy.IEnergyStorage; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java index fad6ce3d7..83781f7ce 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java @@ -14,7 +14,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.server.ServerLifecycleHooks; +import net.neoforged.server.ServerLifecycleHooks; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java index e3bc4a364..06f076f2e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java @@ -15,8 +15,8 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.util.LazyOptional; +import net.neoforged.common.capabilities.Capability; +import net.neoforged.common.util.LazyOptional; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java b/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java index 3acb4414c..e18a4ce85 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java +++ b/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java @@ -11,9 +11,10 @@ import net.minecraft.network.chat.ComponentUtils; import net.minecraft.network.chat.HoverEvent; import net.minecraft.server.level.ServerPlayer; -import net.minecraftforge.event.RegisterCommandsEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.Mod; +import net.neoforged.neoforge.event.RegisterCommandsEvent; + @Mod.EventBusSubscriber(modid = AdvancedPeripherals.MOD_ID) public class APCommands { diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/APConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/APConfig.java index 8695dd01a..bff1378a9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/APConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/APConfig.java @@ -1,11 +1,11 @@ package de.srendi.advancedperipherals.common.configuration; import com.electronwill.nightconfig.core.file.CommentedFileConfig; -import net.minecraftforge.fml.ModContainer; -import net.minecraftforge.fml.ModLoadingContext; -import net.minecraftforge.fml.config.ConfigFileTypeHandler; -import net.minecraftforge.fml.config.ModConfig; -import net.minecraftforge.fml.loading.FMLPaths; +import net.neoforged.fml.ModContainer; +import net.neoforged.fml.ModLoadingContext; +import net.neoforged.fml.config.ConfigFileTypeHandler; +import net.neoforged.fml.config.ModConfig; +import net.neoforged.fml.loading.FMLPaths; import java.nio.file.Path; import java.util.function.Function; diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/GeneralConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/GeneralConfig.java index 57c32e43d..8918cbf36 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/GeneralConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/GeneralConfig.java @@ -2,8 +2,7 @@ import de.srendi.advancedperipherals.lib.LibConfig; import net.minecraft.FieldsAreNonnullByDefault; -import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.fml.config.ModConfig; +import net.neoforged.fml.config.ModConfig; @FieldsAreNonnullByDefault public class GeneralConfig implements IAPConfig { diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/IAPConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/IAPConfig.java index 05cb51657..65fcd4879 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/IAPConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/IAPConfig.java @@ -1,8 +1,8 @@ package de.srendi.advancedperipherals.common.configuration; import de.srendi.advancedperipherals.lib.misc.IConfigHandler; -import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.fml.config.ModConfig; +import net.neoforged.common.ForgeConfigSpec; +import net.neoforged.fml.config.ModConfig; public interface IAPConfig { diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/MetaphysicsConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/MetaphysicsConfig.java index e45fdcbde..7d537b279 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/MetaphysicsConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/MetaphysicsConfig.java @@ -2,8 +2,8 @@ import de.srendi.advancedperipherals.common.addons.computercraft.operations.AutomataCoreTier; import net.minecraft.FieldsAreNonnullByDefault; -import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.fml.config.ModConfig; +import net.neoforged.common.ForgeConfigSpec; +import net.neoforged.fml.config.ModConfig; @FieldsAreNonnullByDefault public class MetaphysicsConfig implements IAPConfig { diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java index e9c7d0d33..256ea5d28 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java @@ -4,8 +4,8 @@ import de.srendi.advancedperipherals.common.addons.computercraft.operations.SingleOperation; import de.srendi.advancedperipherals.common.addons.computercraft.operations.SphereOperation; import net.minecraft.FieldsAreNonnullByDefault; -import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.fml.config.ModConfig; +import net.neoforged.common.ForgeConfigSpec; +import net.neoforged.fml.config.ModConfig; @FieldsAreNonnullByDefault public class PeripheralsConfig implements IAPConfig { diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/WorldConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/WorldConfig.java index de050af71..6665cc41b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/WorldConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/WorldConfig.java @@ -1,8 +1,8 @@ package de.srendi.advancedperipherals.common.configuration; import net.minecraft.FieldsAreNonnullByDefault; -import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.fml.config.ModConfig; +import net.neoforged.common.ForgeConfigSpec; +import net.neoforged.fml.config.ModConfig; @FieldsAreNonnullByDefault public class WorldConfig implements IAPConfig { diff --git a/src/main/java/de/srendi/advancedperipherals/common/container/InventoryManagerContainer.java b/src/main/java/de/srendi/advancedperipherals/common/container/InventoryManagerContainer.java index 4ccc859cf..0f78b7ef1 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/container/InventoryManagerContainer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/container/InventoryManagerContainer.java @@ -11,7 +11,7 @@ import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; -import net.minecraftforge.common.capabilities.ForgeCapabilities; +import net.neoforged.common.capabilities.ForgeCapabilities; import org.jetbrains.annotations.NotNull; public class InventoryManagerContainer extends BaseContainer { diff --git a/src/main/java/de/srendi/advancedperipherals/common/container/base/BaseContainer.java b/src/main/java/de/srendi/advancedperipherals/common/container/base/BaseContainer.java index 9d11ca901..a1bf6e8f6 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/container/base/BaseContainer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/container/base/BaseContainer.java @@ -10,9 +10,9 @@ import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.items.SlotItemHandler; -import net.minecraftforge.items.wrapper.InvWrapper; +import net.neoforged.items.IItemHandler; +import net.neoforged.items.SlotItemHandler; +import net.neoforged.items.wrapper.InvWrapper; import org.jetbrains.annotations.Nullable; public abstract class BaseContainer extends AbstractContainerMenu { diff --git a/src/main/java/de/srendi/advancedperipherals/common/container/base/BaseItemContainer.java b/src/main/java/de/srendi/advancedperipherals/common/container/base/BaseItemContainer.java index dfc8ceab8..0f89076b4 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/container/base/BaseItemContainer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/container/base/BaseItemContainer.java @@ -4,9 +4,9 @@ import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.items.SlotItemHandler; -import net.minecraftforge.items.wrapper.InvWrapper; +import net.neoforged.items.IItemHandler; +import net.neoforged.items.SlotItemHandler; +import net.neoforged.items.wrapper.InvWrapper; import org.jetbrains.annotations.Nullable; public abstract class BaseItemContainer extends AbstractContainerMenu { diff --git a/src/main/java/de/srendi/advancedperipherals/common/container/base/SlotInputHandler.java b/src/main/java/de/srendi/advancedperipherals/common/container/base/SlotInputHandler.java index ea7e7320d..5ecafe63c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/container/base/SlotInputHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/container/base/SlotInputHandler.java @@ -1,8 +1,8 @@ package de.srendi.advancedperipherals.common.container.base; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.items.SlotItemHandler; +import net.neoforged.items.IItemHandler; +import net.neoforged.items.SlotItemHandler; import org.jetbrains.annotations.NotNull; public class SlotInputHandler extends SlotItemHandler { diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java b/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java index 2d825a312..4ddc97346 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java @@ -4,7 +4,7 @@ import net.minecraft.data.loot.BlockLootSubProvider; import net.minecraft.world.flag.FeatureFlags; import net.minecraft.world.level.block.Block; -import net.minecraftforge.registries.RegistryObject; +import net.neoforged.registries.RegistryObject; import org.jetbrains.annotations.NotNull; import java.util.Set; diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/BlockStatesAndModelsProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/BlockStatesAndModelsProvider.java index 0249ff5db..107095f1b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/BlockStatesAndModelsProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/BlockStatesAndModelsProvider.java @@ -8,9 +8,9 @@ import net.minecraft.data.PackOutput; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.Block; -import net.minecraftforge.client.model.generators.*; -import net.minecraftforge.common.data.ExistingFileHelper; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.client.model.generators.*; +import net.neoforged.common.data.ExistingFileHelper; +import net.neoforged.registries.ForgeRegistries; public class BlockStatesAndModelsProvider extends BlockStateProvider { diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/BlockTagsProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/BlockTagsProvider.java index c0f98257a..22b2fc711 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/BlockTagsProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/BlockTagsProvider.java @@ -7,10 +7,10 @@ import net.minecraft.data.tags.TagsProvider; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.Block; -import net.minecraftforge.common.data.ExistingFileHelper; -import net.minecraftforge.registries.DeferredRegister; -import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.RegistryObject; +import net.neoforged.common.data.ExistingFileHelper; +import net.neoforged.registries.DeferredRegister; +import net.neoforged.registries.ForgeRegistries; +import net.neoforged.registries.RegistryObject; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/DataGenerators.java b/src/main/java/de/srendi/advancedperipherals/common/data/DataGenerators.java index 36cfb5d11..d4fc67a20 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/DataGenerators.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/DataGenerators.java @@ -7,10 +7,10 @@ import net.minecraft.data.DataGenerator; import net.minecraft.data.PackOutput; import net.minecraft.data.registries.VanillaRegistries; -import net.minecraftforge.common.data.ExistingFileHelper; -import net.minecraftforge.data.event.GatherDataEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; +import net.neoforged.common.data.ExistingFileHelper; +import net.neoforged.data.event.GatherDataEvent; +import net.neoforged.eventbus.api.SubscribeEvent; +import net.neoforged.fml.common.Mod; import java.util.concurrent.CompletableFuture; diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java index 78a97d6d9..c3ca24842 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java @@ -12,8 +12,8 @@ import net.minecraft.world.entity.npc.VillagerProfession; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; -import net.minecraftforge.common.data.LanguageProvider; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.common.data.LanguageProvider; +import net.neoforged.registries.ForgeRegistries; import org.jetbrains.annotations.NotNull; import java.util.function.Supplier; diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/PoiTypeProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/PoiTypeProvider.java index b4aec08c4..f43170599 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/PoiTypeProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/PoiTypeProvider.java @@ -8,8 +8,8 @@ import net.minecraft.data.tags.TagsProvider; import net.minecraft.tags.PoiTypeTags; import net.minecraft.world.entity.ai.village.poi.PoiType; -import net.minecraftforge.common.data.ExistingFileHelper; -import net.minecraftforge.registries.RegistryObject; +import net.neoforged.common.data.ExistingFileHelper; +import net.neoforged.registries.RegistryObject; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java index 9166436e1..014a25fdf 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java @@ -17,10 +17,10 @@ import net.minecraft.world.item.alchemy.Potions; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.level.block.Block; -import net.minecraftforge.common.Tags; -import net.minecraftforge.common.crafting.ConditionalRecipe; -import net.minecraftforge.common.crafting.StrictNBTIngredient; -import net.minecraftforge.common.crafting.conditions.IConditionBuilder; +import net.neoforged.common.Tags; +import net.neoforged.common.crafting.ConditionalRecipe; +import net.neoforged.common.crafting.StrictNBTIngredient; +import net.neoforged.common.crafting.conditions.IConditionBuilder; import org.jetbrains.annotations.NotNull; import java.util.function.Consumer; diff --git a/src/main/java/de/srendi/advancedperipherals/common/events/Events.java b/src/main/java/de/srendi/advancedperipherals/common/events/Events.java index ee9e4b3ef..3cbc390a4 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/events/Events.java +++ b/src/main/java/de/srendi/advancedperipherals/common/events/Events.java @@ -12,13 +12,13 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.event.CommandEvent; -import net.minecraftforge.event.ServerChatEvent; -import net.minecraftforge.event.entity.player.PlayerEvent; -import net.minecraftforge.eventbus.api.EventPriority; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.event.CommandEvent; +import net.neoforged.event.ServerChatEvent; +import net.neoforged.event.entity.player.PlayerEvent; +import net.neoforged.eventbus.api.EventPriority; +import net.neoforged.eventbus.api.SubscribeEvent; +import net.neoforged.fml.common.Mod; +import net.neoforged.registries.ForgeRegistries; import java.util.function.Consumer; diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/WeakAutomataCore.java b/src/main/java/de/srendi/advancedperipherals/common/items/WeakAutomataCore.java index a6dd52389..d1eae4104 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/WeakAutomataCore.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/WeakAutomataCore.java @@ -16,8 +16,8 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.level.Level; -import net.minecraftforge.common.util.FakePlayer; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.common.util.FakePlayer; +import net.neoforged.registries.ForgeRegistries; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/base/BaseItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/base/BaseItem.java index f0facfa03..cceba80dc 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/base/BaseItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/base/BaseItem.java @@ -14,7 +14,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.level.Level; -import net.minecraftforge.network.NetworkHooks; +import net.neoforged.network.NetworkHooks; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/BlockEntityTypes.java b/src/main/java/de/srendi/advancedperipherals/common/setup/BlockEntityTypes.java index e9364067f..c0efd9ad4 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/BlockEntityTypes.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/BlockEntityTypes.java @@ -3,8 +3,8 @@ import com.google.common.collect.Sets; import de.srendi.advancedperipherals.common.blocks.blockentities.*; import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraftforge.fml.ModList; -import net.minecraftforge.registries.RegistryObject; +import net.neoforged.fml.ModList; +import net.neoforged.registries.RegistryObject; public class BlockEntityTypes { diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/Blocks.java b/src/main/java/de/srendi/advancedperipherals/common/setup/Blocks.java index eb6cf8681..609e32f95 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/Blocks.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/Blocks.java @@ -12,8 +12,8 @@ import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.fml.ModList; -import net.minecraftforge.registries.RegistryObject; +import net.neoforged.fml.ModList; +import net.neoforged.registries.RegistryObject; import java.util.function.Supplier; diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/CCRegistration.java b/src/main/java/de/srendi/advancedperipherals/common/setup/CCRegistration.java index fa774ba6f..bd663e26d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/CCRegistration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/CCRegistration.java @@ -9,8 +9,8 @@ import de.srendi.advancedperipherals.common.addons.computercraft.turtles.*; import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.*; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.registries.RegistryObject; +import net.neoforged.fml.common.Mod; +import net.neoforged.registries.RegistryObject; @Mod.EventBusSubscriber(modid = AdvancedPeripherals.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) public class CCRegistration { diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/ContainerTypes.java b/src/main/java/de/srendi/advancedperipherals/common/setup/ContainerTypes.java index 68ed5dc8c..15def7f6d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/ContainerTypes.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/ContainerTypes.java @@ -4,8 +4,8 @@ import net.minecraft.core.BlockPos; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.level.Level; -import net.minecraftforge.common.extensions.IForgeMenuType; -import net.minecraftforge.registries.RegistryObject; +import net.neoforged.common.extensions.IForgeMenuType; +import net.neoforged.registries.RegistryObject; public class ContainerTypes { diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/CreativeTabs.java b/src/main/java/de/srendi/advancedperipherals/common/setup/CreativeTabs.java index f7cb8f1a4..96cc8d1f2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/CreativeTabs.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/CreativeTabs.java @@ -3,7 +3,7 @@ import de.srendi.advancedperipherals.APCreativeTab; import de.srendi.advancedperipherals.AdvancedPeripherals; import net.minecraft.world.item.CreativeModeTab; -import net.minecraftforge.registries.RegistryObject; +import net.neoforged.registries.RegistryObject; public class CreativeTabs { diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/Items.java b/src/main/java/de/srendi/advancedperipherals/common/setup/Items.java index 89a165ca9..e24713a73 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/Items.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/Items.java @@ -5,7 +5,7 @@ import de.srendi.advancedperipherals.common.items.MemoryCardItem; import de.srendi.advancedperipherals.common.items.WeakAutomataCore; import net.minecraft.world.item.Item; -import net.minecraftforge.registries.RegistryObject; +import net.neoforged.registries.RegistryObject; public class Items { diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/Registration.java b/src/main/java/de/srendi/advancedperipherals/common/setup/Registration.java index 7199921ea..b232ea83c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/Registration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/Registration.java @@ -11,10 +11,10 @@ import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -import net.minecraftforge.registries.DeferredRegister; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.eventbus.api.IEventBus; +import net.neoforged.fml.javafmlmod.FMLJavaModLoadingContext; +import net.neoforged.registries.DeferredRegister; +import net.neoforged.registries.ForgeRegistries; public class Registration { diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/Villagers.java b/src/main/java/de/srendi/advancedperipherals/common/setup/Villagers.java index a57ec197b..705ff9b14 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/Villagers.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/Villagers.java @@ -6,7 +6,7 @@ import net.minecraft.sounds.SoundEvents; import net.minecraft.world.entity.ai.village.poi.PoiType; import net.minecraft.world.entity.npc.VillagerProfession; -import net.minecraftforge.registries.RegistryObject; +import net.neoforged.registries.RegistryObject; public class Villagers { diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java index dbd324dc8..f25f05c01 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java @@ -6,13 +6,13 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.saveddata.SavedData; -import net.minecraftforge.common.world.ForgeChunkManager; -import net.minecraftforge.event.TickEvent; -import net.minecraftforge.event.server.ServerStartedEvent; -import net.minecraftforge.event.server.ServerStoppingEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.server.ServerLifecycleHooks; +import net.neoforged.common.world.ForgeChunkManager; +import net.neoforged.event.TickEvent; +import net.neoforged.event.server.ServerStartedEvent; +import net.neoforged.event.server.ServerStoppingEvent; +import net.neoforged.eventbus.api.SubscribeEvent; +import net.neoforged.fml.common.Mod; +import net.neoforged.server.ServerLifecycleHooks; import org.apache.logging.log4j.Level; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/EnergyStorageProxy.java b/src/main/java/de/srendi/advancedperipherals/common/util/EnergyStorageProxy.java index 81d7f4a00..65461f7e1 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/EnergyStorageProxy.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/EnergyStorageProxy.java @@ -1,7 +1,7 @@ package de.srendi.advancedperipherals.common.util; import de.srendi.advancedperipherals.common.blocks.blockentities.EnergyDetectorEntity; -import net.minecraftforge.energy.IEnergyStorage; +import net.neoforged.energy.IEnergyStorage; import java.util.Optional; diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/KeybindUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/KeybindUtil.java index c0c9f68cd..b54ebd676 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/KeybindUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/KeybindUtil.java @@ -3,7 +3,7 @@ import com.mojang.blaze3d.platform.InputConstants; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; -import net.minecraftforge.client.settings.KeyModifier; +import net.neoforged.client.settings.KeyModifier; import org.lwjgl.glfw.GLFW; public class KeybindUtil { diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java b/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java index ba2c2c85c..baf50a56e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java @@ -14,7 +14,7 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.state.properties.Property; -import net.minecraftforge.common.IForgeShearable; +import net.neoforged.common.IForgeShearable; import org.jetbrains.annotations.NotNull; import java.util.Collections; diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/Platform.java b/src/main/java/de/srendi/advancedperipherals/common/util/Platform.java index 9acab5e70..b564f15fa 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/Platform.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/Platform.java @@ -2,7 +2,7 @@ import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.configuration.APConfig; -import net.minecraftforge.fml.ModList; +import net.neoforged.fml.ModList; import java.util.Optional; diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/RawValue.java b/src/main/java/de/srendi/advancedperipherals/common/util/RawValue.java index 6195df726..0ab85b58a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/RawValue.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/RawValue.java @@ -4,7 +4,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.registries.ForgeRegistries; import org.jetbrains.annotations.NotNull; import java.util.Collection; diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ServerWorker.java b/src/main/java/de/srendi/advancedperipherals/common/util/ServerWorker.java index 558fee12c..15570c293 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ServerWorker.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ServerWorker.java @@ -1,9 +1,9 @@ package de.srendi.advancedperipherals.common.util; import de.srendi.advancedperipherals.AdvancedPeripherals; -import net.minecraftforge.event.TickEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; +import net.neoforged.event.TickEvent; +import net.neoforged.eventbus.api.SubscribeEvent; +import net.neoforged.fml.common.Mod; import java.util.ArrayDeque; import java.util.Queue; diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java index d30d6eaf2..f07457e0d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java @@ -34,12 +34,12 @@ import net.minecraft.world.level.block.StructureBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.*; -import net.minecraftforge.common.ForgeHooks; -import net.minecraftforge.common.ForgeMod; -import net.minecraftforge.common.util.FakePlayer; -import net.minecraftforge.event.ForgeEventFactory; -import net.minecraftforge.event.entity.player.PlayerInteractEvent; -import net.minecraftforge.eventbus.api.Event; +import net.neoforged.common.ForgeHooks; +import net.neoforged.common.ForgeMod; +import net.neoforged.common.util.FakePlayer; +import net.neoforged.event.ForgeEventFactory; +import net.neoforged.event.entity.player.PlayerInteractEvent; +import net.neoforged.eventbus.api.Event; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java index ceaa4a5b2..a37f463d5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java @@ -12,8 +12,8 @@ import net.minecraft.tags.TagKey; import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.Fluids; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.fluids.FluidStack; +import net.neoforged.registries.ForgeRegistries; import java.util.Map; diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidUtil.java index a3d8cdec6..0199040fb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidUtil.java @@ -12,12 +12,12 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.material.Fluid; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.common.capabilities.ICapabilityProvider; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.IFluidHandler; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.common.capabilities.ForgeCapabilities; +import net.neoforged.common.capabilities.ICapabilityProvider; +import net.neoforged.common.util.LazyOptional; +import net.neoforged.fluids.FluidStack; +import net.neoforged.fluids.capability.IFluidHandler; +import net.neoforged.registries.ForgeRegistries; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemFluidHandler.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemFluidHandler.java index f86f1e487..0656de8e3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemFluidHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemFluidHandler.java @@ -1,7 +1,7 @@ package de.srendi.advancedperipherals.common.util.inventory; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.IFluidHandler; +import net.neoforged.fluids.FluidStack; +import net.neoforged.fluids.capability.IFluidHandler; import org.jetbrains.annotations.NotNull; public interface IStorageSystemFluidHandler extends IFluidHandler { diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemItemHandler.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemItemHandler.java index f5b161f6a..fbb61c412 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemItemHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemItemHandler.java @@ -1,7 +1,7 @@ package de.srendi.advancedperipherals.common.util.inventory; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.items.IItemHandler; +import net.neoforged.items.IItemHandler; import org.jetbrains.annotations.NotNull; public interface IStorageSystemItemHandler extends IItemHandler { diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/InventoryUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/InventoryUtil.java index 599872d24..67610be79 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/InventoryUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/InventoryUtil.java @@ -10,14 +10,14 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.common.capabilities.ICapabilityProvider; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.IFluidHandler; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.items.ItemHandlerHelper; -import net.minecraftforge.items.wrapper.InvWrapper; +import net.neoforged.common.capabilities.ForgeCapabilities; +import net.neoforged.common.capabilities.ICapabilityProvider; +import net.neoforged.common.util.LazyOptional; +import net.neoforged.fluids.FluidStack; +import net.neoforged.fluids.capability.IFluidHandler; +import net.neoforged.items.IItemHandler; +import net.neoforged.items.ItemHandlerHelper; +import net.neoforged.items.wrapper.InvWrapper; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java index 580ab9764..af88819d1 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java @@ -13,7 +13,7 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.registries.ForgeRegistries; import java.util.Map; diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemUtil.java index d9d39f9e1..6734a7849 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemUtil.java @@ -8,9 +8,9 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.IForgeRegistry; +import net.neoforged.items.IItemHandler; +import net.neoforged.registries.ForgeRegistries; +import net.neoforged.registries.IForgeRegistry; import org.apache.logging.log4j.Level; import java.nio.charset.StandardCharsets; diff --git a/src/main/java/de/srendi/advancedperipherals/common/village/VillageStructures.java b/src/main/java/de/srendi/advancedperipherals/common/village/VillageStructures.java index a5f279496..6b3b2b325 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/village/VillageStructures.java +++ b/src/main/java/de/srendi/advancedperipherals/common/village/VillageStructures.java @@ -12,9 +12,9 @@ import net.minecraft.world.level.levelgen.structure.pools.StructurePoolElement; import net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool; import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessorList; -import net.minecraftforge.event.server.ServerAboutToStartEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; +import net.neoforged.event.server.ServerAboutToStartEvent; +import net.neoforged.eventbus.api.SubscribeEvent; +import net.neoforged.fml.common.Mod; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrade.java b/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrade.java index 37509a075..b6cee7d31 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrade.java +++ b/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrade.java @@ -7,8 +7,8 @@ import net.minecraft.world.item.Items; import net.minecraft.world.item.trading.MerchantOffer; import net.minecraft.world.level.ItemLike; -import net.minecraftforge.event.village.VillagerTradesEvent; -import net.minecraftforge.event.village.WandererTradesEvent; +import net.neoforged.event.village.VillagerTradesEvent; +import net.neoforged.event.village.WandererTradesEvent; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrades.java b/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrades.java index c0d32fd76..fe92aa638 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrades.java +++ b/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrades.java @@ -7,10 +7,10 @@ import de.srendi.advancedperipherals.common.setup.Items; import de.srendi.advancedperipherals.common.setup.Villagers; import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; -import net.minecraftforge.event.village.VillagerTradesEvent; -import net.minecraftforge.event.village.WandererTradesEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; +import net.neoforged.event.village.VillagerTradesEvent; +import net.neoforged.event.village.WandererTradesEvent; +import net.neoforged.eventbus.api.SubscribeEvent; +import net.neoforged.fml.common.Mod; import static de.srendi.advancedperipherals.common.village.VillagerTrade.TradeBuilder; diff --git a/src/main/java/de/srendi/advancedperipherals/lib/LibConfig.java b/src/main/java/de/srendi/advancedperipherals/lib/LibConfig.java index 0ca3c3a25..067f7f137 100644 --- a/src/main/java/de/srendi/advancedperipherals/lib/LibConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/lib/LibConfig.java @@ -1,6 +1,6 @@ package de.srendi.advancedperipherals.lib; -import net.minecraftforge.common.ForgeConfigSpec; +import net.neoforged.common.ForgeConfigSpec; /** * Configuration class for tweaks of library diff --git a/src/main/java/de/srendi/advancedperipherals/lib/misc/IConfigHandler.java b/src/main/java/de/srendi/advancedperipherals/lib/misc/IConfigHandler.java index a7f86422e..ed2a3fffa 100644 --- a/src/main/java/de/srendi/advancedperipherals/lib/misc/IConfigHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/lib/misc/IConfigHandler.java @@ -1,6 +1,6 @@ package de.srendi.advancedperipherals.lib.misc; -import net.minecraftforge.common.ForgeConfigSpec; +import net.neoforged.common.ForgeConfigSpec; import java.util.Arrays; import java.util.stream.Collectors; diff --git a/src/main/java/de/srendi/advancedperipherals/lib/peripherals/IPeripheralPlugin.java b/src/main/java/de/srendi/advancedperipherals/lib/peripherals/IPeripheralPlugin.java index 07b784e9c..ac6f67bc5 100644 --- a/src/main/java/de/srendi/advancedperipherals/lib/peripherals/IPeripheralPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/lib/peripherals/IPeripheralPlugin.java @@ -2,7 +2,7 @@ import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.shared.computer.core.ServerContext; -import net.minecraftforge.server.ServerLifecycleHooks; +import net.neoforged.server.ServerLifecycleHooks; import org.jetbrains.annotations.Nullable; import java.util.List; diff --git a/src/main/java/de/srendi/advancedperipherals/network/APNetworking.java b/src/main/java/de/srendi/advancedperipherals/network/APNetworking.java index f1064f26e..e3ff5b5f2 100644 --- a/src/main/java/de/srendi/advancedperipherals/network/APNetworking.java +++ b/src/main/java/de/srendi/advancedperipherals/network/APNetworking.java @@ -12,12 +12,12 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraftforge.common.util.FakePlayer; -import net.minecraftforge.fml.ModLoadingContext; -import net.minecraftforge.network.NetworkDirection; -import net.minecraftforge.network.NetworkRegistry; -import net.minecraftforge.network.PacketDistributor; -import net.minecraftforge.network.simple.SimpleChannel; +import net.neoforged.common.util.FakePlayer; +import net.neoforged.fml.ModLoadingContext; +import net.neoforged.network.NetworkDirection; +import net.neoforged.network.NetworkRegistry; +import net.neoforged.network.PacketDistributor; +import net.neoforged.network.simple.SimpleChannel; import java.util.Optional; import java.util.function.Function; diff --git a/src/main/java/de/srendi/advancedperipherals/network/base/IPacket.java b/src/main/java/de/srendi/advancedperipherals/network/base/IPacket.java index 9a52059bb..85815054c 100644 --- a/src/main/java/de/srendi/advancedperipherals/network/base/IPacket.java +++ b/src/main/java/de/srendi/advancedperipherals/network/base/IPacket.java @@ -1,7 +1,7 @@ package de.srendi.advancedperipherals.network.base; import net.minecraft.network.FriendlyByteBuf; -import net.minecraftforge.network.NetworkEvent; +import net.neoforged.network.NetworkEvent; import java.util.function.Supplier; diff --git a/src/main/java/de/srendi/advancedperipherals/network/toclient/ToastToClientPacket.java b/src/main/java/de/srendi/advancedperipherals/network/toclient/ToastToClientPacket.java index e2a804eff..ced579df4 100644 --- a/src/main/java/de/srendi/advancedperipherals/network/toclient/ToastToClientPacket.java +++ b/src/main/java/de/srendi/advancedperipherals/network/toclient/ToastToClientPacket.java @@ -5,8 +5,8 @@ import de.srendi.advancedperipherals.network.base.IPacket; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; -import net.minecraftforge.fml.loading.FMLEnvironment; -import net.minecraftforge.network.NetworkEvent; +import net.neoforged.fml.loading.FMLEnvironment; +import net.neoforged.network.NetworkEvent; public class ToastToClientPacket implements IPacket { From 8716d5bcd8b54684d0ae3f19a53b26b4909f6efc Mon Sep 17 00:00:00 2001 From: zyxkad Date: Thu, 18 Apr 2024 15:51:34 -0600 Subject: [PATCH 113/228] fix commands --- .../common/commands/APCommands.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java b/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java index 7ca0ebaed..7536eb58c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java +++ b/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java @@ -31,8 +31,8 @@ public class APCommands { public static final String ROOT_LITERAL = "advancedperipherals"; public static final String FORCELOAD_LITERAL = "forceload"; static final String FORCELOAD_HELP = - "/" + ROOT_LITERAL + " " + FORCELOAD_LITERAL + " help" + " : show this help message\n" + - "/" + ROOT_LITERAL + " " + FORCELOAD_LITERAL + " dump" + " : show all chunky turtles\n"; + "/" + ROOT_LITERAL + " " + FORCELOAD_LITERAL + " help" + " - show this help message\n" + + "/" + ROOT_LITERAL + " " + FORCELOAD_LITERAL + " dump" + " - show all chunky turtles\n"; @SubscribeEvent public static void register(RegisterCommandsEvent event) { @@ -75,7 +75,7 @@ private static int forceloadHelp(CommandSourceStack source) throws CommandSyntax } private static int forceloadDump(CommandSourceStack source) throws CommandSyntaxException { - TableBuilder table = new TableBuilder("All Chunky Turtles", "Computer", "Position"); + TableBuilder table = new TableBuilder("ChunkyTurtles", "Computer", "Position"); ServerComputer[] computers = ServerContext.get(source.getServer()).registry().getComputers().stream().filter((computer) -> { Environment env = computer.getComputer().getEnvironment(); @@ -90,7 +90,7 @@ private static int forceloadDump(CommandSourceStack source) throws CommandSyntax for (ServerComputer computer : computers) { table.row( makeComputerDumpCommand(computer), - ChatHelpers.position(computer.getPosition()) + makeComputerPosCommand(computer) ); } @@ -102,8 +102,16 @@ private static int forceloadDump(CommandSourceStack source) throws CommandSyntax private static Component makeComputerDumpCommand(ServerComputer computer) { return ChatHelpers.link( Component.literal("#" + computer.getID()), - String.format("/computercraft dump %d", computer.getID()), + "/computercraft dump " + computer.getInstanceID(), Component.translatable("commands.computercraft.dump.action") ); } + + private static Component makeComputerPosCommand(ServerComputer computer) { + return ChatHelpers.link( + ChatHelpers.position(computer.getPosition()), + "/computercraft tp " + computer.getInstanceID(), + Component.translatable("commands.computercraft.tp.action") + ); + } } From b40a5611a391b62272d291a1d8444e296568fead Mon Sep 17 00:00:00 2001 From: zyxkad Date: Thu, 18 Apr 2024 16:00:53 -0600 Subject: [PATCH 114/228] apply patch 8716d5bcd8b54684d0ae3f19a53b26b4909f6efc --- .../common/commands/APCommands.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java b/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java index ea94ee805..06f8a9aa8 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java +++ b/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java @@ -31,8 +31,8 @@ public class APCommands { public static final String ROOT_LITERAL = "advancedperipherals"; public static final String FORCELOAD_LITERAL = "forceload"; static final String FORCELOAD_HELP = - "/" + ROOT_LITERAL + " " + FORCELOAD_LITERAL + " help" + " : show this help message\n" + - "/" + ROOT_LITERAL + " " + FORCELOAD_LITERAL + " dump" + " : show all chunky turtles\n"; + "/" + ROOT_LITERAL + " " + FORCELOAD_LITERAL + " help" + " - show this help message\n" + + "/" + ROOT_LITERAL + " " + FORCELOAD_LITERAL + " dump" + " - show all chunky turtles\n"; @SubscribeEvent public static void register(RegisterCommandsEvent event) { @@ -75,7 +75,7 @@ private static int forceloadHelp(CommandSourceStack source) throws CommandSyntax } private static int forceloadDump(CommandSourceStack source) throws CommandSyntaxException { - TableBuilder table = new TableBuilder("All Chunky Turtles", "Computer", "Position"); + TableBuilder table = new TableBuilder("ChunkyTurtles", "Computer", "Position"); ServerComputer[] computers = ServerContext.get(source.getServer()).registry().getComputers().stream().filter((computer) -> { Environment env = computer.getComputer().getEnvironment(); @@ -90,7 +90,7 @@ private static int forceloadDump(CommandSourceStack source) throws CommandSyntax for (ServerComputer computer : computers) { table.row( makeComputerDumpCommand(computer), - ChatHelpers.position(computer.getPosition()) + makeComputerPosCommand(computer) ); } @@ -102,8 +102,16 @@ private static int forceloadDump(CommandSourceStack source) throws CommandSyntax private static Component makeComputerDumpCommand(ServerComputer computer) { return ChatHelpers.link( Component.literal("#" + computer.getID()), - String.format("/computercraft dump %d", computer.getID()), + "/computercraft dump " + computer.getInstanceID(), Component.translatable("commands.computercraft.dump.action") ); } + + private static Component makeComputerPosCommand(ServerComputer computer) { + return ChatHelpers.link( + ChatHelpers.position(computer.getPosition()), + "/computercraft tp " + computer.getInstanceID(), + Component.translatable("commands.computercraft.tp.action") + ); + } } From 760fe0d62fa5f3f9249d390bb42982b6e3f585d8 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Thu, 18 Apr 2024 16:25:04 -0600 Subject: [PATCH 115/228] use arrow switch instead throw runtime exception --- .../common/util/CoordUtil.java | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java index 19f66b417..a21f2ab8d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java @@ -100,26 +100,24 @@ public static Direction getDirection(FrontAndTop orientation, String computerSid } if (front.getAxis() == Direction.Axis.Y) { - switch (side) { - case FRONT: return front; - case BACK: return front.getOpposite(); - case TOP: return top; - case BOTTOM: return top.getOpposite(); - case RIGHT: return top.getClockWise(); - case LEFT: return top.getCounterClockWise(); - } + return switch (side) { + case FRONT -> front; + case BACK -> front.getOpposite(); + case TOP -> top; + case BOTTOM -> top.getOpposite(); + case RIGHT -> top.getClockWise(); + case LEFT -> top.getCounterClockWise(); + }; } else { - switch (side) { - case FRONT: return front; - case BACK: return front.getOpposite(); - case TOP: return Direction.UP; - case BOTTOM: return Direction.DOWN; - case RIGHT: return front.getCounterClockWise(); - case LEFT: return front.getClockWise(); - } + return switch (side) { + case FRONT -> front; + case BACK -> front.getOpposite(); + case TOP -> Direction.UP; + case BOTTOM -> Direction.DOWN; + case RIGHT -> front.getCounterClockWise(); + case LEFT -> front.getClockWise(); + }; } - - throw new LuaException(computerSide + " is not a expected side"); } } From d9b769a2bc3f6d31d3b5f1fd14053f0050f6a4d2 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Thu, 18 Apr 2024 16:43:02 -0600 Subject: [PATCH 116/228] setDirty if record has removed during cleanup --- .../de/srendi/advancedperipherals/common/util/ChunkManager.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java index 033c8435c..bc876c4f8 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java @@ -213,6 +213,7 @@ public synchronized void cleanup() { AdvancedPeripherals.debug(String.format("Purge forced chunk for %s", uuid), Level.WARN); unforceChunkRecord(uuid, chunkRecord, level); iterator.remove(); + setDirty(); } } From 6b04b406a7acbe81743e0fe620350067291f8132 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Thu, 18 Apr 2024 16:43:02 -0600 Subject: [PATCH 117/228] setDirty if record has removed during cleanup --- .../de/srendi/advancedperipherals/common/util/ChunkManager.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java index ea9294a30..806ebe7d1 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java @@ -213,6 +213,7 @@ public synchronized void cleanup() { AdvancedPeripherals.debug(String.format("Purge forced chunk for %s", uuid), Level.WARN); unforceChunkRecord(uuid, chunkRecord, level); iterator.remove(); + setDirty(); } } From 1e7bb0670e58e581dc07b581b1c49fe4ff021f28 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Thu, 18 Apr 2024 18:06:26 -0600 Subject: [PATCH 118/228] fix force & unforce chunk when changing radius --- .../common/util/ChunkManager.java | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java index bc876c4f8..cb217fe6c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java @@ -57,8 +57,10 @@ public static void afterServerStarted(ServerStartedEvent event) { @SubscribeEvent public static void serverTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.END) { - tickCounter += 2; - if (tickCounter >= APConfig.PERIPHERALS_CONFIG.chunkLoadValidTime.get()) { + tickCounter++; + // run cleanup per chunkLoadValidTime / 10 + final int checkIntervalInTick = APConfig.PERIPHERALS_CONFIG.chunkLoadValidTime.get() * 20 / 10; + if (tickCounter >= checkIntervalInTick) { tickCounter = 0; ChunkManager.get(ServerLifecycleHooks.getCurrentServer().overworld()).cleanup(); } @@ -66,10 +68,12 @@ public static void serverTick(TickEvent.ServerTickEvent event) { } private static boolean forceChunk(UUID owner, ServerLevel level, ChunkPos pos) { + AdvancedPeripherals.debug("Forcing chunk " + pos, Level.WARN); return ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, owner, pos.x, pos.z, true, true); } private static boolean unforceChunk(UUID owner, ServerLevel level, ChunkPos pos) { + AdvancedPeripherals.debug("Unforcing chunk " + pos, Level.WARN); return ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, owner, pos.x, pos.z, false, true); } @@ -145,7 +149,7 @@ public synchronized void init() { } initialized = true; - AdvancedPeripherals.debug("Schedule chunk manager init, forcedChunks = " + forcedChunks.size(), Level.WARN); + AdvancedPeripherals.debug(String.format("Schedule chunk manager init, forcedChunks = %d", forcedChunks.size()), Level.WARN); final int chunkRadius = APConfig.PERIPHERALS_CONFIG.chunkyTurtleRadius.get(); final Map levels = getServerLevels(); forcedChunks.forEach((uuid, value) -> { @@ -170,22 +174,20 @@ public synchronized void init() { } } else if (loadedRadius > chunkRadius) { // clean overflowed load radius - for (int x = chunkRadius + 1; x <= loadedRadius; x++) { - for (int z = chunkRadius + 1; z <= loadedRadius; z++) { - unforceChunk(uuid, level, new ChunkPos(pos.x + x, pos.z + z)); - unforceChunk(uuid, level, new ChunkPos(pos.x + x, pos.z - z)); - unforceChunk(uuid, level, new ChunkPos(pos.x - x, pos.z + z)); - unforceChunk(uuid, level, new ChunkPos(pos.x - x, pos.z - z)); + for (int x = -loadedRadius; x <= loadedRadius; x++) { + for (int z = -loadedRadius; z <= loadedRadius; z++) { + if (Math.abs(x) > chunkRadius || Math.abs(z) > chunkRadius) { + unforceChunk(uuid, level, new ChunkPos(pos.x + x, pos.z + z)); + } } } } else if (loadedRadius < chunkRadius) { // otherwise, only do the changed part to reduce startup time (in case we have a lot chunky turtle) - for (int x = loadedRadius + 1; x <= chunkRadius; x++) { - for (int z = loadedRadius + 1; z <= chunkRadius; z++) { - forceChunk(uuid, level, new ChunkPos(pos.x + x, pos.z + z)); - forceChunk(uuid, level, new ChunkPos(pos.x + x, pos.z - z)); - forceChunk(uuid, level, new ChunkPos(pos.x - x, pos.z + z)); - forceChunk(uuid, level, new ChunkPos(pos.x - x, pos.z - z)); + for (int x = -chunkRadius; x <= chunkRadius; x++) { + for (int z = -chunkRadius; z <= chunkRadius; z++) { + if (Math.abs(x) > loadedRadius || Math.abs(z) > loadedRadius) { + forceChunk(uuid, level, new ChunkPos(pos.x + x, pos.z + z)); + } } } } From 03950568d868209a5cb9d22df9c9f81c8654d6d4 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Thu, 18 Apr 2024 18:06:26 -0600 Subject: [PATCH 119/228] fix force & unforce chunk when changing radius --- .../common/util/ChunkManager.java | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java index 806ebe7d1..3b338284d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java @@ -57,8 +57,10 @@ public static void afterServerStarted(ServerStartedEvent event) { @SubscribeEvent public static void serverTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.END) { - tickCounter += 2; - if (tickCounter >= APConfig.PERIPHERALS_CONFIG.chunkLoadValidTime.get()) { + tickCounter++; + // run cleanup per chunkLoadValidTime / 10 + final int checkIntervalInTick = APConfig.PERIPHERALS_CONFIG.chunkLoadValidTime.get() * 20 / 10; + if (tickCounter >= checkIntervalInTick) { tickCounter = 0; ChunkManager.get(ServerLifecycleHooks.getCurrentServer().overworld()).cleanup(); } @@ -66,10 +68,12 @@ public static void serverTick(TickEvent.ServerTickEvent event) { } private static boolean forceChunk(UUID owner, ServerLevel level, ChunkPos pos) { + AdvancedPeripherals.debug("Forcing chunk " + pos, Level.WARN); return ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, owner, pos.x, pos.z, true, true); } private static boolean unforceChunk(UUID owner, ServerLevel level, ChunkPos pos) { + AdvancedPeripherals.debug("Unforcing chunk " + pos, Level.WARN); return ForgeChunkManager.forceChunk(level, AdvancedPeripherals.MOD_ID, owner, pos.x, pos.z, false, true); } @@ -145,7 +149,7 @@ public synchronized void init() { } initialized = true; - AdvancedPeripherals.debug("Schedule chunk manager init, forcedChunks = " + forcedChunks.size(), Level.WARN); + AdvancedPeripherals.debug(String.format("Schedule chunk manager init, forcedChunks = %d", forcedChunks.size()), Level.WARN); final int chunkRadius = APConfig.PERIPHERALS_CONFIG.chunkyTurtleRadius.get(); final Map levels = getServerLevels(); forcedChunks.forEach((uuid, value) -> { @@ -170,22 +174,20 @@ public synchronized void init() { } } else if (loadedRadius > chunkRadius) { // clean overflowed load radius - for (int x = chunkRadius + 1; x <= loadedRadius; x++) { - for (int z = chunkRadius + 1; z <= loadedRadius; z++) { - unforceChunk(uuid, level, new ChunkPos(pos.x + x, pos.z + z)); - unforceChunk(uuid, level, new ChunkPos(pos.x + x, pos.z - z)); - unforceChunk(uuid, level, new ChunkPos(pos.x - x, pos.z + z)); - unforceChunk(uuid, level, new ChunkPos(pos.x - x, pos.z - z)); + for (int x = -loadedRadius; x <= loadedRadius; x++) { + for (int z = -loadedRadius; z <= loadedRadius; z++) { + if (Math.abs(x) > chunkRadius || Math.abs(z) > chunkRadius) { + unforceChunk(uuid, level, new ChunkPos(pos.x + x, pos.z + z)); + } } } } else if (loadedRadius < chunkRadius) { // otherwise, only do the changed part to reduce startup time (in case we have a lot chunky turtle) - for (int x = loadedRadius + 1; x <= chunkRadius; x++) { - for (int z = loadedRadius + 1; z <= chunkRadius; z++) { - forceChunk(uuid, level, new ChunkPos(pos.x + x, pos.z + z)); - forceChunk(uuid, level, new ChunkPos(pos.x + x, pos.z - z)); - forceChunk(uuid, level, new ChunkPos(pos.x - x, pos.z + z)); - forceChunk(uuid, level, new ChunkPos(pos.x - x, pos.z - z)); + for (int x = -chunkRadius; x <= chunkRadius; x++) { + for (int z = -chunkRadius; z <= chunkRadius; z++) { + if (Math.abs(x) > loadedRadius || Math.abs(z) > loadedRadius) { + forceChunk(uuid, level, new ChunkPos(pos.x + x, pos.z + z)); + } } } } From ff6d1b857f9f9d7bf4af885358ec37fe3adeaa3a Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sat, 20 Apr 2024 22:49:10 -0600 Subject: [PATCH 120/228] fix typo maxHeatlh -> maxHealth close #588 --- .../computercraft/peripheral/PlayerDetectorPeripheral.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/PlayerDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/PlayerDetectorPeripheral.java index 61cec7656..36858f741 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/PlayerDetectorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/PlayerDetectorPeripheral.java @@ -259,7 +259,9 @@ public final Map getPlayerPos(IArguments arguments) throws LuaEx info.put("dimension", existingPlayer.getLevel().dimension().location().toString()); info.put("eyeHeight", existingPlayer.getEyeHeight()); info.put("health", existingPlayer.getHealth()); - info.put("maxHeatlh", existingPlayer.getMaxHealth()); + // TODO: remove the next line in next major version + info.put("maxHeatlh", existingPlayer.getMaxHealth()); // keep this for backward compatibility + info.put("maxHealth", existingPlayer.getMaxHealth()); info.put("airSupply", existingPlayer.getAirSupply()); info.put("respawnPosition", LuaConverter.posToObject(existingPlayer.getRespawnPosition())); info.put("respawnDimension", existingPlayer.getRespawnDimension().location().toString()); From ba3b33dee1b32c24a10d75469ac35ea6cb5c7315 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sat, 20 Apr 2024 22:54:02 -0600 Subject: [PATCH 121/228] do not call Math.pow multiple times --- .../computercraft/peripheral/PlayerDetectorPeripheral.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/PlayerDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/PlayerDetectorPeripheral.java index 36858f741..6e8b90fa3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/PlayerDetectorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/PlayerDetectorPeripheral.java @@ -250,9 +250,10 @@ public final Map getPlayerPos(IArguments arguments) throws LuaEx int decimals = Math.min(arguments.optInt(1, 0), 4); - info.put("x", Math.floor(x * Math.pow(10, decimals)) / Math.pow(10, decimals)); - info.put("y", Math.floor(y * Math.pow(10, decimals)) / Math.pow(10, decimals)); - info.put("z", Math.floor(z * Math.pow(10, decimals)) / Math.pow(10, decimals)); + final double unit = Math.pow(10, decimals); + info.put("x", Math.floor(x * unit) / unit); + info.put("y", Math.floor(y * unit) / unit); + info.put("z", Math.floor(z * unit) / unit); if (APConfig.PERIPHERALS_CONFIG.morePlayerInformation.get()) { info.put("yaw", existingPlayer.yRotO); info.put("pitch", existingPlayer.xRotO); From 7e2d55febfefe92cf990eb9e04aef7f50c023bc4 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Mon, 22 Apr 2024 08:09:54 -0600 Subject: [PATCH 122/228] comment unused code --- .../addons/computercraft/turtles/TurtleChunkyUpgrade.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChunkyUpgrade.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChunkyUpgrade.java index 7e4d50404..bed242638 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChunkyUpgrade.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChunkyUpgrade.java @@ -39,12 +39,12 @@ public void update(@NotNull ITurtleAccess turtle, @NotNull TurtleSide side) { // The turtle can move, so we need to do that. super.update(turtle, side); if (APConfig.PERIPHERALS_CONFIG.enableChunkyTurtle.get()) { - updateTick++; // TODO: turtle will stop work when crossing chunks if update every 10 ticks + // updateTick++; // if (updateTick < 10) { // return; // } - updateTick = 0; + // updateTick = 0; IPeripheral peripheral = turtle.getPeripheral(side); if (peripheral instanceof ChunkyPeripheral chunkyPeripheral) { chunkyPeripheral.updateChunkState(); From d10641f68966620b39f63791609764fde5e2426b Mon Sep 17 00:00:00 2001 From: zyxkad Date: Mon, 22 Apr 2024 08:09:54 -0600 Subject: [PATCH 123/228] comment unused code --- .../addons/computercraft/turtles/TurtleChunkyUpgrade.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChunkyUpgrade.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChunkyUpgrade.java index 7e4d50404..bed242638 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChunkyUpgrade.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/turtles/TurtleChunkyUpgrade.java @@ -39,12 +39,12 @@ public void update(@NotNull ITurtleAccess turtle, @NotNull TurtleSide side) { // The turtle can move, so we need to do that. super.update(turtle, side); if (APConfig.PERIPHERALS_CONFIG.enableChunkyTurtle.get()) { - updateTick++; // TODO: turtle will stop work when crossing chunks if update every 10 ticks + // updateTick++; // if (updateTick < 10) { // return; // } - updateTick = 0; + // updateTick = 0; IPeripheral peripheral = turtle.getPeripheral(side); if (peripheral instanceof ChunkyPeripheral chunkyPeripheral) { chunkyPeripheral.updateChunkState(); From e2c69e9a4aec5fd54ef2eb70a0b1aec2996061d3 Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 22 Apr 2024 18:10:53 +0200 Subject: [PATCH 124/228] Added build and test workflow to 1.19.2 --- .github/workflows/build-and-test.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .github/workflows/build-and-test.yaml diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml new file mode 100644 index 000000000..ac5da2b84 --- /dev/null +++ b/.github/workflows/build-and-test.yaml @@ -0,0 +1,16 @@ +name: Build and Test + +on: + workflow_run: + workflows: [Build And Test] + types: + - completed + push: + pull_request_target: + types: + - opened + - synchronize + +jobs: + build-and-test: + uses: IntelligenceModding/actions/.github/workflows/build-and-test.yaml@main \ No newline at end of file From 1e2412ee9540718638cb161585f478e4eb262822 Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 22 Apr 2024 18:12:36 +0200 Subject: [PATCH 125/228] Fixed on triggers --- .github/workflows/build-and-test.yaml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml index ac5da2b84..e4d74bd46 100644 --- a/.github/workflows/build-and-test.yaml +++ b/.github/workflows/build-and-test.yaml @@ -1,10 +1,7 @@ name: Build and Test on: - workflow_run: - workflows: [Build And Test] - types: - - completed + workflow_dispatch: push: pull_request_target: types: From d7fc90a8f806d55f7ceda20136b4d47eea8e3c4a Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 22 Apr 2024 18:13:08 +0200 Subject: [PATCH 126/228] Fixed branch of workflow --- .github/workflows/build-and-test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml index e4d74bd46..f3c7b7f7e 100644 --- a/.github/workflows/build-and-test.yaml +++ b/.github/workflows/build-and-test.yaml @@ -10,4 +10,4 @@ on: jobs: build-and-test: - uses: IntelligenceModding/actions/.github/workflows/build-and-test.yaml@main \ No newline at end of file + uses: IntelligenceModding/actions/.github/workflows/build-and-test.yaml@master \ No newline at end of file From 4acaa1c435dd95e03fd61e0e052948c7c198c4f9 Mon Sep 17 00:00:00 2001 From: Kevin Z Date: Sun, 14 Apr 2024 08:37:26 -0600 Subject: [PATCH 127/228] use ConcurrentLinkedQueue instead of non-thread-safe ArrayDeque --- .../srendi/advancedperipherals/common/util/ServerWorker.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ServerWorker.java b/src/main/java/de/srendi/advancedperipherals/common/util/ServerWorker.java index 558fee12c..884cbd5a2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ServerWorker.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ServerWorker.java @@ -5,13 +5,13 @@ import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; -import java.util.ArrayDeque; import java.util.Queue; +import java.util.concurrent.ConcurrentLinkedQueue; @Mod.EventBusSubscriber(modid = AdvancedPeripherals.MOD_ID) public class ServerWorker { - private static final Queue callQueue = new ArrayDeque<>(); + private static final Queue callQueue = new ConcurrentLinkedQueue<>(); public static void add(final Runnable call) { callQueue.add(call); From 4282602f978c074d9de5f3ee3ffa3b4e1a4f1b1b Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 22 Apr 2024 19:01:19 +0200 Subject: [PATCH 128/228] Make gradle a bit more happy. The dependencies now load. It's time to port --- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../advancedperipherals/AdvancedPeripherals.java | 7 ++----- .../common/configuration/APConfig.java | 2 +- .../common/configuration/GeneralConfig.java | 11 +++++++---- .../common/configuration/IAPConfig.java | 7 ++++--- .../de/srendi/advancedperipherals/lib/LibConfig.java | 8 ++++---- .../advancedperipherals/lib/misc/IConfigHandler.java | 4 ++-- 8 files changed, 22 insertions(+), 21 deletions(-) diff --git a/build.gradle b/build.gradle index d3b6b07ed..609d49c6f 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ plugins { java.toolchain.languageVersion = JavaLanguageVersion.of(17) wrapper { - gradleVersion = '8.6' + gradleVersion = '8.7' distributionType = Wrapper.DistributionType.BIN } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a80b22ce5..b82aa23a4 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java index c5834083c..38293f89d 100644 --- a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java +++ b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java @@ -6,8 +6,7 @@ import de.srendi.advancedperipherals.network.APNetworking; import net.minecraft.resources.ResourceLocation; -import net.neoforged.common.MinecraftForge; -import net.neoforged.eventbus.api.IEventBus; +import net.neoforged.bus.api.IEventBus; import net.neoforged.fml.ModLoadingContext; import net.neoforged.fml.common.Mod; import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; @@ -26,15 +25,13 @@ public class AdvancedPeripherals { public static final Logger LOGGER = LogManager.getLogger(NAME); public static final Random RANDOM = new Random(); - public AdvancedPeripherals() { + public AdvancedPeripherals(IEventBus modBus) { LOGGER.info("AdvancedPeripherals says hello!"); - IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus(); APConfig.register(ModLoadingContext.get()); modBus.addListener(this::commonSetup); Registration.register(); - MinecraftForge.EVENT_BUS.register(this); } public static void debug(String message) { diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/APConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/APConfig.java index bff1378a9..fc778ce5f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/APConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/APConfig.java @@ -53,7 +53,7 @@ public Function reader(Path configBasePath) { } @Override - public void unload(Path configBasePath, ModConfig config) { + public void unload(ModConfig config) { super.unload(getPath(configBasePath), config); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/GeneralConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/GeneralConfig.java index 8918cbf36..5468408c6 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/GeneralConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/GeneralConfig.java @@ -3,15 +3,18 @@ import de.srendi.advancedperipherals.lib.LibConfig; import net.minecraft.FieldsAreNonnullByDefault; import net.neoforged.fml.config.ModConfig; +import net.neoforged.neoforge.common.ModConfigSpec; +import net.neoforged.neoforge.common.NeoForge; +import net.neoforged.neoforge.common.NeoForgeConfig; @FieldsAreNonnullByDefault public class GeneralConfig implements IAPConfig { - public final ForgeConfigSpec.BooleanValue enableDebugMode; - private final ForgeConfigSpec configSpec; + public final ModConfigSpec.BooleanValue enableDebugMode; + private final ModConfigSpec configSpec; GeneralConfig() { - ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder(); + ModConfigSpec.Builder builder = new ModConfigSpec.Builder(); builder.comment("Config to adjust general mod settings").push("General"); @@ -29,7 +32,7 @@ public class GeneralConfig implements IAPConfig { @Override - public ForgeConfigSpec getConfigSpec() { + public ModConfigSpec getConfigSpec() { return configSpec; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/IAPConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/IAPConfig.java index 65fcd4879..770a44b63 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/IAPConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/IAPConfig.java @@ -3,22 +3,23 @@ import de.srendi.advancedperipherals.lib.misc.IConfigHandler; import net.neoforged.common.ForgeConfigSpec; import net.neoforged.fml.config.ModConfig; +import net.neoforged.neoforge.common.ModConfigSpec; public interface IAPConfig { - ForgeConfigSpec getConfigSpec(); + ModConfigSpec getConfigSpec(); String getFileName(); ModConfig.Type getType(); - default void register(IConfigHandler[] data, final ForgeConfigSpec.Builder builder) { + default void register(IConfigHandler[] data, final ModConfigSpec.Builder builder) { for (IConfigHandler handler : data) { handler.addToConfig(builder); } } - default void pop(String name, ForgeConfigSpec.Builder builder) { + default void pop(String name, ModConfigSpec.Builder builder) { builder.pop(); builder.push(name); } diff --git a/src/main/java/de/srendi/advancedperipherals/lib/LibConfig.java b/src/main/java/de/srendi/advancedperipherals/lib/LibConfig.java index 067f7f137..3f4826436 100644 --- a/src/main/java/de/srendi/advancedperipherals/lib/LibConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/lib/LibConfig.java @@ -1,6 +1,6 @@ package de.srendi.advancedperipherals.lib; -import net.neoforged.common.ForgeConfigSpec; +import net.neoforged.neoforge.common.ModConfigSpec; /** * Configuration class for tweaks of library @@ -10,8 +10,8 @@ public class LibConfig { public static boolean initialCooldownEnabled = true; public static int initialCooldownSensitivity = 6_000; private static boolean testMode = false; - private static ForgeConfigSpec.BooleanValue isInitialCooldownEnabled; - private static ForgeConfigSpec.IntValue initialCooldownSensitiveLevel; + private static ModConfigSpec.BooleanValue isInitialCooldownEnabled; + private static ModConfigSpec.IntValue initialCooldownSensitiveLevel; public static void setTestMode(boolean mode) { testMode = mode; @@ -26,7 +26,7 @@ public static void setTestMode(boolean mode) { } } - public static void build(final ForgeConfigSpec.Builder builder) { + public static void build(final ModConfigSpec.Builder builder) { isInitialCooldownEnabled = builder.comment("Enables initial cooldown on peripheral initialization").define("isInitialCooldownEnabled", true); initialCooldownSensitiveLevel = builder.comment("Determinates initial cooldown sensitive level, values lower then this value will not trigger initial cooldown").defineInRange("initialCooldownSensitiveLevel", 6_000, 0, Integer.MAX_VALUE); } diff --git a/src/main/java/de/srendi/advancedperipherals/lib/misc/IConfigHandler.java b/src/main/java/de/srendi/advancedperipherals/lib/misc/IConfigHandler.java index ed2a3fffa..095c25bc9 100644 --- a/src/main/java/de/srendi/advancedperipherals/lib/misc/IConfigHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/lib/misc/IConfigHandler.java @@ -1,12 +1,12 @@ package de.srendi.advancedperipherals.lib.misc; -import net.neoforged.common.ForgeConfigSpec; +import net.neoforged.neoforge.common.ModConfigSpec; import java.util.Arrays; import java.util.stream.Collectors; public interface IConfigHandler { - void addToConfig(ForgeConfigSpec.Builder builder); + void addToConfig(ModConfigSpec.Builder builder); String name(); From 972044460551a285b504d64c073a6b573eecbeb7 Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 22 Apr 2024 20:01:16 +0200 Subject: [PATCH 129/228] Some registry work --- .../advancedperipherals/APCreativeTab.java | 3 +- .../AdvancedPeripherals.java | 2 +- .../client/ClientRegistry.java | 7 ++-- .../common/setup/BlockEntityTypes.java | 25 +++++++------- .../common/setup/Blocks.java | 33 ++++++++++--------- .../common/setup/ContainerTypes.java | 3 +- .../common/setup/CreativeTabs.java | 4 +-- .../common/setup/Items.java | 21 +++++++----- .../common/setup/Registration.java | 24 ++++++-------- .../common/setup/Villagers.java | 7 ++-- 10 files changed, 66 insertions(+), 63 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java b/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java index cb9699333..b5b82889f 100644 --- a/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java +++ b/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java @@ -8,7 +8,6 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.ItemStack; -import net.neoforged.registries.RegistryObject; import java.util.Collection; import java.util.Set; @@ -17,7 +16,7 @@ public class APCreativeTab { public static void populateCreativeTabBuilder(CreativeModeTab.Builder builder) { builder.displayItems((set, out) -> { - Registration.ITEMS.getEntries().stream().map(RegistryObject::get).forEach(out::accept); + Registration.ITEMS.().stream().map(RegistryObject::get).forEach(out::accept); out.acceptAll(pocketUpgrade(CCRegistration.ID.COLONY_POCKET)); out.acceptAll(pocketUpgrade(CCRegistration.ID.CHATTY_POCKET)); out.acceptAll(pocketUpgrade(CCRegistration.ID.PLAYER_POCKET)); diff --git a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java index 38293f89d..aa60f4955 100644 --- a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java +++ b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java @@ -31,7 +31,7 @@ public AdvancedPeripherals(IEventBus modBus) { APConfig.register(ModLoadingContext.get()); modBus.addListener(this::commonSetup); - Registration.register(); + Registration.register(modBus); } public static void debug(String message) { diff --git a/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java b/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java index fcdef9dfc..5e053f83c 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java +++ b/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java @@ -1,6 +1,5 @@ package de.srendi.advancedperipherals.client; -import dan200.computercraft.api.client.ComputerCraftAPIClient; import dan200.computercraft.api.client.turtle.TurtleUpgradeModeller; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.container.InventoryManagerScreen; @@ -10,11 +9,11 @@ import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.resources.ResourceLocation; import net.neoforged.api.distmarker.Dist; -import net.neoforged.client.event.ModelEvent; -import net.neoforged.client.event.RegisterKeyMappingsEvent; -import net.neoforged.eventbus.api.SubscribeEvent; +import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.common.Mod; import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; +import net.neoforged.neoforge.client.event.ModelEvent; +import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent; @Mod.EventBusSubscriber(modid = AdvancedPeripherals.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD) public class ClientRegistry { diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/BlockEntityTypes.java b/src/main/java/de/srendi/advancedperipherals/common/setup/BlockEntityTypes.java index c0efd9ad4..fa56352e5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/BlockEntityTypes.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/BlockEntityTypes.java @@ -4,23 +4,24 @@ import de.srendi.advancedperipherals.common.blocks.blockentities.*; import net.minecraft.world.level.block.entity.BlockEntityType; import net.neoforged.fml.ModList; +import net.neoforged.neoforge.registries.DeferredHolder; import net.neoforged.registries.RegistryObject; public class BlockEntityTypes { - public static final RegistryObject> CHAT_BOX = Registration.TILE_ENTITIES.register("chat_box", () -> new BlockEntityType<>(ChatBoxEntity::new, Sets.newHashSet(Blocks.CHAT_BOX.get()), null)); - public static final RegistryObject> ENVIRONMENT_DETECTOR = Registration.TILE_ENTITIES.register("environment_detector", () -> new BlockEntityType<>(EnvironmentDetectorEntity::new, Sets.newHashSet(Blocks.ENVIRONMENT_DETECTOR.get()), null)); - public static final RegistryObject> PLAYER_DETECTOR = Registration.TILE_ENTITIES.register("player_detector", () -> new BlockEntityType<>(PlayerDetectorEntity::new, Sets.newHashSet(Blocks.PLAYER_DETECTOR.get()), null)); - public static final RegistryObject> ME_BRIDGE = ModList.get().isLoaded("ae2") ? Registration.TILE_ENTITIES.register("me_bridge", () -> new BlockEntityType<>(MeBridgeEntity::new, Sets.newHashSet(Blocks.ME_BRIDGE.get()), null)) : null; - public static final RegistryObject> RS_BRIDGE = ModList.get().isLoaded("refinedstorage") ? Registration.TILE_ENTITIES.register("rs_bridge", () -> new BlockEntityType<>(RsBridgeEntity::new, Sets.newHashSet(Blocks.RS_BRIDGE.get()), null)) : null; - public static final RegistryObject> ENERGY_DETECTOR = Registration.TILE_ENTITIES.register("energy_detector", () -> new BlockEntityType<>(EnergyDetectorEntity::new, Sets.newHashSet(Blocks.ENERGY_DETECTOR.get()), null)); - public static final RegistryObject> INVENTORY_MANAGER = Registration.TILE_ENTITIES.register("inventory_manager", () -> new BlockEntityType<>(InventoryManagerEntity::new, Sets.newHashSet(Blocks.INVENTORY_MANAGER.get()), null)); - public static final RegistryObject> REDSTONE_INTEGRATOR = Registration.TILE_ENTITIES.register("redstone_integrator", () -> new BlockEntityType<>(RedstoneIntegratorEntity::new, Sets.newHashSet(Blocks.REDSTONE_INTEGRATOR.get()), null)); - public static final RegistryObject> BLOCK_READER = Registration.TILE_ENTITIES.register("block_reader", () -> new BlockEntityType<>(BlockReaderEntity::new, Sets.newHashSet(Blocks.BLOCK_READER.get()), null)); - public static final RegistryObject> GEO_SCANNER = Registration.TILE_ENTITIES.register("geo_scanner", () -> new BlockEntityType<>(GeoScannerEntity::new, Sets.newHashSet(Blocks.GEO_SCANNER.get()), null)); - public static final RegistryObject> COLONY_INTEGRATOR = Registration.TILE_ENTITIES.register("colony_integrator", () -> new BlockEntityType<>(ColonyIntegratorEntity::new, Sets.newHashSet(Blocks.COLONY_INTEGRATOR.get()), null)); + public static final DeferredHolder, BlockEntityType> CHAT_BOX = Registration.TILE_ENTITIES.register("chat_box", () -> new BlockEntityType<>(ChatBoxEntity::new, Sets.newHashSet(Blocks.CHAT_BOX.get()), null)); + public static final DeferredHolder, BlockEntityType> ENVIRONMENT_DETECTOR = Registration.TILE_ENTITIES.register("environment_detector", () -> new BlockEntityType<>(EnvironmentDetectorEntity::new, Sets.newHashSet(Blocks.ENVIRONMENT_DETECTOR.get()), null)); + public static final DeferredHolder, BlockEntityType> PLAYER_DETECTOR = Registration.TILE_ENTITIES.register("player_detector", () -> new BlockEntityType<>(PlayerDetectorEntity::new, Sets.newHashSet(Blocks.PLAYER_DETECTOR.get()), null)); + public static final DeferredHolder, BlockEntityType> ME_BRIDGE = ModList.get().isLoaded("ae2") ? Registration.TILE_ENTITIES.register("me_bridge", () -> new BlockEntityType<>(MeBridgeEntity::new, Sets.newHashSet(Blocks.ME_BRIDGE.get()), null)) : null; + public static final DeferredHolder, BlockEntityType> RS_BRIDGE = ModList.get().isLoaded("refinedstorage") ? Registration.TILE_ENTITIES.register("rs_bridge", () -> new BlockEntityType<>(RsBridgeEntity::new, Sets.newHashSet(Blocks.RS_BRIDGE.get()), null)) : null; + public static final DeferredHolder, BlockEntityType> ENERGY_DETECTOR = Registration.TILE_ENTITIES.register("energy_detector", () -> new BlockEntityType<>(EnergyDetectorEntity::new, Sets.newHashSet(Blocks.ENERGY_DETECTOR.get()), null)); + public static final DeferredHolder, BlockEntityType> INVENTORY_MANAGER = Registration.TILE_ENTITIES.register("inventory_manager", () -> new BlockEntityType<>(InventoryManagerEntity::new, Sets.newHashSet(Blocks.INVENTORY_MANAGER.get()), null)); + public static final DeferredHolder, BlockEntityType> REDSTONE_INTEGRATOR = Registration.TILE_ENTITIES.register("redstone_integrator", () -> new BlockEntityType<>(RedstoneIntegratorEntity::new, Sets.newHashSet(Blocks.REDSTONE_INTEGRATOR.get()), null)); + public static final DeferredHolder, BlockEntityType> BLOCK_READER = Registration.TILE_ENTITIES.register("block_reader", () -> new BlockEntityType<>(BlockReaderEntity::new, Sets.newHashSet(Blocks.BLOCK_READER.get()), null)); + public static final DeferredHolder, BlockEntityType> GEO_SCANNER = Registration.TILE_ENTITIES.register("geo_scanner", () -> new BlockEntityType<>(GeoScannerEntity::new, Sets.newHashSet(Blocks.GEO_SCANNER.get()), null)); + public static final DeferredHolder, BlockEntityType> COLONY_INTEGRATOR = Registration.TILE_ENTITIES.register("colony_integrator", () -> new BlockEntityType<>(ColonyIntegratorEntity::new, Sets.newHashSet(Blocks.COLONY_INTEGRATOR.get()), null)); - public static final RegistryObject> NBT_STORAGE = Registration.TILE_ENTITIES.register("nbt_storage", () -> new BlockEntityType<>(NBTStorageEntity::new, Sets.newHashSet(Blocks.NBT_STORAGE.get()), null)); + public static final DeferredHolder, BlockEntityType> NBT_STORAGE = Registration.TILE_ENTITIES.register("nbt_storage", () -> new BlockEntityType<>(NBTStorageEntity::new, Sets.newHashSet(Blocks.NBT_STORAGE.get()), null)); public static void register() { } diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/Blocks.java b/src/main/java/de/srendi/advancedperipherals/common/setup/Blocks.java index 609e32f95..ee7214c37 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/Blocks.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/Blocks.java @@ -13,35 +13,36 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.neoforged.fml.ModList; +import net.neoforged.neoforge.registries.DeferredHolder; import net.neoforged.registries.RegistryObject; import java.util.function.Supplier; public class Blocks { - public static final RegistryObject ENVIRONMENT_DETECTOR = register("environment_detector", () -> new APBlockEntityBlock<>(BlockEntityTypes.ENVIRONMENT_DETECTOR, false), () -> new APBlockItem(Blocks.ENVIRONMENT_DETECTOR.get(), APConfig.PERIPHERALS_CONFIG.enableEnvironmentDetector::get)); - public static final RegistryObject CHAT_BOX = register("chat_box", () -> new APBlockEntityBlock<>(BlockEntityTypes.CHAT_BOX, true), () -> new APBlockItem(Blocks.CHAT_BOX.get(), APConfig.PERIPHERALS_CONFIG.enableChatBox::get)); - public static final RegistryObject PLAYER_DETECTOR = register("player_detector", PlayerDetectorBlock::new, () -> new APBlockItem(Blocks.PLAYER_DETECTOR.get(), APConfig.PERIPHERALS_CONFIG.enablePlayerDetector::get)); - public static final RegistryObject ME_BRIDGE = register("me_bridge", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("ae2") ? BlockEntityTypes.ME_BRIDGE : null, ModList.get().isLoaded("ae2")), () -> new APBlockItem(Blocks.ME_BRIDGE.get(), APConfig.PERIPHERALS_CONFIG.enableMEBridge::get)); - public static final RegistryObject RS_BRIDGE = register("rs_bridge", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("refinedstorage") ? BlockEntityTypes.RS_BRIDGE : null, false), () -> new APBlockItem(Blocks.RS_BRIDGE.get(), APConfig.PERIPHERALS_CONFIG.enableRSBridge::get)); - public static final RegistryObject ENERGY_DETECTOR = register("energy_detector", () -> new APBlockEntityBlock<>(BlockEntityTypes.ENERGY_DETECTOR, true), () -> new APBlockItem(Blocks.ENERGY_DETECTOR.get(), APConfig.PERIPHERALS_CONFIG.enableEnergyDetector::get)); - public static final RegistryObject PERIPHERAL_CASING = register("peripheral_casing", BaseBlock::new, () -> new APBlockItem(Blocks.PERIPHERAL_CASING.get(), new Item.Properties().stacksTo(16), () -> true)); - public static final RegistryObject INVENTORY_MANAGER = register("inventory_manager", () -> new APBlockEntityBlock<>(BlockEntityTypes.INVENTORY_MANAGER, false), () -> new APBlockItem(Blocks.INVENTORY_MANAGER.get(), APConfig.PERIPHERALS_CONFIG.enableInventoryManager::get)); - public static final RegistryObject REDSTONE_INTEGRATOR = register("redstone_integrator", RedstoneIntegratorBlock::new, () -> new APBlockItem(Blocks.REDSTONE_INTEGRATOR.get(), APConfig.PERIPHERALS_CONFIG.enableRedstoneIntegrator::get)); - public static final RegistryObject BLOCK_READER = register("block_reader", () -> new APBlockEntityBlock<>(BlockEntityTypes.BLOCK_READER, true), () -> new APBlockItem(Blocks.BLOCK_READER.get(), APConfig.PERIPHERALS_CONFIG.enableBlockReader::get)); - public static final RegistryObject GEO_SCANNER = register("geo_scanner", () -> new APBlockEntityBlock<>(BlockEntityTypes.GEO_SCANNER, false), () -> new APBlockItem(Blocks.GEO_SCANNER.get(), APConfig.PERIPHERALS_CONFIG.enableGeoScanner::get)); - public static final RegistryObject COLONY_INTEGRATOR = register("colony_integrator", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("minecolonies") ? BlockEntityTypes.COLONY_INTEGRATOR : null, false), () -> new APBlockItem(Blocks.COLONY_INTEGRATOR.get(), APConfig.PERIPHERALS_CONFIG.enableColonyIntegrator::get)); - public static final RegistryObject NBT_STORAGE = register("nbt_storage", () -> new APBlockEntityBlock<>(BlockEntityTypes.NBT_STORAGE, false), () -> new APBlockItem(Blocks.NBT_STORAGE.get(), APConfig.PERIPHERALS_CONFIG.enableNBTStorage::get)); + public static final DeferredHolder> ENVIRONMENT_DETECTOR = register("environment_detector", () -> new APBlockEntityBlock<>(BlockEntityTypes.ENVIRONMENT_DETECTOR, false), () -> new APBlockItem(Blocks.ENVIRONMENT_DETECTOR.get(), APConfig.PERIPHERALS_CONFIG.enableEnvironmentDetector::get)); + public static final DeferredHolder> CHAT_BOX = register("chat_box", () -> new APBlockEntityBlock<>(BlockEntityTypes.CHAT_BOX, true), () -> new APBlockItem(Blocks.CHAT_BOX.get(), APConfig.PERIPHERALS_CONFIG.enableChatBox::get)); + public static final DeferredHolder> PLAYER_DETECTOR = register("player_detector", PlayerDetectorBlock::new, () -> new APBlockItem(Blocks.PLAYER_DETECTOR.get(), APConfig.PERIPHERALS_CONFIG.enablePlayerDetector::get)); + public static final DeferredHolder> ME_BRIDGE = register("me_bridge", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("ae2") ? BlockEntityTypes.ME_BRIDGE : null, ModList.get().isLoaded("ae2")), () -> new APBlockItem(Blocks.ME_BRIDGE.get(), APConfig.PERIPHERALS_CONFIG.enableMEBridge::get)); + public static final DeferredHolder> RS_BRIDGE = register("rs_bridge", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("refinedstorage") ? BlockEntityTypes.RS_BRIDGE : null, false), () -> new APBlockItem(Blocks.RS_BRIDGE.get(), APConfig.PERIPHERALS_CONFIG.enableRSBridge::get)); + public static final DeferredHolder> ENERGY_DETECTOR = register("energy_detector", () -> new APBlockEntityBlock<>(BlockEntityTypes.ENERGY_DETECTOR, true), () -> new APBlockItem(Blocks.ENERGY_DETECTOR.get(), APConfig.PERIPHERALS_CONFIG.enableEnergyDetector::get)); + public static final DeferredHolder PERIPHERAL_CASING = register("peripheral_casing", BaseBlock::new, () -> new APBlockItem(Blocks.PERIPHERAL_CASING.get(), new Item.Properties().stacksTo(16), () -> true)); + public static final DeferredHolder> INVENTORY_MANAGER = register("inventory_manager", () -> new APBlockEntityBlock<>(BlockEntityTypes.INVENTORY_MANAGER, false), () -> new APBlockItem(Blocks.INVENTORY_MANAGER.get(), APConfig.PERIPHERALS_CONFIG.enableInventoryManager::get)); + public static final DeferredHolder> REDSTONE_INTEGRATOR = register("redstone_integrator", RedstoneIntegratorBlock::new, () -> new APBlockItem(Blocks.REDSTONE_INTEGRATOR.get(), APConfig.PERIPHERALS_CONFIG.enableRedstoneIntegrator::get)); + public static final DeferredHolder> BLOCK_READER = register("block_reader", () -> new APBlockEntityBlock<>(BlockEntityTypes.BLOCK_READER, true), () -> new APBlockItem(Blocks.BLOCK_READER.get(), APConfig.PERIPHERALS_CONFIG.enableBlockReader::get)); + public static final DeferredHolder> GEO_SCANNER = register("geo_scanner", () -> new APBlockEntityBlock<>(BlockEntityTypes.GEO_SCANNER, false), () -> new APBlockItem(Blocks.GEO_SCANNER.get(), APConfig.PERIPHERALS_CONFIG.enableGeoScanner::get)); + public static final DeferredHolder> COLONY_INTEGRATOR = register("colony_integrator", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("minecolonies") ? BlockEntityTypes.COLONY_INTEGRATOR : null, false), () -> new APBlockItem(Blocks.COLONY_INTEGRATOR.get(), APConfig.PERIPHERALS_CONFIG.enableColonyIntegrator::get)); + public static final DeferredHolder> NBT_STORAGE = register("nbt_storage", () -> new APBlockEntityBlock<>(BlockEntityTypes.NBT_STORAGE, false), () -> new APBlockItem(Blocks.NBT_STORAGE.get(), APConfig.PERIPHERALS_CONFIG.enableNBTStorage::get)); public static void register() { } - private static RegistryObject registerNoItem(String name, Supplier block) { + private static DeferredHolder registerNoItem(String name, Supplier block) { return Registration.BLOCKS.register(name, block); } - private static RegistryObject register(String name, Supplier block, Supplier blockItem) { - RegistryObject registryObject = registerNoItem(name, block); + private static DeferredHolder register(String name, Supplier block, Supplier blockItem) { + DeferredHolder registryObject = registerNoItem(name, block); Registration.ITEMS.register(name, blockItem); return registryObject; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/ContainerTypes.java b/src/main/java/de/srendi/advancedperipherals/common/setup/ContainerTypes.java index 15def7f6d..eb37d1b24 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/ContainerTypes.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/ContainerTypes.java @@ -5,11 +5,12 @@ import net.minecraft.world.inventory.MenuType; import net.minecraft.world.level.Level; import net.neoforged.common.extensions.IForgeMenuType; +import net.neoforged.neoforge.registries.DeferredHolder; import net.neoforged.registries.RegistryObject; public class ContainerTypes { - public static final RegistryObject> INVENTORY_MANAGER_CONTAINER = Registration.CONTAINER_TYPES.register("memory_card_container", () -> IForgeMenuType.create((windowId, inv, data) -> { + public static final DeferredHolder, MenuType> INVENTORY_MANAGER_CONTAINER = Registration.CONTAINER_TYPES.register("memory_card_container", () -> IMenUType.create((windowId, inv, data) -> { BlockPos pos = data.readBlockPos(); Level level = inv.player.getCommandSenderWorld(); return new InventoryManagerContainer(windowId, inv, pos, level); diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/CreativeTabs.java b/src/main/java/de/srendi/advancedperipherals/common/setup/CreativeTabs.java index 96cc8d1f2..78b7e74e3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/CreativeTabs.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/CreativeTabs.java @@ -3,11 +3,11 @@ import de.srendi.advancedperipherals.APCreativeTab; import de.srendi.advancedperipherals.AdvancedPeripherals; import net.minecraft.world.item.CreativeModeTab; -import net.neoforged.registries.RegistryObject; +import net.neoforged.neoforge.registries.DeferredHolder; public class CreativeTabs { - public static final RegistryObject AP_CREATIVE_MODE_TAB = Registration.CREATIVE_MODE_TABS.register(AdvancedPeripherals.MOD_ID, CreativeTabs::createCreativeTab); + public static final DeferredHolder AP_CREATIVE_MODE_TAB = Registration.CREATIVE_MODE_TABS.register(AdvancedPeripherals.MOD_ID, CreativeTabs::createCreativeTab); private static CreativeModeTab createCreativeTab() { CreativeModeTab.Builder builder = new CreativeModeTab.Builder(CreativeModeTab.Row.BOTTOM, -1); diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/Items.java b/src/main/java/de/srendi/advancedperipherals/common/setup/Items.java index e24713a73..ceebc25bb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/Items.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/Items.java @@ -1,23 +1,26 @@ package de.srendi.advancedperipherals.common.setup; +import com.refinedmods.refinedstorage.apiimpl.API; import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.items.APItem; import de.srendi.advancedperipherals.common.items.MemoryCardItem; import de.srendi.advancedperipherals.common.items.WeakAutomataCore; import net.minecraft.world.item.Item; +import net.neoforged.neoforge.registries.DeferredHolder; +import net.neoforged.neoforge.registries.DeferredItem; import net.neoforged.registries.RegistryObject; public class Items { - public static final RegistryObject CHUNK_CONTROLLER = Registration.ITEMS.register("chunk_controller", () -> new APItem(new Item.Properties().stacksTo(16), APConfig.PERIPHERALS_CONFIG.enableChunkyTurtle::get)); - public static final RegistryObject COMPUTER_TOOL = Registration.ITEMS.register("computer_tool", () -> new APItem(new Item.Properties().stacksTo(1), () -> true)); - public static final RegistryObject MEMORY_CARD = Registration.ITEMS.register("memory_card", MemoryCardItem::new); - public static final RegistryObject END_AUTOMATA_CORE = Registration.ITEMS.register("end_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableEndAutomataCore)); - public static final RegistryObject HUSBANDRY_AUTOMATA_CORE = Registration.ITEMS.register("husbandry_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableHusbandryAutomataCore)); - public static final RegistryObject WEAK_AUTOMATA_CORE = Registration.ITEMS.register("weak_automata_core", () -> new WeakAutomataCore(new Item.Properties().stacksTo(1))); - public static final RegistryObject OVERPOWERED_WEAK_AUTOMATA_CORE = Registration.ITEMS.register("overpowered_weak_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableWeakAutomataCore)); - public static final RegistryObject OVERPOWERED_END_AUTOMATA_CORE = Registration.ITEMS.register("overpowered_end_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableEndAutomataCore)); - public static final RegistryObject OVERPOWERED_HUSBANDRY_AUTOMATA_CORE = Registration.ITEMS.register("overpowered_husbandry_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableHusbandryAutomataCore)); + public static final DeferredHolder CHUNK_CONTROLLER = Registration.ITEMS.register("chunk_controller", () -> new APItem(new Item.Properties().stacksTo(16), APConfig.PERIPHERALS_CONFIG.enableChunkyTurtle::get)); + public static final DeferredHolder COMPUTER_TOOL = Registration.ITEMS.register("computer_tool", () -> new APItem(new Item.Properties().stacksTo(1), () -> true)); + public static final DeferredHolder MEMORY_CARD = Registration.ITEMS.register("memory_card", MemoryCardItem::new); + public static final DeferredHolder END_AUTOMATA_CORE = Registration.ITEMS.register("end_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableEndAutomataCore)); + public static final DeferredHolder HUSBANDRY_AUTOMATA_CORE = Registration.ITEMS.register("husbandry_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableHusbandryAutomataCore)); + public static final DeferredHolder WEAK_AUTOMATA_CORE = Registration.ITEMS.register("weak_automata_core", () -> new WeakAutomataCore(new Item.Properties().stacksTo(1))); + public static final DeferredHolder OVERPOWERED_WEAK_AUTOMATA_CORE = Registration.ITEMS.register("overpowered_weak_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableWeakAutomataCore)); + public static final DeferredHolder OVERPOWERED_END_AUTOMATA_CORE = Registration.ITEMS.register("overpowered_end_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableEndAutomataCore)); + public static final DeferredHolder OVERPOWERED_HUSBANDRY_AUTOMATA_CORE = Registration.ITEMS.register("overpowered_husbandry_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableHusbandryAutomataCore)); public static void register() { } diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/Registration.java b/src/main/java/de/srendi/advancedperipherals/common/setup/Registration.java index b232ea83c..6b6432be1 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/Registration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/Registration.java @@ -1,7 +1,5 @@ package de.srendi.advancedperipherals.common.setup; -import dan200.computercraft.api.pocket.PocketUpgradeSerialiser; -import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser; import de.srendi.advancedperipherals.AdvancedPeripherals; import net.minecraft.core.registries.Registries; import net.minecraft.world.entity.ai.village.poi.PoiType; @@ -11,25 +9,23 @@ import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntityType; -import net.neoforged.eventbus.api.IEventBus; -import net.neoforged.fml.javafmlmod.FMLJavaModLoadingContext; -import net.neoforged.registries.DeferredRegister; -import net.neoforged.registries.ForgeRegistries; +import net.neoforged.bus.api.IEventBus; + +import net.neoforged.neoforge.registries.DeferredRegister; public class Registration { - public static final DeferredRegister BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, AdvancedPeripherals.MOD_ID); - public static final DeferredRegister ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, AdvancedPeripherals.MOD_ID); - public static final DeferredRegister> TILE_ENTITIES = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, AdvancedPeripherals.MOD_ID); - public static final DeferredRegister> CONTAINER_TYPES = DeferredRegister.create(ForgeRegistries.MENU_TYPES, AdvancedPeripherals.MOD_ID); - public static final DeferredRegister POI_TYPES = DeferredRegister.create(ForgeRegistries.POI_TYPES, AdvancedPeripherals.MOD_ID); - public static final DeferredRegister VILLAGER_PROFESSIONS = DeferredRegister.create(ForgeRegistries.VILLAGER_PROFESSIONS, AdvancedPeripherals.MOD_ID); + public static final DeferredRegister BLOCKS = DeferredRegister.create(Registries.BLOCK, AdvancedPeripherals.MOD_ID); + public static final DeferredRegister ITEMS = DeferredRegister.create(Registries.ITEM, AdvancedPeripherals.MOD_ID); + public static final DeferredRegister> TILE_ENTITIES = DeferredRegister.create(Registries.BLOCK_ENTITY_TYPE, AdvancedPeripherals.MOD_ID); + public static final DeferredRegister> CONTAINER_TYPES = DeferredRegister.create(Registries.MENU, AdvancedPeripherals.MOD_ID); + public static final DeferredRegister POI_TYPES = DeferredRegister.create(Registries.POINT_OF_INTEREST_TYPE, AdvancedPeripherals.MOD_ID); + public static final DeferredRegister VILLAGER_PROFESSIONS = DeferredRegister.create(Registries.VILLAGER_PROFESSION, AdvancedPeripherals.MOD_ID); public static final DeferredRegister> TURTLE_SERIALIZER = DeferredRegister.create(TurtleUpgradeSerialiser.registryId(), AdvancedPeripherals.MOD_ID); public static final DeferredRegister> POCKET_SERIALIZER = DeferredRegister.create(PocketUpgradeSerialiser.registryId(), AdvancedPeripherals.MOD_ID); public static final DeferredRegister CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, AdvancedPeripherals.MOD_ID); - public static void register() { - IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); + public static void register(IEventBus modEventBus) { BLOCKS.register(modEventBus); ITEMS.register(modEventBus); TILE_ENTITIES.register(modEventBus); diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/Villagers.java b/src/main/java/de/srendi/advancedperipherals/common/setup/Villagers.java index 705ff9b14..f26b9d69e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/Villagers.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/Villagers.java @@ -6,12 +6,15 @@ import net.minecraft.sounds.SoundEvents; import net.minecraft.world.entity.ai.village.poi.PoiType; import net.minecraft.world.entity.npc.VillagerProfession; +import net.neoforged.neoforge.registries.DeferredHolder; import net.neoforged.registries.RegistryObject; +import java.util.function.Supplier; + public class Villagers { - public static final RegistryObject COMPUTER_SCIENTIST_POI = Registration.POI_TYPES.register("computer_scientist", () -> new PoiType(ImmutableSet.copyOf(ModRegistry.Blocks.COMPUTER_ADVANCED.get().getStateDefinition().getPossibleStates()), 1, 1)); - public static final RegistryObject COMPUTER_SCIENTIST = Registration.VILLAGER_PROFESSIONS.register("computer_scientist", () -> new VillagerProfession(AdvancedPeripherals.MOD_ID + ":computer_scientist", holder -> holder.is(COMPUTER_SCIENTIST_POI.getKey()), holder -> holder.is(COMPUTER_SCIENTIST_POI.getKey()), ImmutableSet.of(), ImmutableSet.of(ModRegistry.Blocks.COMPUTER_ADVANCED.get()), SoundEvents.VILLAGER_WORK_TOOLSMITH)); + public static final Supplier COMPUTER_SCIENTIST_POI = Registration.POI_TYPES.register("computer_scientist", () -> new PoiType(ImmutableSet.copyOf(ModRegistry.Blocks.COMPUTER_ADVANCED.get().getStateDefinition().getPossibleStates()), 1, 1)); + public static final Supplier COMPUTER_SCIENTIST = Registration.VILLAGER_PROFESSIONS.register("computer_scientist", () -> new VillagerProfession(AdvancedPeripherals.MOD_ID + ":computer_scientist", holder -> holder.is(COMPUTER_SCIENTIST_POI.getKey()), holder -> holder.is(COMPUTER_SCIENTIST_POI.getKey()), ImmutableSet.of(), ImmutableSet.of(ModRegistry.Blocks.COMPUTER_ADVANCED.get()), SoundEvents.VILLAGER_WORK_TOOLSMITH)); public static void register() { } From f87532b656a357ed7dfbd27925478b98b1cdc0cb Mon Sep 17 00:00:00 2001 From: Srendi Date: Wed, 24 Apr 2024 13:27:46 +0200 Subject: [PATCH 130/228] Aktualisieren von bug_report.yml --- .github/ISSUE_TEMPLATE/bug_report.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 75fe2e0b1..15e3241ee 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -41,14 +41,14 @@ body: multiple: false options: - Own compiled build. - - 1.20.1-0.7.38r (Latest 1.20.1) + - 1.20.1-0.7.39r (Latest 1.20.1) + - 1.20.1-0.7.38r - 1.20.1-0.7.37r - - 1.20.1-0.7.36r - - 1.20.1-0.7.35b - - 1.19.2-0.7.34r (Latest 1.19.2) + - 1.20.1-0.7.36r + - 1.19.2-0.7.35r (Latest 1.19.2) + - 1.19.2-0.7.34r - 1.19.2-0.7.33r - - 1.19.2-0.7.32r - - 1.19.2-0.7.31r + - 1.19.2-0.7.32r - 1.18.2-0.7.31r (Latest 1.18.2) - 1.18.2-0.7.30r - 1.18.2-0.7.29r From 8c7723135385005e5a54aa9298b0d09506917b27 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Wed, 24 Apr 2024 18:31:56 -0600 Subject: [PATCH 131/228] add advanced place method to the compass peripheral --- .../peripheral/CompassPeripheral.java | 81 +++++++++++++++++++ .../configuration/PeripheralsConfig.java | 37 +++++---- 2 files changed, 101 insertions(+), 17 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java index fb24c8c1a..877f1310a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java @@ -1,11 +1,28 @@ package de.srendi.advancedperipherals.common.addons.computercraft.peripheral; +import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaFunction; +import dan200.computercraft.api.lua.MethodResult; import dan200.computercraft.api.turtle.ITurtleAccess; import dan200.computercraft.api.turtle.TurtleSide; +import dan200.computercraft.core.apis.TableHelper; +import dan200.computercraft.shared.turtle.core.TurtlePlayer; import de.srendi.advancedperipherals.common.addons.computercraft.owner.TurtlePeripheralOwner; import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.DirectionalPlaceContext; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.Vec3; +import net.minecraftforge.common.ForgeHooks; +import net.minecraftforge.event.entity.player.PlayerInteractEvent; +import java.util.Map; public class CompassPeripheral extends BasePeripheral { @@ -24,4 +41,68 @@ public boolean isEnabled() { public String getFacing() { return owner.getFacing().toString(); } + + @LuaFunction(mainThread = true) + /** + * + * @param options A table contains how to place the block: + * x: the x offset relative to the turtle + * y: the y offset relative to the turtle + * z: the z offset relative to the turtle + * forward: the direction the block is going to facing. Default is the facing direction of the turtle + * top: the direction the block's top is going to facing. Default is TOP + */ + public MethodResult place(Map options) throws LuaException { + int x = TableHelper.optIntField(options, "x", 0); + int y = TableHelper.optIntField(options, "y", 0); + int z = TableHelper.optIntField(options, "z", 0); + final int maxRange = APConfig.PERIPHERALS_CONFIG.compassTurtleRadius.get(); + if (x > maxRange || y > maxRange || z > maxRange) { + return MethodResult.of(false, "OUT_OF_RANGE"); + } + String forward = TableHelper.optStringField(options, "forward", null); + String top = TableHelper.optStringField(options, "top", null) + Direction forwardDir, topDir; + if (forward != null && (forwardDir = Direction.byName(forward.toLowerCase())) == null) { + throw new LuaException(forward + "is not a valid direction"); + } + if (top != null && (topDir = Direction.byName(top.toLowerCase())) == null) { + throw new LuaException(top + "is not a valid direction"); + } + + ITurtleAccess turtle = owner.getTurtle(); + ItemStack stack = turtle.getInventory().getItem(turtle.getSelectedSlot()); + if (stack.isEmpty()) { + return MethodResult.of(false, "EMPTY_SLOT"); + } + BlockPos position = turtle.getPosition().offset(x, y, z); + return deployOn(stack, position, forwardDir, topDir, options); + } + + private MethodResult deployOn(ItemStack stack, BlockPos position, Direction forward, Direction top, Map options) throws LuaException { + ITurtleAccess turtle = owner.getTurtle(); + Level world = turtle.getLevel(); + if (forward == null) { + forward = turtle.getDirection(); + } + if (top == null) { + top = Direction.UP; + } + TurtlePlayer turtlePlayer = TurtlePlayer.getWithPosition(turtle, position, forward.getOpposite()); + BlockHitResult hit = BlockHitResult.miss(Vec3.atCenterOf(position), top, position); + DirectionalPlaceContext context = new DirectionalPlaceContext(world, position, forward, stack, top); + PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock(turtlePlayer, InteractionHand.MAIN_HAND, position, hit); + if (event.isCanceled()) { + return MethodResult.of(false, "EVENT_CANCELED"); + } + if (stack.getItem() instanceof BlockItem block) { + InteractionResult res = block.place(context); + if (!res.consumesAction()) { + return MethodResult.of(false, "CANNOT_PLACE"); + } + } else { + return MethodResult.of(false, "NOT_BLOCK"); + } + return MethodResult.of(true); + } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java index e9c7d0d33..398b75a06 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java @@ -10,7 +10,7 @@ @FieldsAreNonnullByDefault public class PeripheralsConfig implements IAPConfig { - //Player Detector + // Player Detector public final ForgeConfigSpec.IntValue playerDetMaxRange; public final ForgeConfigSpec.BooleanValue playerSpy; public final ForgeConfigSpec.BooleanValue morePlayerInformation; @@ -20,57 +20,59 @@ public class PeripheralsConfig implements IAPConfig { public final ForgeConfigSpec.IntValue playerSpyRandErrorAmount; public final ForgeConfigSpec.IntValue playerSpyPreciseMaxRange; - //Energy Detector + // Energy Detector public final ForgeConfigSpec.IntValue energyDetectorMaxFlow; public final ForgeConfigSpec.BooleanValue enableEnergyDetector; - //NBT Storage + // NBT Storage public final ForgeConfigSpec.IntValue nbtStorageMaxSize; public final ForgeConfigSpec.BooleanValue enableNBTStorage; - //Chunky turtle - public final ForgeConfigSpec.IntValue chunkLoadValidTime; + // Chunky turtle + public final ForgeConfigSpec.IntValue chunkLoadValidTime; public final ForgeConfigSpec.IntValue chunkyTurtleRadius; public final ForgeConfigSpec.BooleanValue enableChunkyTurtle; - //Chat box + + // Chat box public final ForgeConfigSpec.BooleanValue enableChatBox; public final ForgeConfigSpec.ConfigValue defaultChatBoxPrefix; public final ForgeConfigSpec.IntValue chatBoxMaxRange; public final ForgeConfigSpec.BooleanValue chatBoxMultiDimensional; - //ME Bridge + // ME Bridge public final ForgeConfigSpec.BooleanValue enableMEBridge; public final ForgeConfigSpec.IntValue meConsumption; - //Rs Bridge + // Rs Bridge public final ForgeConfigSpec.BooleanValue enableRSBridge; public final ForgeConfigSpec.IntValue rsConsumption; - //Environment Detector + // Environment Detector public final ForgeConfigSpec.BooleanValue enableEnvironmentDetector; - //AR Controller + // AR Controller public final ForgeConfigSpec.BooleanValue enableARGoggles; - //Inventory Manager + // Inventory Manager public final ForgeConfigSpec.BooleanValue enableInventoryManager; - //Redstone Integrator + // Redstone Integrator public final ForgeConfigSpec.BooleanValue enableRedstoneIntegrator; - //Block reader + // Block reader public final ForgeConfigSpec.BooleanValue enableBlockReader; - //Geo Scanner + // Geo Scanner public final ForgeConfigSpec.BooleanValue enableGeoScanner; - //Colony integrator + // Colony integrator public final ForgeConfigSpec.BooleanValue enableColonyIntegrator; - //Compass turtle + // Compass turtle public final ForgeConfigSpec.BooleanValue enableCompassTurtle; + public final ForgeConfigSpec.IntValue compassTurtleRadius; - //Powered Peripherals + // Powered Peripherals public final ForgeConfigSpec.BooleanValue enablePoweredPeripherals; public final ForgeConfigSpec.BooleanValue disablePocketFuelConsumption; public final ForgeConfigSpec.IntValue poweredPeripheralMaxEnergyStorage; @@ -155,6 +157,7 @@ public PeripheralsConfig() { pop("Compass_Turtle", builder); enableCompassTurtle = builder.comment("Enable the compass turtle or not.").define("enableCompassTurtle", true); + compassTurtleRadius = builder.comment("The maximum distance the compass turtle can reach in each axis.").defineInRange("compassTurtleRadius", 1, 0, 8); pop("Powered_Peripherals", builder); From fcbcc72c0d80ff47328efa5d3f38883cdefedb1a Mon Sep 17 00:00:00 2001 From: zyxkad Date: Wed, 24 Apr 2024 21:10:49 -0600 Subject: [PATCH 132/228] costs fuel when tring to use compass to place in far distance --- .../operations/SingleOperation.java | 4 +- .../peripheral/ChatBoxPeripheral.java | 25 +++-- .../peripheral/CompassPeripheral.java | 103 ++++++++++++++---- .../configuration/PeripheralsConfig.java | 4 +- .../common/util/StringUtil.java | 19 ++++ 5 files changed, 118 insertions(+), 37 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SingleOperation.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SingleOperation.java index 08ebd3c6b..90205db17 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SingleOperation.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SingleOperation.java @@ -13,7 +13,8 @@ public enum SingleOperation implements IPeripheralOperation 1), + LINEAR(d -> d), SQRT(d -> (int) Math.sqrt(d)); private final Function factorFunction; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java index 4519202af..d0bcb5c32 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java @@ -18,6 +18,7 @@ import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.events.Events; import de.srendi.advancedperipherals.common.util.CoordUtil; +import de.srendi.advancedperipherals.common.util.StringUtil; import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; import de.srendi.advancedperipherals.lib.peripherals.IPeripheralFunction; import de.srendi.advancedperipherals.network.APNetworking; @@ -121,9 +122,9 @@ public final MethodResult sendFormattedMessage(@NotNull IArguments arguments) th return MethodResult.of(null, "incorrect bracket string (e.g. [], {}, <>, ...)"); MutableComponent preparedMessage = appendPrefix( - arguments.optString(1, APConfig.PERIPHERALS_CONFIG.defaultChatBoxPrefix.get()).replaceAll("&", "\u00a7"), + StringUtil.convertAndToSectionMark(arguments.optString(1, APConfig.PERIPHERALS_CONFIG.defaultChatBoxPrefix.get())), arguments.optString(2, "[]"), - arguments.optString(3, "").replaceAll("&", "\u00a7") + StringUtil.convertAndToSectionMark(arguments.optString(3, "")) ).append(component); for (ServerPlayer player : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers()) { if (!APConfig.PERIPHERALS_CONFIG.chatBoxMultiDimensional.get() && player.getLevel().dimension() != dimension) @@ -147,9 +148,9 @@ public final MethodResult sendMessage(@NotNull IArguments arguments) throws LuaE return MethodResult.of(null, "incorrect bracket string (e.g. [], {}, <>, ...)"); MutableComponent preparedMessage = appendPrefix( - arguments.optString(1, APConfig.PERIPHERALS_CONFIG.defaultChatBoxPrefix.get()).replaceAll("&", "\u00a7"), + StringUtil.convertAndToSectionMark(arguments.optString(1, APConfig.PERIPHERALS_CONFIG.defaultChatBoxPrefix.get())), arguments.optString(2, "[]"), - arguments.optString(3, "").replaceAll("&", "\u00a7") + StringUtil.convertAndToSectionMark(arguments.optString(3, "")) ).append(message); for (ServerPlayer player : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers()) { if (!APConfig.PERIPHERALS_CONFIG.chatBoxMultiDimensional.get() && player.getLevel().dimension() != dimension) @@ -182,9 +183,9 @@ public final MethodResult sendFormattedMessageToPlayer(@NotNull IArguments argum return MethodResult.of(null, "incorrect bracket string (e.g. [], {}, <>, ...)"); MutableComponent preparedMessage = appendPrefix( - arguments.optString(2, APConfig.PERIPHERALS_CONFIG.defaultChatBoxPrefix.get()).replaceAll("&", "\u00a7"), + StringUtil.convertAndToSectionMark(arguments.optString(2, APConfig.PERIPHERALS_CONFIG.defaultChatBoxPrefix.get())), arguments.optString(3, "[]"), - arguments.optString(4, "").replaceAll("&", "\u00a7") + StringUtil.convertAndToSectionMark(arguments.optString(4, "")) ).append(component); if (!APConfig.PERIPHERALS_CONFIG.chatBoxMultiDimensional.get() && player.getLevel().dimension() != dimension) return MethodResult.of(false, "NOT_SAME_DIMENSION"); @@ -222,9 +223,9 @@ public final MethodResult sendFormattedToastToPlayer(@NotNull IArguments argumen return MethodResult.of(null, "incorrect bracket string (e.g. [], {}, <>, ,,,)"); MutableComponent preparedMessage = appendPrefix( - arguments.optString(3, APConfig.PERIPHERALS_CONFIG.defaultChatBoxPrefix.get()).replaceAll("&", "\u00a7"), + StringUtil.convertAndToSectionMark(arguments.optString(3, APConfig.PERIPHERALS_CONFIG.defaultChatBoxPrefix.get())), arguments.optString(4, "[]"), - arguments.optString(5, "").replaceAll("&", "\u00a7") + StringUtil.convertAndToSectionMark(arguments.optString(5, "")) ).append(messageComponent); if (!APConfig.PERIPHERALS_CONFIG.chatBoxMultiDimensional.get() && player.getLevel().dimension() != dimension) @@ -256,9 +257,9 @@ public final MethodResult sendMessageToPlayer(@NotNull IArguments arguments) thr return MethodResult.of(null, "incorrect bracket string (e.g. [], {}, <>, ...)"); MutableComponent preparedMessage = appendPrefix( - arguments.optString(2, APConfig.PERIPHERALS_CONFIG.defaultChatBoxPrefix.get()).replaceAll("&", "\u00a7"), + StringUtil.convertAndToSectionMark(arguments.optString(2, APConfig.PERIPHERALS_CONFIG.defaultChatBoxPrefix.get())), arguments.optString(3, "[]"), - arguments.optString(4, "").replaceAll("&", "\u00a7") + StringUtil.convertAndToSectionMark(arguments.optString(4, "")) ).append(message); if (!APConfig.PERIPHERALS_CONFIG.chatBoxMultiDimensional.get() && player.getLevel().dimension() != dimension) return MethodResult.of(false, "NOT_SAME_DIMENSION"); @@ -287,9 +288,9 @@ public final MethodResult sendToastToPlayer(@NotNull IArguments arguments) throw return MethodResult.of(null, "incorrect bracket string (e.g. [], {}, <>, ...)"); MutableComponent preparedMessage = appendPrefix( - arguments.optString(3, APConfig.PERIPHERALS_CONFIG.defaultChatBoxPrefix.get()).replaceAll("&", "\u00a7"), + StringUtil.convertAndToSectionMark(arguments.optString(3, APConfig.PERIPHERALS_CONFIG.defaultChatBoxPrefix.get())), arguments.optString(4, "[]"), - arguments.optString(5, "").replaceAll("&", "\u00a7") + StringUtil.convertAndToSectionMark(arguments.optString(5, "")) ).append(message); if (!APConfig.PERIPHERALS_CONFIG.chatBoxMultiDimensional.get() && player.getLevel().dimension() != dimension) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java index 877f1310a..5020b44c0 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java @@ -7,29 +7,45 @@ import dan200.computercraft.api.turtle.TurtleSide; import dan200.computercraft.core.apis.TableHelper; import dan200.computercraft.shared.turtle.core.TurtlePlayer; +import de.srendi.advancedperipherals.common.addons.computercraft.operations.SingleOperationContext; import de.srendi.advancedperipherals.common.addons.computercraft.owner.TurtlePeripheralOwner; import de.srendi.advancedperipherals.common.configuration.APConfig; +import de.srendi.advancedperipherals.common.util.StringUtil; import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.network.chat.Component; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.SignItem; import net.minecraft.world.item.context.DirectionalPlaceContext; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.SignBlockEntity; import net.minecraft.world.level.Level; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec3; import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import java.util.Map; +import javax.annotation.Nullable; + +import static de.srendi.advancedperipherals.common.addons.computercraft.operations.SingleOperation.ACCURE_PLACE; public class CompassPeripheral extends BasePeripheral { public static final String PERIPHERAL_TYPE = "compass"; + protected CompassPeripheral(TurtlePeripheralOwner owner) { + super(PERIPHERAL_TYPE, owner); + owner.attachOperation(ACCURE_PLACE); + } + public CompassPeripheral(ITurtleAccess turtle, TurtleSide side) { - super(PERIPHERAL_TYPE, new TurtlePeripheralOwner(turtle, side)); + this(new TurtlePeripheralOwner(turtle, side).attachFuel(1)); } @Override @@ -46,23 +62,25 @@ public String getFacing() { /** * * @param options A table contains how to place the block: - * x: the x offset relative to the turtle - * y: the y offset relative to the turtle - * z: the z offset relative to the turtle + * x: the x offset relative to the turtle. Default 0 + * y: the y offset relative to the turtle. Default 0 + * z: the z offset relative to the turtle. Default 0 * forward: the direction the block is going to facing. Default is the facing direction of the turtle * top: the direction the block's top is going to facing. Default is TOP + * text: the text going to write on the sign. Default is null */ public MethodResult place(Map options) throws LuaException { int x = TableHelper.optIntField(options, "x", 0); int y = TableHelper.optIntField(options, "y", 0); int z = TableHelper.optIntField(options, "z", 0); - final int maxRange = APConfig.PERIPHERALS_CONFIG.compassTurtleRadius.get(); - if (x > maxRange || y > maxRange || z > maxRange) { + final int maxDist = APConfig.PERIPHERALS_CONFIG.compassTurtleRadius.get(); + final int freeDist = APConfig.PERIPHERALS_CONFIG.compassTurtleFreeRadius.get(); + if (Math.abs(x) > maxDist || Math.abs(y) > maxDist || Math.abs(z) > maxDist) { return MethodResult.of(false, "OUT_OF_RANGE"); } String forward = TableHelper.optStringField(options, "forward", null); - String top = TableHelper.optStringField(options, "top", null) - Direction forwardDir, topDir; + String top = TableHelper.optStringField(options, "top", null); + Direction forwardDir = null, topDir = null; if (forward != null && (forwardDir = Direction.byName(forward.toLowerCase())) == null) { throw new LuaException(forward + "is not a valid direction"); } @@ -70,16 +88,32 @@ public MethodResult place(Map options) throws LuaException { throw new LuaException(top + "is not a valid direction"); } - ITurtleAccess turtle = owner.getTurtle(); - ItemStack stack = turtle.getInventory().getItem(turtle.getSelectedSlot()); - if (stack.isEmpty()) { - return MethodResult.of(false, "EMPTY_SLOT"); - } - BlockPos position = turtle.getPosition().offset(x, y, z); - return deployOn(stack, position, forwardDir, topDir, options); + // variable must be final to be used in lambda + final Direction forwardDirF = forwardDir, topDirF = topDir; + int distance = + Math.max(0, Math.abs(x) - freeDist) + + Math.max(0, Math.abs(y) - freeDist) + + Math.max(0, Math.abs(z) - freeDist); + return withOperation(ACCURE_PLACE, new SingleOperationContext(1, distance), null, context -> { + ITurtleAccess turtle = owner.getTurtle(); + ItemStack stack = turtle.getInventory().getItem(turtle.getSelectedSlot()); + if (stack.isEmpty()) { + return MethodResult.of(false, "EMPTY_SLOT"); + } + BlockPos position = turtle.getPosition().offset(x, y, z); + String err = deployOn(stack, position, forwardDirF, topDirF, options); + if (err != null) { + return MethodResult.of(false, err); + } + return MethodResult.of(true); + }, null, null); } - private MethodResult deployOn(ItemStack stack, BlockPos position, Direction forward, Direction top, Map options) throws LuaException { + /** + * @return A nullable string of the error. null means the operation is successful + */ + @Nullable + private String deployOn(ItemStack stack, BlockPos position, Direction forward, Direction top, Map options) throws LuaException { ITurtleAccess turtle = owner.getTurtle(); Level world = turtle.getLevel(); if (forward == null) { @@ -93,16 +127,39 @@ private MethodResult deployOn(ItemStack stack, BlockPos position, Direction forw DirectionalPlaceContext context = new DirectionalPlaceContext(world, position, forward, stack, top); PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock(turtlePlayer, InteractionHand.MAIN_HAND, position, hit); if (event.isCanceled()) { - return MethodResult.of(false, "EVENT_CANCELED"); + return "EVENT_CANCELED"; + } + Item item = stack.getItem(); + if (!(item instanceof BlockItem)) { + return "NOT_BLOCK"; + } + BlockItem block = (BlockItem) item; + InteractionResult res = block.place(context); + if (!res.consumesAction()) { + return "CANNOT_PLACE"; + } + if (block instanceof SignItem) { + BlockEntity blockEntity = world.getBlockEntity(position); + if (blockEntity instanceof SignBlockEntity sign) { + String text = StringUtil.convertAndToSectionMark(TableHelper.optStringField(options, "text", null)); + setSignText(world, sign, text); + } } - if (stack.getItem() instanceof BlockItem block) { - InteractionResult res = block.place(context); - if (!res.consumesAction()) { - return MethodResult.of(false, "CANNOT_PLACE"); + return null; + } + + private static void setSignText(Level world, SignBlockEntity sign, String text) { + if (text == null) { + for (int i = 0; i < SignBlockEntity.LINES; i++) { + sign.setMessage(i, Component.literal("")); } } else { - return MethodResult.of(false, "NOT_BLOCK"); + String[] lines = text.split("\n"); + for (int i = 0; i < SignBlockEntity.LINES; i++) { + sign.setMessage(i, Component.literal(i < lines.length ? lines[i] : "")); + } } - return MethodResult.of(true); + sign.setChanged(); + world.sendBlockUpdated(sign.getBlockPos(), sign.getBlockState(), sign.getBlockState(), Block.UPDATE_ALL); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java index 398b75a06..f64b79560 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java @@ -71,6 +71,7 @@ public class PeripheralsConfig implements IAPConfig { // Compass turtle public final ForgeConfigSpec.BooleanValue enableCompassTurtle; public final ForgeConfigSpec.IntValue compassTurtleRadius; + public final ForgeConfigSpec.IntValue compassTurtleFreeRadius; // Powered Peripherals public final ForgeConfigSpec.BooleanValue enablePoweredPeripherals; @@ -157,7 +158,8 @@ public PeripheralsConfig() { pop("Compass_Turtle", builder); enableCompassTurtle = builder.comment("Enable the compass turtle or not.").define("enableCompassTurtle", true); - compassTurtleRadius = builder.comment("The maximum distance the compass turtle can reach in each axis.").defineInRange("compassTurtleRadius", 1, 0, 8); + compassTurtleRadius = builder.comment("The maximum distance the compass turtle can reach in each axis.").defineInRange("compassTurtleRadius", 3, 0, 8); + compassTurtleFreeRadius = builder.comment("The free distance the compass turtle can reach in each axis.").defineInRange("compassTurtleFreeRadius", 1, 0, 4); pop("Powered_Peripherals", builder); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/StringUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/StringUtil.java index bc586425d..51031bf4e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/StringUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/StringUtil.java @@ -12,4 +12,23 @@ public static String toHexString(byte[] bytes) { } return new String(hexChars); } + + /** + * This method will convert "&[0-9a-z]" to "§[0-9a-z]", then we can make colored message in CC easier + * If a '&' is behind reverse slash '\', it will be ignored. + * Note: In CC, you need to use "\\&" to get an unescaped '&' character + * If the character after '&' is not a digital number or lowercase letter, the & operator will not be escaped as well. + * + * Some convert example: + * "&a" -> "§a" + * "&" -> "&" + * "\\&" -> "&" + * "\\&a" -> "&a" + * "&A" -> "&A" + * "& a" -> "& a" + * "&&a" -> "&§a" + */ + public static String convertAndToSectionMark(String str) { + return str == null ? null : str.replaceAll("(? Date: Wed, 24 Apr 2024 21:52:15 -0600 Subject: [PATCH 133/228] add wall operation --- .../peripheral/CompassPeripheral.java | 51 +++++++++++++++---- .../common/util/StringUtil.java | 2 +- 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java index 5020b44c0..c13447757 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java @@ -58,17 +58,17 @@ public String getFacing() { return owner.getFacing().toString(); } - @LuaFunction(mainThread = true) /** - * * @param options A table contains how to place the block: * x: the x offset relative to the turtle. Default 0 * y: the y offset relative to the turtle. Default 0 * z: the z offset relative to the turtle. Default 0 * forward: the direction the block is going to facing. Default is the facing direction of the turtle * top: the direction the block's top is going to facing. Default is TOP + * wall: the direction the block is going to hanging on. Default is same as forward * text: the text going to write on the sign. Default is null */ + @LuaFunction(mainThread = true) public MethodResult place(Map options) throws LuaException { int x = TableHelper.optIntField(options, "x", 0); int y = TableHelper.optIntField(options, "y", 0); @@ -78,18 +78,22 @@ public MethodResult place(Map options) throws LuaException { if (Math.abs(x) > maxDist || Math.abs(y) > maxDist || Math.abs(z) > maxDist) { return MethodResult.of(false, "OUT_OF_RANGE"); } + String wall = TableHelper.optStringField(options, "wall", null); String forward = TableHelper.optStringField(options, "forward", null); String top = TableHelper.optStringField(options, "top", null); - Direction forwardDir = null, topDir = null; + Direction wallDir = null, forwardDir = null, topDir = null; + if (wall != null && (wallDir = Direction.byName(wall.toLowerCase())) == null) { + throw new LuaException(wall + " is not a valid direction"); + } if (forward != null && (forwardDir = Direction.byName(forward.toLowerCase())) == null) { - throw new LuaException(forward + "is not a valid direction"); + throw new LuaException(forward + " is not a valid direction"); } if (top != null && (topDir = Direction.byName(top.toLowerCase())) == null) { - throw new LuaException(top + "is not a valid direction"); + throw new LuaException(top + " is not a valid direction"); } // variable must be final to be used in lambda - final Direction forwardDirF = forwardDir, topDirF = topDir; + final Direction wallDirF = wallDir, forwardDirF = forwardDir, topDirF = topDir; int distance = Math.max(0, Math.abs(x) - freeDist) + Math.max(0, Math.abs(y) - freeDist) + @@ -101,7 +105,7 @@ public MethodResult place(Map options) throws LuaException { return MethodResult.of(false, "EMPTY_SLOT"); } BlockPos position = turtle.getPosition().offset(x, y, z); - String err = deployOn(stack, position, forwardDirF, topDirF, options); + String err = deployOn(stack, position, wallDirF, forwardDirF, topDirF, options); if (err != null) { return MethodResult.of(false, err); } @@ -113,7 +117,7 @@ public MethodResult place(Map options) throws LuaException { * @return A nullable string of the error. null means the operation is successful */ @Nullable - private String deployOn(ItemStack stack, BlockPos position, Direction forward, Direction top, Map options) throws LuaException { + private String deployOn(ItemStack stack, BlockPos position, Direction wall, Direction forward, Direction top, Map options) throws LuaException { ITurtleAccess turtle = owner.getTurtle(); Level world = turtle.getLevel(); if (forward == null) { @@ -122,9 +126,12 @@ private String deployOn(ItemStack stack, BlockPos position, Direction forward, D if (top == null) { top = Direction.UP; } + if (wall == null) { + wall = forward; + } TurtlePlayer turtlePlayer = TurtlePlayer.getWithPosition(turtle, position, forward.getOpposite()); BlockHitResult hit = BlockHitResult.miss(Vec3.atCenterOf(position), top, position); - DirectionalPlaceContext context = new DirectionalPlaceContext(world, position, forward, stack, top); + AdvanceDirectionalPlaceContext context = new AdvanceDirectionalPlaceContext(world, position, wall, forward, stack, top); PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock(turtlePlayer, InteractionHand.MAIN_HAND, position, hit); if (event.isCanceled()) { return "EVENT_CANCELED"; @@ -163,3 +170,29 @@ private static void setSignText(Level world, SignBlockEntity sign, String text) world.sendBlockUpdated(sign.getBlockPos(), sign.getBlockState(), sign.getBlockState(), Block.UPDATE_ALL); } } + +class AdvanceDirectionalPlaceContext extends DirectionalPlaceContext { + private final Direction wall; + + public AdvanceDirectionalPlaceContext(Level world, BlockPos pos, Direction wall, Direction forward, ItemStack stack, Direction top) { + super(world, pos, forward, stack, top); + this.wall = wall; + } + + @Override + public Direction getNearestLookingDirection() { + return this.wall; + } + + @Override + public Direction[] getNearestLookingDirections() { + return switch (this.wall) { + case DOWN -> new Direction[]{Direction.DOWN, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST, Direction.UP}; + case UP -> new Direction[]{Direction.UP, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST, Direction.DOWN}; + case NORTH -> new Direction[]{Direction.NORTH, Direction.EAST, Direction.WEST, Direction.UP, Direction.DOWN, Direction.SOUTH}; + case SOUTH -> new Direction[]{Direction.SOUTH, Direction.EAST, Direction.WEST, Direction.UP, Direction.DOWN, Direction.NORTH}; + case WEST -> new Direction[]{Direction.WEST, Direction.SOUTH, Direction.UP, Direction.NORTH, Direction.DOWN, Direction.EAST}; + case EAST -> new Direction[]{Direction.EAST, Direction.SOUTH, Direction.UP, Direction.NORTH, Direction.DOWN, Direction.WEST}; + }; + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/StringUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/StringUtil.java index 51031bf4e..f166eda25 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/StringUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/StringUtil.java @@ -18,7 +18,7 @@ public static String toHexString(byte[] bytes) { * If a '&' is behind reverse slash '\', it will be ignored. * Note: In CC, you need to use "\\&" to get an unescaped '&' character * If the character after '&' is not a digital number or lowercase letter, the & operator will not be escaped as well. - * + * * Some convert example: * "&a" -> "§a" * "&" -> "&" From bb6f385cfb76e5efe693630e5827d71a5025d45e Mon Sep 17 00:00:00 2001 From: zyxkad Date: Wed, 24 Apr 2024 21:56:10 -0600 Subject: [PATCH 134/228] rename argument wall -> anchor --- .../peripheral/CompassPeripheral.java | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java index c13447757..e035d4d12 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java @@ -65,7 +65,7 @@ public String getFacing() { * z: the z offset relative to the turtle. Default 0 * forward: the direction the block is going to facing. Default is the facing direction of the turtle * top: the direction the block's top is going to facing. Default is TOP - * wall: the direction the block is going to hanging on. Default is same as forward + * anchor: the direction the block is going to hanging on. Default is same as forward * text: the text going to write on the sign. Default is null */ @LuaFunction(mainThread = true) @@ -78,12 +78,12 @@ public MethodResult place(Map options) throws LuaException { if (Math.abs(x) > maxDist || Math.abs(y) > maxDist || Math.abs(z) > maxDist) { return MethodResult.of(false, "OUT_OF_RANGE"); } - String wall = TableHelper.optStringField(options, "wall", null); + String anchor = TableHelper.optStringField(options, "anchor", null); String forward = TableHelper.optStringField(options, "forward", null); String top = TableHelper.optStringField(options, "top", null); - Direction wallDir = null, forwardDir = null, topDir = null; - if (wall != null && (wallDir = Direction.byName(wall.toLowerCase())) == null) { - throw new LuaException(wall + " is not a valid direction"); + Direction anchorDir = null, forwardDir = null, topDir = null; + if (anchor != null && (anchorDir = Direction.byName(anchor.toLowerCase())) == null) { + throw new LuaException(anchor + " is not a valid direction"); } if (forward != null && (forwardDir = Direction.byName(forward.toLowerCase())) == null) { throw new LuaException(forward + " is not a valid direction"); @@ -93,7 +93,7 @@ public MethodResult place(Map options) throws LuaException { } // variable must be final to be used in lambda - final Direction wallDirF = wallDir, forwardDirF = forwardDir, topDirF = topDir; + final Direction anchorDirF = anchorDir, forwardDirF = forwardDir, topDirF = topDir; int distance = Math.max(0, Math.abs(x) - freeDist) + Math.max(0, Math.abs(y) - freeDist) + @@ -105,7 +105,7 @@ public MethodResult place(Map options) throws LuaException { return MethodResult.of(false, "EMPTY_SLOT"); } BlockPos position = turtle.getPosition().offset(x, y, z); - String err = deployOn(stack, position, wallDirF, forwardDirF, topDirF, options); + String err = deployOn(stack, position, anchorDirF, forwardDirF, topDirF, options); if (err != null) { return MethodResult.of(false, err); } @@ -117,7 +117,7 @@ public MethodResult place(Map options) throws LuaException { * @return A nullable string of the error. null means the operation is successful */ @Nullable - private String deployOn(ItemStack stack, BlockPos position, Direction wall, Direction forward, Direction top, Map options) throws LuaException { + private String deployOn(ItemStack stack, BlockPos position, Direction anchor, Direction forward, Direction top, Map options) throws LuaException { ITurtleAccess turtle = owner.getTurtle(); Level world = turtle.getLevel(); if (forward == null) { @@ -126,12 +126,12 @@ private String deployOn(ItemStack stack, BlockPos position, Direction wall, Dire if (top == null) { top = Direction.UP; } - if (wall == null) { - wall = forward; + if (anchor == null) { + anchor = forward; } TurtlePlayer turtlePlayer = TurtlePlayer.getWithPosition(turtle, position, forward.getOpposite()); BlockHitResult hit = BlockHitResult.miss(Vec3.atCenterOf(position), top, position); - AdvanceDirectionalPlaceContext context = new AdvanceDirectionalPlaceContext(world, position, wall, forward, stack, top); + AdvanceDirectionalPlaceContext context = new AdvanceDirectionalPlaceContext(world, position, anchor, forward, stack, top); PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock(turtlePlayer, InteractionHand.MAIN_HAND, position, hit); if (event.isCanceled()) { return "EVENT_CANCELED"; @@ -172,21 +172,21 @@ private static void setSignText(Level world, SignBlockEntity sign, String text) } class AdvanceDirectionalPlaceContext extends DirectionalPlaceContext { - private final Direction wall; + private final Direction anchor; - public AdvanceDirectionalPlaceContext(Level world, BlockPos pos, Direction wall, Direction forward, ItemStack stack, Direction top) { + public AdvanceDirectionalPlaceContext(Level world, BlockPos pos, Direction anchor, Direction forward, ItemStack stack, Direction top) { super(world, pos, forward, stack, top); - this.wall = wall; + this.anchor = anchor; } @Override public Direction getNearestLookingDirection() { - return this.wall; + return this.anchor; } @Override public Direction[] getNearestLookingDirections() { - return switch (this.wall) { + return switch (this.anchor) { case DOWN -> new Direction[]{Direction.DOWN, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST, Direction.UP}; case UP -> new Direction[]{Direction.UP, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST, Direction.DOWN}; case NORTH -> new Direction[]{Direction.NORTH, Direction.EAST, Direction.WEST, Direction.UP, Direction.DOWN, Direction.SOUTH}; From 3dc0f4acdd53dc44d240eb08363fa197524e1b2a Mon Sep 17 00:00:00 2001 From: zyxkad Date: Wed, 24 Apr 2024 22:02:22 -0600 Subject: [PATCH 135/228] fix stylecheck --- .../peripheral/CompassPeripheral.java | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java index e035d4d12..3eed26eec 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java @@ -169,30 +169,30 @@ private static void setSignText(Level world, SignBlockEntity sign, String text) sign.setChanged(); world.sendBlockUpdated(sign.getBlockPos(), sign.getBlockState(), sign.getBlockState(), Block.UPDATE_ALL); } -} -class AdvanceDirectionalPlaceContext extends DirectionalPlaceContext { - private final Direction anchor; + private class AdvanceDirectionalPlaceContext extends DirectionalPlaceContext { + private final Direction anchor; - public AdvanceDirectionalPlaceContext(Level world, BlockPos pos, Direction anchor, Direction forward, ItemStack stack, Direction top) { - super(world, pos, forward, stack, top); - this.anchor = anchor; - } + AdvanceDirectionalPlaceContext(Level world, BlockPos pos, Direction anchor, Direction forward, ItemStack stack, Direction top) { + super(world, pos, forward, stack, top); + this.anchor = anchor; + } - @Override - public Direction getNearestLookingDirection() { - return this.anchor; - } + @Override + public Direction getNearestLookingDirection() { + return this.anchor; + } - @Override - public Direction[] getNearestLookingDirections() { - return switch (this.anchor) { - case DOWN -> new Direction[]{Direction.DOWN, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST, Direction.UP}; - case UP -> new Direction[]{Direction.UP, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST, Direction.DOWN}; - case NORTH -> new Direction[]{Direction.NORTH, Direction.EAST, Direction.WEST, Direction.UP, Direction.DOWN, Direction.SOUTH}; - case SOUTH -> new Direction[]{Direction.SOUTH, Direction.EAST, Direction.WEST, Direction.UP, Direction.DOWN, Direction.NORTH}; - case WEST -> new Direction[]{Direction.WEST, Direction.SOUTH, Direction.UP, Direction.NORTH, Direction.DOWN, Direction.EAST}; - case EAST -> new Direction[]{Direction.EAST, Direction.SOUTH, Direction.UP, Direction.NORTH, Direction.DOWN, Direction.WEST}; - }; + @Override + public Direction[] getNearestLookingDirections() { + return switch (this.anchor) { + case DOWN -> new Direction[]{Direction.DOWN, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST, Direction.UP}; + case UP -> new Direction[]{Direction.UP, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST, Direction.DOWN}; + case NORTH -> new Direction[]{Direction.NORTH, Direction.EAST, Direction.WEST, Direction.UP, Direction.DOWN, Direction.SOUTH}; + case SOUTH -> new Direction[]{Direction.SOUTH, Direction.EAST, Direction.WEST, Direction.UP, Direction.DOWN, Direction.NORTH}; + case WEST -> new Direction[]{Direction.WEST, Direction.SOUTH, Direction.UP, Direction.NORTH, Direction.DOWN, Direction.EAST}; + case EAST -> new Direction[]{Direction.EAST, Direction.SOUTH, Direction.UP, Direction.NORTH, Direction.DOWN, Direction.WEST}; + }; + } } } From 0dd82f8d9638c0a8108783778fb1bbf8584aa314 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Thu, 25 Apr 2024 08:06:25 -0600 Subject: [PATCH 136/228] use nil instead of false --- .../addons/computercraft/peripheral/CompassPeripheral.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java index 3eed26eec..9415f1c5f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java @@ -76,7 +76,7 @@ public MethodResult place(Map options) throws LuaException { final int maxDist = APConfig.PERIPHERALS_CONFIG.compassTurtleRadius.get(); final int freeDist = APConfig.PERIPHERALS_CONFIG.compassTurtleFreeRadius.get(); if (Math.abs(x) > maxDist || Math.abs(y) > maxDist || Math.abs(z) > maxDist) { - return MethodResult.of(false, "OUT_OF_RANGE"); + return MethodResult.of(null, "OUT_OF_RANGE"); } String anchor = TableHelper.optStringField(options, "anchor", null); String forward = TableHelper.optStringField(options, "forward", null); @@ -102,12 +102,12 @@ public MethodResult place(Map options) throws LuaException { ITurtleAccess turtle = owner.getTurtle(); ItemStack stack = turtle.getInventory().getItem(turtle.getSelectedSlot()); if (stack.isEmpty()) { - return MethodResult.of(false, "EMPTY_SLOT"); + return MethodResult.of(null, "EMPTY_SLOT"); } BlockPos position = turtle.getPosition().offset(x, y, z); String err = deployOn(stack, position, anchorDirF, forwardDirF, topDirF, options); if (err != null) { - return MethodResult.of(false, err); + return MethodResult.of(null, err); } return MethodResult.of(true); }, null, null); From 7acb7768a6243a8b8191073370f5c80573cab1e1 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Thu, 25 Apr 2024 11:24:41 -0600 Subject: [PATCH 137/228] use validateSide instaed of Direction.byName --- .../peripheral/CompassPeripheral.java | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java index 9415f1c5f..8e19bb491 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java @@ -81,19 +81,10 @@ public MethodResult place(Map options) throws LuaException { String anchor = TableHelper.optStringField(options, "anchor", null); String forward = TableHelper.optStringField(options, "forward", null); String top = TableHelper.optStringField(options, "top", null); - Direction anchorDir = null, forwardDir = null, topDir = null; - if (anchor != null && (anchorDir = Direction.byName(anchor.toLowerCase())) == null) { - throw new LuaException(anchor + " is not a valid direction"); - } - if (forward != null && (forwardDir = Direction.byName(forward.toLowerCase())) == null) { - throw new LuaException(forward + " is not a valid direction"); - } - if (top != null && (topDir = Direction.byName(top.toLowerCase())) == null) { - throw new LuaException(top + " is not a valid direction"); - } + Direction anchorDir = anchor != null ? validateSide(anchor) : null; + Direction forwardDir = forward != null ? validateSide(forward) : null; + Direction topDir = top != null ? validateSide(top) : null; - // variable must be final to be used in lambda - final Direction anchorDirF = anchorDir, forwardDirF = forwardDir, topDirF = topDir; int distance = Math.max(0, Math.abs(x) - freeDist) + Math.max(0, Math.abs(y) - freeDist) + @@ -105,7 +96,7 @@ public MethodResult place(Map options) throws LuaException { return MethodResult.of(null, "EMPTY_SLOT"); } BlockPos position = turtle.getPosition().offset(x, y, z); - String err = deployOn(stack, position, anchorDirF, forwardDirF, topDirF, options); + String err = deployOn(stack, position, anchorDir, forwardDir, topDir, options); if (err != null) { return MethodResult.of(null, err); } From fc3520329bb138dd6e2988ee467c4be9afcba323 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Thu, 25 Apr 2024 15:37:23 -0600 Subject: [PATCH 138/228] call livingEntityToLua but not entityToLua when serializing animal fix #592 --- .../de/srendi/advancedperipherals/common/util/LuaConverter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java b/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java index 40741dcb9..5bef952ad 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java @@ -47,7 +47,7 @@ public static Map livingEntityToLua(LivingEntity entity) { } public static Map animalToLua(Animal animal, ItemStack itemInHand) { - Map data = entityToLua(animal); + Map data = livingEntityToLua(animal); data.put("baby", animal.isBaby()); data.put("inLove", animal.isInLove()); data.put("aggressive", animal.isAggressive()); From b735bde5eca5dd6c6c2fea1115509d4794219293 Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 26 Apr 2024 14:50:45 +0200 Subject: [PATCH 139/228] Implement `cancelCraftingTasks` for the ME Bridge --- gradle.properties | 2 +- .../peripheral/MeBridgePeripheral.java | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/gradle.properties b/gradle.properties index 978f3d0c5..bb8f4e723 100644 --- a/gradle.properties +++ b/gradle.properties @@ -24,7 +24,7 @@ ttoolkit_version=0.1.3 cc_version=1.101.3 curios_version=1.19.2-5.1.4.1 minecolonies_version=1.19.2-1.1.473-BETA -appliedenergistics_version=12.9.8 +appliedenergistics_version=12.9.9 patchouli_version=1.19.2-77 refinedstorage_version=1.11.7 botania_version=1.19.2-440-FORGE diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java index 4ff64fa4b..7eb22d097 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java @@ -8,6 +8,7 @@ import appeng.api.stacks.AEFluidKey; import appeng.api.stacks.AEItemKey; import appeng.api.storage.MEStorage; +import appeng.me.cluster.implementations.CraftingCPUCluster; import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaFunction; @@ -598,6 +599,7 @@ public final MethodResult craftFluid(IComputerAccess computer, IArguments argume } @Override + @LuaFunction(mainThread = true) public MethodResult getCraftingTasks() { if (!isAvailable()) return notConnected(); @@ -614,7 +616,8 @@ public MethodResult getCraftingTasks() { } @Override - public MethodResult cancelCraftingTasks(IArguments arguments) throws LuaException { + @LuaFunction(mainThread = true) + public MethodResult cancelCraftingTasks(IArguments arguments) { if (!isAvailable()) return notConnected(); @@ -634,14 +637,16 @@ public MethodResult cancelCraftingTasks(IArguments arguments) throws LuaExceptio if (filter.getRight() != null) return MethodResult.of(null, filter.getRight()); - //TODO: See https://github.com/AppliedEnergistics/Applied-Energistics-2/issues/7560 - /* + int jobsCanceled = 0; for (ICraftingCPU cpu : craftingGrid.getCpus()) { - if (cpu.getJobStatus() != null) { + if (cpu.getJobStatus() != null && filter.getLeft().test(cpu.getJobStatus().crafting())) { + if (cpu instanceof CraftingCPUCluster cpuCluster) { + cpuCluster.cancel(); + jobsCanceled++; + } } } - */ - return null; + return MethodResult.of(jobsCanceled, "SUCCESSFUL"); } @Override From 8116c68e7aefde2926ccfd572f95b9870b006adb Mon Sep 17 00:00:00 2001 From: zyxkad Date: Fri, 26 Apr 2024 12:51:48 -0600 Subject: [PATCH 140/228] add pitch & yaw argument to automata core close IntelligenceModding/Advanced-Peripherals-Features#43 fix #419 --- .../plugins/AutomataBlockHandPlugin.java | 19 ++++-- .../common/util/fakeplayer/APFakePlayer.java | 60 ++++++++++++++++++- .../fakeplayer/FakePlayerProviderTurtle.java | 12 +--- 3 files changed, 75 insertions(+), 16 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java index f4022a219..d3c3fb4c0 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java @@ -1,8 +1,10 @@ package de.srendi.advancedperipherals.common.addons.computercraft.peripheral.plugins; +import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.lua.MethodResult; +import dan200.computercraft.core.apis.TableHelper; import de.srendi.advancedperipherals.common.addons.computercraft.owner.TurtlePeripheralOwner; import de.srendi.advancedperipherals.common.util.Pair; import de.srendi.advancedperipherals.common.util.fakeplayer.APFakePlayer; @@ -10,8 +12,11 @@ import de.srendi.advancedperipherals.lib.peripherals.IPeripheralOperation; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Map; + import static de.srendi.advancedperipherals.common.addons.computercraft.operations.SingleOperation.DIG; import static de.srendi.advancedperipherals.common.addons.computercraft.operations.SingleOperation.USE_ON_BLOCK; @@ -27,12 +32,15 @@ public AutomataBlockHandPlugin(AutomataCorePeripheral automataCore) { } @LuaFunction(mainThread = true) - public final MethodResult digBlock() throws LuaException { + public final MethodResult digBlock(@NotNull IArguments arguments) throws LuaException { + Map opts = arguments.count() > 0 ? arguments.getTable(0) : null; + float yaw = opts != null ? (float) TableHelper.optNumberField(opts, "yaw", 0) : 0; + float pitch = opts != null ? (float) TableHelper.optNumberField(opts, "pitch", 0) : 0; return automataCore.withOperation(DIG, context -> { TurtlePeripheralOwner owner = automataCore.getPeripheralOwner(); ItemStack selectedTool = owner.getToolInMainHand(); int previousDamageValue = selectedTool.getDamageValue(); - Pair result = owner.withPlayer(apFakePlayer -> apFakePlayer.digBlock(owner.getFacing().getOpposite())); + Pair result = owner.withPlayer(apFakePlayer -> apFakePlayer.digBlock(yaw, pitch)); if (!result.getLeft()) { return MethodResult.of(null, result.getRight()); } @@ -43,12 +51,15 @@ public final MethodResult digBlock() throws LuaException { } @LuaFunction(mainThread = true) - public final MethodResult useOnBlock() throws LuaException { + public final MethodResult useOnBlock(@NotNull IArguments arguments) throws LuaException { + Map opts = arguments.count() > 0 ? arguments.getTable(0) : null; + float yaw = opts != null ? (float) TableHelper.optNumberField(opts, "yaw", 0) : 0; + float pitch = opts != null ? (float) TableHelper.optNumberField(opts, "pitch", 0) : 0; return automataCore.withOperation(USE_ON_BLOCK, context -> { TurtlePeripheralOwner owner = automataCore.getPeripheralOwner(); ItemStack selectedTool = owner.getToolInMainHand(); int previousDamageValue = selectedTool.getDamageValue(); - InteractionResult result = owner.withPlayer(APFakePlayer::useOnBlock); + InteractionResult result = owner.withPlayer(apFakePlayer -> apFakePlayer.useOnBlock(yaw, pitch)); if (automataCore.hasAttribute(AutomataCorePeripheral.ATTR_STORING_TOOL_DURABILITY)) selectedTool.setDamageValue(previousDamageValue); return MethodResult.of(true, result.toString()); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java index aa804874c..a0176a166 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java @@ -119,7 +119,30 @@ public float getEyeHeight(@NotNull Pose pose) { return 0; } + @Deprecated(forRemoval = true) public Pair digBlock(Direction direction) { + return digBlock(direction.toYRot() - this.getYRot(), direction == Direction.DOWN ? 90 : direction == Direction.UP ? -90 : 0); + } + + public Pair digBlock() { + return digBlock(0, 0); + } + + /** + * @param yaw The Y axis rotation relative to turtle's heading + * @param pitch The pitch + */ + public Pair digBlock(float yaw, float pitch) { + final float oldRot = this.getYRot(); + this.setRot((oldRot + yaw % 360 + 360) % 360, pitch % 360); + try { + return this.digBlockAction(); + } finally { + this.setRot(oldRot, 0); + } + } + + private Pair digBlockAction() { Level world = getLevel(); HitResult hit = findHit(true, false); if (hit.getType() == HitResult.Type.MISS) @@ -137,6 +160,9 @@ public Pair digBlock(Direction direction) { if (block != digBlock || !pos.equals(digPosition)) setState(block, pos); + Vec3 look = getLookAngle(); + Direction direction = Direction.getNearest(look.x, look.y, look.z).getOpposite(); + if (!world.isEmptyBlock(pos) && !state.getMaterial().isLiquid()) { if (block == Blocks.BEDROCK || state.getDestroySpeed(world, pos) <= -1) return Pair.of(false, "Unbreakable block detected"); @@ -159,7 +185,7 @@ public Pair digBlock(Direction direction) { if (currentDamage > 9) { world.playSound(null, pos, state.getSoundType().getHitSound(), SoundSource.NEUTRAL, .25f, 1); - manager.handleBlockBreakAction(pos, ServerboundPlayerActionPacket.Action.STOP_DESTROY_BLOCK, direction.getOpposite(), 320, 1); + manager.handleBlockBreakAction(pos, ServerboundPlayerActionPacket.Action.STOP_DESTROY_BLOCK, direction, 320, 1); manager.destroyBlock(pos); world.destroyBlockProgress(getId(), pos, -1); setState(null, null); @@ -177,14 +203,26 @@ public InteractionResult useOnBlock() { return use(true, false); } + public InteractionResult useOnBlock(float yaw, float pitch) { + return use(true, false, yaw, pitch); + } + public InteractionResult useOnEntity() { return use(false, true); } + public InteractionResult useOnEntity(float yaw, float pitch) { + return use(false, true, yaw, pitch); + } + public InteractionResult useOnFilteredEntity(Predicate filter) { return use(false, true, filter); } + public InteractionResult useOnFilteredEntity(Predicate filter, float yaw, float pitch) { + return use(false, true, filter, yaw, pitch); + } + public InteractionResult useOnSpecificEntity(@NotNull Entity entity, HitResult result) { InteractionResult simpleInteraction = interactOn(entity, InteractionHand.MAIN_HAND); if (simpleInteraction == InteractionResult.SUCCESS) return simpleInteraction; @@ -198,7 +236,25 @@ public InteractionResult use(boolean skipEntity, boolean skipBlock) { return use(skipEntity, skipBlock, null); } + public InteractionResult use(boolean skipEntity, boolean skipBlock, float yaw, float pitch) { + return use(skipEntity, skipBlock, null, yaw, pitch); + } + public InteractionResult use(boolean skipEntity, boolean skipBlock, @Nullable Predicate entityFilter) { + return use(skipEntity, skipBlock, entityFilter, 0, 0); + } + + public InteractionResult use(boolean skipEntity, boolean skipBlock, @Nullable Predicate entityFilter, float yaw, float pitch) { + final float oldRot = this.getYRot(); + this.setRot((oldRot + yaw % 360 + 360) % 360, pitch % 360); + try { + return this.useAction(skipEntity, skipBlock, entityFilter); + } finally { + this.setRot(oldRot, 0); + } + } + + private InteractionResult useAction(boolean skipEntity, boolean skipBlock, @Nullable Predicate entityFilter) { HitResult hit = findHit(skipEntity, skipBlock, entityFilter); if (hit instanceof BlockHitResult blockHit) { @@ -269,7 +325,7 @@ public HitResult findHit(boolean skipEntity, boolean skipBlock, @Nullable Predic blockHit = BlockHitResult.miss(traceContext.getTo(), traceDirection, new BlockPos(traceContext.getTo())); } else { blockHit = BlockGetter.traverseBlocks(traceContext.getFrom(), traceContext.getTo(), traceContext, (rayTraceContext, blockPos) -> { - if (level.isEmptyBlock(blockPos)) { + if (level.isEmptyBlock(blockPos) || blockPos.equals(blockPosition())) { return null; } return new BlockHitResult(new Vec3(blockPos.getX(), blockPos.getY(), blockPos.getZ()), traceDirection, blockPos, false); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/FakePlayerProviderTurtle.java b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/FakePlayerProviderTurtle.java index f4719552a..f19bc7322 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/FakePlayerProviderTurtle.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/FakePlayerProviderTurtle.java @@ -35,17 +35,9 @@ public static APFakePlayer getPlayer(ITurtleAccess turtle, GameProfile profile) public static void load(APFakePlayer player, ITurtleAccess turtle) { Direction direction = turtle.getDirection(); player.setLevel((ServerLevel) turtle.getLevel()); - BlockPos position = turtle.getPosition(); // Player position - float pitch = direction == Direction.UP ? -90 : direction == Direction.DOWN ? 90 : 0; - float yaw = direction == Direction.SOUTH ? 0 : direction == Direction.WEST ? 90 : direction == Direction.NORTH ? 180 : -90; - Vec3i sideVec = direction.getNormal(); - Direction.Axis a = direction.getAxis(); - Direction.AxisDirection ad = direction.getAxisDirection(); - double x = a == Direction.Axis.X && ad == Direction.AxisDirection.NEGATIVE ? -.5 : .5 + sideVec.getX() / 1.9D; - double y = 0.5 + sideVec.getY() / 1.9D; - double z = a == Direction.Axis.Z && ad == Direction.AxisDirection.NEGATIVE ? -.5 : .5 + sideVec.getZ() / 1.9D; - player.moveTo(position.getX() + x, position.getY() + y, position.getZ() + z, yaw, pitch); + BlockPos position = turtle.getPosition(); + player.moveTo(position.getX() + 0.5, position.getY() + 0.5, position.getZ() + 0.5, direction.toYRot(), 0); // Player inventory Inventory playerInventory = player.getInventory(); playerInventory.selected = 0; From 6d7d52afed7cc667334201290cbdbd689d9c7e3a Mon Sep 17 00:00:00 2001 From: zyxkad Date: Fri, 26 Apr 2024 14:52:07 -0600 Subject: [PATCH 141/228] add player.doActionWithRot instead of writing ton of overload methods --- .../plugins/AutomataBlockHandPlugin.java | 4 +- .../plugins/AutomataEntityHandPlugin.java | 15 +++-- .../plugins/AutomataEntityTransferPlugin.java | 8 ++- .../plugins/AutomataLookPlugin.java | 16 ++++-- .../common/util/fakeplayer/APFakePlayer.java | 56 +++---------------- 5 files changed, 40 insertions(+), 59 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java index d3c3fb4c0..8ca3abe5c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java @@ -40,7 +40,7 @@ public final MethodResult digBlock(@NotNull IArguments arguments) throws LuaExce TurtlePeripheralOwner owner = automataCore.getPeripheralOwner(); ItemStack selectedTool = owner.getToolInMainHand(); int previousDamageValue = selectedTool.getDamageValue(); - Pair result = owner.withPlayer(apFakePlayer -> apFakePlayer.digBlock(yaw, pitch)); + Pair result = owner.withPlayer(apFakePlayer -> apFakePlayer.doActionWithRot(yaw, pitch, APFakePlayer::digBlock)); if (!result.getLeft()) { return MethodResult.of(null, result.getRight()); } @@ -59,7 +59,7 @@ public final MethodResult useOnBlock(@NotNull IArguments arguments) throws LuaEx TurtlePeripheralOwner owner = automataCore.getPeripheralOwner(); ItemStack selectedTool = owner.getToolInMainHand(); int previousDamageValue = selectedTool.getDamageValue(); - InteractionResult result = owner.withPlayer(apFakePlayer -> apFakePlayer.useOnBlock(yaw, pitch)); + InteractionResult result = owner.withPlayer(apFakePlayer -> apFakePlayer.doActionWithRot(yaw, pitch, APFakePlayer::useOnBlock)); if (automataCore.hasAttribute(AutomataCorePeripheral.ATTR_STORING_TOOL_DURABILITY)) selectedTool.setDamageValue(previousDamageValue); return MethodResult.of(true, result.toString()); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java index 1bc139df1..c0647b008 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java @@ -39,12 +39,15 @@ public AutomataEntityHandPlugin(AutomataCorePeripheral automataCore, Predicate opts = arguments.count() > 0 ? arguments.getTable(0) : null; + float yaw = opts != null ? (float) TableHelper.optNumberField(opts, "yaw", 0) : 0; + float pitch = opts != null ? (float) TableHelper.optNumberField(opts, "pitch", 0) : 0; return automataCore.withOperation(USE_ON_ANIMAL, context -> { TurtlePeripheralOwner owner = automataCore.getPeripheralOwner(); ItemStack selectedTool = owner.getToolInMainHand(); int previousDamageValue = selectedTool.getDamageValue(); - InteractionResult result = owner.withPlayer(player -> player.useOnFilteredEntity(suitableEntity)); + InteractionResult result = owner.withPlayer(player -> player.doActionWithRot(yaw, pitch, player -> player.useOnFilteredEntity(suitableEntity))); if (automataCore.hasAttribute(AutomataCorePeripheral.ATTR_STORING_TOOL_DURABILITY)) selectedTool.setDamageValue(previousDamageValue); @@ -53,10 +56,14 @@ public final MethodResult useOnAnimal() throws LuaException { } @LuaFunction(mainThread = true) - public final MethodResult inspectAnimal() { + public final MethodResult inspectAnimal(@NotNull IArguments arguments) throws LuaException { + Map opts = arguments.count() > 0 ? arguments.getTable(0) : null; + float yaw = opts != null ? (float) TableHelper.optNumberField(opts, "yaw", 0) : 0; + float pitch = opts != null ? (float) TableHelper.optNumberField(opts, "pitch", 0) : 0; + automataCore.addRotationCycle(); TurtlePeripheralOwner owner = automataCore.getPeripheralOwner(); - HitResult entityHit = owner.withPlayer(player -> player.findHit(false, true, suitableEntity)); + HitResult entityHit = owner.withPlayer(player -> player.doActionWithRot(yaw, pitch, player -> player.findHit(false, true, suitableEntity))); if (entityHit.getType() == HitResult.Type.MISS) return MethodResult.of(null, "Nothing found"); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityTransferPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityTransferPlugin.java index b99d53de3..0a955c868 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityTransferPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityTransferPlugin.java @@ -69,8 +69,12 @@ protected Entity extractEntity() { @LuaFunction(mainThread = true) - public final MethodResult captureAnimal() throws LuaException { - HitResult entityHit = automataCore.getPeripheralOwner().withPlayer(player -> player.findHit(false, true, suitableEntity)); + public final MethodResult captureAnimal(@NotNull IArguments arguments) throws LuaException { + Map opts = arguments.count() > 0 ? arguments.getTable(0) : null; + float yaw = opts != null ? (float) TableHelper.optNumberField(opts, "yaw", 0) : 0; + float pitch = opts != null ? (float) TableHelper.optNumberField(opts, "pitch", 0) : 0; + + HitResult entityHit = automataCore.getPeripheralOwner().withPlayer(player -> player.doActionWithRot(yaw, pitch, player -> player.findHit(false, true, suitableEntity))); if (entityHit.getType() == HitResult.Type.MISS) return MethodResult.of(null, "Nothing found"); return automataCore.withOperation(CAPTURE_ANIMAL, context -> { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataLookPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataLookPlugin.java index c79019c53..329108bf6 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataLookPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataLookPlugin.java @@ -22,10 +22,14 @@ public AutomataLookPlugin(AutomataCorePeripheral automataCore) { } @LuaFunction(mainThread = true) - public final MethodResult lookAtBlock() { + public final MethodResult lookAtBlock(@NotNull IArguments arguments) throws LuaException { + Map opts = arguments.count() > 0 ? arguments.getTable(0) : null; + float yaw = opts != null ? (float) TableHelper.optNumberField(opts, "yaw", 0) : 0; + float pitch = opts != null ? (float) TableHelper.optNumberField(opts, "pitch", 0) : 0; + automataCore.addRotationCycle(); TurtlePeripheralOwner owner = automataCore.getPeripheralOwner(); - HitResult result = owner.withPlayer(apFakePlayer -> apFakePlayer.findHit(true, false)); + HitResult result = owner.withPlayer(apFakePlayer -> apFakePlayer.doActionWithRot(yaw, pitch, apFakePlayer -> apFakePlayer.findHit(true, false))); if (result.getType() == HitResult.Type.MISS) return MethodResult.of(null, "No block find"); @@ -40,9 +44,13 @@ public final MethodResult lookAtBlock() { } @LuaFunction(mainThread = true) - public final MethodResult lookAtEntity() { + public final MethodResult lookAtEntity(@NotNull IArguments arguments) throws LuaException { + Map opts = arguments.count() > 0 ? arguments.getTable(0) : null; + float yaw = opts != null ? (float) TableHelper.optNumberField(opts, "yaw", 0) : 0; + float pitch = opts != null ? (float) TableHelper.optNumberField(opts, "pitch", 0) : 0; + automataCore.addRotationCycle(); - HitResult result = automataCore.getPeripheralOwner().withPlayer(apFakePlayer -> apFakePlayer.findHit(false, true)); + HitResult result = automataCore.getPeripheralOwner().withPlayer(apFakePlayer -> apFakePlayer.doActionWithRot(yaw, pitch, apFakePlayer -> apFakePlayer.findHit(false, true))); if (result.getType() == HitResult.Type.MISS) return MethodResult.of(null, "No entity find"); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java index a0176a166..d6af4968f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java @@ -119,30 +119,22 @@ public float getEyeHeight(@NotNull Pose pose) { return 0; } - @Deprecated(forRemoval = true) - public Pair digBlock(Direction direction) { - return digBlock(direction.toYRot() - this.getYRot(), direction == Direction.DOWN ? 90 : direction == Direction.UP ? -90 : 0); - } - - public Pair digBlock() { - return digBlock(0, 0); - } - - /** - * @param yaw The Y axis rotation relative to turtle's heading - * @param pitch The pitch - */ - public Pair digBlock(float yaw, float pitch) { + public T doActionWithRot(float yaw, float pitch, Function action) { final float oldRot = this.getYRot(); - this.setRot((oldRot + yaw % 360 + 360) % 360, pitch % 360); + this.setRot(oldRot + yaw, pitch); try { - return this.digBlockAction(); + return action.apply(this); } finally { this.setRot(oldRot, 0); } } - private Pair digBlockAction() { + @Deprecated(forRemoval = true) + public Pair digBlock(Direction direction) { + return digBlock(direction.toYRot() - this.getYRot(), direction == Direction.DOWN ? 90 : direction == Direction.UP ? -90 : 0); + } + + public Pair digBlock() { Level world = getLevel(); HitResult hit = findHit(true, false); if (hit.getType() == HitResult.Type.MISS) @@ -203,26 +195,14 @@ public InteractionResult useOnBlock() { return use(true, false); } - public InteractionResult useOnBlock(float yaw, float pitch) { - return use(true, false, yaw, pitch); - } - public InteractionResult useOnEntity() { return use(false, true); } - public InteractionResult useOnEntity(float yaw, float pitch) { - return use(false, true, yaw, pitch); - } - public InteractionResult useOnFilteredEntity(Predicate filter) { return use(false, true, filter); } - public InteractionResult useOnFilteredEntity(Predicate filter, float yaw, float pitch) { - return use(false, true, filter, yaw, pitch); - } - public InteractionResult useOnSpecificEntity(@NotNull Entity entity, HitResult result) { InteractionResult simpleInteraction = interactOn(entity, InteractionHand.MAIN_HAND); if (simpleInteraction == InteractionResult.SUCCESS) return simpleInteraction; @@ -236,25 +216,7 @@ public InteractionResult use(boolean skipEntity, boolean skipBlock) { return use(skipEntity, skipBlock, null); } - public InteractionResult use(boolean skipEntity, boolean skipBlock, float yaw, float pitch) { - return use(skipEntity, skipBlock, null, yaw, pitch); - } - public InteractionResult use(boolean skipEntity, boolean skipBlock, @Nullable Predicate entityFilter) { - return use(skipEntity, skipBlock, entityFilter, 0, 0); - } - - public InteractionResult use(boolean skipEntity, boolean skipBlock, @Nullable Predicate entityFilter, float yaw, float pitch) { - final float oldRot = this.getYRot(); - this.setRot((oldRot + yaw % 360 + 360) % 360, pitch % 360); - try { - return this.useAction(skipEntity, skipBlock, entityFilter); - } finally { - this.setRot(oldRot, 0); - } - } - - private InteractionResult useAction(boolean skipEntity, boolean skipBlock, @Nullable Predicate entityFilter) { HitResult hit = findHit(skipEntity, skipBlock, entityFilter); if (hit instanceof BlockHitResult blockHit) { From f2506b0f0679852e85e150042235e0aec0c8c7be Mon Sep 17 00:00:00 2001 From: zyxkad Date: Fri, 26 Apr 2024 14:56:47 -0600 Subject: [PATCH 142/228] fix java generic --- .../peripheral/plugins/AutomataEntityHandPlugin.java | 5 +++-- .../peripheral/plugins/AutomataEntityTransferPlugin.java | 3 ++- .../computercraft/peripheral/plugins/AutomataLookPlugin.java | 3 ++- .../common/util/fakeplayer/APFakePlayer.java | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java index c0647b008..fc0d5f159 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java @@ -3,6 +3,7 @@ import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.lua.MethodResult; +import dan200.computercraft.core.apis.TableHelper; import de.srendi.advancedperipherals.common.addons.computercraft.owner.TurtlePeripheralOwner; import de.srendi.advancedperipherals.common.util.LuaConverter; import de.srendi.advancedperipherals.lib.peripherals.AutomataCorePeripheral; @@ -47,7 +48,7 @@ public final MethodResult useOnAnimal(@NotNull IArguments arguments) throws LuaE TurtlePeripheralOwner owner = automataCore.getPeripheralOwner(); ItemStack selectedTool = owner.getToolInMainHand(); int previousDamageValue = selectedTool.getDamageValue(); - InteractionResult result = owner.withPlayer(player -> player.doActionWithRot(yaw, pitch, player -> player.useOnFilteredEntity(suitableEntity))); + InteractionResult result = owner.withPlayer(player -> player.doActionWithRot(yaw, pitch, p -> p.useOnFilteredEntity(suitableEntity))); if (automataCore.hasAttribute(AutomataCorePeripheral.ATTR_STORING_TOOL_DURABILITY)) selectedTool.setDamageValue(previousDamageValue); @@ -63,7 +64,7 @@ public final MethodResult inspectAnimal(@NotNull IArguments arguments) throws Lu automataCore.addRotationCycle(); TurtlePeripheralOwner owner = automataCore.getPeripheralOwner(); - HitResult entityHit = owner.withPlayer(player -> player.doActionWithRot(yaw, pitch, player -> player.findHit(false, true, suitableEntity))); + HitResult entityHit = owner.withPlayer(player -> player.doActionWithRot(yaw, pitch, p -> p.findHit(false, true, suitableEntity))); if (entityHit.getType() == HitResult.Type.MISS) return MethodResult.of(null, "Nothing found"); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityTransferPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityTransferPlugin.java index 0a955c868..c031ca1f2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityTransferPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityTransferPlugin.java @@ -3,6 +3,7 @@ import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.lua.MethodResult; +import dan200.computercraft.core.apis.TableHelper; import de.srendi.advancedperipherals.common.addons.computercraft.owner.TurtlePeripheralOwner; import de.srendi.advancedperipherals.common.util.LuaConverter; import de.srendi.advancedperipherals.lib.peripherals.AutomataCorePeripheral; @@ -74,7 +75,7 @@ public final MethodResult captureAnimal(@NotNull IArguments arguments) throws Lu float yaw = opts != null ? (float) TableHelper.optNumberField(opts, "yaw", 0) : 0; float pitch = opts != null ? (float) TableHelper.optNumberField(opts, "pitch", 0) : 0; - HitResult entityHit = automataCore.getPeripheralOwner().withPlayer(player -> player.doActionWithRot(yaw, pitch, player -> player.findHit(false, true, suitableEntity))); + HitResult entityHit = automataCore.getPeripheralOwner().withPlayer(player -> player.doActionWithRot(yaw, pitch, p -> p.findHit(false, true, suitableEntity))); if (entityHit.getType() == HitResult.Type.MISS) return MethodResult.of(null, "Nothing found"); return automataCore.withOperation(CAPTURE_ANIMAL, context -> { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataLookPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataLookPlugin.java index 329108bf6..eb6ce8965 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataLookPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataLookPlugin.java @@ -2,6 +2,7 @@ import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.lua.MethodResult; +import dan200.computercraft.core.apis.TableHelper; import de.srendi.advancedperipherals.common.addons.computercraft.owner.TurtlePeripheralOwner; import de.srendi.advancedperipherals.common.util.LuaConverter; import de.srendi.advancedperipherals.lib.peripherals.AutomataCorePeripheral; @@ -50,7 +51,7 @@ public final MethodResult lookAtEntity(@NotNull IArguments arguments) throws Lua float pitch = opts != null ? (float) TableHelper.optNumberField(opts, "pitch", 0) : 0; automataCore.addRotationCycle(); - HitResult result = automataCore.getPeripheralOwner().withPlayer(apFakePlayer -> apFakePlayer.doActionWithRot(yaw, pitch, apFakePlayer -> apFakePlayer.findHit(false, true))); + HitResult result = automataCore.getPeripheralOwner().withPlayer(apFakePlayer -> apFakePlayer.doActionWithRot(yaw, pitch, p -> p.findHit(false, true))); if (result.getType() == HitResult.Type.MISS) return MethodResult.of(null, "No entity find"); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java index d6af4968f..4c8b673c8 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java @@ -119,7 +119,7 @@ public float getEyeHeight(@NotNull Pose pose) { return 0; } - public T doActionWithRot(float yaw, float pitch, Function action) { + public T doActionWithRot(float yaw, float pitch, Function action) { final float oldRot = this.getYRot(); this.setRot(oldRot + yaw, pitch); try { From 3c487cf16fa6350d8a9904c809462cc2383b254a Mon Sep 17 00:00:00 2001 From: zyxkad Date: Fri, 26 Apr 2024 15:05:54 -0600 Subject: [PATCH 143/228] fix missing imports --- .../peripheral/plugins/AutomataBlockHandPlugin.java | 2 +- .../peripheral/plugins/AutomataChargingPlugin.java | 2 +- .../peripheral/plugins/AutomataEntityHandPlugin.java | 4 +++- .../peripheral/plugins/AutomataEntityTransferPlugin.java | 3 +++ .../peripheral/plugins/AutomataItemSuckPlugin.java | 2 +- .../computercraft/peripheral/plugins/AutomataLookPlugin.java | 5 ++++- .../common/util/fakeplayer/APFakePlayer.java | 3 ++- 7 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java index 8ca3abe5c..3013963f2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java @@ -12,9 +12,9 @@ import de.srendi.advancedperipherals.lib.peripherals.IPeripheralOperation; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.ItemStack; + import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; - import java.util.Map; import static de.srendi.advancedperipherals.common.addons.computercraft.operations.SingleOperation.DIG; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataChargingPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataChargingPlugin.java index 2ffdb4d43..d47108ac4 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataChargingPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataChargingPlugin.java @@ -11,8 +11,8 @@ import de.srendi.advancedperipherals.lib.peripherals.AutomataCorePeripheral; import net.minecraft.world.item.ItemStack; import net.minecraftforge.common.capabilities.ForgeCapabilities; -import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.NotNull; import java.util.Objects; public class AutomataChargingPlugin extends AutomataCorePlugin { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java index fc0d5f159..d7d185e00 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java @@ -1,5 +1,6 @@ package de.srendi.advancedperipherals.common.addons.computercraft.peripheral.plugins; +import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.lua.MethodResult; @@ -16,8 +17,9 @@ import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.HitResult; -import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; import java.util.Map; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityTransferPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityTransferPlugin.java index c031ca1f2..e447b4201 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityTransferPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityTransferPlugin.java @@ -1,5 +1,6 @@ package de.srendi.advancedperipherals.common.addons.computercraft.peripheral.plugins; +import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.lua.MethodResult; @@ -17,7 +18,9 @@ import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.HitResult; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Map; import java.util.function.Predicate; import static de.srendi.advancedperipherals.common.addons.computercraft.operations.SingleOperation.CAPTURE_ANIMAL; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataItemSuckPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataItemSuckPlugin.java index bcc87f781..526ffd532 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataItemSuckPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataItemSuckPlugin.java @@ -15,8 +15,8 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.phys.AABB; import net.minecraftforge.registries.ForgeRegistries; -import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.List; import java.util.Map; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataLookPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataLookPlugin.java index eb6ce8965..0d1f30702 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataLookPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataLookPlugin.java @@ -1,5 +1,7 @@ package de.srendi.advancedperipherals.common.addons.computercraft.peripheral.plugins; +import dan200.computercraft.api.lua.IArguments; +import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.lua.MethodResult; import dan200.computercraft.core.apis.TableHelper; @@ -13,6 +15,7 @@ import net.minecraft.world.phys.HitResult; import net.minecraftforge.registries.ForgeRegistries; +import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map; @@ -30,7 +33,7 @@ public final MethodResult lookAtBlock(@NotNull IArguments arguments) throws LuaE automataCore.addRotationCycle(); TurtlePeripheralOwner owner = automataCore.getPeripheralOwner(); - HitResult result = owner.withPlayer(apFakePlayer -> apFakePlayer.doActionWithRot(yaw, pitch, apFakePlayer -> apFakePlayer.findHit(true, false))); + HitResult result = owner.withPlayer(apFakePlayer -> apFakePlayer.doActionWithRot(yaw, pitch, p -> p.findHit(true, false))); if (result.getType() == HitResult.Type.MISS) return MethodResult.of(null, "No block find"); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java index 4c8b673c8..8f1990584 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java @@ -48,6 +48,7 @@ import java.util.List; import java.util.Optional; import java.util.UUID; +import java.util.function.Function; import java.util.function.Predicate; public class APFakePlayer extends FakePlayer { @@ -131,7 +132,7 @@ public T doActionWithRot(float yaw, float pitch, Function a @Deprecated(forRemoval = true) public Pair digBlock(Direction direction) { - return digBlock(direction.toYRot() - this.getYRot(), direction == Direction.DOWN ? 90 : direction == Direction.UP ? -90 : 0); + return doActionWithRot(direction.toYRot() - this.getYRot(), direction == Direction.DOWN ? 90 : direction == Direction.UP ? -90 : 0, APFakePlayer::digBlock); } public Pair digBlock() { From d1673531a9101976fbf04764457996c6e97004b2 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Fri, 26 Apr 2024 15:12:46 -0600 Subject: [PATCH 144/228] remove unused import --- .../common/util/fakeplayer/FakePlayerProviderTurtle.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/FakePlayerProviderTurtle.java b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/FakePlayerProviderTurtle.java index f19bc7322..fff168b9f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/FakePlayerProviderTurtle.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/FakePlayerProviderTurtle.java @@ -5,7 +5,6 @@ import dan200.computercraft.shared.util.WorldUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.core.Vec3i; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.EquipmentSlot; From 8be8351000480491dac764d3ede3e83a7719834b Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sat, 27 Apr 2024 06:53:55 -0600 Subject: [PATCH 145/228] accept NBTed items as turtle upgrade fix #599 --- .../lib/turtle/PeripheralTurtleUpgrade.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/lib/turtle/PeripheralTurtleUpgrade.java b/src/main/java/de/srendi/advancedperipherals/lib/turtle/PeripheralTurtleUpgrade.java index 2c1488eb0..c7e898790 100644 --- a/src/main/java/de/srendi/advancedperipherals/lib/turtle/PeripheralTurtleUpgrade.java +++ b/src/main/java/de/srendi/advancedperipherals/lib/turtle/PeripheralTurtleUpgrade.java @@ -21,7 +21,7 @@ protected PeripheralTurtleUpgrade(ResourceLocation id, ItemStack item) { super(id, TurtleUpgradeType.PERIPHERAL, TranslationUtil.turtle(id.getPath()), item); } - //TODO: Do we still need this with the new modeller system? + // TODO: Do we still need this with the new modeller system? public abstract ModelResourceLocation getLeftModel(); public abstract ModelResourceLocation getRightModel(); @@ -37,4 +37,10 @@ public IPeripheral createPeripheral(@NotNull ITurtleAccess turtle, @NotNull Turt } return peripheral; } + + @Override + public boolean isItemSuitable(@NotNull ItemStack stack ) { + // always accept NBTed items + return true; + } } From 39b994f951f89a30d14fbdbf56ac58355fe3ca8b Mon Sep 17 00:00:00 2001 From: zyxkad Date: Thu, 25 Apr 2024 16:31:38 -0600 Subject: [PATCH 146/228] add slot field to inventoryManager.getItemInHand close IntelligenceModding/Advanced-Peripherals-Features#67 --- .../computercraft/peripheral/InventoryManagerPeripheral.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java index 190ba5aa7..922db0bda 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java @@ -189,7 +189,7 @@ public final int getFreeSlot() throws LuaException { @LuaFunction(mainThread = true) public final Map getItemInHand() throws LuaException { - return LuaConverter.itemStackToObject(getOwnerPlayer().getMainHandItem()); + return LuaConverter.stackToObjectWithSlot(getOwnerPlayer().getMainHandItem(), getOwnerPlayer().getInventory().selected); } @LuaFunction(mainThread = true) From 62e55839b1d90a75aa52af2d5cb1951404dd34f3 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sat, 27 Apr 2024 07:05:42 -0600 Subject: [PATCH 147/228] make inventoryManager.getItem return nil instead of empty table --- .../peripheral/InventoryManagerPeripheral.java | 9 +++++++-- .../common/util/LuaConverter.java | 13 ++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java index 922db0bda..6f93e56cf 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java @@ -23,8 +23,8 @@ import net.minecraftforge.items.wrapper.PlayerArmorInvWrapper; import net.minecraftforge.items.wrapper.PlayerInvWrapper; import net.minecraftforge.items.wrapper.PlayerOffhandInvWrapper; -import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -187,9 +187,14 @@ public final int getFreeSlot() throws LuaException { return getOwnerPlayer().getInventory().getFreeSlot(); } + @LuaFunction(mainThread = true) + public final int getHandSlot() throws LuaException { + return getOwnerPlayer().getInventory().selected; + } + @LuaFunction(mainThread = true) public final Map getItemInHand() throws LuaException { - return LuaConverter.stackToObjectWithSlot(getOwnerPlayer().getMainHandItem(), getOwnerPlayer().getInventory().selected); + return LuaConverter.itemStackToObject(getOwnerPlayer().getMainHandItem(), getOwnerPlayer().getInventory().selected); } @LuaFunction(mainThread = true) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java b/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java index 08b24136d..e23c9242f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java @@ -19,8 +19,9 @@ import net.minecraftforge.common.IForgeShearable; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidType; -import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -104,8 +105,11 @@ public static Object posToObject(BlockPos pos) { return map; } + @Nullable public static Map itemStackToObject(@NotNull ItemStack stack) { - if (stack.isEmpty()) return new HashMap<>(); + if (stack.isEmpty()) { + return null; + } Map map = itemToObject(stack.getItem()); CompoundTag nbt = stack.copy().getOrCreateTag(); map.put("count", stack.getCount()); @@ -141,8 +145,11 @@ public static Map itemStackToObject(@NotNull ItemStack itemStack * @return a Map containing proper item stack details * @see InventoryManagerPeripheral#getItems() */ + @Nullable public static Map stackToObjectWithSlot(@NotNull ItemStack stack, int slot) { - if (stack.isEmpty()) return new HashMap<>(); + if (stack.isEmpty()) { + return null; + } Map map = itemStackToObject(stack); map.put("slot", slot); return map; From 5062b4d745a299374473af17c332919833876377 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sat, 27 Apr 2024 08:01:05 -0600 Subject: [PATCH 148/228] change slot index starts from 1 fix #587 --- .../srendi/advancedperipherals/common/util/LuaConverter.java | 2 +- .../advancedperipherals/common/util/inventory/ItemFilter.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java b/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java index e23c9242f..86003d68a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java @@ -151,7 +151,7 @@ public static Map stackToObjectWithSlot(@NotNull ItemStack stack return null; } Map map = itemStackToObject(stack); - map.put("slot", slot); + map.put("slot", slot + 1); return map; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java index cfc9d4892..f44bb19f9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java @@ -69,14 +69,14 @@ public static Pair parse(Map item) { } if (item.containsKey("fromSlot")) { try { - itemFilter.fromSlot = TableHelper.getIntField(item, "fromSlot"); + itemFilter.fromSlot = TableHelper.getIntField(item, "fromSlot") - 1; } catch (LuaException luaException) { return Pair.of(null, "NO_VALID_FROMSLOT"); } } if (item.containsKey("toSlot")) { try { - itemFilter.toSlot = TableHelper.getIntField(item, "toSlot"); + itemFilter.toSlot = TableHelper.getIntField(item, "toSlot") - 1; } catch (LuaException luaException) { return Pair.of(null, "NO_VALID_TOSLOT"); } From 9d3e5289202de044dfa067295e52a70b1c8cc49c Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sat, 27 Apr 2024 15:20:56 -0600 Subject: [PATCH 149/228] add UnsafeConfig for ignore NBT --- .../common/configuration/GeneralConfig.java | 5 +++++ .../common/configuration/UnsafeConfig.java | 22 +++++++++++++++++++ .../lib/turtle/PeripheralTurtleUpgrade.java | 10 ++++++--- 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/configuration/UnsafeConfig.java diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/GeneralConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/GeneralConfig.java index 57c32e43d..9ebf6a61d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/GeneralConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/GeneralConfig.java @@ -23,6 +23,11 @@ public class GeneralConfig implements IAPConfig { LibConfig.build(builder); + builder.pop(); + builder.push("Unsafe"); + + UnsafeConfig.build(builder); + builder.pop(); configSpec = builder.build(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/UnsafeConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/UnsafeConfig.java new file mode 100644 index 000000000..faff69e5f --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/UnsafeConfig.java @@ -0,0 +1,22 @@ +package de.srendi.advancedperipherals.common.configuration; + +import net.minecraftforge.common.ForgeConfigSpec; + +public class UnsafeConfig { + + private static ForgeConfigSpec.BooleanValue enableUnsafe; + private static ForgeConfigSpec.BooleanValue ignoreTurtlePeripheralItemNBT; + + public static void build(final ForgeConfigSpec.Builder builder) { + enableUnsafe = builder.comment("By setting this value to true, I understand all operations below are danger to my adventure, and if they caused unexpected behaviour in my world, I will not consider it as AP's liability").define("enableUnsafe", false); + ignoreTurtlePeripheralItemNBT = builder.comment("Ignore turtle peripheral item's NBT when equipping. **YOU WILL LOST ALL NBT ON THE ITEM**").define("ignoreTurtlePeripheralItemNBT", false); + } + + public static boolean enabled() { + return enableUnsafe.get(); + } + + public static boolean getIgnoreTurtlePeripheralItemNBT() { + return enabled() && ignoreTurtlePeripheralItemNBT.get(); + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/lib/turtle/PeripheralTurtleUpgrade.java b/src/main/java/de/srendi/advancedperipherals/lib/turtle/PeripheralTurtleUpgrade.java index c7e898790..2f06c5944 100644 --- a/src/main/java/de/srendi/advancedperipherals/lib/turtle/PeripheralTurtleUpgrade.java +++ b/src/main/java/de/srendi/advancedperipherals/lib/turtle/PeripheralTurtleUpgrade.java @@ -5,6 +5,7 @@ import dan200.computercraft.api.turtle.ITurtleAccess; import dan200.computercraft.api.turtle.TurtleSide; import dan200.computercraft.api.turtle.TurtleUpgradeType; +import de.srendi.advancedperipherals.common.configuration.UnsafeConfig; import de.srendi.advancedperipherals.common.util.TranslationUtil; import de.srendi.advancedperipherals.lib.peripherals.DisabledPeripheral; import de.srendi.advancedperipherals.lib.peripherals.IBasePeripheral; @@ -39,8 +40,11 @@ public IPeripheral createPeripheral(@NotNull ITurtleAccess turtle, @NotNull Turt } @Override - public boolean isItemSuitable(@NotNull ItemStack stack ) { - // always accept NBTed items - return true; + public boolean isItemSuitable(@NotNull ItemStack stack) { + if (UnsafeConfig.getIgnoreTurtlePeripheralItemNBT()) { + // always accept NBTed items + return true; + } + return super.isItemSuitable(stack); } } From 702ad137af22ef165f5b03f71961d93d2b68f17b Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sat, 27 Apr 2024 17:57:11 -0600 Subject: [PATCH 150/228] fix null pointer --- .../peripheral/plugins/AutomataBlockHandPlugin.java | 11 +++++++---- .../peripheral/plugins/AutomataEntityHandPlugin.java | 8 +++++--- .../plugins/AutomataEntityTransferPlugin.java | 3 ++- .../peripheral/plugins/AutomataLookPlugin.java | 5 +++-- .../common/util/fakeplayer/APFakePlayer.java | 10 ++++++++++ 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java index 3013963f2..109839ad1 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java @@ -15,6 +15,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; import java.util.Map; import static de.srendi.advancedperipherals.common.addons.computercraft.operations.SingleOperation.DIG; @@ -33,14 +34,15 @@ public AutomataBlockHandPlugin(AutomataCorePeripheral automataCore) { @LuaFunction(mainThread = true) public final MethodResult digBlock(@NotNull IArguments arguments) throws LuaException { - Map opts = arguments.count() > 0 ? arguments.getTable(0) : null; + Map opts = arguments.count() > 0 ? arguments.getTable(0) : Collections.emptyMap(); + boolean sneak = TableHelper.optBooleanField(opts, "sneak", false); float yaw = opts != null ? (float) TableHelper.optNumberField(opts, "yaw", 0) : 0; float pitch = opts != null ? (float) TableHelper.optNumberField(opts, "pitch", 0) : 0; return automataCore.withOperation(DIG, context -> { TurtlePeripheralOwner owner = automataCore.getPeripheralOwner(); ItemStack selectedTool = owner.getToolInMainHand(); int previousDamageValue = selectedTool.getDamageValue(); - Pair result = owner.withPlayer(apFakePlayer -> apFakePlayer.doActionWithRot(yaw, pitch, APFakePlayer::digBlock)); + Pair result = owner.withPlayer(apFakePlayer -> apFakePlayer.doActionWithShiftKey(sneak, p -> p.doActionWithRot(yaw, pitch, APFakePlayer::digBlock))); if (!result.getLeft()) { return MethodResult.of(null, result.getRight()); } @@ -52,14 +54,15 @@ public final MethodResult digBlock(@NotNull IArguments arguments) throws LuaExce @LuaFunction(mainThread = true) public final MethodResult useOnBlock(@NotNull IArguments arguments) throws LuaException { - Map opts = arguments.count() > 0 ? arguments.getTable(0) : null; + Map opts = arguments.count() > 0 ? arguments.getTable(0) : Collections.emptyMap(); + boolean sneak = TableHelper.optBooleanField(opts, "sneak", false); float yaw = opts != null ? (float) TableHelper.optNumberField(opts, "yaw", 0) : 0; float pitch = opts != null ? (float) TableHelper.optNumberField(opts, "pitch", 0) : 0; return automataCore.withOperation(USE_ON_BLOCK, context -> { TurtlePeripheralOwner owner = automataCore.getPeripheralOwner(); ItemStack selectedTool = owner.getToolInMainHand(); int previousDamageValue = selectedTool.getDamageValue(); - InteractionResult result = owner.withPlayer(apFakePlayer -> apFakePlayer.doActionWithRot(yaw, pitch, APFakePlayer::useOnBlock)); + InteractionResult result = owner.withPlayer(apFakePlayer -> apFakePlayer.doActionWithShiftKey(sneak, p -> p.doActionWithRot(yaw, pitch, APFakePlayer::useOnBlock))); if (automataCore.hasAttribute(AutomataCorePeripheral.ATTR_STORING_TOOL_DURABILITY)) selectedTool.setDamageValue(previousDamageValue); return MethodResult.of(true, result.toString()); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java index d7d185e00..43e41adfa 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java @@ -21,6 +21,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.function.Predicate; @@ -43,14 +44,15 @@ public AutomataEntityHandPlugin(AutomataCorePeripheral automataCore, Predicate opts = arguments.count() > 0 ? arguments.getTable(0) : null; + Map opts = arguments.count() > 0 ? arguments.getTable(0) : Collections.emptyMap(); + boolean sneak = TableHelper.optBooleanField(opts, "sneak", false); float yaw = opts != null ? (float) TableHelper.optNumberField(opts, "yaw", 0) : 0; float pitch = opts != null ? (float) TableHelper.optNumberField(opts, "pitch", 0) : 0; return automataCore.withOperation(USE_ON_ANIMAL, context -> { TurtlePeripheralOwner owner = automataCore.getPeripheralOwner(); ItemStack selectedTool = owner.getToolInMainHand(); int previousDamageValue = selectedTool.getDamageValue(); - InteractionResult result = owner.withPlayer(player -> player.doActionWithRot(yaw, pitch, p -> p.useOnFilteredEntity(suitableEntity))); + InteractionResult result = owner.withPlayer(apFakePlayer -> apFakePlayer.doActionWithShiftKey(sneak, player -> player.doActionWithRot(yaw, pitch, p -> p.useOnFilteredEntity(suitableEntity)))); if (automataCore.hasAttribute(AutomataCorePeripheral.ATTR_STORING_TOOL_DURABILITY)) selectedTool.setDamageValue(previousDamageValue); @@ -60,7 +62,7 @@ public final MethodResult useOnAnimal(@NotNull IArguments arguments) throws LuaE @LuaFunction(mainThread = true) public final MethodResult inspectAnimal(@NotNull IArguments arguments) throws LuaException { - Map opts = arguments.count() > 0 ? arguments.getTable(0) : null; + Map opts = arguments.count() > 0 ? arguments.getTable(0) : Collections.emptyMap(); float yaw = opts != null ? (float) TableHelper.optNumberField(opts, "yaw", 0) : 0; float pitch = opts != null ? (float) TableHelper.optNumberField(opts, "pitch", 0) : 0; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityTransferPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityTransferPlugin.java index e447b4201..e33c28550 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityTransferPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityTransferPlugin.java @@ -20,6 +20,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; import java.util.Map; import java.util.function.Predicate; @@ -74,7 +75,7 @@ protected Entity extractEntity() { @LuaFunction(mainThread = true) public final MethodResult captureAnimal(@NotNull IArguments arguments) throws LuaException { - Map opts = arguments.count() > 0 ? arguments.getTable(0) : null; + Map opts = arguments.count() > 0 ? arguments.getTable(0) : Collections.emptyMap(); float yaw = opts != null ? (float) TableHelper.optNumberField(opts, "yaw", 0) : 0; float pitch = opts != null ? (float) TableHelper.optNumberField(opts, "pitch", 0) : 0; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataLookPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataLookPlugin.java index 0d1f30702..8fb03e855 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataLookPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataLookPlugin.java @@ -16,6 +16,7 @@ import net.minecraftforge.registries.ForgeRegistries; import org.jetbrains.annotations.NotNull; +import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -27,7 +28,7 @@ public AutomataLookPlugin(AutomataCorePeripheral automataCore) { @LuaFunction(mainThread = true) public final MethodResult lookAtBlock(@NotNull IArguments arguments) throws LuaException { - Map opts = arguments.count() > 0 ? arguments.getTable(0) : null; + Map opts = arguments.count() > 0 ? arguments.getTable(0) : Collections.emptyMap(); float yaw = opts != null ? (float) TableHelper.optNumberField(opts, "yaw", 0) : 0; float pitch = opts != null ? (float) TableHelper.optNumberField(opts, "pitch", 0) : 0; @@ -49,7 +50,7 @@ public final MethodResult lookAtBlock(@NotNull IArguments arguments) throws LuaE @LuaFunction(mainThread = true) public final MethodResult lookAtEntity(@NotNull IArguments arguments) throws LuaException { - Map opts = arguments.count() > 0 ? arguments.getTable(0) : null; + Map opts = arguments.count() > 0 ? arguments.getTable(0) : Collections.emptyMap(); float yaw = opts != null ? (float) TableHelper.optNumberField(opts, "yaw", 0) : 0; float pitch = opts != null ? (float) TableHelper.optNumberField(opts, "pitch", 0) : 0; diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java index 8f1990584..d797ba2d8 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java @@ -130,6 +130,16 @@ public T doActionWithRot(float yaw, float pitch, Function a } } + public T doActionWithShiftKey(boolean shift, Function action) { + boolean old = this.isShiftKeyDown(); + this.setShiftKeyDown(shift); + try { + return action.apply(this); + } finally { + this.setShiftKeyDown(old); + } + } + @Deprecated(forRemoval = true) public Pair digBlock(Direction direction) { return doActionWithRot(direction.toYRot() - this.getYRot(), direction == Direction.DOWN ? 90 : direction == Direction.UP ? -90 : 0, APFakePlayer::digBlock); From b6600fad04b1e0b85b6ce1574889eaf08bb77fdc Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sat, 27 Apr 2024 18:57:17 -0600 Subject: [PATCH 151/228] fix automata core will place two blocks at a time --- .../plugins/AutomataBlockHandPlugin.java | 12 +- .../plugins/AutomataEntityHandPlugin.java | 8 +- .../plugins/AutomataEntityTransferPlugin.java | 3 +- .../plugins/AutomataLookPlugin.java | 5 +- .../common/util/fakeplayer/APFakePlayer.java | 110 ++++++++++-------- 5 files changed, 77 insertions(+), 61 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java index 109839ad1..3d3c375b8 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java @@ -42,12 +42,13 @@ public final MethodResult digBlock(@NotNull IArguments arguments) throws LuaExce TurtlePeripheralOwner owner = automataCore.getPeripheralOwner(); ItemStack selectedTool = owner.getToolInMainHand(); int previousDamageValue = selectedTool.getDamageValue(); - Pair result = owner.withPlayer(apFakePlayer -> apFakePlayer.doActionWithShiftKey(sneak, p -> p.doActionWithRot(yaw, pitch, APFakePlayer::digBlock))); + Pair result = owner.withPlayer(APFakePlayer.wrapActionWithShiftKey(sneak, APFakePlayer.wrapActionWithRot(yaw, pitch, APFakePlayer::digBlock))); if (!result.getLeft()) { return MethodResult.of(null, result.getRight()); } - if (automataCore.hasAttribute(AutomataCorePeripheral.ATTR_STORING_TOOL_DURABILITY)) + if (automataCore.hasAttribute(AutomataCorePeripheral.ATTR_STORING_TOOL_DURABILITY)) { selectedTool.setDamageValue(previousDamageValue); + } return MethodResult.of(true); }); } @@ -62,10 +63,11 @@ public final MethodResult useOnBlock(@NotNull IArguments arguments) throws LuaEx TurtlePeripheralOwner owner = automataCore.getPeripheralOwner(); ItemStack selectedTool = owner.getToolInMainHand(); int previousDamageValue = selectedTool.getDamageValue(); - InteractionResult result = owner.withPlayer(apFakePlayer -> apFakePlayer.doActionWithShiftKey(sneak, p -> p.doActionWithRot(yaw, pitch, APFakePlayer::useOnBlock))); - if (automataCore.hasAttribute(AutomataCorePeripheral.ATTR_STORING_TOOL_DURABILITY)) + InteractionResult result = owner.withPlayer(APFakePlayer.wrapActionWithShiftKey(sneak, APFakePlayer.wrapActionWithRot(yaw, pitch, APFakePlayer::useOnBlock))); + if (automataCore.hasAttribute(AutomataCorePeripheral.ATTR_STORING_TOOL_DURABILITY)) { selectedTool.setDamageValue(previousDamageValue); - return MethodResult.of(true, result.toString()); + } + return MethodResult.of(result.consumesAction(), result.toString()); }); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java index 43e41adfa..6400a1a57 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java @@ -7,6 +7,7 @@ import dan200.computercraft.core.apis.TableHelper; import de.srendi.advancedperipherals.common.addons.computercraft.owner.TurtlePeripheralOwner; import de.srendi.advancedperipherals.common.util.LuaConverter; +import de.srendi.advancedperipherals.common.util.fakeplayer.APFakePlayer; import de.srendi.advancedperipherals.lib.peripherals.AutomataCorePeripheral; import de.srendi.advancedperipherals.lib.peripherals.IPeripheralOperation; import net.minecraft.core.BlockPos; @@ -52,7 +53,7 @@ public final MethodResult useOnAnimal(@NotNull IArguments arguments) throws LuaE TurtlePeripheralOwner owner = automataCore.getPeripheralOwner(); ItemStack selectedTool = owner.getToolInMainHand(); int previousDamageValue = selectedTool.getDamageValue(); - InteractionResult result = owner.withPlayer(apFakePlayer -> apFakePlayer.doActionWithShiftKey(sneak, player -> player.doActionWithRot(yaw, pitch, p -> p.useOnFilteredEntity(suitableEntity)))); + InteractionResult result = owner.withPlayer(APFakePlayer.wrapActionWithShiftKey(sneak, APFakePlayer.wrapActionWithRot(yaw, pitch, p -> p.useOnFilteredEntity(suitableEntity)))); if (automataCore.hasAttribute(AutomataCorePeripheral.ATTR_STORING_TOOL_DURABILITY)) selectedTool.setDamageValue(previousDamageValue); @@ -68,7 +69,7 @@ public final MethodResult inspectAnimal(@NotNull IArguments arguments) throws Lu automataCore.addRotationCycle(); TurtlePeripheralOwner owner = automataCore.getPeripheralOwner(); - HitResult entityHit = owner.withPlayer(player -> player.doActionWithRot(yaw, pitch, p -> p.findHit(false, true, suitableEntity))); + HitResult entityHit = owner.withPlayer(APFakePlayer.wrapActionWithRot(yaw, pitch, p -> p.findHit(false, true, suitableEntity))); if (entityHit.getType() == HitResult.Type.MISS) return MethodResult.of(null, "Nothing found"); @@ -85,9 +86,8 @@ public final MethodResult searchAnimals() { TurtlePeripheralOwner owner = automataCore.getPeripheralOwner(); BlockPos currentPos = owner.getPos(); AABB box = new AABB(currentPos); - List> entities = new ArrayList<>(); ItemStack itemInHand = owner.getToolInMainHand(); - owner.getLevel().getEntities((Entity) null, box.inflate(automataCore.getInteractionRadius()), suitableEntity).forEach(entity -> entities.add(LuaConverter.completeEntityWithPositionToLua(entity, itemInHand, currentPos))); + List> entities = owner.getLevel().getEntities((Entity) null, box.inflate(automataCore.getInteractionRadius()), suitableEntity).stream().map(entity -> LuaConverter.completeEntityWithPositionToLua(entity, itemInHand, currentPos)).toList(); return MethodResult.of(entities); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityTransferPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityTransferPlugin.java index e33c28550..e46ca4356 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityTransferPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityTransferPlugin.java @@ -7,6 +7,7 @@ import dan200.computercraft.core.apis.TableHelper; import de.srendi.advancedperipherals.common.addons.computercraft.owner.TurtlePeripheralOwner; import de.srendi.advancedperipherals.common.util.LuaConverter; +import de.srendi.advancedperipherals.common.util.fakeplayer.APFakePlayer; import de.srendi.advancedperipherals.lib.peripherals.AutomataCorePeripheral; import de.srendi.advancedperipherals.lib.peripherals.IPeripheralOperation; import net.minecraft.core.BlockPos; @@ -79,7 +80,7 @@ public final MethodResult captureAnimal(@NotNull IArguments arguments) throws Lu float yaw = opts != null ? (float) TableHelper.optNumberField(opts, "yaw", 0) : 0; float pitch = opts != null ? (float) TableHelper.optNumberField(opts, "pitch", 0) : 0; - HitResult entityHit = automataCore.getPeripheralOwner().withPlayer(player -> player.doActionWithRot(yaw, pitch, p -> p.findHit(false, true, suitableEntity))); + HitResult entityHit = automataCore.getPeripheralOwner().withPlayer(APFakePlayer.wrapActionWithRot(yaw, pitch, p -> p.findHit(false, true, suitableEntity))); if (entityHit.getType() == HitResult.Type.MISS) return MethodResult.of(null, "Nothing found"); return automataCore.withOperation(CAPTURE_ANIMAL, context -> { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataLookPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataLookPlugin.java index 8fb03e855..2b27487bf 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataLookPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataLookPlugin.java @@ -7,6 +7,7 @@ import dan200.computercraft.core.apis.TableHelper; import de.srendi.advancedperipherals.common.addons.computercraft.owner.TurtlePeripheralOwner; import de.srendi.advancedperipherals.common.util.LuaConverter; +import de.srendi.advancedperipherals.common.util.fakeplayer.APFakePlayer; import de.srendi.advancedperipherals.lib.peripherals.AutomataCorePeripheral; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.state.BlockState; @@ -34,7 +35,7 @@ public final MethodResult lookAtBlock(@NotNull IArguments arguments) throws LuaE automataCore.addRotationCycle(); TurtlePeripheralOwner owner = automataCore.getPeripheralOwner(); - HitResult result = owner.withPlayer(apFakePlayer -> apFakePlayer.doActionWithRot(yaw, pitch, p -> p.findHit(true, false))); + HitResult result = owner.withPlayer(APFakePlayer.wrapActionWithRot(yaw, pitch, p -> p.findHit(true, false))); if (result.getType() == HitResult.Type.MISS) return MethodResult.of(null, "No block find"); @@ -55,7 +56,7 @@ public final MethodResult lookAtEntity(@NotNull IArguments arguments) throws Lua float pitch = opts != null ? (float) TableHelper.optNumberField(opts, "pitch", 0) : 0; automataCore.addRotationCycle(); - HitResult result = automataCore.getPeripheralOwner().withPlayer(apFakePlayer -> apFakePlayer.doActionWithRot(yaw, pitch, p -> p.findHit(false, true))); + HitResult result = automataCore.getPeripheralOwner().withPlayer(APFakePlayer.wrapActionWithRot(yaw, pitch, p -> p.findHit(false, true))); if (result.getType() == HitResult.Type.MISS) return MethodResult.of(null, "No entity find"); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java index d797ba2d8..e5e9d90f2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java @@ -120,6 +120,10 @@ public float getEyeHeight(@NotNull Pose pose) { return 0; } + public static Function wrapActionWithRot(float yaw, float pitch, Function action) { + return player -> player.doActionWithRot(yaw, pitch, action); + } + public T doActionWithRot(float yaw, float pitch, Function action) { final float oldRot = this.getYRot(); this.setRot(oldRot + yaw, pitch); @@ -130,6 +134,10 @@ public T doActionWithRot(float yaw, float pitch, Function a } } + public static Function wrapActionWithShiftKey(boolean shift, Function action) { + return player -> player.doActionWithShiftKey(shift, action); + } + public T doActionWithShiftKey(boolean shift, Function action) { boolean old = this.isShiftKeyDown(); this.setShiftKeyDown(shift); @@ -148,58 +156,56 @@ public Pair digBlock(Direction direction) { public Pair digBlock() { Level world = getLevel(); HitResult hit = findHit(true, false); - if (hit.getType() == HitResult.Type.MISS) + if (hit.getType() == HitResult.Type.MISS) { return Pair.of(false, "Nothing to break"); - BlockPos pos = new BlockPos(hit.getLocation().x, hit.getLocation().y, hit.getLocation().z); + } + BlockPos pos = new BlockPos(hit.getLocation()); BlockState state = world.getBlockState(pos); Block block = state.getBlock(); ItemStack tool = getInventory().getSelected(); - - if (tool.isEmpty()) + if (tool.isEmpty()) { return Pair.of(false, "Cannot dig without tool"); + } - - if (block != digBlock || !pos.equals(digPosition)) + if (block != digBlock || !pos.equals(digPosition)) { setState(block, pos); + } Vec3 look = getLookAngle(); Direction direction = Direction.getNearest(look.x, look.y, look.z).getOpposite(); - if (!world.isEmptyBlock(pos) && !state.getMaterial().isLiquid()) { - if (block == Blocks.BEDROCK || state.getDestroySpeed(world, pos) <= -1) - return Pair.of(false, "Unbreakable block detected"); - - if (!(tool.getItem() instanceof DiggerItem) && !(tool.getItem() instanceof ShearsItem)) - return Pair.of(false, "Item should be digger tool"); + if (world.isEmptyBlock(pos) || state.getMaterial().isLiquid()) { + return Pair.of(false, "Nothing to dig here"); + } - if (tool.getItem() instanceof DiggerItem toolItem && !toolItem.isCorrectToolForDrops(tool, state)) - return Pair.of(false, "Tool cannot mine this block"); + if (block == Blocks.BEDROCK || state.getDestroySpeed(world, pos) <= -1) { + return Pair.of(false, "Unbreakable block detected"); + } - if (tool.getItem() instanceof ShearsItem shearsItem && shearsItem.isCorrectToolForDrops(state)) - return Pair.of(false, "Shear cannot mine this block"); + if (!tool.isCorrectToolForDrops(state)) { + return Pair.of(false, "Tool cannot mine this block"); + } - ServerPlayerGameMode manager = gameMode; - float breakSpeed = 0.5f * tool.getDestroySpeed(state) / state.getDestroySpeed(level, pos) - 0.1f; - for (int i = 0; i < 10; i++) { - currentDamage += breakSpeed; + ServerPlayerGameMode manager = gameMode; + float breakSpeed = 0.5f * tool.getDestroySpeed(state) / state.getDestroySpeed(level, pos) - 0.1f; + for (int i = 0; i < 10; i++) { + currentDamage += breakSpeed; - world.destroyBlockProgress(getId(), pos, i); + world.destroyBlockProgress(getId(), pos, i); - if (currentDamage > 9) { - world.playSound(null, pos, state.getSoundType().getHitSound(), SoundSource.NEUTRAL, .25f, 1); - manager.handleBlockBreakAction(pos, ServerboundPlayerActionPacket.Action.STOP_DESTROY_BLOCK, direction, 320, 1); - manager.destroyBlock(pos); - world.destroyBlockProgress(getId(), pos, -1); - setState(null, null); - break; - } + if (currentDamage > 9) { + world.playSound(null, pos, state.getSoundType().getHitSound(), SoundSource.NEUTRAL, .25f, 1); + manager.handleBlockBreakAction(pos, ServerboundPlayerActionPacket.Action.STOP_DESTROY_BLOCK, direction, 320, 1); + manager.destroyBlock(pos); + world.destroyBlockProgress(getId(), pos, -1); + setState(null, null); + break; } - - return Pair.of(true, "block"); } - return Pair.of(false, "Nothing to dig here"); + return Pair.of(true, "block"); + } public InteractionResult useOnBlock() { @@ -217,8 +223,9 @@ public InteractionResult useOnFilteredEntity(Predicate filter) { public InteractionResult useOnSpecificEntity(@NotNull Entity entity, HitResult result) { InteractionResult simpleInteraction = interactOn(entity, InteractionHand.MAIN_HAND); if (simpleInteraction == InteractionResult.SUCCESS) return simpleInteraction; - if (ForgeHooks.onInteractEntityAt(this, entity, result.getLocation(), InteractionHand.MAIN_HAND) != null) + if (ForgeHooks.onInteractEntityAt(this, entity, result.getLocation(), InteractionHand.MAIN_HAND) != null) { return InteractionResult.FAIL; + } return entity.interactAt(this, result.getLocation(), InteractionHand.MAIN_HAND); } @@ -231,44 +238,49 @@ public InteractionResult use(boolean skipEntity, boolean skipBlock, @Nullable Pr HitResult hit = findHit(skipEntity, skipBlock, entityFilter); if (hit instanceof BlockHitResult blockHit) { - ItemStack stack = getMainHandItem(); BlockPos pos = blockHit.getBlockPos(); PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock(this, InteractionHand.MAIN_HAND, pos, blockHit); - if (event.isCanceled()) + if (event.isCanceled()) { return event.getCancellationResult(); - - if (event.getUseItem() != Event.Result.DENY) { + } + boolean denied = event.getUseItem() == Event.Result.DENY; + if (!denied) { InteractionResult result = stack.onItemUseFirst(new UseOnContext(level, this, InteractionHand.MAIN_HAND, stack, blockHit)); - if (result != InteractionResult.PASS) + if (result != InteractionResult.PASS) { return result; - } - - boolean bypass = getMainHandItem().doesSneakBypassUse(level, pos, this); - if (getPose() != Pose.CROUCHING || bypass || event.getUseBlock() == Event.Result.ALLOW) { - InteractionResult useType = gameMode.useItemOn(this, level, stack, InteractionHand.MAIN_HAND, blockHit); - if (event.getUseBlock() != Event.Result.DENY && useType == InteractionResult.SUCCESS) - return InteractionResult.SUCCESS; + } + boolean bypass = getMainHandItem().doesSneakBypassUse(level, pos, this); + if (isShiftKeyDown() || bypass || event.getUseBlock() == Event.Result.ALLOW) { + InteractionResult useType = gameMode.useItemOn(this, level, stack, InteractionHand.MAIN_HAND, blockHit); + if (useType == InteractionResult.SUCCESS) { + return InteractionResult.SUCCESS; + } + } } - if (stack.isEmpty() || getCooldowns().isOnCooldown(stack.getItem())) + if (stack.isEmpty() || getCooldowns().isOnCooldown(stack.getItem())) { return InteractionResult.PASS; + } if (stack.getItem() instanceof BlockItem blockItem) { Block block = blockItem.getBlock(); - if (block instanceof CommandBlock || block instanceof StructureBlock) + if (block instanceof CommandBlock || block instanceof StructureBlock) { return InteractionResult.FAIL; + } } - if (event.getUseItem() == Event.Result.DENY) + if (denied) { return InteractionResult.PASS; + } ItemStack copyBeforeUse = stack.copy(); InteractionResult result = stack.useOn(new UseOnContext(level, this, InteractionHand.MAIN_HAND, copyBeforeUse, blockHit)); - if (stack.isEmpty()) + if (stack.isEmpty()) { ForgeEventFactory.onPlayerDestroyItem(this, copyBeforeUse, InteractionHand.MAIN_HAND); + } return result; } else if (hit instanceof EntityHitResult entityHit) { return useOnSpecificEntity(entityHit.getEntity(), entityHit); From 1c2685d3544713761b5611a668a18f5398eb6450 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sat, 27 Apr 2024 19:02:41 -0600 Subject: [PATCH 152/228] remove unused imports --- .../peripheral/plugins/AutomataEntityHandPlugin.java | 1 - .../common/util/fakeplayer/APFakePlayer.java | 2 -- 2 files changed, 3 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java index 6400a1a57..14dd9e6f1 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java @@ -21,7 +21,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java index e5e9d90f2..405713ddb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java @@ -21,9 +21,7 @@ import net.minecraft.world.entity.ai.attributes.AttributeInstance; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.DiggerItem; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.ShearsItem; import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.ClipContext; From 6c107595eefac04dd4fc33d01f8d4d4a9728f206 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Tue, 30 Apr 2024 15:36:36 -0600 Subject: [PATCH 153/228] move place method from compass to automataBlockHandPlugin --- .../peripheral/CompassPeripheral.java | 158 +----------------- .../plugins/AutomataBlockHandPlugin.java | 157 +++++++++++++++++ .../configuration/PeripheralsConfig.java | 8 +- .../peripherals/AutomataCorePeripheral.java | 6 +- 4 files changed, 167 insertions(+), 162 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java index 8e19bb491..e1db290fa 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java @@ -1,39 +1,12 @@ package de.srendi.advancedperipherals.common.addons.computercraft.peripheral; -import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaFunction; -import dan200.computercraft.api.lua.MethodResult; import dan200.computercraft.api.turtle.ITurtleAccess; import dan200.computercraft.api.turtle.TurtleSide; -import dan200.computercraft.core.apis.TableHelper; -import dan200.computercraft.shared.turtle.core.TurtlePlayer; -import de.srendi.advancedperipherals.common.addons.computercraft.operations.SingleOperationContext; import de.srendi.advancedperipherals.common.addons.computercraft.owner.TurtlePeripheralOwner; import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.util.StringUtil; import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.network.chat.Component; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.SignItem; -import net.minecraft.world.item.context.DirectionalPlaceContext; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.entity.SignBlockEntity; -import net.minecraft.world.level.Level; -import net.minecraft.world.phys.BlockHitResult; -import net.minecraft.world.phys.Vec3; -import net.minecraftforge.common.ForgeHooks; -import net.minecraftforge.event.entity.player.PlayerInteractEvent; -import java.util.Map; -import javax.annotation.Nullable; -import static de.srendi.advancedperipherals.common.addons.computercraft.operations.SingleOperation.ACCURE_PLACE; public class CompassPeripheral extends BasePeripheral { @@ -41,11 +14,10 @@ public class CompassPeripheral extends BasePeripheral { protected CompassPeripheral(TurtlePeripheralOwner owner) { super(PERIPHERAL_TYPE, owner); - owner.attachOperation(ACCURE_PLACE); } public CompassPeripheral(ITurtleAccess turtle, TurtleSide side) { - this(new TurtlePeripheralOwner(turtle, side).attachFuel(1)); + this(new TurtlePeripheralOwner(turtle, side)); } @Override @@ -58,132 +30,4 @@ public String getFacing() { return owner.getFacing().toString(); } - /** - * @param options A table contains how to place the block: - * x: the x offset relative to the turtle. Default 0 - * y: the y offset relative to the turtle. Default 0 - * z: the z offset relative to the turtle. Default 0 - * forward: the direction the block is going to facing. Default is the facing direction of the turtle - * top: the direction the block's top is going to facing. Default is TOP - * anchor: the direction the block is going to hanging on. Default is same as forward - * text: the text going to write on the sign. Default is null - */ - @LuaFunction(mainThread = true) - public MethodResult place(Map options) throws LuaException { - int x = TableHelper.optIntField(options, "x", 0); - int y = TableHelper.optIntField(options, "y", 0); - int z = TableHelper.optIntField(options, "z", 0); - final int maxDist = APConfig.PERIPHERALS_CONFIG.compassTurtleRadius.get(); - final int freeDist = APConfig.PERIPHERALS_CONFIG.compassTurtleFreeRadius.get(); - if (Math.abs(x) > maxDist || Math.abs(y) > maxDist || Math.abs(z) > maxDist) { - return MethodResult.of(null, "OUT_OF_RANGE"); - } - String anchor = TableHelper.optStringField(options, "anchor", null); - String forward = TableHelper.optStringField(options, "forward", null); - String top = TableHelper.optStringField(options, "top", null); - Direction anchorDir = anchor != null ? validateSide(anchor) : null; - Direction forwardDir = forward != null ? validateSide(forward) : null; - Direction topDir = top != null ? validateSide(top) : null; - - int distance = - Math.max(0, Math.abs(x) - freeDist) + - Math.max(0, Math.abs(y) - freeDist) + - Math.max(0, Math.abs(z) - freeDist); - return withOperation(ACCURE_PLACE, new SingleOperationContext(1, distance), null, context -> { - ITurtleAccess turtle = owner.getTurtle(); - ItemStack stack = turtle.getInventory().getItem(turtle.getSelectedSlot()); - if (stack.isEmpty()) { - return MethodResult.of(null, "EMPTY_SLOT"); - } - BlockPos position = turtle.getPosition().offset(x, y, z); - String err = deployOn(stack, position, anchorDir, forwardDir, topDir, options); - if (err != null) { - return MethodResult.of(null, err); - } - return MethodResult.of(true); - }, null, null); - } - - /** - * @return A nullable string of the error. null means the operation is successful - */ - @Nullable - private String deployOn(ItemStack stack, BlockPos position, Direction anchor, Direction forward, Direction top, Map options) throws LuaException { - ITurtleAccess turtle = owner.getTurtle(); - Level world = turtle.getLevel(); - if (forward == null) { - forward = turtle.getDirection(); - } - if (top == null) { - top = Direction.UP; - } - if (anchor == null) { - anchor = forward; - } - TurtlePlayer turtlePlayer = TurtlePlayer.getWithPosition(turtle, position, forward.getOpposite()); - BlockHitResult hit = BlockHitResult.miss(Vec3.atCenterOf(position), top, position); - AdvanceDirectionalPlaceContext context = new AdvanceDirectionalPlaceContext(world, position, anchor, forward, stack, top); - PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock(turtlePlayer, InteractionHand.MAIN_HAND, position, hit); - if (event.isCanceled()) { - return "EVENT_CANCELED"; - } - Item item = stack.getItem(); - if (!(item instanceof BlockItem)) { - return "NOT_BLOCK"; - } - BlockItem block = (BlockItem) item; - InteractionResult res = block.place(context); - if (!res.consumesAction()) { - return "CANNOT_PLACE"; - } - if (block instanceof SignItem) { - BlockEntity blockEntity = world.getBlockEntity(position); - if (blockEntity instanceof SignBlockEntity sign) { - String text = StringUtil.convertAndToSectionMark(TableHelper.optStringField(options, "text", null)); - setSignText(world, sign, text); - } - } - return null; - } - - private static void setSignText(Level world, SignBlockEntity sign, String text) { - if (text == null) { - for (int i = 0; i < SignBlockEntity.LINES; i++) { - sign.setMessage(i, Component.literal("")); - } - } else { - String[] lines = text.split("\n"); - for (int i = 0; i < SignBlockEntity.LINES; i++) { - sign.setMessage(i, Component.literal(i < lines.length ? lines[i] : "")); - } - } - sign.setChanged(); - world.sendBlockUpdated(sign.getBlockPos(), sign.getBlockState(), sign.getBlockState(), Block.UPDATE_ALL); - } - - private class AdvanceDirectionalPlaceContext extends DirectionalPlaceContext { - private final Direction anchor; - - AdvanceDirectionalPlaceContext(Level world, BlockPos pos, Direction anchor, Direction forward, ItemStack stack, Direction top) { - super(world, pos, forward, stack, top); - this.anchor = anchor; - } - - @Override - public Direction getNearestLookingDirection() { - return this.anchor; - } - - @Override - public Direction[] getNearestLookingDirections() { - return switch (this.anchor) { - case DOWN -> new Direction[]{Direction.DOWN, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST, Direction.UP}; - case UP -> new Direction[]{Direction.UP, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST, Direction.DOWN}; - case NORTH -> new Direction[]{Direction.NORTH, Direction.EAST, Direction.WEST, Direction.UP, Direction.DOWN, Direction.SOUTH}; - case SOUTH -> new Direction[]{Direction.SOUTH, Direction.EAST, Direction.WEST, Direction.UP, Direction.DOWN, Direction.NORTH}; - case WEST -> new Direction[]{Direction.WEST, Direction.SOUTH, Direction.UP, Direction.NORTH, Direction.DOWN, Direction.EAST}; - case EAST -> new Direction[]{Direction.EAST, Direction.SOUTH, Direction.UP, Direction.NORTH, Direction.DOWN, Direction.WEST}; - }; - } - } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java index 3d3c375b8..45cccdede 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java @@ -4,22 +4,47 @@ import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.lua.MethodResult; +import dan200.computercraft.api.turtle.ITurtleAccess; +import dan200.computercraft.api.turtle.TurtleSide; import dan200.computercraft.core.apis.TableHelper; +import dan200.computercraft.shared.turtle.core.TurtlePlayer; +import de.srendi.advancedperipherals.common.addons.computercraft.operations.SingleOperationContext; import de.srendi.advancedperipherals.common.addons.computercraft.owner.TurtlePeripheralOwner; +import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.CompassPeripheral; +import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.util.Pair; +import de.srendi.advancedperipherals.common.util.StringUtil; import de.srendi.advancedperipherals.common.util.fakeplayer.APFakePlayer; import de.srendi.advancedperipherals.lib.peripherals.AutomataCorePeripheral; import de.srendi.advancedperipherals.lib.peripherals.IPeripheralOperation; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.network.chat.Component; +import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.SignItem; +import net.minecraft.world.item.context.DirectionalPlaceContext; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.SignBlockEntity; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.Vec3; +import net.minecraftforge.common.ForgeHooks; +import net.minecraftforge.event.entity.player.PlayerInteractEvent; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.Map; +import java.util.stream.Stream; import static de.srendi.advancedperipherals.common.addons.computercraft.operations.SingleOperation.DIG; import static de.srendi.advancedperipherals.common.addons.computercraft.operations.SingleOperation.USE_ON_BLOCK; +import static de.srendi.advancedperipherals.common.addons.computercraft.operations.SingleOperation.ACCURE_PLACE; public class AutomataBlockHandPlugin extends AutomataCorePlugin { @@ -71,4 +96,136 @@ public final MethodResult useOnBlock(@NotNull IArguments arguments) throws LuaEx }); } + /** + * @param options A table contains how to place the block: + * x: the x offset relative to the turtle. Default 0 + * y: the y offset relative to the turtle. Default 0 + * z: the z offset relative to the turtle. Default 0 + * forward: the direction the block is going to facing. Default is the facing direction of the turtle + * top: the direction the block's top is going to facing. Default is TOP + * anchor: the direction the block is going to hanging on. Default is same as forward + * text: the text going to write on the sign. Default is null + */ + @LuaFunction(mainThread = true) + public MethodResult placeBlock(@NotNull Map options) throws LuaException { + ITurtleAccess turtle = automataCore.getPeripheralOwner().getTurtle(); + CompassPeripheral compassPeripheral = Stream.of(TurtleSide.values()).map(side -> turtle.getPeripheral(side) instanceof CompassPeripheral compass ? compass : null).filter(peripheral -> peripheral != null).findFirst().orElse(null); + if (compassPeripheral == null || !compassPeripheral.isEnabled()) { + return MethodResult.of(false, "COMPASS_NOT_EQUIPPED"); + } + int x = TableHelper.optIntField(options, "x", 0); + int y = TableHelper.optIntField(options, "y", 0); + int z = TableHelper.optIntField(options, "z", 0); + final int maxDist = APConfig.PERIPHERALS_CONFIG.compassAccurePlaceRadius.get(); + final int freeDist = APConfig.PERIPHERALS_CONFIG.compassAccurePlaceFreeRadius.get(); + if (Math.abs(x) > maxDist || Math.abs(y) > maxDist || Math.abs(z) > maxDist) { + return MethodResult.of(null, "OUT_OF_RANGE"); + } + String anchor = TableHelper.optStringField(options, "anchor", null); + String forward = TableHelper.optStringField(options, "forward", null); + String top = TableHelper.optStringField(options, "top", null); + Direction anchorDir = anchor != null ? automataCore.validateSide(anchor) : null; + Direction forwardDir = forward != null ? automataCore.validateSide(forward) : null; + Direction topDir = top != null ? automataCore.validateSide(top) : null; + + int distance = + Math.max(0, Math.abs(x) - freeDist) + + Math.max(0, Math.abs(y) - freeDist) + + Math.max(0, Math.abs(z) - freeDist); + return automataCore.withOperation(ACCURE_PLACE, new SingleOperationContext(1, distance), context -> { + ItemStack stack = turtle.getInventory().getItem(turtle.getSelectedSlot()); + if (stack.isEmpty()) { + return MethodResult.of(null, "EMPTY_SLOT"); + } + BlockPos position = turtle.getPosition().offset(x, y, z); + String err = deployOn(stack, position, anchorDir, forwardDir, topDir, options); + if (err != null) { + return MethodResult.of(null, err); + } + return MethodResult.of(true); + }, null); + } + + /** + * @return A nullable string of the error. null means the operation is successful + */ + @Nullable + private String deployOn(ItemStack stack, BlockPos position, Direction anchor, Direction forward, Direction top, Map options) throws LuaException { + ITurtleAccess turtle = automataCore.getPeripheralOwner().getTurtle(); + Level world = turtle.getLevel(); + if (forward == null) { + forward = turtle.getDirection(); + } + if (top == null) { + top = Direction.UP; + } + if (anchor == null) { + anchor = forward; + } + TurtlePlayer turtlePlayer = TurtlePlayer.getWithPosition(turtle, position, forward.getOpposite()); + BlockHitResult hit = BlockHitResult.miss(Vec3.atCenterOf(position), top, position); + AdvanceDirectionalPlaceContext context = new AdvanceDirectionalPlaceContext(world, position, anchor, forward, stack, top); + PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock(turtlePlayer, InteractionHand.MAIN_HAND, position, hit); + if (event.isCanceled()) { + return "EVENT_CANCELED"; + } + Item item = stack.getItem(); + if (!(item instanceof BlockItem)) { + return "NOT_BLOCK"; + } + BlockItem block = (BlockItem) item; + InteractionResult res = block.place(context); + if (!res.consumesAction()) { + return "CANNOT_PLACE"; + } + if (block instanceof SignItem) { + BlockEntity blockEntity = world.getBlockEntity(position); + if (blockEntity instanceof SignBlockEntity sign) { + String text = StringUtil.convertAndToSectionMark(TableHelper.optStringField(options, "text", null)); + setSignText(world, sign, text); + } + } + return null; + } + + private static void setSignText(Level world, SignBlockEntity sign, String text) { + if (text == null) { + for (int i = 0; i < SignBlockEntity.LINES; i++) { + sign.setMessage(i, Component.literal("")); + } + } else { + String[] lines = text.split("\n"); + for (int i = 0; i < SignBlockEntity.LINES; i++) { + sign.setMessage(i, Component.literal(i < lines.length ? lines[i] : "")); + } + } + sign.setChanged(); + world.sendBlockUpdated(sign.getBlockPos(), sign.getBlockState(), sign.getBlockState(), Block.UPDATE_ALL); + } + + private class AdvanceDirectionalPlaceContext extends DirectionalPlaceContext { + private final Direction anchor; + + AdvanceDirectionalPlaceContext(Level world, BlockPos pos, Direction anchor, Direction forward, ItemStack stack, Direction top) { + super(world, pos, forward, stack, top); + this.anchor = anchor; + } + + @Override + public Direction getNearestLookingDirection() { + return this.anchor; + } + + @Override + public Direction[] getNearestLookingDirections() { + return switch (this.anchor) { + case DOWN -> new Direction[]{Direction.DOWN, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST, Direction.UP}; + case UP -> new Direction[]{Direction.UP, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST, Direction.DOWN}; + case NORTH -> new Direction[]{Direction.NORTH, Direction.EAST, Direction.WEST, Direction.UP, Direction.DOWN, Direction.SOUTH}; + case SOUTH -> new Direction[]{Direction.SOUTH, Direction.EAST, Direction.WEST, Direction.UP, Direction.DOWN, Direction.NORTH}; + case WEST -> new Direction[]{Direction.WEST, Direction.SOUTH, Direction.UP, Direction.NORTH, Direction.DOWN, Direction.EAST}; + case EAST -> new Direction[]{Direction.EAST, Direction.SOUTH, Direction.UP, Direction.NORTH, Direction.DOWN, Direction.WEST}; + }; + } + } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java index f64b79560..a31183cf4 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java @@ -70,8 +70,8 @@ public class PeripheralsConfig implements IAPConfig { // Compass turtle public final ForgeConfigSpec.BooleanValue enableCompassTurtle; - public final ForgeConfigSpec.IntValue compassTurtleRadius; - public final ForgeConfigSpec.IntValue compassTurtleFreeRadius; + public final ForgeConfigSpec.IntValue compassAccurePlaceRadius; + public final ForgeConfigSpec.IntValue compassAccurePlaceFreeRadius; // Powered Peripherals public final ForgeConfigSpec.BooleanValue enablePoweredPeripherals; @@ -158,8 +158,8 @@ public PeripheralsConfig() { pop("Compass_Turtle", builder); enableCompassTurtle = builder.comment("Enable the compass turtle or not.").define("enableCompassTurtle", true); - compassTurtleRadius = builder.comment("The maximum distance the compass turtle can reach in each axis.").defineInRange("compassTurtleRadius", 3, 0, 8); - compassTurtleFreeRadius = builder.comment("The free distance the compass turtle can reach in each axis.").defineInRange("compassTurtleFreeRadius", 1, 0, 4); + compassAccurePlaceRadius = builder.comment("The maximum distance the compass can locate accurately with in each axis.").defineInRange("compassAccurePlaceRadius", 3, 0, 8); + compassAccurePlaceFreeRadius = builder.comment("The free distance the compass can locate accurately with in each axis.").defineInRange("compassAccurePlaceFreeRadius", 1, 0, 4); pop("Powered_Peripherals", builder); diff --git a/src/main/java/de/srendi/advancedperipherals/lib/peripherals/AutomataCorePeripheral.java b/src/main/java/de/srendi/advancedperipherals/lib/peripherals/AutomataCorePeripheral.java index 00618d94b..6327b87f6 100644 --- a/src/main/java/de/srendi/advancedperipherals/lib/peripherals/AutomataCorePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/lib/peripherals/AutomataCorePeripheral.java @@ -10,7 +10,7 @@ import de.srendi.advancedperipherals.common.util.DataStorageUtil; import de.srendi.advancedperipherals.lib.metaphysics.IAutomataCoreTier; import net.minecraft.core.BlockPos; - +import net.minecraft.core.Direction; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -80,4 +80,8 @@ public boolean hasAttribute(String attribute) { public void setAttribute(String attribute) { attributes.put(attribute, true); } + + public Direction validateSide(String direction) throws LuaException { + return super.validateSide(direction); + } } From eaf8fc35942fcd7ff4ec0d30019a4c570c6671fb Mon Sep 17 00:00:00 2001 From: zyxkad Date: Tue, 30 Apr 2024 15:47:17 -0600 Subject: [PATCH 154/228] add comment for placeBlock method --- .../peripheral/plugins/AutomataBlockHandPlugin.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java index 45cccdede..36bd8c0c3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java @@ -97,6 +97,9 @@ public final MethodResult useOnBlock(@NotNull IArguments arguments) throws LuaEx } /** + * placeBlock method will make turtle place a block with more details when compass has equipped. + * It should not able to place fluids / use any item, because compass do not recognize them. + * * @param options A table contains how to place the block: * x: the x offset relative to the turtle. Default 0 * y: the y offset relative to the turtle. Default 0 From db8b9383eb4154322f26b844e8bb8104a2a75925 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Tue, 30 Apr 2024 15:49:10 -0600 Subject: [PATCH 155/228] add static keyword for internal class --- .../peripheral/plugins/AutomataBlockHandPlugin.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java index 36bd8c0c3..34937b709 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java @@ -97,7 +97,7 @@ public final MethodResult useOnBlock(@NotNull IArguments arguments) throws LuaEx } /** - * placeBlock method will make turtle place a block with more details when compass has equipped. + * placeBlock method will let turtle place a block with more details when compass has equipped. * It should not able to place fluids / use any item, because compass do not recognize them. * * @param options A table contains how to place the block: @@ -206,7 +206,7 @@ private static void setSignText(Level world, SignBlockEntity sign, String text) world.sendBlockUpdated(sign.getBlockPos(), sign.getBlockState(), sign.getBlockState(), Block.UPDATE_ALL); } - private class AdvanceDirectionalPlaceContext extends DirectionalPlaceContext { + private static class AdvanceDirectionalPlaceContext extends DirectionalPlaceContext { private final Direction anchor; AdvanceDirectionalPlaceContext(Level world, BlockPos pos, Direction anchor, Direction forward, ItemStack stack, Direction top) { From 3006ed739293522096895f066da9db97f3de0604 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Tue, 30 Apr 2024 16:09:13 -0600 Subject: [PATCH 156/228] remove extra empty lines --- .../addons/computercraft/peripheral/CompassPeripheral.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java index e1db290fa..5ee6e8eee 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/CompassPeripheral.java @@ -7,7 +7,6 @@ import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; - public class CompassPeripheral extends BasePeripheral { public static final String PERIPHERAL_TYPE = "compass"; @@ -29,5 +28,4 @@ public boolean isEnabled() { public String getFacing() { return owner.getFacing().toString(); } - } From 8a2210a1beaa7af019eb90f6045063599fce9a96 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Tue, 30 Apr 2024 17:27:48 -0600 Subject: [PATCH 157/228] fix typo forward -> front --- .../plugins/AutomataBlockHandPlugin.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java index 34937b709..f3308e49e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java @@ -104,9 +104,9 @@ public final MethodResult useOnBlock(@NotNull IArguments arguments) throws LuaEx * x: the x offset relative to the turtle. Default 0 * y: the y offset relative to the turtle. Default 0 * z: the z offset relative to the turtle. Default 0 - * forward: the direction the block is going to facing. Default is the facing direction of the turtle + * front: the direction the block is going to facing. Default is the facing direction of the turtle * top: the direction the block's top is going to facing. Default is TOP - * anchor: the direction the block is going to hanging on. Default is same as forward + * anchor: the direction the block is going to hanging on. Default is same as front * text: the text going to write on the sign. Default is null */ @LuaFunction(mainThread = true) @@ -125,10 +125,10 @@ public MethodResult placeBlock(@NotNull Map options) throws LuaException { return MethodResult.of(null, "OUT_OF_RANGE"); } String anchor = TableHelper.optStringField(options, "anchor", null); - String forward = TableHelper.optStringField(options, "forward", null); + String front = TableHelper.optStringField(options, "front", null); String top = TableHelper.optStringField(options, "top", null); Direction anchorDir = anchor != null ? automataCore.validateSide(anchor) : null; - Direction forwardDir = forward != null ? automataCore.validateSide(forward) : null; + Direction frontDir = front != null ? automataCore.validateSide(front) : null; Direction topDir = top != null ? automataCore.validateSide(top) : null; int distance = @@ -141,7 +141,7 @@ public MethodResult placeBlock(@NotNull Map options) throws LuaException { return MethodResult.of(null, "EMPTY_SLOT"); } BlockPos position = turtle.getPosition().offset(x, y, z); - String err = deployOn(stack, position, anchorDir, forwardDir, topDir, options); + String err = deployOn(stack, position, anchorDir, frontDir, topDir, options); if (err != null) { return MethodResult.of(null, err); } @@ -153,21 +153,21 @@ public MethodResult placeBlock(@NotNull Map options) throws LuaException { * @return A nullable string of the error. null means the operation is successful */ @Nullable - private String deployOn(ItemStack stack, BlockPos position, Direction anchor, Direction forward, Direction top, Map options) throws LuaException { + private String deployOn(ItemStack stack, BlockPos position, Direction anchor, Direction front, Direction top, Map options) throws LuaException { ITurtleAccess turtle = automataCore.getPeripheralOwner().getTurtle(); Level world = turtle.getLevel(); - if (forward == null) { - forward = turtle.getDirection(); + if (front == null) { + front = turtle.getDirection(); } if (top == null) { top = Direction.UP; } if (anchor == null) { - anchor = forward; + anchor = front; } - TurtlePlayer turtlePlayer = TurtlePlayer.getWithPosition(turtle, position, forward.getOpposite()); + TurtlePlayer turtlePlayer = TurtlePlayer.getWithPosition(turtle, position, front.getOpposite()); BlockHitResult hit = BlockHitResult.miss(Vec3.atCenterOf(position), top, position); - AdvanceDirectionalPlaceContext context = new AdvanceDirectionalPlaceContext(world, position, anchor, forward, stack, top); + AdvanceDirectionalPlaceContext context = new AdvanceDirectionalPlaceContext(world, position, anchor, front, stack, top); PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock(turtlePlayer, InteractionHand.MAIN_HAND, position, hit); if (event.isCanceled()) { return "EVENT_CANCELED"; @@ -209,8 +209,8 @@ private static void setSignText(Level world, SignBlockEntity sign, String text) private static class AdvanceDirectionalPlaceContext extends DirectionalPlaceContext { private final Direction anchor; - AdvanceDirectionalPlaceContext(Level world, BlockPos pos, Direction anchor, Direction forward, ItemStack stack, Direction top) { - super(world, pos, forward, stack, top); + AdvanceDirectionalPlaceContext(Level world, BlockPos pos, Direction anchor, Direction front, ItemStack stack, Direction top) { + super(world, pos, front, stack, top); this.anchor = anchor; } From e40cd538636c90b41e0ee094114aa8d4c87b8246 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Tue, 30 Apr 2024 22:10:36 -0600 Subject: [PATCH 158/228] make the directions makes more sense --- .../computercraft/owner/TurtlePeripheralOwner.java | 5 +---- .../peripheral/plugins/AutomataBlockHandPlugin.java | 12 ++++++------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/TurtlePeripheralOwner.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/TurtlePeripheralOwner.java index 02ad29cea..c2709e02d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/TurtlePeripheralOwner.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/TurtlePeripheralOwner.java @@ -55,13 +55,10 @@ public Direction getFacing() { return turtle.getDirection(); } - /** - * Not used for turtles - */ @NotNull @Override public FrontAndTop getOrientation() { - return FrontAndTop.NORTH_UP; + return FrontAndTop.fromFrontAndTop(getFacing(), Direction.UP); } @Nullable diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java index f3308e49e..a92143043 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java @@ -104,9 +104,9 @@ public final MethodResult useOnBlock(@NotNull IArguments arguments) throws LuaEx * x: the x offset relative to the turtle. Default 0 * y: the y offset relative to the turtle. Default 0 * z: the z offset relative to the turtle. Default 0 - * front: the direction the block is going to facing. Default is the facing direction of the turtle + * anchor: the direction the block is going to hanging on. Default is the direction of the turtle + * front: the direction the block is going to facing. Default is same as anchor * top: the direction the block's top is going to facing. Default is TOP - * anchor: the direction the block is going to hanging on. Default is same as front * text: the text going to write on the sign. Default is null */ @LuaFunction(mainThread = true) @@ -156,15 +156,15 @@ public MethodResult placeBlock(@NotNull Map options) throws LuaException { private String deployOn(ItemStack stack, BlockPos position, Direction anchor, Direction front, Direction top, Map options) throws LuaException { ITurtleAccess turtle = automataCore.getPeripheralOwner().getTurtle(); Level world = turtle.getLevel(); + if (anchor == null) { + anchor = turtle.getDirection(); + } if (front == null) { - front = turtle.getDirection(); + front = anchor; } if (top == null) { top = Direction.UP; } - if (anchor == null) { - anchor = front; - } TurtlePlayer turtlePlayer = TurtlePlayer.getWithPosition(turtle, position, front.getOpposite()); BlockHitResult hit = BlockHitResult.miss(Vec3.atCenterOf(position), top, position); AdvanceDirectionalPlaceContext context = new AdvanceDirectionalPlaceContext(world, position, anchor, front, stack, top); From 1de7972c0e3439d3e2401061faea619b792fb27b Mon Sep 17 00:00:00 2001 From: zyxkad Date: Wed, 1 May 2024 07:35:10 -0600 Subject: [PATCH 159/228] fix playNote will not trigger alley fix #603 --- .../addons/computercraft/integrations/NoteBlockIntegration.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/NoteBlockIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/NoteBlockIntegration.java index b0b5c83c7..ad5a653d3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/NoteBlockIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/NoteBlockIntegration.java @@ -7,6 +7,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.NoteBlock; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.gameevent.GameEvent; import org.jetbrains.annotations.NotNull; public class NoteBlockIntegration extends BlockIntegrationPeripheral { @@ -50,6 +51,7 @@ public final int getNote() { public final void playNote() { if (world.isEmptyBlock(pos.above())) { world.blockEvent(pos, getBlock(), 0, 0); + world.gameEvent(null, GameEvent.NOTE_BLOCK_PLAY, pos); } } } From bd047e5d0ff89d9250af50b8fd4460f294c76567 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Wed, 1 May 2024 07:35:10 -0600 Subject: [PATCH 160/228] fix playNote will not trigger alley fix #603 --- .../addons/computercraft/integrations/NoteBlockIntegration.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/NoteBlockIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/NoteBlockIntegration.java index b0b5c83c7..ad5a653d3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/NoteBlockIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/NoteBlockIntegration.java @@ -7,6 +7,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.NoteBlock; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.gameevent.GameEvent; import org.jetbrains.annotations.NotNull; public class NoteBlockIntegration extends BlockIntegrationPeripheral { @@ -50,6 +51,7 @@ public final int getNote() { public final void playNote() { if (world.isEmptyBlock(pos.above())) { world.blockEvent(pos, getBlock(), 0, 0); + world.gameEvent(null, GameEvent.NOTE_BLOCK_PLAY, pos); } } } From ed906c48697ebfdc86d268743a8e7aa280ae5d36 Mon Sep 17 00:00:00 2001 From: Srendi Date: Thu, 2 May 2024 18:10:47 +0200 Subject: [PATCH 161/228] Revert "Merge branch 'dev/0.8' into dev/1.19.2" This reverts commit 70fcad1deace2e3de1877e562ca693d1bbc41316, reversing changes made to 529d8a6ef3a4b662d39045bcee856264014d087a. --- .github/FUNDING.yml | 3 +- README.md | 2 +- build.gradle | 36 +- config/checkstyle/checkstyle.xml | 1 + gradle.properties | 17 +- qodana.yaml | 3 +- .../2db41954e490230d51b10affff25ee2ee27b8d5b | 2 +- .../5a761efb7472ef97566e41e81451930a004134bf | 2 +- .../67cce32b1c3cbbcb1f646605f4914e3f196986c2 | 5 +- .../9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e | 4 +- .../ae219fa7c7d3297c14e454863eac3998a4eab78c | 2 +- .../b8526e444ae7356037f3a813274f6835d1f3dd16 | 2 +- .../c622617f6fabf890a00b9275cd5f643584a8a2c8 | 4 +- .../f95c7003282837dabaa33e3ffceec4e6865b5218 | 8 +- .../advancedperipherals/lang/en_us.json | 13 +- .../loot_tables/blocks/distance_detector.json | 20 - .../loot_tables/blocks/fluid_detector.json | 20 - .../loot_tables/blocks/gas_detector.json | 20 - .../forge/tags/blocks/needs_wood_tool.json | 3 +- .../tags/blocks/mineable/pickaxe.json | 5 +- .../tags/blocks/needs_iron_tool.json | 6 +- .../advancedperipherals/APCreativeTab.java | 8 +- .../AdvancedPeripherals.java | 16 +- .../client/ClientRegistry.java | 24 +- .../client/ItemPropertiesRegistry.java | 17 - .../client/KeyBindings.java | 2 - .../renderer/DistanceDetectorRenderer.java | 97 --- .../client/screens/SmartGlassesScreen.java | 78 --- .../widgets/SmartGlassesSettingsSwitch.java | 85 --- .../common/addons/APAddons.java | 38 +- .../addons/appliedenergistics/AppEngApi.java | 512 ++------------ .../addons/appliedenergistics/CraftJob.java | 1 + .../MeBridgeEntityListener.java | 5 +- .../appliedenergistics/MeFluidHandler.java | 5 +- .../addons/botania/ManaFlowerIntegration.java | 2 +- .../addons/botania/ManaPoolIntegration.java | 2 +- .../addons/botania/SpreaderIntegration.java | 2 +- .../integrations/BeaconIntegration.java | 5 +- .../IntegrationPeripheralProvider.java | 2 +- .../operations/SingleOperation.java | 10 +- .../owner/BasePeripheralOwner.java | 2 +- .../owner/BlockEntityPeripheralOwner.java | 8 +- .../computercraft/owner/FuelAbility.java | 2 +- .../owner/PeripheralOwnerAbility.java | 2 +- .../owner/PocketPeripheralOwner.java | 8 +- .../peripheral/BlockReaderPeripheral.java | 2 +- .../peripheral/ChatBoxPeripheral.java | 10 +- .../peripheral/ColonyPeripheral.java | 4 +- .../DistanceDetectorPeripheral.java | 103 --- .../peripheral/EnergyDetectorPeripheral.java | 2 +- .../EnvironmentDetectorPeripheral.java | 14 +- .../peripheral/FluidDetectorPeripheral.java | 43 -- .../peripheral/GasDetectorPeripheral.java | 42 -- .../peripheral/GeoScannerPeripheral.java | 2 +- .../InventoryManagerPeripheral.java | 13 +- .../peripheral/MeBridgePeripheral.java | 653 ++++++------------ .../peripheral/NBTStoragePeripheral.java | 2 +- .../peripheral/PlayerDetectorPeripheral.java | 2 +- .../RedstoneIntegratorPeripheral.java | 2 +- .../peripheral/RsBridgePeripheral.java | 286 ++------ .../EndAutomataCorePeripheral.java | 2 +- .../HusbandryAutomataCorePeripheral.java | 2 +- .../OverpoweredEndAutomataCorePeripheral.java | 2 +- ...oweredHusbandryAutomataCorePeripheral.java | 3 +- ...OverpoweredWeakAutomataCorePeripheral.java | 3 +- .../WeakAutomataCorePeripheral.java | 8 +- .../plugins/AutomataBlockHandPlugin.java | 4 +- .../plugins/AutomataItemSuckPlugin.java | 2 +- .../addons/create/BasinIntegration.java | 14 +- .../addons/create/BlazeBurnerIntegration.java | 2 +- .../addons/create/FluidTankIntegration.java | 2 +- .../create/MechanicalMixerIntegration.java | 2 +- .../ScrollValueBehaviourIntegration.java | 2 +- .../dimstorage/DimChestIntegration.java | 55 -- .../common/addons/dimstorage/Integration.java | 12 - .../addons/mekanism/MekanismCapabilities.java | 15 - .../addons/minecolonies/MineColonies.java | 4 +- .../addons/powah/EnderCellIntegration.java | 2 +- .../addons/powah/EnergyCellIntegration.java | 2 +- .../addons/powah/ReactorIntegration.java | 2 +- .../addons/powah/SolarPanelIntegration.java | 2 +- .../addons/refinedstorage/RefinedStorage.java | 68 +- .../addons/refinedstorage/RsFluidHandler.java | 4 +- .../addons/refinedstorage/RsItemHandler.java | 4 +- .../common/blocks/PlayerDetectorBlock.java | 6 +- .../blocks/RedstoneIntegratorBlock.java | 8 +- .../blocks/base/BaseBlockEntityBlock.java | 3 +- .../common/blocks/base/IInventoryBlock.java | 2 + .../blocks/base/PeripheralBlockEntity.java | 9 +- .../base/PoweredPeripheralBlockEntity.java | 2 +- .../blockentities/BlockReaderEntity.java | 4 +- .../blocks/blockentities/ChatBoxEntity.java | 5 +- .../blockentities/ColonyIntegratorEntity.java | 4 +- .../blockentities/DistanceDetectorEntity.java | 164 ----- .../blockentities/EnergyDetectorEntity.java | 33 +- .../EnvironmentDetectorEntity.java | 4 +- .../blockentities/FluidDetectorEntity.java | 106 --- .../blockentities/GasDetectorEntity.java | 106 --- .../blockentities/GeoScannerEntity.java | 4 +- .../blockentities/InventoryManagerEntity.java | 4 +- .../blocks/blockentities/MeBridgeEntity.java | 8 +- .../blockentities/NBTStorageEntity.java | 4 +- .../blockentities/PlayerDetectorEntity.java | 4 +- .../RedstoneIntegratorEntity.java | 6 +- .../blocks/blockentities/RsBridgeEntity.java | 4 +- .../common/commands/APCommands.java | 4 +- .../common/configuration/GeneralConfig.java | 1 + .../configuration/PeripheralsConfig.java | 36 +- .../container/InventoryManagerContainer.java | 11 +- .../container}/InventoryManagerScreen.java | 5 +- .../container/SmartGlassesContainer.java | 100 --- .../container}/base/BaseItemScreen.java | 10 +- .../container}/base/BaseScreen.java | 5 +- .../common/container/base/SlotCondition.java | 10 +- .../common/data/BlockLootTables.java | 6 +- .../data/BlockStatesAndModelsProvider.java | 35 +- .../common/data/DataGenerators.java | 5 +- .../common/data/EnUsLanguageProvider.java | 111 ++- .../common/data/PocketUpgradesProvider.java | 12 +- .../common/data/PoiTypeProvider.java | 6 +- .../common/data/RecipesProvider.java | 101 +-- .../common/data/TurtleUpgradesProvider.java | 26 +- .../common/items/APBlockItem.java | 25 +- .../common/items/APItem.java | 26 +- .../items/SmartGlassesInterfaceItem.java | 71 -- .../common/items/SmartGlassesItem.java | 304 -------- .../common/items/WeakAutomataCore.java | 19 +- .../items/base/SmartGlassesMaterials.java | 73 -- .../common/network/PacketHandler.java | 75 -- .../toclient/DistanceDetectorSyncPacket.java | 59 -- .../network/toserver/GlassesHotkeyPacket.java | 55 -- .../common/setup/APBlockEntityTypes.java | 30 - .../common/setup/APBlocks.java | 58 -- .../common/setup/APContainerTypes.java | 28 - .../common/setup/APItems.java | 33 - .../common/setup/APVillagers.java | 20 - .../common/setup/BlockEntityTypes.java | 27 + .../common/setup/Blocks.java | 53 ++ .../common/setup/CCRegistration.java | 56 +- .../common/setup/ContainerTypes.java | 20 + .../common/setup/Items.java | 25 + ...{APRegistration.java => Registration.java} | 12 +- .../common/setup/Villagers.java | 19 + .../common/smartglasses/SlotType.java | 22 - .../common/smartglasses/SmartGlassesAPI.java | 11 - .../smartglasses/SmartGlassesAccess.java | 67 -- .../smartglasses/SmartGlassesComputer.java | 213 ------ .../smartglasses/SmartGlassesItemHandler.java | 147 ---- .../SmartGlassesMenuProvider.java | 43 -- .../common/smartglasses/SmartGlassesSlot.java | 42 -- .../common/smartglasses/modules/IModule.java | 38 - .../modules/IModuleFunctions.java | 13 - .../smartglasses/modules/IModuleItem.java | 24 - .../modules/ModulePeripheral.java | 29 - .../modules/ModulePeripheralOwner.java | 114 --- .../modules/hotkey/HotkeyModule.java | 21 - .../modules/hotkey/HotkeyModuleItem.java | 58 -- .../nightvision/NightVisionFunctions.java | 24 - .../nightvision/NightVisionModule.java | 48 -- .../nightvision/NightVisionModuleItem.java | 40 -- .../modules/overlay/ObjectProperty.java | 22 - .../overlay/OverlayGlassesFunctions.java | 42 -- .../modules/overlay/OverlayGlassesItem.java | 19 - .../modules/overlay/OverlayModule.java | 69 -- .../modules/overlay/OverlayObject.java | 194 ------ .../smartglasses/modules/overlay/Panel.java | 61 -- .../modules/overlay/RenderableObject.java | 47 -- .../propertyTypes/BooleanProperty.java | 15 - .../overlay/propertyTypes/BooleanType.java | 20 - .../FixedPointNumberProperty.java | 18 - .../propertyTypes/FixedPointNumberType.java | 34 - .../propertyTypes/FloatingNumberProperty.java | 18 - .../propertyTypes/FloatingNumberType.java | 29 - .../overlay/propertyTypes/PropertyType.java | 31 - .../common/util/CoordUtil.java | 10 +- .../common/util/EnumColor.java | 46 +- .../common/util/FluidStorageProxy.java | 92 --- .../common/util/GasStorageProxy.java | 99 --- .../common/util/HitResultUtil.java | 157 ----- .../common/util/LuaConverter.java | 50 +- .../advancedperipherals/common/util/Pair.java | 4 +- .../common/util/ServerWorker.java | 4 +- .../common/util/StringUtil.java | 7 - .../common/util/ZeroGasTank.java | 47 -- .../fakeplayer/FakePlayerProviderTurtle.java | 5 +- .../common/util/inventory/FluidFilter.java | 12 +- .../common/util/inventory/GenericFilter.java | 69 -- .../inventory/IStorageSystemFluidHandler.java | 2 +- .../inventory/IStorageSystemItemHandler.java | 1 - .../inventory/IStorageSystemPeripheral.java | 100 --- .../common/util/inventory/ItemFilter.java | 16 +- .../common/util/inventory/ItemUtil.java | 15 + .../common/village/VillagerTrade.java | 38 +- .../common/village/VillagerTrades.java | 32 +- .../metaphysics/IFeedableAutomataCore.java | 3 +- .../network/APNetworking.java | 75 ++ .../{common => }/network/base/IPacket.java | 2 +- .../network/toclient/ToastToClientPacket.java | 4 +- .../resources/META-INF/accesstransformer.cfg | 2 - .../models/item/ar_goggles.json | 6 + .../models/item/memory_card.json | 12 +- .../models/item/memory_card_bounded.json | 6 - .../models/item/smart_glasses.json | 6 - .../textures/gui/corners_glasses.png | Bin 999 -> 0 bytes .../textures/gui/smart_glasses_gui.png | Bin 1974 -> 0 bytes .../{smart_glasses.png => ar_goggles.png} | Bin .../{slot => item}/empty_glasses_slot.png | Bin .../textures/item/memory_card.png | Bin 702 -> 774 bytes .../textures/item/memory_card_bounded.png | Bin 699 -> 0 bytes .../textures/models/ar_goggles.png | Bin 0 -> 1133 bytes .../models/armor/smart_glasses_layer_1.png | Bin 191 -> 0 bytes .../loot_tables/chest/scientist_common.json | 133 ---- .../structures/villages/scientist_taiga.nbt | Bin 6265 -> 4478 bytes .../computercraft/lua/rom/programs/flat.lua | 1 - src/main/resources/pack.mcmeta | 3 +- 215 files changed, 1185 insertions(+), 6018 deletions(-) delete mode 100644 src/generated/resources/data/advancedperipherals/loot_tables/blocks/distance_detector.json delete mode 100644 src/generated/resources/data/advancedperipherals/loot_tables/blocks/fluid_detector.json delete mode 100644 src/generated/resources/data/advancedperipherals/loot_tables/blocks/gas_detector.json delete mode 100644 src/main/java/de/srendi/advancedperipherals/client/ItemPropertiesRegistry.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/client/screens/SmartGlassesScreen.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/client/widgets/SmartGlassesSettingsSwitch.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/FluidDetectorPeripheral.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/GasDetectorPeripheral.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/addons/dimstorage/DimChestIntegration.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/addons/dimstorage/Integration.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/MekanismCapabilities.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/FluidDetectorEntity.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/GasDetectorEntity.java rename src/main/java/de/srendi/advancedperipherals/{client/screens => common/container}/InventoryManagerScreen.java (78%) delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java rename src/main/java/de/srendi/advancedperipherals/{client/screens => common/container}/base/BaseItemScreen.java (73%) rename src/main/java/de/srendi/advancedperipherals/{client/screens => common/container}/base/BaseScreen.java (86%) delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesInterfaceItem.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/items/base/SmartGlassesMaterials.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/network/PacketHandler.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/network/toclient/DistanceDetectorSyncPacket.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/network/toserver/GlassesHotkeyPacket.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/setup/APVillagers.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/setup/BlockEntityTypes.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/setup/Blocks.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/setup/ContainerTypes.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/setup/Items.java rename src/main/java/de/srendi/advancedperipherals/common/setup/{APRegistration.java => Registration.java} (92%) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/setup/Villagers.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/SlotType.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesAPI.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesAccess.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesMenuProvider.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesSlot.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModuleFunctions.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModuleItem.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheralOwner.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModule.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModuleItem.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/nightvision/NightVisionFunctions.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/nightvision/NightVisionModule.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/nightvision/NightVisionModuleItem.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/ObjectProperty.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesFunctions.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesItem.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayObject.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/Panel.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/RenderableObject.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/BooleanProperty.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/BooleanType.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FixedPointNumberProperty.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FixedPointNumberType.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FloatingNumberProperty.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FloatingNumberType.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/PropertyType.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/util/FluidStorageProxy.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/util/GasStorageProxy.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/util/ZeroGasTank.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java delete mode 100644 src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java create mode 100644 src/main/java/de/srendi/advancedperipherals/network/APNetworking.java rename src/main/java/de/srendi/advancedperipherals/{common => }/network/base/IPacket.java (89%) rename src/main/java/de/srendi/advancedperipherals/{common => }/network/toclient/ToastToClientPacket.java (90%) create mode 100644 src/main/resources/assets/advancedperipherals/models/item/ar_goggles.json delete mode 100644 src/main/resources/assets/advancedperipherals/models/item/memory_card_bounded.json delete mode 100644 src/main/resources/assets/advancedperipherals/models/item/smart_glasses.json delete mode 100644 src/main/resources/assets/advancedperipherals/textures/gui/corners_glasses.png delete mode 100644 src/main/resources/assets/advancedperipherals/textures/gui/smart_glasses_gui.png rename src/main/resources/assets/advancedperipherals/textures/item/{smart_glasses.png => ar_goggles.png} (100%) rename src/main/resources/assets/advancedperipherals/textures/{slot => item}/empty_glasses_slot.png (100%) delete mode 100644 src/main/resources/assets/advancedperipherals/textures/item/memory_card_bounded.png create mode 100644 src/main/resources/assets/advancedperipherals/textures/models/ar_goggles.png delete mode 100644 src/main/resources/assets/advancedperipherals/textures/models/armor/smart_glasses_layer_1.png delete mode 100644 src/main/resources/data/advancedperipherals/loot_tables/chest/scientist_common.json delete mode 100644 src/main/resources/data/computercraft/lua/rom/programs/flat.lua diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 66d7109fd..4cd1fe88c 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,2 +1 @@ -ko_fi: srendi -github: SirEndii \ No newline at end of file +patreon: srendi diff --git a/README.md b/README.md index 78c94213d..74d5d8a3e 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ will close pull requests related to translations. [CurseForge]: https://www.curseforge.com/minecraft/mc-mods/advanced-peripherals [Actions]: https://github.com/Seniorendi/AdvancedPeripherals/actions [Crowdin]: https://crowdin.com/project/advanced-peripherals -[Discord]: https://discord.intelligence-modding.de +[Discord]: https://discord.com/invite/QuF3hWDtWC [Banner]: https://www.bisecthosting.com/images/CF/Advanced_Peripherals/BH_AP_Header.png 'Advanced Peripherals' [PeripheralsPlusOne]: https://github.com/rolandoislas/PeripheralsPlusOne diff --git a/build.gradle b/build.gradle index 65efa6a1c..cea635d97 100644 --- a/build.gradle +++ b/build.gradle @@ -260,20 +260,12 @@ dependencies { compileOnly "org.jetbrains:annotations:${jb_annotations}" minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation fg.deobf("org.squiddev:cc-tweaked-${minecraft_version}:${cc_version}") - // Compile-time API required - // Ae2 - implementation fg.deobf("appeng:appliedenergistics2-forge:${appliedenergistics_version}") - - // Applied Mekanistics - implementation fg.deobf("curse.maven:applied-mekanistics-574300:${appliedmekanistics_version}") - - // Curios - implementation fg.deobf("top.theillusivec4.curios:curios-forge:${curios_version}:api") // Minimal requirements end // Extended requirements // We don't use the api since we need a specific class from mekanism - implementation fg.deobf("mekanism:Mekanism:${mekanism_version}") + compileOnly fg.deobf("mekanism:Mekanism:${mekanism_version}") + runtimeOnly fg.deobf("mekanism:Mekanism:${mekanism_version}") // Applied Energistics 2 compileOnly fg.deobf("appeng:appliedenergistics2-forge:${appliedenergistics_version}") @@ -324,27 +316,24 @@ dependencies { runtimeOnly fg.deobf("com.ldtteam:blockui:${blockui_version}") //Patchouli + compileOnly fg.deobf("vazkii.patchouli:Patchouli:${patchouli_version}") runtimeOnly fg.deobf("vazkii.patchouli:Patchouli:${patchouli_version}") // Create compileOnly fg.deobf("com.simibubi.create:create-${minecraft_version}:${create_version}:all") - // runtimeOnly fg.deobf("com.simibubi.create:create-${minecraft_version}:${create_version}:all") - - //DimStorage - compileOnly fg.deobf("curse.maven:dimstorage-353882:${dimstorage_version}") - runtimeOnly fg.deobf("curse.maven:dimstorage-353882:${dimstorage_version}") - compileOnly fg.deobf("curse.maven:edivadlib-638508:${edivadlib_version}") - runtimeOnly fg.deobf("curse.maven:edivadlib-638508:${edivadlib_version}") + runtimeOnly fg.deobf("com.simibubi.create:create-${minecraft_version}:${create_version}:all") //Removed until fully ported //testImplementation fg.deobf("site.siredvin.ttoolkit:ttoolkit-${minecraft_version}:${ttoolkit_version}") //Powah compileOnly fg.deobf("curse.maven:powah-633483:${powah_version}") - compileOnly fg.deobf("me.shedaniel.cloth:cloth-config-forge:8.2.88") - compileOnly fg.deobf("dev.architectury:architectury-forge:6.2.43") + runtimeOnly fg.deobf("curse.maven:powah-633483:${powah_version}") + runtimeOnly fg.deobf("me.shedaniel.cloth:cloth-config-forge:8.2.88") + runtimeOnly fg.deobf("dev.architectury:architectury-forge:6.2.43") - compileOnly fg.deobf("curse.maven:crash-utilities-371813:4406293") + // Crash utilities. Used to debug the chunky turtle. Can be uncommented if not needed + runtimeOnly fg.deobf("curse.maven:crash-utilities-371813:4406293") testImplementation "org.junit.jupiter:junit-jupiter-api:${junit_version}" testImplementation "org.junit.jupiter:junit-jupiter-params:${junit_version}" @@ -358,9 +347,6 @@ dependencies { // JEI implementation fg.deobf("mezz.jei:jei-${jei_version}") - // Jade - implementation fg.deobf("curse.maven:jade-324717:${jade_version}") - // Create Crafts & Additions compileOnly fg.deobf("curse.maven:createaddition-439890:5099757") // runtimeOnly fg.deobf("curse.maven:createaddition-439890:5099757") @@ -503,7 +489,7 @@ tasks.register('publishCurseForge', TaskPublishCurseForge, { task -> addRequirement('cc-tweaked') - addModLoader("forge") + addModLoader("forge", "neoforge") releaseType = "${release_type}" } @@ -538,7 +524,7 @@ modrinth { versionType = release_type uploadFile = jar gameVersions = [minecraft_version] - loaders = ["forge"] + loaders = ["forge", "neoforge"] dependencies { required.project "cc-tweaked" } diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml index a379e1d45..7ca06cbc2 100644 --- a/config/checkstyle/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -37,6 +37,7 @@ + diff --git a/gradle.properties b/gradle.properties index bb8f4e723..5fb9d7792 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,26 +7,26 @@ mod_id=advancedperipherals minecraft_version=1.19.2 forge_version=43.3.8 loader_version=43 -mod_version=0.8r +mod_version=0.7.36r release_type=release mappings_channel=parchment -mappings_version=2022.11.20-1.19.2 +mappings_version=2022.11.27-1.19.2 jb_annotations=21.0.1 # Test dependencies junit_version=5.7.2 hamcrest_version=2.2 kotlin_version=1.8.0 -kotlinx_coroutines_version=1.7.3 +kotlinx_coroutines_version=1.6.0-RC3 ttoolkit_version=0.1.3 # Mod dependencies cc_version=1.101.3 curios_version=1.19.2-5.1.4.1 minecolonies_version=1.19.2-1.1.473-BETA -appliedenergistics_version=12.9.9 +appliedenergistics_version=12.9.5 patchouli_version=1.19.2-77 -refinedstorage_version=1.11.7 +refinedstorage_version=1.11.6 botania_version=1.19.2-440-FORGE create_version=0.5.1.f-46 createca_version=5099757 @@ -36,7 +36,6 @@ powah_version=4183078 ae2additions_version=4646599 kotlinforforge_version=3.12.0 appliedmekanistics_version=4734608 -dimstorage_version=3927875 # Mod dependencies which are needed for other mods # For minecolonies @@ -45,9 +44,5 @@ multipiston_version=1.19.2-1.2.21-ALPHA blockui_version=1.19.2-0.0.102-ALPHA domumornamentum_version=1.19-1.0.141-BETA -# For DimStorage -edivadlib_version=3927847 - # Mod dependencies for testing stuff(Only used in the dev environment) -jei_version=1.19.2-forge:11.6.0.1016 -jade_version=4914105 \ No newline at end of file +jei_version=1.19.2-forge:11.6.0.1016 \ No newline at end of file diff --git a/qodana.yaml b/qodana.yaml index f2df31528..dfc5cbb26 100644 --- a/qodana.yaml +++ b/qodana.yaml @@ -16,8 +16,7 @@ exclude: - src/test/resources/* - src/testMod/resources/* - src/server-files/resources/* - - name: CheckDependencyLicenses - include: + - name: CheckDependencyLicenses - name: TrivialIf - name: NullableProblems \ No newline at end of file diff --git a/src/generated/resources/.cache/2db41954e490230d51b10affff25ee2ee27b8d5b b/src/generated/resources/.cache/2db41954e490230d51b10affff25ee2ee27b8d5b index 834374d4a..f319707e2 100644 --- a/src/generated/resources/.cache/2db41954e490230d51b10affff25ee2ee27b8d5b +++ b/src/generated/resources/.cache/2db41954e490230d51b10affff25ee2ee27b8d5b @@ -1,2 +1,2 @@ -// 1.19.2 2023-09-25T15:21:21.7663044 AP POI Type Tags +// 1.19.2 2023-07-19T14:31:39.6951106 AP POI Type Tags d3d6b837660a4e213f287ad9d11e12368b90cd8e data/minecraft/tags/point_of_interest_type/acquirable_job_site.json diff --git a/src/generated/resources/.cache/5a761efb7472ef97566e41e81451930a004134bf b/src/generated/resources/.cache/5a761efb7472ef97566e41e81451930a004134bf index 863bee0d1..cb8219ecf 100644 --- a/src/generated/resources/.cache/5a761efb7472ef97566e41e81451930a004134bf +++ b/src/generated/resources/.cache/5a761efb7472ef97566e41e81451930a004134bf @@ -1,4 +1,4 @@ -// 1.19.2 2023-09-25T15:21:21.7927076 Turtle Upgrades +// 1.19.2 2023-07-19T14:31:39.6751301 Turtle Upgrades b8f19ae0fb5bb898facc08e3787e0f96c8211881 data/advancedperipherals/computercraft/turtle_upgrades/chatty_turtle.json fe98c60e7d61139aacf2d0872873e610aac8a37b data/advancedperipherals/computercraft/turtle_upgrades/chunky_turtle.json ae619da638ad89d7302d832d6c09e2c87401c539 data/advancedperipherals/computercraft/turtle_upgrades/compass_turtle.json diff --git a/src/generated/resources/.cache/67cce32b1c3cbbcb1f646605f4914e3f196986c2 b/src/generated/resources/.cache/67cce32b1c3cbbcb1f646605f4914e3f196986c2 index 5362386e5..b767c20d4 100644 --- a/src/generated/resources/.cache/67cce32b1c3cbbcb1f646605f4914e3f196986c2 +++ b/src/generated/resources/.cache/67cce32b1c3cbbcb1f646605f4914e3f196986c2 @@ -1,12 +1,9 @@ -// 1.19.2 2023-09-25T15:21:21.7873091 LootTables +// 1.19.2 2024-01-15T20:01:57.516745 LootTables d865e8ac35302c486faf5c7122569c554186186d data/advancedperipherals/loot_tables/blocks/block_reader.json a6f896cc3dbd8da12737825ec71e32970f54025c data/advancedperipherals/loot_tables/blocks/chat_box.json f50f506ae1987537f76be4c05a81689b25798f91 data/advancedperipherals/loot_tables/blocks/colony_integrator.json -4dcad851450e4ddd8d28a0017a417bf6e5579bda data/advancedperipherals/loot_tables/blocks/distance_detector.json 1d1b858d09538dc66bab2c33a2f9c58361a9c472 data/advancedperipherals/loot_tables/blocks/energy_detector.json 317004b1358ef9bf83957d2d6796529a226161c7 data/advancedperipherals/loot_tables/blocks/environment_detector.json -df6186990887f77b7db37ebb8ee50a7e7f096b0a data/advancedperipherals/loot_tables/blocks/fluid_detector.json -cea5a036d4ccdcc6ef026d1a226b5e13f1060676 data/advancedperipherals/loot_tables/blocks/gas_detector.json d5a3964f518b138cbd7305c819a36af3d9340e4a data/advancedperipherals/loot_tables/blocks/geo_scanner.json 8aa1deea908fd02f049e047c8ca16679bbef68a2 data/advancedperipherals/loot_tables/blocks/inventory_manager.json 9a2898a63e2e0c087ce8eba211c63d1c8b9fd4aa data/advancedperipherals/loot_tables/blocks/me_bridge.json diff --git a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e index 57b11e7d4..949aa05ae 100644 --- a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e +++ b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e @@ -1,5 +1,4 @@ -// 1.19.2 2023-09-27T10:45:57.2509102 Recipes -045608027e4a5ea2d7dee7f402346b8e69f21675 data/advancedperipherals/advancements/recipes/advancedperipheralstab/armor/smart_glasses_netherite.json +// 1.19.2 2024-01-15T20:01:57.5157458 Recipes db2dada2fdf42ca1bbf47f1eb075d1f9de89dfa8 data/advancedperipherals/advancements/recipes/advancedperipheralstab/block_reader.json 77c55e8500be4a344ca563a8bf7642257cdc7b8b data/advancedperipherals/advancements/recipes/advancedperipheralstab/chat_box.json 96208b06b0c3c125762cd517506a5ffb6b1d55ac data/advancedperipherals/advancements/recipes/advancedperipheralstab/chunk_controller.json @@ -17,7 +16,6 @@ d27c1267208fd9036c5c45f7f6cbd4f6f67b3845 data/advancedperipherals/advancements/r d8870644bb7d48c5ae33dcea2afbcfa106729d7b data/advancedperipherals/advancements/recipes/advancedperipheralstab/player_detector.json 7acff70533792bd089a655f8f24cdea6995aac0c data/advancedperipherals/advancements/recipes/advancedperipheralstab/redstone_integrator.json fc0c3d99bec43318802f357083c7d98fde92567f data/advancedperipherals/advancements/recipes/advancedperipheralstab/weak_automata_core.json -66999fea36aa4113567753f104630f6490dda6ba data/advancedperipherals/recipes/armor/smart_glasses_netherite.json b10b5cbcc668438001744d5b90d9838ab4d293cb data/advancedperipherals/recipes/block_reader.json 3c9618832fe0ac32cac0f04fbc5afad225418239 data/advancedperipherals/recipes/chat_box.json a78adfcca4c7579b143aac5648a7eca9085c0dba data/advancedperipherals/recipes/chunk_controller.json diff --git a/src/generated/resources/.cache/ae219fa7c7d3297c14e454863eac3998a4eab78c b/src/generated/resources/.cache/ae219fa7c7d3297c14e454863eac3998a4eab78c index 920ac4b21..b9e492ca6 100644 --- a/src/generated/resources/.cache/ae219fa7c7d3297c14e454863eac3998a4eab78c +++ b/src/generated/resources/.cache/ae219fa7c7d3297c14e454863eac3998a4eab78c @@ -1,4 +1,4 @@ -// 1.19.2 2023-09-25T15:21:21.7823145 Pocket Computer Upgrades +// 1.19.2 2023-07-19T14:31:39.6815264 Pocket Computer Upgrades b672635324c0df354e587efc81d0b19a581eae2f data/advancedperipherals/computercraft/pocket_upgrades/chatty_pocket.json 30b8f663613c7ce77048fd69631afcc11a682276 data/advancedperipherals/computercraft/pocket_upgrades/colony_pocket.json d4647159c2f2693a9c5e8d12bf740635751d29a8 data/advancedperipherals/computercraft/pocket_upgrades/environment_pocket.json diff --git a/src/generated/resources/.cache/b8526e444ae7356037f3a813274f6835d1f3dd16 b/src/generated/resources/.cache/b8526e444ae7356037f3a813274f6835d1f3dd16 index a31e71cd0..54d53cf45 100644 --- a/src/generated/resources/.cache/b8526e444ae7356037f3a813274f6835d1f3dd16 +++ b/src/generated/resources/.cache/b8526e444ae7356037f3a813274f6835d1f3dd16 @@ -1,4 +1,4 @@ -// 1.19.2 2023-09-25T15:21:21.7763015 Block States: advancedperipherals +// 1.19.2 2024-01-15T20:01:57.5177444 Block States: advancedperipherals 5e28ce1be9a6996d982641e5df1fa7162090b8cc assets/advancedperipherals/blockstates/block_reader.json f42bdde60f84fdb312f7cf3b2be461d9c11ebdc8 assets/advancedperipherals/blockstates/chat_box.json 1227aa092fcf1327547ace6ccc9db230e45891b0 assets/advancedperipherals/blockstates/colony_integrator.json diff --git a/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 b/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 index 0350a3d7c..42f19ff63 100644 --- a/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 +++ b/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 @@ -1,2 +1,2 @@ -// 1.19.2 2023-09-25T15:21:21.7533003 Languages: en_us -e7e0fec72e3f82423dea2c37d1fef381865df701 assets/advancedperipherals/lang/en_us.json +// 1.19.2 2024-01-15T20:01:57.5147447 Languages: en_us +d2006c7f1d9c5f1f768b50a3c445dc8b566bf9dd assets/advancedperipherals/lang/en_us.json diff --git a/src/generated/resources/.cache/f95c7003282837dabaa33e3ffceec4e6865b5218 b/src/generated/resources/.cache/f95c7003282837dabaa33e3ffceec4e6865b5218 index 9609f52b0..042110e02 100644 --- a/src/generated/resources/.cache/f95c7003282837dabaa33e3ffceec4e6865b5218 +++ b/src/generated/resources/.cache/f95c7003282837dabaa33e3ffceec4e6865b5218 @@ -1,4 +1,4 @@ -// 1.19.2 2023-09-25T15:21:21.7713005 Block tags -c4d65b1ce5b5b3ed603cbcc87cc47338be4406fe data/forge/tags/blocks/needs_wood_tool.json -ef4684e10e5054e8cfd515dffa4a98169d281078 data/minecraft/tags/blocks/mineable/pickaxe.json -26803b7d98247a3df6ee256ceb9509a2ad1ec2e5 data/minecraft/tags/blocks/needs_iron_tool.json +// 1.19.2 2024-01-15T20:01:57.5177444 Block tags +e1f71dcb4f9e7e36e29b0ad09d6520dc3adfa4a6 data/forge/tags/blocks/needs_wood_tool.json +dcbdeb0bc268b24e9970e4bada12e8e8da97b8d5 data/minecraft/tags/blocks/mineable/pickaxe.json +1017ee5cf2a99941ddfc00c2c5e07a19644470b6 data/minecraft/tags/blocks/needs_iron_tool.json diff --git a/src/generated/resources/assets/advancedperipherals/lang/en_us.json b/src/generated/resources/assets/advancedperipherals/lang/en_us.json index acbdd3c4c..ed66cc743 100644 --- a/src/generated/resources/assets/advancedperipherals/lang/en_us.json +++ b/src/generated/resources/assets/advancedperipherals/lang/en_us.json @@ -29,8 +29,7 @@ "block.advancedperipherals.player_detector": "Player Detector", "block.advancedperipherals.redstone_integrator": "Redstone Integrator", "block.advancedperipherals.rs_bridge": "RS Bridge", - "curios.identifier.glasses": "Glasses", - "entity.minecraft.villager.advancedperipherals.advancedperipherals:computer_scientist": "Computer Scientist", + "entity.minecraft.villager.advancedperipherals.computer_scientist": "Computer Scientist", "item.advancedperipherals.chunk_controller": "Chunk Controller", "item.advancedperipherals.computer_tool": "Computer Tool", "item.advancedperipherals.end_automata_core": "End Automata Core", @@ -39,15 +38,12 @@ "item.advancedperipherals.overpowered_end_automata_core": "Overpowered End Automata Core", "item.advancedperipherals.overpowered_husbandry_automata_core": "Overpowered Husbandry Automata Core", "item.advancedperipherals.overpowered_weak_automata_core": "Overpowered Weak Automata Core", - "item.advancedperipherals.smart_glasses": "Smart Glasses", - "item.advancedperipherals.smart_glasses_interface": "Smart Glasses Interface", - "item.advancedperipherals.smart_glasses_netherite": "Netherite reinforced Smart Glasses", "item.advancedperipherals.tooltip.block_reader": "&7Reads nbt data of blocks to interact with blocks which do not have computer support.", "item.advancedperipherals.tooltip.chat_box": "&7Interacts with the ingame chat, can read and write messages.", "item.advancedperipherals.tooltip.chunk_controller": "&7A crafting ingredient for the Chunky Turtle.", "item.advancedperipherals.tooltip.colony_integrator": "&7Interacts with Minecolonies to read data about your colony and citizens.", "item.advancedperipherals.tooltip.computer_tool": "&7This tool was made to tune our blocks. But for now, it's just a blue useless wrench.", - "item.advancedperipherals.tooltip.disabled": "&cThis item is disabled in config, so you can craft it, but it'll not have any functionality.", + "item.advancedperipherals.tooltip.disabled": "&cThis item is disabled in the config, so you can craft it, but it'll not have any functionality.", "item.advancedperipherals.tooltip.end_automata_core": "&7Upgrade for turtles, that allows basic interaction with the world and teleportation in one dimension.", "item.advancedperipherals.tooltip.energy_detector": "&7Can detect energy flow and acts as a resistor.", "item.advancedperipherals.tooltip.environment_detector": "&7This peripheral interacts with the minecraft world.", @@ -61,13 +57,14 @@ "item.advancedperipherals.tooltip.overpowered_end_automata_core": "&7Improved version of the end automata core, that provides some overpowered uses! Be careful, the upgrade is very fragile.", "item.advancedperipherals.tooltip.overpowered_husbandry_automata_core": "&7Improved version of the husbandry automata core, that provides some overpowered uses! Be careful, the upgrade is very fragile.", "item.advancedperipherals.tooltip.overpowered_weak_automata_core": "&7Improved version of the weak automata core, that provides some overpowered uses! Be careful, the upgrade is very fragile.", - "item.advancedperipherals.tooltip.peripheral_casing": "&7An empty hull without the love it deserves. Used as crafting ingredient", + "item.advancedperipherals.tooltip.peripheral_casing": "&7An empty hull without the love it deserves. Used as a crafting ingredient", "item.advancedperipherals.tooltip.player_detector": "&7This peripheral can be used to interact with players, but don't be a stalker.", "item.advancedperipherals.tooltip.redstone_integrator": "&7This block is able to interact with redstone. Works exactly like the redstone api of an computer.", "item.advancedperipherals.tooltip.rs_bridge": "&7The RS Bridge interacts with Refined Storage to manage your items.", "item.advancedperipherals.tooltip.show_desc": "&b[&7%s&b] &7For Description", "item.advancedperipherals.tooltip.weak_automata_core": "&7Upgrade for turtles, which makes turtles more useful.", "item.advancedperipherals.weak_automata_core": "Weak Automata Core", + "itemGroup.advancedperipheralstab": "Advanced Peripherals", "keybind.advancedperipherals.category": "Advanced Peripherals", "keybind.advancedperipherals.description": "Show Description", "pocket.advancedperipherals.chatty_pocket": "Chatty", @@ -78,8 +75,6 @@ "text.advancedperipherals.added_player": "Added you to the memory card", "text.advancedperipherals.automata_core_feed_by_player": "You're trying to feed an entity to a soul, but your own body refuses to do this. Maybe something more mechanical can do this?", "text.advancedperipherals.removed_player": "Cleared the memory card", - "text.advancedperipherals.smart_glasses.modules": "Modules", - "text.advancedperipherals.smart_glasses.peripherals": "Peripherals", "turtle.advancedperipherals.chatty_turtle": "Chatty", "turtle.advancedperipherals.chunky_turtle": "Chunky", "turtle.advancedperipherals.compass_turtle": "Compass", diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/distance_detector.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/distance_detector.json deleted file mode 100644 index 21855bf71..000000000 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/distance_detector.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "type": "minecraft:block", - "pools": [ - { - "bonus_rolls": 0.0, - "conditions": [ - { - "condition": "minecraft:survives_explosion" - } - ], - "entries": [ - { - "type": "minecraft:item", - "name": "advancedperipherals:distance_detector" - } - ], - "rolls": 1.0 - } - ] -} \ No newline at end of file diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/fluid_detector.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/fluid_detector.json deleted file mode 100644 index 731bc1f02..000000000 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/fluid_detector.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "type": "minecraft:block", - "pools": [ - { - "bonus_rolls": 0.0, - "conditions": [ - { - "condition": "minecraft:survives_explosion" - } - ], - "entries": [ - { - "type": "minecraft:item", - "name": "advancedperipherals:fluid_detector" - } - ], - "rolls": 1.0 - } - ] -} \ No newline at end of file diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/gas_detector.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/gas_detector.json deleted file mode 100644 index dadeb8bc5..000000000 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/gas_detector.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "type": "minecraft:block", - "pools": [ - { - "bonus_rolls": 0.0, - "conditions": [ - { - "condition": "minecraft:survives_explosion" - } - ], - "entries": [ - { - "type": "minecraft:item", - "name": "advancedperipherals:gas_detector" - } - ], - "rolls": 1.0 - } - ] -} \ No newline at end of file diff --git a/src/generated/resources/data/forge/tags/blocks/needs_wood_tool.json b/src/generated/resources/data/forge/tags/blocks/needs_wood_tool.json index 0578bfe7e..ffd23c4b9 100644 --- a/src/generated/resources/data/forge/tags/blocks/needs_wood_tool.json +++ b/src/generated/resources/data/forge/tags/blocks/needs_wood_tool.json @@ -1,6 +1,5 @@ { "values": [ - "advancedperipherals:peripheral_casing", - "advancedperipherals:colony_integrator" + "advancedperipherals:peripheral_casing" ] } \ No newline at end of file diff --git a/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json b/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json index 8f9cf40b9..ada8618ef 100644 --- a/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json +++ b/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json @@ -6,15 +6,12 @@ "advancedperipherals:me_bridge", "advancedperipherals:rs_bridge", "advancedperipherals:energy_detector", - "advancedperipherals:fluid_detector", - "advancedperipherals:gas_detector", "advancedperipherals:peripheral_casing", "advancedperipherals:inventory_manager", "advancedperipherals:redstone_integrator", "advancedperipherals:block_reader", "advancedperipherals:geo_scanner", "advancedperipherals:colony_integrator", - "advancedperipherals:nbt_storage", - "advancedperipherals:distance_detector" + "advancedperipherals:nbt_storage" ] } \ No newline at end of file diff --git a/src/generated/resources/data/minecraft/tags/blocks/needs_iron_tool.json b/src/generated/resources/data/minecraft/tags/blocks/needs_iron_tool.json index 76fb2b79d..002d1e917 100644 --- a/src/generated/resources/data/minecraft/tags/blocks/needs_iron_tool.json +++ b/src/generated/resources/data/minecraft/tags/blocks/needs_iron_tool.json @@ -6,13 +6,11 @@ "advancedperipherals:me_bridge", "advancedperipherals:rs_bridge", "advancedperipherals:energy_detector", - "advancedperipherals:fluid_detector", - "advancedperipherals:gas_detector", "advancedperipherals:inventory_manager", "advancedperipherals:redstone_integrator", "advancedperipherals:block_reader", "advancedperipherals:geo_scanner", - "advancedperipherals:nbt_storage", - "advancedperipherals:distance_detector" + "advancedperipherals:colony_integrator", + "advancedperipherals:nbt_storage" ] } \ No newline at end of file diff --git a/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java b/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java index 52eba5e66..dcdd0c566 100644 --- a/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java +++ b/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java @@ -1,8 +1,8 @@ package de.srendi.advancedperipherals; -import de.srendi.advancedperipherals.common.setup.APBlocks; -import de.srendi.advancedperipherals.common.setup.APRegistration; +import de.srendi.advancedperipherals.common.setup.Blocks; import de.srendi.advancedperipherals.common.setup.CCRegistration; +import de.srendi.advancedperipherals.common.setup.Registration; import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; import net.minecraft.core.NonNullList; import net.minecraft.resources.ResourceLocation; @@ -22,7 +22,7 @@ public APCreativeTab() { @Override public void fillItemList(NonNullList items) { - APRegistration.ITEMS.getEntries().stream().map(RegistryObject::get).forEach(item -> items.add(new ItemStack(item))); + Registration.ITEMS.getEntries().stream().map(RegistryObject::get).forEach(item -> items.add(new ItemStack(item))); items.addAll(pocketUpgrade(CCRegistration.ID.COLONY_POCKET)); items.addAll(pocketUpgrade(CCRegistration.ID.CHATTY_POCKET)); items.addAll(pocketUpgrade(CCRegistration.ID.PLAYER_POCKET)); @@ -57,6 +57,6 @@ private static Collection turtleUpgrade(ResourceLocation pocketId) { @Override @NotNull public ItemStack makeIcon() { - return new ItemStack(APBlocks.CHAT_BOX.get()); + return new ItemStack(Blocks.CHAT_BOX.get()); } } diff --git a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java index a52cf0fa7..40ab9c1a9 100644 --- a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java +++ b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java @@ -2,9 +2,9 @@ import de.srendi.advancedperipherals.common.addons.APAddons; import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.network.PacketHandler; -import de.srendi.advancedperipherals.common.setup.APRegistration; +import de.srendi.advancedperipherals.common.setup.Registration; import de.srendi.advancedperipherals.common.village.VillageStructures; +import de.srendi.advancedperipherals.network.APNetworking; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.IEventBus; @@ -26,7 +26,6 @@ public class AdvancedPeripherals { public static final Logger LOGGER = LogManager.getLogger(NAME); public static final Random RANDOM = new Random(); public static final APCreativeTab TAB = new APCreativeTab(); - public static final APAddons ADDONS = new APAddons(); public AdvancedPeripherals() { LOGGER.info("AdvancedPeripherals says hello!"); @@ -35,7 +34,7 @@ public AdvancedPeripherals() { APConfig.register(ModLoadingContext.get()); modBus.addListener(this::commonSetup); - APRegistration.register(); + Registration.register(); MinecraftForge.EVENT_BUS.register(this); } @@ -49,19 +48,14 @@ public static void debug(String message, Level level) { LOGGER.log(level, "[DEBUG] {}", message); } - public static void exception(String message, Exception exception) { - if (APConfig.GENERAL_CONFIG.enableDebugMode.get()) { - LOGGER.error("[DEBUG]", exception); - } - } - public static ResourceLocation getRL(String resource) { return new ResourceLocation(MOD_ID, resource); } public void commonSetup(FMLCommonSetupEvent event) { + APAddons.commonSetup(); event.enqueueWork(() -> { - PacketHandler.init(); + APNetworking.init(); VillageStructures.init(); }); } diff --git a/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java b/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java index d5e52ae28..160836009 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java +++ b/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java @@ -3,17 +3,13 @@ import dan200.computercraft.api.client.ComputerCraftAPIClient; import dan200.computercraft.api.client.turtle.TurtleUpgradeModeller; import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.client.renderer.DistanceDetectorRenderer; -import de.srendi.advancedperipherals.client.screens.InventoryManagerScreen; -import de.srendi.advancedperipherals.client.screens.SmartGlassesScreen; -import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; -import de.srendi.advancedperipherals.common.setup.APContainerTypes; +import de.srendi.advancedperipherals.common.container.InventoryManagerScreen; import de.srendi.advancedperipherals.common.setup.CCRegistration; +import de.srendi.advancedperipherals.common.setup.ContainerTypes; import net.minecraft.client.gui.screens.MenuScreens; import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.client.event.EntityRenderersEvent; import net.minecraftforge.client.event.ModelEvent; import net.minecraftforge.client.event.RegisterKeyMappingsEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; @@ -34,8 +30,7 @@ public static void registerModels(ModelEvent.RegisterAdditional event) { @SubscribeEvent public static void onClientSetup(FMLClientSetupEvent event) { - MenuScreens.register(APContainerTypes.INVENTORY_MANAGER_CONTAINER.get(), InventoryManagerScreen::new); - MenuScreens.register(APContainerTypes.SMART_GLASSES_CONTAINER.get(), SmartGlassesScreen::new); + MenuScreens.register(ContainerTypes.INVENTORY_MANAGER_CONTAINER.get(), InventoryManagerScreen::new); ComputerCraftAPIClient.registerTurtleUpgradeModeller(CCRegistration.CHUNKY_TURTLE.get(), TurtleUpgradeModeller.flatItem()); ComputerCraftAPIClient.registerTurtleUpgradeModeller(CCRegistration.COMPASS_TURTLE.get(), TurtleUpgradeModeller.flatItem()); @@ -49,17 +44,16 @@ public static void onClientSetup(FMLClientSetupEvent event) { ComputerCraftAPIClient.registerTurtleUpgradeModeller(CCRegistration.HUSBANDRY_TURTLE.get(), new MetaTurtleUpgradeModeller<>()); ComputerCraftAPIClient.registerTurtleUpgradeModeller(CCRegistration.END_TURTLE.get(), new MetaTurtleUpgradeModeller<>()); ComputerCraftAPIClient.registerTurtleUpgradeModeller(CCRegistration.WEAK_TURTLE.get(), new MetaTurtleUpgradeModeller<>()); - - ItemPropertiesRegistry.register(); } @SubscribeEvent - public static void registeringKeymappings(RegisterKeyMappingsEvent event) { + public static void onClientSetup(RegisterKeyMappingsEvent event) { KeyBindings.register(event); } - @SubscribeEvent - public static void registeringRenderers(EntityRenderersEvent.RegisterRenderers event) { - event.registerBlockEntityRenderer(APBlockEntityTypes.DISTANCE_DETECTOR.get(), DistanceDetectorRenderer::new); - } + //TODO change the icon of the curio icon + /*@SubscribeEvent + public static void onTextureStitching(TextureStitchEvent.Pre event) { + event.addSprite(new ResourceLocation(AdvancedPeripherals.MOD_ID, "item/empty_glasses_slot")); + }*/ } diff --git a/src/main/java/de/srendi/advancedperipherals/client/ItemPropertiesRegistry.java b/src/main/java/de/srendi/advancedperipherals/client/ItemPropertiesRegistry.java deleted file mode 100644 index 00ef43539..000000000 --- a/src/main/java/de/srendi/advancedperipherals/client/ItemPropertiesRegistry.java +++ /dev/null @@ -1,17 +0,0 @@ -package de.srendi.advancedperipherals.client; - -import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.common.setup.APItems; -import net.minecraft.client.renderer.item.ItemProperties; -import net.minecraft.resources.ResourceLocation; - -public class ItemPropertiesRegistry { - - public static void register() { - ItemProperties.register(APItems.MEMORY_CARD.get(), new ResourceLocation(AdvancedPeripherals.MOD_ID, "bounded"), (stack, level, entity, seed) -> { - boolean bounded = stack.getOrCreateTag().contains("owner"); - return bounded ? 1 : 0; - }); - } - -} diff --git a/src/main/java/de/srendi/advancedperipherals/client/KeyBindings.java b/src/main/java/de/srendi/advancedperipherals/client/KeyBindings.java index 37cea5f0d..2cbd46438 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/KeyBindings.java +++ b/src/main/java/de/srendi/advancedperipherals/client/KeyBindings.java @@ -7,11 +7,9 @@ public class KeyBindings { public static final KeyMapping DESCRIPTION_KEYBINDING = new KeyMapping("keybind.advancedperipherals.description", GLFW.GLFW_KEY_LEFT_CONTROL, "keybind.advancedperipherals.category"); - public static final KeyMapping GLASSES_HOTKEY_KEYBINDING = new KeyMapping("keybind.advancedperipherals.glasses_hotkey", GLFW.GLFW_KEY_G, "keybind.advancedperipherals.category"); public static void register(RegisterKeyMappingsEvent event) { event.register(DESCRIPTION_KEYBINDING); - event.register(GLASSES_HOTKEY_KEYBINDING); } } diff --git a/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java b/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java deleted file mode 100644 index 6731f755e..000000000 --- a/src/main/java/de/srendi/advancedperipherals/client/renderer/DistanceDetectorRenderer.java +++ /dev/null @@ -1,97 +0,0 @@ -package de.srendi.advancedperipherals.client.renderer; - -import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.blaze3d.vertex.VertexConsumer; -import com.mojang.math.Matrix3f; -import com.mojang.math.Matrix4f; -import com.mojang.math.Vector3f; -import de.srendi.advancedperipherals.common.blocks.base.BaseBlock; -import de.srendi.advancedperipherals.common.blocks.blockentities.DistanceDetectorEntity; -import de.srendi.advancedperipherals.common.util.EnumColor; -import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.blockentity.BeaconRenderer; -import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; -import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; -import net.minecraft.client.renderer.texture.OverlayTexture; -import net.minecraft.core.Direction; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.Mth; -import net.minecraft.world.phys.Vec3; -import org.jetbrains.annotations.NotNull; - -public class DistanceDetectorRenderer implements BlockEntityRenderer { - - public DistanceDetectorRenderer(BlockEntityRendererProvider.Context pContext) { - super(); - } - - @Override - public void render(@NotNull DistanceDetectorEntity pBlockEntity, float pPartialTick, @NotNull PoseStack pPoseStack, MultiBufferSource pBufferSource, int pPackedLight, int pPackedOverlay) { - if (pBlockEntity.getLaserVisibility()) - renderBeaconBeam(pBlockEntity, pPoseStack, pBufferSource, BeaconRenderer.BEAM_LOCATION, pPartialTick, 1, 0, pBlockEntity.getCurrentDistance() - 0.5f, EnumColor.RED.getRgb(), 0.05f, 0.09f); - } - - @Override - public boolean shouldRenderOffScreen(@NotNull DistanceDetectorEntity pBlockEntity) { - return true; - } - - @Override - public int getViewDistance() { - return 256; - } - - @Override - public boolean shouldRender(@NotNull DistanceDetectorEntity pBlockEntity, @NotNull Vec3 pCameraPos) { - return true; - } - - public static void renderBeaconBeam(DistanceDetectorEntity detectorEntity, PoseStack pPoseStack, MultiBufferSource pBufferSource, ResourceLocation pBeamLocation, float pPartialTick, float pTextureScale, int pYOffset, float pHeight, float[] pColors, float pBeamRadius, float pGlowRadius) { - long pGameTime = detectorEntity.getLevel().getGameTime(); - float maxX = pYOffset + pHeight; - Direction direction = detectorEntity.getBlockState().getValue(BaseBlock.ORIENTATION).front(); - pPoseStack.pushPose(); - pPoseStack.translate(0.5D, 0.5D, 0.5D); - float degrees = Math.floorMod(pGameTime, 360) + pPartialTick; - float reversedDegrees = pHeight < 0 ? degrees : -degrees; - float time = Mth.frac(reversedDegrees * 0.2F - Mth.floor(reversedDegrees * 0.1F)); - float r = pColors[0]; - float g = pColors[1]; - float b = pColors[2]; - pPoseStack.pushPose(); - pPoseStack.mulPose(direction.getRotation()); - pPoseStack.mulPose(Vector3f.YP.rotationDegrees(degrees * 2.25F - 45.0F)); - float f15 = -1.0F + time; - float f16 = pHeight * pTextureScale * (0.5F / pBeamRadius) + f15; - renderPart(pPoseStack, pBufferSource.getBuffer(RenderType.beaconBeam(pBeamLocation, false)), r, g, b, 1.0F, pYOffset, maxX, 0.0F, pBeamRadius, pBeamRadius, 0.0F, -pBeamRadius, 0.0F, 0.0F, -pBeamRadius, 0.0F, 1.0F, f16, f15); - pPoseStack.popPose(); - pPoseStack.mulPose(direction.getRotation()); - f15 = -1.0F + time; - f16 = pHeight * pTextureScale + f15; - renderPart(pPoseStack, pBufferSource.getBuffer(RenderType.beaconBeam(pBeamLocation, true)), r, g, b, 0.225F, pYOffset, maxX, -pGlowRadius, -pGlowRadius, pGlowRadius, -pGlowRadius, -pBeamRadius, pGlowRadius, pGlowRadius, pGlowRadius, 0.0F, 1.0F, f16, f15); - pPoseStack.popPose(); - } - - private static void renderPart(PoseStack pPoseStack, VertexConsumer pConsumer, float pRed, float pGreen, float pBlue, float pAlpha, int pMinY, float pMaxY, float pX0, float pZ0, float pX1, float pZ1, float pX2, float pZ2, float pX3, float pZ3, float pMinU, float pMaxU, float pMinV, float pMaxV) { - PoseStack.Pose posestackPose = pPoseStack.last(); - Matrix4f matrix4f = posestackPose.pose(); - Matrix3f matrix3f = posestackPose.normal(); - renderQuad(matrix4f, matrix3f, pConsumer, pRed, pGreen, pBlue, pAlpha, pMinY, pMaxY, pX0, pZ0, pX1, pZ1, pMinU, pMaxU, pMinV, pMaxV); - renderQuad(matrix4f, matrix3f, pConsumer, pRed, pGreen, pBlue, pAlpha, pMinY, pMaxY, pX3, pZ3, pX2, pZ2, pMinU, pMaxU, pMinV, pMaxV); - renderQuad(matrix4f, matrix3f, pConsumer, pRed, pGreen, pBlue, pAlpha, pMinY, pMaxY, pX1, pZ1, pX3, pZ3, pMinU, pMaxU, pMinV, pMaxV); - renderQuad(matrix4f, matrix3f, pConsumer, pRed, pGreen, pBlue, pAlpha, pMinY, pMaxY, pX2, pZ2, pX0, pZ0, pMinU, pMaxU, pMinV, pMaxV); - } - - private static void renderQuad(Matrix4f pPose, Matrix3f pNormal, VertexConsumer pConsumer, float pRed, float pGreen, float pBlue, float pAlpha, int pMinY, float pMaxY, float pMinX, float pMinZ, float pMaxX, float pMaxZ, float pMinU, float pMaxU, float pMinV, float pMaxV) { - addVertex(pPose, pNormal, pConsumer, pRed, pGreen, pBlue, pAlpha, pMaxY, pMinX, pMinZ, pMaxU, pMinV); - addVertex(pPose, pNormal, pConsumer, pRed, pGreen, pBlue, pAlpha, pMinY, pMinX, pMinZ, pMaxU, pMaxV); - addVertex(pPose, pNormal, pConsumer, pRed, pGreen, pBlue, pAlpha, pMinY, pMaxX, pMaxZ, pMinU, pMaxV); - addVertex(pPose, pNormal, pConsumer, pRed, pGreen, pBlue, pAlpha, pMaxY, pMaxX, pMaxZ, pMinU, pMinV); - } - - private static void addVertex(Matrix4f pPose, Matrix3f pNormal, VertexConsumer pConsumer, float pRed, float pGreen, float pBlue, float pAlpha, float pY, float pX, float pZ, float pU, float pV) { - pConsumer.vertex(pPose, pX, pY, pZ).color(pRed, pGreen, pBlue, pAlpha).uv(pU, pV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(15728880).normal(pNormal, 0.0F, 1.0F, 0.0F).endVertex(); - } - -} diff --git a/src/main/java/de/srendi/advancedperipherals/client/screens/SmartGlassesScreen.java b/src/main/java/de/srendi/advancedperipherals/client/screens/SmartGlassesScreen.java deleted file mode 100644 index 9b4aa2346..000000000 --- a/src/main/java/de/srendi/advancedperipherals/client/screens/SmartGlassesScreen.java +++ /dev/null @@ -1,78 +0,0 @@ -package de.srendi.advancedperipherals.client.screens; - -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.PoseStack; -import dan200.computercraft.client.gui.ComputerScreenBase; -import dan200.computercraft.client.gui.widgets.ComputerSidebar; -import dan200.computercraft.client.gui.widgets.WidgetTerminal; -import dan200.computercraft.shared.turtle.inventory.ContainerTurtle; -import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.client.widgets.SmartGlassesSettingsSwitch; -import de.srendi.advancedperipherals.common.container.SmartGlassesContainer; -import de.srendi.advancedperipherals.common.smartglasses.SlotType; -import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.FormattedCharSequence; -import net.minecraft.world.entity.player.Inventory; -import org.jetbrains.annotations.NotNull; - -public class SmartGlassesScreen extends ComputerScreenBase { - - private static final ResourceLocation BACKGROUND = new ResourceLocation(AdvancedPeripherals.MOD_ID, "textures/gui/smart_glasses_gui.png"); - public static final ResourceLocation SIDEBAR = new ResourceLocation(AdvancedPeripherals.MOD_ID, "textures/gui/corners_glasses.png"); - - private static final int TEX_WIDTH = 254; - private static final int TEX_HEIGHT = 217; - private SlotType currentType = SlotType.defaultType(); - - public SmartGlassesScreen(SmartGlassesContainer container, Inventory player, Component title) { - super(container, player, title, ContainerTurtle.BORDER); - - imageWidth = TEX_WIDTH + ComputerSidebar.WIDTH; - imageHeight = TEX_HEIGHT; - } - - @Override - protected void init() { - super.init(); - addRenderableWidget(new SmartGlassesSettingsSwitch(254, 147, SlotType.PERIPHERALS, this)); - addRenderableWidget(new SmartGlassesSettingsSwitch(254, 170, SlotType.MODULES, this)); - } - - @Override - protected WidgetTerminal createTerminal() { - return new WidgetTerminal(terminalData, input, leftPos + ContainerTurtle.BORDER + ComputerSidebar.WIDTH, topPos + ContainerTurtle.BORDER); - } - - @Override - protected void renderBg(@NotNull PoseStack transform, float partialTicks, int mouseX, int mouseY) { - RenderSystem.setShaderTexture(0, BACKGROUND); - blit(transform, leftPos + ComputerSidebar.WIDTH, topPos, 0, 0, TEX_WIDTH, TEX_HEIGHT); - - if (currentType == SlotType.PERIPHERALS) - blit(transform, leftPos + ComputerSidebar.WIDTH + 222, topPos + 183, 186, 183, 18, 18); - - RenderSystem.setShaderTexture(0, SIDEBAR); - ComputerSidebar.renderBackground(transform, leftPos, topPos + sidebarYOffset); - } - - @Override - protected void renderTooltip(@NotNull PoseStack poseStack, int x, int y) { - super.renderTooltip(poseStack, x, y); - renderables.forEach(renderable -> { - if (renderable instanceof SmartGlassesSettingsSwitch smartGlassesSettingsSwitch) { - smartGlassesSettingsSwitch.renderTooltip(poseStack, x, y); - } - }); - } - - @Override - protected void renderLabels(PoseStack poseStack, int x, int y) { - FormattedCharSequence formattedcharsequence = currentType.getName().getVisualOrderText(); - this.font.draw(poseStack, formattedcharsequence, (212 + ComputerSidebar.WIDTH - (float) this.font.width(formattedcharsequence) / 2), 133, 4210752); - } - - public void setCurrentType(SlotType currentType) { - this.currentType = currentType; - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/client/widgets/SmartGlassesSettingsSwitch.java b/src/main/java/de/srendi/advancedperipherals/client/widgets/SmartGlassesSettingsSwitch.java deleted file mode 100644 index 3ee6e1fb1..000000000 --- a/src/main/java/de/srendi/advancedperipherals/client/widgets/SmartGlassesSettingsSwitch.java +++ /dev/null @@ -1,85 +0,0 @@ -package de.srendi.advancedperipherals.client.widgets; - -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.PoseStack; -import dan200.computercraft.client.gui.widgets.ComputerSidebar; -import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.client.screens.SmartGlassesScreen; -import de.srendi.advancedperipherals.common.smartglasses.SlotType; -import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesSlot; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.components.AbstractWidget; -import net.minecraft.client.gui.narration.NarrationElementOutput; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.inventory.Slot; -import org.jetbrains.annotations.NotNull; - -import java.util.Collections; - -public class SmartGlassesSettingsSwitch extends AbstractWidget { - - private static final ResourceLocation BACKGROUND = new ResourceLocation(AdvancedPeripherals.MOD_ID, "textures/gui/smart_glasses_gui.png"); - - private final SmartGlassesScreen screen; - private final SlotType type; - private boolean isEnabled; - - public SmartGlassesSettingsSwitch(int x, int y, SlotType type, SmartGlassesScreen screen) { - super(screen.getGuiLeft() + x + ComputerSidebar.WIDTH, screen.getGuiTop() + y, 21, 22, type.getName()); - this.screen = screen; - this.type = type; - this.isEnabled = type == SlotType.defaultType(); - } - - @Override - public void render(@NotNull PoseStack pPoseStack, int pMouseX, int pMouseY, float pPartialTick) { - renderBg(pPoseStack, Minecraft.getInstance(), pMouseX, pMouseY); - } - - @Override - public void renderButton(@NotNull PoseStack pPoseStack, int pMouseX, int pMouseY, float pPartialTick) { - // Disable rendering of default buttons - } - - @Override - protected void renderBg(@NotNull PoseStack pPoseStack, @NotNull Minecraft pMinecraft, int pMouseX, int pMouseY) { - RenderSystem.setShaderTexture(0, BACKGROUND); - if (isEnabled) { - blit(pPoseStack, this.x - 3, this.y, 45, 217, 24, 22); - } else { - blit(pPoseStack, this.x, this.y, 23, 217, 21, 22); - } - } - - @Override - public void onClick(double pMouseX, double pMouseY) { - if (this.isEnabled) - return; - for (Slot slot : screen.getMenu().slots) { - if (slot instanceof SmartGlassesSlot smartGlassesSlot) { - if (smartGlassesSlot.slotType == this.type) { - smartGlassesSlot.setEnabled(true); - continue; - } - smartGlassesSlot.setEnabled(false); - } - } - screen.renderables.forEach(renderable -> { - if (renderable instanceof SmartGlassesSettingsSwitch smartGlassesSettingsSwitch) { - smartGlassesSettingsSwitch.isEnabled = false; - } - }); - screen.setCurrentType(this.type); - this.isEnabled = true; - } - - public void renderTooltip(PoseStack poseStack, int x, int y) { - if (screen != null && isMouseOver(x, y)) - screen.renderComponentTooltip(poseStack, Collections.singletonList(type.getName()), x, y); - } - - @Override - public void updateNarration(NarrationElementOutput pNarrationElementOutput) { - - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java b/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java index 5bdce0093..c26e2652a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java @@ -2,19 +2,10 @@ import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.addons.refinedstorage.RefinedStorage; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.InterModComms; import net.minecraftforge.fml.ModList; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent; -import top.theillusivec4.curios.api.CuriosApi; -import top.theillusivec4.curios.api.SlotResult; -import top.theillusivec4.curios.api.SlotTypeMessage; - -import java.util.List; @Mod.EventBusSubscriber(modid = AdvancedPeripherals.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) public class APAddons { @@ -22,32 +13,29 @@ public class APAddons { public static final String CURIOS_MODID = "curios"; public static final String REFINEDSTORAGE_MODID = "refinedstorage"; public static final String AE_THINGS_MODID = "ae2things"; - public static final String APPLIEDENERGISTICS_MODID = "ae2"; - public static final String MEKANISM_MODID = "mekanism"; public static final String AE_ADDITIONS_MODID = "ae2additions"; public static final String APP_MEKANISTICS_MODID = "appmek"; public static boolean curiosLoaded; public static boolean refinedStorageLoaded; public static boolean aeThingsLoaded; - public static boolean appliedEnergisticsLoaded; - public static boolean mekanismLoaded; public static boolean aeAdditionsLoaded; public static boolean appMekLoaded; - // Use static so these checks run as early as possible, so we can use them for our registries - static { + private APAddons() { + } + + public static void commonSetup() { ModList modList = ModList.get(); curiosLoaded = modList.isLoaded(CURIOS_MODID); refinedStorageLoaded = modList.isLoaded(REFINEDSTORAGE_MODID); - appliedEnergisticsLoaded = modList.isLoaded(APPLIEDENERGISTICS_MODID); - mekanismLoaded = modList.isLoaded(MEKANISM_MODID); aeThingsLoaded = modList.isLoaded(AE_THINGS_MODID); aeAdditionsLoaded = modList.isLoaded(AE_ADDITIONS_MODID); appMekLoaded = modList.isLoaded(APP_MEKANISTICS_MODID); if (refinedStorageLoaded) RefinedStorage.instance = new RefinedStorage(); + } @SubscribeEvent @@ -55,20 +43,6 @@ public static void interModComms(InterModEnqueueEvent event) { if (!curiosLoaded) return; - InterModComms.sendTo(CURIOS_MODID, SlotTypeMessage.REGISTER_TYPE, - () -> new SlotTypeMessage.Builder("glasses") - .size(1) - .icon(new ResourceLocation(AdvancedPeripherals.MOD_ID, "slot/empty_glasses_slot")) - .build()); - } - - public static ItemStack getCurioGlasses(Player player) { - if (!curiosLoaded) - return ItemStack.EMPTY; - List curioSlots = CuriosApi.getCuriosHelper().findCurios(player, "glasses"); - if (curioSlots.isEmpty()) - return ItemStack.EMPTY; - - return curioSlots.get(0).stack(); + // InterModComms.sendTo("curios", SlotTypeMessage.REGISTER_TYPE, () -> new SlotTypeMessage.Builder("glasses").size(1).build()); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java index c640159b9..10173f316 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java @@ -1,8 +1,6 @@ package de.srendi.advancedperipherals.common.addons.appliedenergistics; -import appeng.api.crafting.IPatternDetails; import appeng.api.inventories.InternalInventory; -import appeng.api.networking.IGrid; import appeng.api.networking.IGridNode; import appeng.api.networking.crafting.CraftingJobStatus; import appeng.api.networking.crafting.ICraftingCPU; @@ -14,11 +12,6 @@ import appeng.api.storage.MEStorage; import appeng.api.storage.cells.IBasicCellItem; import appeng.blockentity.storage.DriveBlockEntity; -import appeng.crafting.pattern.EncodedPatternItem; -import appeng.helpers.iface.PatternContainer; -import appeng.items.storage.BasicStorageCell; -import appeng.me.cells.BasicCellHandler; -import appeng.me.cells.BasicCellInventory; import appeng.parts.storagebus.StorageBusPart; import com.the9grounds.aeadditions.item.storage.StorageCell; import com.the9grounds.aeadditions.item.storage.SuperStorageCell; @@ -28,20 +21,14 @@ import de.srendi.advancedperipherals.common.util.LuaConverter; import de.srendi.advancedperipherals.common.util.Pair; import de.srendi.advancedperipherals.common.util.inventory.FluidFilter; -import de.srendi.advancedperipherals.common.util.inventory.GenericFilter; import de.srendi.advancedperipherals.common.util.inventory.ItemFilter; import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; import io.github.projectet.ae2things.item.DISKDrive; import it.unimi.dsi.fastutil.objects.Object2LongMap; import me.ramidzkh.mekae2.ae2.MekanismKey; -import me.ramidzkh.mekae2.ae2.MekanismKeyType; -import me.ramidzkh.mekae2.item.ChemicalStorageCell; -import mekanism.api.chemical.merged.MergedChemicalTank; -import mekanism.common.tile.TileEntityChemicalTank; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.util.LazyOptional; @@ -49,10 +36,10 @@ import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.registries.ForgeRegistries; +import org.apache.logging.log4j.Level; import org.jetbrains.annotations.Nullable; import java.util.*; -import java.util.stream.Collectors; public class AppEngApi { @@ -98,60 +85,6 @@ public static Pair findAEFluidFromFilter(MEStorage monitor, @N return null; } - /** - * Finds a pattern from filters. - * - * @param grid The grid to search patterns from. - * @param level The level of the grid. - * @param inputFilter The input filter to apply, can be null to ignore input filter. - * @param outputFilter The output filter to apply, can be null to ignore output filter. - * @return A Pair object containing the matched pattern and an error message if no pattern is found. - * The pattern can be null if no pattern is found. - * The error message is "NO_PATTERN_FOUND" if no pattern is found. - */ - public static Pair findPatternFromFilters(IGrid grid, Level level, @Nullable GenericFilter inputFilter, @Nullable GenericFilter outputFilter) { - for (IPatternDetails pattern : getPatterns(grid, level)) { - if (pattern.getInputs().length == 0) - continue; - if (pattern.getOutputs().length == 0) - continue; - - boolean inputMatch = false; - boolean outputMatch = false; - - if (inputFilter != null) { - outerLoop: - for (IPatternDetails.IInput input : pattern.getInputs()) { - for (GenericStack possibleInput : input.getPossibleInputs()) { - if (inputFilter.test(possibleInput)) { - inputMatch = true; - break outerLoop; - } - } - } - } else { - inputMatch = true; - } - - if (outputFilter != null) { - for (GenericStack output : pattern.getOutputs()) { - if (outputFilter.test(output)) { - outputMatch = true; - break; - } - } - } else { - outputMatch = true; - } - - if (inputMatch && outputMatch) - return Pair.of(pattern, null); - } - - return Pair.of(null, "NO_PATTERN_FOUND"); - } - - public static List listStacks(MEStorage monitor, ICraftingService service) { List items = new ArrayList<>(); KeyCounter keyCounter = monitor.getAvailableStacks(); @@ -185,7 +118,7 @@ public static List listFluids(MEStorage monitor, ICraftingService servic return items; } - public static List listGases(MEStorage monitor, ICraftingService service) { + public static List listGases(MEStorage monitor, ICraftingService service, int flag) { List items = new ArrayList<>(); for (Object2LongMap.Entry aeKey : monitor.getAvailableStacks()) { if (APAddons.appMekLoaded && aeKey.getKey() instanceof MekanismKey itemKey) { @@ -207,55 +140,6 @@ public static List listCraftableFluids(MEStorage monitor, ICraftingServi return items; } - public static List getPatterns(IGrid grid, Level level) { - List patterns = new ArrayList<>(); - for (var machineClass : grid.getMachineClasses()) { - var containerClass = tryCastMachineToContainer(machineClass); - if (containerClass == null) - continue; - - for (var container : grid.getActiveMachines(containerClass)) { - for (ItemStack patternItem : container.getTerminalPatternInventory()) { - if (patternItem.getItem() instanceof EncodedPatternItem item) { - IPatternDetails patternDetails = item.decode(patternItem, level, false); - if (patternDetails == null) - continue; - - patterns.add(patternDetails); - } - } - } - } - return patterns; - } - - public static List listPatterns(IGrid grid, Level level) { - return getPatterns(grid, level).stream().map(AppEngApi::getObjectFromPattern).collect(Collectors.toList()); - } - - public static List listDrives(IGrid grid) { - List drives = new ArrayList<>(); - - for (IGridNode node : grid.getMachineNodes(DriveBlockEntity.class)) { - DriveBlockEntity drive = (DriveBlockEntity) node.getService(IStorageProvider.class); - - // A normal drive has a cellCount of 10 - if (drive == null || drive.getCellCount() != 10) - continue; - - drives.add(getObjectFromDrive(drive)); - } - - return drives; - } - - private static Class tryCastMachineToContainer(Class machineClass) { - if (PatternContainer.class.isAssignableFrom(machineClass)) - return machineClass.asSubclass(PatternContainer.class); - - return null; - } - public static Map getObjectFromStack(Pair stack, @Nullable ICraftingService service) { if (stack.getRight() == null) return Collections.emptyMap(); @@ -266,58 +150,10 @@ public static Map getObjectFromStack(Pair getObjectFromDrive(DriveBlockEntity drive) { - Map map = new HashMap<>(); - - map.put("powered", drive.isPowered()); - - long totalBytes = 0; - long usedBytes = 0; - - if (drive.getCellCount() != 10) - return map; - - List driveCells = new ArrayList<>(); - for (ItemStack item : drive.getInternalInventory()) { - if (item.getItem() instanceof BasicStorageCell cell) { - BasicCellInventory cellInventory = BasicCellHandler.INSTANCE.getCellInventory(item, null); - totalBytes += cellInventory.getTotalBytes(); - usedBytes += cellInventory.getUsedBytes(); - - driveCells.add(getObjectFromCell(cell, item)); - } - } - - map.put("usedBytes", usedBytes); - map.put("totalBytes", totalBytes); - map.put("cells", driveCells); - map.put("priority", drive.getPriority()); - map.put("menuIcon", LuaConverter.itemToObject(drive.getMainMenuIcon().getItem())); - map.put("position", LuaConverter.posToObject(drive.getBlockPos())); - map.put("name", drive.getCustomInventoryName().getString()); - - return map; - } - - public static Map getObjectFromCell(BasicStorageCell cell, ItemStack cellItem) { - Map map = new HashMap<>(); - BasicCellInventory cellInventory = BasicCellHandler.INSTANCE.getCellInventory(cellItem, null); - - map.put("item", LuaConverter.itemToObject(cellItem.getItem())); - map.put("type", cell.getKeyType().toString()); - map.put("bytes", cell.getBytes(cellItem)); - map.put("bytesPerType", cell.getBytesPerType(cellItem)); - map.put("usedBytes", cellInventory.getUsedBytes()); - map.put("totalTypes", cell.getTotalTypes(cellItem)); - map.put("fuzzyMode", cell.getFuzzyMode(cellItem).toString()); - - return map; - } - private static Map getObjectFromItemStack(Pair stack, @Nullable ICraftingService craftingService) { Map map = new HashMap<>(); String displayName = stack.getRight().getDisplayName().getString(); @@ -357,27 +193,7 @@ private static Map getObjectFromGasStack(Pair return map; } - public static Map getObjectFromPattern(IPatternDetails pattern) { - Map map = new HashMap<>(); - - map.put("inputs", Arrays.stream(pattern.getInputs()).map(AppEngApi::getObjectFromPatternInput).collect(Collectors.toList())); - map.put("outputs", Arrays.stream(pattern.getOutputs()).map(AppEngApi::getObjectFromGenericStack).collect(Collectors.toList())); - map.put("primaryOutput", getObjectFromGenericStack(pattern.getPrimaryOutput())); - return map; - } - - public static Map getObjectFromPatternInput(IPatternDetails.IInput patternInput) { - Map map = new HashMap<>(); - map.put("primaryInput", getObjectFromGenericStack(patternInput.getPossibleInputs()[0])); - map.put("possibleInputs", - Arrays.stream(Arrays.copyOfRange(patternInput.getPossibleInputs(), 1, patternInput.getPossibleInputs().length)) - .map(AppEngApi::getObjectFromGenericStack)); - map.put("multiplier", patternInput.getMultiplier()); - map.put("remaining", patternInput.getRemainingKey(patternInput.getPossibleInputs()[0].what())); - return map; - } - - public static Map getObjectFromCPU(ICraftingCPU cpu, boolean recursive) { + public static Map getObjectFromCPU(ICraftingCPU cpu) { Map map = new HashMap<>(); long storage = cpu.getAvailableStorage(); int coProcessors = cpu.getCoProcessors(); @@ -385,24 +201,20 @@ public static Map getObjectFromCPU(ICraftingCPU cpu, boolean rec map.put("storage", storage); map.put("coProcessors", coProcessors); map.put("isBusy", isBusy); - if (!recursive) - map.put("craftingJob", cpu.getJobStatus() != null ? getObjectFromJob(cpu.getJobStatus(), null) : null); + map.put("craftingJob", cpu.getJobStatus() != null ? getObjectFromJob(cpu.getJobStatus()) : null); map.put("name", cpu.getName() != null ? cpu.getName().getString() : "Unnamed"); map.put("selectionMode", cpu.getSelectionMode().toString()); return map; } - public static Map getObjectFromJob(CraftingJobStatus job, @Nullable ICraftingCPU cpu) { + public static Map getObjectFromJob(CraftingJobStatus job) { Map map = new HashMap<>(); map.put("storage", getObjectFromGenericStack(job.crafting())); map.put("elapsedTimeNanos", job.elapsedTimeNanos()); map.put("totalItem", job.totalItems()); map.put("progress", job.progress()); - if (cpu != null) - map.put("cpu", getObjectFromCPU(cpu, true)); - return map; } @@ -496,137 +308,6 @@ public static boolean isFluidCrafting(MEStorage monitor, ICraftingService grid, return false; } - /// External Storage - /// Total - - public static long getTotalExternalItemStorage(IGridNode node) { - long total = 0; - - for (IGridNode iGridNode : node.getGrid().getMachineNodes(StorageBusPart.class)) { - StorageBusPart bus = (StorageBusPart) iGridNode.getService(IStorageProvider.class); - Level level = bus.getLevel(); - BlockPos connectedInventoryPos = bus.getHost().getBlockEntity().getBlockPos().relative(bus.getSide()); - BlockEntity connectedInventoryEntity = level.getBlockEntity(connectedInventoryPos); - - if (connectedInventoryEntity == null) - continue; - - LazyOptional itemHandler = connectedInventoryEntity.getCapability(ForgeCapabilities.ITEM_HANDLER); - if (itemHandler.isPresent()) { - IItemHandler handler = itemHandler.orElse(null); - for (int i = 0; i < handler.getSlots(); i++) { - total += handler.getSlotLimit(i); - } - } - } - - return total; - } - - public static long getTotalExternalFluidStorage(IGridNode node) { - long total = 0; - - for (IGridNode iGridNode : node.getGrid().getMachineNodes(StorageBusPart.class)) { - StorageBusPart bus = (StorageBusPart) iGridNode.getService(IStorageProvider.class); - Level level = bus.getLevel(); - BlockPos connectedInventoryPos = bus.getHost().getBlockEntity().getBlockPos().relative(bus.getSide()); - BlockEntity connectedInventoryEntity = level.getBlockEntity(connectedInventoryPos); - - if (connectedInventoryEntity == null) - continue; - - LazyOptional fluidHandler = connectedInventoryEntity.getCapability(ForgeCapabilities.FLUID_HANDLER); - if (fluidHandler.isPresent()) { - IFluidHandler handler = fluidHandler.orElse(null); - for (int i = 0; i < handler.getTanks(); i++) { - total += handler.getTankCapacity(i); - } - } - } - - return total; - } - - public static long getTotalExternalChemicalStorage(IGridNode node) { - long total = 0; - - if (!APAddons.appMekLoaded) - return 0; - - for (IGridNode iGridNode : node.getGrid().getMachineNodes(StorageBusPart.class)) { - StorageBusPart bus = (StorageBusPart) iGridNode.getService(IStorageProvider.class); - Level level = bus.getLevel(); - BlockPos connectedInventoryPos = bus.getHost().getBlockEntity().getBlockPos().relative(bus.getSide()); - BlockEntity connectedInventoryEntity = level.getBlockEntity(connectedInventoryPos); - - if (connectedInventoryEntity == null) - continue; - - if (connectedInventoryEntity instanceof TileEntityChemicalTank tank) { - MergedChemicalTank.Current current = tank.getChemicalTank().getCurrent() == MergedChemicalTank.Current.EMPTY ? MergedChemicalTank.Current.GAS : tank.getChemicalTank().getCurrent(); - total += tank.getChemicalTank().getTankFromCurrent(current).getCapacity(); - } - } - - return total; - } - - /// Used - - public static long getUsedExternalItemStorage(IGridNode node) { - long used = 0; - - for (IGridNode iGridNode : node.getGrid().getMachineNodes(StorageBusPart.class)) { - StorageBusPart bus = (StorageBusPart) iGridNode.getService(IStorageProvider.class); - KeyCounter keyCounter = bus.getInternalHandler().getAvailableStacks(); - - for (Object2LongMap.Entry aeKey : keyCounter) { - if (aeKey.getKey() instanceof AEItemKey) - used += aeKey.getLongValue(); - } - } - - return used; - } - - public static long getUsedExternalFluidStorage(IGridNode node) { - long used = 0; - - for (IGridNode iGridNode : node.getGrid().getMachineNodes(StorageBusPart.class)) { - StorageBusPart bus = (StorageBusPart) iGridNode.getService(IStorageProvider.class); - KeyCounter keyCounter = bus.getInternalHandler().getAvailableStacks(); - - for (Object2LongMap.Entry aeKey : keyCounter) { - if (aeKey.getKey() instanceof AEFluidKey) - used += aeKey.getLongValue(); - } - } - - return used; - } - - public static long getUsedExternalChemicalStorage(IGridNode node) { - long used = 0; - - if (!APAddons.appMekLoaded) - return 0; - - for (IGridNode iGridNode : node.getGrid().getMachineNodes(StorageBusPart.class)) { - StorageBusPart bus = (StorageBusPart) iGridNode.getService(IStorageProvider.class); - KeyCounter keyCounter = bus.getInternalHandler().getAvailableStacks(); - - for (Object2LongMap.Entry aeKey : keyCounter) { - if (aeKey.getKey() instanceof MekanismKey) - used += aeKey.getLongValue(); - } - } - - return used; - } - - /// Internal Storage - /// Total - public static long getTotalItemStorage(IGridNode node) { long total = 0; @@ -654,7 +335,7 @@ public static long getTotalItemStorage(IGridNode node) { total += disk.getBytes(null); } } else if (APAddons.aeAdditionsLoaded && (stack.getItem() instanceof SuperStorageCell superStorageCell)) { - total += superStorageCell.getKiloBytes() * 1024L; + total += superStorageCell.getKiloBytes() * 1024; } else if (APAddons.aeAdditionsLoaded && (stack.getItem() instanceof StorageCell storageCell)) { if (storageCell.getKeyType() != AEKeyType.items()) continue; @@ -662,6 +343,24 @@ public static long getTotalItemStorage(IGridNode node) { } } } + + iterator = node.getGrid().getMachineNodes(StorageBusPart.class).iterator(); + + while (iterator.hasNext()) { + StorageBusPart bus = (StorageBusPart) iterator.next().getService(IStorageProvider.class); + net.minecraft.world.level.Level level = bus.getLevel(); + BlockPos connectedInventoryPos = bus.getHost().getBlockEntity().getBlockPos().relative(bus.getSide()); + BlockEntity connectedInventoryEntity = level.getBlockEntity(connectedInventoryPos); + + LazyOptional itemHandler = connectedInventoryEntity.getCapability(ForgeCapabilities.ITEM_HANDLER); + if (itemHandler.isPresent()) { + IItemHandler handler = itemHandler.orElse(null); + for (int i = 0; i < handler.getSlots(); i++) { + total += handler.getSlotLimit(i); + } + } + } + return total; } @@ -687,7 +386,7 @@ public static long getTotalFluidStorage(IGridNode node) { total += cell.getBytes(null); } } else if (APAddons.aeAdditionsLoaded && stack.getItem() instanceof SuperStorageCell superStorageCell) { - total += superStorageCell.getKiloBytes() * 1024L; + total += superStorageCell.getKiloBytes() * 1024; } else if (APAddons.aeAdditionsLoaded && (stack.getItem() instanceof StorageCell storageCell)) { if (storageCell.getKeyType() != AEKeyType.fluids()) continue; @@ -696,32 +395,19 @@ public static long getTotalFluidStorage(IGridNode node) { } } - return total; - } - - public static long getTotalChemicalStorage(IGridNode node) { - long total = 0; - - if (!APAddons.appMekLoaded) - return 0; - - for (IGridNode iGridNode : node.getGrid().getMachineNodes(DriveBlockEntity.class)) { - DriveBlockEntity entity = (DriveBlockEntity) iGridNode.getService(IStorageProvider.class); - if (entity == null) - continue; + iterator = node.getGrid().getMachineNodes(StorageBusPart.class).iterator(); - InternalInventory inventory = entity.getInternalInventory(); - - for (int i = 0; i < inventory.size(); i++) { - ItemStack stack = inventory.getStackInSlot(i); - - if (stack.isEmpty()) - continue; + while (iterator.hasNext()) { + StorageBusPart bus = (StorageBusPart) iterator.next().getService(IStorageProvider.class); + net.minecraft.world.level.Level level = bus.getLevel(); + BlockPos connectedInventoryPos = bus.getHost().getBlockEntity().getBlockPos().relative(bus.getSide()); + BlockEntity connectedInventoryEntity = level.getBlockEntity(connectedInventoryPos); - if (stack.getItem() instanceof ChemicalStorageCell cell) { - if (cell.getKeyType() instanceof MekanismKeyType) { - total += cell.getBytes(null); - } + LazyOptional fluidHandler = connectedInventoryEntity.getCapability(ForgeCapabilities.FLUID_HANDLER); + if (fluidHandler.isPresent()) { + IFluidHandler handler = fluidHandler.orElse(null); + for (int i = 0; i < handler.getTanks(); i++) { + total += handler.getTankCapacity(i); } } } @@ -729,8 +415,6 @@ public static long getTotalChemicalStorage(IGridNode node) { return total; } - /// Used - public static long getUsedItemStorage(IGridNode node) { long used = 0; @@ -749,10 +433,15 @@ public static long getUsedItemStorage(IGridNode node) { continue; if (stack.getItem() instanceof IBasicCellItem cell) { + int bytesPerType = cell.getBytesPerType(null); + if (cell.getKeyType().getClass().isAssignableFrom(AEKeyType.items().getClass())) { - BasicCellInventory cellInventory = BasicCellHandler.INSTANCE.getCellInventory(stack, null); + if (stack.getTag() == null) + continue; + int numOfType = stack.getTag().getLongArray("amts").length; + long numItemsInCell = stack.getTag().getLong("ic"); - used += cellInventory.getUsedBytes(); + used += ((int) Math.ceil(((double) numItemsInCell) / 8)) + ((long) bytesPerType * numOfType); } } else if (APAddons.aeThingsLoaded && stack.getItem() instanceof DISKDrive disk) { if (disk.getKeyType().toString().equals("ae2:i")) { @@ -779,6 +468,19 @@ public static long getUsedItemStorage(IGridNode node) { } } + iterator = node.getGrid().getMachineNodes(StorageBusPart.class).iterator(); + + while (iterator.hasNext()) { + StorageBusPart bus = (StorageBusPart) iterator.next().getService(IStorageProvider.class); + KeyCounter keyCounter = bus.getInternalHandler().getAvailableStacks(); + + for (Object2LongMap.Entry aeKey : keyCounter) { + if (aeKey.getKey() instanceof AEItemKey) { + used += aeKey.getLongValue(); + } + } + } + return used; } @@ -797,10 +499,15 @@ public static long getUsedFluidStorage(IGridNode node) { ItemStack stack = inventory.getStackInSlot(i); if (stack.getItem() instanceof IBasicCellItem cell) { + int bytesPerType = cell.getBytesPerType(null); + if (cell.getKeyType().getClass().isAssignableFrom(AEKeyType.fluids().getClass())) { - BasicCellInventory cellInventory = BasicCellHandler.INSTANCE.getCellInventory(stack, null); + if (stack.getTag() == null) + continue; + int numOfType = stack.getTag().getLongArray("amts").length; + long numBucketsInCell = stack.getTag().getLong("ic") / 1000; - used += cellInventory.getUsedBytes(); + used += ((int) Math.ceil(((double) numBucketsInCell) / 8)) + ((long) bytesPerType * numOfType); } } else if (APAddons.aeAdditionsLoaded && stack.getItem() instanceof SuperStorageCell) { if (stack.getTag() == null) @@ -820,29 +527,15 @@ public static long getUsedFluidStorage(IGridNode node) { } } - return used; - } - - public static long getUsedChemicalStorage(IGridNode node) { - long used = 0; - - if (!APAddons.appMekLoaded) - return 0; + iterator = node.getGrid().getMachineNodes(StorageBusPart.class).iterator(); - for (IGridNode iGridNode : node.getGrid().getMachineNodes(DriveBlockEntity.class)) { - DriveBlockEntity entity = (DriveBlockEntity) iGridNode.getService(IStorageProvider.class); - if (entity == null) - continue; - - InternalInventory inventory = entity.getInternalInventory(); - - for (int i = 0; i < inventory.size(); i++) { - ItemStack stack = inventory.getStackInSlot(i); - - if (stack.getItem() instanceof ChemicalStorageCell) { - BasicCellInventory cellInventory = BasicCellHandler.INSTANCE.getCellInventory(stack, null); + while (iterator.hasNext()) { + StorageBusPart bus = (StorageBusPart) iterator.next().getService(IStorageProvider.class); + KeyCounter keyCounter = bus.getInternalHandler().getAvailableStacks(); - used = cellInventory.getUsedBytes() / MekanismKeyType.TYPE.getAmountPerByte(); + for (Object2LongMap.Entry aeKey : keyCounter) { + if (aeKey.getKey() instanceof AEFluidKey fluidKey) { + used += aeKey.getLongValue(); } } } @@ -850,77 +543,14 @@ public static long getUsedChemicalStorage(IGridNode node) { return used; } - /// Available Storage - - /** - * Calculates the available item storage on a given grid node. - * It subtracts the used item storage from the total item storage. - * - * @param node The grid node to calculate the available item storage for. - * @return The available item storage in bytes. - */ public static long getAvailableItemStorage(IGridNode node) { return getTotalItemStorage(node) - getUsedItemStorage(node); } - /** - * Calculates the available fluid storage in a given grid node. - * - * @param node The grid node to calculate the available fluid storage for. - * @return The available fluid storage in bytes. - */ public static long getAvailableFluidStorage(IGridNode node) { return getTotalFluidStorage(node) - getUsedFluidStorage(node); } - public static long getAvailableChemicalStorage(IGridNode node) { - return getTotalChemicalStorage(node) - getUsedChemicalStorage(node); - } - - /** - * Calculates the available external item storage of a given grid node. - * - * @param node The grid node for which to calculate the available external item storage. - * @return The available external item storage. - */ - public static long getAvailableExternalItemStorage(IGridNode node) { - return getTotalExternalItemStorage(node) - getUsedExternalItemStorage(node); - } - - /** - * Calculates the available external fluid storage on a given grid node by subtracting the used external fluid storage - * from the total external fluid storage. - * - * @param node The grid node on which to calculate the available external fluid storage. - * @return The available external fluid storage on the grid node. - */ - public static long getAvailableExternalFluidStorage(IGridNode node) { - return getTotalExternalFluidStorage(node) - getUsedExternalFluidStorage(node); - } - - public static long getAvailableExternalChemicalStorage(IGridNode node) { - return getTotalExternalChemicalStorage(node) - getUsedExternalChemicalStorage(node); - } - - public static ICraftingCPU getCraftingCPU(IGridNode node, String cpuName) { - if (cpuName.isEmpty()) return null; - ICraftingService grid = node.getGrid().getService(ICraftingService.class); - if (grid == null) return null; - - Iterator iterator = grid.getCpus().iterator(); - if (!iterator.hasNext()) return null; - - while (iterator.hasNext()) { - ICraftingCPU cpu = iterator.next(); - - if (cpu.getName() != null && cpu.getName().getString().equals(cpuName)) { - return cpu; - } - } - - return null; - } - public static List listCells(IGridNode node) { List items = new ArrayList<>(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/CraftJob.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/CraftJob.java index 05db7c7c6..1b2d5d9a9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/CraftJob.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/CraftJob.java @@ -52,6 +52,7 @@ protected void fireEvent(boolean success, @Nullable String exception) { this.result = MethodResult.of(success, exception); this.exception = new LuaException(exception); this.computer.queueEvent(EVENT, success, exception); + } protected void fireNotConnected() { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeBridgeEntityListener.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeBridgeEntityListener.java index 10cc242fb..1aee16c85 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeBridgeEntityListener.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeBridgeEntityListener.java @@ -4,17 +4,18 @@ import appeng.api.networking.IGridNodeListener; import de.srendi.advancedperipherals.common.blocks.blockentities.MeBridgeEntity; +//TODO: Maybe do something special with these methods? public class MeBridgeEntityListener implements IGridNodeListener { public static final MeBridgeEntityListener INSTANCE = new MeBridgeEntityListener(); @Override public void onSecurityBreak(MeBridgeEntity nodeOwner, IGridNode node) { - // Maybe do something special with these methods? + } @Override public void onSaveChanges(MeBridgeEntity nodeOwner, IGridNode node) { - // Maybe do something special with these methods? + } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeFluidHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeFluidHandler.java index 6f10b6be9..8072a777d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeFluidHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeFluidHandler.java @@ -12,7 +12,6 @@ /** * Used to transfer item between an inventory and the ME system. - * * @see de.srendi.advancedperipherals.common.addons.computercraft.peripheral.MeBridgePeripheral */ public class MeFluidHandler implements IStorageSystemFluidHandler { @@ -29,7 +28,7 @@ public MeFluidHandler(@NotNull MEStorage storageMonitor, @NotNull IActionSource @Override public int fill(FluidStack resource, FluidAction action) { - if (resource.isEmpty()) + if(resource.isEmpty()) return 0; AEFluidKey itemKey = AEFluidKey.of(resource.getFluid()); long inserted = storageMonitor.insert(itemKey, resource.getAmount(), action == FluidAction.SIMULATE ? Actionable.SIMULATE : Actionable.MODULATE, actionSource); @@ -41,7 +40,7 @@ public int fill(FluidStack resource, FluidAction action) { @Override public FluidStack drain(FluidFilter filter, FluidAction simulate) { Pair itemKey = AppEngApi.findAEFluidFromFilter(storageMonitor, null, filter); - if (itemKey == null) + if(itemKey == null) return FluidStack.EMPTY; long extracted = storageMonitor.extract(itemKey.getRight(), filter.getCount(), simulate == FluidAction.SIMULATE ? Actionable.SIMULATE : Actionable.MODULATE, actionSource); return new FluidStack(itemKey.getRight().getFluid(), (int) Math.min(extracted, Integer.MAX_VALUE)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaFlowerIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaFlowerIntegration.java index fb3c8e1c2..4a18763bd 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaFlowerIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaFlowerIntegration.java @@ -15,7 +15,7 @@ public ManaFlowerIntegration(BlockEntity entity) { @NotNull @Override public String getType() { - return "mana_flower"; + return "manaFlower"; } @LuaFunction(mainThread = true) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaPoolIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaPoolIntegration.java index 2d2fb83c9..cea44bbe9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaPoolIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaPoolIntegration.java @@ -15,7 +15,7 @@ public ManaPoolIntegration(BlockEntity entity) { @NotNull @Override public String getType() { - return "mana_pool"; + return "manaPool"; } @LuaFunction(mainThread = true) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/botania/SpreaderIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/botania/SpreaderIntegration.java index d615db44f..e0ea451f9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/botania/SpreaderIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/botania/SpreaderIntegration.java @@ -16,7 +16,7 @@ public SpreaderIntegration(BlockEntity entity) { @NotNull @Override public String getType() { - return "mana_spreader"; + return "manaSpreader"; } @LuaFunction(mainThread = true) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/BeaconIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/BeaconIntegration.java index 0a35755df..09e655726 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/BeaconIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/BeaconIntegration.java @@ -2,6 +2,7 @@ import dan200.computercraft.api.lua.LuaFunction; import de.srendi.advancedperipherals.lib.peripherals.BlockEntityIntegrationPeripheral; +import net.minecraft.nbt.CompoundTag; import net.minecraft.world.level.block.entity.BeaconBlockEntity; import net.minecraft.world.level.block.entity.BlockEntity; import org.jetbrains.annotations.NotNull; @@ -19,7 +20,9 @@ public BeaconIntegration(BlockEntity entity) { @LuaFunction(mainThread = true) public final int getLevel() { - return blockEntity.levels; + // because levels are now protected field .... why? + CompoundTag savedData = blockEntity.saveWithoutMetadata(); + return savedData.getInt("Levels"); } @LuaFunction(mainThread = true) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/IntegrationPeripheralProvider.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/IntegrationPeripheralProvider.java index 2d9ccb553..f5c2fef95 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/IntegrationPeripheralProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/integrations/IntegrationPeripheralProvider.java @@ -23,7 +23,7 @@ public class IntegrationPeripheralProvider implements IPeripheralProvider { - private static final String[] SUPPORTED_MODS = new String[]{"botania", "create", "mekanism", "powah", "dimstorage"}; + private static final String[] SUPPORTED_MODS = new String[]{"botania", "create", "mekanism", "powah"}; private static final PriorityQueue integrations = new PriorityQueue<>(Comparator.comparingInt(IPeripheralIntegration::getPriority)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SingleOperation.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SingleOperation.java index df8cd27e9..08ebd3c6b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SingleOperation.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SingleOperation.java @@ -5,7 +5,7 @@ import java.util.HashMap; import java.util.Map; -import java.util.function.UnaryOperator; +import java.util.function.Function; public enum SingleOperation implements IPeripheralOperation { DIG(1000, 1), @@ -76,9 +76,9 @@ public enum DistancePolicy { IGNORED(d -> 1), SQRT(d -> (int) Math.sqrt(d)); - private final UnaryOperator factorFunction; + private final Function factorFunction; - DistancePolicy(UnaryOperator factorFunction) { + DistancePolicy(Function factorFunction) { this.factorFunction = factorFunction; } @@ -90,9 +90,9 @@ public int getFactor(int distance) { public enum CountPolicy { MULTIPLY(c -> c); - private final UnaryOperator factorFunction; + private final Function factorFunction; - CountPolicy(UnaryOperator factorFunction) { + CountPolicy(Function factorFunction) { this.factorFunction = factorFunction; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BasePeripheralOwner.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BasePeripheralOwner.java index 5503c3bdf..c23b0d025 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BasePeripheralOwner.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BasePeripheralOwner.java @@ -9,7 +9,7 @@ public abstract class BasePeripheralOwner implements IPeripheralOwner { private final Map, IOwnerAbility> abilities; - protected BasePeripheralOwner() { + public BasePeripheralOwner() { abilities = new HashMap<>(); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java index 4e7d1bd94..0317806d4 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java @@ -12,8 +12,8 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.JigsawBlock; import net.minecraft.world.level.block.entity.BlockEntity; -import org.apache.commons.lang3.NotImplementedException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -50,7 +50,7 @@ public BlockPos getPos() { @NotNull @Override public Direction getFacing() { - return getOrientation().front(); + return tileEntity.getBlockState().getValue(JigsawBlock.ORIENTATION).front(); } @NotNull @@ -80,7 +80,7 @@ public void markDataStorageDirty() { @Override public T1 withPlayer(Function function) { - throw new NotImplementedException(); + throw new RuntimeException("Not implemented yet"); } @Override @@ -91,7 +91,7 @@ public ItemStack getToolInMainHand() { @Override public ItemStack storeItem(ItemStack stored) { // TODO: tricks with capability needed - throw new NotImplementedException(); + throw new RuntimeException("Not implemented yet"); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/FuelAbility.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/FuelAbility.java index 80ecdefb0..07245d648 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/FuelAbility.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/FuelAbility.java @@ -14,7 +14,7 @@ public abstract class FuelAbility implements IOwnerA protected @NotNull T owner; - protected FuelAbility(@NotNull T owner) { + public FuelAbility(@NotNull T owner) { this.owner = owner; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/PeripheralOwnerAbility.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/PeripheralOwnerAbility.java index fefa8a5be..4f5627f5e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/PeripheralOwnerAbility.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/PeripheralOwnerAbility.java @@ -5,6 +5,6 @@ public class PeripheralOwnerAbility { public static final PeripheralOwnerAbility> FUEL = new PeripheralOwnerAbility<>(); public static final PeripheralOwnerAbility OPERATION = new PeripheralOwnerAbility<>(); - private PeripheralOwnerAbility() { + public PeripheralOwnerAbility() { } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/PocketPeripheralOwner.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/PocketPeripheralOwner.java index ee9153f06..5cd8e588c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/PocketPeripheralOwner.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/PocketPeripheralOwner.java @@ -12,7 +12,6 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; -import org.apache.commons.lang3.NotImplementedException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -89,7 +88,7 @@ public void markDataStorageDirty() { @Override public T withPlayer(Function function) { - throw new NotImplementedException(); + throw new RuntimeException("Not implemented yet"); } @Override @@ -99,12 +98,13 @@ public ItemStack getToolInMainHand() { @Override public ItemStack storeItem(ItemStack stored) { - throw new NotImplementedException(); + // Tricks with inventory needed + throw new RuntimeException("Not implemented yet"); } @Override public void destroyUpgrade() { - throw new NotImplementedException(); + throw new RuntimeException("Not implemented yet"); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/BlockReaderPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/BlockReaderPeripheral.java index ce78b5077..086fa4fe9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/BlockReaderPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/BlockReaderPeripheral.java @@ -18,7 +18,7 @@ public class BlockReaderPeripheral extends BasePeripheral> { - public static final String PERIPHERAL_TYPE = "block_reader"; + public static final String PERIPHERAL_TYPE = "blockReader"; public BlockReaderPeripheral(BlockReaderEntity tileEntity) { super(PERIPHERAL_TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java index 41469e211..4519202af 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java @@ -17,11 +17,11 @@ import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.events.Events; -import de.srendi.advancedperipherals.common.network.PacketHandler; import de.srendi.advancedperipherals.common.util.CoordUtil; import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; import de.srendi.advancedperipherals.lib.peripherals.IPeripheralFunction; -import de.srendi.advancedperipherals.common.network.toclient.ToastToClientPacket; +import de.srendi.advancedperipherals.network.APNetworking; +import de.srendi.advancedperipherals.network.toclient.ToastToClientPacket; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceKey; @@ -37,7 +37,7 @@ public class ChatBoxPeripheral extends BasePeripheral { - public static final String PERIPHERAL_TYPE = "chat_box"; + public static final String PERIPHERAL_TYPE = "chatBox"; private long lastConsumedMessage; @@ -232,7 +232,7 @@ public final MethodResult sendFormattedToastToPlayer(@NotNull IArguments argumen if (range == -1 || CoordUtil.isInRange(getPos(), getLevel(), player, range, maxRange)) { ToastToClientPacket packet = new ToastToClientPacket(titleComponent, preparedMessage); - PacketHandler.sendTo(packet, player); + APNetworking.sendTo(packet, player); } return MethodResult.of(true); @@ -297,7 +297,7 @@ public final MethodResult sendToastToPlayer(@NotNull IArguments arguments) throw if (range == -1 || CoordUtil.isInRange(getPos(), getLevel(), player, range, maxRange)) { ToastToClientPacket packet = new ToastToClientPacket(Component.literal(title), preparedMessage); - PacketHandler.sendTo(packet, player); + APNetworking.sendTo(packet, player); } return MethodResult.of(true); }); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ColonyPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ColonyPeripheral.java index ae97a5c6b..5a689c538 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ColonyPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ColonyPeripheral.java @@ -37,7 +37,7 @@ public class ColonyPeripheral extends BasePeripheral { - public static final String PERIPHERAL_TYPE = "colony_integrator"; + public static final String PERIPHERAL_TYPE = "colonyIntegrator"; protected boolean hasPermission = true; @@ -272,7 +272,7 @@ public final Object getRequests() throws LuaException { map.put("state", request.getState().toString()); map.put("count", deliverableRequest.getCount()); map.put("minCount", deliverableRequest.getMinimumCount()); - map.put("items", request.getDisplayStacks().stream().map(LuaConverter::itemStackToObject).collect(Collectors.toList())); + map.put("items", request.getDisplayStacks().stream().map(LuaConverter::stackToObject).collect(Collectors.toList())); map.put("target", request.getRequester().getRequesterDisplayName(requestManager, request).getString()); result.add(map); }); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java deleted file mode 100644 index af1045e4c..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java +++ /dev/null @@ -1,103 +0,0 @@ -package de.srendi.advancedperipherals.common.addons.computercraft.peripheral; - -import dan200.computercraft.api.lua.LuaFunction; -import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner; -import de.srendi.advancedperipherals.common.blocks.blockentities.DistanceDetectorEntity; -import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; - -public class DistanceDetectorPeripheral extends BasePeripheral> { - - public static final String PERIPHERAL_TYPE = "distance_detector"; - - public DistanceDetectorPeripheral(DistanceDetectorEntity tileEntity) { - super(PERIPHERAL_TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); - } - - @Override - public boolean isEnabled() { - return APConfig.PERIPHERALS_CONFIG.enableDistanceDetector.get(); - } - - @LuaFunction - public final void setLaserVisibility(boolean laser) { - getPeripheralOwner().tileEntity.setShowLaser(laser); - } - - @LuaFunction - public final boolean getLaserVisibility() { - return getPeripheralOwner().tileEntity.getLaserVisibility(); - } - - @LuaFunction - public final void setIgnoreTransparency(boolean enable) { - getPeripheralOwner().tileEntity.setIgnoreTransparent(enable); - } - - @LuaFunction - public final boolean ignoresTransparency() { - return getPeripheralOwner().tileEntity.ignoreTransparent(); - } - - @LuaFunction - public final void setDetectionMode(int mode) { - if (mode > 2) mode = 2; - if (mode < 0) mode = 0; - getPeripheralOwner().tileEntity.setDetectionType(DetectionType.values()[mode]); - } - - @LuaFunction - public final boolean detectsEntities() { - DetectionType detectionType = getPeripheralOwner().tileEntity.getDetectionType(); - return detectionType == DetectionType.ENTITIES || detectionType == DetectionType.BOTH; - } - - @LuaFunction - public final boolean detectsBlocks() { - DetectionType detectionType = getPeripheralOwner().tileEntity.getDetectionType(); - return detectionType == DetectionType.BLOCK || detectionType == DetectionType.BOTH; - } - - @LuaFunction - public final String getDetectionMode() { - DetectionType detectionType = getPeripheralOwner().tileEntity.getDetectionType(); - return detectionType.toString(); - } - - @LuaFunction - public final double getDistance() { - return getPeripheralOwner().tileEntity.getCurrentDistance() - 1; - } - - @LuaFunction - public final double calculateDistance() { - return getPeripheralOwner().tileEntity.calculateDistance() - 1; - } - - @LuaFunction - public final boolean shouldCalculatePeriodically() { - return getPeripheralOwner().tileEntity.shouldCalculatePeriodically(); - } - - @LuaFunction - public final void setCalculatePeriodically(boolean shouldRenderPeriodically) { - getPeripheralOwner().tileEntity.setShouldCalculatePeriodically(shouldRenderPeriodically); - } - - @LuaFunction - public final void setMaxRange(double maxDistance) { - getPeripheralOwner().tileEntity.setMaxRange(Math.max(0, Math.min(APConfig.PERIPHERALS_CONFIG.distanceDetectorRange.get(), maxDistance))); - } - - @LuaFunction - public final double getMaxRange() { - return getPeripheralOwner().tileEntity.getMaxDistance(); - } - - public enum DetectionType { - BLOCK, - ENTITIES, - BOTH - } - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/EnergyDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/EnergyDetectorPeripheral.java index 0898fb611..8b0e016f2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/EnergyDetectorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/EnergyDetectorPeripheral.java @@ -8,7 +8,7 @@ public class EnergyDetectorPeripheral extends BasePeripheral> { - public static final String PERIPHERAL_TYPE = "energy_detector"; + public static final String PERIPHERAL_TYPE = "energyDetector"; public EnergyDetectorPeripheral(EnergyDetectorEntity tileEntity) { super(PERIPHERAL_TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/EnvironmentDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/EnvironmentDetectorPeripheral.java index 0054a4d45..f37aa156e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/EnvironmentDetectorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/EnvironmentDetectorPeripheral.java @@ -36,6 +36,7 @@ import net.minecraftforge.event.entity.player.SleepingTimeCheckEvent; import net.minecraftforge.eventbus.api.Event; import net.minecraftforge.server.ServerLifecycleHooks; + import org.jetbrains.annotations.NotNull; import java.util.*; @@ -45,7 +46,7 @@ public class EnvironmentDetectorPeripheral extends BasePeripheral { - public static final String PERIPHERAL_TYPE = "environment_detector"; + public static final String PERIPHERAL_TYPE = "environmentDetector"; private static final List> PERIPHERAL_PLUGINS = new LinkedList<>(); protected EnvironmentDetectorPeripheral(IPeripheralOwner owner) { @@ -172,10 +173,13 @@ private Map getCurrentMoonPhase() { case 5 -> moon.put(5, "Waxing crescent"); case 6 -> moon.put(6, "First quarter"); case 7 -> moon.put(7, "Waxing gibbous"); - default -> moon.put(0, "What is a moon"); + default -> + //should never happen + moon.put(0, "What is a moon"); } } else { - // aren't we in the overworld? + //Yay, easter egg + //Returns when the function is not used in the overworld moon.put(0, "Moon.exe not found..."); } return moon; @@ -228,10 +232,10 @@ public final MethodResult canSleepHere() { @LuaFunction(mainThread = true) public final MethodResult canSleepPlayer(String playername) { Player player = ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayerByName(playername); - if (player == null) + if(player == null) return MethodResult.of(false, "player_not_online"); - if (!player.level.dimensionType().bedWorks()) + if(!player.level.dimensionType().bedWorks()) return MethodResult.of(false, "not_allowed_in_dimension"); SleepingTimeCheckEvent evt = new SleepingTimeCheckEvent(player, Optional.empty()); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/FluidDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/FluidDetectorPeripheral.java deleted file mode 100644 index c54dde612..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/FluidDetectorPeripheral.java +++ /dev/null @@ -1,43 +0,0 @@ -package de.srendi.advancedperipherals.common.addons.computercraft.peripheral; - -import dan200.computercraft.api.lua.LuaFunction; -import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner; -import de.srendi.advancedperipherals.common.blocks.blockentities.FluidDetectorEntity; -import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; -import net.minecraftforge.registries.ForgeRegistries; - -public class FluidDetectorPeripheral extends BasePeripheral> { - - public static final String TYPE = "fluid_detector"; - - public FluidDetectorPeripheral(FluidDetectorEntity tileEntity) { - super(TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); - } - - @Override - public boolean isEnabled() { - return APConfig.PERIPHERALS_CONFIG.enableFluidDetector.get(); - } - - @LuaFunction(mainThread = true) - public final int getTransferRateLimit() { - return owner.tileEntity.storageProxy.getMaxTransferRate(); - } - - @LuaFunction(mainThread = true) - public final String getTransferedFluid() { - return ForgeRegistries.FLUIDS.getKey(owner.tileEntity.lastFlowedLiquid.getFluid()).toString(); - } - - @LuaFunction(mainThread = true) - public final void setTransferRateLimit(long transferRate) { - transferRate = Math.min(APConfig.PERIPHERALS_CONFIG.fluidDetectorMaxFlow.get(), transferRate); - owner.tileEntity.storageProxy.setMaxTransferRate((int) transferRate); - } - - @LuaFunction(mainThread = true) - public final int getTransferRate() { - return owner.tileEntity.transferRate; - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/GasDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/GasDetectorPeripheral.java deleted file mode 100644 index fd94811e3..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/GasDetectorPeripheral.java +++ /dev/null @@ -1,42 +0,0 @@ -package de.srendi.advancedperipherals.common.addons.computercraft.peripheral; - -import dan200.computercraft.api.lua.LuaFunction; -import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner; -import de.srendi.advancedperipherals.common.blocks.blockentities.GasDetectorEntity; -import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; - -public class GasDetectorPeripheral extends BasePeripheral> { - - public static final String TYPE = "gas_detector"; - - public GasDetectorPeripheral(GasDetectorEntity tileEntity) { - super(TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); - } - - @Override - public boolean isEnabled() { - return APConfig.PERIPHERALS_CONFIG.enableGasDetector.get(); - } - - @LuaFunction(mainThread = true) - public final int getTransferRateLimit() { - return owner.tileEntity.storageProxy.getMaxTransferRate(); - } - - @LuaFunction(mainThread = true) - public final String getTransferedGas() { - return owner.tileEntity.lastFlowedGas.getRaw().getRegistryName().toString(); - } - - @LuaFunction(mainThread = true) - public final void setTransferRateLimit(long transferRate) { - transferRate = Math.min(APConfig.PERIPHERALS_CONFIG.gasDetectorMaxFlow.get(), transferRate); - owner.tileEntity.storageProxy.setMaxTransferRate((int) transferRate); - } - - @LuaFunction(mainThread = true) - public final int getTransferRate() { - return owner.tileEntity.transferRate; - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/GeoScannerPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/GeoScannerPeripheral.java index c94496149..438815585 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/GeoScannerPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/GeoScannerPeripheral.java @@ -41,7 +41,7 @@ public class GeoScannerPeripheral extends BasePeripheral { Highly inspired by https://github.com/SquidDev-CC/plethora/ BlockScanner */ - public static final String PERIPHERAL_TYPE = "geo_scanner"; + public static final String PERIPHERAL_TYPE = "geoScanner"; protected GeoScannerPeripheral(IPeripheralOwner owner) { super(PERIPHERAL_TYPE, owner); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java index 6f93e56cf..66abb49fb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java @@ -23,15 +23,15 @@ import net.minecraftforge.items.wrapper.PlayerArmorInvWrapper; import net.minecraftforge.items.wrapper.PlayerInvWrapper; import net.minecraftforge.items.wrapper.PlayerOffhandInvWrapper; - import org.jetbrains.annotations.NotNull; + import java.util.ArrayList; import java.util.List; import java.util.Map; public class InventoryManagerPeripheral extends BasePeripheral> { - public static final String PERIPHERAL_TYPE = "inventory_manager"; + public static final String PERIPHERAL_TYPE = "inventoryManager"; public InventoryManagerPeripheral(InventoryManagerEntity tileEntity) { super(PERIPHERAL_TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); @@ -187,19 +187,14 @@ public final int getFreeSlot() throws LuaException { return getOwnerPlayer().getInventory().getFreeSlot(); } - @LuaFunction(mainThread = true) - public final int getHandSlot() throws LuaException { - return getOwnerPlayer().getInventory().selected; - } - @LuaFunction(mainThread = true) public final Map getItemInHand() throws LuaException { - return LuaConverter.itemStackToObject(getOwnerPlayer().getMainHandItem(), getOwnerPlayer().getInventory().selected); + return LuaConverter.stackToObject(getOwnerPlayer().getMainHandItem()); } @LuaFunction(mainThread = true) public final Map getItemInOffHand() throws LuaException { - return LuaConverter.itemStackToObject(getOwnerPlayer().getOffhandItem()); + return LuaConverter.stackToObject(getOwnerPlayer().getOffhandItem()); } private Player getOwnerPlayer() throws LuaException { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java index 7eb22d097..731e451f4 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java @@ -1,6 +1,5 @@ package de.srendi.advancedperipherals.common.addons.computercraft.peripheral; -import appeng.api.crafting.IPatternDetails; import appeng.api.networking.IGridNode; import appeng.api.networking.IManagedGridNode; import appeng.api.networking.crafting.ICraftingCPU; @@ -8,14 +7,11 @@ import appeng.api.stacks.AEFluidKey; import appeng.api.stacks.AEItemKey; import appeng.api.storage.MEStorage; -import appeng.me.cluster.implementations.CraftingCPUCluster; import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.lua.MethodResult; import dan200.computercraft.api.peripheral.IComputerAccess; -import dan200.computercraft.core.apis.TableHelper; -import dan200.computercraft.core.computer.ComputerSide; import de.srendi.advancedperipherals.common.addons.appliedenergistics.AppEngApi; import de.srendi.advancedperipherals.common.addons.appliedenergistics.CraftJob; import de.srendi.advancedperipherals.common.addons.appliedenergistics.MeFluidHandler; @@ -25,17 +21,21 @@ import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.util.Pair; import de.srendi.advancedperipherals.common.util.ServerWorker; -import de.srendi.advancedperipherals.common.util.inventory.*; +import de.srendi.advancedperipherals.common.util.inventory.FluidFilter; +import de.srendi.advancedperipherals.common.util.inventory.FluidUtil; +import de.srendi.advancedperipherals.common.util.inventory.InventoryUtil; +import de.srendi.advancedperipherals.common.util.inventory.ItemFilter; import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; -import net.minecraft.core.Direction; import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.items.IItemHandler; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; -public class MeBridgePeripheral extends BasePeripheral> implements IStorageSystemPeripheral { +public class MeBridgePeripheral extends BasePeripheral> { public static final String PERIPHERAL_TYPE = "meBridge"; private final MeBridgeEntity tile; @@ -148,637 +148,408 @@ private MethodResult notConnected() { return MethodResult.of(null, "NOT_CONNECTED"); } - private boolean isAvailable() { - return node.getGrid() != null && node.hasGridBooted(); - } - - @Override - @LuaFunction(mainThread = true) - public final MethodResult isConnected() { - return MethodResult.of(isAvailable()); - } - - @Override @LuaFunction(mainThread = true) - public MethodResult isOnline() { - return MethodResult.of(node.isOnline()); + public final boolean isConnected() { + return node.getGrid() != null && node.hasGridBooted() && node.isActive(); } - @Override - @LuaFunction(mainThread = true) - public final MethodResult getItem(IArguments arguments) throws LuaException { - if (!isAvailable()) + @LuaFunction + public final MethodResult craftItem(IComputerAccess computer, IArguments arguments) throws LuaException { + if (!isConnected()) return notConnected(); - MEStorage monitor = AppEngApi.getMonitor(node); Pair filter = ItemFilter.parse(arguments.getTable(0)); if (filter.rightPresent()) - return MethodResult.of(null, filter.getRight()); + return MethodResult.of(false, filter.getRight()); ItemFilter parsedFilter = filter.getLeft(); if (parsedFilter.isEmpty()) - return MethodResult.of(null, "EMPTY_FILTER"); + return MethodResult.of(false, "EMPTY_FILTER"); - return MethodResult.of(AppEngApi.getObjectFromStack(AppEngApi.findAEStackFromFilter(monitor, getCraftingService(), parsedFilter), getCraftingService())); + String cpuName = arguments.optString(1, ""); + ICraftingCPU target = getCraftingCPU(cpuName); + if (!cpuName.isEmpty() && target == null) + return MethodResult.of(false, "CPU " + cpuName + " does not exists"); + + ICraftingService craftingGrid = node.getGrid().getService(ICraftingService.class); + Pair stack = AppEngApi.findAEStackFromFilter(AppEngApi.getMonitor(tile.getGridNode()), craftingGrid, filter.getLeft()); + if (stack.getRight() == null && stack.getLeft() == 0) + return MethodResult.of(null, "NOT_CRAFTABLE"); + + CraftJob job = new CraftJob(owner.getLevel(), computer, node, stack.getRight(), parsedFilter.getCount(), tile, tile, target); + tile.addJob(job); + ServerWorker.add(job::startCrafting); + return MethodResult.of(true); } - @Override - @LuaFunction(mainThread = true) - public MethodResult getFluid(IArguments arguments) throws LuaException { - if (!isAvailable()) + @LuaFunction + public final MethodResult craftFluid(IComputerAccess computer, IArguments arguments) throws LuaException { + if (!isConnected()) return notConnected(); Pair filter = FluidFilter.parse(arguments.getTable(0)); if (filter.rightPresent()) - return MethodResult.of(null, filter.getRight()); + return MethodResult.of(false, filter.getRight()); FluidFilter parsedFilter = filter.getLeft(); if (parsedFilter.isEmpty()) - return MethodResult.of(null, "EMPTY_FILTER"); + return MethodResult.of(false, "EMPTY_FILTER"); - return MethodResult.of(AppEngApi.findAEFluidFromFilter(AppEngApi.getMonitor(node), getCraftingService(), parsedFilter)); - } + String cpuName = arguments.optString(1, ""); + ICraftingCPU target = getCraftingCPU(cpuName); + if (!cpuName.isEmpty() && target == null) + return MethodResult.of(false, "CPU " + cpuName + " does not exists"); - @Override - @LuaFunction(mainThread = true) - public final MethodResult listItems() { - if (!isAvailable()) - return notConnected(); + ICraftingService craftingGrid = node.getGrid().getService(ICraftingService.class); + Pair stack = AppEngApi.findAEFluidFromFilter(AppEngApi.getMonitor(tile.getGridNode()), craftingGrid, filter.getLeft()); + if (stack.getRight() == null && stack.getLeft() == 0) + return MethodResult.of(null, "NOT_CRAFTABLE"); - return MethodResult.of(AppEngApi.listStacks(AppEngApi.getMonitor(node), getCraftingService())); + CraftJob job = new CraftJob(owner.getLevel(), computer, node, stack.getRight(), parsedFilter.getCount(), tile, tile, target); + tile.addJob(job); + ServerWorker.add(job::startCrafting); + return MethodResult.of(true); } - @Override @LuaFunction(mainThread = true) - public final MethodResult listFluids() { - if (!isAvailable()) + public final MethodResult getEnergyUsage() { + if (!isConnected()) return notConnected(); - return MethodResult.of(AppEngApi.listFluids(AppEngApi.getMonitor(node), getCraftingService())); + return MethodResult.of(node.getGrid().getEnergyService().getAvgPowerUsage()); } - @Override @LuaFunction(mainThread = true) - public final MethodResult listCraftableItems() { - if (!isAvailable()) + public final MethodResult getEnergyStorage() { + if (!isConnected()) return notConnected(); - return MethodResult.of(AppEngApi.listCraftableStacks(AppEngApi.getMonitor(node), getCraftingService())); + return MethodResult.of(node.getGrid().getEnergyService().getStoredPower()); } - @Override @LuaFunction(mainThread = true) - public final MethodResult listCraftableFluids() { - if (!isAvailable()) + public final MethodResult getAvgPowerUsage() { + if (!isConnected()) return notConnected(); - return MethodResult.of(AppEngApi.listCraftableStacks(AppEngApi.getMonitor(node), getCraftingService())); + return MethodResult.of(node.getGrid().getEnergyService().getAvgPowerUsage()); } - @Override @LuaFunction(mainThread = true) - public final MethodResult listCells() { - if (!isAvailable()) + public final MethodResult getAvgPowerInjection() { + if (!isConnected()) return notConnected(); - return MethodResult.of(AppEngApi.listCells(node)); + return MethodResult.of(node.getGrid().getEnergyService().getAvgPowerInjection()); } - @Override - @LuaFunction(mainThread = true) - public MethodResult listDrives() { - if (!isAvailable()) - return notConnected(); - - return MethodResult.of(AppEngApi.listDrives(node.getGrid())); - } - @Override @LuaFunction(mainThread = true) - public final MethodResult importItem(IComputerAccess computer, IArguments arguments) throws LuaException { - if (!isAvailable()) + public final MethodResult getMaxEnergyStorage() { + if (!isConnected()) return notConnected(); - String side = arguments.getString(1); - IItemHandler inventory; - - if (Direction.byName(side.toUpperCase(Locale.ROOT)) == null && ComputerSide.valueOfInsensitive(side.toUpperCase(Locale.ROOT)) == null) { - inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); - } else { - inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); - } - - return importToME(arguments, inventory); + return MethodResult.of(node.getGrid().getEnergyService().getMaxStoredPower()); } - @Override @LuaFunction(mainThread = true) - public final MethodResult exportItem(IComputerAccess computer, @NotNull IArguments arguments) throws LuaException { - if (!isAvailable()) + public final MethodResult isItemCrafting(IArguments arguments) throws LuaException { + if (!isConnected()) return notConnected(); - String side = arguments.getString(1); - IItemHandler inventory; + MEStorage monitor = AppEngApi.getMonitor(node); + ICraftingService grid = node.getGrid().getService(ICraftingService.class); + + Pair filter = ItemFilter.parse(arguments.getTable(0)); + if (filter.rightPresent()) + return MethodResult.of(false, filter.getRight()); - if (Direction.byName(side.toUpperCase(Locale.ROOT)) == null && ComputerSide.valueOfInsensitive(side.toUpperCase(Locale.ROOT)) == null) { - inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); - } else { - inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); - } + ItemFilter parsedFilter = filter.getLeft(); + if (parsedFilter.isEmpty()) + return MethodResult.of(false, "EMPTY_FILTER"); + String cpuName = arguments.optString(1, ""); + ICraftingCPU craftingCPU = getCraftingCPU(cpuName); - return exportToChest(arguments, inventory); + return MethodResult.of(AppEngApi.isItemCrafting(monitor, grid, parsedFilter, craftingCPU)); } - @Override @LuaFunction(mainThread = true) - public MethodResult getFilteredPatterns(IArguments arguments) throws LuaException { - if (!isAvailable()) + public final MethodResult isItemCraftable(IArguments arguments) throws LuaException { + if (!isConnected()) return notConnected(); - // Expected input is a table with either an input table, an output table or both to filter for both - Map filterTable; - try { - Optional> optionalTable = arguments.optTable(0); - if (optionalTable.isEmpty()) - return MethodResult.of(null, "EMPTY_INPUT"); - filterTable = optionalTable.get(); - } catch (LuaException e) { - return MethodResult.of(null, "NO_TABLE"); - } - - boolean hasInputFilter = filterTable.containsKey("input"); - boolean hasOutputFilter = filterTable.containsKey("output"); - boolean hasAnyFilter = hasInputFilter || hasOutputFilter; - - // If the player tries to filter for nothing, return nothing. - if (!hasAnyFilter) - return MethodResult.of(null, "NO_FILTER"); - - GenericFilter inputFilter = null; - GenericFilter outputFilter = null; - - if (hasInputFilter) { - Map inputFilterTable = TableHelper.getTableField(filterTable, "input"); - - inputFilter = GenericFilter.parseGeneric(inputFilterTable).getLeft(); - } - if (hasOutputFilter) { - Map outputFilterTable = TableHelper.getTableField(filterTable, "output"); - - outputFilter = GenericFilter.parseGeneric(outputFilterTable).getLeft(); - } - + Pair filter = ItemFilter.parse(arguments.getTable(0)); + if (filter.rightPresent()) + return MethodResult.of(false, filter.getRight()); - Pair pattern = AppEngApi.findPatternFromFilters(node.getGrid(), getLevel(), inputFilter, outputFilter); + ItemFilter parsedFilter = filter.getLeft(); + if (parsedFilter.isEmpty()) + return MethodResult.of(false, "EMPTY_FILTER"); - if (pattern.getRight() != null) - return MethodResult.of(null, pattern.getRight()); + AEItemKey item = AEItemKey.of(parsedFilter.toItemStack()); - return MethodResult.of(AppEngApi.getObjectFromPattern(pattern.getLeft())); + return MethodResult.of(getCraftingService().isCraftable(item)); } - @Override @LuaFunction(mainThread = true) - public MethodResult getPatterns() { - if (!isAvailable()) + public final MethodResult isFluidCrafting(IArguments arguments) throws LuaException { + if (!isConnected()) return notConnected(); - return MethodResult.of(AppEngApi.listPatterns(node.getGrid(), getLevel())); - } - - @Override - @LuaFunction(mainThread = true) - public final MethodResult getStoredEnergy() { - if (!isAvailable()) - return notConnected(); + MEStorage monitor = AppEngApi.getMonitor(node); + ICraftingService grid = node.getGrid().getService(ICraftingService.class); - return MethodResult.of(node.getGrid().getEnergyService().getStoredPower()); - } + Pair filter = FluidFilter.parse(arguments.getTable(0)); + if (filter.rightPresent()) + return MethodResult.of(false, filter.getRight()); - @Override - @LuaFunction(mainThread = true) - public final MethodResult getEnergyCapacity() { - if (!isAvailable()) - return notConnected(); + FluidFilter parsedFilter = filter.getLeft(); + if (parsedFilter.isEmpty()) + return MethodResult.of(false, "EMPTY_FILTER"); + String cpuName = arguments.optString(1, ""); + ICraftingCPU craftingCPU = getCraftingCPU(cpuName); - return MethodResult.of(node.getGrid().getEnergyService().getMaxStoredPower()); + return MethodResult.of(AppEngApi.isFluidCrafting(monitor, grid, parsedFilter, craftingCPU)); } - @Override @LuaFunction(mainThread = true) - public final MethodResult getEnergyUsage() { - if (!isAvailable()) + public final MethodResult isFluidCraftable(IArguments arguments) throws LuaException { + if (!isConnected()) return notConnected(); - return MethodResult.of(node.getGrid().getEnergyService().getAvgPowerUsage()); - } - - @Override - @LuaFunction(mainThread = true) - public final MethodResult getAvgPowerInjection() { - if (!isAvailable()) - return notConnected(); + Pair filter = FluidFilter.parse(arguments.getTable(0)); + if (filter.rightPresent()) + return MethodResult.of(false, filter.getRight()); - return MethodResult.of(node.getGrid().getEnergyService().getAvgPowerInjection()); - } + FluidFilter parsedFilter = filter.getLeft(); + if (parsedFilter.isEmpty()) + return MethodResult.of(false, "EMPTY_FILTER"); - @Override - @LuaFunction(mainThread = true) - public MethodResult getTotalExternItemStorage() { - if (!isAvailable()) - return notConnected(); + AEFluidKey fluid = AEFluidKey.of(parsedFilter.toFluidStack()); - return MethodResult.of(AppEngApi.getTotalExternalItemStorage(node)); + return MethodResult.of(getCraftingService().isCraftable(fluid)); } - @Override @LuaFunction(mainThread = true) - public MethodResult getTotalExternFluidStorage() { - if (!isAvailable()) - return notConnected(); - - return MethodResult.of(AppEngApi.getTotalExternalFluidStorage(node)); + public final MethodResult exportFluid(@NotNull IArguments arguments) throws LuaException { + IFluidHandler handler = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); + return exportToTank(arguments, handler); } @LuaFunction(mainThread = true) - public MethodResult getTotalExternChemicalStorage() { - if (!isAvailable()) - return notConnected(); - - return MethodResult.of(AppEngApi.getTotalExternalChemicalStorage(node)); - } + public final MethodResult exportFluidToPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { + IFluidHandler handler = FluidUtil.getHandlerFromName(computer, arguments.getString(1)); - @Override - @LuaFunction(mainThread = true) - public final MethodResult getTotalItemStorage() { - if (!isAvailable()) - return notConnected(); + if (handler == null) + return MethodResult.of(0, "The target tank does not exist. Make sure the bridge is exposed in the computer network. Reach out to our discord or our documentation for help."); - return MethodResult.of(AppEngApi.getTotalItemStorage(node)); + return exportToTank(arguments, handler); } - @Override @LuaFunction(mainThread = true) - public final MethodResult getTotalFluidStorage() { - if (!isAvailable()) - return notConnected(); - - return MethodResult.of(AppEngApi.getTotalFluidStorage(node)); + public final MethodResult importFluid(IArguments arguments) throws LuaException { + IFluidHandler handler = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); + return importToME(arguments, handler); } @LuaFunction(mainThread = true) - public MethodResult getTotalChemicalStorage() { - if (!isAvailable()) - return notConnected(); + public final MethodResult importFluidFromPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { + IFluidHandler handler = FluidUtil.getHandlerFromName(computer, arguments.getString(1)); - return MethodResult.of(AppEngApi.getTotalChemicalStorage(node)); - } - - @Override - @LuaFunction(mainThread = true) - public MethodResult getUsedExternItemStorage() { - if (!isAvailable()) - return notConnected(); + if (handler == null) + return MethodResult.of(0, "The target tank does not exist. Make sure the bridge is exposed in the computer network. Reach out to our discord or our documentation for help."); - return MethodResult.of(AppEngApi.getUsedExternalItemStorage(node)); + return importToME(arguments, handler); } - @Override @LuaFunction(mainThread = true) - public MethodResult getUsedExternFluidStorage() { - if (!isAvailable()) + public final MethodResult exportItem(@NotNull IArguments arguments) throws LuaException { + if (!isConnected()) return notConnected(); - return MethodResult.of(AppEngApi.getUsedExternalFluidStorage(node)); + IItemHandler inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); + return exportToChest(arguments, inventory); } @LuaFunction(mainThread = true) - public MethodResult getUsedExternChemicalStorage() { - if (!isAvailable()) + public final MethodResult exportItemToPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { + if (!isConnected()) return notConnected(); - return MethodResult.of(AppEngApi.getUsedExternalChemicalStorage(node)); - } + IItemHandler inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); - @Override - @LuaFunction(mainThread = true) - public final MethodResult getUsedItemStorage() { - if (!isAvailable()) - return notConnected(); + if (inventory == null) + return MethodResult.of(0, "The target inventory does not exist. Make sure the bridge is exposed in the computer network. Reach out to our discord or our documentation for help."); - return MethodResult.of(AppEngApi.getUsedItemStorage(node)); + return exportToChest(arguments, inventory); } - @Override @LuaFunction(mainThread = true) - public final MethodResult getUsedFluidStorage() { - if (!isAvailable()) + public final MethodResult importItem(IArguments arguments) throws LuaException { + if (!isConnected()) return notConnected(); - return MethodResult.of(AppEngApi.getUsedFluidStorage(node)); + IItemHandler inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); + return importToME(arguments, inventory); } @LuaFunction(mainThread = true) - public MethodResult getUsedChemicalStorage() { - if (!isAvailable()) + public final MethodResult importItemFromPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { + if (!isConnected()) return notConnected(); - return MethodResult.of(AppEngApi.getUsedChemicalStorage(node)); - } + IItemHandler inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); - @Override - @LuaFunction(mainThread = true) - public MethodResult getAvailableExternItemStorage() { - if (!isAvailable()) - return notConnected(); + if (inventory == null) + return MethodResult.of(0, "The target inventory does not exist. Make sure the bridge is exposed in the computer network. Reach out to our discord or our documentation for help."); - return MethodResult.of(AppEngApi.getAvailableExternalItemStorage(node)); + return importToME(arguments, inventory); } - @Override @LuaFunction(mainThread = true) - public MethodResult getAvailableExternFluidStorage() { - if (!isAvailable()) + public final MethodResult getItem(IArguments arguments) throws LuaException { + if (!isConnected()) return notConnected(); - return MethodResult.of(AppEngApi.getAvailableExternalFluidStorage(node)); - } + MEStorage monitor = AppEngApi.getMonitor(node); + Pair filter = ItemFilter.parse(arguments.getTable(0)); + if (filter.rightPresent()) + return MethodResult.of(null, filter.getRight()); - @LuaFunction(mainThread = true) - public MethodResult getAvailableExternChemicalStorage() { - if (!isAvailable()) - return notConnected(); + ItemFilter parsedFilter = filter.getLeft(); + if (parsedFilter.isEmpty()) + return MethodResult.of(null, "EMPTY_FILTER"); - return MethodResult.of(AppEngApi.getAvailableExternalChemicalStorage(node)); + return MethodResult.of(AppEngApi.getObjectFromStack(AppEngApi.findAEStackFromFilter(monitor, getCraftingService(), parsedFilter), getCraftingService())); } - @Override @LuaFunction(mainThread = true) - public final MethodResult getAvailableItemStorage() { - if (!isAvailable()) + public final MethodResult listItems() { + if (!isConnected()) return notConnected(); - return MethodResult.of(AppEngApi.getAvailableItemStorage(node)); + return MethodResult.of(AppEngApi.listStacks(AppEngApi.getMonitor(node), getCraftingService())); } - @Override @LuaFunction(mainThread = true) - public final MethodResult getAvailableFluidStorage() { - if (!isAvailable()) + public final MethodResult listCraftableItems() { + if (!isConnected()) return notConnected(); - return MethodResult.of(AppEngApi.getAvailableFluidStorage(node)); + return MethodResult.of(AppEngApi.listCraftableStacks(AppEngApi.getMonitor(node), getCraftingService())); } @LuaFunction(mainThread = true) - public MethodResult getAvailableChemicalStorage() { - if (!isAvailable()) + public final MethodResult listFluid() { + if (!isConnected()) return notConnected(); - return MethodResult.of(AppEngApi.getAvailableChemicalStorage(node)); + return MethodResult.of(AppEngApi.listFluids(AppEngApi.getMonitor(node), getCraftingService())); } - @Override @LuaFunction(mainThread = true) - public final MethodResult craftItem(IComputerAccess computer, IArguments arguments) throws LuaException { - if (!isAvailable()) + public final MethodResult listGas() { + if (!isConnected()) return notConnected(); - Pair filter = ItemFilter.parse(arguments.getTable(0)); - if (filter.rightPresent()) - return MethodResult.of(false, filter.getRight()); - - ItemFilter parsedFilter = filter.getLeft(); - if (parsedFilter.isEmpty()) - return MethodResult.of(false, "EMPTY_FILTER"); - - String cpuName = arguments.optString(1, ""); - ICraftingCPU target = AppEngApi.getCraftingCPU(node, cpuName); - if (!cpuName.isEmpty() && target == null) - return MethodResult.of(false, "CPU " + cpuName + " does not exists"); - - ICraftingService craftingGrid = node.getGrid().getService(ICraftingService.class); - Pair stack = AppEngApi.findAEStackFromFilter(AppEngApi.getMonitor(tile.getGridNode()), craftingGrid, filter.getLeft()); - if (stack.getRight() == null && stack.getLeft() == 0) - return MethodResult.of(null, "NOT_CRAFTABLE"); - - CraftJob job = new CraftJob(owner.getLevel(), computer, node, stack.getRight(), parsedFilter.getCount(), tile, tile, target); - tile.addJob(job); - ServerWorker.add(job::startCrafting); - return MethodResult.of(true); + return MethodResult.of(AppEngApi.listGases(AppEngApi.getMonitor(node), getCraftingService(), 0)); } - @Override @LuaFunction(mainThread = true) - public final MethodResult craftFluid(IComputerAccess computer, IArguments arguments) throws LuaException { - if (!isAvailable()) + public final MethodResult listCraftableFluid() { + if (!isConnected()) return notConnected(); - Pair filter = FluidFilter.parse(arguments.getTable(0)); - if (filter.rightPresent()) - return MethodResult.of(false, filter.getRight()); - - FluidFilter parsedFilter = filter.getLeft(); - if (parsedFilter.isEmpty()) - return MethodResult.of(false, "EMPTY_FILTER"); - - String cpuName = arguments.optString(1, ""); - ICraftingCPU target = AppEngApi.getCraftingCPU(node, cpuName); - if (!cpuName.isEmpty() && target == null) - return MethodResult.of(false, "CPU " + cpuName + " does not exists"); - - ICraftingService craftingGrid = node.getGrid().getService(ICraftingService.class); - Pair stack = AppEngApi.findAEFluidFromFilter(AppEngApi.getMonitor(tile.getGridNode()), craftingGrid, filter.getLeft()); - if (stack.getRight() == null && stack.getLeft() == 0) - return MethodResult.of(null, "NOT_CRAFTABLE"); - - CraftJob job = new CraftJob(owner.getLevel(), computer, node, stack.getRight(), parsedFilter.getCount(), tile, tile, target); - tile.addJob(job); - ServerWorker.add(job::startCrafting); - return MethodResult.of(true); + return MethodResult.of(AppEngApi.listCraftableFluids(AppEngApi.getMonitor(node), getCraftingService())); } - @Override @LuaFunction(mainThread = true) - public MethodResult getCraftingTasks() { - if (!isAvailable()) + public final MethodResult getTotalItemStorage() { + if (!isConnected()) return notConnected(); - ICraftingService craftingGrid = node.getGrid().getService(ICraftingService.class); - - List jobs = new ArrayList<>(); - - for (ICraftingCPU cpu : craftingGrid.getCpus()) { - if (cpu.getJobStatus() != null) - jobs.add(AppEngApi.getObjectFromJob(cpu.getJobStatus(), cpu)); - } - return MethodResult.of(jobs); + return MethodResult.of(AppEngApi.getTotalItemStorage(node)); } - @Override @LuaFunction(mainThread = true) - public MethodResult cancelCraftingTasks(IArguments arguments) { - if (!isAvailable()) + public final MethodResult getTotalFluidStorage() { + if (!isConnected()) return notConnected(); - ICraftingService craftingGrid = node.getGrid().getService(ICraftingService.class); - - Map filterTable; - try { - Optional> optionalTable = arguments.optTable(0); - if (optionalTable.isEmpty()) - return MethodResult.of(null, "EMPTY_INPUT"); - filterTable = optionalTable.get(); - } catch (LuaException e) { - return MethodResult.of(null, "NO_TABLE"); - } - - Pair filter = GenericFilter.parseGeneric(filterTable); - if (filter.getRight() != null) - return MethodResult.of(null, filter.getRight()); - - int jobsCanceled = 0; - for (ICraftingCPU cpu : craftingGrid.getCpus()) { - if (cpu.getJobStatus() != null && filter.getLeft().test(cpu.getJobStatus().crafting())) { - if (cpu instanceof CraftingCPUCluster cpuCluster) { - cpuCluster.cancel(); - jobsCanceled++; - } - } - } - return MethodResult.of(jobsCanceled, "SUCCESSFUL"); + return MethodResult.of(AppEngApi.getTotalFluidStorage(node)); } - @Override @LuaFunction(mainThread = true) - public final MethodResult isItemCraftable(IArguments arguments) throws LuaException { - if (!isAvailable()) + public final MethodResult getUsedItemStorage() { + if (!isConnected()) return notConnected(); - Pair filter = ItemFilter.parse(arguments.getTable(0)); - if (filter.rightPresent()) - return MethodResult.of(false, filter.getRight()); - - ItemFilter parsedFilter = filter.getLeft(); - if (parsedFilter.isEmpty()) - return MethodResult.of(false, "EMPTY_FILTER"); - - AEItemKey item = AEItemKey.of(parsedFilter.toItemStack()); - - return MethodResult.of(getCraftingService().isCraftable(item)); + return MethodResult.of(AppEngApi.getUsedItemStorage(node)); } - @Override @LuaFunction(mainThread = true) - public final MethodResult isFluidCrafting(IArguments arguments) throws LuaException { - if (!isAvailable()) + public final MethodResult getUsedFluidStorage() { + if (!isConnected()) return notConnected(); - MEStorage monitor = AppEngApi.getMonitor(node); - ICraftingService grid = node.getGrid().getService(ICraftingService.class); - - Pair filter = FluidFilter.parse(arguments.getTable(0)); - if (filter.rightPresent()) - return MethodResult.of(false, filter.getRight()); - - FluidFilter parsedFilter = filter.getLeft(); - if (parsedFilter.isEmpty()) - return MethodResult.of(false, "EMPTY_FILTER"); - String cpuName = arguments.optString(1, ""); - ICraftingCPU craftingCPU = AppEngApi.getCraftingCPU(node, cpuName); - - return MethodResult.of(AppEngApi.isFluidCrafting(monitor, grid, parsedFilter, craftingCPU)); + return MethodResult.of(AppEngApi.getUsedFluidStorage(node)); } - @Override @LuaFunction(mainThread = true) - public final MethodResult isFluidCraftable(IArguments arguments) throws LuaException { - if (!isAvailable()) + public final MethodResult getAvailableItemStorage() { + if (!isConnected()) return notConnected(); - Pair filter = FluidFilter.parse(arguments.getTable(0)); - if (filter.rightPresent()) - return MethodResult.of(false, filter.getRight()); - - FluidFilter parsedFilter = filter.getLeft(); - if (parsedFilter.isEmpty()) - return MethodResult.of(false, "EMPTY_FILTER"); - - AEFluidKey fluid = AEFluidKey.of(parsedFilter.toFluidStack()); - - return MethodResult.of(getCraftingService().isCraftable(fluid)); - } - - @Override - @LuaFunction(mainThread = true) - public final MethodResult exportFluid(IComputerAccess computer, IArguments arguments) throws LuaException { - String side = arguments.getString(1); - IFluidHandler fluidHandler; - - if (Direction.byName(side.toUpperCase(Locale.ROOT)) == null && ComputerSide.valueOfInsensitive(side.toUpperCase(Locale.ROOT)) == null) { - fluidHandler = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); - } else { - fluidHandler = FluidUtil.getHandlerFromName(computer, arguments.getString(1)); - } - - if (fluidHandler == null) - return MethodResult.of(0, "The target tank does not exist. Make sure the bridge is exposed in the computer network. Reach out to our discord or our documentation for help."); - - return exportToTank(arguments, fluidHandler); + return MethodResult.of(AppEngApi.getAvailableItemStorage(node)); } - @Override @LuaFunction(mainThread = true) - public final MethodResult importFluid(IComputerAccess computer, IArguments arguments) throws LuaException { - String side = arguments.getString(1); - IFluidHandler fluidHandler; - - if (Direction.byName(side.toUpperCase(Locale.ROOT)) == null && ComputerSide.valueOfInsensitive(side.toUpperCase(Locale.ROOT)) == null) { - fluidHandler = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); - } else { - fluidHandler = FluidUtil.getHandlerFromName(computer, arguments.getString(1)); - } - - if (fluidHandler == null) - return MethodResult.of(0, "The target tank does not exist. Make sure the bridge is exposed in the computer network. Reach out to our discord or our documentation for help."); + public final MethodResult getAvailableFluidStorage() { + if (!isConnected()) + return notConnected(); - return importToME(arguments, fluidHandler); + return MethodResult.of(AppEngApi.getAvailableFluidStorage(node)); } - @Override @LuaFunction(mainThread = true) - public final MethodResult isItemCrafting(IArguments arguments) throws LuaException { - if (!isAvailable()) + public final MethodResult listCells() { + if (!isConnected()) return notConnected(); - MEStorage monitor = AppEngApi.getMonitor(node); - ICraftingService grid = node.getGrid().getService(ICraftingService.class); - - Pair filter = ItemFilter.parse(arguments.getTable(0)); - if (filter.rightPresent()) - return MethodResult.of(false, filter.getRight()); - - ItemFilter parsedFilter = filter.getLeft(); - if (parsedFilter.isEmpty()) - return MethodResult.of(false, "EMPTY_FILTER"); - String cpuName = arguments.optString(1, ""); - ICraftingCPU craftingCPU = AppEngApi.getCraftingCPU(node, cpuName); - - return MethodResult.of(AppEngApi.isItemCrafting(monitor, grid, parsedFilter, craftingCPU)); + return MethodResult.of(AppEngApi.listCells(node)); } @LuaFunction(mainThread = true) public final MethodResult getCraftingCPUs() throws LuaException { - if (!isAvailable()) + if (!isConnected()) return notConnected(); ICraftingService grid = node.getGrid().getService(ICraftingService.class); List map = new ArrayList<>(); for (ICraftingCPU iCraftingCPU : grid.getCpus()) { - Object cpu = AppEngApi.getObjectFromCPU(iCraftingCPU, false); + Object cpu = AppEngApi.getObjectFromCPU(iCraftingCPU); map.add(cpu); } return MethodResult.of(map); } + + public final ICraftingCPU getCraftingCPU(String cpuName) { + if (cpuName.isEmpty()) return null; + ICraftingService grid = node.getGrid().getService(ICraftingService.class); + if (grid == null) return null; + + Iterator iterator = grid.getCpus().iterator(); + if (!iterator.hasNext()) return null; + + while (iterator.hasNext()) { + ICraftingCPU cpu = iterator.next(); + + if (cpu.getName() != null && cpu.getName().getString().equals(cpuName)) { + return cpu; + } + } + + return null; + } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/NBTStoragePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/NBTStoragePeripheral.java index 957594180..5e327d1f6 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/NBTStoragePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/NBTStoragePeripheral.java @@ -18,7 +18,7 @@ public class NBTStoragePeripheral extends BasePeripheral> { - public static final String PERIPHERAL_TYPE = "nbt_storage"; + public static final String PERIPHERAL_TYPE = "nbtStorage"; public NBTStoragePeripheral(NBTStorageEntity tileEntity) { super(PERIPHERAL_TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/PlayerDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/PlayerDetectorPeripheral.java index d6489bc3d..6e8b90fa3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/PlayerDetectorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/PlayerDetectorPeripheral.java @@ -27,7 +27,7 @@ public class PlayerDetectorPeripheral extends BasePeripheral { - public static final String PERIPHERAL_TYPE = "player_detector"; + public static final String PERIPHERAL_TYPE = "playerDetector"; private static final int MAX_RANGE = APConfig.PERIPHERALS_CONFIG.playerDetMaxRange.get(); public PlayerDetectorPeripheral(PeripheralBlockEntity tileEntity) { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RedstoneIntegratorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RedstoneIntegratorPeripheral.java index b3d181a4c..ec70aa47c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RedstoneIntegratorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RedstoneIntegratorPeripheral.java @@ -10,7 +10,7 @@ public class RedstoneIntegratorPeripheral extends BasePeripheral> { - public static final String PERIPHERAL_TYPE = "redstone_integrator"; + public static final String PERIPHERAL_TYPE = "redstoneIntegrator"; public RedstoneIntegratorPeripheral(RedstoneIntegratorEntity tileEntity) { super(PERIPHERAL_TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java index 15ca27785..a45b81086 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java @@ -9,7 +9,6 @@ import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.lua.MethodResult; import dan200.computercraft.api.peripheral.IComputerAccess; -import dan200.computercraft.core.computer.ComputerSide; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner; import de.srendi.advancedperipherals.common.addons.refinedstorage.RefinedStorage; @@ -21,7 +20,6 @@ import de.srendi.advancedperipherals.common.util.Pair; import de.srendi.advancedperipherals.common.util.inventory.*; import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; -import net.minecraft.core.Direction; import net.minecraft.world.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.capability.IFluidHandler; @@ -31,11 +29,10 @@ import java.util.ArrayList; import java.util.List; -import java.util.Locale; -public class RsBridgePeripheral extends BasePeripheral> implements IStorageSystemPeripheral { +public class RsBridgePeripheral extends BasePeripheral> { - public static final String PERIPHERAL_TYPE = "rs_bridge"; + public static final String PERIPHERAL_TYPE = "rsBridge"; public RsBridgePeripheral(RsBridgeEntity tileEntity) { super(PERIPHERAL_TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); @@ -53,42 +50,27 @@ private MethodResult notConnected() { return MethodResult.of(null, "NOT_CONNECTED"); } - private boolean isAvailable() { - return getNetwork() != null; - } - @Override public boolean isEnabled() { return APConfig.PERIPHERALS_CONFIG.enableRSBridge.get(); } - @Override - @LuaFunction(mainThread = true) - public final MethodResult isConnected() { - return MethodResult.of(isAvailable()); - } - - @Override @LuaFunction(mainThread = true) - public final MethodResult isOnline() { - // Is there a more proper method? - return MethodResult.of(getNode().isActive()); + public final boolean isConnected() { + return getNetwork() != null; } - - @Override @LuaFunction(mainThread = true) public final MethodResult listItems() { - if (!isAvailable()) + if (!isConnected()) return notConnected(); return MethodResult.of(RefinedStorage.listItems(getNetwork())); } - @Override @LuaFunction(mainThread = true) public final MethodResult listCraftableItems() { - if (!isAvailable()) + if (!isConnected()) return notConnected(); List items = new ArrayList<>(); @@ -96,10 +78,9 @@ public final MethodResult listCraftableItems() { return MethodResult.of(items); } - @Override @LuaFunction(mainThread = true) - public final MethodResult listCraftableFluids() { - if (!isAvailable()) + public final Object listCraftableFluids() { + if (!isConnected()) return notConnected(); List fluids = new ArrayList<>(); @@ -107,148 +88,73 @@ public final MethodResult listCraftableFluids() { return MethodResult.of(fluids); } - @Override - @LuaFunction(mainThread = true) - public final MethodResult listCells() { - return null; - } - - @Override - @LuaFunction(mainThread = true) - public final MethodResult listDrives() { - return null; - } - - @Override @LuaFunction(mainThread = true) - public final MethodResult getTotalItemStorage() { - if (!isAvailable()) + public final MethodResult getMaxItemDiskStorage() { + if (!isConnected()) return notConnected(); return MethodResult.of(RefinedStorage.getMaxItemDiskStorage(getNetwork())); } - @Override @LuaFunction(mainThread = true) - public final MethodResult getTotalFluidStorage() { - if (!isAvailable()) + public final MethodResult getMaxFluidDiskStorage() { + if (!isConnected()) return notConnected(); return MethodResult.of(RefinedStorage.getMaxFluidDiskStorage(getNetwork())); } - @Override - @LuaFunction(mainThread = true) - public final MethodResult getUsedExternItemStorage() { - return null; - } - - @Override - @LuaFunction(mainThread = true) - public final MethodResult getUsedExternFluidStorage() { - return null; - } - - @Override - @LuaFunction(mainThread = true) - public final MethodResult getUsedItemStorage() { - return null; - } - - @Override - @LuaFunction(mainThread = true) - public final MethodResult getUsedFluidStorage() { - return null; - } - - @Override - @LuaFunction(mainThread = true) - public final MethodResult getAvailableExternItemStorage() { - return null; - } - - @Override - @LuaFunction(mainThread = true) - public final MethodResult getAvailableExternFluidStorage() { - return null; - } - - @Override - @LuaFunction(mainThread = true) - public final MethodResult getAvailableItemStorage() { - return null; - } - - @Override @LuaFunction(mainThread = true) - public final MethodResult getAvailableFluidStorage() { - return null; - } - - @Override - @LuaFunction(mainThread = true) - public final MethodResult getTotalExternItemStorage() { - if (!isAvailable()) + public final MethodResult getMaxItemExternalStorage() { + if (!isConnected()) return notConnected(); return MethodResult.of(RefinedStorage.getMaxItemExternalStorage(getNetwork())); } - @Override @LuaFunction(mainThread = true) - public final MethodResult getTotalExternFluidStorage() { - if (!isAvailable()) + public final MethodResult getMaxFluidExternalStorage() { + if (!isConnected()) return notConnected(); return MethodResult.of(RefinedStorage.getMaxFluidExternalStorage(getNetwork())); } - @Override @LuaFunction(mainThread = true) public final MethodResult listFluids() { - if (!isAvailable()) + if (!isConnected()) return notConnected(); return MethodResult.of(RefinedStorage.listFluids(getNetwork())); } - @Override @LuaFunction(mainThread = true) public final MethodResult getEnergyUsage() { - if (!isAvailable()) + if (!isConnected()) return notConnected(); return MethodResult.of(getNetwork().getEnergyUsage()); } - @Override @LuaFunction(mainThread = true) - public final MethodResult getEnergyCapacity() { - if (!isAvailable()) + public final MethodResult getMaxEnergyStorage() { + if (!isConnected()) return notConnected(); return MethodResult.of(getNetwork().getEnergyStorage().getMaxEnergyStored()); } - @Override @LuaFunction(mainThread = true) - public final MethodResult getStoredEnergy() { - if (!isAvailable()) + public final MethodResult getEnergyStorage() { + if (!isConnected()) return notConnected(); return MethodResult.of(getNetwork().getEnergyStorage().getEnergyStored()); } - @Override - @LuaFunction(mainThread = true) - public final MethodResult getAvgPowerInjection() { - return null; - } - - @Override @LuaFunction(mainThread = true) - public final MethodResult getFilteredPatterns(IArguments arguments) throws LuaException { - if (!isAvailable()) + public final MethodResult getPattern(IArguments arguments) throws LuaException { + if (!isConnected()) return notConnected(); Pair filter = ItemFilter.parse(arguments.getTable(0)); @@ -264,12 +170,6 @@ public final MethodResult getFilteredPatterns(IArguments arguments) throws LuaEx return MethodResult.of(RefinedStorage.getObjectFromPattern(getNetwork().getCraftingManager().getPattern(patternItem), getNetwork())); } - @Override - @LuaFunction(mainThread = true) - public final MethodResult getPatterns() { - return null; - } - protected MethodResult exportToChest(@NotNull IArguments arguments, @Nullable IItemHandler targetInventory) throws LuaException { RsItemHandler itemHandler = new RsItemHandler(getNetwork()); if (targetInventory == null) @@ -318,88 +218,81 @@ protected MethodResult importToSystem(@NotNull IArguments arguments, @Nullable I return MethodResult.of(InventoryUtil.moveFluid(targetInventory, itemHandler, filter.getLeft()), null); } - @Override @LuaFunction(mainThread = true) - public final MethodResult exportItem(IComputerAccess computer, IArguments arguments) throws LuaException { - if (!isAvailable()) + public final MethodResult exportItem(@NotNull IArguments arguments) throws LuaException { + if (!isConnected()) return notConnected(); - String side = arguments.getString(1); - IItemHandler inventory; + IItemHandler inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); + return exportToChest(arguments, inventory); + } - if (Direction.byName(side.toUpperCase(Locale.ROOT)) == null && ComputerSide.valueOfInsensitive(side.toUpperCase(Locale.ROOT)) == null) { - inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); - } else { - inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); - } + @LuaFunction(mainThread = true) + public final MethodResult exportItemToPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { + if (!isConnected()) + return notConnected(); + IItemHandler inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); return exportToChest(arguments, inventory); } - @Override @LuaFunction(mainThread = true) - public final MethodResult importItem(IComputerAccess computer, IArguments arguments) throws LuaException { - if (!isAvailable()) + public final MethodResult importItem(IArguments arguments) throws LuaException { + if (!isConnected()) return notConnected(); - String side = arguments.getString(1); - IItemHandler inventory; + IItemHandler inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); + return importToSystem(arguments, inventory); + } - if (Direction.byName(side.toUpperCase(Locale.ROOT)) == null && ComputerSide.valueOfInsensitive(side.toUpperCase(Locale.ROOT)) == null) { - inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); - } else { - inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); - } + @LuaFunction(mainThread = true) + public final MethodResult importItemFromPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { + if (!isConnected()) + return notConnected(); + IItemHandler inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); return importToSystem(arguments, inventory); } - @Override @LuaFunction(mainThread = true) - public final MethodResult exportFluid(IComputerAccess computer, IArguments arguments) throws LuaException { - if (!isAvailable()) + public final MethodResult exportFluid(@NotNull IArguments arguments) throws LuaException { + if (!isConnected()) return notConnected(); - String side = arguments.getString(1); - IFluidHandler fluidHandler; - - if (Direction.byName(side.toUpperCase(Locale.ROOT)) == null && ComputerSide.valueOfInsensitive(side.toUpperCase(Locale.ROOT)) == null) { - fluidHandler = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); - } else { - fluidHandler = FluidUtil.getHandlerFromName(computer, arguments.getString(1)); - } + IFluidHandler inventory = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); + return exportToTank(arguments, inventory); + } - if (fluidHandler == null) - return MethodResult.of(0, "The target tank does not exist. Make sure the bridge is exposed in the computer network. Reach out to our discord or our documentation for help."); + @LuaFunction(mainThread = true) + public final MethodResult exportFluidToPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { + if (!isConnected()) + return notConnected(); - return exportToTank(arguments, fluidHandler); + IFluidHandler inventory = FluidUtil.getHandlerFromName(computer, arguments.getString(1)); + return exportToTank(arguments, inventory); } - @Override @LuaFunction(mainThread = true) - public final MethodResult importFluid(IComputerAccess computer, IArguments arguments) throws LuaException { - if (!isAvailable()) + public final MethodResult importFluid(IArguments arguments) throws LuaException { + if (!isConnected()) return notConnected(); - String side = arguments.getString(1); - IFluidHandler fluidHandler; - - if (Direction.byName(side.toUpperCase(Locale.ROOT)) == null && ComputerSide.valueOfInsensitive(side.toUpperCase(Locale.ROOT)) == null) { - fluidHandler = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); - } else { - fluidHandler = FluidUtil.getHandlerFromName(computer, arguments.getString(1)); - } + IFluidHandler inventory = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); + return importToSystem(arguments, inventory); + } - if (fluidHandler == null) - return MethodResult.of(0, "The target tank does not exist. Make sure the bridge is exposed in the computer network. Reach out to our discord or our documentation for help."); + @LuaFunction(mainThread = true) + public final MethodResult importFluidFromPeripheral(IComputerAccess computer, IArguments arguments) throws LuaException { + if (!isConnected()) + return notConnected(); - return importToSystem(arguments, fluidHandler); + IFluidHandler inventory = FluidUtil.getHandlerFromName(computer, arguments.getString(1)); + return importToSystem(arguments, inventory); } - @Override @LuaFunction(mainThread = true) public final MethodResult getItem(IArguments arguments) throws LuaException { - if (!isAvailable()) + if (!isConnected()) return notConnected(); Pair filter = ItemFilter.parse(arguments.getTable(0)); @@ -409,16 +302,9 @@ public final MethodResult getItem(IArguments arguments) throws LuaException { return MethodResult.of(RefinedStorage.getObjectFromStack(RefinedStorage.findStackFromFilter(getNetwork(), getNetwork().getCraftingManager(), filter.getLeft()), getNetwork())); } - @Override @LuaFunction(mainThread = true) - public final MethodResult getFluid(IArguments arguments) throws LuaException { - return null; - } - - @Override - @LuaFunction(mainThread = true) - public final MethodResult craftItem(IComputerAccess computerAccess, IArguments arguments) throws LuaException { - if (!isAvailable()) + public final MethodResult craftItem(IArguments arguments) throws LuaException { + if (!isConnected()) return notConnected(); @@ -438,10 +324,9 @@ public final MethodResult craftItem(IComputerAccess computerAccess, IArguments a return MethodResult.of(type == CalculationResultType.OK); } - @Override @LuaFunction(mainThread = true) - public final MethodResult craftFluid(IComputerAccess computerAccess, IArguments arguments) throws LuaException { - if (!isAvailable()) + public final MethodResult craftFluid(IArguments arguments) throws LuaException { + if (!isConnected()) return notConnected(); Pair filter = FluidFilter.parse(arguments.getTable(0)); @@ -453,6 +338,7 @@ public final MethodResult craftFluid(IComputerAccess computerAccess, IArguments return MethodResult.of(null, "NOT_CRAFTABLE"); ICalculationResult result = getNetwork().getCraftingManager().create(stack, filter.getLeft().getCount()); + getNetwork().getCraftingManager().getPatterns(); CalculationResultType type = result.getType(); if (type == CalculationResultType.OK) getNetwork().getCraftingManager().start(result.getTask()); @@ -460,20 +346,9 @@ public final MethodResult craftFluid(IComputerAccess computerAccess, IArguments return MethodResult.of(type == CalculationResultType.OK); } - @Override - public MethodResult getCraftingTasks() { - return null; - } - - @Override - public MethodResult cancelCraftingTasks(IArguments arguments) throws LuaException { - return null; - } - - @Override @LuaFunction(mainThread = true) public final MethodResult isItemCrafting(IArguments arguments) throws LuaException { - if (!isAvailable()) + if (!isConnected()) return notConnected(); Pair filter = ItemFilter.parse(arguments.getTable(0)); if (filter.rightPresent()) @@ -491,22 +366,9 @@ public final MethodResult isItemCrafting(IArguments arguments) throws LuaExcepti return MethodResult.of(false); } - @Override - @LuaFunction(mainThread = true) - public final MethodResult isFluidCraftable(IArguments arguments) throws LuaException { - return null; - } - - @Override - @LuaFunction(mainThread = true) - public final MethodResult isFluidCrafting(IArguments arguments) throws LuaException { - return null; - } - - @Override @LuaFunction(mainThread = true) public final MethodResult isItemCraftable(IArguments arguments) throws LuaException { - if (!isAvailable()) + if (!isConnected()) return notConnected(); Pair filter = ItemFilter.parse(arguments.getTable(0)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/EndAutomataCorePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/EndAutomataCorePeripheral.java index bb50f1d60..90f6ceda7 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/EndAutomataCorePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/EndAutomataCorePeripheral.java @@ -10,7 +10,7 @@ public class EndAutomataCorePeripheral extends WeakAutomataCorePeripheral { - public static final String TYPE = "end_automata"; + public static final String TYPE = "endAutomata"; public EndAutomataCorePeripheral(ITurtleAccess turtle, TurtleSide side) { this(TYPE, turtle, side, AutomataCoreTier.TIER2); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/HusbandryAutomataCorePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/HusbandryAutomataCorePeripheral.java index ba89f1629..baba65bfd 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/HusbandryAutomataCorePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/HusbandryAutomataCorePeripheral.java @@ -14,7 +14,7 @@ import java.util.function.Predicate; public class HusbandryAutomataCorePeripheral extends WeakAutomataCorePeripheral { - public static final String TYPE = "husbandry_automata"; + public static final String TYPE = "husbandryAutomata"; private static final Predicate isAnimal = entity1 -> entity1.getType().getCategory().isFriendly(); private static final Predicate isLivingEntity = LivingEntity.class::isInstance; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredEndAutomataCorePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredEndAutomataCorePeripheral.java index 392dcfaf2..40a991573 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredEndAutomataCorePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredEndAutomataCorePeripheral.java @@ -8,7 +8,7 @@ public class OverpoweredEndAutomataCorePeripheral extends EndAutomataCorePeripheral { - public static final String TYPE = "overpowered_end_automata"; + public static final String TYPE = "overpoweredEndAutomata"; public OverpoweredEndAutomataCorePeripheral(ITurtleAccess turtle, TurtleSide side) { super(TYPE, turtle, side, AutomataCoreTier.OVERPOWERED_TIER2); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredHusbandryAutomataCorePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredHusbandryAutomataCorePeripheral.java index 220e9ce49..fc8f7e980 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredHusbandryAutomataCorePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredHusbandryAutomataCorePeripheral.java @@ -8,14 +8,13 @@ public class OverpoweredHusbandryAutomataCorePeripheral extends HusbandryAutomataCorePeripheral { - public static final String TYPE = "overpowered_husbandry_automata"; + public static final String TYPE = "overpoweredHusbandryAutomata"; public OverpoweredHusbandryAutomataCorePeripheral(ITurtleAccess turtle, TurtleSide side) { super(TYPE, turtle, side, AutomataCoreTier.OVERPOWERED_TIER2); setAttribute(ATTR_STORING_TOOL_DURABILITY); } - @Override public void addRotationCycle(int count) { super.addRotationCycle(count); if (AdvancedPeripherals.RANDOM.nextDouble() <= APConfig.METAPHYSICS_CONFIG.overpoweredAutomataBreakChance.get()) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredWeakAutomataCorePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredWeakAutomataCorePeripheral.java index 1b19eb40e..cca911a2a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredWeakAutomataCorePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredWeakAutomataCorePeripheral.java @@ -8,14 +8,13 @@ public class OverpoweredWeakAutomataCorePeripheral extends WeakAutomataCorePeripheral { - public static final String TYPE = "overpowered_weak_automata"; + public static final String TYPE = "overpoweredWeakAutomata"; public OverpoweredWeakAutomataCorePeripheral(ITurtleAccess turtle, TurtleSide side) { super(TYPE, turtle, side, AutomataCoreTier.OVERPOWERED_TIER1); setAttribute(ATTR_STORING_TOOL_DURABILITY); } - @Override public void addRotationCycle(int count) { super.addRotationCycle(count); if (AdvancedPeripherals.RANDOM.nextDouble() <= APConfig.METAPHYSICS_CONFIG.overpoweredAutomataBreakChance.get()) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/WeakAutomataCorePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/WeakAutomataCorePeripheral.java index 64bd72511..afaae9ebc 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/WeakAutomataCorePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/WeakAutomataCorePeripheral.java @@ -3,13 +3,17 @@ import dan200.computercraft.api.turtle.ITurtleAccess; import dan200.computercraft.api.turtle.TurtleSide; import de.srendi.advancedperipherals.common.addons.computercraft.operations.AutomataCoreTier; -import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.plugins.*; +import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.plugins.AutomataBlockHandPlugin; +import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.plugins.AutomataChargingPlugin; +import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.plugins.AutomataItemSuckPlugin; +import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.plugins.AutomataLookPlugin; +import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.plugins.AutomataSoulFeedingPlugin; import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.lib.metaphysics.IAutomataCoreTier; import de.srendi.advancedperipherals.lib.peripherals.AutomataCorePeripheral; public class WeakAutomataCorePeripheral extends AutomataCorePeripheral { - public static final String TYPE = "weak_automata"; + public static final String TYPE = "weakAutomata"; public WeakAutomataCorePeripheral(ITurtleAccess turtle, TurtleSide side) { this(TYPE, turtle, side, AutomataCoreTier.TIER1); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java index 4f9fb08e6..3d3c375b8 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java @@ -44,12 +44,12 @@ public final MethodResult digBlock(@NotNull IArguments arguments) throws LuaExce int previousDamageValue = selectedTool.getDamageValue(); Pair result = owner.withPlayer(APFakePlayer.wrapActionWithShiftKey(sneak, APFakePlayer.wrapActionWithRot(yaw, pitch, APFakePlayer::digBlock))); if (!result.getLeft()) { - return MethodResult.of(false, result.getRight()); + return MethodResult.of(null, result.getRight()); } if (automataCore.hasAttribute(AutomataCorePeripheral.ATTR_STORING_TOOL_DURABILITY)) { selectedTool.setDamageValue(previousDamageValue); } - return MethodResult.of(true, result.getRight()); + return MethodResult.of(true); }); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataItemSuckPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataItemSuckPlugin.java index 7c2ea5a92..526ffd532 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataItemSuckPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataItemSuckPlugin.java @@ -84,7 +84,7 @@ public final MethodResult scanItems() { int index = 1; for (ItemEntity item : items) { ItemStack stack = item.getItem(); - Map itemData = LuaConverter.itemStackToObject(stack); + Map itemData = LuaConverter.stackToObject(stack); itemData.put("entityID", item.getId()); data.put(index, itemData); index++; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/create/BasinIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/create/BasinIntegration.java index 04c9711b2..fd94787a9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/create/BasinIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/create/BasinIntegration.java @@ -6,13 +6,17 @@ import de.srendi.advancedperipherals.lib.peripherals.BlockEntityIntegrationPeripheral; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.registries.ForgeRegistries; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.IFluidHandler; import org.jetbrains.annotations.NotNull; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; public class BasinIntegration extends BlockEntityIntegrationPeripheral { @@ -64,7 +68,7 @@ public final List getOutputFluids() { @LuaFunction(mainThread = true) public final Map getFilter() { - return LuaConverter.itemStackToObject(blockEntity.getFilter().getFilter()); + return LuaConverter.stackToObject(blockEntity.getFilter().getFilter()); } @LuaFunction(mainThread = true) @@ -74,7 +78,7 @@ public final List getInventory() { IItemHandler handler = handlerOptional.get(); List items = new ArrayList<>(); for (int slot = 0; slot < handler.getSlots(); slot++) { - items.add(LuaConverter.itemStackToObject(handler.getStackInSlot(slot))); + items.add(LuaConverter.stackToObject(handler.getStackInSlot(slot))); } return items; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/create/BlazeBurnerIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/create/BlazeBurnerIntegration.java index eb45e1f28..88bde5dca 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/create/BlazeBurnerIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/create/BlazeBurnerIntegration.java @@ -18,7 +18,7 @@ public BlazeBurnerIntegration(BlockEntity entity) { @NotNull @Override public String getType() { - return "blaze_burner"; + return "blazeBurner"; } @LuaFunction(mainThread = true) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/create/FluidTankIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/create/FluidTankIntegration.java index cc59643e2..e8d4b0779 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/create/FluidTankIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/create/FluidTankIntegration.java @@ -19,7 +19,7 @@ public FluidTankIntegration(BlockEntity entity) { @NotNull @Override public String getType() { - return "fluid_tank"; + return "fluidTank"; } @LuaFunction(mainThread = true) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/create/MechanicalMixerIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/create/MechanicalMixerIntegration.java index 91140fd47..0c87f7763 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/create/MechanicalMixerIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/create/MechanicalMixerIntegration.java @@ -16,7 +16,7 @@ public MechanicalMixerIntegration(BlockEntity entity) { @NotNull @Override public String getType() { - return "mechanical_mixer"; + return "mechanicalMixer"; } @LuaFunction(mainThread = true) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/create/ScrollValueBehaviourIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/create/ScrollValueBehaviourIntegration.java index 81e58614b..32dbc4a1d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/create/ScrollValueBehaviourIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/create/ScrollValueBehaviourIntegration.java @@ -19,7 +19,7 @@ public ScrollValueBehaviourIntegration(BlockEntity entity) { @NotNull @Override public String getType() { - return "scroll_behaviour_entity"; + return "scrollBehaviourEntity"; } @LuaFunction(mainThread = true) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/dimstorage/DimChestIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/dimstorage/DimChestIntegration.java deleted file mode 100644 index 037775037..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/dimstorage/DimChestIntegration.java +++ /dev/null @@ -1,55 +0,0 @@ -package de.srendi.advancedperipherals.common.addons.dimstorage; - -import dan200.computercraft.api.lua.LuaFunction; -import de.srendi.advancedperipherals.lib.peripherals.BlockEntityIntegrationPeripheral; -import edivad.dimstorage.api.Frequency; -import edivad.dimstorage.blockentities.BlockEntityDimChest; -import net.minecraft.world.level.block.entity.BlockEntity; -import org.jetbrains.annotations.NotNull; - -import java.util.UUID; - -public class DimChestIntegration extends BlockEntityIntegrationPeripheral { - - protected DimChestIntegration(BlockEntity entity) { - super(entity); - } - - @NotNull - @Override - public String getType() { - return "dimChest"; - } - - @LuaFunction(mainThread = true) - public final String getOwnerUUID() { - UUID uuid = blockEntity.getFrequency().getOwnerUUID(); - if (uuid == null) - return null; - return uuid.toString(); - } - - @LuaFunction(mainThread = true) - public final String getOwner() { - return blockEntity.getFrequency().getOwner(); - } - - @LuaFunction(mainThread = true) - public final boolean hasOwner() { - return blockEntity.getFrequency().hasOwner(); - } - - @LuaFunction(mainThread = true) - public final int getChannel() { - return blockEntity.getFrequency().getChannel(); - } - - @LuaFunction(mainThread = true) - public final boolean setChannel(int channel) { - Frequency fre = blockEntity.getFrequency(); - if (fre.hasOwner()) return false; - fre.setChannel(channel); - blockEntity.setFrequency(fre); - return true; - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/dimstorage/Integration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/dimstorage/Integration.java deleted file mode 100644 index a74e46b62..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/dimstorage/Integration.java +++ /dev/null @@ -1,12 +0,0 @@ -package de.srendi.advancedperipherals.common.addons.dimstorage; - -import de.srendi.advancedperipherals.common.addons.computercraft.integrations.IntegrationPeripheralProvider; -import edivad.dimstorage.blockentities.BlockEntityDimChest; - -public class Integration implements Runnable { - - @Override - public void run() { - IntegrationPeripheralProvider.registerBlockEntityIntegration(DimChestIntegration::new, BlockEntityDimChest.class); - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/MekanismCapabilities.java b/src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/MekanismCapabilities.java deleted file mode 100644 index 858a11b3d..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/mekanism/MekanismCapabilities.java +++ /dev/null @@ -1,15 +0,0 @@ -package de.srendi.advancedperipherals.common.addons.mekanism; - -import mekanism.api.chemical.gas.IGasHandler; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.CapabilityToken; - -import static net.minecraftforge.common.capabilities.CapabilityManager.get; - -public class MekanismCapabilities { - - public static final Capability GAS_HANDLER = get(new CapabilityToken<>() { - }); - - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/minecolonies/MineColonies.java b/src/main/java/de/srendi/advancedperipherals/common/addons/minecolonies/MineColonies.java index 52f1fe572..96ec59d49 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/minecolonies/MineColonies.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/minecolonies/MineColonies.java @@ -107,7 +107,7 @@ public static Object visitorToObject(IVisitorData visitor) { map.put("saturation", visitor.getSaturation()); map.put("happiness", visitor.getCitizenHappinessHandler().getHappiness(visitor.getColony(), visitor)); map.put("skills", skillsToObject(visitor.getCitizenSkillHandler().getSkills())); - map.put("recruitCost", LuaConverter.itemStackToObject(visitor.getRecruitCost())); + map.put("recruitCost", LuaConverter.stackToObject(visitor.getRecruitCost())); return map; } @@ -349,7 +349,7 @@ public static Object builderResourcesToObject(IColony colony, BlockPos pos) { Map map = new HashMap<>(); ItemStack stack = resource.getItemStack().copy(); - map.put("item", LuaConverter.itemStackToObject(stack)); + map.put("item", LuaConverter.stackToObject(stack)); map.put("displayName", resource.getName()); map.put("available", resource.getAvailable()); map.put("delivering", resource.getAmountInDelivery()); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/EnderCellIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/EnderCellIntegration.java index b6e2dcf76..cee6df8b1 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/EnderCellIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/EnderCellIntegration.java @@ -14,7 +14,7 @@ protected EnderCellIntegration(BlockEntity entity) { @NotNull @Override public String getType() { - return "ender_cell"; + return "enderCell"; } @LuaFunction(mainThread = true) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/EnergyCellIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/EnergyCellIntegration.java index 043b29f81..c437e31a6 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/EnergyCellIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/EnergyCellIntegration.java @@ -14,7 +14,7 @@ protected EnergyCellIntegration(BlockEntity entity) { @NotNull @Override public String getType() { - return "energy_cell"; + return "energyCell"; } @LuaFunction(mainThread = true) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/ReactorIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/ReactorIntegration.java index 08f51db5e..d8f1a9db8 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/ReactorIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/ReactorIntegration.java @@ -15,7 +15,7 @@ protected ReactorIntegration(BlockEntity entity) { @Override @NotNull public String getType() { - return "uraninite_reactor"; + return "uraniniteReactor"; } @LuaFunction(mainThread = true) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/SolarPanelIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/SolarPanelIntegration.java index c921ae00a..238ce5999 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/SolarPanelIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/SolarPanelIntegration.java @@ -14,7 +14,7 @@ protected SolarPanelIntegration(BlockEntity entity) { @NotNull @Override public String getType() { - return "solar_panel"; + return "solarPanel"; } @LuaFunction(mainThread = true) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java index 2a102e1ea..9e13e7d8d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java @@ -18,14 +18,20 @@ import de.srendi.advancedperipherals.common.util.inventory.FluidFilter; import de.srendi.advancedperipherals.common.util.inventory.ItemFilter; import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; +import net.minecraft.core.NonNullList; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagKey; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.material.Fluid; import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.registries.ForgeRegistries; import org.jetbrains.annotations.Nullable; import java.util.*; -import java.util.stream.Collectors; +import java.util.function.Supplier; +import java.util.stream.Stream; public class RefinedStorage { @@ -57,7 +63,7 @@ public static ItemStack findStackFromFilter(INetwork network, @Nullable ICraftin return ItemStack.EMPTY; for (ICraftingPattern pattern : crafting.getPatterns()) { - for (ItemStack stack : pattern.getOutputs()) { + for(ItemStack stack : pattern.getOutputs()) { if (filter.test(stack.copy())) return stack.copy(); } @@ -154,43 +160,35 @@ public static long getMaxFluidExternalStorage(INetwork network) { } public static Object getObjectFromPattern(ICraftingPattern pattern, INetwork network) { - if (pattern == null) - return null; - + if (pattern == null) return null; Map map = new HashMap<>(); - map.put("outputs", pattern.getOutputs().stream().map(stack -> getObjectFromStack(stack.copy(), network)).toList()); - map.put("fluidOutputs", pattern.getFluidOutputs().stream().map(stack -> getObjectFromFluid(stack.copy(), network)).toList()); - - List>> inputs = pattern.getInputs().stream() - .map(singleInputList -> singleInputList.stream() - .map(stack -> getObjectFromStack(stack.copy(), network)) - .collect(Collectors.toList())) - .collect(Collectors.toList()); - - List>> fluidInputs = pattern.getInputs().stream() - .map(singleInputList -> singleInputList.stream() - .map(stack -> getObjectFromStack(stack.copy(), network)) - .collect(Collectors.toList())) - .collect(Collectors.toList()); + List outputsList = pattern.getOutputs(); + List outputs = new ArrayList<>(); + for (ItemStack itemStack : outputsList) + outputs.add(getObjectFromStack(itemStack.copy(), network)); + + map.put("outputs", outputs); + + List> inputList = pattern.getInputs(); + List inputs = new ArrayList<>(); + for (List singleInputList : inputList) { + List inputs1 = new ArrayList<>(); + for (ItemStack stack : singleInputList) + inputs1.add(getObjectFromStack(stack.copy(), network)); + inputs.add(inputs1); + } List byproducts = new ArrayList<>(); if (!pattern.isProcessing()) { - byproducts = pattern.getByproducts().stream() - .map(stack -> getObjectFromStack(stack.copy(), network)) - .collect(Collectors.toList()); + List byproductsList = pattern.getByproducts(); + for (ItemStack stack : byproductsList) + byproducts.add(getObjectFromStack(stack.copy(), network)); } - map.put("fluidInputs", fluidInputs); map.put("inputs", inputs); + map.put("outputs", outputs); map.put("byproducts", byproducts); map.put("processing", pattern.isProcessing()); - Map container = new HashMap<>(); - map.put("name", pattern.getContainer().getName().getString()); - map.put("position", LuaConverter.posToObject(pattern.getContainer().getPosition())); - - map.put("container", container); - map.put("isValid", pattern.isValid()); - map.put("errorMessage", pattern.getErrorMessage() == null ? "" : pattern.getErrorMessage().getString()); return map; } @@ -198,13 +196,16 @@ public static Map getObjectFromStack(@Nullable ItemStack itemSta if (itemStack == null) return Collections.emptyMap(); - Map map = LuaConverter.itemToObject(itemStack.getItem()); + Map map = new HashMap<>(); CompoundTag nbt = itemStack.getTag(); + Supplier>> tags = () -> itemStack.getItem().builtInRegistryHolder().tags(); map.put("fingerprint", ItemUtil.getFingerprint(itemStack)); + map.put("name", ItemUtil.getRegistryKey(itemStack.getItem()).toString()); map.put("amount", itemStack.getCount()); map.put("displayName", itemStack.getDisplayName().getString()); map.put("isCraftable", isItemCraftable(network, itemStack)); map.put("nbt", nbt == null ? null : NBTUtil.toLua(nbt)); + map.put("tags", tags.get().findAny().isEmpty() ? null : LuaConverter.tagsToList(tags)); return map; } @@ -213,10 +214,13 @@ public static Map getObjectFromFluid(@Nullable FluidStack fluidS if (fluidStack == null) return Collections.emptyMap(); - Map map = LuaConverter.fluidToObject(fluidStack.getFluid()); + Map map = new HashMap<>(); + Supplier>> tags = () -> fluidStack.getFluid().builtInRegistryHolder().tags(); + map.put("name", ForgeRegistries.FLUIDS.getKey(fluidStack.getFluid()).toString()); map.put("amount", fluidStack.getAmount()); map.put("displayName", fluidStack.getDisplayName().getString()); map.put("isCraftable", isFluidCraftable(network, fluidStack)); + map.put("tags", tags.get().findAny().isEmpty() ? null : LuaConverter.tagsToList(tags)); return map; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsFluidHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsFluidHandler.java index 06da6c0bf..f945fb8b6 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsFluidHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsFluidHandler.java @@ -19,7 +19,7 @@ public RsFluidHandler(@NotNull INetwork network) { @Override public int fill(FluidStack resource, FluidAction action) { - if (resource.isEmpty()) + if(resource.isEmpty()) return 0; return resource.getAmount() - network.insertFluid(resource, resource.getAmount(), action == FluidAction.SIMULATE ? Action.SIMULATE : Action.PERFORM).getAmount(); } @@ -28,7 +28,7 @@ public int fill(FluidStack resource, FluidAction action) { @Override public FluidStack drain(FluidFilter filter, FluidAction simulate) { FluidStack fluid = RefinedStorage.findFluidFromFilter(network, null, filter); - if (fluid == null) + if(fluid == null) return FluidStack.EMPTY; return network.extractFluid(fluid, filter.getCount(), IComparer.COMPARE_QUANTITY, simulate == FluidAction.SIMULATE ? Action.SIMULATE : Action.PERFORM); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java index 900c8a5b0..a95035903 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java @@ -11,7 +11,6 @@ /** * Used to transfer item between an inventory and the RS system. - * * @see de.srendi.advancedperipherals.common.addons.computercraft.peripheral.RsBridgePeripheral */ public class RsItemHandler implements IStorageSystemItemHandler { @@ -32,8 +31,7 @@ public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate @Override public ItemStack extractItem(ItemFilter filter, int count, boolean simulate) { ItemStack item = RefinedStorage.findStackFromFilter(network, network.getCraftingManager(), filter); - if (item == null) - AdvancedPeripherals.debug("Trying to extract item: " + item + " from filter: " + filter); + AdvancedPeripherals.debug("Trying to extract item: " + item + " from filter: " + filter); if(item == null) return ItemStack.EMPTY; ItemStack extracted = network.extractItem(item, count, IComparer.COMPARE_NBT, simulate ? Action.SIMULATE : Action.PERFORM); diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/PlayerDetectorBlock.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/PlayerDetectorBlock.java index fec9f22c5..5da7a86ff 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/PlayerDetectorBlock.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/PlayerDetectorBlock.java @@ -4,7 +4,7 @@ import de.srendi.advancedperipherals.common.blocks.base.APBlockEntityBlock; import de.srendi.advancedperipherals.common.blocks.blockentities.PlayerDetectorEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; +import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; import net.minecraft.core.BlockPos; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; @@ -19,13 +19,13 @@ public class PlayerDetectorBlock extends APBlockEntityBlock { public PlayerDetectorBlock() { - super(APBlockEntityTypes.PLAYER_DETECTOR, true); + super(BlockEntityTypes.PLAYER_DETECTOR, true); } @Nullable @Override public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) { - return APBlockEntityTypes.PLAYER_DETECTOR.get().create(pos, state); + return BlockEntityTypes.PLAYER_DETECTOR.get().create(pos, state); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/RedstoneIntegratorBlock.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/RedstoneIntegratorBlock.java index 209d4e106..32a3b183f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/RedstoneIntegratorBlock.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/RedstoneIntegratorBlock.java @@ -2,8 +2,8 @@ import de.srendi.advancedperipherals.common.blocks.base.BaseBlockEntityBlock; import de.srendi.advancedperipherals.common.blocks.blockentities.RedstoneIntegratorEntity; -import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; -import de.srendi.advancedperipherals.common.setup.APBlocks; +import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; +import de.srendi.advancedperipherals.common.setup.Blocks; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.BlockGetter; @@ -16,13 +16,13 @@ public class RedstoneIntegratorBlock extends BaseBlockEntityBlock { public RedstoneIntegratorBlock() { - super(false, Properties.of(Material.METAL).isRedstoneConductor(APBlocks::never)); + super(false, Properties.of(Material.METAL).isRedstoneConductor(Blocks::never)); } @Nullable @Override public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) { - return APBlockEntityTypes.REDSTONE_INTEGRATOR.get().create(pos, state); + return BlockEntityTypes.REDSTONE_INTEGRATOR.get().create(pos, state); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlockEntityBlock.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlockEntityBlock.java index aaf4a1e7e..14549c842 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlockEntityBlock.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlockEntityBlock.java @@ -88,8 +88,7 @@ public MenuProvider getMenuProvider(@NotNull BlockState pState, Level pLevel, @N return menuProvider; } - @NotNull - public RenderShape getRenderShape(@NotNull BlockState state) { + public @NotNull RenderShape getRenderShape(@NotNull BlockState state) { return RenderShape.MODEL; } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/IInventoryBlock.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/IInventoryBlock.java index 5bfa6325c..3d118525b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/IInventoryBlock.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/IInventoryBlock.java @@ -10,8 +10,10 @@ * Used to assign a container to a TileEntity * * @param The container related to this inventory + * @deprecated Will be merged with the APBlock in 0.9 */ +@Deprecated(since = "0.7.16", forRemoval = true) public interface IInventoryBlock { Component getDisplayName(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PeripheralBlockEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PeripheralBlockEntity.java index 6fe4d3354..2b6d3ca8f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PeripheralBlockEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PeripheralBlockEntity.java @@ -34,7 +34,7 @@ import java.util.Collections; public abstract class PeripheralBlockEntity> extends BaseContainerBlockEntity implements WorldlyContainer, MenuProvider, IPeripheralTileEntity { - + // TODO: move inventory logic to another tile entity! private static final String PERIPHERAL_SETTINGS_KEY = "peripheralSettings"; protected CompoundTag peripheralSettings; protected NonNullList items; @@ -44,7 +44,7 @@ public abstract class PeripheralBlockEntity> extends private LazyOptional fluidHandler; private LazyOptional peripheralCap; - protected PeripheralBlockEntity(BlockEntityType tileEntityTypeIn, BlockPos pos, BlockState state) { + public PeripheralBlockEntity(BlockEntityType tileEntityTypeIn, BlockPos pos, BlockState state) { super(tileEntityTypeIn, pos, state); if (this instanceof IInventoryBlock inventoryBlock) { items = NonNullList.withSize(inventoryBlock.getInvSize(), ItemStack.EMPTY); @@ -113,11 +113,6 @@ public Iterable getConnectedComputers() { return peripheral.getConnectedComputers(); } - @Nullable - public T getPeripheral() { - return peripheral; - } - /*@Override public ITextComponent getDisplayName() { return this instanceof IInventoryBlock ? ((IInventoryBlock) this).getDisplayName() : null; diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PoweredPeripheralBlockEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PoweredPeripheralBlockEntity.java index 21a25c070..bace719d3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PoweredPeripheralBlockEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/PoweredPeripheralBlockEntity.java @@ -19,7 +19,7 @@ public abstract class PoweredPeripheralBlockEntity> private final LazyOptional lazyEnergyStorage; - protected PoweredPeripheralBlockEntity(BlockEntityType tileEntityTypeIn, BlockPos pos, BlockState state) { + public PoweredPeripheralBlockEntity(BlockEntityType tileEntityTypeIn, BlockPos pos, BlockState state) { super(tileEntityTypeIn, pos, state); if (APConfig.PERIPHERALS_CONFIG.enablePoweredPeripherals.get()) { lazyEnergyStorage = LazyOptional.of(() -> new EnergyStorage(this.getMaxEnergyStored())); diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/BlockReaderEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/BlockReaderEntity.java index 33e7b128f..db48c0460 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/BlockReaderEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/BlockReaderEntity.java @@ -2,7 +2,7 @@ import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.BlockReaderPeripheral; import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; -import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; +import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; import net.minecraft.core.BlockPos; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.NotNull; @@ -10,7 +10,7 @@ public class BlockReaderEntity extends PeripheralBlockEntity { public BlockReaderEntity(BlockPos pos, BlockState state) { - super(APBlockEntityTypes.BLOCK_READER.get(), pos, state); + super(BlockEntityTypes.BLOCK_READER.get(), pos, state); } @NotNull diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/ChatBoxEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/ChatBoxEntity.java index 594645f0c..118611259 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/ChatBoxEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/ChatBoxEntity.java @@ -2,7 +2,7 @@ import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.ChatBoxPeripheral; import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; -import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; +import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; import net.minecraft.core.BlockPos; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; @@ -11,9 +11,8 @@ import org.jetbrains.annotations.NotNull; public class ChatBoxEntity extends PeripheralBlockEntity { - public ChatBoxEntity(BlockPos pos, BlockState state) { - super(APBlockEntityTypes.CHAT_BOX.get(), pos, state); + super(BlockEntityTypes.CHAT_BOX.get(), pos, state); } @NotNull diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/ColonyIntegratorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/ColonyIntegratorEntity.java index 27e9d5e1f..8c6504791 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/ColonyIntegratorEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/ColonyIntegratorEntity.java @@ -2,7 +2,7 @@ import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.ColonyPeripheral; import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; -import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; +import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; import net.minecraft.core.BlockPos; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.NotNull; @@ -10,7 +10,7 @@ public class ColonyIntegratorEntity extends PeripheralBlockEntity { public ColonyIntegratorEntity(BlockPos pos, BlockState state) { - super(APBlockEntityTypes.COLONY_INTEGRATOR.get(), pos, state); + super(BlockEntityTypes.COLONY_INTEGRATOR.get(), pos, state); } @NotNull diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java deleted file mode 100644 index 94c8b11d9..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java +++ /dev/null @@ -1,164 +0,0 @@ -package de.srendi.advancedperipherals.common.blocks.blockentities; - -import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.DistanceDetectorPeripheral; -import de.srendi.advancedperipherals.common.blocks.base.BaseBlock; -import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; -import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.network.PacketHandler; -import de.srendi.advancedperipherals.common.network.toclient.DistanceDetectorSyncPacket; -import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; -import de.srendi.advancedperipherals.common.util.HitResultUtil; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.SlabBlock; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.properties.SlabType; -import net.minecraft.world.phys.*; -import org.jetbrains.annotations.NotNull; - -public class DistanceDetectorEntity extends PeripheralBlockEntity { - - private double maxRange = APConfig.PERIPHERALS_CONFIG.distanceDetectorRange.get(); - private float currentDistance = 0; - private boolean showLaser = true; - private boolean shouldCalculatePeriodically = false; - private boolean ignoreTransparent = true; - private DistanceDetectorPeripheral.DetectionType detectionType = DistanceDetectorPeripheral.DetectionType.BOTH; - - public DistanceDetectorEntity(BlockPos pos, BlockState state) { - super(APBlockEntityTypes.DISTANCE_DETECTOR.get(), pos, state); - } - - @NotNull - @Override - protected DistanceDetectorPeripheral createPeripheral() { - return new DistanceDetectorPeripheral(this); - } - - public void setShowLaser(boolean showLaser) { - if (this.showLaser != showLaser) - PacketHandler.sendToAll(new DistanceDetectorSyncPacket(getBlockPos(), getLevel().dimension(), currentDistance, showLaser)); - this.showLaser = showLaser; - } - - public void setCurrentDistance(float currentDistance) { - if (this.currentDistance != currentDistance) - PacketHandler.sendToAll(new DistanceDetectorSyncPacket(getBlockPos(), getLevel().dimension(), currentDistance, showLaser)); - this.currentDistance = currentDistance; - } - - public void setShouldCalculatePeriodically(boolean shouldCalculatePeriodically) { - this.shouldCalculatePeriodically = shouldCalculatePeriodically; - } - - public double getMaxDistance() { - return maxRange; - } - - public void setMaxRange(double maxRange) { - this.maxRange = maxRange; - } - - public float getCurrentDistance() { - return currentDistance; - } - - public boolean getLaserVisibility() { - return showLaser; - } - - public boolean shouldCalculatePeriodically() { - return shouldCalculatePeriodically; - } - - public boolean ignoreTransparent() { - return ignoreTransparent; - } - - public void setIgnoreTransparent(boolean ignoreTransparent) { - this.ignoreTransparent = ignoreTransparent; - } - - public DistanceDetectorPeripheral.DetectionType getDetectionType() { - return detectionType; - } - - public void setDetectionType(DistanceDetectorPeripheral.DetectionType detectionType) { - this.detectionType = detectionType; - } - - @Override - public void handleTick(Level level, BlockState state, BlockEntityType type) { - if (level.getGameTime() % APConfig.PERIPHERALS_CONFIG.distanceDetectorUpdateRate.get() == 0 && shouldCalculatePeriodically) { - // We calculate the distance every 2 ticks, so we do not have to run the getDistance function of the peripheral - // on the main thread which prevents the 1 tick yield time of the function. - // The calculateDistance function is not thread safe, so we have to run it on the main thread. - // It should be okay to run that function every 2 ticks, calculating it does not take too much time. - calculateDistance(); - } - } - - @Override - public AABB getRenderBoundingBox() { - Direction direction = getBlockState().getValue(BaseBlock.ORIENTATION).front(); - return AABB.ofSize(Vec3.atCenterOf(getBlockPos()), direction.getStepX() * currentDistance + 1, direction.getStepY() * currentDistance + 1, direction.getStepZ() * currentDistance + 1) - .move(direction.getStepX() * currentDistance / 2, direction.getStepY() * currentDistance / 2, direction.getStepZ() * currentDistance / 2); - } - - public double calculateDistance() { - Direction direction = getBlockState().getValue(BaseBlock.ORIENTATION).front(); - Vec3 center = Vec3.atCenterOf(getBlockPos()); - Vec3 from = center.add(direction.getStepX() * 0.501, direction.getStepY() * 0.501, direction.getStepZ() * 0.501); - Vec3 to = from.add(direction.getStepX() * maxRange, direction.getStepY() * maxRange, direction.getStepZ() * maxRange); - HitResult result = getResult(to, from); - - float distance = calculateDistance(result, center, direction); - setCurrentDistance(distance); - return distance; - } - - private HitResult getResult(Vec3 to, Vec3 from) { - if (detectionType == DistanceDetectorPeripheral.DetectionType.ENTITIES) - return HitResultUtil.getEntityHitResult(to, from, getLevel()); - if (detectionType == DistanceDetectorPeripheral.DetectionType.BLOCK) - return HitResultUtil.getBlockHitResult(to, from, getLevel(), ignoreTransparent); - return HitResultUtil.getHitResult(to, from, getLevel(), ignoreTransparent); - } - - private float calculateDistance(HitResult result, Vec3 center, Direction direction) { - float distance = 0; - if (result.getType() != HitResult.Type.MISS) { - if (result instanceof BlockHitResult blockHitResult) { - BlockState resultBlock = getLevel().getBlockState(blockHitResult.getBlockPos()); - distance = distManhattan(Vec3.atCenterOf(blockHitResult.getBlockPos()), center); - - distance = amendDistance(resultBlock, direction, distance); - } - if (result instanceof EntityHitResult entityHitResult) { - distance = distManhattan(entityHitResult.getLocation(), center); - } - } - return distance; - } - - private float amendDistance(BlockState resultBlock, Direction direction, float distance) { - if (resultBlock.getBlock() instanceof SlabBlock && direction.getAxis() == Direction.Axis.Y) { - SlabType type = resultBlock.getValue(SlabBlock.TYPE); - if (type == SlabType.TOP && direction == Direction.UP) - return distance + 0.5f; - if (type == SlabType.BOTTOM && direction == Direction.DOWN) - return distance - 0.5f; - } - return distance; - } - - private float distManhattan(Vec3 from, Vec3 to) { - float f = (float) Math.abs(from.x - to.x); - float f1 = (float) Math.abs(from.y - to.y); - float f2 = (float) Math.abs(from.z - to.z); - return f + f1 + f2; - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnergyDetectorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnergyDetectorEntity.java index a15e914d2..f8db556aa 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnergyDetectorEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnergyDetectorEntity.java @@ -1,15 +1,15 @@ package de.srendi.advancedperipherals.common.blocks.blockentities; import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.EnergyDetectorPeripheral; -import de.srendi.advancedperipherals.common.blocks.base.BaseBlock; import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; +import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; import de.srendi.advancedperipherals.common.util.EnergyStorageProxy; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.JigsawBlock; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; @@ -25,21 +25,20 @@ public class EnergyDetectorEntity extends PeripheralBlockEntity { - public int transferRate = 0; - //storageProxy that will forward the energy to the output but limit it to maxTransferRate - public final EnergyStorageProxy storageProxy = new EnergyStorageProxy(this, APConfig.PERIPHERALS_CONFIG.energyDetectorMaxFlow.get()); //a zero size, zero transfer energy storage to ensure that cables connect private final EnergyStorage zeroStorage = new EnergyStorage(0, 0, 0); - private final LazyOptional energyStorageCap = LazyOptional.of(() -> storageProxy); - private final LazyOptional zeroStorageCap = LazyOptional.of(() -> zeroStorage); + public int transferRate = 0; + //storageProxy that will forward the energy to the output but limit it to maxTransferRate + public EnergyStorageProxy storageProxy = new EnergyStorageProxy(this, APConfig.PERIPHERALS_CONFIG.energyDetectorMaxFlow.get()); + LazyOptional energyStorageCap = LazyOptional.of(() -> storageProxy); + Direction energyInDirection = Direction.NORTH; + Direction energyOutDirection = Direction.SOUTH; + LazyOptional zeroStorageCap = LazyOptional.of(() -> zeroStorage); @NotNull private Optional outReceivingStorage = Optional.empty(); - private Direction energyInDirection = Direction.NORTH; - private Direction energyOutDirection = Direction.SOUTH; - public EnergyDetectorEntity(BlockPos pos, BlockState state) { - super(APBlockEntityTypes.ENERGY_DETECTOR.get(), pos, state); + super(BlockEntityTypes.ENERGY_DETECTOR.get(), pos, state); } @NotNull @@ -51,8 +50,8 @@ protected EnergyDetectorPeripheral createPeripheral() { @NotNull @Override public LazyOptional getCapability(@NotNull Capability cap, @Nullable Direction direction) { - energyInDirection = getBlockState().getValue(BaseBlock.ORIENTATION).front(); - energyOutDirection = getBlockState().getValue(BaseBlock.ORIENTATION).front().getOpposite(); + energyInDirection = getBlockState().getValue(JigsawBlock.ORIENTATION).front(); + energyOutDirection = getBlockState().getValue(JigsawBlock.ORIENTATION).front().getOpposite(); if (cap == ForgeCapabilities.ENERGY) { if (direction == energyInDirection) { return energyStorageCap.cast(); @@ -79,19 +78,19 @@ public void handleTick(Level level, BlockState state, Bl } @Override - public void load(CompoundTag nbt) { + public void deserializeNBT(CompoundTag nbt) { storageProxy.setMaxTransferRate(nbt.getInt("rateLimit")); - super.load(nbt); + super.deserializeNBT(nbt); } public void invalidateStorages() { outReceivingStorage = Optional.empty(); } - // returns the cached output storage of the receiving block or fetches it if it has been invalidated + // returns the cached output storage of the receiving block or refetches it if it has been invalidated @NotNull public Optional getOutputStorage() { - // the documentation says that the value of the LazyOptional should be cached locally and invalidated using addListener + // the documentation says that the value of the LazyOptional should be cached locally and invallidated using addListener if (outReceivingStorage.isEmpty()) { BlockEntity teOut = level.getBlockEntity(worldPosition.relative(energyOutDirection)); if (teOut == null) { diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnvironmentDetectorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnvironmentDetectorEntity.java index 681ed938e..64a4527cc 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnvironmentDetectorEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/EnvironmentDetectorEntity.java @@ -3,7 +3,7 @@ import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.EnvironmentDetectorPeripheral; import de.srendi.advancedperipherals.common.blocks.base.PoweredPeripheralBlockEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; +import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; import net.minecraft.core.BlockPos; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.NotNull; @@ -11,7 +11,7 @@ public class EnvironmentDetectorEntity extends PoweredPeripheralBlockEntity { public EnvironmentDetectorEntity(BlockPos pos, BlockState state) { - super(APBlockEntityTypes.ENVIRONMENT_DETECTOR.get(), pos, state); + super(BlockEntityTypes.ENVIRONMENT_DETECTOR.get(), pos, state); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/FluidDetectorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/FluidDetectorEntity.java deleted file mode 100644 index 3a808db82..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/FluidDetectorEntity.java +++ /dev/null @@ -1,106 +0,0 @@ -package de.srendi.advancedperipherals.common.blocks.blockentities; - -import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.FluidDetectorPeripheral; -import de.srendi.advancedperipherals.common.blocks.base.BaseBlock; -import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; -import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; -import de.srendi.advancedperipherals.common.util.FluidStorageProxy; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.IFluidHandler; -import net.minecraftforge.fluids.capability.templates.FluidTank; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Optional; - -public class FluidDetectorEntity extends PeripheralBlockEntity { - - public int transferRate = 0; - public FluidStack lastFlowedLiquid = FluidStack.EMPTY; - - //storageProxy that will forward the fluid to the output but limit it to maxTransferRate - public final FluidStorageProxy storageProxy = new FluidStorageProxy(this, APConfig.PERIPHERALS_CONFIG.fluidDetectorMaxFlow.get()); - //a zero size, zero transfer fluid storage to ensure that cables connect - private final FluidTank zeroStorage = new FluidTank(0); - private final LazyOptional fluidStorageCap = LazyOptional.of(() -> storageProxy); - private final LazyOptional zeroStorageCap = LazyOptional.of(() -> zeroStorage); - private Optional outReceivingStorage = Optional.empty(); - - private Direction fluidInDetection = Direction.NORTH; - private Direction fluidOutDirection = Direction.SOUTH; - - public FluidDetectorEntity(BlockPos pos, BlockState state) { - super(APBlockEntityTypes.FLUID_DETECTOR.get(), pos, state); - } - - @NotNull - @Override - protected FluidDetectorPeripheral createPeripheral() { - return new FluidDetectorPeripheral(this); - } - - @NotNull - @Override - public LazyOptional getCapability(@NotNull Capability cap, @Nullable Direction direction) { - fluidInDetection = getBlockState().getValue(BaseBlock.ORIENTATION).front(); - fluidOutDirection = getBlockState().getValue(BaseBlock.ORIENTATION).front().getOpposite(); - if (cap == ForgeCapabilities.FLUID_HANDLER) { - if (direction == fluidInDetection) { - return fluidStorageCap.cast(); - } else if (direction == fluidOutDirection) { - return zeroStorageCap.cast(); - } - } - return super.getCapability(cap, direction); - } - - @Override - public void saveAdditional(@NotNull CompoundTag compound) { - super.saveAdditional(compound); - compound.putInt("rateLimit", storageProxy.getMaxTransferRate()); - } - - @Override - public void handleTick(Level level, BlockState state, BlockEntityType type) { - if (!level.isClientSide) { - // this handles the rare edge case that receiveFluid is called multiple times in one tick - transferRate = storageProxy.getTransferedInThisTick(); - storageProxy.resetTransferedInThisTick(); - } - } - - @Override - public void load(CompoundTag nbt) { - storageProxy.setMaxTransferRate(nbt.getInt("rateLimit")); - super.load(nbt); - } - - // returns the cached output storage of the receiving block or fetches it if it has been invalidated - @NotNull - public Optional getOutputStorage() { - // the documentation says that the value of the LazyOptional should be cached locally and invalidated using addListener - if (outReceivingStorage.isEmpty()) { - BlockEntity teOut = level.getBlockEntity(worldPosition.relative(fluidOutDirection)); - if (teOut == null) { - return Optional.empty(); - } - LazyOptional lazyOptionalOutStorage = teOut.getCapability(ForgeCapabilities.FLUID_HANDLER, fluidOutDirection.getOpposite()); - outReceivingStorage = lazyOptionalOutStorage.resolve(); - lazyOptionalOutStorage.addListener(l -> { - outReceivingStorage = Optional.empty(); - }); - } - return outReceivingStorage; - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/GasDetectorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/GasDetectorEntity.java deleted file mode 100644 index 23f7dda1c..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/GasDetectorEntity.java +++ /dev/null @@ -1,106 +0,0 @@ -package de.srendi.advancedperipherals.common.blocks.blockentities; - -import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.GasDetectorPeripheral; -import de.srendi.advancedperipherals.common.addons.mekanism.MekanismCapabilities; -import de.srendi.advancedperipherals.common.blocks.base.BaseBlock; -import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; -import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; -import de.srendi.advancedperipherals.common.util.GasStorageProxy; -import de.srendi.advancedperipherals.common.util.ZeroGasTank; -import mekanism.api.chemical.gas.GasStack; -import mekanism.api.chemical.gas.IGasHandler; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.util.LazyOptional; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Optional; - -public class GasDetectorEntity extends PeripheralBlockEntity { - - public int transferRate = 0; - public GasStack lastFlowedGas = GasStack.EMPTY; - - //storageProxy that will forward the gas to the output but limit it to maxTransferRate - public final GasStorageProxy storageProxy = new GasStorageProxy(this, APConfig.PERIPHERALS_CONFIG.gasDetectorMaxFlow.get()); - //a zero size, zero transfer gas storage to ensure that cables connect - private final IGasHandler zeroStorage = new ZeroGasTank(); - private final LazyOptional gasStorageCap = LazyOptional.of(() -> storageProxy); - private final LazyOptional zeroStorageCap = LazyOptional.of(() -> zeroStorage); - private Optional outReceivingStorage = Optional.empty(); - - private Direction gasInDirection = Direction.NORTH; - private Direction gasOutDirection = Direction.SOUTH; - - public GasDetectorEntity(BlockPos pos, BlockState state) { - super(APBlockEntityTypes.GAS_DETECTOR.get(), pos, state); - } - - @NotNull - @Override - protected GasDetectorPeripheral createPeripheral() { - return new GasDetectorPeripheral(this); - } - - @NotNull - @Override - public LazyOptional getCapability(@NotNull Capability cap, @Nullable Direction direction) { - gasInDirection = getBlockState().getValue(BaseBlock.ORIENTATION).front(); - gasOutDirection = getBlockState().getValue(BaseBlock.ORIENTATION).front().getOpposite(); - if (cap == MekanismCapabilities.GAS_HANDLER) { - if (direction == gasInDirection) { - return gasStorageCap.cast(); - } else if (direction == gasOutDirection) { - return zeroStorageCap.cast(); - } - } - return super.getCapability(cap, direction); - } - - @Override - public void saveAdditional(@NotNull CompoundTag compound) { - super.saveAdditional(compound); - compound.putInt("rateLimit", storageProxy.getMaxTransferRate()); - } - - @Override - public void handleTick(Level level, BlockState state, BlockEntityType type) { - if (!level.isClientSide) { - // this handles the rare edge case that receiveGas is called multiple times in one tick - transferRate = storageProxy.getTransferedInThisTick(); - storageProxy.resetTransferedInThisTick(); - } - } - - @Override - public void load(CompoundTag nbt) { - storageProxy.setMaxTransferRate(nbt.getInt("rateLimit")); - super.load(nbt); - } - - // returns the cached output storage of the receiving block or fetches it if it has been invalidated - @NotNull - public Optional getOutputStorage() { - // the documentation says that the value of the LazyOptional should be cached locally and invalidated using addListener - if (outReceivingStorage.isEmpty()) { - BlockEntity teOut = level.getBlockEntity(worldPosition.relative(gasOutDirection)); - if (teOut == null) { - return Optional.empty(); - } - LazyOptional lazyOptionalOutStorage = teOut.getCapability(MekanismCapabilities.GAS_HANDLER, gasOutDirection.getOpposite()); - outReceivingStorage = lazyOptionalOutStorage.resolve(); - lazyOptionalOutStorage.addListener(l -> { - outReceivingStorage = Optional.empty(); - }); - } - return outReceivingStorage; - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/GeoScannerEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/GeoScannerEntity.java index 56eab8959..225541a4d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/GeoScannerEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/GeoScannerEntity.java @@ -3,7 +3,7 @@ import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.GeoScannerPeripheral; import de.srendi.advancedperipherals.common.blocks.base.PoweredPeripheralBlockEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; +import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; import net.minecraft.core.BlockPos; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.NotNull; @@ -11,7 +11,7 @@ public class GeoScannerEntity extends PoweredPeripheralBlockEntity { public GeoScannerEntity(BlockPos pos, BlockState state) { - super(APBlockEntityTypes.GEO_SCANNER.get(), pos, state); + super(BlockEntityTypes.GEO_SCANNER.get(), pos, state); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java index d92104fe1..fad6ce3d7 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java @@ -5,7 +5,7 @@ import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; import de.srendi.advancedperipherals.common.container.InventoryManagerContainer; import de.srendi.advancedperipherals.common.items.MemoryCardItem; -import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; +import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.network.chat.Component; @@ -21,7 +21,7 @@ public class InventoryManagerEntity extends PeripheralBlockEntity implements IInventoryBlock { public InventoryManagerEntity(BlockPos pos, BlockState state) { - super(APBlockEntityTypes.INVENTORY_MANAGER.get(), pos, state); + super(BlockEntityTypes.INVENTORY_MANAGER.get(), pos, state); } @NotNull diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/MeBridgeEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/MeBridgeEntity.java index c85092a9a..d9eb38a98 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/MeBridgeEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/MeBridgeEntity.java @@ -10,8 +10,8 @@ import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.MeBridgePeripheral; import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; -import de.srendi.advancedperipherals.common.setup.APBlocks; +import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; +import de.srendi.advancedperipherals.common.setup.Blocks; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.entity.player.Player; @@ -34,7 +34,7 @@ public class MeBridgeEntity extends PeripheralBlockEntity im private final IManagedGridNode mainNode = GridHelper.createManagedNode(this, MeBridgeEntityListener.INSTANCE); public MeBridgeEntity(BlockPos pos, BlockState state) { - super(APBlockEntityTypes.ME_BRIDGE.get(), pos, state); + super(BlockEntityTypes.ME_BRIDGE.get(), pos, state); } @NotNull @@ -50,7 +50,7 @@ public void handleTick(Level level, BlockState state, Bl mainNode.setFlags(GridFlags.REQUIRE_CHANNEL); mainNode.setIdlePowerUsage(APConfig.PERIPHERALS_CONFIG.meConsumption.get()); - mainNode.setVisualRepresentation(new ItemStack(APBlocks.ME_BRIDGE.get())); + mainNode.setVisualRepresentation(new ItemStack(Blocks.ME_BRIDGE.get())); mainNode.setInWorldNode(true); mainNode.create(level, getBlockPos()); diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/NBTStorageEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/NBTStorageEntity.java index 0b56fedc1..707fec188 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/NBTStorageEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/NBTStorageEntity.java @@ -2,7 +2,7 @@ import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.NBTStoragePeripheral; import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; -import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; +import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.level.block.state.BlockState; @@ -13,7 +13,7 @@ public class NBTStorageEntity extends PeripheralBlockEntity#384 * * @param direction Cardinal direction - * @param power The redstone power from 0 to 15 + * @param power The redstone power from 0 to 15 */ public void setOutput(Direction direction, int power) { ServerWorker.add(() -> setRedstoneOutput(direction, power)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java index aee5e4a58..e3bc4a364 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java @@ -8,7 +8,7 @@ import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.RsBridgePeripheral; import de.srendi.advancedperipherals.common.addons.refinedstorage.RefinedStorageNode; -import de.srendi.advancedperipherals.common.setup.APBlockEntityTypes; +import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; import de.srendi.advancedperipherals.lib.peripherals.IPeripheralTileEntity; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -32,7 +32,7 @@ public class RsBridgeEntity extends NetworkNodeBlockEntity i private LazyOptional peripheralCap; public RsBridgeEntity(BlockPos pos, BlockState state) { - super(APBlockEntityTypes.RS_BRIDGE.get(), pos, state, SPEC); + super(BlockEntityTypes.RS_BRIDGE.get(), pos, state, SPEC); peripheralSettings = new CompoundTag(); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java b/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java index 3a641a7cc..06f8a9aa8 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java +++ b/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java @@ -37,8 +37,8 @@ public class APCommands { @SubscribeEvent public static void register(RegisterCommandsEvent event) { event.getDispatcher().register(Commands.literal(ROOT_LITERAL) - .then(Commands.literal("getHashItem") - .executes(context -> getHashItem(context.getSource()))).then(Commands.literal(FORCELOAD_LITERAL) + .then(Commands.literal("getHashItem").executes(context -> getHashItem(context.getSource()))) + .then(Commands.literal(FORCELOAD_LITERAL) .executes(context -> forceloadHelp(context.getSource())) .then(Commands.literal("help") .executes(context -> forceloadHelp(context.getSource()))) diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/GeneralConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/GeneralConfig.java index 954dad5a3..57c32e43d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/GeneralConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/GeneralConfig.java @@ -28,6 +28,7 @@ public class GeneralConfig implements IAPConfig { configSpec = builder.build(); } + @Override public ForgeConfigSpec getConfigSpec() { return configSpec; diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java index 9589d4f43..e9c7d0d33 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java @@ -24,13 +24,6 @@ public class PeripheralsConfig implements IAPConfig { public final ForgeConfigSpec.IntValue energyDetectorMaxFlow; public final ForgeConfigSpec.BooleanValue enableEnergyDetector; - //Fluid Detector - public final ForgeConfigSpec.IntValue fluidDetectorMaxFlow; - public final ForgeConfigSpec.BooleanValue enableFluidDetector; - - //Gas Detector - public final ForgeConfigSpec.IntValue gasDetectorMaxFlow; - public final ForgeConfigSpec.BooleanValue enableGasDetector; //NBT Storage public final ForgeConfigSpec.IntValue nbtStorageMaxSize; public final ForgeConfigSpec.BooleanValue enableNBTStorage; @@ -57,7 +50,8 @@ public class PeripheralsConfig implements IAPConfig { public final ForgeConfigSpec.BooleanValue enableEnvironmentDetector; //AR Controller - public final ForgeConfigSpec.BooleanValue enableSmartGlasses; + public final ForgeConfigSpec.BooleanValue enableARGoggles; + //Inventory Manager public final ForgeConfigSpec.BooleanValue enableInventoryManager; @@ -76,11 +70,6 @@ public class PeripheralsConfig implements IAPConfig { //Compass turtle public final ForgeConfigSpec.BooleanValue enableCompassTurtle; - //Compass turtle - public final ForgeConfigSpec.BooleanValue enableDistanceDetector; - public final ForgeConfigSpec.DoubleValue distanceDetectorRange; - public final ForgeConfigSpec.IntValue distanceDetectorUpdateRate; - //Powered Peripherals public final ForgeConfigSpec.BooleanValue enablePoweredPeripherals; public final ForgeConfigSpec.BooleanValue disablePocketFuelConsumption; @@ -106,17 +95,7 @@ public PeripheralsConfig() { pop("Energy_Detector", builder); enableEnergyDetector = builder.comment("Enable the Energy Detector or not.").define("enableEnergyDetector", true); - energyDetectorMaxFlow = builder.comment("Defines the maximum energy flow of the energy detector.").defineInRange("energyDetectorMaxFlow", Integer.MAX_VALUE, 0, Integer.MAX_VALUE); - - pop("Fluid_Detector", builder); - - enableFluidDetector = builder.comment("Enable the Fluid Detector or not.").define("enableFluidDetector", true); - fluidDetectorMaxFlow = builder.comment("Defines the maximum fluid flow of the fluid detector.").defineInRange("energyDetectorMaxFlow", Integer.MAX_VALUE, 0, Integer.MAX_VALUE); - - pop("Gas_Detector", builder); - - enableGasDetector = builder.comment("Enable the Gas Detector or not.").define("enableGasDetector", true); - gasDetectorMaxFlow = builder.comment("Defines the maximum gas flow of the gas detector.").defineInRange("gasDetectorMaxFlow", Integer.MAX_VALUE, 0, Integer.MAX_VALUE); + energyDetectorMaxFlow = builder.comment("Defines the maximum energy flow of the energy detector.").defineInRange("energyDetectorMaxFlow", Integer.MAX_VALUE, 1, Integer.MAX_VALUE); pop("NBT_Storage", builder); @@ -151,7 +130,7 @@ public PeripheralsConfig() { pop("AR_Controller", builder); - enableSmartGlasses = builder.comment("Enable the smart glasses or not.").define("enableSmartGlasses", true); + enableARGoggles = builder.comment("Enable the AR goggles or not.").define("enableARGoggles", true); pop("Inventory_Manager", builder); @@ -177,13 +156,6 @@ public PeripheralsConfig() { enableCompassTurtle = builder.comment("Enable the compass turtle or not.").define("enableCompassTurtle", true); - pop("Distance_Detector", builder); - - enableDistanceDetector = builder.comment("Enable the distance detector or not.").define("enableDistanceDetector", true); - distanceDetectorRange = builder.comment("Maximum range of the distance detector").defineInRange("distanceDetectorRange", 64D, 0D, Integer.MAX_VALUE); - distanceDetectorUpdateRate = builder.comment("Defines how often the distance detector updates it's distance if periodically updates are enabled. \n" + - "Periodically updates exists so we do not need to run \"getDistance\" on the main thread which eliminates the 1 tick yield of the lua function").defineInRange("maxUpdateRate", 2, 1, 100); - pop("Powered_Peripherals", builder); enablePoweredPeripherals = builder.comment("Enable RF storage for peripherals, that could use it").define("enablePoweredPeripherals", false); diff --git a/src/main/java/de/srendi/advancedperipherals/common/container/InventoryManagerContainer.java b/src/main/java/de/srendi/advancedperipherals/common/container/InventoryManagerContainer.java index b4116aa2c..4ccc859cf 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/container/InventoryManagerContainer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/container/InventoryManagerContainer.java @@ -3,8 +3,8 @@ import de.srendi.advancedperipherals.common.container.base.BaseContainer; import de.srendi.advancedperipherals.common.container.base.SlotCondition; import de.srendi.advancedperipherals.common.container.base.SlotInputHandler; -import de.srendi.advancedperipherals.common.setup.APContainerTypes; -import de.srendi.advancedperipherals.common.setup.APItems; +import de.srendi.advancedperipherals.common.setup.ContainerTypes; +import de.srendi.advancedperipherals.common.setup.Items; import net.minecraft.core.BlockPos; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; @@ -17,11 +17,11 @@ public class InventoryManagerContainer extends BaseContainer { public InventoryManagerContainer(int id, Inventory inventory, BlockPos pos, Level level) { - super(APContainerTypes.INVENTORY_MANAGER_CONTAINER.get(), id, inventory, pos, level); + super(ContainerTypes.INVENTORY_MANAGER_CONTAINER.get(), id, inventory, pos, level); layoutPlayerInventorySlots(7, 84); if (tileEntity != null) { tileEntity.getCapability(ForgeCapabilities.ITEM_HANDLER).ifPresent(handler -> { - addSlot(new SlotInputHandler(handler, 0, 79, 29, new SlotCondition().setNeededItem(APItems.MEMORY_CARD.get()))); //Input + addSlot(new SlotInputHandler(handler, 0, 79, 29, new SlotCondition().setNeededItem(Items.MEMORY_CARD.get()))); //Input }); } } @@ -44,7 +44,7 @@ public ItemStack quickMoveStack(@NotNull Player player, int index) { return ItemStack.EMPTY; } } else if (index <= 35) { - if (itemstack1.getItem().equals(APItems.MEMORY_CARD.get())) { + if (itemstack1.getItem().equals(Items.MEMORY_CARD.get())) { if (!this.moveItemStackTo(itemstack1, 36, 37, true)) { return ItemStack.EMPTY; } @@ -68,5 +68,4 @@ public ItemStack quickMoveStack(@NotNull Player player, int index) { return itemstack; } - } diff --git a/src/main/java/de/srendi/advancedperipherals/client/screens/InventoryManagerScreen.java b/src/main/java/de/srendi/advancedperipherals/common/container/InventoryManagerScreen.java similarity index 78% rename from src/main/java/de/srendi/advancedperipherals/client/screens/InventoryManagerScreen.java rename to src/main/java/de/srendi/advancedperipherals/common/container/InventoryManagerScreen.java index d1730b50b..e4d88e29c 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/screens/InventoryManagerScreen.java +++ b/src/main/java/de/srendi/advancedperipherals/common/container/InventoryManagerScreen.java @@ -1,8 +1,7 @@ -package de.srendi.advancedperipherals.client.screens; +package de.srendi.advancedperipherals.common.container; import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.client.screens.base.BaseScreen; -import de.srendi.advancedperipherals.common.container.InventoryManagerContainer; +import de.srendi.advancedperipherals.common.container.base.BaseScreen; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; diff --git a/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java b/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java deleted file mode 100644 index 8a8bd7684..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/container/SmartGlassesContainer.java +++ /dev/null @@ -1,100 +0,0 @@ -package de.srendi.advancedperipherals.common.container; - -import dan200.computercraft.client.gui.widgets.ComputerSidebar; -import dan200.computercraft.shared.computer.core.ComputerFamily; -import dan200.computercraft.shared.computer.core.ServerComputer; -import dan200.computercraft.shared.computer.inventory.ContainerComputerBase; -import dan200.computercraft.shared.network.container.ComputerContainerData; -import de.srendi.advancedperipherals.common.setup.APContainerTypes; -import de.srendi.advancedperipherals.common.smartglasses.SlotType; -import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesSlot; -import net.minecraft.world.entity.player.Inventory; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.Slot; -import net.minecraft.world.item.ItemStack; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.items.IItemHandler; -import org.jetbrains.annotations.NotNull; - -import java.util.function.Predicate; - -public class SmartGlassesContainer extends ContainerComputerBase { - public static final int BORDER = 8; - public static final int PLAYER_START_Y = 134; - public static final int PLAYER_START_X = ComputerSidebar.WIDTH + BORDER; - - public SmartGlassesContainer(int id, Predicate canUse, ServerComputer computer, Inventory playerInventory, IItemHandler inventory, ComputerContainerData data) { - super(APContainerTypes.SMART_GLASSES_CONTAINER.get(), id, canUse, ComputerFamily.ADVANCED, computer, data); - - // Glasses Peripherals - addSlot(new SmartGlassesSlot(inventory, 0, 222, 148, SlotType.PERIPHERALS)); - addSlot(new SmartGlassesSlot(inventory, 1, 204, 166, SlotType.PERIPHERALS)); - addSlot(new SmartGlassesSlot(inventory, 2, 222, 166, SlotType.PERIPHERALS)); - addSlot(new SmartGlassesSlot(inventory, 3, 240, 166, SlotType.PERIPHERALS)); - addSlot(new SmartGlassesSlot(inventory, 4, 222, 184, SlotType.PERIPHERALS)); - - // Glasses Modules - addSlot(new SmartGlassesSlot(inventory, 5, 222, 148, SlotType.MODULES)); - addSlot(new SmartGlassesSlot(inventory, 6, 204, 166, SlotType.MODULES)); - addSlot(new SmartGlassesSlot(inventory, 7, 222, 166, SlotType.MODULES)); - addSlot(new SmartGlassesSlot(inventory, 8, 240, 166, SlotType.MODULES)); - addSlot(new SmartGlassesSlot(inventory, 9, 222, 184, SlotType.MODULES)); - addSlot(new SmartGlassesSlot(inventory, 10, 240, 184, SlotType.MODULES)); - - // Player inventory - for (var y = 0; y < 3; y++) { - for (var x = 0; x < 9; x++) { - addSlot(new Slot(playerInventory, x + y * 9 + 9, PLAYER_START_X + x * 18, PLAYER_START_Y + 1 + y * 18)); - } - } - - // Player hotbar - for (var x = 0; x < 9; x++) { - addSlot(new Slot(playerInventory, x, PLAYER_START_X + x * 18, PLAYER_START_Y + 3 * 18 + 5)); - } - - } - - public SmartGlassesContainer(int id, Predicate predicate, ServerComputer computer, ComputerContainerData data, Inventory player, ItemStack glasses) { - this(id, predicate, computer, player, glasses.getCapability(ForgeCapabilities.ITEM_HANDLER).resolve().orElseThrow(), data); - } - - @NotNull - @Override - public ItemStack quickMoveStack(@NotNull Player player, int index) { - ItemStack itemstack = ItemStack.EMPTY; - Slot slot = this.slots.get(index); - if (slot.hasItem()) { - ItemStack itemstack1 = slot.getItem(); - itemstack = itemstack1.copy(); - if (index >= 36) { - if (!this.moveItemStackTo(itemstack1, 0, 36, true)) { - return ItemStack.EMPTY; - } - } else { - if (!this.moveItemStackTo(itemstack1, 36, 37, true)) { - return ItemStack.EMPTY; - } - } - - if (itemstack1.isEmpty()) { - slot.set(ItemStack.EMPTY); - } else { - slot.setChanged(); - } - - if (itemstack1.getCount() == itemstack.getCount()) { - return ItemStack.EMPTY; - } - - slot.onTake(player, itemstack1); - } - - return itemstack; - } - - @Override - public boolean stillValid(Player player) { - return true; - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/client/screens/base/BaseItemScreen.java b/src/main/java/de/srendi/advancedperipherals/common/container/base/BaseItemScreen.java similarity index 73% rename from src/main/java/de/srendi/advancedperipherals/client/screens/base/BaseItemScreen.java rename to src/main/java/de/srendi/advancedperipherals/common/container/base/BaseItemScreen.java index a7e7e9476..527878f10 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/screens/base/BaseItemScreen.java +++ b/src/main/java/de/srendi/advancedperipherals/common/container/base/BaseItemScreen.java @@ -1,18 +1,16 @@ -package de.srendi.advancedperipherals.client.screens.base; +package de.srendi.advancedperipherals.common.container.base; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; -import de.srendi.advancedperipherals.common.container.base.BaseItemContainer; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; -import org.jetbrains.annotations.NotNull; public abstract class BaseItemScreen extends AbstractContainerScreen { - protected BaseItemScreen(T screenContainer, Inventory inv, Component titleIn) { + public BaseItemScreen(T screenContainer, Inventory inv, Component titleIn) { super(screenContainer, inv, titleIn); imageWidth = getSizeX(); @@ -20,14 +18,14 @@ protected BaseItemScreen(T screenContainer, Inventory inv, Component titleIn) { } @Override - public void render(@NotNull PoseStack matrixStack, int x, int y, float partialTicks) { + public void render(PoseStack matrixStack, int x, int y, float partialTicks) { renderBackground(matrixStack); super.render(matrixStack, x, y, partialTicks); renderTooltip(matrixStack, x, y); } @Override - protected void renderBg(@NotNull PoseStack matrixStack, float partialTicks, int x, int y) { + protected void renderBg(PoseStack matrixStack, float partialTicks, int x, int y) { RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShaderTexture(0, getTexture()); diff --git a/src/main/java/de/srendi/advancedperipherals/client/screens/base/BaseScreen.java b/src/main/java/de/srendi/advancedperipherals/common/container/base/BaseScreen.java similarity index 86% rename from src/main/java/de/srendi/advancedperipherals/client/screens/base/BaseScreen.java rename to src/main/java/de/srendi/advancedperipherals/common/container/base/BaseScreen.java index 9390fa902..f9311435e 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/screens/base/BaseScreen.java +++ b/src/main/java/de/srendi/advancedperipherals/common/container/base/BaseScreen.java @@ -1,8 +1,7 @@ -package de.srendi.advancedperipherals.client.screens.base; +package de.srendi.advancedperipherals.common.container.base; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; -import de.srendi.advancedperipherals.common.container.base.BaseContainer; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.network.chat.Component; @@ -12,7 +11,7 @@ public abstract class BaseScreen extends AbstractContainerScreen { - protected BaseScreen(T screenContainer, Inventory inv, Component titleIn) { + public BaseScreen(T screenContainer, Inventory inv, Component titleIn) { super(screenContainer, inv, titleIn); imageWidth = getSizeX(); imageHeight = getSizeY(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/container/base/SlotCondition.java b/src/main/java/de/srendi/advancedperipherals/common/container/base/SlotCondition.java index 1adcfcbc3..d1fae341c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/container/base/SlotCondition.java +++ b/src/main/java/de/srendi/advancedperipherals/common/container/base/SlotCondition.java @@ -12,9 +12,9 @@ */ public class SlotCondition { - private List> neededTags = new ArrayList<>(); + public List> neededTags = new ArrayList<>(); - private List neededItems = new ArrayList<>(); + public List neededItems = new ArrayList<>(); /** * Sets the valid tags for the item @@ -75,9 +75,9 @@ public boolean isValid(ItemStack stack) { if (stack.getTags().noneMatch(tag::equals)) valid = false; } } - if (!neededItems.isEmpty() && (!neededItems.contains(stack.getItem()))) - valid = false; - + if (!neededItems.isEmpty()) { + if (!neededItems.contains(stack.getItem())) valid = false; + } return valid; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java b/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java index be546eda1..fe6799cd7 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java @@ -1,6 +1,6 @@ package de.srendi.advancedperipherals.common.data; -import de.srendi.advancedperipherals.common.setup.APRegistration; +import de.srendi.advancedperipherals.common.setup.Registration; import net.minecraft.world.level.block.Block; import net.minecraftforge.registries.RegistryObject; import org.jetbrains.annotations.NotNull; @@ -9,12 +9,12 @@ public class BlockLootTables extends net.minecraft.data.loot.BlockLoot { @Override protected void addTables() { - APRegistration.BLOCKS.getEntries().stream().map(RegistryObject::get).forEach(this::dropSelf); + Registration.BLOCKS.getEntries().stream().map(RegistryObject::get).forEach(this::dropSelf); } @NotNull @Override protected Iterable getKnownBlocks() { - return APRegistration.BLOCKS.getEntries().stream().map(RegistryObject::get)::iterator; + return Registration.BLOCKS.getEntries().stream().map(RegistryObject::get)::iterator; } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/BlockStatesAndModelsProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/BlockStatesAndModelsProvider.java index ac90a7390..05ca01c26 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/BlockStatesAndModelsProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/BlockStatesAndModelsProvider.java @@ -2,7 +2,7 @@ import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.blocks.base.BaseBlock; -import de.srendi.advancedperipherals.common.setup.APBlocks; +import de.srendi.advancedperipherals.common.setup.Blocks; import net.minecraft.core.Direction; import net.minecraft.core.FrontAndTop; import net.minecraft.data.DataGenerator; @@ -20,30 +20,29 @@ public BlockStatesAndModelsProvider(DataGenerator packOutput, ExistingFileHelper @Override protected void registerStatesAndModels() { - peripheralBlock(APBlocks.ENVIRONMENT_DETECTOR.get(), "front"); - peripheralBlock(APBlocks.CHAT_BOX.get(), "front"); - peripheralBlock(APBlocks.PLAYER_DETECTOR.get(), "side", "front"); - peripheralBlock(APBlocks.ME_BRIDGE.get(), "front"); - peripheralBlock(APBlocks.RS_BRIDGE.get(), "front"); - peripheralBlock(APBlocks.ENERGY_DETECTOR.get(), "front", "back"); - peripheralBlock(APBlocks.PERIPHERAL_CASING.get()); - peripheralBlock(APBlocks.INVENTORY_MANAGER.get(), "front"); - peripheralBlock(APBlocks.REDSTONE_INTEGRATOR.get(), "front"); - peripheralBlock(APBlocks.BLOCK_READER.get(), generateModel(APBlocks.BLOCK_READER.get(), false, "north", "south", "east", "west", "up", "down")); - peripheralBlock(APBlocks.GEO_SCANNER.get(), "front"); - peripheralBlock(APBlocks.COLONY_INTEGRATOR.get(), generateModel(APBlocks.COLONY_INTEGRATOR.get()) - .texture("particle", blockTexture(APBlocks.COLONY_INTEGRATOR.get())) + peripheralBlock(Blocks.ENVIRONMENT_DETECTOR.get(), "front"); + peripheralBlock(Blocks.CHAT_BOX.get(), "front"); + peripheralBlock(Blocks.PLAYER_DETECTOR.get(), "side", "front"); + peripheralBlock(Blocks.ME_BRIDGE.get(), "front"); + peripheralBlock(Blocks.RS_BRIDGE.get(), "front"); + peripheralBlock(Blocks.ENERGY_DETECTOR.get(), "front", "back"); + peripheralBlock(Blocks.PERIPHERAL_CASING.get()); + peripheralBlock(Blocks.INVENTORY_MANAGER.get(), "front"); + peripheralBlock(Blocks.REDSTONE_INTEGRATOR.get(), "front"); + peripheralBlock(Blocks.BLOCK_READER.get(), generateModel(Blocks.BLOCK_READER.get(), false, "north", "south", "east", "west", "up", "down")); + peripheralBlock(Blocks.GEO_SCANNER.get(), "front"); + peripheralBlock(Blocks.COLONY_INTEGRATOR.get(), generateModel(Blocks.COLONY_INTEGRATOR.get()) + .texture("particle", blockTexture(Blocks.COLONY_INTEGRATOR.get())) .texture("up", blockTexture(net.minecraft.world.level.block.Blocks.OAK_LOG, "top")) .texture("down", blockTexture(net.minecraft.world.level.block.Blocks.OAK_LOG, "top"))); - peripheralBlock(APBlocks.NBT_STORAGE.get(), "front"); + peripheralBlock(Blocks.NBT_STORAGE.get(), "front"); } private void peripheralBlock(Block block, ModelFile file) { getVariantBuilder(block).forAllStates(state -> { ConfiguredModel.Builder builder = ConfiguredModel.builder().modelFile(file); FrontAndTop orientation = state.getValue(BaseBlock.ORIENTATION); - int x = 0; - int y; + int x = 0, y; if (orientation.top().getAxis() == Direction.Axis.Y) { y = (int) (orientation.front().toYRot() + 180) % 360; } else { @@ -74,7 +73,7 @@ private BlockModelBuilder generateModel(Block block, boolean hasNormalSide, Stri for (Direction direction : Direction.Plane.HORIZONTAL) builder.texture(direction.toString(), blockTexture(block, sideTexture)); } - if (side.equals("north")) + if(side.equals("north")) particleTexture = blockTexture(block, "north"); if (side.equals("front")) { diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/DataGenerators.java b/src/main/java/de/srendi/advancedperipherals/common/data/DataGenerators.java index b5b92dd20..e1f3f16a3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/DataGenerators.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/DataGenerators.java @@ -1,7 +1,7 @@ package de.srendi.advancedperipherals.common.data; import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.common.setup.APRegistration; +import de.srendi.advancedperipherals.common.setup.Registration; import net.minecraft.data.DataGenerator; import net.minecraftforge.common.data.ExistingFileHelper; import net.minecraftforge.data.event.GatherDataEvent; @@ -19,7 +19,7 @@ public static void genData(GatherDataEvent event) { DataGenerator generator = event.getGenerator(); ExistingFileHelper existingFileHelper = event.getExistingFileHelper(); - generator.addProvider(event.includeServer(), new BlockTagsProvider(generator, existingFileHelper, APRegistration.BLOCKS)); + generator.addProvider(event.includeServer(), new BlockTagsProvider(generator, existingFileHelper, Registration.BLOCKS)); generator.addProvider(event.includeServer(), new RecipesProvider(generator)); generator.addProvider(event.includeServer(), new BlockLootTablesProvider(generator)); generator.addProvider(event.includeServer(), new TurtleUpgradesProvider(generator)); @@ -29,4 +29,5 @@ public static void genData(GatherDataEvent event) { generator.addProvider(event.includeClient(), new EnUsLanguageProvider(generator)); } + } diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java index 2c96363be..22ada0834 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java @@ -2,10 +2,10 @@ import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.client.KeyBindings; -import de.srendi.advancedperipherals.common.setup.APBlocks; -import de.srendi.advancedperipherals.common.setup.APItems; -import de.srendi.advancedperipherals.common.setup.APVillagers; +import de.srendi.advancedperipherals.common.setup.Blocks; import de.srendi.advancedperipherals.common.setup.CCRegistration; +import de.srendi.advancedperipherals.common.setup.Items; +import de.srendi.advancedperipherals.common.setup.Villagers; import net.minecraft.client.KeyMapping; import net.minecraft.data.DataGenerator; import net.minecraft.resources.ResourceLocation; @@ -34,40 +34,37 @@ protected void addTranslations() { addTooltips(); addKeybinds(); addText(); - add(APVillagers.COMPUTER_SCIENTIST, "Computer Scientist"); - add("advancedperipherals.name", "Advanced Peripherals"); - add("curios.identifier.glasses", "Glasses"); + add(Villagers.COMPUTER_SCIENTIST, "Computer Scientist"); + add("advancedperipherals.name", AdvancedPeripherals.NAME); + add("itemGroup.advancedperipheralstab", AdvancedPeripherals.NAME); } private void addItems() { - addItem(APItems.CHUNK_CONTROLLER, "Chunk Controller"); - addItem(APItems.COMPUTER_TOOL, "Computer Tool"); - addItem(APItems.WEAK_AUTOMATA_CORE, "Weak Automata Core"); - addItem(APItems.HUSBANDRY_AUTOMATA_CORE, "Husbandry Automata Core"); - addItem(APItems.END_AUTOMATA_CORE, "End Automata Core"); - addItem(APItems.OVERPOWERED_WEAK_AUTOMATA_CORE, "Overpowered Weak Automata Core"); - addItem(APItems.OVERPOWERED_HUSBANDRY_AUTOMATA_CORE, "Overpowered Husbandry Automata Core"); - addItem(APItems.OVERPOWERED_END_AUTOMATA_CORE, "Overpowered End Automata Core"); - addItem(APItems.MEMORY_CARD, "Memory Card"); - addItem(APItems.SMART_GLASSES, "Smart Glasses"); - addItem(APItems.SMART_GLASSES_NETHERITE, "Netherite reinforced Smart Glasses"); - addItem(APItems.SMART_GLASSES_INTERFACE, "Smart Glasses Interface"); + addItem(Items.CHUNK_CONTROLLER, "Chunk Controller"); + addItem(Items.COMPUTER_TOOL, "Computer Tool"); + addItem(Items.WEAK_AUTOMATA_CORE, "Weak Automata Core"); + addItem(Items.HUSBANDRY_AUTOMATA_CORE, "Husbandry Automata Core"); + addItem(Items.END_AUTOMATA_CORE, "End Automata Core"); + addItem(Items.OVERPOWERED_WEAK_AUTOMATA_CORE, "Overpowered Weak Automata Core"); + addItem(Items.OVERPOWERED_HUSBANDRY_AUTOMATA_CORE, "Overpowered Husbandry Automata Core"); + addItem(Items.OVERPOWERED_END_AUTOMATA_CORE, "Overpowered End Automata Core"); + addItem(Items.MEMORY_CARD, "Memory Card"); } private void addBlocks() { - addBlock(APBlocks.BLOCK_READER, "Block Reader"); - addBlock(APBlocks.CHAT_BOX, "Chat Box"); - addBlock(APBlocks.COLONY_INTEGRATOR, "Colony Integrator"); - addBlock(APBlocks.ENERGY_DETECTOR, "Energy Detector"); - addBlock(APBlocks.ENVIRONMENT_DETECTOR, "Environment Detector"); - addBlock(APBlocks.GEO_SCANNER, "Geo Scanner"); - addBlock(APBlocks.INVENTORY_MANAGER, "Inventory Manager"); - addBlock(APBlocks.ME_BRIDGE, "ME Bridge"); - addBlock(APBlocks.RS_BRIDGE, "RS Bridge"); - addBlock(APBlocks.NBT_STORAGE, "NBT Storage"); - addBlock(APBlocks.PERIPHERAL_CASING, "Peripheral Casing"); - addBlock(APBlocks.PLAYER_DETECTOR, "Player Detector"); - addBlock(APBlocks.REDSTONE_INTEGRATOR, "Redstone Integrator"); + addBlock(Blocks.BLOCK_READER, "Block Reader"); + addBlock(Blocks.CHAT_BOX, "Chat Box"); + addBlock(Blocks.COLONY_INTEGRATOR, "Colony Integrator"); + addBlock(Blocks.ENERGY_DETECTOR, "Energy Detector"); + addBlock(Blocks.ENVIRONMENT_DETECTOR, "Environment Detector"); + addBlock(Blocks.GEO_SCANNER, "Geo Scanner"); + addBlock(Blocks.INVENTORY_MANAGER, "Inventory Manager"); + addBlock(Blocks.ME_BRIDGE, "ME Bridge"); + addBlock(Blocks.RS_BRIDGE, "RS Bridge"); + addBlock(Blocks.NBT_STORAGE, "NBT Storage"); + addBlock(Blocks.PERIPHERAL_CASING, "Peripheral Casing"); + addBlock(Blocks.PLAYER_DETECTOR, "Player Detector"); + addBlock(Blocks.REDSTONE_INTEGRATOR, "Redstone Integrator"); } private void addTurtles() { @@ -106,42 +103,40 @@ private void addAdvancements() { private void addTooltips() { addTooltip("show_desc", "&b[&7%s&b] &7For Description"); - addTooltip("disabled", "&cThis item is disabled in config, so you can craft it, but it'll not have any functionality."); - addTooltip(APItems.COMPUTER_TOOL.get(), "&7This tool was made to tune our blocks. But for now, it's just a blue useless wrench."); - addTooltip(APBlocks.ENERGY_DETECTOR.get(), "&7Can detect energy flow and acts as a resistor."); - addTooltip(APItems.CHUNK_CONTROLLER.get(), "&7A crafting ingredient for the Chunky Turtle."); - addTooltip(APBlocks.ENVIRONMENT_DETECTOR.get(), "&7This peripheral interacts with the minecraft world."); - addTooltip(APBlocks.PLAYER_DETECTOR.get(), "&7This peripheral can be used to interact with players, but don't be a stalker."); - addTooltip(APBlocks.RS_BRIDGE.get(), "&7The RS Bridge interacts with Refined Storage to manage your items."); - addTooltip(APBlocks.ME_BRIDGE.get(), "&7The ME Bridge interacts with Applied Energistics to manage your items."); - addTooltip(APBlocks.CHAT_BOX.get(), "&7Interacts with the ingame chat, can read and write messages."); - addTooltip(APBlocks.PERIPHERAL_CASING.get(), "&7An empty hull without the love it deserves. Used as crafting ingredient"); - addTooltip(APItems.MEMORY_CARD.get(), "&7Can save the rights of a player to use it in an inventory manager."); + addTooltip("disabled", "&cThis item is disabled in the config, so you can craft it, but it'll not have any functionality."); + addTooltip(Items.COMPUTER_TOOL.get(), "&7This tool was made to tune our blocks. But for now, it's just a blue useless wrench."); + addTooltip(Blocks.ENERGY_DETECTOR.get(), "&7Can detect energy flow and acts as a resistor."); + addTooltip(Items.CHUNK_CONTROLLER.get(), "&7A crafting ingredient for the Chunky Turtle."); + addTooltip(Blocks.ENVIRONMENT_DETECTOR.get(), "&7This peripheral interacts with the minecraft world."); + addTooltip(Blocks.PLAYER_DETECTOR.get(), "&7This peripheral can be used to interact with players, but don't be a stalker."); + addTooltip(Blocks.RS_BRIDGE.get(), "&7The RS Bridge interacts with Refined Storage to manage your items."); + addTooltip(Blocks.ME_BRIDGE.get(), "&7The ME Bridge interacts with Applied Energistics to manage your items."); + addTooltip(Blocks.CHAT_BOX.get(), "&7Interacts with the ingame chat, can read and write messages."); + addTooltip(Blocks.PERIPHERAL_CASING.get(), "&7An empty hull without the love it deserves. Used as a crafting ingredient"); + addTooltip(Items.MEMORY_CARD.get(), "&7Can save the rights of a player to use it in an inventory manager."); addTooltip("memory_card.bound", "&7Bound to &b%s&7."); - addTooltip(APBlocks.INVENTORY_MANAGER.get(), "&7This block is able to send or receive specific items from a player inventory."); - addTooltip(APBlocks.REDSTONE_INTEGRATOR.get(), "&7This block is able to interact with redstone. Works exactly like the redstone api of an computer."); - addTooltip(APBlocks.BLOCK_READER.get(), "&7Reads nbt data of blocks to interact with blocks which do not have computer support."); - addTooltip(APBlocks.GEO_SCANNER.get(), "&7Scans the area around it to find some shiny ores."); - addTooltip(APBlocks.COLONY_INTEGRATOR.get(), "&7Interacts with Minecolonies to read data about your colony and citizens."); - addTooltip(APBlocks.NBT_STORAGE.get(), "&7Acts like a storage disk. Can store nbt based data."); - addTooltip(APItems.WEAK_AUTOMATA_CORE.get(), "&7Upgrade for turtles, which makes turtles more useful."); - addTooltip(APItems.OVERPOWERED_WEAK_AUTOMATA_CORE.get(), "&7Improved version of the weak automata core, that provides some overpowered uses! Be careful, the upgrade is very fragile."); - addTooltip(APItems.HUSBANDRY_AUTOMATA_CORE.get(), "&7Upgrade for turtles, that allows basic and advanced interactions with animals."); - addTooltip(APItems.OVERPOWERED_HUSBANDRY_AUTOMATA_CORE.get(), "&7Improved version of the husbandry automata core, that provides some overpowered uses! Be careful, the upgrade is very fragile."); - addTooltip(APItems.END_AUTOMATA_CORE.get(), "&7Upgrade for turtles, that allows basic interaction with the world and teleportation in one dimension."); - addTooltip(APItems.OVERPOWERED_END_AUTOMATA_CORE.get(), "&7Improved version of the end automata core, that provides some overpowered uses! Be careful, the upgrade is very fragile."); + addTooltip(Blocks.INVENTORY_MANAGER.get(), "&7This block is able to send or receive specific items from a player inventory."); + addTooltip(Blocks.REDSTONE_INTEGRATOR.get(), "&7This block is able to interact with redstone. Works exactly like the redstone api of an computer."); + addTooltip(Blocks.BLOCK_READER.get(), "&7Reads nbt data of blocks to interact with blocks which do not have computer support."); + addTooltip(Blocks.GEO_SCANNER.get(), "&7Scans the area around it to find some shiny ores."); + addTooltip(Blocks.COLONY_INTEGRATOR.get(), "&7Interacts with Minecolonies to read data about your colony and citizens."); + addTooltip(Blocks.NBT_STORAGE.get(), "&7Acts like a storage disk. Can store nbt based data."); + addTooltip(Items.WEAK_AUTOMATA_CORE.get(), "&7Upgrade for turtles, which makes turtles more useful."); + addTooltip(Items.OVERPOWERED_WEAK_AUTOMATA_CORE.get(), "&7Improved version of the weak automata core, that provides some overpowered uses! Be careful, the upgrade is very fragile."); + addTooltip(Items.HUSBANDRY_AUTOMATA_CORE.get(), "&7Upgrade for turtles, that allows basic and advanced interactions with animals."); + addTooltip(Items.OVERPOWERED_HUSBANDRY_AUTOMATA_CORE.get(), "&7Improved version of the husbandry automata core, that provides some overpowered uses! Be careful, the upgrade is very fragile."); + addTooltip(Items.END_AUTOMATA_CORE.get(), "&7Upgrade for turtles, that allows basic interaction with the world and teleportation in one dimension."); + addTooltip(Items.OVERPOWERED_END_AUTOMATA_CORE.get(), "&7Improved version of the end automata core, that provides some overpowered uses! Be careful, the upgrade is very fragile."); } private void addText() { add("text." + AdvancedPeripherals.MOD_ID + ".removed_player", "Cleared the memory card"); add("text." + AdvancedPeripherals.MOD_ID + ".added_player", "Added you to the memory card"); add("text." + AdvancedPeripherals.MOD_ID + ".automata_core_feed_by_player", "You're trying to feed an entity to a soul, but your own body refuses to do this. Maybe something more mechanical can do this?"); - add("text." + AdvancedPeripherals.MOD_ID + ".smart_glasses.peripherals", "Peripherals"); - add("text." + AdvancedPeripherals.MOD_ID + ".smart_glasses.modules", "Modules"); } private void addKeybinds() { - add("keybind.advancedperipherals.category", "Advanced Peripherals"); + add("keybind.advancedperipherals.category", AdvancedPeripherals.NAME); addKeybind(KeyBindings.DESCRIPTION_KEYBINDING, "Show Description"); } @@ -151,7 +146,7 @@ private void addAdvancement(@NotNull String advancement, @NotNull String name, @ } private void add(@NotNull Supplier key, @NotNull String name) { - add("entity.minecraft.villager." + AdvancedPeripherals.MOD_ID + "." + key.get().name(), name); + add("entity.minecraft.villager." + AdvancedPeripherals.MOD_ID + "." + key.get().name().split(":")[1], name); } private void addTurtle(@NotNull ResourceLocation key, @NotNull String name) { diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/PocketUpgradesProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/PocketUpgradesProvider.java index 385b75679..bb78f341b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/PocketUpgradesProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/PocketUpgradesProvider.java @@ -2,7 +2,7 @@ import dan200.computercraft.api.pocket.PocketUpgradeDataProvider; import dan200.computercraft.api.pocket.PocketUpgradeSerialiser; -import de.srendi.advancedperipherals.common.setup.APBlocks; +import de.srendi.advancedperipherals.common.setup.Blocks; import de.srendi.advancedperipherals.common.setup.CCRegistration; import net.minecraft.data.DataGenerator; import org.jetbrains.annotations.NotNull; @@ -17,10 +17,10 @@ public PocketUpgradesProvider(DataGenerator output) { @Override protected void addUpgrades(@NotNull Consumer>> addUpgrade) { - simpleWithCustomItem(CCRegistration.ID.CHATTY_POCKET, CCRegistration.CHAT_BOX_POCKET.get(), APBlocks.CHAT_BOX.get().asItem()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.PLAYER_POCKET, CCRegistration.PLAYER_DETECTOR_POCKET.get(), APBlocks.PLAYER_DETECTOR.get().asItem()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.ENVIRONMENT_POCKET, CCRegistration.ENVIRONMENT_POCKET.get(), APBlocks.ENVIRONMENT_DETECTOR.get().asItem()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.GEOSCANNER_POCKET, CCRegistration.GEO_SCANNER_POCKET.get(), APBlocks.GEO_SCANNER.get().asItem()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.COLONY_POCKET, CCRegistration.COLONY_POCKET.get(), APBlocks.COLONY_INTEGRATOR.get().asItem()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.CHATTY_POCKET, CCRegistration.CHAT_BOX_POCKET.get(), Blocks.CHAT_BOX.get().asItem()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.PLAYER_POCKET, CCRegistration.PLAYER_DETECTOR_POCKET.get(), Blocks.PLAYER_DETECTOR.get().asItem()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.ENVIRONMENT_POCKET, CCRegistration.ENVIRONMENT_POCKET.get(), Blocks.ENVIRONMENT_DETECTOR.get().asItem()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.GEOSCANNER_POCKET, CCRegistration.GEO_SCANNER_POCKET.get(), Blocks.GEO_SCANNER.get().asItem()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.COLONY_POCKET, CCRegistration.COLONY_POCKET.get(), Blocks.COLONY_INTEGRATOR.get().asItem()).add(addUpgrade); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/PoiTypeProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/PoiTypeProvider.java index f2f22b7ab..d3ca346a4 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/PoiTypeProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/PoiTypeProvider.java @@ -1,8 +1,7 @@ package de.srendi.advancedperipherals.common.data; import de.srendi.advancedperipherals.AdvancedPeripherals; - -import de.srendi.advancedperipherals.common.setup.APRegistration; +import de.srendi.advancedperipherals.common.setup.Registration; import net.minecraft.data.DataGenerator; import net.minecraft.data.tags.PoiTypeTagsProvider; import net.minecraft.data.tags.TagsProvider; @@ -15,6 +14,7 @@ public class PoiTypeProvider extends PoiTypeTagsProvider { + public PoiTypeProvider(DataGenerator pGenerator, @Nullable ExistingFileHelper existingFileHelper) { super(pGenerator, AdvancedPeripherals.MOD_ID, existingFileHelper); } @@ -22,7 +22,7 @@ public PoiTypeProvider(DataGenerator pGenerator, @Nullable ExistingFileHelper ex @Override protected void addTags() { TagsProvider.TagAppender appender = tag(PoiTypeTags.ACQUIRABLE_JOB_SITE); - APRegistration.POI_TYPES.getEntries().stream().map(RegistryObject::getKey).forEach(appender::add); + Registration.POI_TYPES.getEntries().stream().map(RegistryObject::getKey).forEach(appender::add); } @NotNull diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java index 58321dbd2..d361c3f8a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java @@ -5,8 +5,7 @@ import com.refinedmods.refinedstorage.RSItems; import dan200.computercraft.shared.Registry; import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.common.setup.APBlocks; -import de.srendi.advancedperipherals.common.setup.APItems; +import de.srendi.advancedperipherals.common.setup.Blocks; import de.srendi.advancedperipherals.common.util.RawValue; import net.minecraft.data.DataGenerator; import net.minecraft.data.recipes.*; @@ -29,52 +28,16 @@ public class RecipesProvider extends RecipeProvider implements IConditionBuilder { - private static final Block CASING = APBlocks.PERIPHERAL_CASING.get(); + private static final Block CASING = Blocks.PERIPHERAL_CASING.get(); private static final String HAS_ITEM = "has_item"; - public RecipesProvider(DataGenerator packOutput) { - super(packOutput); + public RecipesProvider(DataGenerator pGenerator) { + super(pGenerator); } @Override protected void buildCraftingRecipes(@NotNull Consumer consumer) { - addShapeless(consumer); - addShaped(consumer); - addSmithing(consumer); - } - - private void addShapeless(@NotNull Consumer consumer) { - ShapelessRecipeBuilder.shapeless(APItems.OVERPOWERED_WEAK_AUTOMATA_CORE.get()) - .requires(APItems.WEAK_AUTOMATA_CORE.get()) - .requires(Items.NETHER_STAR) - .unlockedBy(HAS_ITEM, has(APItems.WEAK_AUTOMATA_CORE.get())) - .save(consumer); - - ShapelessRecipeBuilder.shapeless(APItems.OVERPOWERED_END_AUTOMATA_CORE.get()) - .requires(APItems.END_AUTOMATA_CORE.get()) - .requires(Items.NETHER_STAR) - .unlockedBy(HAS_ITEM, has(APItems.END_AUTOMATA_CORE.get())) - .save(consumer); - - ShapelessRecipeBuilder.shapeless(APItems.OVERPOWERED_HUSBANDRY_AUTOMATA_CORE.get()) - .requires(APItems.HUSBANDRY_AUTOMATA_CORE.get()) - .requires(Items.NETHER_STAR) - .unlockedBy(HAS_ITEM, has(APItems.HUSBANDRY_AUTOMATA_CORE.get())) - .save(consumer); - } - - private void addShaped(@NotNull Consumer consumer) { - /*ShapedRecipeBuilder.shaped(APItems.AR_GOGGLES.get()) - .define('E', Tags.Items.ENDER_PEARLS) - .define('S', Tags.Items.RODS_WOODEN) - .define('G', Tags.Items.GLASS_BLACK) - .pattern("GSG") - .pattern(" E ") - .unlockedBy(HAS_ITEM, has(Items.STICK)) - .save(consumer); - */ - - ShapedRecipeBuilder.shaped(APBlocks.CHAT_BOX.get()) + ShapedRecipeBuilder.shaped(Blocks.CHAT_BOX.get()) .define('P', ItemTags.LOGS) .define('A', CASING) .define('G', Tags.Items.INGOTS_GOLD) @@ -84,7 +47,7 @@ private void addShaped(@NotNull Consumer consumer) { .unlockedBy(HAS_ITEM, has(CASING)) .save(consumer); - ShapedRecipeBuilder.shaped(APItems.CHUNK_CONTROLLER.get()) + ShapedRecipeBuilder.shaped(de.srendi.advancedperipherals.common.setup.Items.CHUNK_CONTROLLER.get()) .define('I', Tags.Items.INGOTS_IRON) .define('R', Tags.Items.DUSTS_REDSTONE) .define('A', Items.ENDER_EYE) @@ -94,7 +57,7 @@ private void addShaped(@NotNull Consumer consumer) { .unlockedBy(HAS_ITEM, has(Items.RESPAWN_ANCHOR)) .save(consumer); - ShapedRecipeBuilder.shaped(APItems.COMPUTER_TOOL.get()) + ShapedRecipeBuilder.shaped(de.srendi.advancedperipherals.common.setup.Items.COMPUTER_TOOL.get()) .define('I', Tags.Items.INGOTS_IRON) .define('B', Items.BLUE_TERRACOTTA) .pattern("I I") @@ -103,7 +66,7 @@ private void addShaped(@NotNull Consumer consumer) { .unlockedBy(HAS_ITEM, has(Items.BLUE_TERRACOTTA)) .save(consumer); - ShapedRecipeBuilder.shaped(APBlocks.ENERGY_DETECTOR.get()) + ShapedRecipeBuilder.shaped(Blocks.ENERGY_DETECTOR.get()) .define('B', Tags.Items.STORAGE_BLOCKS_REDSTONE) .define('R', Items.REDSTONE_TORCH) .define('C', Items.COMPARATOR) @@ -115,7 +78,7 @@ private void addShaped(@NotNull Consumer consumer) { .unlockedBy(HAS_ITEM, has(CASING)) .save(consumer); - ShapedRecipeBuilder.shaped(APBlocks.ENVIRONMENT_DETECTOR.get()) + ShapedRecipeBuilder.shaped(Blocks.ENVIRONMENT_DETECTOR.get()) .define('W', ItemTags.WOOL) .define('S', ItemTags.SAPLINGS) .define('C', Tags.Items.CROPS) @@ -127,7 +90,7 @@ private void addShaped(@NotNull Consumer consumer) { .unlockedBy(HAS_ITEM, has(CASING)) .save(consumer); - ShapedRecipeBuilder.shaped(APBlocks.INVENTORY_MANAGER.get()) + ShapedRecipeBuilder.shaped(Blocks.INVENTORY_MANAGER.get()) .define('I', Tags.Items.INGOTS_IRON) .define('C', Tags.Items.CHESTS) .define('A', CASING) @@ -137,7 +100,7 @@ private void addShaped(@NotNull Consumer consumer) { .unlockedBy(HAS_ITEM, has(CASING)) .save(consumer); - ShapedRecipeBuilder.shaped(APItems.MEMORY_CARD.get()) + ShapedRecipeBuilder.shaped(de.srendi.advancedperipherals.common.setup.Items.MEMORY_CARD.get()) .define('I', Tags.Items.INGOTS_IRON) .define('W', Tags.Items.GLASS_WHITE) .define('O', Items.OBSERVER) @@ -148,7 +111,7 @@ private void addShaped(@NotNull Consumer consumer) { .unlockedBy(HAS_ITEM, has(Items.OBSERVER)) .save(consumer); - ShapedRecipeBuilder.shaped(APBlocks.PERIPHERAL_CASING.get()) + ShapedRecipeBuilder.shaped(Blocks.PERIPHERAL_CASING.get()) .define('I', Tags.Items.INGOTS_IRON) .define('i', Items.IRON_BARS) .define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE) @@ -158,7 +121,7 @@ private void addShaped(@NotNull Consumer consumer) { .unlockedBy(HAS_ITEM, has(Items.REDSTONE_BLOCK)) .save(consumer); - ShapedRecipeBuilder.shaped(APBlocks.PLAYER_DETECTOR.get()) + ShapedRecipeBuilder.shaped(Blocks.PLAYER_DETECTOR.get()) .define('S', Items.SMOOTH_STONE) .define('A', CASING) .define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE) @@ -168,7 +131,7 @@ private void addShaped(@NotNull Consumer consumer) { .unlockedBy(HAS_ITEM, has(CASING)) .save(consumer); - ShapedRecipeBuilder.shaped(APBlocks.REDSTONE_INTEGRATOR.get()) + ShapedRecipeBuilder.shaped(Blocks.REDSTONE_INTEGRATOR.get()) .define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE) .define('A', CASING) .define('C', Items.COMPARATOR) @@ -178,7 +141,7 @@ private void addShaped(@NotNull Consumer consumer) { .unlockedBy(HAS_ITEM, has(CASING)) .save(consumer); - ShapedRecipeBuilder.shaped(APBlocks.BLOCK_READER.get()) + ShapedRecipeBuilder.shaped(Blocks.BLOCK_READER.get()) .define('O', Items.OBSERVER) .define('I', Tags.Items.INGOTS_IRON) .define('M', Registry.ModBlocks.WIRED_MODEM_FULL.get()) @@ -190,7 +153,7 @@ private void addShaped(@NotNull Consumer consumer) { .unlockedBy(HAS_ITEM, has(CASING)) .save(consumer); - ShapedRecipeBuilder.shaped(APBlocks.GEO_SCANNER.get()) + ShapedRecipeBuilder.shaped(Blocks.GEO_SCANNER.get()) .define('O', Items.OBSERVER) .define('D', Tags.Items.GEMS_DIAMOND) .define('C', CASING) @@ -202,7 +165,7 @@ private void addShaped(@NotNull Consumer consumer) { .unlockedBy(HAS_ITEM, has(CASING)) .save(consumer); - ShapedRecipeBuilder.shaped(APBlocks.NBT_STORAGE.get()) + ShapedRecipeBuilder.shaped(Blocks.NBT_STORAGE.get()) .define('C', Tags.Items.CHESTS) .define('A', CASING) .define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE) @@ -218,7 +181,7 @@ private void addShaped(@NotNull Consumer consumer) { modLoaded("minecolonies") ) .addRecipe( - ShapedRecipeBuilder.shaped(APBlocks.COLONY_INTEGRATOR.get()) + ShapedRecipeBuilder.shaped(Blocks.COLONY_INTEGRATOR.get()) .define('O', ItemTags.LOGS) .define('A', CASING) .define('R', Ingredient.fromValues(Stream.of(new RawValue(new ResourceLocation("minecolonies", "blockminecoloniesrack"))))) @@ -233,7 +196,7 @@ private void addShaped(@NotNull Consumer consumer) { modLoaded("ae2") ) .addRecipe( - ShapedRecipeBuilder.shaped(APBlocks.ME_BRIDGE.get()) + ShapedRecipeBuilder.shaped(Blocks.ME_BRIDGE.get()) .define('F', AEBlocks.FLUIX_BLOCK.asItem()) .define('A', CASING) .define('I', AEBlocks.INTERFACE.asItem()) @@ -248,7 +211,7 @@ private void addShaped(@NotNull Consumer consumer) { modLoaded("refinedstorage") ) .addRecipe( - ShapedRecipeBuilder.shaped(APBlocks.RS_BRIDGE.get()) + ShapedRecipeBuilder.shaped(Blocks.RS_BRIDGE.get()) .define('Q', RSItems.QUARTZ_ENRICHED_IRON.get()) .define('A', CASING) .define('I', RSBlocks.INTERFACE.get()) @@ -258,7 +221,7 @@ private void addShaped(@NotNull Consumer consumer) { .unlockedBy(HAS_ITEM, has(CASING))::save ).build(consumer, new ResourceLocation(AdvancedPeripherals.MOD_ID, "rs_bridge")); - ShapedRecipeBuilder.shaped(APItems.WEAK_AUTOMATA_CORE.get()) + ShapedRecipeBuilder.shaped(de.srendi.advancedperipherals.common.setup.Items.WEAK_AUTOMATA_CORE.get()) .define('A', CASING) .define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE) .define('S', Items.SOUL_LANTERN) @@ -270,13 +233,23 @@ private void addShaped(@NotNull Consumer consumer) { .unlockedBy(HAS_ITEM, has(CASING)) .save(consumer); - } + ShapelessRecipeBuilder.shapeless(de.srendi.advancedperipherals.common.setup.Items.OVERPOWERED_WEAK_AUTOMATA_CORE.get()) + .requires(de.srendi.advancedperipherals.common.setup.Items.WEAK_AUTOMATA_CORE.get()) + .requires(Items.NETHER_STAR) + .unlockedBy(HAS_ITEM, has(de.srendi.advancedperipherals.common.setup.Items.WEAK_AUTOMATA_CORE.get())) + .save(consumer); - private void addSmithing(@NotNull Consumer consumer) { - UpgradeRecipeBuilder - .smithing(Ingredient.of(APItems.SMART_GLASSES.get()), Ingredient.of(Items.NETHERITE_INGOT), APItems.SMART_GLASSES_NETHERITE.get()) - .unlocks("has_item", has(Items.NETHERITE_INGOT)) - .save(consumer, new ResourceLocation(AdvancedPeripherals.MOD_ID, "armor/" + APItems.SMART_GLASSES_NETHERITE.getKey().location().getPath())); + ShapelessRecipeBuilder.shapeless(de.srendi.advancedperipherals.common.setup.Items.OVERPOWERED_END_AUTOMATA_CORE.get()) + .requires(de.srendi.advancedperipherals.common.setup.Items.END_AUTOMATA_CORE.get()) + .requires(Items.NETHER_STAR) + .unlockedBy(HAS_ITEM, has(de.srendi.advancedperipherals.common.setup.Items.END_AUTOMATA_CORE.get())) + .save(consumer); + + ShapelessRecipeBuilder.shapeless(de.srendi.advancedperipherals.common.setup.Items.OVERPOWERED_HUSBANDRY_AUTOMATA_CORE.get()) + .requires(de.srendi.advancedperipherals.common.setup.Items.HUSBANDRY_AUTOMATA_CORE.get()) + .requires(Items.NETHER_STAR) + .unlockedBy(HAS_ITEM, has(de.srendi.advancedperipherals.common.setup.Items.HUSBANDRY_AUTOMATA_CORE.get())) + .save(consumer); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/TurtleUpgradesProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/TurtleUpgradesProvider.java index 70ec6c177..4a1ec409a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/TurtleUpgradesProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/TurtleUpgradesProvider.java @@ -2,9 +2,9 @@ import dan200.computercraft.api.turtle.TurtleUpgradeDataProvider; import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser; -import de.srendi.advancedperipherals.common.setup.APBlocks; -import de.srendi.advancedperipherals.common.setup.APItems; +import de.srendi.advancedperipherals.common.setup.Blocks; import de.srendi.advancedperipherals.common.setup.CCRegistration; +import de.srendi.advancedperipherals.common.setup.Items; import net.minecraft.data.DataGenerator; import org.jetbrains.annotations.NotNull; @@ -18,18 +18,18 @@ public TurtleUpgradesProvider(DataGenerator generator) { @Override protected void addUpgrades(@NotNull Consumer>> addUpgrade) { - simpleWithCustomItem(CCRegistration.ID.CHATTY_TURTLE, CCRegistration.CHAT_BOX_TURTLE.get(), APBlocks.CHAT_BOX.get().asItem()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.PLAYER_TURTLE, CCRegistration.PLAYER_DETECTOR_TURTLE.get(), APBlocks.PLAYER_DETECTOR.get().asItem()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.ENVIRONMENT_TURTLE, CCRegistration.ENVIRONMENT_TURTLE.get(), APBlocks.ENVIRONMENT_DETECTOR.get().asItem()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.CHUNKY_TURTLE, CCRegistration.CHUNKY_TURTLE.get(), APItems.CHUNK_CONTROLLER.get()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.GEOSCANNER_TURTLE, CCRegistration.GEO_SCANNER_TURTLE.get(), APBlocks.GEO_SCANNER.get().asItem()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.CHATTY_TURTLE, CCRegistration.CHAT_BOX_TURTLE.get(), Blocks.CHAT_BOX.get().asItem()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.PLAYER_TURTLE, CCRegistration.PLAYER_DETECTOR_TURTLE.get(), Blocks.PLAYER_DETECTOR.get().asItem()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.ENVIRONMENT_TURTLE, CCRegistration.ENVIRONMENT_TURTLE.get(), Blocks.ENVIRONMENT_DETECTOR.get().asItem()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.CHUNKY_TURTLE, CCRegistration.CHUNKY_TURTLE.get(), Items.CHUNK_CONTROLLER.get()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.GEOSCANNER_TURTLE, CCRegistration.GEO_SCANNER_TURTLE.get(), Blocks.GEO_SCANNER.get().asItem()).add(addUpgrade); simpleWithCustomItem(CCRegistration.ID.COMPASS_TURTLE, CCRegistration.COMPASS_TURTLE.get(), net.minecraft.world.item.Items.COMPASS).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.WEAK_AUTOMATA, CCRegistration.WEAK_TURTLE.get(), APItems.WEAK_AUTOMATA_CORE.get()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.END_AUTOMATA, CCRegistration.END_TURTLE.get(), APItems.END_AUTOMATA_CORE.get()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.HUSBANDRY_AUTOMATA, CCRegistration.HUSBANDRY_TURTLE.get(), APItems.HUSBANDRY_AUTOMATA_CORE.get()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.OP_WEAK_AUTOMATA, CCRegistration.OP_WEAK_TURTLE.get(), APItems.OVERPOWERED_WEAK_AUTOMATA_CORE.get()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.OP_END_AUTOMATA, CCRegistration.OP_END_TURTLE.get(), APItems.OVERPOWERED_END_AUTOMATA_CORE.get()).add(addUpgrade); - simpleWithCustomItem(CCRegistration.ID.OP_HUSBANDRY_AUTOMATA, CCRegistration.OP_HUSBANDRY_TURTLE.get(), APItems.OVERPOWERED_HUSBANDRY_AUTOMATA_CORE.get()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.WEAK_AUTOMATA, CCRegistration.WEAK_TURTLE.get(), Items.WEAK_AUTOMATA_CORE.get()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.END_AUTOMATA, CCRegistration.END_TURTLE.get(), Items.END_AUTOMATA_CORE.get()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.HUSBANDRY_AUTOMATA, CCRegistration.HUSBANDRY_TURTLE.get(), Items.HUSBANDRY_AUTOMATA_CORE.get()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.OP_WEAK_AUTOMATA, CCRegistration.OP_WEAK_TURTLE.get(), Items.OVERPOWERED_WEAK_AUTOMATA_CORE.get()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.OP_END_AUTOMATA, CCRegistration.OP_END_TURTLE.get(), Items.OVERPOWERED_END_AUTOMATA_CORE.get()).add(addUpgrade); + simpleWithCustomItem(CCRegistration.ID.OP_HUSBANDRY_AUTOMATA, CCRegistration.OP_HUSBANDRY_TURTLE.get(), Items.OVERPOWERED_HUSBANDRY_AUTOMATA_CORE.get()).add(addUpgrade); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/APBlockItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/APBlockItem.java index fbfc664f9..296852eee 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/APBlockItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/APBlockItem.java @@ -1,21 +1,36 @@ package de.srendi.advancedperipherals.common.items; import de.srendi.advancedperipherals.common.items.base.BaseBlockItem; +import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Block; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.function.Supplier; public class APBlockItem extends BaseBlockItem { + @Nullable + private final ResourceLocation turtleID; + @Nullable + private final ResourceLocation pocketID; private final Supplier enabledSup; - public APBlockItem(Block blockIn, Properties properties, Supplier enabledSup) { + public APBlockItem(Block blockIn, Properties properties, @Nullable ResourceLocation turtleID, @Nullable ResourceLocation pocketID, Supplier enabledSup) { super(blockIn, properties); + this.turtleID = turtleID; + this.pocketID = pocketID; this.enabledSup = enabledSup; } - public APBlockItem(Block blockIn, Supplier enabledSup) { + public APBlockItem(Block blockIn, @Nullable ResourceLocation turtleID, @Nullable ResourceLocation pocketID, Supplier enabledSup) { super(blockIn); + this.turtleID = turtleID; + this.pocketID = pocketID; this.enabledSup = enabledSup; } @@ -24,4 +39,10 @@ public boolean isEnabled() { return enabledSup.get(); } + @Override + public void fillItemCategory(@NotNull CreativeModeTab group, @NotNull NonNullList items) { + super.fillItemCategory(group, items); + if(allowedIn(group)) + ItemUtil.addComputerItemToTab(turtleID, pocketID, items); + } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/APItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/APItem.java index 34ffcbeb5..04f5e9d8f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/APItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/APItem.java @@ -1,20 +1,35 @@ package de.srendi.advancedperipherals.common.items; import de.srendi.advancedperipherals.common.items.base.BaseItem; +import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.function.Supplier; public class APItem extends BaseItem { + @Nullable + private final ResourceLocation turtleID; + @Nullable + private final ResourceLocation pocketID; private final Supplier enabledSup; - public APItem(Properties properties, Supplier enabledSup) { + public APItem(Properties properties, @Nullable ResourceLocation turtleID, @Nullable ResourceLocation pocketID, Supplier enabledSup) { super(properties); + this.turtleID = turtleID; + this.pocketID = pocketID; this.enabledSup = enabledSup; } - public APItem(Supplier enabledSup) { + public APItem(@Nullable ResourceLocation turtleID, @Nullable ResourceLocation pocketID, Supplier enabledSup) { super(); + this.turtleID = turtleID; + this.pocketID = pocketID; this.enabledSup = enabledSup; } @@ -23,4 +38,11 @@ public boolean isEnabled() { return enabledSup.get(); } + @Override + public void fillItemCategory(@NotNull CreativeModeTab group, @NotNull NonNullList items) { + super.fillItemCategory(group, items); + if(allowedIn(group)) + ItemUtil.addComputerItemToTab(turtleID, pocketID, items); + } + } diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesInterfaceItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesInterfaceItem.java deleted file mode 100644 index a030b25e3..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesInterfaceItem.java +++ /dev/null @@ -1,71 +0,0 @@ -package de.srendi.advancedperipherals.common.items; - -import dan200.computercraft.shared.network.container.ComputerContainerData; -import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.common.addons.APAddons; -import de.srendi.advancedperipherals.common.items.base.BaseItem; -import de.srendi.advancedperipherals.common.setup.APItems; -import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesComputer; -import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesMenuProvider; -import net.minecraft.network.chat.Component; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.InteractionResultHolder; -import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.network.NetworkHooks; -import org.jetbrains.annotations.NotNull; - -public class SmartGlassesInterfaceItem extends BaseItem { - - public SmartGlassesInterfaceItem() { - super(new Properties().stacksTo(1)); - } - - @Override - public InteractionResultHolder use(@NotNull Level world, @NotNull Player player, InteractionHand hand) { - if (world.isClientSide) - return new InteractionResultHolder<>(InteractionResult.PASS, player.getItemInHand(hand)); - - ItemStack findGlasses = player.getItemBySlot(EquipmentSlot.HEAD); - - // In case this method gets executed by the smart glasses interface, we need to check if the glasses may be in the - // curio slot or on the head - if (!findGlasses.is(APItems.SMART_GLASSES.get())) { - if (APAddons.curiosLoaded) findGlasses = APAddons.getCurioGlasses(player); - if (!findGlasses.is(APItems.SMART_GLASSES.get())) { - player.displayClientMessage(Component.translatable("item.advancedperipherals.smartglasses.dontwear"), false); - return super.use(world, player, hand); - } - } - - // The constructor of the ComputerContainerData in the lambda wants a final version of this var - ItemStack glasses = findGlasses; - - SmartGlassesItem smartGlasses = (SmartGlassesItem) glasses.getItem(); - - SmartGlassesComputer computer = smartGlasses.getOrCreateComputer((ServerLevel) world, player, player.getInventory(), glasses); - computer.turnOn(); - - LazyOptional itemHandler = glasses.getCapability(ForgeCapabilities.ITEM_HANDLER); - if (!itemHandler.isPresent() || itemHandler.resolve().isEmpty()) { - AdvancedPeripherals.debug("There was an issue with the item handler of the glasses while trying to open the gui"); - return super.use(world, player, hand); - } - NetworkHooks.openScreen((ServerPlayer) player, new SmartGlassesMenuProvider(computer, glasses, itemHandler.resolve().get()), bytes -> new ComputerContainerData(computer, glasses).toBytes(bytes)); - - return super.use(world, player, hand); - } - - @Override - public boolean isEnabled() { - return true; - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java deleted file mode 100644 index 35ac3cbf7..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/items/SmartGlassesItem.java +++ /dev/null @@ -1,304 +0,0 @@ -package de.srendi.advancedperipherals.common.items; - -import com.google.common.base.Objects; -import dan200.computercraft.ComputerCraft; -import dan200.computercraft.api.ComputerCraftAPI; -import dan200.computercraft.api.filesystem.IWritableMount; -import dan200.computercraft.api.media.IMedia; -import dan200.computercraft.core.computer.ComputerSide; -import dan200.computercraft.shared.computer.core.ComputerFamily; -import dan200.computercraft.shared.computer.core.ServerComputerRegistry; -import dan200.computercraft.shared.computer.core.ServerContext; -import dan200.computercraft.shared.computer.items.IComputerItem; -import dan200.computercraft.shared.network.container.ComputerContainerData; -import dan200.computercraft.shared.util.IDAssigner; -import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.common.smartglasses.*; -import de.srendi.advancedperipherals.common.smartglasses.modules.IModule; -import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleItem; -import de.srendi.advancedperipherals.common.smartglasses.modules.ModulePeripheral; -import net.minecraft.ChatFormatting; -import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.chat.Component; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.Container; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResultHolder; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.entity.item.ItemEntity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ArmorItem; -import net.minecraft.world.item.ArmorMaterial; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.TooltipFlag; -import net.minecraft.world.level.Level; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.common.capabilities.ICapabilityProvider; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.server.ServerLifecycleHooks; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -public class SmartGlassesItem extends ArmorItem implements IComputerItem, IMedia { - - private static final String NBT_UPGRADE = "Upgrade"; - private static final String NBT_UPGRADE_INFO = "UpgradeInfo"; - public static final String NBT_LIGHT = "Light"; - public static final String NBT_ON = "On"; - - private static final String NBT_INSTANCE = "InstanceId"; - private static final String NBT_SESSION = "SessionId"; - - public SmartGlassesItem(ArmorMaterial material) { - super(material, EquipmentSlot.HEAD, new Properties().stacksTo(1).tab(AdvancedPeripherals.TAB)); - } - - @Nullable - @Override - public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundTag nbt) { - return new ICapabilityProvider() { - @NotNull - @Override - public LazyOptional getCapability(@NotNull Capability cap, @Nullable Direction side) { - if (cap == ForgeCapabilities.ITEM_HANDLER) - return LazyOptional.of(() -> new SmartGlassesItemHandler(stack, getServerComputer(ServerLifecycleHooks.getCurrentServer(), stack))).cast(); - return LazyOptional.empty(); - } - }; - } - - private boolean tick(ItemStack stack, Level world, Entity entity, SmartGlassesComputer computer) { - computer.setLevel((ServerLevel) world); - - boolean changed = false; - - // Sync ID - int id = computer.getID(); - if (id != getComputerID(stack)) { - changed = true; - setComputerID(stack, id); - } - - // Sync label - String label = computer.getLabel(); - if (!Objects.equal(label, getLabel(stack))) { - changed = true; - setLabel(stack, label); - } - - boolean on = computer.isOn(); - if (on != isMarkedOn(stack)) { - changed = true; - stack.getOrCreateTag().putBoolean(NBT_ON, on); - } - - Entity computerEntity = computer.getEntity(); - if (computerEntity != entity) { - changed = true; - computer.setEntity(entity); - } - - ItemStack computerStack = computer.getStack(); - if (computerStack != stack) { - changed = true; - computer.setStack(stack); - } - - return changed; - } - - @Override - public void inventoryTick(@NotNull ItemStack stack, @NotNull Level world, @NotNull Entity entity, int slotNum, boolean selected) { - LazyOptional itemHandler = stack.getCapability(ForgeCapabilities.ITEM_HANDLER); - if(itemHandler.isPresent()) { - itemHandler.resolve().ifPresent(iItemHandler -> { - for(int slot = 0; slot < iItemHandler.getSlots(); slot++) { - ItemStack itemStack = iItemHandler.getStackInSlot(slot); - if(itemStack.getItem() instanceof IModuleItem iModuleItem) { - SmartGlassesAccess glassesAccess = null; - IModule module = null; - if (!world.isClientSide) { - SmartGlassesComputer computer = getOrCreateComputer((ServerLevel) world, entity, entity instanceof Player player ? player.getInventory() : null, stack); - module = computer.getModules().get(slot); - glassesAccess = computer.getSmartGlassesAccess(); - } - iModuleItem.inventoryTick(itemStack, world, entity, slot, selected, glassesAccess, module); - } - } - }); - } - - if (world.isClientSide) - return; - Container inventory = entity instanceof Player player ? player.getInventory() : null; - SmartGlassesComputer computer = getOrCreateComputer((ServerLevel) world, entity, inventory, stack); - computer.keepAlive(); - - var changed = tick(stack, world, entity, computer); - if (changed && inventory != null) - inventory.setChanged(); - } - - @Override - public boolean onEntityItemUpdate(ItemStack stack, ItemEntity entity) { - if (entity.level.isClientSide || entity.level.getServer() == null) return false; - - SmartGlassesComputer computer = getServerComputer(entity.level.getServer(), stack); - if (computer != null && tick(stack, entity.level, entity, computer)) - entity.setItem(stack.copy()); - return false; - } - - @NotNull - @Override - public InteractionResultHolder use(Level world, Player player, @NotNull InteractionHand hand) { - ItemStack glasses = player.getItemInHand(hand); - - if (!world.isClientSide) { - SmartGlassesComputer computer = getOrCreateComputer((ServerLevel) world, player, player.getInventory(), glasses); - computer.turnOn(); - - LazyOptional itemHandler = glasses.getCapability(ForgeCapabilities.ITEM_HANDLER); - if (!itemHandler.isPresent() || itemHandler.resolve().isEmpty()) { - AdvancedPeripherals.debug("There was an issue with the item handler of the glasses while trying to open the gui"); - return InteractionResultHolder.sidedSuccess(player.getItemInHand(hand), world.isClientSide); - } - new ComputerContainerData(computer, glasses).open(player, new SmartGlassesMenuProvider(computer, glasses, itemHandler.resolve().get())); - } - return super.use(world, player, hand); - } - - public ItemStack create(int id, @Nullable String label) { - ItemStack result = new ItemStack(this); - if (id >= 0) - result.getOrCreateTag().putInt(NBT_ID, id); - if (label != null) - result.setHoverName(Component.literal(label)); - return result; - } - - @Override - public ComputerFamily getFamily() { - return ComputerFamily.ADVANCED; - } - - @Override - public ItemStack withFamily(ItemStack stack, ComputerFamily family) { - return create(getComputerID(stack), getLabel(stack)); - } - - @Override - public void appendHoverText(@NotNull ItemStack stack, @Nullable Level world, @NotNull List list, TooltipFlag flag) { - if (flag.isAdvanced() || getLabel(stack) == null) { - int id = getComputerID(stack); - if (id >= 0) { - list.add(Component.translatable("gui.computercraft.tooltip.computer_id", id).withStyle(ChatFormatting.GRAY)); - } - } - } - - @Override - public String getCreatorModId(ItemStack stack) { - return AdvancedPeripherals.MOD_ID; - } - - public SmartGlassesComputer getOrCreateComputer(ServerLevel level, Entity entity, @Nullable Container inventory, ItemStack stack) { - int sessionID = getSessionID(stack); - - ServerComputerRegistry registry = ServerContext.get(level.getServer()).registry(); - SmartGlassesComputer computer = (SmartGlassesComputer) registry.get(sessionID, getInstanceID(stack)); - if (computer == null) { - int computerID = getComputerID(stack); - if (computerID < 0) { - computerID = ComputerCraftAPI.createUniqueNumberedSaveDir(level, IDAssigner.COMPUTER); - setComputerID(stack, computerID); - } - - computer = new SmartGlassesComputer(level, getComputerID(stack), getLabel(stack), getFamily()); - - setInstanceID(stack, computer.register()); - setSessionID(stack, registry.getSessionID()); - - computer.addAPI(new SmartGlassesAPI()); - - // Only turn on when initially creating the computer, rather than each tick. - if (isMarkedOn(stack) && entity instanceof Player) - computer.turnOn(); - - if (inventory != null) - inventory.setChanged(); - } - computer.setPeripheral(ComputerSide.BACK, new ModulePeripheral(computer)); - computer.setLevel(level); - return computer; - } - - @Nullable - public static SmartGlassesComputer getServerComputer(MinecraftServer server, ItemStack stack) { - if (server == null) - return null; - return (SmartGlassesComputer) ServerContext.get(server).registry().get(getSessionID(stack), getInstanceID(stack)); - } - - // IComputerItem implementation - protected static void setComputerID(ItemStack stack, int computerID) { - stack.getOrCreateTag().putInt(NBT_ID, computerID); - } - - @Nullable - @Override - public String getLabel(ItemStack stack) { - return IComputerItem.super.getLabel(stack); - } - - @Override - public boolean setLabel(ItemStack stack, @Nullable String label) { - if (label != null) { - stack.setHoverName(Component.literal(label)); - } else { - stack.resetHoverName(); - } - return true; - } - - @Nullable - @Override - public IWritableMount createDataMount(@NotNull ItemStack stack, @NotNull Level level) { - int id = getComputerID(stack); - if (id >= 0) { - return ComputerCraftAPI.createSaveDirMount(level, "computer/" + id, ComputerCraft.computerSpaceLimit); - } - return null; - } - - public static int getInstanceID(ItemStack stack) { - CompoundTag nbt = stack.getTag(); - return nbt != null && nbt.contains(NBT_INSTANCE) ? nbt.getInt(NBT_INSTANCE) : -1; - } - - protected static void setInstanceID(ItemStack stack, int instanceID) { - stack.getOrCreateTag().putInt(NBT_INSTANCE, instanceID); - } - - protected static int getSessionID(ItemStack stack) { - CompoundTag nbt = stack.getTag(); - return nbt != null && nbt.contains(NBT_SESSION) ? nbt.getInt(NBT_SESSION) : -1; - } - - protected static void setSessionID(ItemStack stack, int sessionID) { - stack.getOrCreateTag().putInt(NBT_SESSION, sessionID); - } - - protected static boolean isMarkedOn(ItemStack stack) { - CompoundTag nbt = stack.getTag(); - return nbt != null && nbt.getBoolean(NBT_ON); - } - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/WeakAutomataCore.java b/src/main/java/de/srendi/advancedperipherals/common/items/WeakAutomataCore.java index 0dd8b101f..12394d92d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/WeakAutomataCore.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/WeakAutomataCore.java @@ -1,12 +1,12 @@ package de.srendi.advancedperipherals.common.items; import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.items.base.BaseItem; -import de.srendi.advancedperipherals.common.setup.APItems; +import de.srendi.advancedperipherals.common.setup.Items; import de.srendi.advancedperipherals.common.util.EnumColor; import de.srendi.advancedperipherals.lib.metaphysics.IFeedableAutomataCore; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; @@ -27,7 +27,7 @@ import java.util.Map; import java.util.Optional; -public class WeakAutomataCore extends BaseItem implements IFeedableAutomataCore { +public class WeakAutomataCore extends APItem implements IFeedableAutomataCore { private static final String CONSUMED_ENTITY_COUNT = "consumed_entity_count"; private static final String CONSUMED_ENTITY_NAME = "consumed_entity_name"; @@ -37,25 +37,24 @@ public class WeakAutomataCore extends BaseItem implements IFeedableAutomataCore static { Map endSouls = new HashMap<>(); endSouls.put(ForgeRegistries.ENTITY_TYPES.getKey(EntityType.ENDERMAN).toString(), 10); - WeakAutomataCoreRecord endSoulRecord = new WeakAutomataCoreRecord(endSouls, APItems.END_AUTOMATA_CORE.get()); + WeakAutomataCoreRecord endSoulRecord = new WeakAutomataCoreRecord(endSouls, Items.END_AUTOMATA_CORE.get()); Map husbandrySouls = new HashMap<>(); husbandrySouls.put(ForgeRegistries.ENTITY_TYPES.getKey(EntityType.COW).toString(), 3); husbandrySouls.put(ForgeRegistries.ENTITY_TYPES.getKey(EntityType.SHEEP).toString(), 3); husbandrySouls.put(ForgeRegistries.ENTITY_TYPES.getKey(EntityType.CHICKEN).toString(), 3); - WeakAutomataCoreRecord husbandrySoulRecord = new WeakAutomataCoreRecord(husbandrySouls, APItems.HUSBANDRY_AUTOMATA_CORE.get()); + WeakAutomataCoreRecord husbandrySoulRecord = new WeakAutomataCoreRecord(husbandrySouls, Items.HUSBANDRY_AUTOMATA_CORE.get()); endSoulRecord.ingredients.keySet().forEach(entityType -> AUTOMATA_CORE_REGISTRY.put(entityType, endSoulRecord)); husbandrySoulRecord.ingredients.keySet().forEach(entityType -> AUTOMATA_CORE_REGISTRY.put(entityType, husbandrySoulRecord)); } - public WeakAutomataCore(Properties properties) { - super(properties); + public WeakAutomataCore(Properties properties, @Nullable ResourceLocation turtleID, @Nullable ResourceLocation pocketID) { + super(properties, turtleID, pocketID, APConfig.METAPHYSICS_CONFIG.enableWeakAutomataCore); } - @Override - public boolean isEnabled() { - return APConfig.METAPHYSICS_CONFIG.enableWeakAutomataCore.get(); + public WeakAutomataCore(@Nullable ResourceLocation turtleID, @Nullable ResourceLocation pocketID) { + super(turtleID, pocketID, APConfig.METAPHYSICS_CONFIG.enableWeakAutomataCore); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/base/SmartGlassesMaterials.java b/src/main/java/de/srendi/advancedperipherals/common/items/base/SmartGlassesMaterials.java deleted file mode 100644 index 071976e3e..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/items/base/SmartGlassesMaterials.java +++ /dev/null @@ -1,73 +0,0 @@ -package de.srendi.advancedperipherals.common.items.base; - -import de.srendi.advancedperipherals.AdvancedPeripherals; -import net.minecraft.sounds.SoundEvent; -import net.minecraft.sounds.SoundEvents; -import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.item.ArmorMaterial; -import net.minecraft.world.item.Items; -import net.minecraft.world.item.crafting.Ingredient; -import org.jetbrains.annotations.NotNull; - -public enum SmartGlassesMaterials implements ArmorMaterial { - - // We use the same name, so they use the same model texture - CHAIN("smart_glasses", 15, new int[]{1, 4, 5, 2}, 12, SoundEvents.ARMOR_EQUIP_CHAIN, 0.0F, 0.0F, Ingredient.of(Items.IRON_INGOT)), - NETHERITE("smart_glasses", 37, new int[]{3, 6, 8, 3}, 15, SoundEvents.ARMOR_EQUIP_NETHERITE, 3.0F, 0.1F, Ingredient.of(Items.NETHERITE_INGOT)); - - private static final int[] HEALTH_PER_SLOT = new int[]{13, 15, 16, 11}; - private final String name; - private final int durabilityMultiplier; - private final int[] slotProtections; - private final int enchantmentValue; - private final SoundEvent sound; - private final float toughness; - private final float knockbackResistance; - private final Ingredient repairIngredient; - - SmartGlassesMaterials(String pName, int pDurabilityMultiplier, int[] pSlotProtections, int pEnchantmentValue, SoundEvent pSound, float pToughness, float pKnockbackResistance, Ingredient pRepairIngredient) { - this.name = pName; - this.durabilityMultiplier = pDurabilityMultiplier; - this.slotProtections = pSlotProtections; - this.enchantmentValue = pEnchantmentValue; - this.sound = pSound; - this.toughness = pToughness; - this.knockbackResistance = pKnockbackResistance; - this.repairIngredient = pRepairIngredient; - } - - public int getDurabilityForSlot(EquipmentSlot pSlot) { - return HEALTH_PER_SLOT[pSlot.getIndex()] * this.durabilityMultiplier; - } - - public int getDefenseForSlot(EquipmentSlot pSlot) { - return this.slotProtections[pSlot.getIndex()]; - } - - public int getEnchantmentValue() { - return this.enchantmentValue; - } - - @NotNull - public SoundEvent getEquipSound() { - return this.sound; - } - - @NotNull - public Ingredient getRepairIngredient() { - return this.repairIngredient; - } - - @NotNull - public String getName() { - return AdvancedPeripherals.MOD_ID + ":" + this.name; - } - - public float getToughness() { - return this.toughness; - } - - public float getKnockbackResistance() { - return this.knockbackResistance; - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/network/PacketHandler.java b/src/main/java/de/srendi/advancedperipherals/common/network/PacketHandler.java deleted file mode 100644 index 77bbd1fb9..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/network/PacketHandler.java +++ /dev/null @@ -1,75 +0,0 @@ -package de.srendi.advancedperipherals.common.network; - -import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.common.network.base.IPacket; -import de.srendi.advancedperipherals.common.network.toclient.DistanceDetectorSyncPacket; -import de.srendi.advancedperipherals.common.network.toclient.ToastToClientPacket; -import de.srendi.advancedperipherals.common.network.toserver.GlassesHotkeyPacket; -import net.minecraft.core.BlockPos; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.level.ChunkPos; -import net.minecraft.world.level.Level; -import net.minecraftforge.common.util.FakePlayer; -import net.minecraftforge.fml.ModLoadingContext; -import net.minecraftforge.network.NetworkDirection; -import net.minecraftforge.network.NetworkRegistry; -import net.minecraftforge.network.PacketDistributor; -import net.minecraftforge.network.simple.SimpleChannel; -import net.minecraftforge.server.ServerLifecycleHooks; - -import java.util.Optional; -import java.util.function.Function; - -public class PacketHandler { - - private static final String PROTOCOL_VERSION = ModLoadingContext.get().getActiveContainer().getModInfo().getVersion().toString(); - - public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel(new ResourceLocation(AdvancedPeripherals.MOD_ID, "main_channel"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals); - - private static int index = 0; - - public static void init() { - registerServerToClient(DistanceDetectorSyncPacket.class, DistanceDetectorSyncPacket::decode); - registerServerToClient(ToastToClientPacket.class, ToastToClientPacket::decode); - registerClientToServer(GlassesHotkeyPacket.class, GlassesHotkeyPacket::decode); - } - - public static void registerServerToClient(Class packet, Function decode) { - CHANNEL.registerMessage(index++, packet, IPacket::encode, decode, IPacket::handle, Optional.of(NetworkDirection.PLAY_TO_CLIENT)); - } - - public static void registerClientToServer(Class packet, Function decode) { - CHANNEL.registerMessage(index++, packet, IPacket::encode, decode, IPacket::handle, Optional.of(NetworkDirection.PLAY_TO_SERVER)); - } - - public static void sendToClient(Object packet, ServerPlayer player) { - CHANNEL.sendTo(packet, player.connection.getConnection(), NetworkDirection.PLAY_TO_CLIENT); - } - - public static void sendToServer(Object packet) { - CHANNEL.sendToServer(packet); - } - - public static void sendTo(Object packet, ServerPlayer player) { - if (!(player instanceof FakePlayer)) { - CHANNEL.sendTo(packet, player.connection.getConnection(), NetworkDirection.PLAY_TO_CLIENT); - } - } - - public static void sendToAll(Object packet) { - MinecraftServer server = ServerLifecycleHooks.getCurrentServer(); - server.getPlayerList().getPlayers().forEach(player -> sendTo(packet, player)); - } - - public static void sendToAllTracking(Object packet, Level world, BlockPos pos) { - if (world instanceof ServerLevel) { - ((ServerLevel) world).getChunkSource().chunkMap.getPlayers(new ChunkPos(pos), false).forEach(p -> sendTo(packet, p)); - } else { - CHANNEL.send(PacketDistributor.TRACKING_CHUNK.with(() -> world.getChunk(pos.getX() >> 4, pos.getZ() >> 4)), packet); - } - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/network/toclient/DistanceDetectorSyncPacket.java b/src/main/java/de/srendi/advancedperipherals/common/network/toclient/DistanceDetectorSyncPacket.java deleted file mode 100644 index 484ec7520..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/network/toclient/DistanceDetectorSyncPacket.java +++ /dev/null @@ -1,59 +0,0 @@ -package de.srendi.advancedperipherals.common.network.toclient; - -import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.common.blocks.blockentities.DistanceDetectorEntity; -import de.srendi.advancedperipherals.common.network.base.IPacket; -import net.minecraft.client.Minecraft; -import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Registry; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceKey; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraftforge.network.NetworkEvent; - -public class DistanceDetectorSyncPacket implements IPacket { - - private final BlockPos position; - private final ResourceKey world; - private final float distance; - private final boolean showLaser; - - public DistanceDetectorSyncPacket(BlockPos position, ResourceKey world, float distance, boolean showLaser) { - this.position = position; - this.world = world; - this.distance = distance; - this.showLaser = showLaser; - } - - @Override - public void handle(NetworkEvent.Context context) { - ClientLevel level = Minecraft.getInstance().level; - if (!level.dimension().equals(world)) - return; - - BlockEntity tileEntity = level.getBlockEntity(position); - if (tileEntity == null) { - AdvancedPeripherals.debug("Could not update distance detector at " + position + " in world " + world.location() - + " because the world or the tile entity couldn't be found. Ignoring it"); - return; - } - if (tileEntity instanceof DistanceDetectorEntity detector) { - detector.setCurrentDistance(distance); - detector.setShowLaser(showLaser); - } - } - - @Override - public void encode(FriendlyByteBuf buffer) { - buffer.writeBlockPos(position); - buffer.writeResourceKey(world); - buffer.writeFloat(distance); - buffer.writeBoolean(showLaser); - } - - public static DistanceDetectorSyncPacket decode(FriendlyByteBuf buffer) { - return new DistanceDetectorSyncPacket(buffer.readBlockPos(), buffer.readResourceKey(Registry.DIMENSION_REGISTRY), buffer.readFloat(), buffer.readBoolean()); - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/network/toserver/GlassesHotkeyPacket.java b/src/main/java/de/srendi/advancedperipherals/common/network/toserver/GlassesHotkeyPacket.java deleted file mode 100644 index c6f5506ed..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/network/toserver/GlassesHotkeyPacket.java +++ /dev/null @@ -1,55 +0,0 @@ -package de.srendi.advancedperipherals.common.network.toserver; - -import de.srendi.advancedperipherals.common.items.SmartGlassesItem; -import de.srendi.advancedperipherals.common.network.base.IPacket; -import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesComputer; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.item.ItemStack; -import net.minecraftforge.network.NetworkEvent; -import net.minecraftforge.server.ServerLifecycleHooks; - -import java.util.UUID; - -public class GlassesHotkeyPacket implements IPacket { - - private final UUID player; - private final String keyBind; - private final int keyPressDuration; - - public GlassesHotkeyPacket(UUID player, String keyBind, int keyPressDuration) { - this.player = player; - this.keyBind = keyBind; - this.keyPressDuration = keyPressDuration; - } - - @Override - public void handle(NetworkEvent.Context context) { - MinecraftServer server = ServerLifecycleHooks.getCurrentServer(); - - ServerPlayer serverPlayer = server.getPlayerList().getPlayer(player); - if (serverPlayer == null) - return; - - for (ItemStack stack : serverPlayer.getAllSlots()) { - if (stack.getItem() instanceof SmartGlassesItem) { - SmartGlassesComputer computer = SmartGlassesItem.getServerComputer(server, stack); - - if (computer != null) - computer.queueEvent("glassesKeyPressed", new Object[]{keyBind, keyPressDuration}); - } - } - } - - @Override - public void encode(FriendlyByteBuf buffer) { - buffer.writeUUID(player); - buffer.writeUtf(keyBind); - buffer.writeInt(keyPressDuration); - } - - public static GlassesHotkeyPacket decode(FriendlyByteBuf buffer) { - return new GlassesHotkeyPacket(buffer.readUUID(), buffer.readUtf(), buffer.readInt()); - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java deleted file mode 100644 index ab760488c..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlockEntityTypes.java +++ /dev/null @@ -1,30 +0,0 @@ -package de.srendi.advancedperipherals.common.setup; - -import com.google.common.collect.Sets; -import de.srendi.advancedperipherals.common.addons.APAddons; -import de.srendi.advancedperipherals.common.blocks.blockentities.*; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraftforge.registries.RegistryObject; - -public class APBlockEntityTypes { - - protected static void register() { - } - - public static final RegistryObject> CHAT_BOX = APRegistration.TILE_ENTITIES.register("chat_box", () -> new BlockEntityType<>(ChatBoxEntity::new, Sets.newHashSet(APBlocks.CHAT_BOX.get()), null)); - public static final RegistryObject> ENVIRONMENT_DETECTOR = APRegistration.TILE_ENTITIES.register("environment_detector", () -> new BlockEntityType<>(EnvironmentDetectorEntity::new, Sets.newHashSet(APBlocks.ENVIRONMENT_DETECTOR.get()), null)); - public static final RegistryObject> PLAYER_DETECTOR = APRegistration.TILE_ENTITIES.register("player_detector", () -> new BlockEntityType<>(PlayerDetectorEntity::new, Sets.newHashSet(APBlocks.PLAYER_DETECTOR.get()), null)); - public static final RegistryObject> ME_BRIDGE = APAddons.appliedEnergisticsLoaded ? APRegistration.TILE_ENTITIES.register("me_bridge", () -> new BlockEntityType<>(MeBridgeEntity::new, Sets.newHashSet(APBlocks.ME_BRIDGE.get()), null)) : null; - public static final RegistryObject> RS_BRIDGE = APAddons.refinedStorageLoaded ? APRegistration.TILE_ENTITIES.register("rs_bridge", () -> new BlockEntityType<>(RsBridgeEntity::new, Sets.newHashSet(APBlocks.RS_BRIDGE.get()), null)) : null; - public static final RegistryObject> ENERGY_DETECTOR = APRegistration.TILE_ENTITIES.register("energy_detector", () -> new BlockEntityType<>(EnergyDetectorEntity::new, Sets.newHashSet(APBlocks.ENERGY_DETECTOR.get()), null)); - public static final RegistryObject> FLUID_DETECTOR = APRegistration.TILE_ENTITIES.register("fluid_detector", () -> new BlockEntityType<>(FluidDetectorEntity::new, Sets.newHashSet(APBlocks.FLUID_DETECTOR.get()), null)); - public static final RegistryObject> GAS_DETECTOR = APAddons.mekanismLoaded ? APRegistration.TILE_ENTITIES.register("gas_detector", () -> new BlockEntityType<>(GasDetectorEntity::new, Sets.newHashSet(APBlocks.GAS_DETECTOR.get()), null)) : null; - public static final RegistryObject> INVENTORY_MANAGER = APRegistration.TILE_ENTITIES.register("inventory_manager", () -> new BlockEntityType<>(InventoryManagerEntity::new, Sets.newHashSet(APBlocks.INVENTORY_MANAGER.get()), null)); - public static final RegistryObject> REDSTONE_INTEGRATOR = APRegistration.TILE_ENTITIES.register("redstone_integrator", () -> new BlockEntityType<>(RedstoneIntegratorEntity::new, Sets.newHashSet(APBlocks.REDSTONE_INTEGRATOR.get()), null)); - public static final RegistryObject> BLOCK_READER = APRegistration.TILE_ENTITIES.register("block_reader", () -> new BlockEntityType<>(BlockReaderEntity::new, Sets.newHashSet(APBlocks.BLOCK_READER.get()), null)); - public static final RegistryObject> GEO_SCANNER = APRegistration.TILE_ENTITIES.register("geo_scanner", () -> new BlockEntityType<>(GeoScannerEntity::new, Sets.newHashSet(APBlocks.GEO_SCANNER.get()), null)); - public static final RegistryObject> COLONY_INTEGRATOR = APRegistration.TILE_ENTITIES.register("colony_integrator", () -> new BlockEntityType<>(ColonyIntegratorEntity::new, Sets.newHashSet(APBlocks.COLONY_INTEGRATOR.get()), null)); - public static final RegistryObject> NBT_STORAGE = APRegistration.TILE_ENTITIES.register("nbt_storage", () -> new BlockEntityType<>(NBTStorageEntity::new, Sets.newHashSet(APBlocks.NBT_STORAGE.get()), null)); - public static final RegistryObject> DISTANCE_DETECTOR = APRegistration.TILE_ENTITIES.register("distance_detector", () -> new BlockEntityType<>(DistanceDetectorEntity::new, Sets.newHashSet(APBlocks.DISTANCE_DETECTOR.get()), null)); - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java deleted file mode 100644 index aab4cdd0b..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APBlocks.java +++ /dev/null @@ -1,58 +0,0 @@ -package de.srendi.advancedperipherals.common.setup; - -import de.srendi.advancedperipherals.common.blocks.PlayerDetectorBlock; -import de.srendi.advancedperipherals.common.blocks.RedstoneIntegratorBlock; -import de.srendi.advancedperipherals.common.blocks.base.APBlockEntityBlock; -import de.srendi.advancedperipherals.common.blocks.base.BaseBlock; -import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.items.APBlockItem; -import net.minecraft.core.BlockPos; -import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.Item; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockBehaviour; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Material; -import net.minecraftforge.fml.ModList; -import net.minecraftforge.registries.RegistryObject; - -import java.util.function.Supplier; - -public class APBlocks { - - protected static void register() { - } - - public static final RegistryObject ENVIRONMENT_DETECTOR = register("environment_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.ENVIRONMENT_DETECTOR, false), () -> new APBlockItem(APBlocks.ENVIRONMENT_DETECTOR.get(), APConfig.PERIPHERALS_CONFIG.enableEnvironmentDetector)); - public static final RegistryObject CHAT_BOX = register("chat_box", () -> new APBlockEntityBlock<>(APBlockEntityTypes.CHAT_BOX, true), () -> new APBlockItem(APBlocks.CHAT_BOX.get(), APConfig.PERIPHERALS_CONFIG.enableChatBox)); - public static final RegistryObject PLAYER_DETECTOR = register("player_detector", PlayerDetectorBlock::new, () -> new APBlockItem(APBlocks.PLAYER_DETECTOR.get(), APConfig.PERIPHERALS_CONFIG.enablePlayerDetector)); - public static final RegistryObject ME_BRIDGE = register("me_bridge", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("ae2") ? APBlockEntityTypes.ME_BRIDGE : null, ModList.get().isLoaded("ae2")), () -> new APBlockItem(APBlocks.ME_BRIDGE.get(), APConfig.PERIPHERALS_CONFIG.enableMEBridge)); - public static final RegistryObject RS_BRIDGE = register("rs_bridge", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("refinedstorage") ? APBlockEntityTypes.RS_BRIDGE : null, false), () -> new APBlockItem(APBlocks.RS_BRIDGE.get(), APConfig.PERIPHERALS_CONFIG.enableRSBridge)); - public static final RegistryObject ENERGY_DETECTOR = register("energy_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.ENERGY_DETECTOR, true), () -> new APBlockItem(APBlocks.ENERGY_DETECTOR.get(), APConfig.PERIPHERALS_CONFIG.enableEnergyDetector)); - public static final RegistryObject FLUID_DETECTOR = register("fluid_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.FLUID_DETECTOR, true), () -> new APBlockItem(APBlocks.FLUID_DETECTOR.get(), APConfig.PERIPHERALS_CONFIG.enableFluidDetector)); - public static final RegistryObject GAS_DETECTOR = register("gas_detector", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("mekanism") ? APBlockEntityTypes.GAS_DETECTOR : null, true), () -> new APBlockItem(APBlocks.GAS_DETECTOR.get(), APConfig.PERIPHERALS_CONFIG.enableGasDetector)); - public static final RegistryObject PERIPHERAL_CASING = register("peripheral_casing", BaseBlock::new, () -> new APBlockItem(APBlocks.PERIPHERAL_CASING.get(), new Item.Properties().stacksTo(16), () -> true)); - public static final RegistryObject INVENTORY_MANAGER = register("inventory_manager", () -> new APBlockEntityBlock<>(APBlockEntityTypes.INVENTORY_MANAGER, false), () -> new APBlockItem(APBlocks.INVENTORY_MANAGER.get(), APConfig.PERIPHERALS_CONFIG.enableInventoryManager)); - public static final RegistryObject REDSTONE_INTEGRATOR = register("redstone_integrator", RedstoneIntegratorBlock::new, () -> new APBlockItem(APBlocks.REDSTONE_INTEGRATOR.get(), APConfig.PERIPHERALS_CONFIG.enableRedstoneIntegrator)); - public static final RegistryObject BLOCK_READER = register("block_reader", () -> new APBlockEntityBlock<>(APBlockEntityTypes.BLOCK_READER, true), () -> new APBlockItem(APBlocks.BLOCK_READER.get(), APConfig.PERIPHERALS_CONFIG.enableBlockReader)); - public static final RegistryObject GEO_SCANNER = register("geo_scanner", () -> new APBlockEntityBlock<>(APBlockEntityTypes.GEO_SCANNER, false), () -> new APBlockItem(APBlocks.GEO_SCANNER.get(), APConfig.PERIPHERALS_CONFIG.enableGeoScanner)); - public static final RegistryObject COLONY_INTEGRATOR = register("colony_integrator", () -> new APBlockEntityBlock<>(APBlockEntityTypes.COLONY_INTEGRATOR, false), () -> new APBlockItem(APBlocks.COLONY_INTEGRATOR.get(), APConfig.PERIPHERALS_CONFIG.enableColonyIntegrator)); - public static final RegistryObject NBT_STORAGE = register("nbt_storage", () -> new APBlockEntityBlock<>(APBlockEntityTypes.NBT_STORAGE, false), () -> new APBlockItem(APBlocks.NBT_STORAGE.get(), APConfig.PERIPHERALS_CONFIG.enableNBTStorage)); - public static final RegistryObject DISTANCE_DETECTOR = register("distance_detector", () -> new APBlockEntityBlock<>(APBlockEntityTypes.DISTANCE_DETECTOR, BlockBehaviour.Properties.of(Material.METAL).noOcclusion(), true), () -> new APBlockItem(APBlocks.DISTANCE_DETECTOR.get(), APConfig.PERIPHERALS_CONFIG.enableNBTStorage)); - - private static RegistryObject registerNoItem(String name, Supplier block) { - return APRegistration.BLOCKS.register(name, block); - } - - private static RegistryObject register(String name, Supplier block, Supplier blockItem) { - RegistryObject registryObject = registerNoItem(name, block); - APRegistration.ITEMS.register(name, blockItem); - return registryObject; - } - - public static boolean never(BlockState state, BlockGetter level, BlockPos pos) { - return false; - } - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java deleted file mode 100644 index b51d363b3..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java +++ /dev/null @@ -1,28 +0,0 @@ -package de.srendi.advancedperipherals.common.setup; - -import dan200.computercraft.shared.network.container.ComputerContainerData; -import dan200.computercraft.shared.network.container.ContainerData; -import de.srendi.advancedperipherals.common.container.InventoryManagerContainer; -import de.srendi.advancedperipherals.common.container.SmartGlassesContainer; -import net.minecraft.core.BlockPos; -import net.minecraft.world.inventory.MenuType; -import net.minecraft.world.level.Level; -import net.minecraftforge.common.extensions.IForgeMenuType; -import net.minecraftforge.registries.RegistryObject; - -public class APContainerTypes { - - public static final RegistryObject> INVENTORY_MANAGER_CONTAINER = APRegistration.CONTAINER_TYPES.register("memory_card_container", () -> IForgeMenuType.create((windowId, inv, data) -> { - BlockPos pos = data.readBlockPos(); - Level level = inv.player.getCommandSenderWorld(); - return new InventoryManagerContainer(windowId, inv, pos, level); - })); - - public static final RegistryObject> SMART_GLASSES_CONTAINER = APRegistration.CONTAINER_TYPES.register("smart_glasses_container", () -> ContainerData.toType(ComputerContainerData::new, - (id, inv, data) -> new SmartGlassesContainer(id, player -> true, null, data, inv, data.displayStack()) - )); - - protected static void register() { - } - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java deleted file mode 100644 index 985a406f8..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java +++ /dev/null @@ -1,33 +0,0 @@ -package de.srendi.advancedperipherals.common.setup; - -import de.srendi.advancedperipherals.common.configuration.APConfig; -import de.srendi.advancedperipherals.common.items.*; -import de.srendi.advancedperipherals.common.items.base.SmartGlassesMaterials; -import de.srendi.advancedperipherals.common.smartglasses.modules.hotkey.HotkeyModuleItem; -import de.srendi.advancedperipherals.common.smartglasses.modules.nightvision.NightVisionModuleItem; -import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.OverlayGlassesItem; -import net.minecraft.world.item.Item; -import net.minecraftforge.registries.RegistryObject; - -public class APItems { - - public static final RegistryObject CHUNK_CONTROLLER = APRegistration.ITEMS.register("chunk_controller", () -> new APItem(new Item.Properties().stacksTo(16), APConfig.PERIPHERALS_CONFIG.enableChunkyTurtle)); - public static final RegistryObject SMART_GLASSES = APRegistration.ITEMS.register("smart_glasses", () -> new SmartGlassesItem(SmartGlassesMaterials.CHAIN)); - public static final RegistryObject SMART_GLASSES_NETHERITE = APRegistration.ITEMS.register("smart_glasses_netherite", () -> new SmartGlassesItem(SmartGlassesMaterials.NETHERITE)); - public static final RegistryObject SMART_GLASSES_INTERFACE = APRegistration.ITEMS.register("smart_glasses_interface", SmartGlassesInterfaceItem::new); - public static final RegistryObject OVERLAY_GLASSES = APRegistration.ITEMS.register("overlayglasses", OverlayGlassesItem::new); - public static final RegistryObject HOTKEY_MODULE = APRegistration.ITEMS.register("hotkeymodule", HotkeyModuleItem::new); - public static final RegistryObject NIGHT_VISION_MODULE = APRegistration.ITEMS.register("nightvisionmodule", NightVisionModuleItem::new); - public static final RegistryObject COMPUTER_TOOL = APRegistration.ITEMS.register("computer_tool", () -> new APItem(new Item.Properties().stacksTo(1), () -> true)); - public static final RegistryObject MEMORY_CARD = APRegistration.ITEMS.register("memory_card", MemoryCardItem::new); - public static final RegistryObject END_AUTOMATA_CORE = APRegistration.ITEMS.register("end_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableEndAutomataCore)); - public static final RegistryObject HUSBANDRY_AUTOMATA_CORE = APRegistration.ITEMS.register("husbandry_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableHusbandryAutomataCore)); - public static final RegistryObject WEAK_AUTOMATA_CORE = APRegistration.ITEMS.register("weak_automata_core", () -> new WeakAutomataCore(new Item.Properties().stacksTo(1))); - public static final RegistryObject OVERPOWERED_WEAK_AUTOMATA_CORE = APRegistration.ITEMS.register("overpowered_weak_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableWeakAutomataCore)); - public static final RegistryObject OVERPOWERED_END_AUTOMATA_CORE = APRegistration.ITEMS.register("overpowered_end_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableEndAutomataCore)); - public static final RegistryObject OVERPOWERED_HUSBANDRY_AUTOMATA_CORE = APRegistration.ITEMS.register("overpowered_husbandry_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableHusbandryAutomataCore)); - - protected static void register() { - } - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APVillagers.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APVillagers.java deleted file mode 100644 index a91c83f7a..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APVillagers.java +++ /dev/null @@ -1,20 +0,0 @@ -package de.srendi.advancedperipherals.common.setup; - -import com.google.common.collect.ImmutableSet; -import dan200.computercraft.shared.Registry; -import de.srendi.advancedperipherals.AdvancedPeripherals; -import net.minecraft.sounds.SoundEvents; -import net.minecraft.world.entity.ai.village.poi.PoiType; -import net.minecraft.world.entity.npc.VillagerProfession; -import net.minecraftforge.registries.RegistryObject; - -public class APVillagers { - - public static final RegistryObject COMPUTER_SCIENTIST_POI = APRegistration.POI_TYPES.register("computer_scientist", () -> new PoiType(ImmutableSet.copyOf(Registry.ModBlocks.COMPUTER_ADVANCED.get().getStateDefinition().getPossibleStates()), 1, 1)); - - public static final RegistryObject COMPUTER_SCIENTIST = APRegistration.VILLAGER_PROFESSIONS.register("computer_scientist", () -> new VillagerProfession(AdvancedPeripherals.MOD_ID + ":computer_scientist", holder -> holder.is(COMPUTER_SCIENTIST_POI.getKey()), holder -> holder.is(COMPUTER_SCIENTIST_POI.getKey()), ImmutableSet.of(), ImmutableSet.of(Registry.ModBlocks.COMPUTER_ADVANCED.get()), SoundEvents.VILLAGER_WORK_TOOLSMITH)); - - protected static void register() { - } - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/BlockEntityTypes.java b/src/main/java/de/srendi/advancedperipherals/common/setup/BlockEntityTypes.java new file mode 100644 index 000000000..e215232e2 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/BlockEntityTypes.java @@ -0,0 +1,27 @@ +package de.srendi.advancedperipherals.common.setup; + +import com.google.common.collect.Sets; +import de.srendi.advancedperipherals.common.blocks.blockentities.*; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraftforge.fml.ModList; +import net.minecraftforge.registries.RegistryObject; + +public class BlockEntityTypes { + + public static final RegistryObject> CHAT_BOX = Registration.TILE_ENTITIES.register("chat_box", () -> new BlockEntityType<>(ChatBoxEntity::new, Sets.newHashSet(Blocks.CHAT_BOX.get()), null)); + public static final RegistryObject> ENVIRONMENT_DETECTOR = Registration.TILE_ENTITIES.register("environment_detector", () -> new BlockEntityType<>(EnvironmentDetectorEntity::new, Sets.newHashSet(Blocks.ENVIRONMENT_DETECTOR.get()), null)); + public static final RegistryObject> PLAYER_DETECTOR = Registration.TILE_ENTITIES.register("player_detector", () -> new BlockEntityType<>(PlayerDetectorEntity::new, Sets.newHashSet(Blocks.PLAYER_DETECTOR.get()), null)); + public static final RegistryObject> ME_BRIDGE = ModList.get().isLoaded("ae2") ? Registration.TILE_ENTITIES.register("me_bridge", () -> new BlockEntityType<>(MeBridgeEntity::new, Sets.newHashSet(Blocks.ME_BRIDGE.get()), null)) : null; + public static final RegistryObject> RS_BRIDGE = ModList.get().isLoaded("refinedstorage") ? Registration.TILE_ENTITIES.register("rs_bridge", () -> new BlockEntityType<>(RsBridgeEntity::new, Sets.newHashSet(Blocks.RS_BRIDGE.get()), null)) : null; + public static final RegistryObject> ENERGY_DETECTOR = Registration.TILE_ENTITIES.register("energy_detector", () -> new BlockEntityType<>(EnergyDetectorEntity::new, Sets.newHashSet(Blocks.ENERGY_DETECTOR.get()), null)); + public static final RegistryObject> INVENTORY_MANAGER = Registration.TILE_ENTITIES.register("inventory_manager", () -> new BlockEntityType<>(InventoryManagerEntity::new, Sets.newHashSet(Blocks.INVENTORY_MANAGER.get()), null)); + public static final RegistryObject> REDSTONE_INTEGRATOR = Registration.TILE_ENTITIES.register("redstone_integrator", () -> new BlockEntityType<>(RedstoneIntegratorEntity::new, Sets.newHashSet(Blocks.REDSTONE_INTEGRATOR.get()), null)); + public static final RegistryObject> BLOCK_READER = Registration.TILE_ENTITIES.register("block_reader", () -> new BlockEntityType<>(BlockReaderEntity::new, Sets.newHashSet(Blocks.BLOCK_READER.get()), null)); + public static final RegistryObject> GEO_SCANNER = Registration.TILE_ENTITIES.register("geo_scanner", () -> new BlockEntityType<>(GeoScannerEntity::new, Sets.newHashSet(Blocks.GEO_SCANNER.get()), null)); + public static final RegistryObject> COLONY_INTEGRATOR = Registration.TILE_ENTITIES.register("colony_integrator", () -> new BlockEntityType<>(ColonyIntegratorEntity::new, Sets.newHashSet(Blocks.COLONY_INTEGRATOR.get()), null)); + public static final RegistryObject> NBT_STORAGE = Registration.TILE_ENTITIES.register("nbt_storage", () -> new BlockEntityType<>(NBTStorageEntity::new, Sets.newHashSet(Blocks.NBT_STORAGE.get()), null)); + + public static void register() { + } + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/Blocks.java b/src/main/java/de/srendi/advancedperipherals/common/setup/Blocks.java new file mode 100644 index 000000000..238c2d939 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/Blocks.java @@ -0,0 +1,53 @@ +package de.srendi.advancedperipherals.common.setup; + +import de.srendi.advancedperipherals.common.blocks.PlayerDetectorBlock; +import de.srendi.advancedperipherals.common.blocks.RedstoneIntegratorBlock; +import de.srendi.advancedperipherals.common.blocks.base.APBlockEntityBlock; +import de.srendi.advancedperipherals.common.blocks.base.BaseBlock; +import de.srendi.advancedperipherals.common.configuration.APConfig; +import de.srendi.advancedperipherals.common.items.APBlockItem; +import net.minecraft.core.BlockPos; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.fml.ModList; +import net.minecraftforge.registries.RegistryObject; + +import java.util.function.Supplier; + +public class Blocks { + + public static final RegistryObject ENVIRONMENT_DETECTOR = register("environment_detector", () -> new APBlockEntityBlock<>(BlockEntityTypes.ENVIRONMENT_DETECTOR, false), () -> new APBlockItem(Blocks.ENVIRONMENT_DETECTOR.get(), CCRegistration.ID.ENVIRONMENT_TURTLE, CCRegistration.ID.ENVIRONMENT_POCKET, APConfig.PERIPHERALS_CONFIG.enableEnvironmentDetector::get)); + public static final RegistryObject CHAT_BOX = register("chat_box", () -> new APBlockEntityBlock<>(BlockEntityTypes.CHAT_BOX, true), () -> new APBlockItem(Blocks.CHAT_BOX.get(), CCRegistration.ID.CHATTY_TURTLE, CCRegistration.ID.CHATTY_POCKET, APConfig.PERIPHERALS_CONFIG.enableChatBox::get)); + public static final RegistryObject PLAYER_DETECTOR = register("player_detector", PlayerDetectorBlock::new, () -> new APBlockItem(Blocks.PLAYER_DETECTOR.get(), CCRegistration.ID.PLAYER_TURTLE, CCRegistration.ID.PLAYER_POCKET, APConfig.PERIPHERALS_CONFIG.enablePlayerDetector::get)); + public static final RegistryObject ME_BRIDGE = register("me_bridge", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("ae2") ? BlockEntityTypes.ME_BRIDGE : null, ModList.get().isLoaded("ae2")), () -> new APBlockItem(Blocks.ME_BRIDGE.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableMEBridge::get)); + public static final RegistryObject RS_BRIDGE = register("rs_bridge", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("refinedstorage") ? BlockEntityTypes.RS_BRIDGE : null, false), () -> new APBlockItem(Blocks.RS_BRIDGE.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableRSBridge::get)); + public static final RegistryObject ENERGY_DETECTOR = register("energy_detector", () -> new APBlockEntityBlock<>(BlockEntityTypes.ENERGY_DETECTOR, true), () -> new APBlockItem(Blocks.ENERGY_DETECTOR.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableEnergyDetector::get)); + public static final RegistryObject PERIPHERAL_CASING = register("peripheral_casing", BaseBlock::new, () -> new APBlockItem(Blocks.PERIPHERAL_CASING.get(), new Item.Properties().stacksTo(16), null, null, () -> true)); + public static final RegistryObject INVENTORY_MANAGER = register("inventory_manager", () -> new APBlockEntityBlock<>(BlockEntityTypes.INVENTORY_MANAGER, false), () -> new APBlockItem(Blocks.INVENTORY_MANAGER.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableInventoryManager::get)); + public static final RegistryObject REDSTONE_INTEGRATOR = register("redstone_integrator", RedstoneIntegratorBlock::new, () -> new APBlockItem(Blocks.REDSTONE_INTEGRATOR.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableRedstoneIntegrator::get)); + public static final RegistryObject BLOCK_READER = register("block_reader", () -> new APBlockEntityBlock<>(BlockEntityTypes.BLOCK_READER, true), () -> new APBlockItem(Blocks.BLOCK_READER.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableBlockReader::get)); + public static final RegistryObject GEO_SCANNER = register("geo_scanner", () -> new APBlockEntityBlock<>(BlockEntityTypes.GEO_SCANNER, false), () -> new APBlockItem(Blocks.GEO_SCANNER.get(), CCRegistration.ID.GEOSCANNER_TURTLE, CCRegistration.ID.GEOSCANNER_POCKET, APConfig.PERIPHERALS_CONFIG.enableGeoScanner::get)); + public static final RegistryObject COLONY_INTEGRATOR = register("colony_integrator", () -> new APBlockEntityBlock<>(ModList.get().isLoaded("minecolonies") ? BlockEntityTypes.COLONY_INTEGRATOR : null, false), () -> new APBlockItem(Blocks.COLONY_INTEGRATOR.get(), null, CCRegistration.ID.COLONY_POCKET, APConfig.PERIPHERALS_CONFIG.enableColonyIntegrator::get)); + public static final RegistryObject NBT_STORAGE = register("nbt_storage", () -> new APBlockEntityBlock<>(BlockEntityTypes.NBT_STORAGE, false), () -> new APBlockItem(Blocks.NBT_STORAGE.get(), null, null, APConfig.PERIPHERALS_CONFIG.enableNBTStorage::get)); + + public static void register() { + } + + private static RegistryObject registerNoItem(String name, Supplier block) { + return Registration.BLOCKS.register(name, block); + } + + private static RegistryObject register(String name, Supplier block, Supplier blockItem) { + RegistryObject registryObject = registerNoItem(name, block); + Registration.ITEMS.register(name, blockItem); + return registryObject; + } + + public static boolean never(BlockState state, BlockGetter level, BlockPos pos) { + return false; + } + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/CCRegistration.java b/src/main/java/de/srendi/advancedperipherals/common/setup/CCRegistration.java index 11962445a..6bf5b1fd4 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/CCRegistration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/CCRegistration.java @@ -5,9 +5,23 @@ import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.addons.computercraft.integrations.IntegrationPeripheralProvider; -import de.srendi.advancedperipherals.common.addons.computercraft.pocket.*; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.*; -import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.*; +import de.srendi.advancedperipherals.common.addons.computercraft.pocket.PocketChatBoxUpgrade; +import de.srendi.advancedperipherals.common.addons.computercraft.pocket.PocketColonyIntegratorUpgrade; +import de.srendi.advancedperipherals.common.addons.computercraft.pocket.PocketEnvironmentUpgrade; +import de.srendi.advancedperipherals.common.addons.computercraft.pocket.PocketGeoScannerUpgrade; +import de.srendi.advancedperipherals.common.addons.computercraft.pocket.PocketPlayerDetectorUpgrade; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.TurtleChatBoxUpgrade; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.TurtleChunkyUpgrade; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.TurtleCompassUpgrade; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.TurtleEnvironmentDetectorUpgrade; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.TurtleGeoScannerUpgrade; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.TurtlePlayerDetectorUpgrade; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.EndAutomata; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.HusbandryAutomata; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.OverpoweredEndAutomata; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.OverpoweredHusbandryAutomata; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.OverpoweredWeakAutomata; +import de.srendi.advancedperipherals.common.addons.computercraft.turtles.metaphysics.WeakAutomata; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.registries.RegistryObject; @@ -15,28 +29,28 @@ @Mod.EventBusSubscriber(modid = AdvancedPeripherals.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) public class CCRegistration { - public static final RegistryObject> CHAT_BOX_TURTLE = APRegistration.TURTLE_SERIALIZER.register(ID.CHATTY_TURTLE.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(TurtleChatBoxUpgrade::new)); - public static final RegistryObject> PLAYER_DETECTOR_TURTLE = APRegistration.TURTLE_SERIALIZER.register(ID.PLAYER_TURTLE.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(TurtlePlayerDetectorUpgrade::new)); - public static final RegistryObject> ENVIRONMENT_TURTLE = APRegistration.TURTLE_SERIALIZER.register(ID.ENVIRONMENT_TURTLE.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(TurtleEnvironmentDetectorUpgrade::new)); - public static final RegistryObject> CHUNKY_TURTLE = APRegistration.TURTLE_SERIALIZER.register(ID.CHUNKY_TURTLE.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(TurtleChunkyUpgrade::new)); - public static final RegistryObject> GEO_SCANNER_TURTLE = APRegistration.TURTLE_SERIALIZER.register(ID.GEOSCANNER_TURTLE.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(TurtleGeoScannerUpgrade::new)); - public static final RegistryObject> COMPASS_TURTLE = APRegistration.TURTLE_SERIALIZER.register(ID.COMPASS_TURTLE.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(TurtleCompassUpgrade::new)); - public static final RegistryObject> WEAK_TURTLE = APRegistration.TURTLE_SERIALIZER.register(ID.WEAK_AUTOMATA.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(WeakAutomata::new)); - public static final RegistryObject> END_TURTLE = APRegistration.TURTLE_SERIALIZER.register(ID.END_AUTOMATA.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(EndAutomata::new)); - public static final RegistryObject> HUSBANDRY_TURTLE = APRegistration.TURTLE_SERIALIZER.register(ID.HUSBANDRY_AUTOMATA.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(HusbandryAutomata::new)); - public static final RegistryObject> OP_WEAK_TURTLE = APRegistration.TURTLE_SERIALIZER.register(ID.OP_WEAK_AUTOMATA.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(OverpoweredWeakAutomata::new)); - public static final RegistryObject> OP_END_TURTLE = APRegistration.TURTLE_SERIALIZER.register(ID.OP_END_AUTOMATA.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(OverpoweredEndAutomata::new)); - public static final RegistryObject> OP_HUSBANDRY_TURTLE = APRegistration.TURTLE_SERIALIZER.register(ID.OP_HUSBANDRY_AUTOMATA.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(OverpoweredHusbandryAutomata::new)); + public static final RegistryObject> CHAT_BOX_TURTLE = Registration.TURTLE_SERIALIZER.register(ID.CHATTY_TURTLE.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(TurtleChatBoxUpgrade::new)); + public static final RegistryObject> PLAYER_DETECTOR_TURTLE = Registration.TURTLE_SERIALIZER.register(ID.PLAYER_TURTLE.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(TurtlePlayerDetectorUpgrade::new)); + public static final RegistryObject> ENVIRONMENT_TURTLE = Registration.TURTLE_SERIALIZER.register(ID.ENVIRONMENT_TURTLE.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(TurtleEnvironmentDetectorUpgrade::new)); + public static final RegistryObject> CHUNKY_TURTLE = Registration.TURTLE_SERIALIZER.register(ID.CHUNKY_TURTLE.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(TurtleChunkyUpgrade::new)); + public static final RegistryObject> GEO_SCANNER_TURTLE = Registration.TURTLE_SERIALIZER.register(ID.GEOSCANNER_TURTLE.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(TurtleGeoScannerUpgrade::new)); + public static final RegistryObject> COMPASS_TURTLE = Registration.TURTLE_SERIALIZER.register(ID.COMPASS_TURTLE.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(TurtleCompassUpgrade::new)); + public static final RegistryObject> WEAK_TURTLE = Registration.TURTLE_SERIALIZER.register(ID.WEAK_AUTOMATA.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(WeakAutomata::new)); + public static final RegistryObject> END_TURTLE = Registration.TURTLE_SERIALIZER.register(ID.END_AUTOMATA.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(EndAutomata::new)); + public static final RegistryObject> HUSBANDRY_TURTLE = Registration.TURTLE_SERIALIZER.register(ID.HUSBANDRY_AUTOMATA.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(HusbandryAutomata::new)); + public static final RegistryObject> OP_WEAK_TURTLE = Registration.TURTLE_SERIALIZER.register(ID.OP_WEAK_AUTOMATA.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(OverpoweredWeakAutomata::new)); + public static final RegistryObject> OP_END_TURTLE = Registration.TURTLE_SERIALIZER.register(ID.OP_END_AUTOMATA.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(OverpoweredEndAutomata::new)); + public static final RegistryObject> OP_HUSBANDRY_TURTLE = Registration.TURTLE_SERIALIZER.register(ID.OP_HUSBANDRY_AUTOMATA.getPath(), () -> TurtleUpgradeSerialiser.simpleWithCustomItem(OverpoweredHusbandryAutomata::new)); - public static final RegistryObject> CHAT_BOX_POCKET = APRegistration.POCKET_SERIALIZER.register(ID.CHATTY_POCKET.getPath(), () -> PocketUpgradeSerialiser.simpleWithCustomItem(PocketChatBoxUpgrade::new)); - public static final RegistryObject> PLAYER_DETECTOR_POCKET = APRegistration.POCKET_SERIALIZER.register(ID.PLAYER_POCKET.getPath(), () -> PocketUpgradeSerialiser.simpleWithCustomItem(PocketPlayerDetectorUpgrade::new)); - public static final RegistryObject> ENVIRONMENT_POCKET = APRegistration.POCKET_SERIALIZER.register(ID.ENVIRONMENT_POCKET.getPath(), () -> PocketUpgradeSerialiser.simpleWithCustomItem(PocketEnvironmentUpgrade::new)); - public static final RegistryObject> GEO_SCANNER_POCKET = APRegistration.POCKET_SERIALIZER.register(ID.GEOSCANNER_POCKET.getPath(), () -> PocketUpgradeSerialiser.simpleWithCustomItem(PocketGeoScannerUpgrade::new)); - public static final RegistryObject> COLONY_POCKET = APRegistration.POCKET_SERIALIZER.register(ID.COLONY_POCKET.getPath(), () -> PocketUpgradeSerialiser.simpleWithCustomItem(PocketColonyIntegratorUpgrade::new)); + public static final RegistryObject> CHAT_BOX_POCKET = Registration.POCKET_SERIALIZER.register(ID.CHATTY_POCKET.getPath(), () -> PocketUpgradeSerialiser.simpleWithCustomItem(PocketChatBoxUpgrade::new)); + public static final RegistryObject> PLAYER_DETECTOR_POCKET = Registration.POCKET_SERIALIZER.register(ID.PLAYER_POCKET.getPath(), () -> PocketUpgradeSerialiser.simpleWithCustomItem(PocketPlayerDetectorUpgrade::new)); + public static final RegistryObject> ENVIRONMENT_POCKET = Registration.POCKET_SERIALIZER.register(ID.ENVIRONMENT_POCKET.getPath(), () -> PocketUpgradeSerialiser.simpleWithCustomItem(PocketEnvironmentUpgrade::new)); + public static final RegistryObject> GEO_SCANNER_POCKET = Registration.POCKET_SERIALIZER.register(ID.GEOSCANNER_POCKET.getPath(), () -> PocketUpgradeSerialiser.simpleWithCustomItem(PocketGeoScannerUpgrade::new)); + public static final RegistryObject> COLONY_POCKET = Registration.POCKET_SERIALIZER.register(ID.COLONY_POCKET.getPath(), () -> PocketUpgradeSerialiser.simpleWithCustomItem(PocketColonyIntegratorUpgrade::new)); public static IntegrationPeripheralProvider integrationPeripheralProvider; - protected static void register() { + public static void register() { IntegrationPeripheralProvider.load(); integrationPeripheralProvider = new IntegrationPeripheralProvider(); ForgeComputerCraftAPI.registerPeripheralProvider(integrationPeripheralProvider); diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/ContainerTypes.java b/src/main/java/de/srendi/advancedperipherals/common/setup/ContainerTypes.java new file mode 100644 index 000000000..68ed5dc8c --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/ContainerTypes.java @@ -0,0 +1,20 @@ +package de.srendi.advancedperipherals.common.setup; + +import de.srendi.advancedperipherals.common.container.InventoryManagerContainer; +import net.minecraft.core.BlockPos; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.level.Level; +import net.minecraftforge.common.extensions.IForgeMenuType; +import net.minecraftforge.registries.RegistryObject; + +public class ContainerTypes { + + public static final RegistryObject> INVENTORY_MANAGER_CONTAINER = Registration.CONTAINER_TYPES.register("memory_card_container", () -> IForgeMenuType.create((windowId, inv, data) -> { + BlockPos pos = data.readBlockPos(); + Level level = inv.player.getCommandSenderWorld(); + return new InventoryManagerContainer(windowId, inv, pos, level); + })); + + public static void register() { + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/Items.java b/src/main/java/de/srendi/advancedperipherals/common/setup/Items.java new file mode 100644 index 000000000..5cf12df13 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/Items.java @@ -0,0 +1,25 @@ +package de.srendi.advancedperipherals.common.setup; + +import de.srendi.advancedperipherals.common.configuration.APConfig; +import de.srendi.advancedperipherals.common.items.APItem; +import de.srendi.advancedperipherals.common.items.MemoryCardItem; +import de.srendi.advancedperipherals.common.items.WeakAutomataCore; +import net.minecraft.world.item.Item; +import net.minecraftforge.registries.RegistryObject; + +public class Items { + + public static final RegistryObject CHUNK_CONTROLLER = Registration.ITEMS.register("chunk_controller", () -> new APItem(new Item.Properties().stacksTo(16), CCRegistration.ID.CHUNKY_TURTLE, null, APConfig.PERIPHERALS_CONFIG.enableChunkyTurtle::get)); + public static final RegistryObject COMPUTER_TOOL = Registration.ITEMS.register("computer_tool", () -> new APItem(new Item.Properties().stacksTo(1), null, null, () -> true)); + public static final RegistryObject MEMORY_CARD = Registration.ITEMS.register("memory_card", MemoryCardItem::new); + public static final RegistryObject END_AUTOMATA_CORE = Registration.ITEMS.register("end_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), CCRegistration.ID.END_AUTOMATA, null, APConfig.METAPHYSICS_CONFIG.enableEndAutomataCore)); + public static final RegistryObject HUSBANDRY_AUTOMATA_CORE = Registration.ITEMS.register("husbandry_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), CCRegistration.ID.WEAK_AUTOMATA, null, APConfig.METAPHYSICS_CONFIG.enableHusbandryAutomataCore)); + public static final RegistryObject WEAK_AUTOMATA_CORE = Registration.ITEMS.register("weak_automata_core", () -> new WeakAutomataCore(new Item.Properties().stacksTo(1), CCRegistration.ID.WEAK_AUTOMATA, null)); + public static final RegistryObject OVERPOWERED_WEAK_AUTOMATA_CORE = Registration.ITEMS.register("overpowered_weak_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), CCRegistration.ID.OP_WEAK_AUTOMATA, null, APConfig.METAPHYSICS_CONFIG.enableWeakAutomataCore)); + public static final RegistryObject OVERPOWERED_END_AUTOMATA_CORE = Registration.ITEMS.register("overpowered_end_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), CCRegistration.ID.OP_END_AUTOMATA, null, APConfig.METAPHYSICS_CONFIG.enableEndAutomataCore)); + public static final RegistryObject OVERPOWERED_HUSBANDRY_AUTOMATA_CORE = Registration.ITEMS.register("overpowered_husbandry_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), CCRegistration.ID.OP_HUSBANDRY_AUTOMATA, null, APConfig.METAPHYSICS_CONFIG.enableHusbandryAutomataCore)); + + public static void register() { + } + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APRegistration.java b/src/main/java/de/srendi/advancedperipherals/common/setup/Registration.java similarity index 92% rename from src/main/java/de/srendi/advancedperipherals/common/setup/APRegistration.java rename to src/main/java/de/srendi/advancedperipherals/common/setup/Registration.java index f8d25961a..d80a33c6b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APRegistration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/Registration.java @@ -14,7 +14,7 @@ import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; -public class APRegistration { +public class Registration { public static final DeferredRegister BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, AdvancedPeripherals.MOD_ID); public static final DeferredRegister ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, AdvancedPeripherals.MOD_ID); @@ -36,11 +36,11 @@ public static void register() { TURTLE_SERIALIZER.register(modEventBus); POCKET_SERIALIZER.register(modEventBus); - APBlocks.register(); - APBlockEntityTypes.register(); - APItems.register(); - APContainerTypes.register(); - APVillagers.register(); + Blocks.register(); + BlockEntityTypes.register(); + Items.register(); + ContainerTypes.register(); + Villagers.register(); CCRegistration.register(); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/Villagers.java b/src/main/java/de/srendi/advancedperipherals/common/setup/Villagers.java new file mode 100644 index 000000000..df00d9d8f --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/Villagers.java @@ -0,0 +1,19 @@ +package de.srendi.advancedperipherals.common.setup; + +import com.google.common.collect.ImmutableSet; +import dan200.computercraft.shared.Registry; +import de.srendi.advancedperipherals.AdvancedPeripherals; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.entity.ai.village.poi.PoiType; +import net.minecraft.world.entity.npc.VillagerProfession; +import net.minecraftforge.registries.RegistryObject; + +public class Villagers { + + public static final RegistryObject COMPUTER_SCIENTIST_POI = Registration.POI_TYPES.register("computer_scientist", () -> new PoiType(ImmutableSet.copyOf(Registry.ModBlocks.COMPUTER_ADVANCED.get().getStateDefinition().getPossibleStates()), 1, 1)); + public static final RegistryObject COMPUTER_SCIENTIST = Registration.VILLAGER_PROFESSIONS.register("computer_scientist", () -> new VillagerProfession(AdvancedPeripherals.MOD_ID + ":computer_scientist", holder -> holder.is(COMPUTER_SCIENTIST_POI.getKey()), holder -> holder.is(COMPUTER_SCIENTIST_POI.getKey()), ImmutableSet.of(), ImmutableSet.of(Registry.ModBlocks.COMPUTER_ADVANCED.get()), SoundEvents.VILLAGER_WORK_TOOLSMITH)); + + public static void register() { + } + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SlotType.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SlotType.java deleted file mode 100644 index f5498935a..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SlotType.java +++ /dev/null @@ -1,22 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses; - -import net.minecraft.network.chat.Component; - -public enum SlotType { - PERIPHERALS(Component.translatable("text.advancedperipherals.smart_glasses.peripherals")), - MODULES(Component.translatable("text.advancedperipherals.smart_glasses.modules")); - - private final Component name; - - SlotType(Component name) { - this.name = name; - } - - public Component getName() { - return name; - } - - public static SlotType defaultType() { - return PERIPHERALS; - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesAPI.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesAPI.java deleted file mode 100644 index 04baafc24..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesAPI.java +++ /dev/null @@ -1,11 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses; - -import dan200.computercraft.api.lua.ILuaAPI; - -public class SmartGlassesAPI implements ILuaAPI { - @Override - public String[] getNames() { - return new String[]{"smartglasses"}; - } - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesAccess.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesAccess.java deleted file mode 100644 index 316c7a715..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesAccess.java +++ /dev/null @@ -1,67 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses; - -import dan200.computercraft.api.peripheral.IPeripheral; -import dan200.computercraft.api.pocket.IPocketAccess; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.Entity; -import org.jetbrains.annotations.Nullable; - -import java.util.Map; - -public class SmartGlassesAccess implements IPocketAccess { - - private final SmartGlassesComputer computer; - - public SmartGlassesAccess(SmartGlassesComputer computer) { - this.computer = computer; - } - - @Nullable - @Override - public Entity getEntity() { - return computer.getEntity(); - } - - @Override - public int getColour() { - return 0; - } - - @Override - public void setColour(int colour) { - } - - @Override - public int getLight() { - return 0; - } - - @Override - public void setLight(int colour) { - } - - @Override - public CompoundTag getUpgradeNBTData() { - return new CompoundTag(); - } - - @Override - public void updateUpgradeNBTData() { - - } - - @Override - public void invalidatePeripheral() { - - } - - @Override - public Map getUpgrades() { - return computer.getUpgrades(); - } - - public SmartGlassesComputer getComputer() { - return computer; - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java deleted file mode 100644 index 21301b954..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java +++ /dev/null @@ -1,213 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses; - -import dan200.computercraft.api.peripheral.IPeripheral; -import dan200.computercraft.api.pocket.IPocketAccess; -import dan200.computercraft.api.pocket.IPocketUpgrade; -import dan200.computercraft.core.computer.ComputerSide; -import dan200.computercraft.shared.PocketUpgrades; -import dan200.computercraft.shared.computer.core.ComputerFamily; -import dan200.computercraft.shared.computer.core.ServerComputer; -import de.srendi.advancedperipherals.common.smartglasses.modules.IModule; -import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleItem; -import de.srendi.advancedperipherals.common.smartglasses.modules.ModulePeripheral; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.item.ItemEntity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraftforge.items.IItemHandler; -import org.jetbrains.annotations.NotNull; - -import javax.annotation.Nullable; -import java.util.*; - -/** - * Basically just a {@link dan200.computercraft.shared.pocket.core.PocketServerComputer} but with some changes - */ -public class SmartGlassesComputer extends ServerComputer implements IPocketAccess { - - @Nullable - private Entity entity; - private ItemStack stack = ItemStack.EMPTY; - private final SmartGlassesAccess smartGlassesAccess = new SmartGlassesAccess(this); - @Nullable - private SmartGlassesItemHandler itemHandler; - - private int lightColour = -1; - private boolean lightChanged = false; - private boolean isDirty = false; - - private final Set tracking = new HashSet<>(); - private final Map modules = new HashMap<>(); - - public SmartGlassesComputer(ServerLevel world, int computerID, @Nullable String label, ComputerFamily family) { - super(world, computerID, label, family, 39, 13); - } - - @Nullable - @Override - public Entity getEntity() { - if (entity == null || stack.isEmpty() || !entity.isAlive()) - return null; - - if (entity instanceof Player player) { - var inventory = player.getInventory(); - return inventory.items.contains(stack) || inventory.armor.contains(stack) || inventory.offhand.contains(stack) ? entity : null; - } else if (entity instanceof ItemEntity itemEntity) { - return itemEntity.getItem() == stack ? entity : null; - } else { - return null; - } - } - - @Override - public int getColour() { - return 0; - } - - @Override - public void setColour(int colour) { - // We don't have a color. - } - - public void setStack(ItemStack stack) { - this.stack = stack; - } - - public ItemStack getStack() { - return stack; - } - - @Override - public int getLight() { - return lightColour; - } - - @Override - public void setLight(int colour) { - if (colour < 0 || colour > 0xFFFFFF) colour = -1; - - if (lightColour == colour) - return; - lightColour = colour; - lightChanged = true; - } - - public void setItemHandler(@Nullable SmartGlassesItemHandler itemHandler) { - this.itemHandler = itemHandler; - } - - public void markDirty() { - isDirty = true; - } - - public boolean isDirty() { - return isDirty; - } - - @Override - @NotNull - public CompoundTag getUpgradeNBTData() { - return new CompoundTag(); - } - - @Override - public void updateUpgradeNBTData() { - if (entity instanceof Player player) - player.getInventory().setChanged(); - } - - @Override - public void invalidatePeripheral() { - } - - @Override - @NotNull - public Map getUpgrades() { - return Collections.emptyMap(); - } - - public void updatePeripheralsAndModules(IItemHandler itemHandler) { - for (int slot = 0; slot < 4; slot++) { - ItemStack peripheralItem = itemHandler.getStackInSlot(slot); - if (!peripheralItem.isEmpty()) { - IPocketUpgrade upgrade = PocketUpgrades.instance().get(peripheralItem); - if (upgrade != null) { - IPeripheral peripheral = upgrade.createPeripheral(smartGlassesAccess); - if (peripheral != null) { - setPeripheral(SmartGlassesSlot.indexToSide(slot), peripheral); - continue; - } - } - } - setPeripheral(SmartGlassesSlot.indexToSide(slot), null); - } - for (int slot = 4; slot < 11; slot++) { - ItemStack peripheralItem = itemHandler.getStackInSlot(slot); - if (!peripheralItem.isEmpty() && peripheralItem.getItem() instanceof IModuleItem module) { - if (modules.get(slot) != null && modules.get(slot).getName().equals(module.createModule(smartGlassesAccess).getName())) - continue; - - modules.put(slot, module.createModule(smartGlassesAccess)); - } else { - if (modules.get(slot) != null) { - modules.get(slot).onUnequipped(smartGlassesAccess); - modules.remove(slot); - } - } - } - setPeripheral(ComputerSide.BACK, new ModulePeripheral(this)); - } - - @Override - public void tickServer() { - super.tickServer(); - - // Find any players which have gone missing and remove them from the tracking list. - tracking.removeIf(player -> !player.isAlive() || player.level != getLevel()); - - // And now find any new players, add them to the tracking list, and broadcast state where appropriate. - var sendState = hasOutputChanged() || lightChanged; - lightChanged = false; - if (sendState) { - tracking.addAll(getLevel().players()); - } - - modules.values().forEach(module -> module.tick(smartGlassesAccess)); - - if (isDirty()) - updatePeripheralsAndModules(itemHandler); - - isDirty = false; - } - - public void setEntity(@Nullable Entity entity) { - this.entity = entity; - } - - public Map getModules() { - return modules; - } - - @Override - protected void onTerminalChanged() { - super.onTerminalChanged(); - - /*if (entity instanceof ServerPlayer player && entity.isAlive()) { - // Broadcast the terminal to the current player. - }*/ - } - - @Override - protected void onRemoved() { - super.onRemoved(); - } - - @NotNull - public SmartGlassesAccess getSmartGlassesAccess() { - return smartGlassesAccess; - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java deleted file mode 100644 index 0cfa780a1..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java +++ /dev/null @@ -1,147 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses; - -import de.srendi.advancedperipherals.common.setup.APItems; -import net.minecraft.core.NonNullList; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.world.ContainerHelper; -import net.minecraft.world.item.ItemStack; -import net.minecraftforge.common.util.INBTSerializable; -import net.minecraftforge.items.IItemHandlerModifiable; -import net.minecraftforge.items.ItemHandlerHelper; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.annotation.Nonnull; - -public class SmartGlassesItemHandler implements IItemHandlerModifiable, INBTSerializable { - - private static final int SLOTS = 12; - - private final NonNullList items = NonNullList.withSize(SLOTS, ItemStack.EMPTY); - private final ItemStack stack; - @Nullable - private final SmartGlassesComputer computer; - - public SmartGlassesItemHandler(ItemStack stack, @Nullable SmartGlassesComputer computer) { - this.stack = stack; - this.computer = computer; - deserializeNBT(stack.getOrCreateTagElement("Items")); - - if(computer != null) - computer.setItemHandler(this); - } - - @Override - public int getSlots() { - return items.size(); - } - - @NotNull - @Override - public ItemStack getStackInSlot(int slot) { - return items.get(slot); - } - - @Override - @Nonnull - public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) { - if (stack.isEmpty()) - return ItemStack.EMPTY; - - if (!isItemValid(slot, stack)) - return stack; - - ItemStack existing = getStackInSlot(slot); - - int limit = getSlotLimit(slot); - - if (!existing.isEmpty()) { - if (!ItemHandlerHelper.canItemStacksStack(stack, existing)) - return stack; - - limit -= existing.getCount(); - } - - if (limit <= 0) - return stack; - - boolean reachedLimit = stack.getCount() > limit; - - if (!simulate) { - if (existing.isEmpty()) { - setStackInSlot(slot, reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, limit) : stack); - } else { - existing.grow(reachedLimit ? limit : stack.getCount()); - } - - setChanged(); - } - - return reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, stack.getCount() - limit) : ItemStack.EMPTY; - } - - @Override - @Nonnull - public ItemStack extractItem(int slot, int amount, boolean simulate) { - if (amount == 0) - return ItemStack.EMPTY; - - ItemStack existing = getStackInSlot(slot); - - if (existing.isEmpty()) - return ItemStack.EMPTY; - - int toExtract = Math.min(amount, existing.getMaxStackSize()); - - if (existing.getCount() <= toExtract) { - if (!simulate) { - setStackInSlot(slot, ItemStack.EMPTY); - return existing; - } else { - return existing.copy(); - } - } else { - if (!simulate) { - setStackInSlot(slot, ItemHandlerHelper.copyStackWithSize(existing, existing.getCount() - toExtract)); - setChanged(); - } - - return ItemHandlerHelper.copyStackWithSize(existing, toExtract); - } - - } - - @Override - public int getSlotLimit(int slot) { - return 64; - } - - @Override - public boolean isItemValid(int slot, @NotNull ItemStack stack) { - return !stack.is(APItems.SMART_GLASSES.get()); - } - - @Override - public void setStackInSlot(int slot, @NotNull ItemStack stack) { - items.set(slot, stack); - setChanged(); - } - - public void setChanged() { - stack.getOrCreateTag().put("Items", serializeNBT()); - if (computer != null) - computer.markDirty(); - } - - @Override - public CompoundTag serializeNBT() { - CompoundTag itemNBT = new CompoundTag(); - ContainerHelper.saveAllItems(itemNBT, items); - return itemNBT; - } - - @Override - public void deserializeNBT(CompoundTag nbt) { - ContainerHelper.loadAllItems(nbt, items); - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesMenuProvider.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesMenuProvider.java deleted file mode 100644 index bf1fb3b53..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesMenuProvider.java +++ /dev/null @@ -1,43 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses; - -import dan200.computercraft.shared.computer.core.ServerComputer; -import de.srendi.advancedperipherals.common.container.SmartGlassesContainer; -import net.minecraft.network.chat.Component; -import net.minecraft.world.MenuProvider; -import net.minecraft.world.entity.player.Inventory; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.item.ItemStack; -import net.minecraftforge.items.IItemHandler; -import org.jetbrains.annotations.NotNull; - -import javax.annotation.Nullable; - -public class SmartGlassesMenuProvider implements MenuProvider { - private final ServerComputer computer; - private final Component name; - private final IItemHandler glassesContainer; - - public SmartGlassesMenuProvider(ServerComputer computer, ItemStack stack, IItemHandler glassesContainer) { - this.computer = computer; - name = stack.getHoverName(); - this.glassesContainer = glassesContainer; - } - - @NotNull - @Override - public Component getDisplayName() { - return name; - } - - @Nullable - @Override - public AbstractContainerMenu createMenu(int id, @NotNull Inventory inventory, @NotNull Player entity) { - return new SmartGlassesContainer(id, - p -> { - return true; - }, - computer, inventory, glassesContainer, null - ); - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesSlot.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesSlot.java deleted file mode 100644 index ed8a0752d..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesSlot.java +++ /dev/null @@ -1,42 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses; - -import dan200.computercraft.core.computer.ComputerSide; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.items.SlotItemHandler; - -public class SmartGlassesSlot extends SlotItemHandler { - - public final SlotType slotType; - private boolean isEnabled; - - public SmartGlassesSlot(IItemHandler itemHandler, int index, int xPosition, int yPosition, SlotType slotType) { - super(itemHandler, index, xPosition, yPosition); - this.slotType = slotType; - this.isEnabled = slotType == SlotType.defaultType(); - } - - public void setEnabled(boolean enabled) { - isEnabled = enabled; - } - - @Override - public boolean isActive() { - return isEnabled; - } - - @Override - public int getMaxStackSize() { - return 1; - } - - public static ComputerSide indexToSide(int slot) { - return switch (slot) { - case 0 -> ComputerSide.TOP; - case 1 -> ComputerSide.LEFT; - case 2 -> ComputerSide.FRONT; - case 3 -> ComputerSide.RIGHT; - default -> ComputerSide.BOTTOM; - }; - } - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java deleted file mode 100644 index 57376e535..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModule.java +++ /dev/null @@ -1,38 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses.modules; - -import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesAccess; -import net.minecraft.resources.ResourceLocation; -import org.jetbrains.annotations.Nullable; - -public interface IModule { - - ResourceLocation getName(); - - /** - * Used to define the available functions of the module. This method only gets called once when indexing the modules - *

- * Return null if the module does not have any functions - * - * @return an object containing lua functions {@link dan200.computercraft.api.lua.LuaFunction} - */ - @Nullable - IModuleFunctions getFunctions(SmartGlassesAccess smartGlassesAccess); - - /** - * Classic tick function. - *

- * Implementations should check if the entity is not null since the glasses can still tick without belonging to an entity - * @param smartGlassesAccess Contains access to the entity, the computer, the level or the upgrades - */ - default void tick(SmartGlassesAccess smartGlassesAccess) {} - - default void onUnequipped(SmartGlassesAccess smartGlassesAccess) {} - - /** - * ErrorConstants class contains constants for error messages. This is used for easier error handling for users. - */ - class ErrorConstants { - public static final String ALREADY_EXISTS = "ID_ALREADY_EXISTS"; - } - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModuleFunctions.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModuleFunctions.java deleted file mode 100644 index 3656500eb..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModuleFunctions.java +++ /dev/null @@ -1,13 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses.modules; - -import de.srendi.advancedperipherals.lib.peripherals.IPeripheralPlugin; - -/** - * Used to define the available functions of the module. - * Functions can be defined by creating final public methods annotated with the @{@link dan200.computercraft.api.lua.LuaFunction} annotation - */ -public interface IModuleFunctions extends IPeripheralPlugin { - - IModuleFunctions EMPTY = new IModuleFunctions() {}; - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModuleItem.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModuleItem.java deleted file mode 100644 index bed3560a2..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/IModuleItem.java +++ /dev/null @@ -1,24 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses.modules; - -import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesAccess; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import org.jetbrains.annotations.Nullable; - -public interface IModuleItem { - - IModule createModule(SmartGlassesAccess access); - - /** - * This method is called every tick the item is in the inventory of the smart glasses - * Runs on the client and server side - * - * @param access The access to the smart glasses - Null on the client side - * @param module The module - Null on the client side - */ - default void inventoryTick(ItemStack itemStack, Level level, Entity entity, int inventorySlot, boolean isCurrentItem, @Nullable SmartGlassesAccess access, @Nullable IModule module) { - - } - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java deleted file mode 100644 index af3c3e237..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java +++ /dev/null @@ -1,29 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses.modules; - -import dan200.computercraft.api.lua.LuaFunction; -import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesComputer; -import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; - -public class ModulePeripheral extends BasePeripheral { - - public static final String PERIPHERAL_TYPE = "smartGlasses"; - - public ModulePeripheral(SmartGlassesComputer computer) { - super(PERIPHERAL_TYPE, new ModulePeripheralOwner(computer)); - getPeripheralOwner().getComputer().getModules().values().forEach(module -> { - IModuleFunctions functions = module.getFunctions(computer.getSmartGlassesAccess()); - if (functions != null) - addPlugin(functions); - }); - } - - @Override - public boolean isEnabled() { - return true; - } - - @LuaFunction(mainThread = true) - public final String[] getModules() { - return getPeripheralOwner().getComputer().getModules().values().stream().map(module -> module.getName().toString()).toArray(String[]::new); - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheralOwner.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheralOwner.java deleted file mode 100644 index 67bf2b6f0..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheralOwner.java +++ /dev/null @@ -1,114 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses.modules; - -import de.srendi.advancedperipherals.common.addons.computercraft.owner.BasePeripheralOwner; -import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesComputer; -import de.srendi.advancedperipherals.common.util.fakeplayer.APFakePlayer; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.core.FrontAndTop; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import org.apache.commons.lang3.NotImplementedException; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.function.Function; - -public class ModulePeripheralOwner extends BasePeripheralOwner { - - //TODO: Think about making our own smart glasses access so we don't have the not used stuff like the color or the light - // We would need to remove the pocket stuff from the SmartGlassesComputer - private final SmartGlassesComputer computer; - - public ModulePeripheralOwner(SmartGlassesComputer computer) { - this.computer = computer; - } - - @Nullable - @Override - public String getCustomName() { - return "smartglasses"; - } - - @Nullable - @Override - public Level getLevel() { - return computer.getEntity().getLevel(); - } - - @NotNull - @Override - public BlockPos getPos() { - return computer.getEntity().getOnPos(); - } - - @NotNull - @Override - public Direction getFacing() { - return Direction.NORTH; - } - - @NotNull - @Override - public FrontAndTop getOrientation() { - return FrontAndTop.NORTH_UP; - } - - @NotNull - public SmartGlassesComputer getComputer() { - return computer; - } - - @Nullable - @Override - public Player getOwner() { - Entity owner = computer.getEntity(); - if (owner instanceof Player player) return player; - return null; - } - - @NotNull - @Override - public CompoundTag getDataStorage() { - return computer.getUpgradeNBTData(); - } - - @Override - public void markDataStorageDirty() { - computer.updateUpgradeNBTData(); - } - - @Override - public T withPlayer(Function function) { - throw new NotImplementedException(); - } - - @Override - public ItemStack getToolInMainHand() { - return ItemStack.EMPTY; - } - - @Override - public ItemStack storeItem(ItemStack stored) { - throw new NotImplementedException(); - } - - @Override - public void destroyUpgrade() { - throw new NotImplementedException(); - } - - @Override - public boolean isMovementPossible(@NotNull Level level, @NotNull BlockPos pos) { - return false; - } - - @Override - public boolean move(@NotNull Level level, @NotNull BlockPos pos) { - return false; - } - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModule.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModule.java deleted file mode 100644 index c695a8334..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModule.java +++ /dev/null @@ -1,21 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses.modules.hotkey; - -import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesAccess; -import de.srendi.advancedperipherals.common.smartglasses.modules.IModule; -import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleFunctions; -import net.minecraft.resources.ResourceLocation; - -public class HotkeyModule implements IModule { - - @Override - public ResourceLocation getName() { - return AdvancedPeripherals.getRL("hotkey"); - } - - @Override - public IModuleFunctions getFunctions(SmartGlassesAccess smartGlassesAccess) { - return null; - } - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModuleItem.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModuleItem.java deleted file mode 100644 index c2817a9c2..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/hotkey/HotkeyModuleItem.java +++ /dev/null @@ -1,58 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses.modules.hotkey; - -import de.srendi.advancedperipherals.client.KeyBindings; -import de.srendi.advancedperipherals.common.items.base.BaseItem; -import de.srendi.advancedperipherals.common.network.PacketHandler; -import de.srendi.advancedperipherals.common.network.toserver.GlassesHotkeyPacket; -import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesAccess; -import de.srendi.advancedperipherals.common.smartglasses.modules.IModule; -import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleItem; -import de.srendi.advancedperipherals.common.util.KeybindUtil; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import org.jetbrains.annotations.NotNull; - -public class HotkeyModuleItem extends BaseItem implements IModuleItem { - - private static final String KEY_PRESS_DURATION_NBT = "KeyPressDuration"; - - @Override - public boolean isEnabled() { - return true; - } - - @Override - public IModule createModule(SmartGlassesAccess access) { - return new HotkeyModule(); - } - - @Override - public void inventoryTick(@NotNull ItemStack stack, @NotNull Level level, @NotNull Entity entity, int slot, boolean isSelected) { - if (!level.isClientSide() || !(entity instanceof Player player)) - return; - - if (KeybindUtil.isKeyPressed(KeyBindings.GLASSES_HOTKEY_KEYBINDING)) { - // Add another 50ms to the duration, one tick - setKeyPressDuration(stack, getKeyPressDuration(stack) + 50); - } else if(getKeyPressDuration(stack) > 0) { - // If the key is not pressed, but the duration is greater than 0, we can assume that the key was pressed - // We can now post the event - - int duration = getKeyPressDuration(stack); - setKeyPressDuration(stack, 0); - - String keyBind = KeyBindings.GLASSES_HOTKEY_KEYBINDING.getKey().getName(); - PacketHandler.sendToServer(new GlassesHotkeyPacket(player.getUUID(), keyBind, duration)); - } - } - - public static int getKeyPressDuration(ItemStack stack) { - return stack.copy().getOrCreateTag().getInt(KEY_PRESS_DURATION_NBT); - } - - public static void setKeyPressDuration(ItemStack stack, int keyPressDuration) { - stack.getOrCreateTag().putInt(KEY_PRESS_DURATION_NBT, keyPressDuration); - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/nightvision/NightVisionFunctions.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/nightvision/NightVisionFunctions.java deleted file mode 100644 index 658ef1ba2..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/nightvision/NightVisionFunctions.java +++ /dev/null @@ -1,24 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses.modules.nightvision; - -import dan200.computercraft.api.lua.LuaFunction; -import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleFunctions; - -public class NightVisionFunctions implements IModuleFunctions { - - private final NightVisionModule nightVisionModule; - - public NightVisionFunctions(NightVisionModule nightVisionModule) { - this.nightVisionModule = nightVisionModule; - } - - @LuaFunction(mainThread = true) - public final boolean isNightVisionEnabled() { - return nightVisionModule.isNightVisionEnabled(); - } - - @LuaFunction(mainThread = true) - public final void enableNightVision(boolean enable) { - nightVisionModule.enableNightVision(enable); - } - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/nightvision/NightVisionModule.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/nightvision/NightVisionModule.java deleted file mode 100644 index b4818a0c9..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/nightvision/NightVisionModule.java +++ /dev/null @@ -1,48 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses.modules.nightvision; - -import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesAccess; -import de.srendi.advancedperipherals.common.smartglasses.modules.IModule; -import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleFunctions; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.effect.MobEffects; -import net.minecraft.world.entity.player.Player; -import org.jetbrains.annotations.Nullable; - -public class NightVisionModule implements IModule { - - public boolean nightVisionEnabled = true; - - public NightVisionModule() { - - } - - @Override - public ResourceLocation getName() { - return AdvancedPeripherals.getRL("night_vision"); - } - - @Override - @Nullable - public IModuleFunctions getFunctions(SmartGlassesAccess smartGlassesAccess) { - return new NightVisionFunctions(this); - } - - @Override - public void onUnequipped(SmartGlassesAccess smartGlassesAccess) { - if (smartGlassesAccess.getEntity() != null) { - if (smartGlassesAccess.getEntity() instanceof Player player) { - player.removeEffect(MobEffects.NIGHT_VISION); - } - } - - } - - public boolean isNightVisionEnabled() { - return nightVisionEnabled; - } - - public void enableNightVision(boolean enable) { - nightVisionEnabled = enable; - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/nightvision/NightVisionModuleItem.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/nightvision/NightVisionModuleItem.java deleted file mode 100644 index 0e9c0257a..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/nightvision/NightVisionModuleItem.java +++ /dev/null @@ -1,40 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses.modules.nightvision; - -import de.srendi.advancedperipherals.common.items.base.BaseItem; -import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesAccess; -import de.srendi.advancedperipherals.common.smartglasses.modules.IModule; -import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleItem; -import net.minecraft.world.effect.MobEffectInstance; -import net.minecraft.world.effect.MobEffects; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import org.jetbrains.annotations.Nullable; - -public class NightVisionModuleItem extends BaseItem implements IModuleItem { - - @Override - public boolean isEnabled() { - return true; - } - - @Override - public IModule createModule(SmartGlassesAccess access) { - return new NightVisionModule(); - } - - @Override - public void inventoryTick(ItemStack itemStack, Level level, Entity entity, int inventorySlot, boolean isCurrentItem, @Nullable SmartGlassesAccess access, @Nullable IModule module) { - if (level.isClientSide() || !(entity instanceof Player player)) - return; - - if (module instanceof NightVisionModule nightVisionModule) { - if (nightVisionModule.nightVisionEnabled) { - player.addEffect(new MobEffectInstance(MobEffects.NIGHT_VISION, Integer.MAX_VALUE)); - } else { - player.removeEffect(MobEffects.NIGHT_VISION); - } - } - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/ObjectProperty.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/ObjectProperty.java deleted file mode 100644 index 4f332efd5..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/ObjectProperty.java +++ /dev/null @@ -1,22 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses.modules.overlay; - -import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertyTypes.PropertyType; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * This annotation is used to mark a field as a property. It is used for the properties of lua objects. - * Fields annotated with @ObjectProperty will be accessible in lua via the arguments/the filter table for the specific object. - * @see PropertyType - * @see OverlayObject - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.ANNOTATION_TYPE) -public @interface ObjectProperty { - - Class> type(); - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesFunctions.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesFunctions.java deleted file mode 100644 index 2ad26b3a8..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesFunctions.java +++ /dev/null @@ -1,42 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses.modules.overlay; - -import dan200.computercraft.api.lua.IArguments; -import dan200.computercraft.api.lua.LuaException; -import dan200.computercraft.api.lua.LuaFunction; -import dan200.computercraft.api.lua.MethodResult; -import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesAccess; -import de.srendi.advancedperipherals.common.smartglasses.modules.IModule; -import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleFunctions; -import de.srendi.advancedperipherals.common.util.Pair; - -public class OverlayGlassesFunctions implements IModuleFunctions { - - private final OverlayModule overlayModule; - private final SmartGlassesAccess access; - - public OverlayGlassesFunctions(OverlayModule overlayModule) { - this.overlayModule = overlayModule; - this.access = overlayModule.access; - } - - @LuaFunction - public final String test() { - return "Hello World! I'm an overlay module!"; - } - - @LuaFunction - public final MethodResult createPanel(String id, IArguments arguments) throws LuaException { - Panel panel = new Panel(id, overlayModule, arguments); - Pair success = overlayModule.addObject(panel); - if(!success.getRight()) - return MethodResult.of(success.getLeft(), IModule.ErrorConstants.ALREADY_EXISTS); - - return MethodResult.of(success.getLeft(), "SUCCESS"); - } - - @LuaFunction - public final MethodResult getObjects(IArguments arguments) { - return MethodResult.of((Object) overlayModule.getObjects().stream().map(OverlayObject::getId).toArray(String[]::new)); - } - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesItem.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesItem.java deleted file mode 100644 index 20a3bd78b..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesItem.java +++ /dev/null @@ -1,19 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses.modules.overlay; - -import de.srendi.advancedperipherals.common.items.base.BaseItem; -import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesAccess; -import de.srendi.advancedperipherals.common.smartglasses.modules.IModule; -import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleItem; - -public class OverlayGlassesItem extends BaseItem implements IModuleItem { - - @Override - public boolean isEnabled() { - return true; - } - - @Override - public IModule createModule(SmartGlassesAccess smartGlassesAccess) { - return new OverlayModule(smartGlassesAccess); - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java deleted file mode 100644 index e7b5c9fe9..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayModule.java +++ /dev/null @@ -1,69 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses.modules.overlay; - -import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesAccess; -import de.srendi.advancedperipherals.common.smartglasses.modules.IModule; -import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleFunctions; -import de.srendi.advancedperipherals.common.util.Pair; -import net.minecraft.resources.ResourceLocation; -import org.jetbrains.annotations.NotNull; - -import java.util.concurrent.CopyOnWriteArraySet; - - -/** - * We want to support scripts which were made for the plethora classes. So we call this item the same as the overlay item from plethora - * We'll first add our own implementation for a rendering system and then add the API endpoints for plethora scripts - */ -public class OverlayModule implements IModule { - - public final CopyOnWriteArraySet objects = new CopyOnWriteArraySet<>(); - public final SmartGlassesAccess access; - - public OverlayModule(SmartGlassesAccess access) { - this.access = access; - } - - @Override - public ResourceLocation getName() { - return AdvancedPeripherals.getRL("glasses"); - } - - @Override - public IModuleFunctions getFunctions(SmartGlassesAccess smartGlassesAccess) { - return new OverlayGlassesFunctions(this); - } - - @Override - public void tick(@NotNull SmartGlassesAccess smartGlassesAccess) { - /* - Entity entity = smartGlassesAccess.getEntity(); - if (entity != null && entity.getLevel().getGameTime() % 20 == 0) - AdvancedPeripherals.LOGGER.info("I'm an overlay module! And I'm alive!"); - */ - } - - public SmartGlassesAccess getAccess() { - return access; - } - - public CopyOnWriteArraySet getObjects() { - return objects; - } - - /** - * Adds an object to the module. If the object already exists, it will return the object and stop proceeding - * - * @param object The object which should be added - * @return A pair of the object and a boolean. The boolean is true if the object was added successfully and false if not. - * The object is the object which was added or the object which already exists(When not successful). - */ - public Pair addObject(OverlayObject object) { - for (OverlayObject overlayObject : objects) { - if (overlayObject.getId().equals(object.getId())) - return Pair.of(overlayObject, false); - } - objects.add(object); - return Pair.of(object, true); - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayObject.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayObject.java deleted file mode 100644 index ff584021d..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayObject.java +++ /dev/null @@ -1,194 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses.modules.overlay; - -import dan200.computercraft.api.lua.IArguments; -import dan200.computercraft.api.lua.LuaException; -import dan200.computercraft.api.lua.LuaFunction; -import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertyTypes.BooleanProperty; -import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertyTypes.PropertyType; -import de.srendi.advancedperipherals.common.util.StringUtil; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.player.Player; -import net.minecraftforge.network.NetworkEvent; -import org.apache.commons.lang3.reflect.FieldUtils; -import org.apache.logging.log4j.Level; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Field; -import java.util.Map; -import java.util.UUID; -import java.util.stream.Collectors; - - -public abstract class OverlayObject { - - @BooleanProperty - private boolean enabled = true; - - private final String id; - private OverlayModule module; - private UUID player; - - public OverlayObject(String id, OverlayModule module, IArguments arguments) { - this.id = id; - this.module = module; - } - - /** - * For clientside initialization - */ - public OverlayObject(String id, UUID player) { - this.id = id; - this.player = player; - } - - @LuaFunction - public final String getId() { - return id; - } - - public OverlayModule getModule() { - return module; - } - - public UUID getPlayer() { - return player; - } - - @LuaFunction - public final void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - @LuaFunction - public final boolean isEnabled() { - return enabled; - } - - /** - * Maps properties from the provided arguments to the fields of this class. - *

- * This method uses Java Reflection to map properties from IArguments to the fields of the classes. - * It only maps properties that have the annotation {@link ObjectProperty}. If a field does not have this annotation, - * a warning message is logged and the method returns. - *

- * If a property is valid, its value is cast to the field type and set as the new value of the field. - * If a property is not valid, a warning message is logged and the method returns. - *

- * If an error occurs during the mapping of properties, an exception message is logged and a LuaException is thrown. - * - * @param arguments the IArguments containing properties to be mapped - * @throws LuaException if an error occurs during the mapping of properties - * @see IArguments - * @see ObjectProperty - * @see PropertyType - */ - public void reflectivelyMapProperties(IArguments arguments) throws LuaException { - if (arguments.optTable(1).isEmpty()) - return; - - try { - Map properties = arguments.optTable(1).get().entrySet().stream() - .filter(entry -> entry.getKey() instanceof String) - .collect(Collectors.toMap(entry -> (String) entry.getKey(), Map.Entry::getValue)); - - Field[] allFields = FieldUtils.getAllFields(this.getClass()); - - for (Field field : allFields) { - if (properties.containsKey(field.getName())) { - var value = properties.get(field.getName()); - - Annotation[] fieldProperties = field.getAnnotations(); - ObjectProperty objectProperty = null; - Annotation propertyAnnotation = null; - - for (Annotation annotation : fieldProperties) { - objectProperty = annotation.annotationType().getAnnotation(ObjectProperty.class); - if (objectProperty != null) { - propertyAnnotation = annotation; - break; - } - } - - if (objectProperty == null) { - AdvancedPeripherals.debug("The field " + field.getName() + " has no ObjectProperty annotation and can't be changed.", Level.WARN); - return; - } - - PropertyType propertyType = PropertyType.of(objectProperty); - if (propertyType != null) { - value = castValueToFieldType(field, value); - if (propertyType.checkIsValid(value)) { - propertyType.init(propertyAnnotation); - value = propertyType.mapValue(value); - - // Make the field accessible - field.setAccessible(true); - - // Set the value of the field - field.set(this, castValueToFieldType(field, value)); - - } else { - AdvancedPeripherals.debug("The value " + value + " is not valid for the field " + field.getName() + ".", Level.WARN); - return; - } - } - } - } - } catch (LuaException | IllegalAccessException exception) { - AdvancedPeripherals.exception("An error occurred while mapping properties.", exception); - throw new LuaException("An error occurred while mapping properties."); - } - } - - /** - * Casts the given value to the type of the provided field. - * Can be overwritten if the desired casting is not supported. - * - * @param field the field object representing the type to cast to - * @param value the value to be casted - * @return the casted value - */ - public Object castValueToFieldType(Field field, Object value) { - Class fieldType = field.getType(); - - if (fieldType.isAssignableFrom(value.getClass())) { - return value; - } else if (fieldType.equals(Integer.TYPE)) { - return Integer.valueOf(StringUtil.removeFloatingPoints(value.toString())); - } else if (fieldType.equals(Double.TYPE)) { - return Double.valueOf(value.toString()); - } else if (fieldType.equals(Boolean.TYPE)) { - return Boolean.valueOf(value.toString()); - } else if (fieldType.equals(Long.TYPE)) { - return Long.valueOf(StringUtil.removeFloatingPoints(value.toString())); - } else if (fieldType.equals(Short.TYPE)) { - return Short.valueOf(StringUtil.removeFloatingPoints(value.toString())); - } else if (fieldType.equals(Byte.TYPE)) { - return Byte.valueOf(StringUtil.removeFloatingPoints(value.toString())); - } else if (fieldType.equals(Float.TYPE)) { - return Float.valueOf(value.toString()); - } else { - AdvancedPeripherals.debug("The field type " + fieldType.getName() + " is not supported for the value " + value + ".", Level.WARN); - } - return value; - } - - protected void handle(NetworkEvent.Context context) { - - } - - protected void encode(FriendlyByteBuf buffer) { - buffer.writeUtf(id); - Entity entity = module.getAccess().getEntity(); - if(entity instanceof Player player) { - buffer.writeBoolean(true); - buffer.writeUUID(player.getUUID()); - } else { - // Should theoretically never happen. But better safe than sorry - buffer.writeBoolean(false); - } - } - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/Panel.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/Panel.java deleted file mode 100644 index 562c07f10..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/Panel.java +++ /dev/null @@ -1,61 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses.modules.overlay; - -import dan200.computercraft.api.lua.IArguments; -import dan200.computercraft.api.lua.LuaException; -import de.srendi.advancedperipherals.AdvancedPeripherals; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraftforge.network.NetworkEvent; -import org.jetbrains.annotations.Nullable; - -import java.util.UUID; - -/** - * A panel is the standard panel which can contain multiple render-able objects in it. - */ -public class Panel extends RenderableObject { - - public Panel(String id, OverlayModule module, IArguments arguments) throws LuaException { - super(id, module, arguments); - } - - /** - * constructor for the client side initialization - * - * @param id id of the object - * @param player the target player - */ - public Panel(String id, UUID player) { - super(id, player); - } - - @Override - protected void encode(FriendlyByteBuf buffer) { - super.encode(buffer); - buffer.writeInt(color); - buffer.writeDouble(opacity); - } - - @Nullable - public static Panel decode(FriendlyByteBuf buffer) { - String id = buffer.readUtf(); - boolean hasValidUUID = buffer.readBoolean(); - if (!hasValidUUID) { - AdvancedPeripherals.exception("Tried to decode a buffer for an OverlayObject but without a valid player as target.", new IllegalArgumentException()); - return null; - } - UUID player = buffer.readUUID(); - int color = buffer.readInt(); - double opacity = buffer.readDouble(); - - Panel clientPanel = new Panel(id, player); - clientPanel.color = color; - clientPanel.opacity = opacity; - - return clientPanel; - } - - @Override - protected void handle(NetworkEvent.Context context) { - super.handle(context); - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/RenderableObject.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/RenderableObject.java deleted file mode 100644 index 01cad70a2..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/RenderableObject.java +++ /dev/null @@ -1,47 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses.modules.overlay; - -import dan200.computercraft.api.lua.IArguments; -import dan200.computercraft.api.lua.LuaException; -import dan200.computercraft.api.lua.LuaFunction; -import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertyTypes.FixedPointNumberProperty; -import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertyTypes.FloatingNumberProperty; - -import java.util.UUID; - -public abstract class RenderableObject extends OverlayObject { - - @FloatingNumberProperty(min = 0, max = 1) - public double opacity = 1; - - @FixedPointNumberProperty(min = 0, max = 0xFFFFFF) - public int color = 0xFFFFFF; - - @LuaFunction - public double getOpacity() { - return opacity; - } - - @LuaFunction - public void setOpacity(double opacity) { - this.opacity = opacity; - } - - @LuaFunction - public int getColor() { - return color; - } - - @LuaFunction - public void setColor(int color) { - this.color = color; - } - - public RenderableObject(String id, OverlayModule module, IArguments arguments) throws LuaException { - super(id, module, arguments); - reflectivelyMapProperties(arguments); - } - - public RenderableObject(String id, UUID player) { - super(id, player); - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/BooleanProperty.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/BooleanProperty.java deleted file mode 100644 index dc082c9d8..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/BooleanProperty.java +++ /dev/null @@ -1,15 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertyTypes; - -import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.ObjectProperty; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -@ObjectProperty(type = BooleanType.class) -public @interface BooleanProperty { - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/BooleanType.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/BooleanType.java deleted file mode 100644 index 25ab0f531..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/BooleanType.java +++ /dev/null @@ -1,20 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertyTypes; - -public class BooleanType implements PropertyType { - - @Override - public boolean checkIsValid(Object type) { - return type instanceof Boolean; - } - - @Override - public Boolean mapValue(Object type) { - return (Boolean) type; - } - - @Override - public void init(Object property) { - // Nothing to init here, we don't have any filters for booleans - } -} - diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FixedPointNumberProperty.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FixedPointNumberProperty.java deleted file mode 100644 index a65635363..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FixedPointNumberProperty.java +++ /dev/null @@ -1,18 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertyTypes; - -import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.ObjectProperty; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -@ObjectProperty(type = FixedPointNumberType.class) -public @interface FixedPointNumberProperty { - - long min() default Long.MIN_VALUE; - long max() default Long.MAX_VALUE; - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FixedPointNumberType.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FixedPointNumberType.java deleted file mode 100644 index 04bf3bde7..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FixedPointNumberType.java +++ /dev/null @@ -1,34 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertyTypes; - -import de.srendi.advancedperipherals.AdvancedPeripherals; - -public class FixedPointNumberType implements PropertyType { - - public long min; - public long max; - - @Override - public boolean checkIsValid(Object type) { - return type instanceof Long || type instanceof Integer || type instanceof Short || type instanceof Byte; - } - - @Override - public Number mapValue(Object type) { - if (type instanceof Long) - return Math.min(Math.max((long) type, min), max); - if (type instanceof Integer) - return Math.min(Math.max((int) type, (int) min), (int) max); - if (type instanceof Short) - return Math.min(Math.max((short) type, (short) min), (short) max); - return Math.min(Math.max((byte) type, (byte) min), (byte) max); - } - - @Override - public void init(Object property) { - FixedPointNumberProperty decimalProperty = (FixedPointNumberProperty) property; - min = decimalProperty.min(); - max = decimalProperty.max(); - AdvancedPeripherals.debug("Initialized number property with min " + min + " and max " + max); - } -} - diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FloatingNumberProperty.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FloatingNumberProperty.java deleted file mode 100644 index e377472f3..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FloatingNumberProperty.java +++ /dev/null @@ -1,18 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertyTypes; - -import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.ObjectProperty; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -@ObjectProperty(type = FloatingNumberType.class) -public @interface FloatingNumberProperty { - - double min() default Double.MIN_VALUE; - double max() default Double.MAX_VALUE; - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FloatingNumberType.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FloatingNumberType.java deleted file mode 100644 index 05d6eb8df..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/FloatingNumberType.java +++ /dev/null @@ -1,29 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertyTypes; - -import de.srendi.advancedperipherals.AdvancedPeripherals; - -public class FloatingNumberType implements PropertyType { - - public double min; - public double max; - - @Override - public boolean checkIsValid(Object type) { - return type instanceof Float || type instanceof Double; - } - - @Override - public Number mapValue(Object type) { - AdvancedPeripherals.debug("Mapping value " + type + " to " + Math.min(Math.max((double) type, min), max)); - return Math.min(Math.max((double) type, min), max); - } - - @Override - public void init(Object property) { - FloatingNumberProperty decimalProperty = (FloatingNumberProperty) property; - min = decimalProperty.min(); - max = decimalProperty.max(); - AdvancedPeripherals.debug("Initialized decimal property with min " + min + " and max " + max); - } -} - diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/PropertyType.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/PropertyType.java deleted file mode 100644 index bd29944ba..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/propertyTypes/PropertyType.java +++ /dev/null @@ -1,31 +0,0 @@ -package de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertyTypes; - -import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.ObjectProperty; - -import java.lang.reflect.InvocationTargetException; - -/** - * This interface represents a property type. It is used to check if a value is valid for the property and to map the value to the correct type. - * - * @param the type of the property value - * @see ObjectProperty - */ -public interface PropertyType { - - boolean checkIsValid(Object type); - - T mapValue(Object type); - - static PropertyType of(ObjectProperty property) { - try { - return property.type().getDeclaredConstructor().newInstance(); - } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException exception) { - AdvancedPeripherals.exception("An error occurred while trying to create the property type", exception); - } - return null; - } - - void init(Object property); - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java index 3c8039fd0..a21f2ab8d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java @@ -17,7 +17,7 @@ public class CoordUtil { public static boolean isInRange(@Nullable BlockPos pos, @Nullable Level world, @Nullable Player player, int range, int maxRange) { - // There are rare cases where these can be null. For example if a player detector pocket computer runs while not in a player inventory + // There are rare cases where these are null. For example if a player detector pocket computer runs while not in a player inventory // Fixes https://github.com/SirEndii/AdvancedPeripherals/issues/356 if (pos == null || world == null || player == null) return false; @@ -83,20 +83,21 @@ public static boolean isInRange(@Nullable BlockPos blockPos, @Nullable Player pl } public static Direction getDirection(FrontAndTop orientation, String computerSide) throws LuaException { - if (computerSide == null) + if (computerSide == null) { throw new LuaException("null is not a valid side"); + } computerSide = computerSide.toLowerCase(Locale.ROOT); Direction dir = Direction.byName(computerSide); if (dir != null) return dir; - Direction top = orientation.top(); Direction front = orientation.front(); final ComputerSide side = ComputerSide.valueOfInsensitive(computerSide); - if (side == null) + if (side == null) { throw new LuaException(computerSide + " is not a valid side"); + } if (front.getAxis() == Direction.Axis.Y) { return switch (side) { @@ -117,7 +118,6 @@ public static Direction getDirection(FrontAndTop orientation, String computerSid case LEFT -> front.getClockWise(); }; } - } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/EnumColor.java b/src/main/java/de/srendi/advancedperipherals/common/util/EnumColor.java index 9273fc561..415b45b23 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/EnumColor.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/EnumColor.java @@ -4,37 +4,33 @@ public enum EnumColor { - BLACK("\u00a70", "Black", "black", "§0", 0, new float[]{0f, 0f, 0f, 1f}), - DARK_BLUE("\u00a71", "Blue", "blue", "§1", 0xFF0000c9, new float[]{0f, 0f, 0.804f, 1f}), - DARK_GREEN("\u00a72", "Green", "green", "§2", 0xFF0c9400, new float[]{0.048f, 0.592f, 0f, 1f}), - DARK_AQUA("\u00a73", "Cyan", "cyan", "§3", 0xFF009494, new float[]{0f, 0.592f, 0.592f, 1f}), - DARK_RED("\u00a74", "Dark Red", "dark_red", "§4", 0xFF940000, new float[]{0.592f, 0f, 0f, 1f}), - DARK_PURPLE("\u00a75", "Purple", "purple", "§5", 0xFF510094, new float[]{0.324f, 0f, 0.592f, 1f}), - GOLD("\u00a76", "Orange", "orange", "§6", 0xFFb59700, new float[]{1f, 0.407f, 0f, 1f}), - GRAY("\u00a77", "Light Gray", "light_gray", "§7", 0xFF616161, new float[]{0.388f, 0.388f, 0.388f, 1f}), - DARK_GRAY("\u00a78", "Gray", "gray", "§8", 0xFF4a4a4a, new float[]{0.296f, 0.296f, 0.296f, 1f}), - BLUE("\u00a79", "Light Blue", "light_blue", "§9", 0xFF1919ff, new float[]{0.098f, 0.098f, 1f, 1f}), - GREEN("\u00a7a", "Lime", "lime", "§a", 0xFF00e02d, new float[]{0f, 0.878f, 0.176f, 1f}), - AQUA("\u00a7b", "Aqua", "aqua", "§b", 0xFF17ffe4, new float[]{0.090f, 1f, 0.894f, 1f}), - RED("\u00a7c", "Red", "red", "§c", 0xFFff1c1c, new float[]{1f, 0.109f, 0.109f, 1f}), - LIGHT_PURPLE("\u00a7d", "Magenta", "magenta", "§d", 0xFF7424ff, new float[]{0.454f, 0.141f, 1f, 1f}), - YELLOW("\u00a7e", "Yellow", "yellow", "§e", 0xFFc8ff00, new float[]{0.784f, 1f, 0f, 1f}), - WHITE("\u00a7f", "White", "white", "§f", 0xFFffffff, new float[]{1f, 1f, 1f, 1f}); + BLACK("\u00a70", "Black", "black", "&0"), + DARK_BLUE("\u00a71", "Blue", "blue", "&1"), + DARK_GREEN("\u00a72", "Green", "green", "&2"), + DARK_AQUA("\u00a73", "Cyan", "cyan", "&3"), + DARK_RED("\u00a74", "Dark Red", "dark_red", "&4"), + DARK_PURPLE("\u00a75", "Purple", "purple", "&5"), + GOLD("\u00a76", "Orange", "orange", "&6"), + GRAY("\u00a77", "Light Gray", "light_gray", "&7"), + DARK_GRAY("\u00a78", "Gray", "gray", "&8"), + BLUE("\u00a79", "Light Blue", "light_blue", "&9"), + GREEN("\u00a7a", "Lime", "lime", "&a"), + AQUA("\u00a7b", "Aqua", "aqua", "&b"), + RED("\u00a7c", "Red", "red", "&c"), + LIGHT_PURPLE("\u00a7d", "Magenta", "magenta", "&d"), + YELLOW("\u00a7e", "Yellow", "yellow", "&e"), + WHITE("\u00a7f", "White", "white", "&f"); private final String code; private final String name; private final String technicalName; private final String alternativeCode; - private final int hex; - private final float[] rgb; - EnumColor(String code, String name, String technicalName, String alternativeCode, int hex, float[] rgb) { + EnumColor(String code, String name, String technicalName, String alternativeCode) { this.code = code; this.name = name; this.technicalName = technicalName; this.alternativeCode = alternativeCode; - this.hex = hex; - this.rgb = rgb; } public static Component buildTextComponent(Component textComponent) { @@ -45,10 +41,6 @@ public static Component buildTextComponent(Component textComponent) { return Component.literal(text); } - public float[] getRgb() { - return rgb; - } - public String getCode() { return code; } @@ -60,8 +52,4 @@ public String getType() { public String getTechnicalName() { return technicalName; } - - public int getHex() { - return hex; - } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/FluidStorageProxy.java b/src/main/java/de/srendi/advancedperipherals/common/util/FluidStorageProxy.java deleted file mode 100644 index a61361aa0..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/util/FluidStorageProxy.java +++ /dev/null @@ -1,92 +0,0 @@ -package de.srendi.advancedperipherals.common.util; - -import de.srendi.advancedperipherals.common.blocks.blockentities.FluidDetectorEntity; -import net.minecraft.world.level.material.Fluid; -import net.minecraft.world.level.material.Fluids; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.IFluidHandler; -import org.jetbrains.annotations.NotNull; - -import java.util.Optional; - -public class FluidStorageProxy implements IFluidHandler { - - private final FluidDetectorEntity fluidDetectorEntity; - private int maxTransferRate; - private int transferedInThisTick = 0; - private final Fluid fluid = Fluids.EMPTY; - - public FluidStorageProxy(FluidDetectorEntity fluidDetectorEntity, int maxTransferRate) { - this.fluidDetectorEntity = fluidDetectorEntity; - this.maxTransferRate = maxTransferRate; - } - - - public int getMaxTransferRate() { - return maxTransferRate; - } - - public void setMaxTransferRate(int rate) { - maxTransferRate = rate; - } - - /** - * should be called on every tick - */ - public void resetTransferedInThisTick() { - transferedInThisTick = 0; - } - - public int getTransferedInThisTick() { - return transferedInThisTick; - } - - @Override - public int getTanks() { - return 1; - } - - @Override - public @NotNull FluidStack getFluidInTank(int tank) { - Optional out = fluidDetectorEntity.getOutputStorage(); - return out.map(outStorage -> outStorage.getFluidInTank(tank)).orElse(FluidStack.EMPTY); - } - - @Override - public int getTankCapacity(int tank) { - Optional out = fluidDetectorEntity.getOutputStorage(); - return out.map(outStorage -> outStorage.getTankCapacity(tank)).orElse(0); - } - - @Override - public boolean isFluidValid(int tank, @NotNull FluidStack stack) { - Optional out = fluidDetectorEntity.getOutputStorage(); - return out.map(outStorage -> outStorage.isFluidValid(tank, stack)).orElse(false); - } - - @Override - public int fill(FluidStack resource, IFluidHandler.FluidAction action) { - Optional out = fluidDetectorEntity.getOutputStorage(); - return out.map(outStorage -> { - FluidStack transferring = resource.copy(); - transferring.setAmount(Math.min(resource.getAmount(), maxTransferRate)); - int transferred = outStorage.fill(transferring, action); - if (!action.simulate()) { - transferedInThisTick += transferred; - fluidDetectorEntity.lastFlowedLiquid = resource.copy(); - //transferedInThisTick = transferred; - } - return transferred; - }).orElse(0); - } - - @Override - public @NotNull FluidStack drain(int maxDrain, IFluidHandler.FluidAction action) { - return FluidStack.EMPTY; - } - - @Override - public @NotNull FluidStack drain(FluidStack resource, IFluidHandler.FluidAction action) { - return FluidStack.EMPTY; - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/GasStorageProxy.java b/src/main/java/de/srendi/advancedperipherals/common/util/GasStorageProxy.java deleted file mode 100644 index d4e514a6d..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/util/GasStorageProxy.java +++ /dev/null @@ -1,99 +0,0 @@ -package de.srendi.advancedperipherals.common.util; - -import de.srendi.advancedperipherals.common.blocks.blockentities.GasDetectorEntity; -import mekanism.api.Action; -import mekanism.api.chemical.gas.GasStack; -import mekanism.api.chemical.gas.IGasHandler; -import org.jetbrains.annotations.NotNull; - -import java.util.Optional; - -public class GasStorageProxy implements IGasHandler { - - private final GasDetectorEntity fluidDetectorEntity; - private int maxTransferRate; - private int transferedInThisTick = 0; - - public GasStorageProxy(GasDetectorEntity fluidDetectorEntity, int maxTransferRate) { - this.fluidDetectorEntity = fluidDetectorEntity; - this.maxTransferRate = maxTransferRate; - } - - - public int getMaxTransferRate() { - return maxTransferRate; - } - - public void setMaxTransferRate(int rate) { - maxTransferRate = rate; - } - - /** - * should be called on every tick - */ - public void resetTransferedInThisTick() { - transferedInThisTick = 0; - } - - public int getTransferedInThisTick() { - return transferedInThisTick; - } - - @Override - public int getTanks() { - return 1; - } - - @NotNull - @Override - public GasStack getChemicalInTank(int tank) { - Optional out = fluidDetectorEntity.getOutputStorage(); - return out.map(outStorage -> outStorage.getChemicalInTank(tank)).orElse(GasStack.EMPTY); - } - - @Override - public void setChemicalInTank(int tank, @NotNull GasStack stack) { - Optional out = fluidDetectorEntity.getOutputStorage(); - out.ifPresent(outStorage -> outStorage.setChemicalInTank(tank, stack)); - } - - @Override - public long getTankCapacity(int tank) { - Optional out = fluidDetectorEntity.getOutputStorage(); - return out.map(outStorage -> outStorage.getTankCapacity(tank)).orElse(0L); - } - - @Override - public boolean isValid(int tank, @NotNull GasStack stack) { - Optional out = fluidDetectorEntity.getOutputStorage(); - return out.map(outStorage -> outStorage.isValid(tank, stack)).orElse(false); - } - - @NotNull - @Override - public GasStack insertChemical(@NotNull GasStack stack, @NotNull Action action) { - Optional out = fluidDetectorEntity.getOutputStorage(); - return out.map(outStorage -> { - GasStack transferring = stack.copy(); - transferring.setAmount(Math.min(stack.getAmount(), maxTransferRate)); - GasStack transferred = outStorage.insertChemical(transferring, action); - if (!action.simulate()) { - transferedInThisTick += transferring.getAmount() - transferred.getAmount(); - fluidDetectorEntity.lastFlowedGas = stack.copy(); - } - return transferred; - }).orElse(GasStack.EMPTY); - } - - @NotNull - @Override - public GasStack insertChemical(int tank, @NotNull GasStack stack, @NotNull Action action) { - return insertChemical(stack, action); - } - - @NotNull - @Override - public GasStack extractChemical(int tank, long amount, @NotNull Action action) { - return GasStack.EMPTY; - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java deleted file mode 100644 index 1a9508a1e..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java +++ /dev/null @@ -1,157 +0,0 @@ -package de.srendi.advancedperipherals.common.util; - -import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.DistanceDetectorPeripheral; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.core.Vec3i; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.ClipContext; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.*; -import net.minecraft.world.phys.shapes.CollisionContext; -import net.minecraft.world.phys.shapes.Shapes; -import net.minecraft.world.phys.shapes.VoxelShape; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -public class HitResultUtil { - - /** - * This method is used to get the hit result of an entity from the start position of a block - * - * @param to the target position/max position - * @param from the source position like a block - * @param level the level - * @param ignoreTransparent if transparent blocks should be ignored - * @return the hit result. {@link BlockHitResult#miss(Vec3, Direction, BlockPos)} if nothing found - */ - @NotNull - public static HitResult getHitResult(Vec3 to, Vec3 from, Level level, boolean ignoreTransparent) { - EntityHitResult entityResult = getEntityHitResult(to, from, level); - BlockHitResult blockResult = getBlockHitResult(to, from, level, ignoreTransparent); - - if (entityResult.getType() != HitResult.Type.MISS && blockResult.getType() == HitResult.Type.MISS) - return entityResult; - - if (entityResult.getType() == HitResult.Type.MISS && blockResult.getType() != HitResult.Type.MISS) - return blockResult; - - if (entityResult.getType() == HitResult.Type.MISS && blockResult.getType() == HitResult.Type.MISS) - return BlockHitResult.miss(from, blockResult.getDirection(), new BlockPos(to)); - - double blockDistance = new BlockPos(from).distManhattan(blockResult.getBlockPos()); - double entityDistance = new BlockPos(from).distManhattan(new Vec3i(entityResult.getLocation().x, entityResult.getLocation().y, entityResult.getLocation().z)); - - if (blockDistance < entityDistance) - return blockResult; - - return entityResult; - } - - /** - * This method is used to get the hit result of an entity from the start position of a block - * This could be used to find an entity from the eyes position of another entity but since - * this method uses one AABB made out of the two coordinates, this would also find any entities - * which are not located in the ray you might want. {@link DistanceDetectorPeripheral#getDistance()} - * - * @param to the target position/max position - * @param from the source position like a block - * @param level the world - * @return the entity hit result. An empty HitResult with {@link HitResult.Type#MISS} as type if nothing found - */ - @NotNull - public static EntityHitResult getEntityHitResult(Vec3 to, Vec3 from, Level level) { - AABB checkingBox = new AABB(to, from); - - List entities = level.getEntities((Entity) null, checkingBox, (entity) -> true); - - if (entities.isEmpty()) - return new EmptyEntityHitResult(); - - Entity nearestEntity = null; - - // Find the nearest entity - for (Entity entity : entities) { - if (nearestEntity == null) { - nearestEntity = entity; - continue; - } - - double distance = new BlockPos(from).distManhattan(new Vec3i(entity.getX(), entity.getY(), entity.getZ())); - double nearestDistance = new BlockPos(from).distManhattan(new Vec3i(nearestEntity.getX(), nearestEntity.getY(), nearestEntity.getZ())); - - // If it's closer, set it as the nearest entity - if (distance < nearestDistance) - nearestEntity = entity; - } - - return new EntityHitResult(nearestEntity); - } - - /** - * This method is used to get the hit result of a block from the start position of a block - * - * @param to the target position/max position - * @param from the source position - * @param level the world - * @param ignoreNoOccluded if true, the method will ignore blocks which are not occluding like glass - * @return the block hit result. {@link BlockHitResult#miss(Vec3, Direction, BlockPos)} if nothing found - */ - @NotNull - public static BlockHitResult getBlockHitResult(Vec3 to, Vec3 from, Level level, boolean ignoreNoOccluded) { - return level.clip(new AdvancecClipContext(from, to, ignoreNoOccluded ? IgnoreNoOccludedContext.INSTANCE : ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, null)); - } - - public static class EmptyEntityHitResult extends EntityHitResult { - - /** - * The super constructor is a NotNull argument but since this result is empty, we'll just return null - */ - public EmptyEntityHitResult() { - super(null, null); - } - - @NotNull - @Override - public Type getType() { - return Type.MISS; - } - } - - /** - * A shape getter which ignores blocks which are not occluding like glass - */ - private enum IgnoreNoOccludedContext implements ClipContext.ShapeGetter { - - INSTANCE; - - @NotNull - @Override - public VoxelShape get(BlockState pState, @NotNull BlockGetter pBlock, @NotNull BlockPos pPos, @NotNull CollisionContext pCollisionContext) { - return !pState.canOcclude() ? Shapes.empty() : pState.getCollisionShape(pBlock, pPos, pCollisionContext); - } - } - - /** - * A clip context but with a custom shape getter. Used to define another shape getter for the block like {@link IgnoreNoOccludedContext} - */ - private static class AdvancecClipContext extends ClipContext { - - private final ShapeGetter blockShapeGetter; - - protected AdvancecClipContext(Vec3 from, Vec3 to, ShapeGetter blockShapeGetter, Fluid fluidShapeGetter, @Nullable Entity entity) { - super(from, to, Block.COLLIDER, fluidShapeGetter, entity); - this.blockShapeGetter = blockShapeGetter; - } - - @NotNull - @Override - public VoxelShape getBlockShape(@NotNull BlockState pBlockState, @NotNull BlockGetter pLevel, @NotNull BlockPos pPos) { - return blockShapeGetter.get(pBlockState, pLevel, pPos, this.collisionContext); - } - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java b/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java index e74410111..5bef952ad 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java @@ -3,7 +3,6 @@ import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.shared.util.NBTUtil; import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.InventoryManagerPeripheral; -import de.srendi.advancedperipherals.common.util.inventory.FluidUtil; import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; @@ -15,13 +14,9 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.state.properties.Property; -import net.minecraft.world.level.material.Fluid; import net.minecraftforge.common.IForgeShearable; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidType; - import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; + import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -105,11 +100,8 @@ public static Object posToObject(BlockPos pos) { return map; } - @Nullable - public static Map itemStackToObject(@NotNull ItemStack stack) { - if (stack.isEmpty()) { - return null; - } + public static Map stackToObject(@NotNull ItemStack stack) { + if (stack.isEmpty()) return new HashMap<>(); Map map = itemToObject(stack.getItem()); CompoundTag nbt = stack.copy().getOrCreateTag(); map.put("count", stack.getCount()); @@ -120,21 +112,10 @@ public static Map itemStackToObject(@NotNull ItemStack stack) { return map; } - public static Map fluidStackToObject(@NotNull FluidStack stack) { - if (stack.isEmpty()) return new HashMap<>(); - Map map = fluidToObject(stack.getFluid()); - CompoundTag nbt = stack.copy().getOrCreateTag(); - map.put("count", stack.getAmount()); - map.put("displayName", stack.getDisplayName().getString()); - map.put("nbt", NBTUtil.toLua(nbt)); - map.put("fingerprint", FluidUtil.getFingerprint(stack)); - return map; - } - - public static Map itemStackToObject(@NotNull ItemStack itemStack, int amount) { + public static Map stackToObject(@NotNull ItemStack itemStack, int amount) { ItemStack stack = itemStack.copy(); stack.setCount(amount); - return itemStackToObject(stack); + return stackToObject(stack); } /** @@ -145,13 +126,10 @@ public static Map itemStackToObject(@NotNull ItemStack itemStack * @return a Map containing proper item stack details * @see InventoryManagerPeripheral#getItems() */ - @Nullable public static Map stackToObjectWithSlot(@NotNull ItemStack stack, int slot) { - if (stack.isEmpty()) { - return null; - } - Map map = itemStackToObject(stack); - map.put("slot", slot + 1); + if (stack.isEmpty()) return new HashMap<>(); + Map map = stackToObject(stack); + map.put("slot", slot); return map; } @@ -162,18 +140,6 @@ public static Map itemToObject(@NotNull Item item) { return map; } - public static Map fluidToObject(@NotNull Fluid fluid) { - Map map = new HashMap<>(); - FluidType fluidType = fluid.getFluidType(); - map.put("tags", tagsToList(() -> fluid.builtInRegistryHolder().tags())); - map.put("name", FluidUtil.getRegistryKey(fluid).toString()); - map.put("density", fluidType.getDensity()); - map.put("lightLevel", fluidType.getLightLevel()); - map.put("temperature", fluidType.getTemperature()); - map.put("viscosity", fluidType.getViscosity()); - return map; - } - public static List tagsToList(@NotNull Supplier>> tags) { if (tags.get().findAny().isEmpty()) return Collections.emptyList(); return tags.get().map(LuaConverter::tagToString).toList(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/Pair.java b/src/main/java/de/srendi/advancedperipherals/common/util/Pair.java index fe2b993dd..46398d900 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/Pair.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/Pair.java @@ -42,12 +42,12 @@ public boolean rightPresent() { } public void ifRightPresent(Consumer consumer) { - if (rightPresent()) + if(rightPresent()) consumer.accept(right); } public void ifLeftPresent(Consumer consumer) { - if (leftPresent()) + if(leftPresent()) consumer.accept(left); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ServerWorker.java b/src/main/java/de/srendi/advancedperipherals/common/util/ServerWorker.java index d4c5762ae..884cbd5a2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ServerWorker.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ServerWorker.java @@ -12,7 +12,6 @@ public class ServerWorker { private static final Queue callQueue = new ConcurrentLinkedQueue<>(); - private static int tasksRan = 0; public static void add(final Runnable call) { callQueue.add(call); @@ -23,8 +22,7 @@ public static void serverTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.END) { while (!callQueue.isEmpty()) { final Runnable runnable = callQueue.poll(); - tasksRan++; - AdvancedPeripherals.debug("Running task #" + tasksRan + ". Running " + runnable.getClass()); + AdvancedPeripherals.debug("Running queued server worker call: " + runnable); runnable.run(); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/StringUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/StringUtil.java index dcf2ab95a..bc586425d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/StringUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/StringUtil.java @@ -12,11 +12,4 @@ public static String toHexString(byte[] bytes) { } return new String(hexChars); } - - public static String removeFloatingPoints(String number) { - if (number.contains(".")) { - return number.substring(0, number.indexOf(".")); - } - return number; - } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ZeroGasTank.java b/src/main/java/de/srendi/advancedperipherals/common/util/ZeroGasTank.java deleted file mode 100644 index 48f81d3b1..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ZeroGasTank.java +++ /dev/null @@ -1,47 +0,0 @@ -package de.srendi.advancedperipherals.common.util; - -import mekanism.api.Action; -import mekanism.api.chemical.gas.GasStack; -import mekanism.api.chemical.gas.IGasHandler; -import org.jetbrains.annotations.NotNull; - -public class ZeroGasTank implements IGasHandler { - - @Override - public int getTanks() { - return 0; - } - - @NotNull - @Override - public GasStack getChemicalInTank(int tank) { - return GasStack.EMPTY; - } - - @Override - public void setChemicalInTank(int tank, GasStack stack) { - - } - - @Override - public long getTankCapacity(int tank) { - return 0; - } - - @Override - public boolean isValid(int tank, @NotNull GasStack stack) { - return false; - } - - @NotNull - @Override - public GasStack insertChemical(int tank, @NotNull GasStack stack, @NotNull Action action) { - return GasStack.EMPTY; - } - - @NotNull - @Override - public GasStack extractChemical(int tank, long amount, @NotNull Action action) { - return GasStack.EMPTY; - } -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/FakePlayerProviderTurtle.java b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/FakePlayerProviderTurtle.java index eaa186d17..fff168b9f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/FakePlayerProviderTurtle.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/FakePlayerProviderTurtle.java @@ -55,9 +55,9 @@ public static void load(APFakePlayer player, ITurtleAccess turtle) { // Add properties ItemStack activeStack = player.getItemInHand(InteractionHand.MAIN_HAND); - if (!activeStack.isEmpty()) + if (!activeStack.isEmpty()) { player.getAttributes().addTransientAttributeModifiers(activeStack.getAttributeModifiers(EquipmentSlot.MAINHAND)); - + } } public static void unload(APFakePlayer player, ITurtleAccess turtle) { @@ -94,6 +94,7 @@ public static void unload(APFakePlayer player, ITurtleAccess turtle) { } } + public static T withPlayer(ITurtleAccess turtle, Function function) { APFakePlayer player = getPlayer(turtle, turtle.getOwningPlayer()); load(player, turtle); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java index da7510ba0..faad46a1f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java @@ -1,7 +1,5 @@ package de.srendi.advancedperipherals.common.util.inventory; -import appeng.api.stacks.AEFluidKey; -import appeng.api.stacks.GenericStack; import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.core.apis.TableHelper; import de.srendi.advancedperipherals.AdvancedPeripherals; @@ -19,7 +17,7 @@ import java.util.Map; -public class FluidFilter extends GenericFilter { +public class FluidFilter { private Fluid fluid = Fluids.EMPTY; private TagKey tag = null; @@ -99,14 +97,6 @@ public FluidFilter setCount(int count) { return this; } - @Override - public boolean test(GenericStack genericStack) { - if (genericStack.what() instanceof AEFluidKey aeFluidKey) { - return test(aeFluidKey.toStack(1)); - } - return false; - } - public boolean test(FluidStack stack) { if (!fingerprint.isEmpty()) { String testFingerprint = FluidUtil.getFingerprint(stack); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java deleted file mode 100644 index 64d148419..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java +++ /dev/null @@ -1,69 +0,0 @@ -package de.srendi.advancedperipherals.common.util.inventory; - -import appeng.api.stacks.GenericStack; -import de.srendi.advancedperipherals.common.util.Pair; -import net.minecraftforge.registries.ForgeRegistries; - -import java.util.Map; - -public abstract class GenericFilter { - - /** - * Try to parse a raw filter table to any existing filter type. Could be a fluid filter, an item filter, maybe something else - * in the future. - *

- * If the function can't find a valid type for the given name/resource location, it will return an empty filter with - * a proper error message. - * - * @param rawFilter The raw filter, which is a map of strings and objects - * @return A pair of the parsed filter and an error message, if there is one - */ - public static Pair parseGeneric(Map rawFilter) { - // TODO: Add chemical filter support - - if (!rawFilter.containsKey("name")) { - if (rawFilter.containsKey("type") && rawFilter.get("type") instanceof String type) { - switch (type) { - case "item": - return ItemFilter.parse(rawFilter); - case "fluid": - return FluidFilter.parse(rawFilter); - } - } - // If the filter does not contain a name or a type, which should never happen, but players are players, we will just - // give the ItemFilter the task to parse the filter - return ItemFilter.parse(rawFilter); - } - String name = rawFilter.get("name").toString(); - - // Let's check in which registry this thing is - if (ItemUtil.getRegistryEntry(name, ForgeRegistries.ITEMS) != null) { - return ItemFilter.parse(rawFilter); - } else if (ItemUtil.getRegistryEntry(name, ForgeRegistries.FLUIDS) != null) { - return FluidFilter.parse(rawFilter); - } else { - // If the name is in neither of the registries, we will just return an empty filter - return Pair.of(empty(), "NO_VALID_FILTER_TYPE"); - } - - } - - public abstract boolean isEmpty(); - - public abstract boolean test(GenericStack genericStack); - - public static GenericFilter empty() { - return new GenericFilter() { - @Override - public boolean isEmpty() { - return true; - } - - @Override - public boolean test(GenericStack genericStack) { - return false; - } - }; - } - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemFluidHandler.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemFluidHandler.java index 9cc76fbee..f86f1e487 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemFluidHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemFluidHandler.java @@ -11,7 +11,7 @@ public interface IStorageSystemFluidHandler extends IFluidHandler { * Uses a filter to find the right item. The amount should never be greater than 64 * stack sizes greater than 64. * - * @param filter The parsed filter + * @param filter The parsed filter * @param simulate Should this action be simulated * @return extracted from the slot, must be empty if nothing can be extracted. The returned ItemStack can be safely modified after, so item handlers should return a new or copied stack. */ diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemItemHandler.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemItemHandler.java index 63ae60a16..f5b161f6a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemItemHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemItemHandler.java @@ -11,7 +11,6 @@ public interface IStorageSystemItemHandler extends IItemHandler { * Uses a filter to find the right item. The amount should never be greater than 64 * stack sizes greater than 64. * - * @param filter The parsed filter * @param filter The parsed filter * @param count The amount to extract * @param simulate Should this action be simulated diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java deleted file mode 100644 index 39b4fd114..000000000 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java +++ /dev/null @@ -1,100 +0,0 @@ -package de.srendi.advancedperipherals.common.util.inventory; - -import dan200.computercraft.api.lua.IArguments; -import dan200.computercraft.api.lua.LuaException; -import dan200.computercraft.api.lua.MethodResult; -import dan200.computercraft.api.peripheral.IComputerAccess; - -/** - * Implementation for common storage peripheral functions. Used for AE2 {@link de.srendi.advancedperipherals.common.addons.computercraft.peripheral.MeBridgePeripheral} - * and RS {@link de.srendi.advancedperipherals.common.addons.computercraft.peripheral.RsBridgePeripheral} - *

- * This ensures that these both bridges use the same methods. This makes it easier to support both in the same script - * In case there is a new mod which adds new ways to store and craft items, this ensures that the new peripheral - * has the same functions as the other ones - *

- * Implementation needs to override {@link dan200.computercraft.api.lua.LuaFunction} - */ -public interface IStorageSystemPeripheral { - - MethodResult isConnected(); - - MethodResult isOnline(); - - MethodResult getItem(IArguments arguments) throws LuaException; - - MethodResult getFluid(IArguments arguments) throws LuaException; - - MethodResult listItems(); - - MethodResult listFluids(); - - MethodResult listCraftableItems(); - - MethodResult listCraftableFluids(); - - MethodResult listCells(); - - MethodResult listDrives(); - - MethodResult importItem(IComputerAccess computer, IArguments arguments) throws LuaException; - - MethodResult exportItem(IComputerAccess computer, IArguments arguments) throws LuaException; - - MethodResult importFluid(IComputerAccess computer, IArguments arguments) throws LuaException; - - MethodResult exportFluid(IComputerAccess computer, IArguments arguments) throws LuaException; - - MethodResult getFilteredPatterns(IArguments arguments) throws LuaException; - - MethodResult getPatterns(); - - MethodResult getStoredEnergy(); - - MethodResult getEnergyCapacity(); - - MethodResult getEnergyUsage(); - - MethodResult getAvgPowerInjection(); - - MethodResult getTotalExternItemStorage(); - - MethodResult getTotalExternFluidStorage(); - - MethodResult getTotalItemStorage(); - - MethodResult getTotalFluidStorage(); - - MethodResult getUsedExternItemStorage(); - - MethodResult getUsedExternFluidStorage(); - - MethodResult getUsedItemStorage(); - - MethodResult getUsedFluidStorage(); - - MethodResult getAvailableExternItemStorage(); - - MethodResult getAvailableExternFluidStorage(); - - MethodResult getAvailableItemStorage(); - - MethodResult getAvailableFluidStorage(); - - MethodResult craftItem(IComputerAccess computer, IArguments arguments) throws LuaException; - - MethodResult getCraftingTasks(); - - MethodResult cancelCraftingTasks(IArguments arguments) throws LuaException; - - MethodResult craftFluid(IComputerAccess computer, IArguments arguments) throws LuaException; - - MethodResult isItemCraftable(IArguments arguments) throws LuaException; - - MethodResult isItemCrafting(IArguments arguments) throws LuaException; - - MethodResult isFluidCraftable(IArguments arguments) throws LuaException; - - MethodResult isFluidCrafting(IArguments arguments) throws LuaException; - -} diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java index f44bb19f9..bd943c892 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java @@ -1,7 +1,5 @@ package de.srendi.advancedperipherals.common.util.inventory; -import appeng.api.stacks.AEItemKey; -import appeng.api.stacks.GenericStack; import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.core.apis.TableHelper; import de.srendi.advancedperipherals.AdvancedPeripherals; @@ -19,7 +17,7 @@ import java.util.Map; -public class ItemFilter extends GenericFilter { +public class ItemFilter { private Item item = Items.AIR; private TagKey tag = null; @@ -69,14 +67,14 @@ public static Pair parse(Map item) { } if (item.containsKey("fromSlot")) { try { - itemFilter.fromSlot = TableHelper.getIntField(item, "fromSlot") - 1; + itemFilter.fromSlot = TableHelper.getIntField(item, "fromSlot"); } catch (LuaException luaException) { return Pair.of(null, "NO_VALID_FROMSLOT"); } } if (item.containsKey("toSlot")) { try { - itemFilter.toSlot = TableHelper.getIntField(item, "toSlot") - 1; + itemFilter.toSlot = TableHelper.getIntField(item, "toSlot"); } catch (LuaException luaException) { return Pair.of(null, "NO_VALID_TOSLOT"); } @@ -114,14 +112,6 @@ public ItemStack toItemStack() { return result; } - @Override - public boolean test(GenericStack genericStack) { - if (genericStack.what() instanceof AEItemKey aeItemKey) { - return test(aeItemKey.toStack()); - } - return false; - } - public boolean test(ItemStack stack) { if (!fingerprint.isEmpty()) { String testFingerprint = ItemUtil.getFingerprint(stack); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemUtil.java index fbd61f7f2..665283d73 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemUtil.java @@ -4,6 +4,7 @@ import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.util.StringUtil; import net.minecraft.ResourceLocationException; +import net.minecraft.core.NonNullList; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -26,6 +27,9 @@ public class ItemUtil { public static final Item POCKET_NORMAL = Registry.ModItems.POCKET_COMPUTER_NORMAL.get(); public static final Item POCKET_ADVANCED = Registry.ModItems.POCKET_COMPUTER_ADVANCED.get(); + private ItemUtil() { + } + public static T getRegistryEntry(String name, IForgeRegistry forgeRegistry) { ResourceLocation location; try { @@ -83,6 +87,17 @@ public static List getItemsFromItemHandler(IItemHandler handler) { return items; } + public static void addComputerItemToTab(ResourceLocation turtleID, ResourceLocation pocketID, NonNullList items) { + if (turtleID != null) { + items.add(makeTurtle(TURTLE_ADVANCED, turtleID.toString())); + items.add(makeTurtle(TURTLE_NORMAL, turtleID.toString())); + } + if (pocketID != null) { + items.add(makePocket(POCKET_ADVANCED, pocketID.toString())); + items.add(makePocket(POCKET_NORMAL, pocketID.toString())); + } + } + public static ResourceLocation getRegistryKey(Item item) { return ForgeRegistries.ITEMS.getKey(item); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrade.java b/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrade.java index ce91b0037..37509a075 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrade.java +++ b/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrade.java @@ -115,10 +115,10 @@ private TradeBuilder(WandererTradesEvent event, ItemStack stack, Type type, int * This one is for normal villagers with any type of{@link ItemLike}. * {@link net.minecraft.world.item.Item} or {@link net.minecraft.world.level.block.Block} as example. * - * @param event this should be executed in an event - pass the villager trade event here - * @param itemLike the item for trade - * @param type the trade type - * @param emeraldAmount the emerald amount of the trade + * @param event this should be executed in an event - pass the villager trade event here + * @param itemLike the item for trade + * @param type the trade type + * @param emeraldAmount the emerald amount of the trade * @param professionLevel the profession level of the villager. 1 to 5 * @return a builder instance */ @@ -130,10 +130,10 @@ public static TradeBuilder createTrade(VillagerTradesEvent event, ItemLike itemL * Creates a new TradeBuilder instance. Can be used to create villager trades for normal villagers * This one is for normal villagers with item stacks * - * @param event this should be executed in an event - pass the villager trade event here - * @param itemStack the item for trade - * @param type the trade type - * @param emeraldAmount the emerald amount of the trade + * @param event this should be executed in an event - pass the villager trade event here + * @param itemStack the item for trade + * @param type the trade type + * @param emeraldAmount the emerald amount of the trade * @param professionLevel the profession level of the villager. 1 to 5 * @return a builder instance */ @@ -146,10 +146,10 @@ public static TradeBuilder createTrade(VillagerTradesEvent event, ItemStack item * This one is for wandering traders with any type of{@link ItemLike}. * {@link net.minecraft.world.item.Item} or {@link net.minecraft.world.level.block.Block} as example. * - * @param event this should be executed in an event - pass the villager trade event here - * @param itemLike the item for trade - * @param type the trade type - * @param emeraldAmount the emerald amount of the trade + * @param event this should be executed in an event - pass the villager trade event here + * @param itemLike the item for trade + * @param type the trade type + * @param emeraldAmount the emerald amount of the trade * @param professionLevel the profession level of the villager. 1 to 5 * @return a builder instance */ @@ -161,10 +161,10 @@ public static TradeBuilder createTrade(WandererTradesEvent event, ItemLike itemL * Creates a new TradeBuilder instance. Can be used to create villager trades for wandering traders. * This one is for normal villagers with item stacks * - * @param event this should be executed in an event - pass the villager trade event here - * @param itemStack the item for trade - * @param type the trade type - * @param emeraldAmount the emerald amount of the trade + * @param event this should be executed in an event - pass the villager trade event here + * @param itemStack the item for trade + * @param type the trade type + * @param emeraldAmount the emerald amount of the trade * @param professionLevel the profession level of the villager. 1 to 5 * @return a builder instance */ @@ -213,10 +213,10 @@ public TradeBuilder setXp(int xp) { */ public void build() { VillagerTrade trade = new VillagerTrade(type, emeraldAmount, itemAmount, maxUses, xp, item, itemStack); - if (wandererEvent != null) { - if (professionLevel == 1) + if(wandererEvent != null) { + if(professionLevel == 1) wandererEvent.getGenericTrades().add(trade); - if (professionLevel == 2) + if(professionLevel == 2) wandererEvent.getRareTrades().add(trade); return; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrades.java b/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrades.java index f0ea18dd3..539e5089d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrades.java +++ b/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrades.java @@ -2,10 +2,10 @@ import dan200.computercraft.shared.Registry; import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.common.setup.APBlocks; -import de.srendi.advancedperipherals.common.setup.APItems; -import de.srendi.advancedperipherals.common.setup.APVillagers; +import de.srendi.advancedperipherals.common.setup.Blocks; import de.srendi.advancedperipherals.common.setup.CCRegistration; +import de.srendi.advancedperipherals.common.setup.Items; +import de.srendi.advancedperipherals.common.setup.Villagers; import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; import net.minecraftforge.event.village.VillagerTradesEvent; import net.minecraftforge.event.village.WandererTradesEvent; @@ -19,7 +19,7 @@ public class VillagerTrades { @SubscribeEvent public static void registerWanderingTrade(WandererTradesEvent event) { - TradeBuilder.createTrade(event, APBlocks.PERIPHERAL_CASING.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 1, 1) + TradeBuilder.createTrade(event, Blocks.PERIPHERAL_CASING.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 1, 1) .setMaxUses(8) .build(); TradeBuilder.createTrade(event, Registry.ModBlocks.TURTLE_ADVANCED.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 2, 1) @@ -29,24 +29,24 @@ public static void registerWanderingTrade(WandererTradesEvent event) { @SubscribeEvent public static void registerVillagerTrades(VillagerTradesEvent event) { - if (event.getType() == APVillagers.COMPUTER_SCIENTIST.get()) { + if (event.getType() == Villagers.COMPUTER_SCIENTIST.get()) { - TradeBuilder.createTrade(event, APBlocks.PERIPHERAL_CASING.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 1, 1) + TradeBuilder.createTrade(event, Blocks.PERIPHERAL_CASING.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 1, 1) .setXp(1) .build(); - TradeBuilder.createTrade(event, APBlocks.CHAT_BOX.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 2, 1) + TradeBuilder.createTrade(event, Blocks.CHAT_BOX.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 2, 1) .build(); TradeBuilder.createTrade(event, Registry.ModBlocks.MONITOR_NORMAL.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 2, 1) .setItemAmount(2) .build(); - TradeBuilder.createTrade(event, APBlocks.PERIPHERAL_CASING.get(), VillagerTrade.Type.EMERALD_FOR_ITEM, 1, 1) + TradeBuilder.createTrade(event, Blocks.PERIPHERAL_CASING.get(), VillagerTrade.Type.EMERALD_FOR_ITEM, 1, 1) .setMaxUses(5) .build(); - TradeBuilder.createTrade(event, APBlocks.INVENTORY_MANAGER.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 2, 2) + TradeBuilder.createTrade(event, Blocks.INVENTORY_MANAGER.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 2, 2) .setXp(4) .build(); - TradeBuilder.createTrade(event, APBlocks.REDSTONE_INTEGRATOR.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 2, 2) + TradeBuilder.createTrade(event, Blocks.REDSTONE_INTEGRATOR.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 2, 2) .setXp(3) .build(); TradeBuilder.createTrade(event, Registry.ModBlocks.COMPUTER_ADVANCED.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 3, 2) @@ -61,11 +61,11 @@ public static void registerVillagerTrades(VillagerTradesEvent event) { .setMaxUses(4) .setXp(7) .build(); - TradeBuilder.createTrade(event, APItems.CHUNK_CONTROLLER.get(), VillagerTrade.Type.EMERALD_FOR_ITEM, 5, 3) + TradeBuilder.createTrade(event, Items.CHUNK_CONTROLLER.get(), VillagerTrade.Type.EMERALD_FOR_ITEM, 5, 3) .setMaxUses(6) .setXp(8) .build(); - TradeBuilder.createTrade(event, APItems.COMPUTER_TOOL.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 1, 3) + TradeBuilder.createTrade(event, Items.COMPUTER_TOOL.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 1, 3) .setMaxUses(1) .setXp(16) .build(); @@ -74,25 +74,25 @@ public static void registerVillagerTrades(VillagerTradesEvent event) { .setItemAmount(4) .build(); - TradeBuilder.createTrade(event, APBlocks.ENERGY_DETECTOR.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 4, 4) + TradeBuilder.createTrade(event, Blocks.ENERGY_DETECTOR.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 4, 4) .setXp(6) .build(); TradeBuilder.createTrade(event, Registry.ModBlocks.COMPUTER_ADVANCED.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 4, 4) .setXp(5) .setMaxUses(3) .build(); - TradeBuilder.createTrade(event, APItems.MEMORY_CARD.get(), VillagerTrade.Type.EMERALD_FOR_ITEM, 2, 4) + TradeBuilder.createTrade(event, Items.MEMORY_CARD.get(), VillagerTrade.Type.EMERALD_FOR_ITEM, 2, 4) .setXp(4) .build(); TradeBuilder.createTrade(event, ItemUtil.makeTurtle(ItemUtil.TURTLE_ADVANCED, CCRegistration.ID.CHUNKY_TURTLE.toString()), VillagerTrade.Type.ITEM_FOR_EMERALD, 8, 4) .setXp(7) .build(); - TradeBuilder.createTrade(event, APItems.CHUNK_CONTROLLER.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 6, 4) + TradeBuilder.createTrade(event, Items.CHUNK_CONTROLLER.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 6, 4) .setMaxUses(6) .setXp(6) .build(); - TradeBuilder.createTrade(event, APBlocks.ME_BRIDGE.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 4, 5) + TradeBuilder.createTrade(event, Blocks.ME_BRIDGE.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 4, 5) .setItemAmount(2) .setXp(4) .build(); diff --git a/src/main/java/de/srendi/advancedperipherals/lib/metaphysics/IFeedableAutomataCore.java b/src/main/java/de/srendi/advancedperipherals/lib/metaphysics/IFeedableAutomataCore.java index c8a4586ab..6c3534300 100644 --- a/src/main/java/de/srendi/advancedperipherals/lib/metaphysics/IFeedableAutomataCore.java +++ b/src/main/java/de/srendi/advancedperipherals/lib/metaphysics/IFeedableAutomataCore.java @@ -1,4 +1,3 @@ package de.srendi.advancedperipherals.lib.metaphysics; -public interface IFeedableAutomataCore { -} +public interface IFeedableAutomataCore {} diff --git a/src/main/java/de/srendi/advancedperipherals/network/APNetworking.java b/src/main/java/de/srendi/advancedperipherals/network/APNetworking.java new file mode 100644 index 000000000..f1064f26e --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/network/APNetworking.java @@ -0,0 +1,75 @@ +package de.srendi.advancedperipherals.network; + +import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.network.base.IPacket; +import de.srendi.advancedperipherals.network.toclient.ToastToClientPacket; +import net.minecraft.core.BlockPos; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraftforge.common.util.FakePlayer; +import net.minecraftforge.fml.ModLoadingContext; +import net.minecraftforge.network.NetworkDirection; +import net.minecraftforge.network.NetworkRegistry; +import net.minecraftforge.network.PacketDistributor; +import net.minecraftforge.network.simple.SimpleChannel; + +import java.util.Optional; +import java.util.function.Function; + +public class APNetworking { + private static final String PROTOCOL_VERSION = ModLoadingContext.get().getActiveContainer().getModInfo().getVersion().toString(); + private static final SimpleChannel NETWORK_CHANNEL = NetworkRegistry.newSimpleChannel(new ResourceLocation(AdvancedPeripherals.MOD_ID, "main_channel"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals); + private static int id = 0; + + public static void init() { + registerServerToClient(ToastToClientPacket.class, ToastToClientPacket::decode); + } + + public static void registerServerToClient(Class packet, Function decode) { + NETWORK_CHANNEL.registerMessage(id++, packet, IPacket::encode, decode, IPacket::handle, Optional.of(NetworkDirection.PLAY_TO_CLIENT)); + } + + public static void registerClientToServer(Class packet, Function decode) { + NETWORK_CHANNEL.registerMessage(id++, packet, IPacket::encode, decode, IPacket::handle, Optional.of(NetworkDirection.PLAY_TO_SERVER)); + } + + /** + * Sends a packet to the server.

+ * Must be called Client side. + */ + public static void sendToServer(Object msg) { + NETWORK_CHANNEL.sendToServer(msg); + } + + /** + * Send a packet to a specific player.

+ * Must be called Server side. + */ + public static void sendTo(Object msg, ServerPlayer player) { + if (!(player instanceof FakePlayer)) { + NETWORK_CHANNEL.send(PacketDistributor.PLAYER.with(() -> player), msg); + } + } + + public static void sendPacketToAll(Object packet) { + NETWORK_CHANNEL.send(PacketDistributor.ALL.noArg(), packet); + } + + public static ClientboundBlockEntityDataPacket createTEUpdatePacket(BlockEntity tile) { + return ClientboundBlockEntityDataPacket.create(tile); + } + + public static void sendToAllAround(Object mes, ResourceKey dim, BlockPos pos, int radius) { + NETWORK_CHANNEL.send(PacketDistributor.NEAR.with(() -> new PacketDistributor.TargetPoint(pos.getX(), pos.getY(), pos.getZ(), radius, dim)), mes); + } + + public static void sendToAllInWorld(Object mes, ServerLevel world) { + NETWORK_CHANNEL.send(PacketDistributor.DIMENSION.with(world::dimension), mes); + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/network/base/IPacket.java b/src/main/java/de/srendi/advancedperipherals/network/base/IPacket.java similarity index 89% rename from src/main/java/de/srendi/advancedperipherals/common/network/base/IPacket.java rename to src/main/java/de/srendi/advancedperipherals/network/base/IPacket.java index 1374f5bff..9a52059bb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/network/base/IPacket.java +++ b/src/main/java/de/srendi/advancedperipherals/network/base/IPacket.java @@ -1,4 +1,4 @@ -package de.srendi.advancedperipherals.common.network.base; +package de.srendi.advancedperipherals.network.base; import net.minecraft.network.FriendlyByteBuf; import net.minecraftforge.network.NetworkEvent; diff --git a/src/main/java/de/srendi/advancedperipherals/common/network/toclient/ToastToClientPacket.java b/src/main/java/de/srendi/advancedperipherals/network/toclient/ToastToClientPacket.java similarity index 90% rename from src/main/java/de/srendi/advancedperipherals/common/network/toclient/ToastToClientPacket.java rename to src/main/java/de/srendi/advancedperipherals/network/toclient/ToastToClientPacket.java index 3536d9462..e2a804eff 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/network/toclient/ToastToClientPacket.java +++ b/src/main/java/de/srendi/advancedperipherals/network/toclient/ToastToClientPacket.java @@ -1,8 +1,8 @@ -package de.srendi.advancedperipherals.common.network.toclient; +package de.srendi.advancedperipherals.network.toclient; import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.common.network.base.IPacket; import de.srendi.advancedperipherals.common.util.ToastUtil; +import de.srendi.advancedperipherals.network.base.IPacket; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; import net.minecraftforge.fml.loading.FMLEnvironment; diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index dc4a3126c..be93663b7 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -2,5 +2,3 @@ public net.minecraft.world.level.block.entity.BeaconBlockEntity f_58652_ public net.minecraft.world.level.block.entity.BeaconBlockEntity f_58653_ public-f net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool f_210559_ # rawTemplates public-f net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool f_210560_ # templates -protected net.minecraft.world.level.ClipContext f_45686_ # collisionContext -public net.minecraft.world.level.block.entity.BeaconBlockEntity f_58650_ # levels \ No newline at end of file diff --git a/src/main/resources/assets/advancedperipherals/models/item/ar_goggles.json b/src/main/resources/assets/advancedperipherals/models/item/ar_goggles.json new file mode 100644 index 000000000..8cedf86ab --- /dev/null +++ b/src/main/resources/assets/advancedperipherals/models/item/ar_goggles.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "advancedperipherals:item/ar_goggles" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/advancedperipherals/models/item/memory_card.json b/src/main/resources/assets/advancedperipherals/models/item/memory_card.json index c39681fc7..0579cb7a6 100644 --- a/src/main/resources/assets/advancedperipherals/models/item/memory_card.json +++ b/src/main/resources/assets/advancedperipherals/models/item/memory_card.json @@ -1,14 +1,6 @@ { - "parent": "minecraft:item/generated", + "parent": "item/generated", "textures": { "layer0": "advancedperipherals:item/memory_card" - }, - "overrides": [ - { - "predicate": { - "advancedperipherals:bounded": 1 - }, - "model": "advancedperipherals:item/memory_card_bounded" - } - ] + } } \ No newline at end of file diff --git a/src/main/resources/assets/advancedperipherals/models/item/memory_card_bounded.json b/src/main/resources/assets/advancedperipherals/models/item/memory_card_bounded.json deleted file mode 100644 index cf7733990..000000000 --- a/src/main/resources/assets/advancedperipherals/models/item/memory_card_bounded.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "parent": "item/generated", - "textures": { - "layer0": "advancedperipherals:item/memory_card_bounded" - } -} \ No newline at end of file diff --git a/src/main/resources/assets/advancedperipherals/models/item/smart_glasses.json b/src/main/resources/assets/advancedperipherals/models/item/smart_glasses.json deleted file mode 100644 index bc29777ce..000000000 --- a/src/main/resources/assets/advancedperipherals/models/item/smart_glasses.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "parent": "item/generated", - "textures": { - "layer0": "advancedperipherals:item/smart_glasses" - } -} \ No newline at end of file diff --git a/src/main/resources/assets/advancedperipherals/textures/gui/corners_glasses.png b/src/main/resources/assets/advancedperipherals/textures/gui/corners_glasses.png deleted file mode 100644 index 18cf12823149b6195ab687d0015a1f5a3d098a85..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 999 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G!U;i$lZxy-8q?;3=GT*JzX3_ zD(1YsyVv)Pg9zIN!y?wpP0|WV3#Yz4V4Cw}MuGJLQT6D9TqhSXt9vY|J1G3(E%%R) zRkky#{n(O03DNFy%!^aBOcwJ|R4&9y`y{oOeBsP2(%Z)X&FR?N_y`rzL zzcibHYa?^R0Tu=pH3kI(MutXC1`ZzvhlH;NJRrH1TbP_<@)#8i(t&vG0f8CO5NRd` zCSeAF84O^Z%S0uZHUkZr!wU2ULqq&JpvC#_P4-rj7Cg?ce*gQs@b)Br{{OWTzK5Mp z-@0VVxmS$)*3bJ{etA+c3t#);6ve~8o_%5T`Te)LrOLyMmKYOoTLeRiF}cqePafpulv6E58si+}KZR}_PZ@8V#AI*aXaUqJmY%HMGLWymfT zj@P&Uv&kIaXeGmUId8kSzrX+W6`T<#*T^2Q=)3y(@#96UGX3ttb&08)r5k}^JZ;Xy z^pDIy?;j`)iLO`fZ*Mn<-}}}0ckK14dW>eP%hKc@Y2D-EnWBsm$|%8z8UaA5)$NHI zvCIJ-vJ5O~DiWZu{Zn+mu3=j7ynAk)^(KK85^X>qdTB1*mTUhv$4m2T?fZptYcjsw zZrq>r`n^oU{dZZ67fjB!hu1E!>2-j`7KSy5h=d0LL-NUmb0QC$7o7w7{rvg!-D1fK z9BZ<_C7rhP|Ni}Zw`kJG!@u;R3cU9PA9%#xAi6icRDb8J-BpLp_MT;#qbK>`X6ap{ zs|>4md20Ip{=2V4)`79~+|M`SYCoN1(t91m?2iQP5f;#J2c|TXFbL~^JR>eXKG^Hr tGiMWX&84p%K3oXW%*PDMFoOofe`Y_F^FYB_FMSutO`fiPF6*2UngGweOez2X diff --git a/src/main/resources/assets/advancedperipherals/textures/gui/smart_glasses_gui.png b/src/main/resources/assets/advancedperipherals/textures/gui/smart_glasses_gui.png deleted file mode 100644 index 7606b08a65e7bfeb87fa72ceebe827b2749a6be0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1974 zcmdT_X;2eJ7~KR2AcJwph*Q8|@qo4pIDkY>wV+}+)DjT^NlQhJCNW?*gNaxVDu*4M zAsodB5-@>;QXm{cKw79I6_8>e0TT^}0^tZE5R%Y9#~+=x{&)ZE?!5VC-rM)yY{p6d zW5%1zHUR*PeU5vb1^}WxLVy8GyM@M8M6TcBPaiu1*iS9q0HA-#$LnxlQjvTFjYkAq zcD|%w1Y!A+gRg3!wqgTwEPMz&xwXAoe^+M`+_!Y^jvsVQuG#E_n&hDtjnma*P{TVl zM3qO+19Opuklxe7&ULxT&~U!M{^-P0X5k|uB07ao!L!@j?3n)E^nJOOR+Uv%n4gpk zPn5butyTwz!R^0vb#<+4YC6~PvYKTn(G|(;>{mWTr_Q6P-n+q;X@OZAQ7jh!(zKa= z5sq|gm~)zd(U~zQi+6GR+omfy9ASCDJzMg~b;$BdfsSt5uu^_gSqV90520eApj{WF z8vP;b%!{9#ey+04Bj?Mzt$?0qZTe(^_CF-2CSieIZhwWu^<_E(YVI`3pJ-s zfLqlyHP86P>E2?S-C*vfX>{q`zsCg`hdT3DiL~N)onGPN4c&1@?`60q8q<4t{?X?< z8{;SZ(=@7NJi80EEk_n8eM9`bdYz$BM!(GT-?f^6v{|05%{mPQ6l~vt6ODTR*}t!@ zW;ra$?A`q^By)3f45p<>3Kf*k8-{D^KN&UCtVjKJqqR`gBvmrr<=L!tTQoG3Ke83F z_UpV8b$oC(k;P)IjiytFP#!A*Dn5L~mjk2KA>vz;wQPehPG(um=mMo;3_a4Cma5p< z-WL^!6QAjK9H_@_M#$DKR?9qF5n&(G?q;3JKkc z!%%YTqYGTz+%6k|Ag>TiZuzQhtg8R}`2Zd2%JXbb_3GJ1PZX+x$>fCd&Zq3fDn;|< zlzZXg)f6_Mu@l^awSrc1?DS}L392U&;Ssv`p#~R`_6a7N*vb?n9T&m{m%MAkTgeX@ z(UW2>ArJW-nL!0@1HGGJ*OVG{svQ@|2nakx8WUB>c-W5ZMT42)Mu&sDE9_()-i$Xv z){Ms`=7HPY+n2OjQxu~<&K|?1TGA*K%|b6hCC%v<)mMdZ@qU`&B-c4dYmSdmp7T%x zkIM~0qtO@f`bSGoh4HSm94+n3Hz@Mh`ufrF(C6dhkpnr`To_I(0rzN|ZsV()n?o!; z$TTv}Qo_se{4Kx|>Y_PtN%ecRO#cRwQZm=|K+ez47+Sbb_e_Ip|Jr{pTE-e=;bL$5 SvF^*6>xhrHzZd%mHvKO?S3ZjX diff --git a/src/main/resources/assets/advancedperipherals/textures/item/smart_glasses.png b/src/main/resources/assets/advancedperipherals/textures/item/ar_goggles.png similarity index 100% rename from src/main/resources/assets/advancedperipherals/textures/item/smart_glasses.png rename to src/main/resources/assets/advancedperipherals/textures/item/ar_goggles.png diff --git a/src/main/resources/assets/advancedperipherals/textures/slot/empty_glasses_slot.png b/src/main/resources/assets/advancedperipherals/textures/item/empty_glasses_slot.png similarity index 100% rename from src/main/resources/assets/advancedperipherals/textures/slot/empty_glasses_slot.png rename to src/main/resources/assets/advancedperipherals/textures/item/empty_glasses_slot.png diff --git a/src/main/resources/assets/advancedperipherals/textures/item/memory_card.png b/src/main/resources/assets/advancedperipherals/textures/item/memory_card.png index 27df1d9f4374d215f0ffe85a37dc7db8927be606..6da07f35e3f043f394b9b0813641b774c0cd2b69 100644 GIT binary patch delta 750 zcmVh3jcw&f~|reD1wNMf52BGVZCDl z38IBF%-)YPdoD9)z!}Nw1_{G>Qr=QqV> zJUS(JQ$2mz7S>u=&zS|`fUv)iujq~QsGE4w#rc@j0a=4sM42Is4~+^d}(G~3O!La=AUH$^xg=hK?l7Gpj00009a7bBm000ic000ic z0Tn1pfB*miHc3Q5R5(w~lD$rZKoo_KBun@S0b>Y-8cp2oC@E|pF&0!?TGjxXU@GD{5c1W_HZ1h76bud7=q_{ zuq+GD^M88hnMONoFUN5VP18^m1tdv=>$-Jwq-D^6u$(Qix>&*YeFQ;(g|a|dmd);t zL4z#Iz(4YkpJmi{HBCa+B*{+(4M<#aDY}iQ(d2$Y>#C|!-Dl9Cswx~^-C+Jc$9i@N z`^|=BS#+QqI)fZ-A&(`dq@-=LbYlge=QVb;sxo$jh&} zh%`;19G`$;nEezjV=ZL%^pLipC`#K7G5$5CY1R)<(^}Vcs)k|oJ`rIs0U^(GoSrG* gIF2g$&i@hM8$tPbpXQ3R-T(jq07*qoM6N<$f(C?HbpQYW delta 678 zcmV;X0$Kfr2EGN5B!72lLqkwWLqi}?a&Km7Y-IodD3NuMJ4*vW6otP$MA1kJMMNx8 zsHBJ>3Sub{OcO1V2u5v^HJb>#>$005!B()b2v~?Vz6$?=wt}sKASi-}jeo#bBeLEx zLPT_y+52&3&SmBd_>+cay1^kZt+JC!#3QrWxk&RPK>~CUCV!gKTze`#nc?5@c8yQf zt3lQ4|9yXsw#9<0fv-h)RI{D3@VIbtrEDwS5bo4UxkceU;g}-_6h2pazRnMdi*||0C;8#5(#UGsi!CJ{Ng`>iKrcu$p&!cVONPJ}!amM|zYDAkh8 z{`L)h`KDPGkAEhAn<|btij>3~6SX2;3sQB_3-TFMRqns@boG(pdiPKqn(jUCxgVN0 z;iKkx@B5zjaR7lkIJFx7WyxvmRrFdz>)VC!8XTWBwEPyFtV8#$opW+uQb49(*Wu|1 z+OyDc39a+>tiIPdyn)QBJkbSg@4$fU4=;QI+=XZQCVyl04*&oG0!c(cR5*?8k+Dhx zK@>$#_Bj$E16c@xpx7A2authh_Aj>dyX=LO`wRYnrqd#(unjDMEml^U;UyNbLsrx; z$ZZB@xaYn%7xwD?yvXx>YmE8VYqZv)s)z_8!o$levR)w~s47X41W42Z zPNt7sXMayvYlCsIoa3AeW*3hU5v;YeVFxXsm~9vi`()X7imGyXaRY#e@UB~q)+^j- zf~tmf0wBMQI6nR4?U`U|PZy6FR3#utRU$GCfUrU_+i-u^59t7l4Tx04R}lkvmHRK@^3*JVen*3PnULQmCYeAPQnB5lj;;k_bj^k~NzMyX&%> zAi-9!u?Sd*Hogk~fwqFJf*>e@h>d^1S0l3CF+xOimf8DpX3k~i4EU3VX1c*4Fs-ta zO2i|x*||vbBS8Xm5hj|`Tze`#nc?5@c8yQft3lQ4|9yXsw#9<0fv-h)RI{D3@VIbt zrEDwS5bo4UxkceU;g}-_6h2pazRnMdi*||0C;8#5(#UGsi!CJ{Ng`>iKrcu$p z&!cVONPJ}!amM|zYDAkh8{`L)h`KDPGk0yVcDvmgcl*AhowIW>$ zQgzV_@)=ZB?!WVN^^xIv_fQ;~?mh3hADTDeqvm<<`=0l40D(I=wHp3q$!Y9W^jbsf z+lBBN9G^9`{1%+7L-(znb8=r&K&D^U;pqt4v(Rw~t@HJ)zSlXtfy}Br(FJVpz<}%z zFMI;rg=hLEWA+aK0093Eyum%`+e_y2ZtK`ZWKka4a4wHk#ml+ zEC)TnPoXgeRYgP)5pJJfko5`?K~+i9)I)*}a5{V7Jb%O(eumr;wm6H`{MO!cNY3y8|qfIjYKWT>)UDxcAksFr;Z3pTou59qfbqBw$om*vXW( hZE?>1&o>?lz5!bDZ#f#Oo=N}!002ovPDHLkV1le|LYe>o diff --git a/src/main/resources/assets/advancedperipherals/textures/models/ar_goggles.png b/src/main/resources/assets/advancedperipherals/textures/models/ar_goggles.png new file mode 100644 index 0000000000000000000000000000000000000000..5ec507c48ee0a0c05dbc570c76a83bd57baf4645 GIT binary patch literal 1133 zcmaJ=&r1|h93M4Hwj>WB=s||@&=1|6A3D44wgQBW7FH@d4G+#WOYetkZl@6Wjv@9VDg z)%pm6sEqYU2|Ul>x4q&h{;qFKPvfZub*4~1OrxA)10t%yAwb3qWf&xYqD_pgfL4Mi zqx577rR0l(3XOo`VFIpUVKzauwz-y~jsQdsfnnW@P}@(IDN@%W)BrCtvL%9y-ZN=~ z{>i?iIys_-HLC3b+3E^dzyL@gU1QXA1UEwM>I!)69n%!K3qd0hYR{>Z94AF+1CkFk z`BjEx$zU+RHuJ$C+emT@%h3#ef_}DH;DZ7eBJ+d7)@&^;B&4pqExe0R8H6l>rgOPm zAlDRt_At$c!(mT@qbLk(je?VtoW@b^$*CplpOIsqJ*wN+fWbiHTF5=0v)2--;q zM+;euXCQ)323n-pA0*EV=%xm9&e>hOEDJHyL5it@m=vL~LO|CwAsh{LMWan2QRGCH z?c`cGo)LMmh2cd$)FFult_0Pr0ZdfjY6skwqFk>P3=3P9fUS=Mt;>c6xf`;e7x#rP zs+Z?##eE4D<Gei|p+D;t0 z`8BpV8kHJ%w%qg$c7D0^<;vp7{ImNf*B&mMpPH&JXWm`?R-4|QYMYyzdc68|IrZvy z&5x($cNgB?yi)gKX8CfcYp}PWt?bmX_|}8*N3i5jE5+>}-1zEBPY~JD4O|v(yddz1 Mb@oXM9fQ~Y0tFming9R* literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/advancedperipherals/textures/models/armor/smart_glasses_layer_1.png b/src/main/resources/assets/advancedperipherals/textures/models/armor/smart_glasses_layer_1.png deleted file mode 100644 index c94f2085af38b661aefa042c3799e03f04ca10e1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 191 zcmeAS@N?(olHy`uVBq!ia0vp^4M6O`!3HERU8}DLQjEnx?oJHr&dIz4awc$NjW7%?NU@;8sFWCxCPY98AQ~7z2asYwiVdX*1OXj}nh+^Um0l+b zj5KKh8Ay;4K&pUX0TL-8l!Q_whC@vEbcGb-QyP{o%JeQq4je>00?ZpHx3S5*GWC;}>kl2`spr zRyNYhoa29WV&YhU+=0-aI2o0jUe~rF2QO$zTUkHLizfyh^1h%xT&$^=rWAj>Pl$P4 z^R&sv=vviyV*U-Epe@erq{}2{^#Q)GkF^*iQb%P$|3iL>z5Y7Mxvrb_wd=h@mW%z) zNm0E`x1Y{EZN1CULrLe|s9c);t13l+!yau_zZ8JIpZQze*Ej1|1x-y9+9)Xcr&=on zQ_yhASr47QI-k~1&mM_K<;Y^@#BQJhuZzWO+-)!|o-WBgP9&eJ(WG(AS|6lObJOs~ z=?)#-GINK9TMiN;0gSfK7tn4?p5|AK>#aomOWsTNmp-jxd|1wvZ?U>U=sbX*Dooj0 zdWCzsKbbh;=IU}(L~`wpHkxH(ZyCS#(FS|xlmrz=0ue|qz+^E_i! zxpi^wL6%eTagY9seLa#{CTm#{ipQFAGk%TgN2C1idD|ghGKn}gHz$%qI=y&KA@O>D)1849dwKlA zK&H-IM^|(-P9FU+wPkv7%AaWO$Gt}k(<7%(PNk|M6TKD>>z>iZ_`dF=xIf6O(~C~{ z5^m6ifHNu54jzT`J>U2bx~=wD%s5`1`ob^Si&fqkvRBfyz0ruO9@Th3CZ95Ynb4($ zc-$h6&|x(j@s2Nn=k-!YWKsfJ5HhXQ2}3rlvJR{L+dM%Z^8SA_c!&*;h5gIz-wuo6 zW04E~a#ThdJi{0J@W+F8sh=8m&woaM!Yv1M0461!+h9MUOrJv(wp74qk3;rK5ZKB) z?;kkft*oQHQy+6r821$2RqBAF?p3J2M(Dcwwp+?Zr8enplTnyb>-=$v`iO<1?TohR z{|_qI*~W;^r?4wg@cN^8B@4{$ce2t145p(SnabxU$J?KnJQV7(q%5e{Dz8})q%6MwskmfZgsz4QaU8fLdnMyUoD?bDQV6UO ztPN2<*PJOe{xYEXH}2c+acnosEjFt~RiF)#t5NQDMc{<9a$Mtz%0;}3t&S|MCtJf) zSqEAwC(cEcVco94wA->j7D8nK76$-*JkZm68+YK)s&@C=t9 zRL3H9RkLUj*HeX>&dP?}F?`sq4pnGg6!EZsY!JR+?bPfVEtH}9p9flml|IWqG|;gUDov<)RVn3k3MjA=4+Lu1hm~sJJ3YuObb2x%~`*W8?ZVQG+;y z$-5zC+hu?g(Z@i&s0ZFyzmBB#<$y^D$vjX-77H~GJq!bmTU%wNuk&8ms26YgbKOo3B_lwBY+Sa0cqW22>>Lm|38 zq7YnoEny0>aLSRieyS)X6>qLO_er6nXpopDrQv zk%+?1oRwx6NH-{d3Tu|8hQfOTTWW?u4cwAJ>$-l&N7NsThktGXrCV5;{Zq)zDhWn_ z6pZxQ2-z=g*%V9f&K{y<9wZLv*{B4!HD<06*hctt;RKs-Y#|(IwnE(fiWsfZCfrjM z>qb1C!tzlrT+Y50Es+ul&M0y&Uxl!ovLNx0n&SBXPj&jGNi0EsNG7GW-<9hYT&M&)9dOlx-z9H>MPQMh~* zO1*dlpiJI$hFVl@0soR_mVWRUEL(7Toav|Hz{0V`cq2GqoU>7XDWq6C^uBIk20 z1oEdgbogW?#xpga)b*;`fnwd)Ygf;wcb_4)8nvr)wUX%S8I^qpa>L=4IWhFNXA+Ax zGvQRi{Rmyvos&lpmso=8a0eOCP{Bn-F)0#?UV#BP8Sm%kux1;Gk}^+3;pSmhbLLve z_p2A&hLFKKP@06w=kiIL_73U`7$T^;6#}5iV2!&98X=D!~5ce4m?`wzwY>L0LSphew5D;2@ppdo7$eQ@DxRAbAN4FGG zML1+l+-5)4Y)cP-Y}`5ku3?VSl1-p^$XcSmb_0If=7Fe#{6I&h9o~ZC1Rr5}qxiu- zz;S`|R|r6b#1EkZF5r|Fmz4~Zf*N-OaqEvYi6dwnTytaQW+>UBEb|75KBd%D}cSHyR z%6<>X7+OQ8Hp)X5>`Dwwd)J)=csVB~w4MFrz}%DxL&?BpWyFKWgjO(~n zb4>pU_N%#=Hby-uKV1$~U)%`e{B9hZQoZ&Rgy}UfMP5ZQ9L+rR#+<@{06p|nqu_n1 zX3`%0=DSv&QU(*HOua5; z_$Xgub!ouaTONm5LQpMybI7K!8pc894Xhc<@H<Mi6r9_BWsSzHQwO02+UZRT+>8B^!($6NRWW$O4?D za!3f-s0Ok4aXwQ`sjKUEUe%{Y$JJ?NOpZi{%ZQJR_-p=J4P8g%`vk{QAa{E7iL*6l6CSkbPAZ9c!n6OEmG*I z#X#nV=cA&k2|OOSZ&8_YMP05nF_y-*-j(^d&Cj#fCzwULzov~T7Dwve9QY$en}!ps zrtHdNK2f?%x*N!zrXshR>PrsV94tOG`b*gOpPjt>-hH!6bh#b*sUnuy_=Fz3!d2x; zNk-4-X~C)4I>ua+bMYb%eJa z-Jw>R?{FgC*mwE-#N=x=!TQnmwzdbq$qxO2$TKazA^dLGL1w^DhV6XqvTslESZX`# z?AejOl1!It)3XL8wE{jH3tBLrSO{^V+&9$S4=(GXE4tTz+NV=-)UQMyM{Fua1nRiA zFNQSu`o={TBZD?m$^pg;34Cd3#QQI!AEL}({&w6+=5JiX2bTvr zv+Ks+1Uhd{Fk&wSsOvwuIozay+h10C7G03EvE!UaJo+mC0HZenZMT1RX^ext6}>2@ zGNbUUenfCV4#^zta$e_MYcQIqwL;Dr>Q{MLjq}@m4AQUBN2yBRe}h7dpnHWiL}&Bq z_DXH1rLBygiOLEMj(ZpIHRQg09<_8xN7`5Lm&f5+%Z1$2sjRCNXVdQP!;g+m`hD#i zZo?7cf8ENjwG}y)+%Lw&y1Ht1CR{9gJ~>8D#;ZvCyiSu9?8)`5l?}&|b>dey%AfbW U5}#@Kd25%?A2&n;<96)$Kdd|T!~g&Q literal 6265 zcmcII30RZIwk^J(f`YF|SyZsqf+CV&SOg7RT4~E|fTBo{B_VLxS7nnWpje%jGc*60v&}hYW}=z8 z<-PUaS`%eC*rPcrDgC^*r*_0{W0hlRPzgVVgvB!LK8f#~?1rc{w%^bx3Dn$RanJO`@kZC%ixAxB=*kqwFMMVM3;xta9s}gp`#xFk$}+ zrnCqXZsjQe^jkpQgjTM@v!ti3!ONxLL>z!Qowr=yuz#mBfmxUKTQR@w z1GPWq$SOnJ{xe8`4*rghRnSlW9J&h|;Uu5ay_ESK+;>1+ zRe259_9?Z=lYWvXjk(BZnPy!`Y5&A6KXmK*@Yhu$gTl0HBeu?5n~T2wJ%jBkn%I6o&5R{*t5LeB92L*CoyT^olAJW7& zCEqQ71f;_3IL2p#59_2y3m@#zdiWYPYdw4e-lPs~3jY^Dc4-YK)EnP||KNcF+nY%A zkBYy8Fy?M=Ud9Bnoml+HrmRxUn|InhzqTz6^UzzhKRx_M0ir^4@=NNmm7n5t#kQRK zp4Cw=>i%WwmDW@&jWVFIH&8n=y);4=Uf&b#CwA~eS2{l;wxwd5YQ|2trf%|BpkSK@#!t7tgUToa16KVlZSww`wbWxcPn<4Y z_TR44r{>^uw6*LS8E2#i=_G)3%EJdJIH8Qc5afJ_Jb=(vM$;3<9T2s0G+e_r9TFY} z(t@Yly5G&_$kNj;u03_YG;`vVdjJYO*TP6HnyH#YbRsG>Xoi{2il-={llZ>&JN3j( zG+c)Qk&zt1uxKimRTghMWUw3ZNHP%YtjGW|QDxCdthomhQ4e25Z&6|-BRc*BRcI*O zTMtPPl^a8<&F9STx<0g@+t=ZoVZ- z&Nj;;75<9w`8mlcei~XgqreZ&~uz(-`Zf+v^&@Sk>Et^3}%+T zCewWxc=cV_WAC#C#B!Ku7*@tKv{4;m4*gfF^{xzb*kO_lOvrHSn?oK%NH0gMhfSZ_ zX~c+}*U5%l*=;kU>2E47sNQLNXsCIij8Yn9LGp!1atd##Wpq+&%*zSNj(e?n>fiS7vuu^0!Xm*5hbI(!h(QJ$ns(D1sQ(KT`BiBrL4 z|ArIga!Q>O2ZW>cTsxY;mvQCL((&74NOW06{Rw~hbriZ8ROOTU5vuIbz8-x3@?Lb9 z<~J$Rmk=F<9a`0jjjttx3$S&MYv{?lw{9J8e!o$KYX3FIJ&k3Pqs}m`o0_CAHAz-q7lXnUQnAKj zaY2psQD_8d3U;bc0iUmaiA8X|iJyR>W2S2`ZXZ+d??9hvJR7Lf<){2>*?dz!chG9J zYH)7(AT3dxP9)l1@a9B#+p$A&9fw%aNht>3ybFHHymPs}TRcqKXD|9rN}ORdh9FW7 z9TuOQGCcz{UfHG3C(;y&o}Wwh@QxI8%7WgmW4|{1gNRJE!}NMbF9VL7E;0v)xQg4p zhHG%VJ#`s}$UMYO!3`gNjc-KgVj`O0s{9Ps7xKJwHx^+YRS#DZd?#0GWjuO?vlm%Y zzDr>`>lo~#_KY^$fKP{73HAMYP@r|$G3TybcZFSge9?Z{pX;8!8f3%-ssqFxEmf3Wgr>UX z9@%{>2`qGAT!SNRItBQvNGK>epbw$zukaUHXiA){Wzin~qj7Klf2;Bzp@8F#lmo}D zud500NM?a%#-6x`_p$^WFwZ=TKU3xN9g=|tkeYlN63hX2yet8_M)d+;)C8<6x*lOb zS76X@DXVZltgqMsR)Cm@>IFX24N!lXjk%hHuwyiCW-qe!0;+?5`(<};Sz*X zH9OT_avFC$krmLXLU7Y{p0m_com8R*Z<%!MTxojM!vlPu={2RhVFM=XZ~opay1Iw1SML{xZchkK@0=8KMVC%sUn0l$F<^pS*JFr~VDtr|<_H}>#(>mozN_-`t1+@Wu0t(9N z1IsUwfaMlwu7xGo^4EOUi6NKm1y`a>i(3v56(nkX4szoTXhZj|_k?ORMrd?=GHcuS z6E1$uN4^EIq;`*FmDrA$-+j+dgO_*7v5ngkx}!KsHAcbRP|-tR(RxaiZ$0j9o%Poc z2n^Jp)^nsLyhSfEQF zC7xMd7QQN#@mS=82w8z5WEF~#cn~3h+t;qwgCX!oJQN8WG{`L+?ISeXVeJmItYE`s z9ewf}a0B;cm&Y(7YUEDs_IDlxL{t{5b~|YGIa=V7@7RR|YED9G&Ov({4J`FUffOjg zF4by$@|RE^@WC0uN&@Sa_r?rSOi-?;2pNzUg>SnHP!W&ZB`kiv6Kr6PC!`11`)1|!%ev#|NZ_!7GieQ=M@Uj`E&TK| z)tEXDe>f4fsia(mm-jv}?J5po2LhmUzhoz`Zp3h7 zGVmPpn7L#KTxN0$3NL&clTG*s^a}M5__Z;i2kY~l;Kj)+p+nV12x7^_cL}*>oNtM5Sva#qD zB#Hh65|sumIc9pGi8~4YWRY54 zWJwM{j0zw|>7X!99lyV#?f@BXXY_iMuo21MH!1o7ca6r5E!kx##W6&DS7ff92*dAf zDjYvd7kIU87Kr%0i(b)H%THV8V$bU1uoUq3Q(IV+SwC{J)2|~oOt2DN=ZI!{X);xW zi|3YKL{w(CMfBT+Mw{SlRJ<#*r0pncd|J(xZ;}EN^o&o=ag_fnvL6TDoGVl zVrDUtV)5)^q1qHJ#!F>hS8Wkb5C6VUk~RL*7v#>m8QTw$Nki51*E)kLqj~4!?RU?- zsNALbVim?0;6m=DoBq4^dhY%vDF$xds(D;Pv^ddQ+WB%sGQQ7tn3K#j5{l=iTHM1| z7bo`&KRsF}Y<+e2A;%_CXop;!jb_J7;R++<6#?Cr&Q6c3Sb7pq-Yiu!mc|daMSjE#kW}69qE@IU*{w?J2p13a&&ks zfW3S^#%wriDwchWecGs?+jz#ZD$4p{Dm$+%`h{^bHjLasFYX+rwo%)HvVQIm+&2Cy z&flpfCjK#B%BPK%21$&>go-|El}bkL>gZH#U0&dt|1q}D5hb{Ia5(On`u0s}M;Nt( zI$Y^@8o?(`TdYMhSQaA!CM8rcG^d+6bwh1N%~v(zBa_0ktw+r>i#F{u@Npf{ywZKt zcWCihKwVYFGJSNkR9w;GvQYc9+BgYS_s^w_0BX(E;@NA(D;{T<3z`*oT?I6%z$n{D zsAwmpyO0&Ve)5%c;kBlMO_E#gpsuVoFoh!5@3<}p&s7qn4#f#{L06W>K|iNDvUIN~Yl6*Lh1=y)MwEu4aTI9UH1}bbY25Q5RjZ5XRAi&n%y;)*pI*IIwp0IVYLDGEFmj zDP2mNJ+yWcj-5EYpk5QXc9SlID_J=E*T-c^3K?`^lcx}OD{sahDNJp8Jaj(7q+eIU z+#Mn`Bhx?FFWc?6~q;*ZXqV9VgH`lyctSQB`Y|ncQ%4N8Dm?w@MVIO z=0{*TDKD*lj~atx$b&*=rF?(qT=ziYP{5LU>`{Y z!bZr}RLe2#7Wz$N#h6%bvAAs|e>@~%&+QQ7hASL41)suUq?|23ItA+zJ{xhK{3?C< zlkQioWw;rC|A?~@`mWg44<(%iE#$*evgOZ)S!VIlhJrc@(}>USUw$=tD7X7;%=xbq zO(qp5$Ie7pMmM8EcxP2JP!2MWuMNQ`8p`eT)6_L*;oMo}N>6Q4baNbR! zw*DkGoZhau^mu3V)^c1#*7N(NMH7v|exKIP4vqN>mk+6jT0CbmTe0DWQHge(#&TN> znR{?NEV4&EE$Gp)e)@sF=&&)3y14VTW-$*kRALwLvFT|_+xL6-M&T)BeG ze0)^QUUa4jqD2aixv-Kkd;Sg;9!%pbX8aIx#}#?irczSO{ftfCB=Q&yqBXtX$d`T` id3-R?Mp3bUHKw9h!;2v4S~FZzOi%dfTkGZb-uoYg8IwQ& diff --git a/src/main/resources/data/computercraft/lua/rom/programs/flat.lua b/src/main/resources/data/computercraft/lua/rom/programs/flat.lua deleted file mode 100644 index 05956edff..000000000 --- a/src/main/resources/data/computercraft/lua/rom/programs/flat.lua +++ /dev/null @@ -1 +0,0 @@ -print("The earth is flat, at least in minecraft!") \ No newline at end of file diff --git a/src/main/resources/pack.mcmeta b/src/main/resources/pack.mcmeta index 4cf3c0150..1c0067a65 100644 --- a/src/main/resources/pack.mcmeta +++ b/src/main/resources/pack.mcmeta @@ -1,6 +1,7 @@ { "pack": { "description": "Advanced peripherals resources", - "pack_format": 10 + "pack_format": 8, + "_comment": "A pack_format of 6 requires json lang files and some texture changes from 1.16.2. Note: we require v6 pack meta for all mods." } } From 965ccef2c0467fb051fee9b8d64881fefb9062dd Mon Sep 17 00:00:00 2001 From: Srendi Date: Wed, 8 May 2024 23:46:27 +0200 Subject: [PATCH 162/228] Skip the calculation of storage busses without any connected storage block --- .../common/addons/appliedenergistics/AppEngApi.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java index 10173f316..97d27b4a9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java @@ -351,6 +351,8 @@ public static long getTotalItemStorage(IGridNode node) { net.minecraft.world.level.Level level = bus.getLevel(); BlockPos connectedInventoryPos = bus.getHost().getBlockEntity().getBlockPos().relative(bus.getSide()); BlockEntity connectedInventoryEntity = level.getBlockEntity(connectedInventoryPos); + if (connectedInventoryEntity == null) + continue; LazyOptional itemHandler = connectedInventoryEntity.getCapability(ForgeCapabilities.ITEM_HANDLER); if (itemHandler.isPresent()) { @@ -402,6 +404,8 @@ public static long getTotalFluidStorage(IGridNode node) { net.minecraft.world.level.Level level = bus.getLevel(); BlockPos connectedInventoryPos = bus.getHost().getBlockEntity().getBlockPos().relative(bus.getSide()); BlockEntity connectedInventoryEntity = level.getBlockEntity(connectedInventoryPos); + if (connectedInventoryEntity == null) + continue; LazyOptional fluidHandler = connectedInventoryEntity.getCapability(ForgeCapabilities.FLUID_HANDLER); if (fluidHandler.isPresent()) { From 5f40941db90564d052cdc9dfe80133f09537463f Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 10 May 2024 22:55:10 +0200 Subject: [PATCH 163/228] lost -> lose, behaviour -> behavior (American English) --- .../common/configuration/UnsafeConfig.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/UnsafeConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/UnsafeConfig.java index faff69e5f..800ec28a4 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/UnsafeConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/UnsafeConfig.java @@ -8,8 +8,8 @@ public class UnsafeConfig { private static ForgeConfigSpec.BooleanValue ignoreTurtlePeripheralItemNBT; public static void build(final ForgeConfigSpec.Builder builder) { - enableUnsafe = builder.comment("By setting this value to true, I understand all operations below are danger to my adventure, and if they caused unexpected behaviour in my world, I will not consider it as AP's liability").define("enableUnsafe", false); - ignoreTurtlePeripheralItemNBT = builder.comment("Ignore turtle peripheral item's NBT when equipping. **YOU WILL LOST ALL NBT ON THE ITEM**").define("ignoreTurtlePeripheralItemNBT", false); + enableUnsafe = builder.comment("By setting this value to true, I understand all operations below are danger to my adventure, and if they caused unexpected behavior in my world, I will not consider it as AP's liability").define("enableUnsafe", false); + ignoreTurtlePeripheralItemNBT = builder.comment("Ignore turtle peripheral item's NBT when equipping. **YOU WILL LOSE ALL NBT ON THE ITEM**").define("ignoreTurtlePeripheralItemNBT", false); } public static boolean enabled() { From 1309b60ebc46bf8888ca57c596a389fd90fcef96 Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 13 May 2024 19:28:16 +0200 Subject: [PATCH 164/228] Fixed `isOnEnchantedSoil()` for the mana flower integration --- .../common/addons/botania/ManaFlowerIntegration.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaFlowerIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaFlowerIntegration.java index 4a18763bd..db5d4d1b4 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaFlowerIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaFlowerIntegration.java @@ -5,6 +5,7 @@ import net.minecraft.world.level.block.entity.BlockEntity; import org.jetbrains.annotations.NotNull; import vazkii.botania.api.block_entity.GeneratingFlowerBlockEntity; +import vazkii.botania.common.block.BotaniaBlocks; public class ManaFlowerIntegration extends BlockEntityIntegrationPeripheral { @@ -35,6 +36,14 @@ public final int getMana() { @LuaFunction(mainThread = true) public final boolean isOnEnchantedSoil() { - return blockEntity.overgrowth; + return isOnSpecialSoil(); + } + + private boolean isOnSpecialSoil() { + if (blockEntity.isFloating()) { + return false; + } else { + return blockEntity.getLevel().getBlockState(blockEntity.getBlockPos().below()).is(BotaniaBlocks.enchantedSoil); + } } } From 4350ca590caaaddd136cfab8208d628b96ce1eff Mon Sep 17 00:00:00 2001 From: srendi Date: Tue, 21 May 2024 11:48:15 +0200 Subject: [PATCH 165/228] Satisfy checkstyle --- .../common/addons/botania/ManaFlowerIntegration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaFlowerIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaFlowerIntegration.java index db5d4d1b4..a4eb92215 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaFlowerIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaFlowerIntegration.java @@ -43,7 +43,7 @@ private boolean isOnSpecialSoil() { if (blockEntity.isFloating()) { return false; } else { - return blockEntity.getLevel().getBlockState(blockEntity.getBlockPos().below()).is(BotaniaBlocks.enchantedSoil); + return blockEntity.getLevel().getBlockState(blockEntity.getBlockPos().below()).is(BotaniaBlocks.enchantedSoil); } } } From 01c907ced1dadb339ad72646a2bea2c89f5d0ade Mon Sep 17 00:00:00 2001 From: zyxkad Date: Tue, 21 May 2024 21:08:20 -0600 Subject: [PATCH 166/228] add chat hover event filter --- .../peripheral/ChatBoxPeripheral.java | 179 +++++++++++++++--- 1 file changed, 148 insertions(+), 31 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java index d0bcb5c32..d9d739711 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java @@ -23,13 +23,19 @@ import de.srendi.advancedperipherals.lib.peripherals.IPeripheralFunction; import de.srendi.advancedperipherals.network.APNetworking; import de.srendi.advancedperipherals.network.toclient.ToastToClientPacket; +import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.ComponentContents; +import net.minecraft.network.chat.HoverEvent; import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.Style; import net.minecraft.resources.ResourceKey; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.level.Level; import net.minecraftforge.server.ServerLifecycleHooks; + import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Optional; import java.util.UUID; @@ -69,6 +75,53 @@ protected MethodResult withChatOperation(IPeripheralFunction dimension = getLevel().dimension(); MutableComponent component = Component.Serializer.fromJson(message); - if (component == null) + if (component == null) { return MethodResult.of(null, "incorrect json"); + } + component = filterMessage(component); + if (component == null) { + return MethodResult.of(null, "illegal message"); + } - if (checkBrackets(arguments.optString(2))) + if (checkBrackets(arguments.optString(2))) { return MethodResult.of(null, "incorrect bracket string (e.g. [], {}, <>, ...)"); + } MutableComponent preparedMessage = appendPrefix( StringUtil.convertAndToSectionMark(arguments.optString(1, APConfig.PERIPHERALS_CONFIG.defaultChatBoxPrefix.get())), arguments.optString(2, "[]"), StringUtil.convertAndToSectionMark(arguments.optString(3, "")) - ).append(component); + ) + if (preparedMessage == null) { + return MethodResult.of(null, "illegal prefix"); + } + preparedMessage.append(component); for (ServerPlayer player : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers()) { - if (!APConfig.PERIPHERALS_CONFIG.chatBoxMultiDimensional.get() && player.getLevel().dimension() != dimension) + if (!APConfig.PERIPHERALS_CONFIG.chatBoxMultiDimensional.get() && player.getLevel().dimension() != dimension) { continue; - if (range == -1 || CoordUtil.isInRange(getPos(), getLevel(), player, range, maxRange)) + } + if (range == -1 || CoordUtil.isInRange(getPos(), getLevel(), player, range, maxRange)) { player.sendSystemMessage(preparedMessage); + } } return MethodResult.of(true); }); @@ -144,19 +209,26 @@ public final MethodResult sendMessage(@NotNull IArguments arguments) throws LuaE int range = arguments.optInt(4, maxRange); range = maxRange == -1 ? range : Math.min(range, APConfig.PERIPHERALS_CONFIG.chatBoxMaxRange.get()); ResourceKey dimension = getLevel().dimension(); - if (checkBrackets(arguments.optString(2))) + if (checkBrackets(arguments.optString(2))) { return MethodResult.of(null, "incorrect bracket string (e.g. [], {}, <>, ...)"); + } MutableComponent preparedMessage = appendPrefix( StringUtil.convertAndToSectionMark(arguments.optString(1, APConfig.PERIPHERALS_CONFIG.defaultChatBoxPrefix.get())), arguments.optString(2, "[]"), StringUtil.convertAndToSectionMark(arguments.optString(3, "")) - ).append(message); + ) + if (preparedMessage == null) { + return MethodResult.of(null, "illegal prefix"); + } + preparedMessage.append(message); for (ServerPlayer player : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers()) { - if (!APConfig.PERIPHERALS_CONFIG.chatBoxMultiDimensional.get() && player.getLevel().dimension() != dimension) + if (!APConfig.PERIPHERALS_CONFIG.chatBoxMultiDimensional.get() && player.getLevel().dimension() != dimension) { continue; - if (range == -1 || CoordUtil.isInRange(getPos(), getLevel(), player, range, maxRange)) + } + if (range == -1 || CoordUtil.isInRange(getPos(), getLevel(), player, range, maxRange)) { player.sendSystemMessage(preparedMessage); + } } return MethodResult.of(true); }); @@ -172,26 +244,39 @@ public final MethodResult sendFormattedMessageToPlayer(@NotNull IArguments argum range = maxRange == -1 ? range : Math.min(range, APConfig.PERIPHERALS_CONFIG.chatBoxMaxRange.get()); ResourceKey dimension = getLevel().dimension(); ServerPlayer player = getPlayer(playerName); - if (player == null) + if (player == null) { return MethodResult.of(null, "incorrect player name/uuid"); + } MutableComponent component = Component.Serializer.fromJson(message); - if (component == null) + if (component == null) { return MethodResult.of(null, "incorrect json"); + } + component = filterMessage(component); + if (component == null) { + return MethodResult.of(null, "illegal message"); + } - if (checkBrackets(arguments.optString(3))) + if (checkBrackets(arguments.optString(3))) { return MethodResult.of(null, "incorrect bracket string (e.g. [], {}, <>, ...)"); + } MutableComponent preparedMessage = appendPrefix( StringUtil.convertAndToSectionMark(arguments.optString(2, APConfig.PERIPHERALS_CONFIG.defaultChatBoxPrefix.get())), arguments.optString(3, "[]"), StringUtil.convertAndToSectionMark(arguments.optString(4, "")) - ).append(component); - if (!APConfig.PERIPHERALS_CONFIG.chatBoxMultiDimensional.get() && player.getLevel().dimension() != dimension) + ) + if (preparedMessage == null) { + return MethodResult.of(null, "illegal prefix"); + } + preparedMessage.append(component); + if (!APConfig.PERIPHERALS_CONFIG.chatBoxMultiDimensional.get() && player.getLevel().dimension() != dimension) { return MethodResult.of(false, "NOT_SAME_DIMENSION"); + } - if (range == -1 || CoordUtil.isInRange(getPos(), getLevel(), player, range, maxRange)) + if (range == -1 || CoordUtil.isInRange(getPos(), getLevel(), player, range, maxRange)) { player.sendSystemMessage(preparedMessage); + } return MethodResult.of(true); }); } @@ -208,28 +293,45 @@ public final MethodResult sendFormattedToastToPlayer(@NotNull IArguments argumen range = maxRange == -1 ? range : Math.min(range, APConfig.PERIPHERALS_CONFIG.chatBoxMaxRange.get()); ResourceKey dimension = getLevel().dimension(); ServerPlayer player = getPlayer(playerName); - if (player == null) + if (player == null) { return MethodResult.of(null, "incorrect player name/uuid"); + } MutableComponent messageComponent = Component.Serializer.fromJson(message); - if (messageComponent == null) + if (messageComponent == null) { return MethodResult.of(null, "incorrect json for message"); + } + messageComponent = filterMessage(messageComponent); + if (messageComponent == null) { + return MethodResult.of(null, "illegal message"); + } MutableComponent titleComponent = Component.Serializer.fromJson(title); - if (titleComponent == null) + if (titleComponent == null) { return MethodResult.of(null, "incorrect json for title"); + } + titleComponent = filterMessage(titleComponent); + if (titleComponent == null) { + return MethodResult.of(null, "illegal title"); + } - if (checkBrackets(arguments.optString(4))) + if (checkBrackets(arguments.optString(4))) { return MethodResult.of(null, "incorrect bracket string (e.g. [], {}, <>, ,,,)"); + } MutableComponent preparedMessage = appendPrefix( StringUtil.convertAndToSectionMark(arguments.optString(3, APConfig.PERIPHERALS_CONFIG.defaultChatBoxPrefix.get())), arguments.optString(4, "[]"), StringUtil.convertAndToSectionMark(arguments.optString(5, "")) - ).append(messageComponent); + ) + if (preparedMessage == null) { + return MethodResult.of(null, "illegal prefix"); + } + preparedMessage.append(messageComponent); - if (!APConfig.PERIPHERALS_CONFIG.chatBoxMultiDimensional.get() && player.getLevel().dimension() != dimension) + if (!APConfig.PERIPHERALS_CONFIG.chatBoxMultiDimensional.get() && player.getLevel().dimension() != dimension) { return MethodResult.of(false, "NOT_SAME_DIMENSION"); + } if (range == -1 || CoordUtil.isInRange(getPos(), getLevel(), player, range, maxRange)) { ToastToClientPacket packet = new ToastToClientPacket(titleComponent, preparedMessage); @@ -250,22 +352,30 @@ public final MethodResult sendMessageToPlayer(@NotNull IArguments arguments) thr range = maxRange == -1 ? range : Math.min(range, APConfig.PERIPHERALS_CONFIG.chatBoxMaxRange.get()); ResourceKey dimension = getLevel().dimension(); ServerPlayer player = getPlayer(playerName); - if (player == null) + if (player == null) { return MethodResult.of(null, "incorrect player name/uuid"); + } - if (checkBrackets(arguments.optString(3))) + if (checkBrackets(arguments.optString(3))) { return MethodResult.of(null, "incorrect bracket string (e.g. [], {}, <>, ...)"); + } MutableComponent preparedMessage = appendPrefix( StringUtil.convertAndToSectionMark(arguments.optString(2, APConfig.PERIPHERALS_CONFIG.defaultChatBoxPrefix.get())), arguments.optString(3, "[]"), StringUtil.convertAndToSectionMark(arguments.optString(4, "")) - ).append(message); - if (!APConfig.PERIPHERALS_CONFIG.chatBoxMultiDimensional.get() && player.getLevel().dimension() != dimension) + ) + if (preparedMessage == null) { + return MethodResult.of(null, "illegal prefix"); + } + preparedMessage.append(message); + if (!APConfig.PERIPHERALS_CONFIG.chatBoxMultiDimensional.get() && player.getLevel().dimension() != dimension) { return MethodResult.of(false, "NOT_SAME_DIMENSION"); + } - if (range == -1 || CoordUtil.isInRange(getPos(), getLevel(), player, range, maxRange)) + if (range == -1 || CoordUtil.isInRange(getPos(), getLevel(), player, range, maxRange)) { player.sendSystemMessage(preparedMessage, false); + } return MethodResult.of(true); }); } @@ -281,20 +391,27 @@ public final MethodResult sendToastToPlayer(@NotNull IArguments arguments) throw range = maxRange == -1 ? range : Math.min(range, APConfig.PERIPHERALS_CONFIG.chatBoxMaxRange.get()); ResourceKey dimension = getLevel().dimension(); ServerPlayer player = getPlayer(playerName); - if (player == null) + if (player == null) { return MethodResult.of(null, "incorrect player name/uuid"); + } - if (checkBrackets(arguments.optString(4))) + if (checkBrackets(arguments.optString(4))) { return MethodResult.of(null, "incorrect bracket string (e.g. [], {}, <>, ...)"); + } MutableComponent preparedMessage = appendPrefix( StringUtil.convertAndToSectionMark(arguments.optString(3, APConfig.PERIPHERALS_CONFIG.defaultChatBoxPrefix.get())), arguments.optString(4, "[]"), StringUtil.convertAndToSectionMark(arguments.optString(5, "")) - ).append(message); + ) + if (preparedMessage == null) { + return MethodResult.of(null, "illegal prefix"); + } + preparedMessage.append(message); - if (!APConfig.PERIPHERALS_CONFIG.chatBoxMultiDimensional.get() && player.getLevel().dimension() != dimension) + if (!APConfig.PERIPHERALS_CONFIG.chatBoxMultiDimensional.get() && player.getLevel().dimension() != dimension) { return MethodResult.of(false, "NOT_SAME_DIMENSION"); + } if (range == -1 || CoordUtil.isInRange(getPos(), getLevel(), player, range, maxRange)) { ToastToClientPacket packet = new ToastToClientPacket(Component.literal(title), preparedMessage); From e8221b530c27fcaa3927616a1ec20748b4beda47 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Tue, 21 May 2024 23:11:09 -0600 Subject: [PATCH 167/228] add command filters --- .../peripheral/ChatBoxPeripheral.java | 26 ++++++++++++++- .../configuration/PeripheralsConfig.java | 32 +++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java index d9d739711..461963b14 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java @@ -26,6 +26,7 @@ import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.ComponentContents; +import net.minecraft.network.chat.ClickEvent; import net.minecraft.network.chat.HoverEvent; import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.Style; @@ -37,6 +38,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.List; import java.util.Optional; import java.util.UUID; @@ -80,8 +82,30 @@ protected ComponentContents filterComponentContents(@NonNull ComponentContents c return content; } + private List> getChatBoxCommandFilters() { + return APConfig.PERIPHERALS_CONFIG.getChatBoxCommandFilters(); + } + + private boolean isCommandBanned(String command) { + for (Predicate pattern : getChatBoxCommandFilters()) { + if (pattern.test(command)) { + return true; + } + } + return false; + } + @Nullable protected Style filterComponentStyle(@NonNull Style style) { + ClickEvent click = style.getClickEvent(); + if (click != null) { + if (click.getAction() == ClickEvent.Action.RUN_COMMAND || click.getAction() == ClickEvent.Action.SUGGEST_COMMAND) { + String command = click.getValue(); + if (isCommandBanned(command)) { + return null; + } + } + } HoverEvent hover = style.getHoverEvent(); if (hover != null) { HoverEvent.ItemStackInfo itemInfo = hover.getValue(HoverEvent.Action.SHOW_ITEM); @@ -89,7 +113,7 @@ protected Style filterComponentStyle(@NonNull Style style) { try { itemInfo.getItemStack().getTooltipLines(null, TooltipFlag.Default.ADVANCED); } catch (RuntimeException e) { - MutableComponent errorMessage = Component.literal("Invalid item").setStyle(ChatFormatting.RED, ChatFormatting.BOLD); + MutableComponent errorMessage = Component.literal("[AP] Invalid item").setStyle(ChatFormatting.RED, ChatFormatting.BOLD); style = style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, errorMessage)); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java index a31183cf4..d29ff1e9e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java @@ -38,6 +38,8 @@ public class PeripheralsConfig implements IAPConfig { public final ForgeConfigSpec.ConfigValue defaultChatBoxPrefix; public final ForgeConfigSpec.IntValue chatBoxMaxRange; public final ForgeConfigSpec.BooleanValue chatBoxMultiDimensional; + public final ForgeConfigSpec.ConfigValue> chatBoxBannedCommands; + private List> chatBoxCommandFilters = null; // ME Bridge public final ForgeConfigSpec.BooleanValue enableMEBridge; @@ -79,6 +81,12 @@ public class PeripheralsConfig implements IAPConfig { public final ForgeConfigSpec.IntValue poweredPeripheralMaxEnergyStorage; private final ForgeConfigSpec configSpec; + private static final List chatBoxDefaultBannedCommands = Arrays.asList( + "/op", + "/deop", + "/gamemode", + ); + public PeripheralsConfig() { ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder(); @@ -117,6 +125,7 @@ public PeripheralsConfig() { defaultChatBoxPrefix = builder.comment("Defines default chatbox prefix").define("defaultChatBoxPrefix", "AP"); chatBoxMaxRange = builder.comment("Defines the maximal range of the chat box in blocks. -1 for infinite. If the range is not -1, players in other dimensions won't able to receive messages").defineInRange("chatBoxMaxRange", -1, -1, 30000000); chatBoxMultiDimensional = builder.comment("If true, the chat box is able to send messages to other dimensions than its own").define("chatBoxMultiDimensional", true); + chatBoxBannedCommands = builder.comment("These command below will not be able to send by 'run_command' or 'suggest_command' action. Use regex pattern").defineList("chatBoxBannedCommands", () -> chatBoxDefaultBannedCommands, (o) -> o instanceof String value && value.length() > 0); pop("ME_Bridge", builder); @@ -195,4 +204,27 @@ public String getFileName() { public ModConfig.Type getType() { return ModConfig.Type.COMMON; } + + private List> parseChatBoxCommandFilters() { + List> filters = new ArrayList(); + for (String s : chatBoxBannedCommands.get()) { + if (s.charAt(0) == '/') { + String p = s.replaceAll("\\s+", "\\\\s+"); + if (p.equals(s)) { + final String prefix = s; + filters.add((v) -> v.startsWith(prefix) && (v.length() == prefix.length() || " \t".indexOf(v.charAt(prefix.length())) != -1)); + continue; + } + s = "^" + p + "\\\\s*"; + } + filters.add(Pattern.compile(s).asPredicate()); + } + } + + public List> getChatBoxCommandFilters() { + if (chatBoxCommandFilters == null) { + chatBoxCommandFilters = parseChatBoxCommandFilters(); + } + return chatBoxCommandFilters; + } } From ff336bb21a72d5636519452671917668c3040ed8 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Wed, 22 May 2024 08:53:35 -0600 Subject: [PATCH 168/228] replace the hoverevent with error instead of block to send --- .../peripheral/ChatBoxPeripheral.java | 21 +++++++++++++++---- .../configuration/PeripheralsConfig.java | 4 +++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java index 461963b14..d45d7339c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java @@ -82,6 +82,10 @@ protected ComponentContents filterComponentContents(@NonNull ComponentContents c return content; } + private boolean getChatBoxNoRunCommand() { + return APConfig.PERIPHERALS_CONFIG.chatBoxNoRunCommand.get(); + } + private List> getChatBoxCommandFilters() { return APConfig.PERIPHERALS_CONFIG.getChatBoxCommandFilters(); } @@ -95,14 +99,24 @@ private boolean isCommandBanned(String command) { return false; } + private static MutableComponent createFormattedError(String message) { + return Component.literal("[AP] " + message).setStyle(ChatFormatting.RED, ChatFormatting.BOLD); + } + @Nullable protected Style filterComponentStyle(@NonNull Style style) { ClickEvent click = style.getClickEvent(); if (click != null) { - if (click.getAction() == ClickEvent.Action.RUN_COMMAND || click.getAction() == ClickEvent.Action.SUGGEST_COMMAND) { + if (getChatBoxNoRunCommand() && click.getAction() == ClickEvent.Action.RUN_COMMAND) { + style = style. + withClickEvent(null). + withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, createFormattedError("'run_command' action is banned"))); + } else if (click.getAction() == ClickEvent.Action.RUN_COMMAND || click.getAction() == ClickEvent.Action.SUGGEST_COMMAND) { String command = click.getValue(); if (isCommandBanned(command)) { - return null; + style = style. + withClickEvent(null). + withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, createFormattedError("Command `" + command + "` is banned"))); } } } @@ -113,8 +127,7 @@ protected Style filterComponentStyle(@NonNull Style style) { try { itemInfo.getItemStack().getTooltipLines(null, TooltipFlag.Default.ADVANCED); } catch (RuntimeException e) { - MutableComponent errorMessage = Component.literal("[AP] Invalid item").setStyle(ChatFormatting.RED, ChatFormatting.BOLD); - style = style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, errorMessage)); + style = style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, createFormattedError("Invalid item"))); } } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java index d29ff1e9e..2b65cb884 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java @@ -38,6 +38,7 @@ public class PeripheralsConfig implements IAPConfig { public final ForgeConfigSpec.ConfigValue defaultChatBoxPrefix; public final ForgeConfigSpec.IntValue chatBoxMaxRange; public final ForgeConfigSpec.BooleanValue chatBoxMultiDimensional; + public final ForgeConfigSpec.BooleanValue chatBoxNoRunCommand; public final ForgeConfigSpec.ConfigValue> chatBoxBannedCommands; private List> chatBoxCommandFilters = null; @@ -125,7 +126,8 @@ public PeripheralsConfig() { defaultChatBoxPrefix = builder.comment("Defines default chatbox prefix").define("defaultChatBoxPrefix", "AP"); chatBoxMaxRange = builder.comment("Defines the maximal range of the chat box in blocks. -1 for infinite. If the range is not -1, players in other dimensions won't able to receive messages").defineInRange("chatBoxMaxRange", -1, -1, 30000000); chatBoxMultiDimensional = builder.comment("If true, the chat box is able to send messages to other dimensions than its own").define("chatBoxMultiDimensional", true); - chatBoxBannedCommands = builder.comment("These command below will not be able to send by 'run_command' or 'suggest_command' action. Use regex pattern").defineList("chatBoxBannedCommands", () -> chatBoxDefaultBannedCommands, (o) -> o instanceof String value && value.length() > 0); + chatBoxNoRunCommand = builder.comment("If true, the chat box cannot use 'run_command' action").define("chatBoxNoRunCommand", false); + chatBoxBannedCommands = builder.comment("These commands below will not be able to send by 'run_command' or 'suggest_command' action. Use regex pattern").defineList("chatBoxBannedCommands", () -> chatBoxDefaultBannedCommands, (o) -> o instanceof String value && value.length() > 0); pop("ME_Bridge", builder); From b49b30d4bed16ab2e82a114584a0c4e6597f16b1 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Fri, 24 May 2024 09:23:40 -0600 Subject: [PATCH 169/228] add imports & fix errors --- .../peripheral/ChatBoxPeripheral.java | 22 ++++++++++--------- .../configuration/PeripheralsConfig.java | 15 +++++++++---- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java index d45d7339c..9fa37a3b0 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java @@ -32,6 +32,7 @@ import net.minecraft.network.chat.Style; import net.minecraft.resources.ResourceKey; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.level.Level; import net.minecraftforge.server.ServerLifecycleHooks; @@ -41,6 +42,7 @@ import java.util.List; import java.util.Optional; import java.util.UUID; +import java.util.function.Predicate; import static de.srendi.advancedperipherals.common.addons.computercraft.operations.SimpleFreeOperation.CHAT_MESSAGE; @@ -78,7 +80,7 @@ protected MethodResult withChatOperation(IPeripheralFunction> chatBoxBannedCommands; + public final ForgeConfigSpec.ConfigValue> chatBoxBannedCommands; private List> chatBoxCommandFilters = null; // ME Bridge @@ -85,7 +91,7 @@ public class PeripheralsConfig implements IAPConfig { private static final List chatBoxDefaultBannedCommands = Arrays.asList( "/op", "/deop", - "/gamemode", + "/gamemode" ); public PeripheralsConfig() { @@ -127,7 +133,7 @@ public PeripheralsConfig() { chatBoxMaxRange = builder.comment("Defines the maximal range of the chat box in blocks. -1 for infinite. If the range is not -1, players in other dimensions won't able to receive messages").defineInRange("chatBoxMaxRange", -1, -1, 30000000); chatBoxMultiDimensional = builder.comment("If true, the chat box is able to send messages to other dimensions than its own").define("chatBoxMultiDimensional", true); chatBoxNoRunCommand = builder.comment("If true, the chat box cannot use 'run_command' action").define("chatBoxNoRunCommand", false); - chatBoxBannedCommands = builder.comment("These commands below will not be able to send by 'run_command' or 'suggest_command' action. Use regex pattern").defineList("chatBoxBannedCommands", () -> chatBoxDefaultBannedCommands, (o) -> o instanceof String value && value.length() > 0); + chatBoxBannedCommands = builder.comment("These commands below will not be able to send by 'run_command' or 'suggest_command' action. Use regex pattern").defineList("chatBoxBannedCommands", chatBoxDefaultBannedCommands, (o) -> o instanceof String value && value.length() > 0); pop("ME_Bridge", builder); @@ -208,7 +214,7 @@ public ModConfig.Type getType() { } private List> parseChatBoxCommandFilters() { - List> filters = new ArrayList(); + List> filters = new ArrayList<>(); for (String s : chatBoxBannedCommands.get()) { if (s.charAt(0) == '/') { String p = s.replaceAll("\\s+", "\\\\s+"); @@ -221,6 +227,7 @@ private List> parseChatBoxCommandFilters() { } filters.add(Pattern.compile(s).asPredicate()); } + return filters; } public List> getChatBoxCommandFilters() { From 4c6367f6f207d402d72b71899f0d743425806688 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Fri, 24 May 2024 12:31:00 -0600 Subject: [PATCH 170/228] fix some styles --- .../peripheral/ChatBoxPeripheral.java | 14 +++++++------- .../common/configuration/PeripheralsConfig.java | 11 ++++++----- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java index 9fa37a3b0..187149c4f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java @@ -110,15 +110,15 @@ protected Style filterComponentStyle(@NotNull Style style) { ClickEvent click = style.getClickEvent(); if (click != null) { if (getChatBoxNoRunCommand() && click.getAction() == ClickEvent.Action.RUN_COMMAND) { - style = style. - withClickEvent(null). - withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, createFormattedError("'run_command' action is banned"))); + style = style + .withClickEvent(null) + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, createFormattedError("'run_command' action is banned"))); } else if (click.getAction() == ClickEvent.Action.RUN_COMMAND || click.getAction() == ClickEvent.Action.SUGGEST_COMMAND) { String command = click.getValue(); if (isCommandBanned(command)) { - style = style. - withClickEvent(null). - withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, createFormattedError("Command `" + command + "` is banned"))); + style = style + .withClickEvent(null) + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, createFormattedError("Command `" + command + "` is banned"))); } } } @@ -166,7 +166,7 @@ private MutableComponent appendPrefix(String prefix, String brackets, String col if (!prefix.isEmpty()) { MutableComponent formattablePrefix; try { - formattablePrefix = MutableComponent.Serializer.fromJson(prefix); + formattablePrefix = Component.Serializer.fromJson(prefix); prefixComponent = formattablePrefix; } catch (JsonSyntaxException exception) { AdvancedPeripherals.debug("Non json prefix, using plain text instead."); diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java index 9d4567c1b..9a32752af 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java @@ -215,17 +215,18 @@ public ModConfig.Type getType() { private List> parseChatBoxCommandFilters() { List> filters = new ArrayList<>(); - for (String s : chatBoxBannedCommands.get()) { - if (s.charAt(0) == '/') { - String p = s.replaceAll("\\s+", "\\\\s+"); + for (final String s : chatBoxBannedCommands.get()) { + String p = s; + if (p.charAt(0) == '/') { + p.replaceAll("\\s+", "\\\\s+"); if (p.equals(s)) { final String prefix = s; filters.add((v) -> v.startsWith(prefix) && (v.length() == prefix.length() || " \t".indexOf(v.charAt(prefix.length())) != -1)); continue; } - s = "^" + p + "\\\\s*"; + p = "^" + p + "\\\\s*"; } - filters.add(Pattern.compile(s).asPredicate()); + filters.add(Pattern.compile(p).asPredicate()); } return filters; } From 30fbaa241a5b2276dce08bc0809421d232b1fc16 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Fri, 24 May 2024 12:35:20 -0600 Subject: [PATCH 171/228] chatBoxNoRunCommand -> chatBoxPreventRunCommand --- .../addons/computercraft/peripheral/ChatBoxPeripheral.java | 6 +++--- .../common/configuration/PeripheralsConfig.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java index 187149c4f..9db45e2e7 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java @@ -84,8 +84,8 @@ protected ComponentContents filterComponentContents(@NotNull ComponentContents c return content; } - private boolean getChatBoxNoRunCommand() { - return APConfig.PERIPHERALS_CONFIG.chatBoxNoRunCommand.get(); + private boolean isChatBoxPreventingRunCommand() { + return APConfig.PERIPHERALS_CONFIG.chatBoxPreventRunCommand.get(); } private List> getChatBoxCommandFilters() { @@ -109,7 +109,7 @@ private static MutableComponent createFormattedError(String message) { protected Style filterComponentStyle(@NotNull Style style) { ClickEvent click = style.getClickEvent(); if (click != null) { - if (getChatBoxNoRunCommand() && click.getAction() == ClickEvent.Action.RUN_COMMAND) { + if (isChatBoxPreventingRunCommand() && click.getAction() == ClickEvent.Action.RUN_COMMAND) { style = style .withClickEvent(null) .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, createFormattedError("'run_command' action is banned"))); diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java index 9a32752af..d30105a32 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java @@ -44,7 +44,7 @@ public class PeripheralsConfig implements IAPConfig { public final ForgeConfigSpec.ConfigValue defaultChatBoxPrefix; public final ForgeConfigSpec.IntValue chatBoxMaxRange; public final ForgeConfigSpec.BooleanValue chatBoxMultiDimensional; - public final ForgeConfigSpec.BooleanValue chatBoxNoRunCommand; + public final ForgeConfigSpec.BooleanValue chatBoxPreventRunCommand; public final ForgeConfigSpec.ConfigValue> chatBoxBannedCommands; private List> chatBoxCommandFilters = null; @@ -132,7 +132,7 @@ public PeripheralsConfig() { defaultChatBoxPrefix = builder.comment("Defines default chatbox prefix").define("defaultChatBoxPrefix", "AP"); chatBoxMaxRange = builder.comment("Defines the maximal range of the chat box in blocks. -1 for infinite. If the range is not -1, players in other dimensions won't able to receive messages").defineInRange("chatBoxMaxRange", -1, -1, 30000000); chatBoxMultiDimensional = builder.comment("If true, the chat box is able to send messages to other dimensions than its own").define("chatBoxMultiDimensional", true); - chatBoxNoRunCommand = builder.comment("If true, the chat box cannot use 'run_command' action").define("chatBoxNoRunCommand", false); + chatBoxPreventRunCommand = builder.comment("If true, the chat box cannot use 'run_command' action").define("chatBoxPreventRunCommand", false); chatBoxBannedCommands = builder.comment("These commands below will not be able to send by 'run_command' or 'suggest_command' action. Use regex pattern").defineList("chatBoxBannedCommands", chatBoxDefaultBannedCommands, (o) -> o instanceof String value && value.length() > 0); pop("ME_Bridge", builder); From a27b77041afb30882437d375b1e6d653c3c9b6b9 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Fri, 24 May 2024 12:56:54 -0600 Subject: [PATCH 172/228] clearify chatBoxBannedCommands comment --- .../common/configuration/PeripheralsConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java index d30105a32..cb0658f83 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java @@ -133,7 +133,7 @@ public PeripheralsConfig() { chatBoxMaxRange = builder.comment("Defines the maximal range of the chat box in blocks. -1 for infinite. If the range is not -1, players in other dimensions won't able to receive messages").defineInRange("chatBoxMaxRange", -1, -1, 30000000); chatBoxMultiDimensional = builder.comment("If true, the chat box is able to send messages to other dimensions than its own").define("chatBoxMultiDimensional", true); chatBoxPreventRunCommand = builder.comment("If true, the chat box cannot use 'run_command' action").define("chatBoxPreventRunCommand", false); - chatBoxBannedCommands = builder.comment("These commands below will not be able to send by 'run_command' or 'suggest_command' action. Use regex pattern").defineList("chatBoxBannedCommands", chatBoxDefaultBannedCommands, (o) -> o instanceof String value && value.length() > 0); + chatBoxBannedCommands = builder.comment("These commands below will not be able to send by 'run_command' or 'suggest_command' action. It will match as prefix if starts with '/', other wise use regex pattern").defineList("chatBoxBannedCommands", chatBoxDefaultBannedCommands, (o) -> o instanceof String value && value.length() > 0); pop("ME_Bridge", builder); From 6a374a094815f0f5004879c34edbc1a58c37e94f Mon Sep 17 00:00:00 2001 From: zyxkad Date: Fri, 24 May 2024 15:30:17 -0600 Subject: [PATCH 173/228] fix regex pattern escape --- .../common/configuration/PeripheralsConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java index cb0658f83..e3cf1864a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java @@ -224,7 +224,7 @@ private List> parseChatBoxCommandFilters() { filters.add((v) -> v.startsWith(prefix) && (v.length() == prefix.length() || " \t".indexOf(v.charAt(prefix.length())) != -1)); continue; } - p = "^" + p + "\\\\s*"; + p = "^" + p + "\\s*"; } filters.add(Pattern.compile(p).asPredicate()); } From 16439fa531a864f5ce37581b8380267490225f58 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Mon, 27 May 2024 07:44:19 -0600 Subject: [PATCH 174/228] update chatBoxDefaultBannedCommands --- .../common/configuration/PeripheralsConfig.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java index e3cf1864a..1287e9c3b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java @@ -89,9 +89,23 @@ public class PeripheralsConfig implements IAPConfig { private final ForgeConfigSpec configSpec; private static final List chatBoxDefaultBannedCommands = Arrays.asList( + "/execute", "/op", "/deop", - "/gamemode" + "/gamemode", + "/gamerule", + "/stop", + + "/give", + "/fill", + "/setblock", + "/summon", + + "/whitelist", + "^/ban-(?:ip)?\\s*", + "^/pardon-(?:ip)?\\s*", + + "^/save-(?:on|off)\\s*" ); public PeripheralsConfig() { From 41da2ee1596740a27aef2a5568d25dc76bb147cc Mon Sep 17 00:00:00 2001 From: zyxkad Date: Mon, 27 May 2024 10:58:29 -0600 Subject: [PATCH 175/228] add safe exec and wrap commands with it while sending through chatbox --- .../peripheral/ChatBoxPeripheral.java | 17 ++++++++++---- .../common/commands/APCommands.java | 22 +++++++++++++++++++ .../configuration/PeripheralsConfig.java | 2 ++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java index 9db45e2e7..d2c9a22e5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java @@ -44,6 +44,7 @@ import java.util.UUID; import java.util.function.Predicate; +import static de.srendi.advancedperipherals.common.commands.APCommands.ROOT_SAFE_EXEC_LITERAL; import static de.srendi.advancedperipherals.common.addons.computercraft.operations.SimpleFreeOperation.CHAT_MESSAGE; public class ChatBoxPeripheral extends BasePeripheral { @@ -92,6 +93,10 @@ private List> getChatBoxCommandFilters() { return APConfig.PERIPHERALS_CONFIG.getChatBoxCommandFilters(); } + private boolean shouldWrapCommand(String command) { + return APConfig.PERIPHERALS_CONFIG.chatBoxWrapCommand.get(); + } + private boolean isCommandBanned(String command) { for (Predicate pattern : getChatBoxCommandFilters()) { if (pattern.test(command)) { @@ -115,10 +120,14 @@ protected Style filterComponentStyle(@NotNull Style style) { .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, createFormattedError("'run_command' action is banned"))); } else if (click.getAction() == ClickEvent.Action.RUN_COMMAND || click.getAction() == ClickEvent.Action.SUGGEST_COMMAND) { String command = click.getValue(); - if (isCommandBanned(command)) { - style = style - .withClickEvent(null) - .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, createFormattedError("Command `" + command + "` is banned"))); + if (command.length() > 0 && command.charAt(0) == '/') { + if (isCommandBanned(command)) { + style = style + .withClickEvent(null) + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, createFormattedError("Command `" + command + "` is banned"))); + } else if (shouldWrapCommand(command)) { + style = style.withClickEvent(new ClickEvent(click.getAction(), "/" + ROOT_SAFE_EXEC_LITERAL + " " + command)); + } } } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java b/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java index 06f8a9aa8..4691aeacb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java +++ b/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java @@ -1,6 +1,9 @@ package de.srendi.advancedperipherals.common.commands; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.tree.LiteralCommandNode; import dan200.computercraft.core.computer.ComputerSide; import dan200.computercraft.core.computer.Environment; @@ -33,9 +36,15 @@ public class APCommands { static final String FORCELOAD_HELP = "/" + ROOT_LITERAL + " " + FORCELOAD_LITERAL + " help" + " - show this help message\n" + "/" + ROOT_LITERAL + " " + FORCELOAD_LITERAL + " dump" + " - show all chunky turtles\n"; + public static final String EXEC_LITERAL = "safe-exec"; + public static final String ROOT_SAFE_EXEC_LITERAL = "ap-safe-exec"; @SubscribeEvent public static void register(RegisterCommandsEvent event) { + LiteralCommandNode safeExecNode = Commands.literal(EXEC_LITERAL) + .then(Commands.argument("command", StringArgumentType.greedyString()) + .executes(APCommands::safeExecute)) + .build(); event.getDispatcher().register(Commands.literal(ROOT_LITERAL) .then(Commands.literal("getHashItem").executes(context -> getHashItem(context.getSource()))) .then(Commands.literal(FORCELOAD_LITERAL) @@ -46,7 +55,9 @@ public static void register(RegisterCommandsEvent event) { .requires(UserLevel.OWNER_OP) .executes(context -> forceloadDump(context.getSource()))) ) + .then(safeExecNode) ); + event.getDispatcher().register(Commands.literal(ROOT_SAFE_EXEC_LITERAL).redirect(safeExecNode)); } private static int getHashItem(CommandSourceStack source) throws CommandSyntaxException { @@ -98,6 +109,17 @@ private static int forceloadDump(CommandSourceStack source) throws CommandSyntax return computers.length; } + private static int safeExecute(CommandContext context) throws CommandSyntaxException { + CommandSourceStack source = context.getSource().withPermission(0); + String command = context.getArgument("command", String.class); + try { + return source.getServer().getCommands().performPrefixedCommand(source, command); + } catch(RuntimeException e) { + source.sendFailure(Component.literal(e.getMessage())); + return 0; + } + } + private static Component makeComputerDumpCommand(ServerComputer computer) { return ChatHelpers.link( diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java index 1287e9c3b..1acb46579 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java @@ -45,6 +45,7 @@ public class PeripheralsConfig implements IAPConfig { public final ForgeConfigSpec.IntValue chatBoxMaxRange; public final ForgeConfigSpec.BooleanValue chatBoxMultiDimensional; public final ForgeConfigSpec.BooleanValue chatBoxPreventRunCommand; + public final ForgeConfigSpec.BooleanValue chatBoxWrapCommand; public final ForgeConfigSpec.ConfigValue> chatBoxBannedCommands; private List> chatBoxCommandFilters = null; @@ -147,6 +148,7 @@ public PeripheralsConfig() { chatBoxMaxRange = builder.comment("Defines the maximal range of the chat box in blocks. -1 for infinite. If the range is not -1, players in other dimensions won't able to receive messages").defineInRange("chatBoxMaxRange", -1, -1, 30000000); chatBoxMultiDimensional = builder.comment("If true, the chat box is able to send messages to other dimensions than its own").define("chatBoxMultiDimensional", true); chatBoxPreventRunCommand = builder.comment("If true, the chat box cannot use 'run_command' action").define("chatBoxPreventRunCommand", false); + chatBoxWrapCommand = builder.comment("If true, the chat box will wrap and execute 'run_command' or 'suggest_command' action with zero permission, in order to prevent operators accidently run dangerous commands.").define("chatBoxWrapCommand", true); chatBoxBannedCommands = builder.comment("These commands below will not be able to send by 'run_command' or 'suggest_command' action. It will match as prefix if starts with '/', other wise use regex pattern").defineList("chatBoxBannedCommands", chatBoxDefaultBannedCommands, (o) -> o instanceof String value && value.length() > 0); pop("ME_Bridge", builder); From 98b04f404d82c648e296bf00cc0f22f141ab7209 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Mon, 27 May 2024 11:01:35 -0600 Subject: [PATCH 176/228] fix the space between `catch` keyword and the left bracket --- .../srendi/advancedperipherals/common/commands/APCommands.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java b/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java index 4691aeacb..8e005bd70 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java +++ b/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java @@ -114,7 +114,7 @@ private static int safeExecute(CommandContext context) throw String command = context.getArgument("command", String.class); try { return source.getServer().getCommands().performPrefixedCommand(source, command); - } catch(RuntimeException e) { + } catch (RuntimeException e) { source.sendFailure(Component.literal(e.getMessage())); return 0; } From ab05b9986f0d3099e55b1e31ef0fde942ca2b676 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Mon, 27 May 2024 11:04:30 -0600 Subject: [PATCH 177/228] use StringArgumentType.getString instead of context.getArgument --- .../srendi/advancedperipherals/common/commands/APCommands.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java b/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java index 8e005bd70..858494f40 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java +++ b/src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java @@ -111,7 +111,7 @@ private static int forceloadDump(CommandSourceStack source) throws CommandSyntax private static int safeExecute(CommandContext context) throws CommandSyntaxException { CommandSourceStack source = context.getSource().withPermission(0); - String command = context.getArgument("command", String.class); + String command = StringArgumentType.getString(context, "command"); try { return source.getServer().getCommands().performPrefixedCommand(source, command); } catch (RuntimeException e) { From 2b8c5f242629234e6d8474db9f9f19ac33874538 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Mon, 27 May 2024 11:20:14 -0600 Subject: [PATCH 178/228] fix forgot to assign the result to variable --- .../common/configuration/PeripheralsConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java index 1acb46579..0163339d2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/PeripheralsConfig.java @@ -234,7 +234,7 @@ private List> parseChatBoxCommandFilters() { for (final String s : chatBoxBannedCommands.get()) { String p = s; if (p.charAt(0) == '/') { - p.replaceAll("\\s+", "\\\\s+"); + p = p.replaceAll("\\s+", "\\\\s+"); if (p.equals(s)) { final String prefix = s; filters.add((v) -> v.startsWith(prefix) && (v.length() == prefix.length() || " \t".indexOf(v.charAt(prefix.length())) != -1)); From ee01ac74bda68b5a5e9cc78b073ab92c4398b04b Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sun, 2 Jun 2024 08:56:45 -0600 Subject: [PATCH 179/228] fix player can bypass the maximum chatbox range by setting a negative message range fix #623 --- .../peripheral/ChatBoxPeripheral.java | 36 ++++++++++++------- .../common/util/CoordUtil.java | 3 +- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java index d0bcb5c32..bf42a8ebc 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java @@ -111,8 +111,10 @@ public final MethodResult sendFormattedMessage(@NotNull IArguments arguments) th return withChatOperation(ignored -> { String message = arguments.getString(0); int maxRange = APConfig.PERIPHERALS_CONFIG.chatBoxMaxRange.get(); - int range = arguments.optInt(4, maxRange); - range = maxRange == -1 ? range : Math.min(range, APConfig.PERIPHERALS_CONFIG.chatBoxMaxRange.get()); + int range = Math.min(arguments.optInt(4, -1), maxRange); + if (range < 0) { + range = maxRange; + } ResourceKey dimension = getLevel().dimension(); MutableComponent component = Component.Serializer.fromJson(message); if (component == null) @@ -141,8 +143,10 @@ public final MethodResult sendMessage(@NotNull IArguments arguments) throws LuaE return withChatOperation(ignored -> { String message = arguments.getString(0); int maxRange = APConfig.PERIPHERALS_CONFIG.chatBoxMaxRange.get(); - int range = arguments.optInt(4, maxRange); - range = maxRange == -1 ? range : Math.min(range, APConfig.PERIPHERALS_CONFIG.chatBoxMaxRange.get()); + int range = Math.min(arguments.optInt(4, -1), maxRange); + if (range < 0) { + range = maxRange; + } ResourceKey dimension = getLevel().dimension(); if (checkBrackets(arguments.optString(2))) return MethodResult.of(null, "incorrect bracket string (e.g. [], {}, <>, ...)"); @@ -168,8 +172,10 @@ public final MethodResult sendFormattedMessageToPlayer(@NotNull IArguments argum String message = arguments.getString(0); String playerName = arguments.getString(1); int maxRange = APConfig.PERIPHERALS_CONFIG.chatBoxMaxRange.get(); - int range = arguments.optInt(5, maxRange); - range = maxRange == -1 ? range : Math.min(range, APConfig.PERIPHERALS_CONFIG.chatBoxMaxRange.get()); + int range = Math.min(arguments.optInt(5, -1), maxRange); + if (range < 0) { + range = maxRange; + } ResourceKey dimension = getLevel().dimension(); ServerPlayer player = getPlayer(playerName); if (player == null) @@ -204,8 +210,10 @@ public final MethodResult sendFormattedToastToPlayer(@NotNull IArguments argumen String title = arguments.getString(1); String playerName = arguments.getString(2); int maxRange = APConfig.PERIPHERALS_CONFIG.chatBoxMaxRange.get(); - int range = arguments.optInt(6, maxRange); - range = maxRange == -1 ? range : Math.min(range, APConfig.PERIPHERALS_CONFIG.chatBoxMaxRange.get()); + int range = Math.min(arguments.optInt(6, -1), maxRange); + if (range < 0) { + range = maxRange; + } ResourceKey dimension = getLevel().dimension(); ServerPlayer player = getPlayer(playerName); if (player == null) @@ -246,8 +254,10 @@ public final MethodResult sendMessageToPlayer(@NotNull IArguments arguments) thr String message = arguments.getString(0); String playerName = arguments.getString(1); int maxRange = APConfig.PERIPHERALS_CONFIG.chatBoxMaxRange.get(); - int range = arguments.optInt(5, maxRange); - range = maxRange == -1 ? range : Math.min(range, APConfig.PERIPHERALS_CONFIG.chatBoxMaxRange.get()); + int range = Math.min(arguments.optInt(5, -1), maxRange); + if (range < 0) { + range = maxRange; + } ResourceKey dimension = getLevel().dimension(); ServerPlayer player = getPlayer(playerName); if (player == null) @@ -277,8 +287,10 @@ public final MethodResult sendToastToPlayer(@NotNull IArguments arguments) throw String title = arguments.getString(1); String playerName = arguments.getString(2); int maxRange = APConfig.PERIPHERALS_CONFIG.chatBoxMaxRange.get(); - int range = arguments.optInt(6, maxRange); - range = maxRange == -1 ? range : Math.min(range, APConfig.PERIPHERALS_CONFIG.chatBoxMaxRange.get()); + int range = Math.min(arguments.optInt(6, -1), maxRange); + if (range < 0) { + range = maxRange; + } ResourceKey dimension = getLevel().dimension(); ServerPlayer player = getPlayer(playerName); if (player == null) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java index a21f2ab8d..980d88d99 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java @@ -19,8 +19,9 @@ public class CoordUtil { public static boolean isInRange(@Nullable BlockPos pos, @Nullable Level world, @Nullable Player player, int range, int maxRange) { // There are rare cases where these are null. For example if a player detector pocket computer runs while not in a player inventory // Fixes https://github.com/SirEndii/AdvancedPeripherals/issues/356 - if (pos == null || world == null || player == null) + if (pos == null || world == null || player == null) { return false; + } range = maxRange == -1 ? range : Math.min(Math.abs(range), maxRange); return isPlayerInBlockRange(pos, world, player, (double) range); From 8fda0f440c0ea5bc9ff8bdf2aecb0ef20d460af7 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sun, 2 Jun 2024 09:33:49 -0600 Subject: [PATCH 180/228] fix playerdetector bypass range issue --- .../peripheral/ChatBoxPeripheral.java | 40 +++++-------------- .../peripheral/PlayerDetectorPeripheral.java | 6 +-- .../common/util/CoordUtil.java | 23 ++++++++++- 3 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java index bf42a8ebc..873f7a0fe 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java @@ -111,10 +111,7 @@ public final MethodResult sendFormattedMessage(@NotNull IArguments arguments) th return withChatOperation(ignored -> { String message = arguments.getString(0); int maxRange = APConfig.PERIPHERALS_CONFIG.chatBoxMaxRange.get(); - int range = Math.min(arguments.optInt(4, -1), maxRange); - if (range < 0) { - range = maxRange; - } + int range = arguments.optInt(4, -1); ResourceKey dimension = getLevel().dimension(); MutableComponent component = Component.Serializer.fromJson(message); if (component == null) @@ -131,7 +128,7 @@ public final MethodResult sendFormattedMessage(@NotNull IArguments arguments) th for (ServerPlayer player : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers()) { if (!APConfig.PERIPHERALS_CONFIG.chatBoxMultiDimensional.get() && player.getLevel().dimension() != dimension) continue; - if (range == -1 || CoordUtil.isInRange(getPos(), getLevel(), player, range, maxRange)) + if (CoordUtil.isInRange(getPos(), getLevel(), player, range, maxRange)) player.sendSystemMessage(preparedMessage); } return MethodResult.of(true); @@ -143,10 +140,7 @@ public final MethodResult sendMessage(@NotNull IArguments arguments) throws LuaE return withChatOperation(ignored -> { String message = arguments.getString(0); int maxRange = APConfig.PERIPHERALS_CONFIG.chatBoxMaxRange.get(); - int range = Math.min(arguments.optInt(4, -1), maxRange); - if (range < 0) { - range = maxRange; - } + int range = arguments.optInt(4, -1); ResourceKey dimension = getLevel().dimension(); if (checkBrackets(arguments.optString(2))) return MethodResult.of(null, "incorrect bracket string (e.g. [], {}, <>, ...)"); @@ -159,7 +153,7 @@ public final MethodResult sendMessage(@NotNull IArguments arguments) throws LuaE for (ServerPlayer player : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers()) { if (!APConfig.PERIPHERALS_CONFIG.chatBoxMultiDimensional.get() && player.getLevel().dimension() != dimension) continue; - if (range == -1 || CoordUtil.isInRange(getPos(), getLevel(), player, range, maxRange)) + if (CoordUtil.isInRange(getPos(), getLevel(), player, range, maxRange)) player.sendSystemMessage(preparedMessage); } return MethodResult.of(true); @@ -173,9 +167,6 @@ public final MethodResult sendFormattedMessageToPlayer(@NotNull IArguments argum String playerName = arguments.getString(1); int maxRange = APConfig.PERIPHERALS_CONFIG.chatBoxMaxRange.get(); int range = Math.min(arguments.optInt(5, -1), maxRange); - if (range < 0) { - range = maxRange; - } ResourceKey dimension = getLevel().dimension(); ServerPlayer player = getPlayer(playerName); if (player == null) @@ -196,7 +187,7 @@ public final MethodResult sendFormattedMessageToPlayer(@NotNull IArguments argum if (!APConfig.PERIPHERALS_CONFIG.chatBoxMultiDimensional.get() && player.getLevel().dimension() != dimension) return MethodResult.of(false, "NOT_SAME_DIMENSION"); - if (range == -1 || CoordUtil.isInRange(getPos(), getLevel(), player, range, maxRange)) + if (CoordUtil.isInRange(getPos(), getLevel(), player, range, maxRange)) player.sendSystemMessage(preparedMessage); return MethodResult.of(true); }); @@ -210,10 +201,7 @@ public final MethodResult sendFormattedToastToPlayer(@NotNull IArguments argumen String title = arguments.getString(1); String playerName = arguments.getString(2); int maxRange = APConfig.PERIPHERALS_CONFIG.chatBoxMaxRange.get(); - int range = Math.min(arguments.optInt(6, -1), maxRange); - if (range < 0) { - range = maxRange; - } + int range = arguments.optInt(6, -1); ResourceKey dimension = getLevel().dimension(); ServerPlayer player = getPlayer(playerName); if (player == null) @@ -239,7 +227,7 @@ public final MethodResult sendFormattedToastToPlayer(@NotNull IArguments argumen if (!APConfig.PERIPHERALS_CONFIG.chatBoxMultiDimensional.get() && player.getLevel().dimension() != dimension) return MethodResult.of(false, "NOT_SAME_DIMENSION"); - if (range == -1 || CoordUtil.isInRange(getPos(), getLevel(), player, range, maxRange)) { + if (CoordUtil.isInRange(getPos(), getLevel(), player, range, maxRange)) { ToastToClientPacket packet = new ToastToClientPacket(titleComponent, preparedMessage); APNetworking.sendTo(packet, player); } @@ -254,10 +242,7 @@ public final MethodResult sendMessageToPlayer(@NotNull IArguments arguments) thr String message = arguments.getString(0); String playerName = arguments.getString(1); int maxRange = APConfig.PERIPHERALS_CONFIG.chatBoxMaxRange.get(); - int range = Math.min(arguments.optInt(5, -1), maxRange); - if (range < 0) { - range = maxRange; - } + int range = arguments.optInt(5, -1); ResourceKey dimension = getLevel().dimension(); ServerPlayer player = getPlayer(playerName); if (player == null) @@ -274,7 +259,7 @@ public final MethodResult sendMessageToPlayer(@NotNull IArguments arguments) thr if (!APConfig.PERIPHERALS_CONFIG.chatBoxMultiDimensional.get() && player.getLevel().dimension() != dimension) return MethodResult.of(false, "NOT_SAME_DIMENSION"); - if (range == -1 || CoordUtil.isInRange(getPos(), getLevel(), player, range, maxRange)) + if (CoordUtil.isInRange(getPos(), getLevel(), player, range, maxRange)) player.sendSystemMessage(preparedMessage, false); return MethodResult.of(true); }); @@ -287,10 +272,7 @@ public final MethodResult sendToastToPlayer(@NotNull IArguments arguments) throw String title = arguments.getString(1); String playerName = arguments.getString(2); int maxRange = APConfig.PERIPHERALS_CONFIG.chatBoxMaxRange.get(); - int range = Math.min(arguments.optInt(6, -1), maxRange); - if (range < 0) { - range = maxRange; - } + int range = arguments.optInt(6, -1); ResourceKey dimension = getLevel().dimension(); ServerPlayer player = getPlayer(playerName); if (player == null) @@ -308,7 +290,7 @@ public final MethodResult sendToastToPlayer(@NotNull IArguments arguments) throw if (!APConfig.PERIPHERALS_CONFIG.chatBoxMultiDimensional.get() && player.getLevel().dimension() != dimension) return MethodResult.of(false, "NOT_SAME_DIMENSION"); - if (range == -1 || CoordUtil.isInRange(getPos(), getLevel(), player, range, maxRange)) { + if (CoordUtil.isInRange(getPos(), getLevel(), player, range, maxRange)) { ToastToClientPacket packet = new ToastToClientPacket(Component.literal(title), preparedMessage); APNetworking.sendTo(packet, player); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/PlayerDetectorPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/PlayerDetectorPeripheral.java index 6e8b90fa3..8a6bf1913 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/PlayerDetectorPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/PlayerDetectorPeripheral.java @@ -97,7 +97,7 @@ public final List getPlayersInRange(int range) { for (ServerPlayer player : getPlayers()) { if (!isAllowedMultiDimensional() && player.getLevel().dimension() != dimension) continue; - if (range == -1 || CoordUtil.isInRange(getPos(), getLevel(), player, range, MAX_RANGE)) + if (CoordUtil.isInRange(getPos(), getLevel(), player, range, MAX_RANGE)) playersName.add(player.getName().getString()); } return playersName; @@ -142,7 +142,7 @@ public final boolean isPlayersInRange(int range) { for (ServerPlayer player : getPlayers()) { if (!isAllowedMultiDimensional() && player.getLevel().dimension() != dimension) continue; - if (range == -1 || CoordUtil.isInRange(getPos(), getLevel(), player, range, MAX_RANGE)) return true; + if (CoordUtil.isInRange(getPos(), getLevel(), player, range, MAX_RANGE)) return true; } return false; } @@ -185,7 +185,7 @@ public final boolean isPlayerInRange(int range, String username) { for (Player player : getPlayers()) { if (!isAllowedMultiDimensional() && player.getLevel().dimension() != dimension) continue; - if (range == -1 || CoordUtil.isInRange(getPos(), getLevel(), player, range, MAX_RANGE)) { + if (CoordUtil.isInRange(getPos(), getLevel(), player, range, MAX_RANGE)) { if(player.getName().getString().equals(username)) return true; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java index 980d88d99..48ff704e0 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java @@ -16,6 +16,17 @@ public class CoordUtil { + /** + * isInRange checks if the player is in the range + * + * @param pos the position to start check + * @param world the world to start check + * @param player the player going to be check + * @param range the range that user want to reach, must be -1, 0, or a positive number + * @param maxRange the maximum range the user can reach, must be -1, 0, or a positive number + * + * @return If the player is in the {@code range} as well as in the {@code maxRange}, or {@code range} and {@code maxRange} are -1 + */ public static boolean isInRange(@Nullable BlockPos pos, @Nullable Level world, @Nullable Player player, int range, int maxRange) { // There are rare cases where these are null. For example if a player detector pocket computer runs while not in a player inventory // Fixes https://github.com/SirEndii/AdvancedPeripherals/issues/356 @@ -23,7 +34,17 @@ public static boolean isInRange(@Nullable BlockPos pos, @Nullable Level world, @ return false; } - range = maxRange == -1 ? range : Math.min(Math.abs(range), maxRange); + if (range == 0 || maxRange == 0) { + return false; + } + if (range < 0) { + if (maxRange < 0) { + return true; + } + range = maxRange; + } else if (maxRange > 0 && range > maxRange) { + range = maxRange; + } return isPlayerInBlockRange(pos, world, player, (double) range); } From 15788bbed6336e676a543e194c0579784ab5a5db Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sun, 2 Jun 2024 12:27:35 -0600 Subject: [PATCH 181/228] forgot to remove a Math.min --- .../addons/computercraft/peripheral/ChatBoxPeripheral.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java index 873f7a0fe..43405f658 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ChatBoxPeripheral.java @@ -166,7 +166,7 @@ public final MethodResult sendFormattedMessageToPlayer(@NotNull IArguments argum String message = arguments.getString(0); String playerName = arguments.getString(1); int maxRange = APConfig.PERIPHERALS_CONFIG.chatBoxMaxRange.get(); - int range = Math.min(arguments.optInt(5, -1), maxRange); + int range = arguments.optInt(5, -1); ResourceKey dimension = getLevel().dimension(); ServerPlayer player = getPlayer(playerName); if (player == null) From 2f3b7b1eeb444868429b8f2812bb94f0860ac2ca Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sun, 2 Jun 2024 12:48:24 -0600 Subject: [PATCH 182/228] fix README link and missing semicolon --- README.md | 8 ++++---- .../common/util/fakeplayer/APFakePlayer.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6c841b3f9..69ad5b0cb 100644 --- a/README.md +++ b/README.md @@ -65,11 +65,11 @@ will close pull requests related to translations. [Documentation]: https://advancedperipherals.madefor.cc/ -[Contributors]: https://github.com/Seniorendi/AdvancedPeripherals/graphs/contributors +[Contributors]: https://github.com/IntelligenceModding/AdvancedPeripherals/graphs/contributors [CurseForge]: https://www.curseforge.com/minecraft/mc-mods/advanced-peripherals -[Actions]: https://github.com/Seniorendi/AdvancedPeripherals/actions +[Actions]: https://github.com/IntelligenceModding/AdvancedPeripherals/actions [Crowdin]: https://crowdin.com/project/advanced-peripherals -[Discord]: https://discord.com/invite/QuF3hWDtWC +[Discord]: https://discord.intelligence-modding.de [Banner]: https://www.bisecthosting.com/images/CF/Advanced_Peripherals/BH_AP_Header.png 'Advanced Peripherals' [PeripheralsPlusOne]: https://github.com/rolandoislas/PeripheralsPlusOne @@ -77,7 +77,7 @@ will close pull requests related to translations. [@FatalMerlin]: https://github.com/FatalMerlin [@SirEdvin]: https://github.com/SirEdvin -[@Srendi]: https://github.com/Seniorendi +[@Srendi]: https://github.com/IntelligenceModding [@Olfi01]: https://github.com/Olfi01 [License]: LICENSE diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java index e0aa45970..0f6e279cb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java @@ -151,7 +151,7 @@ public Pair digBlock() { if (hit.getType() == HitResult.Type.MISS) { return Pair.of(false, "Nothing to break"); } - BlockPos pos = new BlockPos(hit.getLocation()) + BlockPos pos = new BlockPos(hit.getLocation()); BlockState state = world.getBlockState(pos); Block block = state.getBlock(); From b28b7b48cfdb675203ee42f307fa89f257ee0edf Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sun, 2 Jun 2024 13:27:53 -0600 Subject: [PATCH 183/228] fix version changes --- .../plugins/AutomataBlockHandPlugin.java | 21 ++++++++++++------- .../common/util/fakeplayer/APFakePlayer.java | 17 ++++++++++----- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java index a92143043..d708f53c7 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java @@ -30,6 +30,7 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.SignBlockEntity; +import net.minecraft.world.level.block.entity.SignText; import net.minecraft.world.level.Level; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec3; @@ -107,7 +108,8 @@ public final MethodResult useOnBlock(@NotNull IArguments arguments) throws LuaEx * anchor: the direction the block is going to hanging on. Default is the direction of the turtle * front: the direction the block is going to facing. Default is same as anchor * top: the direction the block's top is going to facing. Default is TOP - * text: the text going to write on the sign. Default is null + * text: the text going to write on the sign's front side. Default is null + * backText: the text going to write on the sign's back side. Default is null */ @LuaFunction(mainThread = true) public MethodResult placeBlock(@NotNull Map options) throws LuaException { @@ -168,7 +170,7 @@ private String deployOn(ItemStack stack, BlockPos position, Direction anchor, Di TurtlePlayer turtlePlayer = TurtlePlayer.getWithPosition(turtle, position, front.getOpposite()); BlockHitResult hit = BlockHitResult.miss(Vec3.atCenterOf(position), top, position); AdvanceDirectionalPlaceContext context = new AdvanceDirectionalPlaceContext(world, position, anchor, front, stack, top); - PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock(turtlePlayer, InteractionHand.MAIN_HAND, position, hit); + PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock(turtlePlayer.player(), InteractionHand.MAIN_HAND, position, hit); if (event.isCanceled()) { return "EVENT_CANCELED"; } @@ -185,25 +187,28 @@ private String deployOn(ItemStack stack, BlockPos position, Direction anchor, Di BlockEntity blockEntity = world.getBlockEntity(position); if (blockEntity instanceof SignBlockEntity sign) { String text = StringUtil.convertAndToSectionMark(TableHelper.optStringField(options, "text", null)); - setSignText(world, sign, text); + setSignText(world, sign, text, true); + String backText = StringUtil.convertAndToSectionMark(TableHelper.optStringField(options, "backText", null)); + setSignText(world, sign, backText, false); } } return null; } - private static void setSignText(Level world, SignBlockEntity sign, String text) { + private static void setSignText(Level world, SignBlockEntity block, String text, boolean front) { + SignText sign = block.getText(front); if (text == null) { - for (int i = 0; i < SignBlockEntity.LINES; i++) { + for (int i = 0; i < SignText.LINES; i++) { sign.setMessage(i, Component.literal("")); } } else { String[] lines = text.split("\n"); - for (int i = 0; i < SignBlockEntity.LINES; i++) { + for (int i = 0; i < SignText.LINES; i++) { sign.setMessage(i, Component.literal(i < lines.length ? lines[i] : "")); } } - sign.setChanged(); - world.sendBlockUpdated(sign.getBlockPos(), sign.getBlockState(), sign.getBlockState(), Block.UPDATE_ALL); + block.setChanged(); + world.sendBlockUpdated(block.getBlockPos(), block.getBlockState(), block.getBlockState(), Block.UPDATE_ALL); } private static class AdvanceDirectionalPlaceContext extends DirectionalPlaceContext { diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java index 0f6e279cb..99e0e61cb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java @@ -28,6 +28,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.CommandBlock; import net.minecraft.world.level.block.StructureBlock; import net.minecraft.world.level.block.state.BlockState; @@ -72,6 +73,12 @@ public APFakePlayer(ServerLevel world, Entity owner, GameProfile profile) { } } + // public protected method + @Override + public void setLevel(Level level) { + super.setLevel(level); + } + @Override public void awardStat(@NotNull Stat stat) { MinecraftServer server = level().getServer(); @@ -146,12 +153,12 @@ public Pair digBlock(Direction direction) { } public Pair digBlock() { - Level world = getLevel(); + Level world = this.level(); HitResult hit = findHit(true, false); if (hit.getType() == HitResult.Type.MISS) { return Pair.of(false, "Nothing to break"); } - BlockPos pos = new BlockPos(hit.getLocation()); + BlockPos pos = ((BlockHitResult) hit).getBlockPos(); BlockState state = world.getBlockState(pos); Block block = state.getBlock(); @@ -167,7 +174,7 @@ public Pair digBlock() { Vec3 look = getLookAngle(); Direction direction = Direction.getNearest(look.x, look.y, look.z).getOpposite(); - if (world.isEmptyBlock(pos) || state.getMaterial().isLiquid()) { + if (world.isEmptyBlock(pos) || state.getBlock() instanceof LiquidBlock) { return Pair.of(false, "Nothing to dig here"); } @@ -180,7 +187,7 @@ public Pair digBlock() { } ServerPlayerGameMode manager = gameMode; - float breakSpeed = 0.5f * tool.getDestroySpeed(state) / state.getDestroySpeed(level, pos) - 0.1f; + float breakSpeed = 0.5f * tool.getDestroySpeed(state) / state.getDestroySpeed(world, pos) - 0.1f; for (int i = 0; i < 10; i++) { currentDamage += breakSpeed; @@ -312,7 +319,7 @@ public HitResult findHit(boolean skipEntity, boolean skipBlock, @Nullable Predic if (skipEntity) return blockHit; - List entities = level().getEntities(this, getBoundingBox().expandTowards(look.x * range, look.y * range, look.z * range).inflate(1, 1, 1), collidablePredicate); + List entities = this.level().getEntities(this, getBoundingBox().expandTowards(look.x * range, look.y * range, look.z * range).inflate(1, 1, 1), collidablePredicate); LivingEntity closestEntity = null; Vec3 closestVec = null; From c7a36953897411cdf2fafa8e825210b85003813f Mon Sep 17 00:00:00 2001 From: Michele Grifa Date: Fri, 7 Jun 2024 10:36:59 +0200 Subject: [PATCH 184/228] Fix ME listCells method --- .../common/addons/appliedenergistics/AppEngApi.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java index 97d27b4a9..df44e2c86 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java @@ -558,7 +558,7 @@ public static long getAvailableFluidStorage(IGridNode node) { public static List listCells(IGridNode node) { List items = new ArrayList<>(); - Iterator iterator = node.getGrid().getMachineNodes(DriveBlockEntity.class).iterator(); + Iterator iterator = node.getGrid().getNodes().iterator(); if (!iterator.hasNext()) return items; while (iterator.hasNext()) { From 660e63f0630f842420dde2cebdfd5dafcde2df72 Mon Sep 17 00:00:00 2001 From: WiggleWizard <1405402+WiggleWizard@users.noreply.github.com> Date: Sun, 9 Jun 2024 00:11:57 +0100 Subject: [PATCH 185/228] AdvancedPeripheral Blocks now keep their name when changed after placing and/or destroying --- .../59eb3dbb5f86130e09b3c62d89b9525ee01cf52d | 28 +++++++++---------- .../loot_tables/blocks/block_reader.json | 6 ++++ .../loot_tables/blocks/chat_box.json | 6 ++++ .../loot_tables/blocks/colony_integrator.json | 6 ++++ .../loot_tables/blocks/energy_detector.json | 6 ++++ .../blocks/environment_detector.json | 6 ++++ .../loot_tables/blocks/geo_scanner.json | 6 ++++ .../loot_tables/blocks/inventory_manager.json | 6 ++++ .../loot_tables/blocks/me_bridge.json | 6 ++++ .../loot_tables/blocks/nbt_storage.json | 6 ++++ .../loot_tables/blocks/peripheral_casing.json | 6 ++++ .../loot_tables/blocks/player_detector.json | 6 ++++ .../blocks/redstone_integrator.json | 6 ++++ .../loot_tables/blocks/rs_bridge.json | 6 ++++ .../blocks/base/BaseBlockEntityBlock.java | 6 +++- .../common/data/BlockLootTables.java | 5 +++- 16 files changed, 101 insertions(+), 16 deletions(-) diff --git a/src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d b/src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d index 21704c05c..c28b3073f 100644 --- a/src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d +++ b/src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d @@ -1,14 +1,14 @@ -// 1.20.1 2023-10-08T00:39:38.7989175 Loot Tables -d83e42ffe1cb1b2c2f3feed0148f44fa31ca9ac8 data/advancedperipherals/loot_tables/blocks/block_reader.json -177b57033208131e377193a8c15bbeec0138dee3 data/advancedperipherals/loot_tables/blocks/chat_box.json -093b500c291b6f3a4e9990c5cd8b2cf0801bd26f data/advancedperipherals/loot_tables/blocks/colony_integrator.json -f6c42ab447af7bd948e609e926ac053b1dc72c44 data/advancedperipherals/loot_tables/blocks/energy_detector.json -1d11eef7114c1fa41841cb0c0f5766901b6eca21 data/advancedperipherals/loot_tables/blocks/environment_detector.json -3023e33353c226c18212ec0df3a88906f6bde1dd data/advancedperipherals/loot_tables/blocks/geo_scanner.json -9d97568cf422184ba1ce940abb3c53b4fb5fc419 data/advancedperipherals/loot_tables/blocks/inventory_manager.json -0f7096e4b313f59985d063f3eca7b9b1c62898ca data/advancedperipherals/loot_tables/blocks/me_bridge.json -9ab5190ac8f1ac6cb900709e278a71dc10ff49c4 data/advancedperipherals/loot_tables/blocks/nbt_storage.json -75b3fa426dbba542747d50323892494532655e00 data/advancedperipherals/loot_tables/blocks/peripheral_casing.json -50a4d6a8736ccf85e6be11fdd816686140caaa48 data/advancedperipherals/loot_tables/blocks/player_detector.json -8c9cbcfa464970683e0fad6628a6440851e333e9 data/advancedperipherals/loot_tables/blocks/redstone_integrator.json -4dd3918b564ef180c05ab88a80f202eae3a9504d data/advancedperipherals/loot_tables/blocks/rs_bridge.json +// 1.20.1 2024-06-09T00:04:43.7599744 Loot Tables +fdf4d9f8220d3a5207f8e4334bff2f06cd203b04 data/advancedperipherals/loot_tables/blocks/block_reader.json +8c3dba853066f5f8da0a27b0783e68fc33e8bebc data/advancedperipherals/loot_tables/blocks/chat_box.json +123a8a096d78070f9aa3e872b0cb34cbc458f595 data/advancedperipherals/loot_tables/blocks/colony_integrator.json +765df45ccaef4e908a480da9cb6f13ab1b4d7545 data/advancedperipherals/loot_tables/blocks/energy_detector.json +9144fbb590a4c6e9cf7b8ef87fc80faf321c7e16 data/advancedperipherals/loot_tables/blocks/environment_detector.json +4e184ec10657d1dc11ee7da33f244b2e23d61460 data/advancedperipherals/loot_tables/blocks/geo_scanner.json +266e98d8eeec6ef465832cac664e5ab05bca96af data/advancedperipherals/loot_tables/blocks/inventory_manager.json +ee86218933f0da283ae1dd6617d74ed41a04575b data/advancedperipherals/loot_tables/blocks/me_bridge.json +6aec9d25423531f9236266e2535d6c4633129935 data/advancedperipherals/loot_tables/blocks/nbt_storage.json +e9ed113da52cddcce17768d0999d4f9aefb4cfa7 data/advancedperipherals/loot_tables/blocks/peripheral_casing.json +33c81013355b11d7c8630c811ddd80232d3c1c7c data/advancedperipherals/loot_tables/blocks/player_detector.json +e88dae55b3850e66ce81752eb060b1e0fe8f707e data/advancedperipherals/loot_tables/blocks/redstone_integrator.json +dfb4e28d40828f2ef96dc9bd7b2a67e40fcd0c78 data/advancedperipherals/loot_tables/blocks/rs_bridge.json diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/block_reader.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/block_reader.json index cd740e279..c6c5746be 100644 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/block_reader.json +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/block_reader.json @@ -11,6 +11,12 @@ "entries": [ { "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_name", + "source": "block_entity" + } + ], "name": "advancedperipherals:block_reader" } ], diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/chat_box.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/chat_box.json index 9319c45bf..1c2aef2a3 100644 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/chat_box.json +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/chat_box.json @@ -11,6 +11,12 @@ "entries": [ { "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_name", + "source": "block_entity" + } + ], "name": "advancedperipherals:chat_box" } ], diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/colony_integrator.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/colony_integrator.json index df9476c77..bdeafb684 100644 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/colony_integrator.json +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/colony_integrator.json @@ -11,6 +11,12 @@ "entries": [ { "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_name", + "source": "block_entity" + } + ], "name": "advancedperipherals:colony_integrator" } ], diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/energy_detector.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/energy_detector.json index 16e1f5a7e..2b4c2c7b2 100644 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/energy_detector.json +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/energy_detector.json @@ -11,6 +11,12 @@ "entries": [ { "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_name", + "source": "block_entity" + } + ], "name": "advancedperipherals:energy_detector" } ], diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/environment_detector.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/environment_detector.json index 310bc5f25..47cbb35c0 100644 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/environment_detector.json +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/environment_detector.json @@ -11,6 +11,12 @@ "entries": [ { "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_name", + "source": "block_entity" + } + ], "name": "advancedperipherals:environment_detector" } ], diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/geo_scanner.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/geo_scanner.json index c3a81e225..7f9d55082 100644 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/geo_scanner.json +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/geo_scanner.json @@ -11,6 +11,12 @@ "entries": [ { "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_name", + "source": "block_entity" + } + ], "name": "advancedperipherals:geo_scanner" } ], diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/inventory_manager.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/inventory_manager.json index 0746f9ee0..de0e972f6 100644 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/inventory_manager.json +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/inventory_manager.json @@ -11,6 +11,12 @@ "entries": [ { "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_name", + "source": "block_entity" + } + ], "name": "advancedperipherals:inventory_manager" } ], diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/me_bridge.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/me_bridge.json index 938982af6..1921ca589 100644 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/me_bridge.json +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/me_bridge.json @@ -11,6 +11,12 @@ "entries": [ { "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_name", + "source": "block_entity" + } + ], "name": "advancedperipherals:me_bridge" } ], diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/nbt_storage.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/nbt_storage.json index 634aa47ed..5b96bf783 100644 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/nbt_storage.json +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/nbt_storage.json @@ -11,6 +11,12 @@ "entries": [ { "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_name", + "source": "block_entity" + } + ], "name": "advancedperipherals:nbt_storage" } ], diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/peripheral_casing.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/peripheral_casing.json index 97ac3c44d..ebc512b29 100644 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/peripheral_casing.json +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/peripheral_casing.json @@ -11,6 +11,12 @@ "entries": [ { "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_name", + "source": "block_entity" + } + ], "name": "advancedperipherals:peripheral_casing" } ], diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/player_detector.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/player_detector.json index f772b7b89..9c06f68ef 100644 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/player_detector.json +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/player_detector.json @@ -11,6 +11,12 @@ "entries": [ { "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_name", + "source": "block_entity" + } + ], "name": "advancedperipherals:player_detector" } ], diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/redstone_integrator.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/redstone_integrator.json index 67b7755a8..771e2e3d3 100644 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/redstone_integrator.json +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/redstone_integrator.json @@ -11,6 +11,12 @@ "entries": [ { "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_name", + "source": "block_entity" + } + ], "name": "advancedperipherals:redstone_integrator" } ], diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/rs_bridge.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/rs_bridge.json index 27f0576fe..5065b7f85 100644 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/rs_bridge.json +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/rs_bridge.json @@ -11,6 +11,12 @@ "entries": [ { "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_name", + "source": "block_entity" + } + ], "name": "advancedperipherals:rs_bridge" } ], diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlockEntityBlock.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlockEntityBlock.java index 4ca37d78f..91c60556b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlockEntityBlock.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlockEntityBlock.java @@ -13,6 +13,7 @@ import net.minecraft.world.level.block.EntityBlock; import net.minecraft.world.level.block.RenderShape; import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.entity.BaseContainerBlockEntity; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityTicker; import net.minecraft.world.level.block.entity.BlockEntityType; @@ -64,7 +65,10 @@ public void setPlacedBy(@NotNull Level worldIn, @NotNull BlockPos pos, @NotNull if (worldIn.getBlockEntity(pos) == null) return; //Used for the lua function getName() - worldIn.getBlockEntity(pos).getPersistentData().putString("CustomName", stack.getDisplayName().getString()); + BlockEntity blockEntity; + if (stack.hasCustomHoverName() && (blockEntity = worldIn.getBlockEntity(pos)) instanceof BaseContainerBlockEntity) { + ((BaseContainerBlockEntity)blockEntity).setCustomName(stack.getHoverName()); + } } @Nullable diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java b/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java index 2d825a312..18b687dca 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java @@ -17,7 +17,10 @@ protected BlockLootTables() { @Override protected void generate() { - Registration.BLOCKS.getEntries().stream().map(RegistryObject::get).forEach(this::dropSelf); + Registration.BLOCKS.getEntries().stream().map(RegistryObject::get).forEach(registeredBlock -> { + //Allow blocks to transfer their name to the dropped block when broken + this.add(registeredBlock, (Block block) -> this.createNameableBlockEntityTable((Block)block)); + }); } @NotNull From 5d635365e063bd7d8bb31389b1e0875cc2ca810a Mon Sep 17 00:00:00 2001 From: WiggleWizard <1405402+WiggleWizard@users.noreply.github.com> Date: Sun, 9 Jun 2024 00:59:52 +0100 Subject: [PATCH 186/228] Peripheral now fetching the block's name via existing base game implementations --- .../owner/BlockEntityPeripheralOwner.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java index 0317806d4..f0d315f6e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java @@ -9,6 +9,7 @@ import net.minecraft.core.Direction; import net.minecraft.core.FrontAndTop; import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.Nameable; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; @@ -32,7 +33,14 @@ public BlockEntityPeripheralOwner(T tileEntity) { @Nullable @Override public String getCustomName() { - return tileEntity.getPersistentData().getString("CustomName"); + String result = ""; + + if (tileEntity instanceof Nameable nameableEntity) + { + result = nameableEntity.getCustomName().getString(); + } + + return result; } @NotNull From 0b25c77b711ccc8df1ce5ea583597d631b393114 Mon Sep 17 00:00:00 2001 From: WiggleWizard <1405402+WiggleWizard@users.noreply.github.com> Date: Sun, 9 Jun 2024 01:07:23 +0100 Subject: [PATCH 187/228] Apply style change suggestions from code review Co-authored-by: Kevin Z Signed-off-by: WiggleWizard <1405402+WiggleWizard@users.noreply.github.com> --- .../computercraft/owner/BlockEntityPeripheralOwner.java | 3 +-- .../common/blocks/base/BaseBlockEntityBlock.java | 5 ++--- .../advancedperipherals/common/data/BlockLootTables.java | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java index f0d315f6e..6eec291ce 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java @@ -35,8 +35,7 @@ public BlockEntityPeripheralOwner(T tileEntity) { public String getCustomName() { String result = ""; - if (tileEntity instanceof Nameable nameableEntity) - { + if (tileEntity instanceof Nameable nameableEntity) { result = nameableEntity.getCustomName().getString(); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlockEntityBlock.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlockEntityBlock.java index 91c60556b..18471bd12 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlockEntityBlock.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlockEntityBlock.java @@ -65,9 +65,8 @@ public void setPlacedBy(@NotNull Level worldIn, @NotNull BlockPos pos, @NotNull if (worldIn.getBlockEntity(pos) == null) return; //Used for the lua function getName() - BlockEntity blockEntity; - if (stack.hasCustomHoverName() && (blockEntity = worldIn.getBlockEntity(pos)) instanceof BaseContainerBlockEntity) { - ((BaseContainerBlockEntity)blockEntity).setCustomName(stack.getHoverName()); + if (stack.hasCustomHoverName() && worldIn.getBlockEntity(pos) instanceof BaseContainerBlockEntity blockEntity) { + blockEntity.setCustomName(stack.getHoverName()); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java b/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java index 18b687dca..3f8adadb1 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java @@ -19,7 +19,7 @@ protected BlockLootTables() { protected void generate() { Registration.BLOCKS.getEntries().stream().map(RegistryObject::get).forEach(registeredBlock -> { //Allow blocks to transfer their name to the dropped block when broken - this.add(registeredBlock, (Block block) -> this.createNameableBlockEntityTable((Block)block)); + this.add(registeredBlock, (block) -> this.createNameableBlockEntityTable(block)); }); } From 4a196f8b14fed0612264f47c51236695c6550185 Mon Sep 17 00:00:00 2001 From: WiggleWizard <1405402+WiggleWizard@users.noreply.github.com> Date: Sun, 9 Jun 2024 12:12:07 +0100 Subject: [PATCH 188/228] Ported https://github.com/IntelligenceModding/AdvancedPeripherals/pull/633 to 1.19.2 --- .../loot_tables/blocks/block_reader.json | 6 ++++++ .../loot_tables/blocks/chat_box.json | 6 ++++++ .../loot_tables/blocks/colony_integrator.json | 6 ++++++ .../loot_tables/blocks/energy_detector.json | 6 ++++++ .../loot_tables/blocks/environment_detector.json | 6 ++++++ .../loot_tables/blocks/geo_scanner.json | 6 ++++++ .../loot_tables/blocks/inventory_manager.json | 6 ++++++ .../loot_tables/blocks/me_bridge.json | 6 ++++++ .../loot_tables/blocks/nbt_storage.json | 6 ++++++ .../loot_tables/blocks/peripheral_casing.json | 6 ++++++ .../loot_tables/blocks/player_detector.json | 6 ++++++ .../loot_tables/blocks/redstone_integrator.json | 6 ++++++ .../loot_tables/blocks/rs_bridge.json | 6 ++++++ .../owner/BlockEntityPeripheralOwner.java | 13 ++++++++++++- .../common/blocks/base/BaseBlockEntityBlock.java | 5 ++++- .../common/data/BlockLootTables.java | 5 ++++- 16 files changed, 98 insertions(+), 3 deletions(-) diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/block_reader.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/block_reader.json index d245e5775..c161fb4a1 100644 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/block_reader.json +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/block_reader.json @@ -11,6 +11,12 @@ "entries": [ { "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_name", + "source": "block_entity" + } + ], "name": "advancedperipherals:block_reader" } ], diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/chat_box.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/chat_box.json index ab850f168..72f11452f 100644 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/chat_box.json +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/chat_box.json @@ -11,6 +11,12 @@ "entries": [ { "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_name", + "source": "block_entity" + } + ], "name": "advancedperipherals:chat_box" } ], diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/colony_integrator.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/colony_integrator.json index 2bb457d23..b3c8367b4 100644 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/colony_integrator.json +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/colony_integrator.json @@ -11,6 +11,12 @@ "entries": [ { "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_name", + "source": "block_entity" + } + ], "name": "advancedperipherals:colony_integrator" } ], diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/energy_detector.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/energy_detector.json index 5f50436a8..157f6af93 100644 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/energy_detector.json +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/energy_detector.json @@ -11,6 +11,12 @@ "entries": [ { "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_name", + "source": "block_entity" + } + ], "name": "advancedperipherals:energy_detector" } ], diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/environment_detector.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/environment_detector.json index 2fcedc863..a82320156 100644 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/environment_detector.json +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/environment_detector.json @@ -11,6 +11,12 @@ "entries": [ { "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_name", + "source": "block_entity" + } + ], "name": "advancedperipherals:environment_detector" } ], diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/geo_scanner.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/geo_scanner.json index 749c1b466..4b8b701d5 100644 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/geo_scanner.json +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/geo_scanner.json @@ -11,6 +11,12 @@ "entries": [ { "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_name", + "source": "block_entity" + } + ], "name": "advancedperipherals:geo_scanner" } ], diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/inventory_manager.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/inventory_manager.json index 0311dbe6a..729cddc1d 100644 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/inventory_manager.json +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/inventory_manager.json @@ -11,6 +11,12 @@ "entries": [ { "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_name", + "source": "block_entity" + } + ], "name": "advancedperipherals:inventory_manager" } ], diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/me_bridge.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/me_bridge.json index 619dc374d..1e3756ca4 100644 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/me_bridge.json +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/me_bridge.json @@ -11,6 +11,12 @@ "entries": [ { "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_name", + "source": "block_entity" + } + ], "name": "advancedperipherals:me_bridge" } ], diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/nbt_storage.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/nbt_storage.json index e901b7504..af33f6fa2 100644 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/nbt_storage.json +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/nbt_storage.json @@ -11,6 +11,12 @@ "entries": [ { "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_name", + "source": "block_entity" + } + ], "name": "advancedperipherals:nbt_storage" } ], diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/peripheral_casing.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/peripheral_casing.json index 487f75488..1d3a2f360 100644 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/peripheral_casing.json +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/peripheral_casing.json @@ -11,6 +11,12 @@ "entries": [ { "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_name", + "source": "block_entity" + } + ], "name": "advancedperipherals:peripheral_casing" } ], diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/player_detector.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/player_detector.json index f3eb0cd73..9cc314ca4 100644 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/player_detector.json +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/player_detector.json @@ -11,6 +11,12 @@ "entries": [ { "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_name", + "source": "block_entity" + } + ], "name": "advancedperipherals:player_detector" } ], diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/redstone_integrator.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/redstone_integrator.json index a2fe008ef..a9fb17e50 100644 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/redstone_integrator.json +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/redstone_integrator.json @@ -11,6 +11,12 @@ "entries": [ { "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_name", + "source": "block_entity" + } + ], "name": "advancedperipherals:redstone_integrator" } ], diff --git a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/rs_bridge.json b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/rs_bridge.json index 18c751f47..0b8f4f6d7 100644 --- a/src/generated/resources/data/advancedperipherals/loot_tables/blocks/rs_bridge.json +++ b/src/generated/resources/data/advancedperipherals/loot_tables/blocks/rs_bridge.json @@ -11,6 +11,12 @@ "entries": [ { "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_name", + "source": "block_entity" + } + ], "name": "advancedperipherals:rs_bridge" } ], diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java index 0317806d4..2ea0bd6a3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java @@ -9,6 +9,8 @@ import net.minecraft.core.Direction; import net.minecraft.core.FrontAndTop; import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.world.Nameable; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; @@ -32,7 +34,16 @@ public BlockEntityPeripheralOwner(T tileEntity) { @Nullable @Override public String getCustomName() { - return tileEntity.getPersistentData().getString("CustomName"); + String result = ""; + + if (tileEntity instanceof Nameable nameableEntity) { + Component customName = nameableEntity.getCustomName(); + if (customName != null) { + result = customName.toString(); + } + } + + return result; } @NotNull diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlockEntityBlock.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlockEntityBlock.java index 14549c842..a0aec0d0e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlockEntityBlock.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/base/BaseBlockEntityBlock.java @@ -12,6 +12,7 @@ import net.minecraft.world.level.block.EntityBlock; import net.minecraft.world.level.block.RenderShape; import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.entity.BaseContainerBlockEntity; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityTicker; import net.minecraft.world.level.block.entity.BlockEntityType; @@ -64,7 +65,9 @@ public void setPlacedBy(@NotNull Level worldIn, @NotNull BlockPos pos, @NotNull if (worldIn.getBlockEntity(pos) == null) return; //Used for the lua function getName() - worldIn.getBlockEntity(pos).getPersistentData().putString("CustomName", stack.getDisplayName().getString()); + if (stack.hasCustomHoverName() && worldIn.getBlockEntity(pos) instanceof BaseContainerBlockEntity blockEntity) { + blockEntity.setCustomName(stack.getHoverName()); + } } @Nullable diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java b/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java index fe6799cd7..894a18ff3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/BlockLootTables.java @@ -9,7 +9,10 @@ public class BlockLootTables extends net.minecraft.data.loot.BlockLoot { @Override protected void addTables() { - Registration.BLOCKS.getEntries().stream().map(RegistryObject::get).forEach(this::dropSelf); + Registration.BLOCKS.getEntries().stream().map(RegistryObject::get).forEach(registeredBlock -> { + //Allow blocks to transfer their name to the dropped block when broken + this.add(registeredBlock, (block) -> this.createNameableBlockEntityTable(block)); + }); } @NotNull From 076c7b62bb72f2435e0aa4903d60a3d8bba4bc0c Mon Sep 17 00:00:00 2001 From: Srendi Date: Tue, 11 Jun 2024 09:38:20 +0200 Subject: [PATCH 189/228] include sources jar with maven artifacts --- build.gradle | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index cea635d97..b63f1f356 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,12 @@ plugins { id 'java' } -java.toolchain.languageVersion = JavaLanguageVersion.of(17) +java { + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } + withSourcesJar() +} wrapper { gradleVersion = '8.4' @@ -544,7 +549,7 @@ publishing { publication.groupId = project.group publication.version = isSnapshotVersion ? "${minecraft_version}-${version}-${project.teamcityBuild}" : "${minecraft_version}-${version}" publication.artifactId = isSnapshotVersion ? "advancedperipherals-snapshots" : "advancedperipherals" - publication.artifacts = [jar] + publication.artifacts = [jar, sourcesJar] publication.pom { name.set("AdvancedPeripherals") packaging = 'jar' From b0f912309eb935257c559d974915a9f872390e34 Mon Sep 17 00:00:00 2001 From: Srendi Date: Tue, 11 Jun 2024 10:23:09 +0200 Subject: [PATCH 190/228] 1.19.2-0.7.36r --- CHANGELOG.md | 25 +++++++++++++++++++++++++ gradle.properties | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca4076697..bcca9a6e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,31 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [1.19.2-0.7.36r] - 2024-06-11 + +### Added +- [Features/#43] Up/down versions of automata block functions using pitch and yaw - Thanks to @zyxkad +- [Features/#9] Added shift sneaking version of `useOnBlock` - Thanks to @zyxkad + +### Fixed +- [#582] Reworked the chunky turtle logic to fix several issues with them - Thanks to @zyxkad +- Fixed a crash with the ME Bridge while trying to iterate through storage busses without a connected storage block +- Fixed `isOnEnchantedSoil()` for the mana flower integration +- [#419] Fixed that the automata `digBlock` function does not use breaking directions the right way. Fixes several issues with hammers or other AOE tools. - Thanks to @zyxkad +- [#629] Fixed that placed blocks do not retain their custom block name when destroyed - Thanks to @WiggleWizzard +- [#621] Fixed that the `listCells` function for the ME Bridge does not search in third party drives - Thanks to @michele-grifa +- [#632] Fixed that the chat box allows sending chat messages with negative range - Thanks to @zyxkad +- [#619] Fixed that the chat box can spoof people to click message to run danger commands - Thanks to @zyxkad +- [#617] Fixed that sending invalid nbt data for some mod items through the chat box can cause a client crash - Thanks to @zyxkad +- [#603] Fixed that the note block integration does not trigger allays - Thanks to @zyxkad +- [#599] Fixed that turtle upgrades can't be equipped with custom NBT values - Thanks to @zyxkad +- [#595] Fixed that `scanEntities` does not include living entity fields - Thanks to @zyxkad +- [#581] Fixed concurrency issues with our server worker, fixes a crash when CC is set to use multiple threads - Thanks to @zyxkad + +### Changed +- [#588] Changed the misspelled `maxHealth` parameter in the player detector, the misspelled attribute is still included in the table for backwards compatibility - Thanks to @zyxkad +- [#613] Clamp analog output of the `setAnalogOutput` function between 0-15 - Thanks to @zyxkad + ## [1.19.2-0.7.35r] - 2024-04-12 ### Fixed diff --git a/gradle.properties b/gradle.properties index 5fb9d7792..bc6264c70 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ mod_id=advancedperipherals minecraft_version=1.19.2 forge_version=43.3.8 loader_version=43 -mod_version=0.7.36r +mod_version=0.7.37r release_type=release mappings_channel=parchment mappings_version=2022.11.27-1.19.2 From 50e64e181cde72824167130464fee1ad92398895 Mon Sep 17 00:00:00 2001 From: Srendi Date: Tue, 11 Jun 2024 10:32:29 +0200 Subject: [PATCH 191/228] Update bug_report.yml Signed-off-by: Srendi --- .github/ISSUE_TEMPLATE/bug_report.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 30df7e0bc..bd8d15a5f 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -1,7 +1,7 @@ name: Bug Report description: Report bugs and problems labels: ["bug", "needs review"] -projects: ["IntelligenceModding/2"] +projects: "IntelligenceModding/2" body: - type: markdown attributes: From 4c4d3702a9b904ca672ee40f9b5486137f9b1a30 Mon Sep 17 00:00:00 2001 From: Srendi Date: Tue, 11 Jun 2024 15:01:29 +0200 Subject: [PATCH 192/228] 1.20.1-0.7.40r --- CHANGELOG.md | 25 +++++++++++++++++++++++++ gradle.properties | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index afbe5287e..19ac667aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,31 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [1.20.1-0.7.40r] - 2024-06-11 + +### Added +- [Features/#43] Up/down versions of automata block functions using pitch and yaw - Thanks to @zyxkad +- [Features/#9] Added shift sneaking version of `useOnBlock` - Thanks to @zyxkad + +### Fixed +- [#582] Reworked the chunky turtle logic to fix several issues with them - Thanks to @zyxkad +- Fixed a crash with the ME Bridge while trying to iterate through storage busses without a connected storage block +- Fixed `isOnEnchantedSoil()` for the mana flower integration +- [#419] Fixed that the automata `digBlock` function does not use breaking directions the right way. Fixes several issues with hammers or other AOE tools. - Thanks to @zyxkad +- [#629] Fixed that placed blocks do not retain their custom block name when destroyed - Thanks to @WiggleWizzard +- [#621] Fixed that the `listCells` function for the ME Bridge does not search in third party drives - Thanks to @michele-grifa +- [#632] Fixed that the chat box allows sending chat messages with negative range - Thanks to @zyxkad +- [#619] Fixed that the chat box can spoof people to click message to run danger commands - Thanks to @zyxkad +- [#617] Fixed that sending invalid nbt data for some mod items through the chat box can cause a client crash - Thanks to @zyxkad +- [#603] Fixed that the note block integration does not trigger allays - Thanks to @zyxkad +- [#599] Fixed that turtle upgrades can't be equipped with custom NBT values - Thanks to @zyxkad +- [#595] Fixed that `scanEntities` does not include living entity fields - Thanks to @zyxkad +- [#581] Fixed concurrency issues with our server worker, fixes a crash when CC is set to use multiple threads - Thanks to @zyxkad + +### Changed +- [#588] Changed the misspelled `maxHealth` parameter in the player detector, the misspelled attribute is still included in the table for backwards compatibility - Thanks to @zyxkad +- [#613] Clamp analog output of the `setAnalogOutput` function between 0-15 - Thanks to @zyxkad + ## [1.20.1-0.7.39r] - 2024-04-12 ### Fixed - [#578] Re-Added botania integration with a few new functions diff --git a/gradle.properties b/gradle.properties index 1489af619..53eb44312 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ mod_id=advancedperipherals minecraft_version=1.20.1 neo_version=47.1.99 loader_version=47 -mod_version=0.7.40r +mod_version=0.7.41r release_type=release mappings_channel=official #mappings_version=2022.11.27-1.19.2 From 99ae602ca5fa309e1d70b581b0b1ef7297ff492b Mon Sep 17 00:00:00 2001 From: zyxkad Date: Fri, 14 Jun 2024 09:17:43 -0600 Subject: [PATCH 193/228] clear owner after put memory card into inventory manager resolve IntelligenceModding/Advanced-Peripherals-Features#87 --- .../blockentities/InventoryManagerEntity.java | 52 ++++++++++++++++--- .../common/items/MemoryCardItem.java | 19 ++++--- 2 files changed, 57 insertions(+), 14 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java index fad6ce3d7..e3a376a08 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java @@ -8,6 +8,7 @@ import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; @@ -15,11 +16,15 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.server.ServerLifecycleHooks; + import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.UUID; public class InventoryManagerEntity extends PeripheralBlockEntity implements IInventoryBlock { + private UUID owner = null; + public InventoryManagerEntity(BlockPos pos, BlockState state) { super(BlockEntityTypes.INVENTORY_MANAGER.get(), pos, state); } @@ -45,21 +50,52 @@ public boolean canPlaceItemThroughFace(int index, @NotNull ItemStack itemStackIn return itemStackIn.getItem() instanceof MemoryCardItem; } + @Override + public void setItem(int index, @NotNull ItemStack stack) { + if (stack.getItem() instanceof MemoryCardItem && stack.hasTag() && stack.getTag().contains("ownerId")) { + UUID owner = stack.getTag().getUUID("ownerId"); + this.owner = owner; + stack.getTag().remove("ownerId"); + stack.getTag().remove("owner"); + } else { + this.owner = null; + } + super.setItem(index, stack); + } + @NotNull @Override public Component getDisplayName() { return Component.translatable("block.advancedperipherals.inventory_manager"); } + @Override + public void load(CompoundTag data) { + if (data.contains("ownerId")) { + this.owner = data.getUUID("ownerId"); + } + super.load(data); + // Fresh the memory card for backward compatibility + this.setItem(0, this.getItem(0)); + } + + @Override + public void saveAdditional(CompoundTag data) { + super.saveAdditional(data); + if (this.owner != null) { + data.putUUID("ownerId", this.owner); + } + } + public Player getOwnerPlayer() { - //Checks if the tile entity has an item in his inventory - if (items.get(0).isEmpty()) return null; - ItemStack stack = items.get(0); - //Checks if the item contains the owner name - if (!stack.getOrCreateTag().contains("owner")) return null; - //Loop through all players and check if the player is online - for (Player entity : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers()) { - if (entity.getName().getString().equals(stack.getOrCreateTag().getString("owner"))) return entity; + if (this.owner == null) { + return null; + } + // Loop through all players and check if the player is online + for (Player player : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers()) { + if (player.getUUID().equals(this.owner)) { + return player; + } } return null; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/MemoryCardItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/MemoryCardItem.java index 030862818..5a4d51344 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/MemoryCardItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/MemoryCardItem.java @@ -3,6 +3,7 @@ import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.items.base.BaseItem; import de.srendi.advancedperipherals.common.util.EnumColor; +import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResultHolder; @@ -28,21 +29,27 @@ public boolean isEnabled() { @Override public void appendHoverText(ItemStack stack, @Nullable Level levelIn, List tooltip, TooltipFlag flagIn) { super.appendHoverText(stack, levelIn, tooltip, flagIn); - if (stack.getOrCreateTag().contains("owner")) - tooltip.add(EnumColor.buildTextComponent(Component.translatable("item.advancedperipherals.tooltip.memory_card.bound", stack.getOrCreateTag().getString("owner")))); - + CompoundTag data = stack.getOrCreateTag(); + // TODO: remove the owner name field + if (data.contains("ownerId") && data.contains("owner")) { + tooltip.add(EnumColor.buildTextComponent(Component.translatable("item.advancedperipherals.tooltip.memory_card.bound", data.getString("owner")))); + } } @Override public InteractionResultHolder use(Level worldIn, Player playerIn, InteractionHand handIn) { if (!worldIn.isClientSide) { ItemStack stack = playerIn.getItemInHand(handIn); - if (stack.getOrCreateTag().contains("owner")) { + CompoundTag data = stack.getOrCreateTag(); + // TODO: remove the owner name field + if (data.contains("ownerId") || data.contains("owner")) { playerIn.displayClientMessage(Component.translatable("text.advancedperipherals.removed_player"), true); - stack.getOrCreateTag().remove("owner"); + data.remove("ownerId"); + data.remove("owner"); } else { playerIn.displayClientMessage(Component.translatable("text.advancedperipherals.added_player"), true); - stack.getOrCreateTag().putString("owner", playerIn.getName().getString()); + data.putUUID("ownerId", playerIn.getUUID()); + data.putString("owner", playerIn.getName().getString()); } } return super.use(worldIn, playerIn, handIn); From 006c6c5947bfa21181dd6bb3b54658296204b31f Mon Sep 17 00:00:00 2001 From: zyxkad Date: Tue, 18 Jun 2024 14:58:31 -0600 Subject: [PATCH 194/228] improve TODO comment and player lookup logic --- .../blocks/blockentities/InventoryManagerEntity.java | 9 ++------- .../advancedperipherals/common/items/MemoryCardItem.java | 4 ++-- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java index e3a376a08..c973be0ae 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java @@ -91,12 +91,7 @@ public Player getOwnerPlayer() { if (this.owner == null) { return null; } - // Loop through all players and check if the player is online - for (Player player : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers()) { - if (player.getUUID().equals(this.owner)) { - return player; - } - } - return null; + Player player = ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayer(this.owner); + return player; } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/MemoryCardItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/MemoryCardItem.java index 5a4d51344..0bd126d4b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/MemoryCardItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/MemoryCardItem.java @@ -30,7 +30,7 @@ public boolean isEnabled() { public void appendHoverText(ItemStack stack, @Nullable Level levelIn, List tooltip, TooltipFlag flagIn) { super.appendHoverText(stack, levelIn, tooltip, flagIn); CompoundTag data = stack.getOrCreateTag(); - // TODO: remove the owner name field + // TODO <0.8>: remove the owner name field if (data.contains("ownerId") && data.contains("owner")) { tooltip.add(EnumColor.buildTextComponent(Component.translatable("item.advancedperipherals.tooltip.memory_card.bound", data.getString("owner")))); } @@ -41,7 +41,7 @@ public InteractionResultHolder use(Level worldIn, Player playerIn, In if (!worldIn.isClientSide) { ItemStack stack = playerIn.getItemInHand(handIn); CompoundTag data = stack.getOrCreateTag(); - // TODO: remove the owner name field + // TODO <0.8>: remove the owner name field if (data.contains("ownerId") || data.contains("owner")) { playerIn.displayClientMessage(Component.translatable("text.advancedperipherals.removed_player"), true); data.remove("ownerId"); From 44c982aa16c42df39506c834401a4acdfe0a3ad6 Mon Sep 17 00:00:00 2001 From: lonevox Date: Fri, 28 Jun 2024 20:03:07 +1200 Subject: [PATCH 195/228] Add wandering trader config --- .../common/configuration/WorldConfig.java | 2 ++ .../common/village/VillagerTrades.java | 15 +++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/WorldConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/WorldConfig.java index de050af71..08ca73158 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/WorldConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/WorldConfig.java @@ -10,6 +10,7 @@ public class WorldConfig implements IAPConfig { public final ForgeConfigSpec.BooleanValue enableVillagerStructures; public final ForgeConfigSpec.BooleanValue givePlayerBookOnJoin; public final ForgeConfigSpec.IntValue villagerStructureWeight; + public final ForgeConfigSpec.BooleanValue enableWanderingTraderTrades; private final ForgeConfigSpec configSpec; public WorldConfig() { @@ -20,6 +21,7 @@ public WorldConfig() { enableVillagerStructures = builder.comment("Enable the villager structures for the computer scientist.").define("enableVillagerStructures", true); givePlayerBookOnJoin = builder.comment("Gives the ap documentation to new players.").define("givePlayerBookOnJoin", true); villagerStructureWeight = builder.comment("The weight of the villager structures.").defineInRange("villagerStructureWeight", 10, 0, 16000); + enableWanderingTraderTrades = builder.comment("Enable new wandering trader trades.").define("enableWanderingVillagerTrades", true); builder.pop(); configSpec = builder.build(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrades.java b/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrades.java index 539e5089d..c53d97ab9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrades.java +++ b/src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrades.java @@ -2,6 +2,7 @@ import dan200.computercraft.shared.Registry; import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.setup.Blocks; import de.srendi.advancedperipherals.common.setup.CCRegistration; import de.srendi.advancedperipherals.common.setup.Items; @@ -19,12 +20,14 @@ public class VillagerTrades { @SubscribeEvent public static void registerWanderingTrade(WandererTradesEvent event) { - TradeBuilder.createTrade(event, Blocks.PERIPHERAL_CASING.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 1, 1) - .setMaxUses(8) - .build(); - TradeBuilder.createTrade(event, Registry.ModBlocks.TURTLE_ADVANCED.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 2, 1) - .setMaxUses(8) - .build(); + if (APConfig.WORLD_CONFIG.enableWanderingTraderTrades.get()) { + TradeBuilder.createTrade(event, Blocks.PERIPHERAL_CASING.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 1, 1) + .setMaxUses(8) + .build(); + TradeBuilder.createTrade(event, Registry.ModBlocks.TURTLE_ADVANCED.get(), VillagerTrade.Type.ITEM_FOR_EMERALD, 2, 1) + .setMaxUses(8) + .build(); + } } @SubscribeEvent From b11b42b8005f62f85d8df45148a50e0d2b59e2dd Mon Sep 17 00:00:00 2001 From: lonevox Date: Fri, 28 Jun 2024 20:21:23 +1200 Subject: [PATCH 196/228] Fix config definition --- .../advancedperipherals/common/configuration/WorldConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/configuration/WorldConfig.java b/src/main/java/de/srendi/advancedperipherals/common/configuration/WorldConfig.java index 08ca73158..8ba81c97c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/configuration/WorldConfig.java +++ b/src/main/java/de/srendi/advancedperipherals/common/configuration/WorldConfig.java @@ -21,7 +21,7 @@ public WorldConfig() { enableVillagerStructures = builder.comment("Enable the villager structures for the computer scientist.").define("enableVillagerStructures", true); givePlayerBookOnJoin = builder.comment("Gives the ap documentation to new players.").define("givePlayerBookOnJoin", true); villagerStructureWeight = builder.comment("The weight of the villager structures.").defineInRange("villagerStructureWeight", 10, 0, 16000); - enableWanderingTraderTrades = builder.comment("Enable new wandering trader trades.").define("enableWanderingVillagerTrades", true); + enableWanderingTraderTrades = builder.comment("Enable new wandering trader trades.").define("enableWanderingTraderTrades", true); builder.pop(); configSpec = builder.build(); From cf2c3068f66180411c34dac8e135439e77d0b21d Mon Sep 17 00:00:00 2001 From: Srendi Date: Wed, 3 Jul 2024 11:25:07 +0200 Subject: [PATCH 197/228] Update bug_report.yml Signed-off-by: Srendi --- .github/ISSUE_TEMPLATE/bug_report.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index bd8d15a5f..f13624226 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -41,12 +41,12 @@ body: multiple: false options: - Own compiled build. - - 1.20.1-0.7.39r (Latest 1.20.1) + - 1.20.1-0.7.40r (Latest 1.20.1) + - 1.20.1-0.7.39r - 1.20.1-0.7.38r - 1.20.1-0.7.37r - - 1.20.1-0.7.36r - - - 1.19.2-0.7.35r (Latest 1.19.2) + - 1.19.2-0.7.36r (Latest 1.19.2) + - 1.19.2-0.7.35r - 1.19.2-0.7.34r - 1.19.2-0.7.33r - 1.19.2-0.7.32r From 2c51bd05d74d6d322a846150b7499a637ad5982b Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sat, 6 Jul 2024 17:22:51 -0600 Subject: [PATCH 198/228] fix null pointer exception when invoking getName fix #640 --- .../computercraft/owner/BlockEntityPeripheralOwner.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java index 6eec291ce..be5ec00ea 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java @@ -33,13 +33,14 @@ public BlockEntityPeripheralOwner(T tileEntity) { @Nullable @Override public String getCustomName() { - String result = ""; - if (tileEntity instanceof Nameable nameableEntity) { - result = nameableEntity.getCustomName().getString(); + Component name = nameableEntity.getCustomName(); + if (name != null) { + return name.getString(); + } } - return result; + return ""; } @NotNull From 2b1240c8b515b8a4c54634cb7d65709256c4d8ee Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sat, 6 Jul 2024 17:46:15 -0600 Subject: [PATCH 199/228] add missing import --- .../addons/computercraft/owner/BlockEntityPeripheralOwner.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java index be5ec00ea..b1530de85 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java @@ -9,6 +9,7 @@ import net.minecraft.core.Direction; import net.minecraft.core.FrontAndTop; import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; import net.minecraft.world.Nameable; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; From 20980d6133ed5dc7a4e36604d8880e5c3d6053ca Mon Sep 17 00:00:00 2001 From: Srendi Date: Sun, 7 Jul 2024 23:46:50 +0200 Subject: [PATCH 200/228] Update PULL_REQUEST_TEMPLATE.md Signed-off-by: Srendi --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 2e659f12e..77d36901d 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -3,7 +3,7 @@ * **Please check if the PR fulfills these requirements** - [ ] The commit message are well described -- [ ] Docs have been added / updated (for features or maybe bugs which were noted). If not, please update the needed documentation [here](https://github.com/SirEndii/Advanced-Peripherals-Documentation/pulls). This is not mandatory +- [ ] Docs have been added / updated (for features or maybe bugs which were noted). If not, please update the needed documentation [here](https://github.com/SirEndii/Advanced-Peripherals-Documentation/pulls). Feel free to remove this check if you don't need it - [ ] All changes have fully been tested * **What kind of change does this PR introduce?** (Bug fix, feature, ...) From a84329743f9934aebb9265195bc2cb1478d7ecea Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sun, 7 Jul 2024 15:48:11 -0600 Subject: [PATCH 201/228] remove extra empty line --- .../addons/computercraft/owner/BlockEntityPeripheralOwner.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java index b1530de85..13009ae9b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java @@ -40,7 +40,6 @@ public String getCustomName() { return name.getString(); } } - return ""; } From 0f5de9c09fe2d067dc52c39af2548770cb6ac80f Mon Sep 17 00:00:00 2001 From: Srendi Date: Sun, 7 Jul 2024 23:56:32 +0200 Subject: [PATCH 202/228] Fixed checkstyle violations --- .../common/addons/botania/ManaFlowerIntegration.java | 1 - .../computercraft/owner/BlockEntityPeripheralOwner.java | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaFlowerIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaFlowerIntegration.java index ad3a19289..7db9f0559 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaFlowerIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/botania/ManaFlowerIntegration.java @@ -3,7 +3,6 @@ import dan200.computercraft.api.lua.LuaFunction; import de.srendi.advancedperipherals.lib.peripherals.APGenericPeripheral; import vazkii.botania.api.block_entity.GeneratingFlowerBlockEntity; -import vazkii.botania.common.block.BotaniaBlocks; public class ManaFlowerIntegration implements APGenericPeripheral { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java index 6eec291ce..d51b001b5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java @@ -34,11 +34,11 @@ public BlockEntityPeripheralOwner(T tileEntity) { @Override public String getCustomName() { String result = ""; - + if (tileEntity instanceof Nameable nameableEntity) { result = nameableEntity.getCustomName().getString(); } - + return result; } From 70b360a0b6acc98730f8ad946e74925b16174ee1 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Tue, 9 Jul 2024 10:05:13 -0600 Subject: [PATCH 203/228] rename getEnergy -> getStoredEnergy in order to prevent the method conflict with CC:Tweaked's energy_storage generic peripheral resolve #642 --- .../common/addons/powah/EnderCellIntegration.java | 7 +++++++ .../common/addons/powah/EnergyCellIntegration.java | 6 ++++++ .../common/addons/powah/FurnatorIntegration.java | 7 +++++++ .../common/addons/powah/MagmatorIntegration.java | 7 +++++++ .../common/addons/powah/ReactorIntegration.java | 9 +++++++++ .../common/addons/powah/SolarPanelIntegration.java | 7 +++++++ .../common/addons/powah/ThermoIntegration.java | 7 +++++++ 7 files changed, 50 insertions(+) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/EnderCellIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/EnderCellIntegration.java index ee8f405c2..b63902435 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/EnderCellIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/EnderCellIntegration.java @@ -11,11 +11,18 @@ public String getPeripheralType() { return "enderCell"; } + // TODO: remove in the next major version + @Deprecated(forRemoval = true, since = "1.20.1-0.7.41r") @LuaFunction(mainThread = true) public final double getEnergy(EnderCellTile blockEntity) { return blockEntity.getEnergy().getEnergyStored(); } + @LuaFunction(mainThread = true) + public final double getStoredEnergy(EnderCellTile blockEntity) { + return blockEntity.getEnergy().getEnergyStored(); + } + @LuaFunction(mainThread = true) public final double getMaxEnergy(EnderCellTile blockEntity) { return blockEntity.getEnergy().getMaxEnergyStored(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/EnergyCellIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/EnergyCellIntegration.java index e995b4501..d7cbcf90c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/EnergyCellIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/EnergyCellIntegration.java @@ -16,10 +16,16 @@ public final String getName() { return "Energy Cell"; } + // TODO: remove in the next major version + @Deprecated(forRemoval = true, since = "1.20.1-0.7.41r") @LuaFunction(mainThread = true) public final double getEnergy(EnergyCellTile blockEntity) { return blockEntity.getEnergy().getEnergyStored(); } + @LuaFunction(mainThread = true) + public final double getStoredEnergy(EnergyCellTile blockEntity) { + return blockEntity.getEnergy().getEnergyStored(); + } @LuaFunction(mainThread = true) public final double getMaxEnergy(EnergyCellTile blockEntity) { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/FurnatorIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/FurnatorIntegration.java index 95c18ee97..100989efa 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/FurnatorIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/FurnatorIntegration.java @@ -17,11 +17,18 @@ public final boolean isBurning(FurnatorTile blockEntity) { return blockEntity.isBurning(); } + // TODO: remove in the next major version + @Deprecated(forRemoval = true, since = "1.20.1-0.7.41r") @LuaFunction(mainThread = true) public final double getEnergy(FurnatorTile blockEntity) { return blockEntity.getEnergy().getEnergyStored(); } + @LuaFunction(mainThread = true) + public final double getStoredEnergy(FurnatorTile blockEntity) { + return blockEntity.getEnergy().getEnergyStored(); + } + @LuaFunction(mainThread = true) public final double getMaxEnergy(FurnatorTile blockEntity) { return blockEntity.getEnergy().getMaxEnergyStored(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/MagmatorIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/MagmatorIntegration.java index 239b31c0c..dbff18a1a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/MagmatorIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/MagmatorIntegration.java @@ -13,11 +13,18 @@ public String getPeripheralType() { return "magmator"; } + // TODO: remove in the next major version + @Deprecated(forRemoval = true, since = "1.20.1-0.7.41r") @LuaFunction(mainThread = true) public final double getEnergy(MagmatorTile blockEntity) { return blockEntity.getEnergy().getEnergyStored(); } + @LuaFunction(mainThread = true) + public final double getStoredEnergy(MagmatorTile blockEntity) { + return blockEntity.getEnergy().getEnergyStored(); + } + @LuaFunction(mainThread = true) public final double getMaxEnergy(MagmatorTile blockEntity) { return blockEntity.getEnergy().getMaxEnergyStored(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/ReactorIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/ReactorIntegration.java index ec63fe8db..1ab636829 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/ReactorIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/ReactorIntegration.java @@ -40,6 +40,8 @@ public final double getRedstone(ReactorPartTile blockEntity) { return blockEntity.core().get().redstone.perCent(); } + // TODO: remove in the next major version + @Deprecated(forRemoval = true, since = "1.20.1-0.7.41r") @LuaFunction(mainThread = true) public final double getEnergy(ReactorPartTile blockEntity) { if (blockEntity.core().isEmpty()) @@ -47,6 +49,13 @@ public final double getEnergy(ReactorPartTile blockEntity) { return blockEntity.core().get().getEnergy().getEnergyStored(); } + @LuaFunction(mainThread = true) + public final double getStoredEnergy(ReactorPartTile blockEntity) { + if (blockEntity.core().isEmpty()) + return 0.0d; + return blockEntity.core().get().getEnergy().getEnergyStored(); + } + @LuaFunction(mainThread = true) public final double getMaxEnergy(ReactorPartTile blockEntity) { if (blockEntity.core().isEmpty()) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/SolarPanelIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/SolarPanelIntegration.java index 3dd965f42..18303170f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/SolarPanelIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/SolarPanelIntegration.java @@ -16,11 +16,18 @@ public final String getName(SolarTile blockEntity) { return "Solar Panel"; } + // TODO: remove in the next major version + @Deprecated(forRemoval = true, since = "1.20.1-0.7.41r") @LuaFunction(mainThread = true) public final double getEnergy(SolarTile blockEntity) { return blockEntity.getEnergy().getEnergyStored(); } + @LuaFunction(mainThread = true) + public final double getStoredEnergy(SolarTile blockEntity) { + return blockEntity.getEnergy().getEnergyStored(); + } + @LuaFunction(mainThread = true) public final double getMaxEnergy(SolarTile blockEntity) { return blockEntity.getEnergy().getMaxEnergyStored(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/ThermoIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/ThermoIntegration.java index f99fc8f5d..e2c020537 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/ThermoIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/ThermoIntegration.java @@ -16,11 +16,18 @@ public final String getName(ThermoTile blockEntity) { return "Thermo generator"; } + // TODO: remove in the next major version + @Deprecated(forRemoval = true, since = "1.20.1-0.7.41r") @LuaFunction(mainThread = true) public final double getEnergy(ThermoTile blockEntity) { return blockEntity.getEnergy().getEnergyStored(); } + @LuaFunction(mainThread = true) + public final double getStoredEnergy(ThermoTile blockEntity) { + return blockEntity.getEnergy().getEnergyStored(); + } + @LuaFunction(mainThread = true) public final double getMaxEnergy(ThermoTile blockEntity) { return blockEntity.getEnergy().getMaxEnergyStored(); From a263d0018fafc63690cab50a4511472887a5a918 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Tue, 9 Jul 2024 10:14:26 -0600 Subject: [PATCH 204/228] fix not exists variable --- .../addons/computercraft/owner/BlockEntityPeripheralOwner.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java index 4f04cf0e5..13009ae9b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java @@ -40,8 +40,7 @@ public String getCustomName() { return name.getString(); } } - - return result; + return ""; } @NotNull From d4bd019abba74c16dcbd96ed56557cd7f3cc311c Mon Sep 17 00:00:00 2001 From: zyxkad Date: Tue, 9 Jul 2024 10:26:03 -0600 Subject: [PATCH 205/228] fix missing empty line for better style --- .../common/addons/powah/EnergyCellIntegration.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/EnergyCellIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/EnergyCellIntegration.java index d7cbcf90c..4a6dd513d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/EnergyCellIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/EnergyCellIntegration.java @@ -22,6 +22,7 @@ public final String getName() { public final double getEnergy(EnergyCellTile blockEntity) { return blockEntity.getEnergy().getEnergyStored(); } + @LuaFunction(mainThread = true) public final double getStoredEnergy(EnergyCellTile blockEntity) { return blockEntity.getEnergy().getEnergyStored(); From 2ae7cff625e96a3bd2b99dfec82a01e67f40a78d Mon Sep 17 00:00:00 2001 From: zyxkad Date: Tue, 9 Jul 2024 10:45:14 -0600 Subject: [PATCH 206/228] fix useOnBlock will returns PASS on some specific case fix #636 --- .../common/util/fakeplayer/APFakePlayer.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java index 405713ddb..d6954e640 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java @@ -242,27 +242,27 @@ public InteractionResult use(boolean skipEntity, boolean skipBlock, @Nullable Pr if (event.isCanceled()) { return event.getCancellationResult(); } - boolean denied = event.getUseItem() == Event.Result.DENY; - if (!denied) { + boolean usedItem = event.getUseItem() != Event.Result.DENY; + boolean usedOnBlock = event.getUseBlock() != Event.Result.DENY; + if (usedItem) { InteractionResult result = stack.onItemUseFirst(new UseOnContext(level, this, InteractionHand.MAIN_HAND, stack, blockHit)); if (result != InteractionResult.PASS) { return result; } boolean bypass = getMainHandItem().doesSneakBypassUse(level, pos, this); - if (isShiftKeyDown() || bypass || event.getUseBlock() == Event.Result.ALLOW) { + if (isShiftKeyDown() || bypass || usedOnBlock) { InteractionResult useType = gameMode.useItemOn(this, level, stack, InteractionHand.MAIN_HAND, blockHit); - if (useType == InteractionResult.SUCCESS) { - return InteractionResult.SUCCESS; + if (useType.consumesAction()) { + return useType; } } } - if (stack.isEmpty() || getCooldowns().isOnCooldown(stack.getItem())) { + if (!stack.isEmpty() && getCooldowns().isOnCooldown(stack.getItem())) { return InteractionResult.PASS; } - if (stack.getItem() instanceof BlockItem blockItem) { Block block = blockItem.getBlock(); if (block instanceof CommandBlock || block instanceof StructureBlock) { @@ -270,12 +270,12 @@ public InteractionResult use(boolean skipEntity, boolean skipBlock, @Nullable Pr } } - if (denied) { + if (!usedItem && !usedOnBlock) { return InteractionResult.PASS; } ItemStack copyBeforeUse = stack.copy(); - InteractionResult result = stack.useOn(new UseOnContext(level, this, InteractionHand.MAIN_HAND, copyBeforeUse, blockHit)); + InteractionResult result = stack.useOn(new UseOnContext(level, this, InteractionHand.MAIN_HAND, stack, blockHit)); if (stack.isEmpty()) { ForgeEventFactory.onPlayerDestroyItem(this, copyBeforeUse, InteractionHand.MAIN_HAND); } From f2b5793ad304b40164d0082836bafb5c92c4e331 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sat, 13 Jul 2024 00:14:02 -0600 Subject: [PATCH 207/228] fix get inevntory on powah will always returns nil fix #645 --- .../addons/powah/FurnatorIntegration.java | 9 ++++- .../addons/powah/ReactorIntegration.java | 40 +++++++++++++------ 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/FurnatorIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/FurnatorIntegration.java index c9522f4a9..f1f7a5771 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/FurnatorIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/FurnatorIntegration.java @@ -2,6 +2,7 @@ import dan200.computercraft.api.lua.LuaFunction; import de.srendi.advancedperipherals.lib.peripherals.BlockEntityIntegrationPeripheral; +import de.srendi.advancedperipherals.common.util.LuaConverter; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.entity.BlockEntity; import org.jetbrains.annotations.NotNull; @@ -44,7 +45,11 @@ public final double getCarbon() { } @LuaFunction(mainThread = true) - public final ItemStack getInventory() { - return blockEntity.getInventory().getStackInSlot(1); + public final Object getInventory() { + ItemStack stack = blockEntity.getInventory().getStackInSlot(1); + if (stack.isEmpty()) { + return null; + } + return LuaConverter.stackToObject(stack); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/ReactorIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/ReactorIntegration.java index d8f1a9db8..150911521 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/ReactorIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/ReactorIntegration.java @@ -2,6 +2,7 @@ import dan200.computercraft.api.lua.LuaFunction; import de.srendi.advancedperipherals.lib.peripherals.BlockEntityIntegrationPeripheral; +import de.srendi.advancedperipherals.common.util.LuaConverter; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.entity.BlockEntity; import org.jetbrains.annotations.NotNull; @@ -73,23 +74,38 @@ public final double getTemperature() { } @LuaFunction(mainThread = true) - public final ItemStack getInventoryUraninite() { - if (blockEntity.core().isEmpty()) - return ItemStack.EMPTY; - return blockEntity.core().get().getInventory().getStackInSlot(1); + public final Object getInventoryUraninite() { + if (blockEntity.core().isEmpty()) { + return null; + } + ItemStack stack = blockEntity.core().get().getStack(1); + if (stack.isEmpty()) { + return null; + } + return LuaConverter.stackToObject(stack); } @LuaFunction(mainThread = true) - public final ItemStack getInventoryRedstone() { - if (blockEntity.core().isEmpty()) - return ItemStack.EMPTY; - return blockEntity.core().get().getInventory().getStackInSlot(3); + public final Object getInventoryRedstone() { + if (blockEntity.core().isEmpty()) { + return null; + } + ItemStack stack = blockEntity.core().get().getStack(3); + if (stack.isEmpty()) { + return null; + } + return LuaConverter.stackToObject(stack); } @LuaFunction(mainThread = true) - public final ItemStack getInventoryCarbon() { - if (blockEntity.core().isEmpty()) - return ItemStack.EMPTY; - return blockEntity.core().get().getInventory().getStackInSlot(2); + public final Object getInventoryCarbon() { + if (blockEntity.core().isEmpty()) { + return null; + } + ItemStack stack = blockEntity.core().get().getStack(2); + if (stack.isEmpty()) { + return null; + } + return LuaConverter.stackToObject(stack); } } From e07ec4b596c1b83ddf092425f87c2951ab070d74 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sun, 21 Jul 2024 10:31:01 -0600 Subject: [PATCH 208/228] fix filters --- .../common/util/inventory/FluidFilter.java | 13 ++++++------- .../common/util/inventory/ItemFilter.java | 13 ++++++------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java index faad46a1f..393fac7da 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java @@ -103,16 +103,15 @@ public boolean test(FluidStack stack) { return fingerprint.equals(testFingerprint); } - // If the filter does not have nbt values, a tag or a fingerprint, just test if the items are the same - if (fluid != Fluids.EMPTY) { - if (tag == null && nbt == null && fingerprint.isEmpty()) - return stack.getFluid().isSame(fluid); + if (fluid != Fluids.EMPTY && !stack.getFluid().isSame(fluid)) { + return false; } - if (tag != null && !stack.getFluid().is(tag)) + if (tag != null && !stack.getFluid().is(tag)) { return false; - if (nbt != null && !stack.getOrCreateTag().equals(nbt) && (fluid == Fluids.EMPTY || stack.getFluid().isSame(fluid))) + } + if (nbt != null && !stack.getOrCreateTag().equals(nbt)) { return false; - + } return true; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java index bd943c892..f8a8074cf 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java @@ -118,16 +118,15 @@ public boolean test(ItemStack stack) { return fingerprint.equals(testFingerprint); } - // If the filter does not have nbt values, a tag or a fingerprint, just test if the items are the same - if (item != Items.AIR) { - if (tag == null && nbt == null && fingerprint.isEmpty()) - return stack.is(item); + if (item != Items.AIR && !stack.is(item)) { + return false; } - if (tag != null && !stack.is(tag)) + if (tag != null && !stack.is(tag)) { return false; - if (nbt != null && !stack.getOrCreateTag().equals(nbt) && (item == Items.AIR || stack.is(item))) + } + if (nbt != null && !stack.getOrCreateTag().equals(nbt)) { return false; - + } return true; } From 7ac8f696911aea506812f2cd2a206d3970de3b6d Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sun, 21 Jul 2024 11:04:55 -0600 Subject: [PATCH 209/228] remove some unnecessary ItemStack.copy()s --- .../peripheral/RsBridgePeripheral.java | 2 +- .../addons/refinedstorage/RefinedStorage.java | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java index a45b81086..b65ce5135 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java @@ -74,7 +74,7 @@ public final MethodResult listCraftableItems() { return notConnected(); List items = new ArrayList<>(); - RefinedStorage.getCraftableItems(getNetwork()).forEach(item -> items.add(RefinedStorage.getObjectFromStack(item.copy(), getNetwork()))); + RefinedStorage.getCraftableItems(getNetwork()).forEach(item -> items.add(RefinedStorage.getObjectFromStack(item, getNetwork()))); return MethodResult.of(items); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java index 9e13e7d8d..7f58105d6 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java @@ -55,7 +55,7 @@ public static ItemStack findStackFromStack(INetwork network, @Nullable ICrafting public static ItemStack findStackFromFilter(INetwork network, @Nullable ICraftingManager crafting, ItemFilter filter) { for (StackListEntry temp : network.getItemStorageCache().getList().getStacks()) { - if (filter.test(temp.getStack().copy())) + if (filter.test(temp.getStack())) return temp.getStack().copy(); } @@ -64,7 +64,7 @@ public static ItemStack findStackFromFilter(INetwork network, @Nullable ICraftin for (ICraftingPattern pattern : crafting.getPatterns()) { for(ItemStack stack : pattern.getOutputs()) { - if (filter.test(stack.copy())) + if (filter.test(stack)) return stack.copy(); } } @@ -78,7 +78,7 @@ public static FluidStack findFluidFromStack(INetwork network, @Nullable ICraftin public static FluidStack findFluidFromFilter(INetwork network, @Nullable ICraftingManager crafting, FluidFilter filter) { for (StackListEntry temp : network.getFluidStorageCache().getList().getStacks()) { - if (filter.test(temp.getStack().copy())) + if (filter.test(temp.getStack())) return temp.getStack().copy(); } @@ -165,7 +165,7 @@ public static Object getObjectFromPattern(ICraftingPattern pattern, INetwork net List outputsList = pattern.getOutputs(); List outputs = new ArrayList<>(); for (ItemStack itemStack : outputsList) - outputs.add(getObjectFromStack(itemStack.copy(), network)); + outputs.add(getObjectFromStack(itemStack, network)); map.put("outputs", outputs); @@ -174,7 +174,7 @@ public static Object getObjectFromPattern(ICraftingPattern pattern, INetwork net for (List singleInputList : inputList) { List inputs1 = new ArrayList<>(); for (ItemStack stack : singleInputList) - inputs1.add(getObjectFromStack(stack.copy(), network)); + inputs1.add(getObjectFromStack(stack, network)); inputs.add(inputs1); } @@ -182,7 +182,7 @@ public static Object getObjectFromPattern(ICraftingPattern pattern, INetwork net if (!pattern.isProcessing()) { List byproductsList = pattern.getByproducts(); for (ItemStack stack : byproductsList) - byproducts.add(getObjectFromStack(stack.copy(), network)); + byproducts.add(getObjectFromStack(stack, network)); } map.put("inputs", inputs); @@ -228,7 +228,7 @@ public static Map getObjectFromFluid(@Nullable FluidStack fluidS public static Object getItem(INetwork network, ItemStack item) { for (ItemStack itemStack : getItems(network)) { if (itemStack.sameItem(item) && Objects.equals(itemStack.getTag(), item.getTag())) - return getObjectFromStack(itemStack.copy(), network); + return getObjectFromStack(itemStack, network); } return null; } From a80ac92f2ed8d27048f30317d09647fa500bd449 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sun, 21 Jul 2024 11:27:56 -0600 Subject: [PATCH 210/228] return nil instead of empty item for getItem --- .../peripheral/MeBridgePeripheral.java | 5 ++++- .../peripheral/RsBridgePeripheral.java | 13 ++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java index 731e451f4..2696ed9ed 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java @@ -420,7 +420,10 @@ public final MethodResult getItem(IArguments arguments) throws LuaException { if (parsedFilter.isEmpty()) return MethodResult.of(null, "EMPTY_FILTER"); - return MethodResult.of(AppEngApi.getObjectFromStack(AppEngApi.findAEStackFromFilter(monitor, getCraftingService(), parsedFilter), getCraftingService())); + Pair item = AppEngApi.findAEStackFromFilter(monitor, getCraftingService(), parsedFilter) + if (item.getRight().isEmpty()) + return MethodResult.of(null, "NOT_FOUND"); + return MethodResult.of(AppEngApi.getObjectFromStack(item, getCraftingService())); } @LuaFunction(mainThread = true) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java index b65ce5135..f9466bf80 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java @@ -296,10 +296,13 @@ public final MethodResult getItem(IArguments arguments) throws LuaException { return notConnected(); Pair filter = ItemFilter.parse(arguments.getTable(0)); - if (filter.rightPresent()) + if (filter.rightPresent()) return MethodResult.of(null, filter.getRight()); - return MethodResult.of(RefinedStorage.getObjectFromStack(RefinedStorage.findStackFromFilter(getNetwork(), getNetwork().getCraftingManager(), filter.getLeft()), getNetwork())); + ItemStack item = RefinedStorage.findStackFromFilter(getNetwork(), getNetwork().getCraftingManager(), filter.getLeft()) + if (item.isEmpty()) + return MethodResult.of(null, "NOT_FOUND"); + return MethodResult.of(RefinedStorage.getObjectFromStack(item, getNetwork())); } @LuaFunction(mainThread = true) @@ -313,7 +316,7 @@ public final MethodResult craftItem(IArguments arguments) throws LuaException { return MethodResult.of(null, filter.getRight()); ItemStack stack = RefinedStorage.findStackFromFilter(getNetwork(), getNetwork().getCraftingManager(), filter.getLeft()); - if (stack == null) + if (stack.isEmpty()) return MethodResult.of(null, "NOT_CRAFTABLE"); ICalculationResult result = getNetwork().getCraftingManager().create(stack, filter.getLeft().getCount()); @@ -334,7 +337,7 @@ public final MethodResult craftFluid(IArguments arguments) throws LuaException { return MethodResult.of(null, filter.getRight()); FluidStack stack = RefinedStorage.findFluidFromFilter(getNetwork(), getNetwork().getCraftingManager(), filter.getLeft()); - if (stack == null) + if (stack.isEmpty()) return MethodResult.of(null, "NOT_CRAFTABLE"); ICalculationResult result = getNetwork().getCraftingManager().create(stack, filter.getLeft().getCount()); @@ -355,7 +358,7 @@ public final MethodResult isItemCrafting(IArguments arguments) throws LuaExcepti return MethodResult.of(null, filter.getRight()); ItemStack stack = RefinedStorage.findStackFromFilter(getNetwork(), getNetwork().getCraftingManager(), filter.getLeft()); - if (stack == null) + if (stack.isEmpty()) return MethodResult.of(null, "NOT_CRAFTABLE"); for (ICraftingTask task : getNetwork().getCraftingManager().getTasks()) { From e61c391ec01254d3845f636bb6e894ed92e6056a Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sun, 21 Jul 2024 13:42:01 -0600 Subject: [PATCH 211/228] remove trailing space --- .../addons/computercraft/peripheral/RsBridgePeripheral.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java index f9466bf80..ee71949cb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java @@ -296,7 +296,7 @@ public final MethodResult getItem(IArguments arguments) throws LuaException { return notConnected(); Pair filter = ItemFilter.parse(arguments.getTable(0)); - if (filter.rightPresent()) + if (filter.rightPresent()) return MethodResult.of(null, filter.getRight()); ItemStack item = RefinedStorage.findStackFromFilter(getNetwork(), getNetwork().getCraftingManager(), filter.getLeft()) From a7c52ed1b2c9d3211ee4eb7633d15c4ddc783809 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Mon, 19 Aug 2024 13:42:46 -0600 Subject: [PATCH 212/228] make some change to fake player --- .../common/util/fakeplayer/APFakePlayer.java | 33 +++++++------------ 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java index d6954e640..795a7fb3e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java @@ -318,7 +318,7 @@ public HitResult findHit(boolean skipEntity, boolean skipBlock, @Nullable Predic if (skipEntity) return blockHit; - List entities = level.getEntities(this, getBoundingBox().expandTowards(look.x * range, look.y * range, look.z * range).inflate(1, 1, 1), collidablePredicate); + List entities = level.getEntities(this, getBoundingBox().expandTowards(look.x * range, look.y * range, look.z * range).inflate(1), collidablePredicate); LivingEntity closestEntity = null; Vec3 closestVec = null; @@ -328,29 +328,20 @@ public HitResult findHit(boolean skipEntity, boolean skipBlock, @Nullable Predic continue; // Add litter bigger that just pick radius AABB box = entityHit.getBoundingBox().inflate(entityHit.getPickRadius() + 0.5); - Optional clipResult = box.clip(origin, target); - if (box.contains(origin)) { - if (closestDistance >= 0.0D) { - closestEntity = (LivingEntity) entityHit; - closestVec = clipResult.orElse(origin); - closestDistance = 0.0D; - } - } else if (clipResult.isPresent()) { + closestEntity = (LivingEntity) entityHit; + closestVec = clipResult.orElse(origin); + closestDistance = 0; + break; + } + Optional clipResult = box.clip(origin, target); + if (clipResult.isPresent()) { Vec3 clipVec = clipResult.get(); double distance = origin.distanceTo(clipVec); - - if (distance < closestDistance || closestDistance == 0.0D) { - if (entityHit == entityHit.getRootVehicle() && !entityHit.canRiderInteract()) { - if (closestDistance == 0.0D) { - closestEntity = (LivingEntity) entityHit; - closestVec = clipVec; - } - } else { - closestEntity = (LivingEntity) entityHit; - closestVec = clipVec; - closestDistance = distance; - } + if (distance < closestDistance) { + closestEntity = (LivingEntity) entityHit; + closestVec = clipVec; + closestDistance = distance; } } } From fc79c30f5b6a17cb90b2e2464b965c9a2383b529 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sat, 24 Aug 2024 13:14:57 -0600 Subject: [PATCH 213/228] fix entity operation does not have enough reach range than expected --- .../plugins/AutomataEntityHandPlugin.java | 2 +- .../plugins/AutomataSoulFeedingPlugin.java | 2 +- .../common/util/fakeplayer/APFakePlayer.java | 61 +++++++++++++------ 3 files changed, 43 insertions(+), 22 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java index 14dd9e6f1..09731f3e2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java @@ -56,7 +56,7 @@ public final MethodResult useOnAnimal(@NotNull IArguments arguments) throws LuaE if (automataCore.hasAttribute(AutomataCorePeripheral.ATTR_STORING_TOOL_DURABILITY)) selectedTool.setDamageValue(previousDamageValue); - return MethodResult.of(true, result.toString()); + return MethodResult.of(result.consumesAction(), result.toString()); }); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataSoulFeedingPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataSoulFeedingPlugin.java index 79368507e..6f4035522 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataSoulFeedingPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataSoulFeedingPlugin.java @@ -24,7 +24,7 @@ public final MethodResult feedSoul() { InteractionResult result = owner.withPlayer(APFakePlayer::useOnEntity); automataCore.addRotationCycle(3); - return MethodResult.of(true, result.toString()); + return MethodResult.of(result.consumesAction(), result.toString()); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java index 795a7fb3e..a98e8fb71 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java @@ -92,7 +92,6 @@ public boolean canAttack(@NotNull LivingEntity livingEntity) { public void openTextEdit(@NotNull SignBlockEntity sign) { } - @Override public boolean isSilent() { return true; @@ -322,33 +321,55 @@ public HitResult findHit(boolean skipEntity, boolean skipBlock, @Nullable Predic LivingEntity closestEntity = null; Vec3 closestVec = null; - double closestDistance = range; + double closestDistance = blockHit.getType() == HitResult.Type.MISS ? range * range : distanceToSqr(blockHit.getLocation()); for (Entity entityHit : entities) { - if (!(entityHit instanceof LivingEntity) || entityFilter != null && !entityFilter.test(entityHit)) + if (!(entityHit instanceof LivingEntity entity)) { + continue; + } + // TODO: maybe let entityFilter returns the priority of the entity, instead of only returns the closest one. + if (entityFilter != null && !entityFilter.test(entity)) { + continue; + } + + // Removed a lot logic here to make Automata cores interact like a player. + // However, the results for some edge cases may change. Need more review and tests. + + // Hit vehicle before passenger + if (entity.isPassenger()) { continue; - // Add litter bigger that just pick radius - AABB box = entityHit.getBoundingBox().inflate(entityHit.getPickRadius() + 0.5); + } + + AABB box = entity.getBoundingBox(); + Vec3 clipVec; if (box.contains(origin)) { - closestEntity = (LivingEntity) entityHit; - closestVec = clipResult.orElse(origin); - closestDistance = 0; - break; + clipVec = origin; + } else { + clipVec = box.clip(origin, target).orElse(null); + if (clipVec == null) { + continue; + } + } + double distance = origin.distanceToSqr(clipVec); + // Ignore small enough distance + if (distance <= 1e-6) { + distance = 0; } - Optional clipResult = box.clip(origin, target); - if (clipResult.isPresent()) { - Vec3 clipVec = clipResult.get(); - double distance = origin.distanceTo(clipVec); - if (distance < closestDistance) { - closestEntity = (LivingEntity) entityHit; - closestVec = clipVec; - closestDistance = distance; + if (distance > closestDistance) { + continue; + } + if (distance == closestDistance && closestEntity != null) { + // Hit larger entity before smaller + if (closestEntity.getBoundingBox().getSize() >= box.getSize()) { + continue; } } + closestEntity = entity; + closestVec = clipVec; + closestDistance = distance; } - if (closestEntity != null && closestDistance <= range && (blockHit.getType() == HitResult.Type.MISS || distanceToSqr(blockHit.getLocation()) > closestDistance * closestDistance)) { + if (closestEntity != null) { return new EntityHitResult(closestEntity, closestVec); - } else { - return blockHit; } + return blockHit; } } From 47af5f964e8b04946f29564db5f0af19b4f6537f Mon Sep 17 00:00:00 2001 From: endi Date: Wed, 28 Aug 2024 14:02:07 +0200 Subject: [PATCH 214/228] Fixed Checkstyle violation --- .../advancedperipherals/common/util/fakeplayer/APFakePlayer.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java index a98e8fb71..a947a4c53 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java @@ -44,7 +44,6 @@ import java.lang.ref.WeakReference; import java.util.List; -import java.util.Optional; import java.util.UUID; import java.util.function.Function; import java.util.function.Predicate; From 2f3ee32517424b21bde92805a6411b96b232d176 Mon Sep 17 00:00:00 2001 From: endi Date: Sat, 7 Sep 2024 22:37:24 +0200 Subject: [PATCH 215/228] Fixed ClassCastException for the `listCells` function --- .../common/addons/appliedenergistics/AppEngApi.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java index df44e2c86..60d5d9d02 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java @@ -562,11 +562,11 @@ public static List listCells(IGridNode node) { if (!iterator.hasNext()) return items; while (iterator.hasNext()) { - DriveBlockEntity entity = (DriveBlockEntity) iterator.next().getService(IStorageProvider.class); - if (entity == null) + IStorageProvider entity = iterator.next().getService(IStorageProvider.class); + if (entity == null || !(entity instanceof DriveBlockEntity drive)) continue; - InternalInventory inventory = entity.getInternalInventory(); + InternalInventory inventory = drive.getInternalInventory(); for (int i = 0; i < inventory.size(); i++) { ItemStack stack = inventory.getStackInSlot(i); From 833e5df3a9fc7d20ab2f58c7eb2526f183e6a67f Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 30 Sep 2024 21:48:33 +0200 Subject: [PATCH 216/228] [#660] Fixed blank nbt when using some inventory manager functions Signed-off-by: Srendi --- .../computercraft/peripheral/InventoryManagerPeripheral.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java index 73e9213a6..a8d01bae8 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java @@ -189,12 +189,12 @@ public final int getFreeSlot() throws LuaException { @LuaFunction(mainThread = true) public final Map getItemInHand() throws LuaException { - return LuaConverter.stackToObject(getOwnerPlayer().getMainHandItem()); + return LuaConverter.stackToObject(getOwnerPlayer().getMainHandItem().copy()); } @LuaFunction(mainThread = true) public final Map getItemInOffHand() throws LuaException { - return LuaConverter.stackToObject(getOwnerPlayer().getOffhandItem()); + return LuaConverter.stackToObject(getOwnerPlayer().getOffhandItem().copy()); } private Player getOwnerPlayer() throws LuaException { From 23d3b917ba66ad2bef04f691e4d4087c51591a01 Mon Sep 17 00:00:00 2001 From: endi Date: Fri, 4 Oct 2024 21:43:55 +0200 Subject: [PATCH 217/228] Fixed class cast exception with me bridge's `listCells` --- .../common/addons/appliedenergistics/AppEngApi.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java index e87f0c2cb..038580e49 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java @@ -570,11 +570,11 @@ public static List listCells(IGridNode node) { if (!iterator.hasNext()) return items; while (iterator.hasNext()) { - DriveBlockEntity entity = (DriveBlockEntity) iterator.next().getService(IStorageProvider.class); - if (entity == null) + IStorageProvider entity = iterator.next().getService(IStorageProvider.class); + if (!(entity instanceof DriveBlockEntity driveEntity)) continue; - InternalInventory inventory = entity.getInternalInventory(); + InternalInventory inventory = driveEntity.getInternalInventory(); for (int i = 0; i < inventory.size(); i++) { ItemStack stack = inventory.getStackInSlot(i); From 647fd5b4192fa7dc71b0babe77e7bbed85c2eb35 Mon Sep 17 00:00:00 2001 From: Srendi Date: Sun, 6 Oct 2024 15:26:57 +0200 Subject: [PATCH 218/228] [#660] Fixed blank nbt when using some inventory manager functions --- .../computercraft/peripheral/InventoryManagerPeripheral.java | 4 ++-- .../addons/computercraft/peripheral/MeBridgePeripheral.java | 4 ++-- .../addons/computercraft/peripheral/RsBridgePeripheral.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java index 66abb49fb..1a8002bd0 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/InventoryManagerPeripheral.java @@ -189,12 +189,12 @@ public final int getFreeSlot() throws LuaException { @LuaFunction(mainThread = true) public final Map getItemInHand() throws LuaException { - return LuaConverter.stackToObject(getOwnerPlayer().getMainHandItem()); + return LuaConverter.stackToObject(getOwnerPlayer().getMainHandItem().copy()); } @LuaFunction(mainThread = true) public final Map getItemInOffHand() throws LuaException { - return LuaConverter.stackToObject(getOwnerPlayer().getOffhandItem()); + return LuaConverter.stackToObject(getOwnerPlayer().getOffhandItem().copy()); } private Player getOwnerPlayer() throws LuaException { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java index 2696ed9ed..216e27702 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java @@ -420,8 +420,8 @@ public final MethodResult getItem(IArguments arguments) throws LuaException { if (parsedFilter.isEmpty()) return MethodResult.of(null, "EMPTY_FILTER"); - Pair item = AppEngApi.findAEStackFromFilter(monitor, getCraftingService(), parsedFilter) - if (item.getRight().isEmpty()) + Pair item = AppEngApi.findAEStackFromFilter(monitor, getCraftingService(), parsedFilter); + if (item.getRight() == null && item.getLeft() == 0) return MethodResult.of(null, "NOT_FOUND"); return MethodResult.of(AppEngApi.getObjectFromStack(item, getCraftingService())); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java index ee71949cb..87fd927b7 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java @@ -299,7 +299,7 @@ public final MethodResult getItem(IArguments arguments) throws LuaException { if (filter.rightPresent()) return MethodResult.of(null, filter.getRight()); - ItemStack item = RefinedStorage.findStackFromFilter(getNetwork(), getNetwork().getCraftingManager(), filter.getLeft()) + ItemStack item = RefinedStorage.findStackFromFilter(getNetwork(), getNetwork().getCraftingManager(), filter.getLeft()); if (item.isEmpty()) return MethodResult.of(null, "NOT_FOUND"); return MethodResult.of(RefinedStorage.getObjectFromStack(item, getNetwork())); From b969a1be9ad51ddf966229e37158974aa69971ee Mon Sep 17 00:00:00 2001 From: Srendi Date: Sun, 6 Oct 2024 15:31:01 +0200 Subject: [PATCH 219/228] Removed redundant null check --- .../common/addons/appliedenergistics/AppEngApi.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java index 60d5d9d02..3bc0c6d8e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java @@ -563,7 +563,7 @@ public static List listCells(IGridNode node) { if (!iterator.hasNext()) return items; while (iterator.hasNext()) { IStorageProvider entity = iterator.next().getService(IStorageProvider.class); - if (entity == null || !(entity instanceof DriveBlockEntity drive)) + if (!(entity instanceof DriveBlockEntity drive)) continue; InternalInventory inventory = drive.getInternalInventory(); From 6888ed52024fb10ef7ba3ccc717e51d125a8febb Mon Sep 17 00:00:00 2001 From: Srendi Date: Sun, 6 Oct 2024 16:29:01 +0200 Subject: [PATCH 220/228] 1.19.2-0.7.37r --- CHANGELOG.md | 14 ++++++++++++++ gradle.properties | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcca9a6e0..dde6f4283 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [1.19.2-0.7.37r] - 2024-10-06 + +### Added +- Wandering Trader config + +### Changed +- Safe the owner of the memory card to the inventory manager after a player places the card into the manager and clear the card after. Resolves a security issue where players could eventually steal memory cards from other players + +### Fixed +- [#660] Fixed that the inventory manager's `getItemInHand` function adds a blank nbt tag to the item +- [#636] Fixed that the automata's `useOnBlock` function will return PASS in some specific case +- [#645] Fixed that the inventory functions for the powah integration would always return nil +- Fixed that some entity operations don't have enough range + ## [1.19.2-0.7.36r] - 2024-06-11 ### Added diff --git a/gradle.properties b/gradle.properties index bc6264c70..26856c7ec 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ mod_id=advancedperipherals minecraft_version=1.19.2 forge_version=43.3.8 loader_version=43 -mod_version=0.7.37r +mod_version=0.7.38r release_type=release mappings_channel=parchment mappings_version=2022.11.27-1.19.2 From 58afe1a146348c093515a1be6b81d5901f9aaec9 Mon Sep 17 00:00:00 2001 From: Srendi Date: Sun, 6 Oct 2024 18:08:57 +0200 Subject: [PATCH 221/228] Bump minecolonies --- build.gradle | 8 ++++---- gradle.properties | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index 46a52e796..76542ef74 100644 --- a/build.gradle +++ b/build.gradle @@ -314,10 +314,10 @@ dependencies { // Minecolonies // Remove/Comment this section if you want to use runData. - //runtimeOnly fg.deobf("com.ldtteam:minecolonies:${minecolonies_version}") - //runtimeOnly fg.deobf("com.ldtteam:structurize:${structurize_version}") - //runtimeOnly fg.deobf("com.ldtteam:domum_ornamentum:${domumornamentum_version}:universal") - //runtimeOnly fg.deobf("com.ldtteam:blockui:${blockui_version}") + runtimeOnly fg.deobf("com.ldtteam:minecolonies:${minecolonies_version}") + runtimeOnly fg.deobf("com.ldtteam:structurize:${structurize_version}") + runtimeOnly fg.deobf("com.ldtteam:domum_ornamentum:${domumornamentum_version}:universal") + runtimeOnly fg.deobf("com.ldtteam:blockui:${blockui_version}") compileOnly fg.deobf("com.ldtteam:minecolonies:${minecolonies_version}") compileOnly fg.deobf("com.ldtteam:structurize:${structurize_version}") diff --git a/gradle.properties b/gradle.properties index 53eb44312..a175320b3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -24,7 +24,7 @@ ttoolkit_version=0.1.3 # Mod dependencies cc_version=1.110.0 curios_version=5.2.0+1.20.1 -minecolonies_version=1.20.1-1.1.472-BETA +minecolonies_version=1.20.1-1.1.684-snapshot appliedenergistics_version=15.0.9-beta patchouli_version=1.20.1-84 refinedstorage_version=1.12.3 @@ -40,14 +40,14 @@ appliedmekanistics_version=4842281 # Mod dependencies which are needed for other mods # For minecolonies -structurize_version=1.20.1-1.0.662-BETA -multipiston_version=1.20-1.2.30-ALPHA -blockui_version=1.20.1-0.0.101-ALPHA -domumornamentum_version=1.20-1.0.150-BETA +structurize_version=1.20.1-1.0.740-BETA +multipiston_version=1.20.1-1.2.30-ALPHA +blockui_version=1.20.1-1.0.186-beta +domumornamentum_version=1.20.1-1.0.184-BETA # For Create flywheel_version=0.6.8.a-1 # Mod dependencies for testing stuff(Only used in the dev environment) -jei_version=1.20.1-forge:15.2.0.22 +jei_version=1.20.1-forge:15.3.0.4 createadditions_version=5099752 \ No newline at end of file From eee605fb7f58864907cbc1c7ad865d18b46501f3 Mon Sep 17 00:00:00 2001 From: endi Date: Tue, 15 Oct 2024 22:09:46 +0200 Subject: [PATCH 222/228] [#661] Fixed incompatibility with minecolonies 1.20.1-1.1.686-snapshot and newer --- gradle.properties | 2 +- .../common/addons/minecolonies/MineColonies.java | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index a175320b3..2d0b438c6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -24,7 +24,7 @@ ttoolkit_version=0.1.3 # Mod dependencies cc_version=1.110.0 curios_version=5.2.0+1.20.1 -minecolonies_version=1.20.1-1.1.684-snapshot +minecolonies_version=1.20.1-1.1.686-snapshot appliedenergistics_version=15.0.9-beta patchouli_version=1.20.1-84 refinedstorage_version=1.12.3 diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/minecolonies/MineColonies.java b/src/main/java/de/srendi/advancedperipherals/common/addons/minecolonies/MineColonies.java index b6dd3c2a1..3d6d0fdd3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/minecolonies/MineColonies.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/minecolonies/MineColonies.java @@ -15,6 +15,7 @@ import com.minecolonies.api.research.util.ResearchState; import com.minecolonies.core.colony.buildings.AbstractBuildingStructureBuilder; import com.minecolonies.core.colony.buildings.utils.BuildingBuilderResource; +import com.minecolonies.core.entity.citizen.citizenhandlers.CitizenSkillHandler; import com.minecolonies.core.research.BuildingResearchRequirement; import com.mojang.brigadier.exceptions.CommandSyntaxException; import de.srendi.advancedperipherals.common.util.LuaConverter; @@ -151,12 +152,12 @@ public static Object homeToObject(IBuilding home) { * @param skills skills as list. Can be obtained via {@link ICitizenData#getCitizenSkillHandler} * @return a map with information about the skill */ - public static Object skillsToObject(Map> skills) { + public static Object skillsToObject(Map skills) { Map map = new HashMap<>(); for (Skill skill : skills.keySet()) { Map skillData = new HashMap<>(); - skillData.put("level", skills.get(skill).getA()); - skillData.put("xp", skills.get(skill).getB()); + skillData.put("level", skills.get(skill).getLevel()); + skillData.put("xp", skills.get(skill).getExperience()); map.put(skill.name(), skillData); } From 56b4497dc1f00627933cadd63f2f89e6bb25d95b Mon Sep 17 00:00:00 2001 From: zyxkad Date: Wed, 16 Oct 2024 12:19:59 -0600 Subject: [PATCH 223/228] use tick rather than epoch time --- .../common/util/ChunkManager.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java index 3b338284d..4a916782e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java @@ -27,7 +27,7 @@ public class ChunkManager extends SavedData { private static final String DATA_NAME = AdvancedPeripherals.MOD_ID + "_ForcedChunks"; private static final String FORCED_CHUNKS_TAG = "forcedChunks"; - private static int tickCounter = 0; + private static long tickCounter = 0; private final Map forcedChunks = new HashMap<>(); private boolean initialized = false; @@ -60,8 +60,7 @@ public static void serverTick(TickEvent.ServerTickEvent event) { tickCounter++; // run cleanup per chunkLoadValidTime / 10 final int checkIntervalInTick = APConfig.PERIPHERALS_CONFIG.chunkLoadValidTime.get() * 20 / 10; - if (tickCounter >= checkIntervalInTick) { - tickCounter = 0; + if (tickCounter % checkIntervalInTick == 0) { ChunkManager.get(ServerLifecycleHooks.getCurrentServer().overworld()).cleanup(); } } @@ -259,7 +258,7 @@ private static class LoadChunkRecord { this.dimensionName = dimensionName; this.pos = pos; this.radius = radius; - this.lastTouch = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC); + this.lastTouch = tickCounter; } public static LoadChunkRecord deserialize(@NotNull CompoundTag tag) { @@ -285,12 +284,11 @@ public void setRadius(int radius) { } public void touch() { - lastTouch = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC); + lastTouch = tickCounter; } public boolean isValid() { - long currentEpoch = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC); - return lastTouch + APConfig.PERIPHERALS_CONFIG.chunkLoadValidTime.get() >= currentEpoch; + return lastTouch + APConfig.PERIPHERALS_CONFIG.chunkLoadValidTime.get() * 20 >= tickCounter; } public @NotNull CompoundTag serialize() { From c09b8c03c06a9f2b9898362083f401a794810313 Mon Sep 17 00:00:00 2001 From: endi Date: Mon, 21 Oct 2024 14:24:27 +0200 Subject: [PATCH 224/228] 1.20.1-0.7.41r --- CHANGELOG.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19ac667aa..cc7068555 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,23 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [1.20.1-0.7.41r] - 2024-10-21 + +### Added +- Wandering Trader config + +### Changed +- Save the owner of the memory card to the inventory manager after a player places the card into the manager and clear the card after. Resolves a security issue where players could eventually steal memory cards from other players + +### Fixed +- [#660] Fixed that the inventory manager's `getItemInHand` function adds a blank nbt tag to the item +- [#636] Fixed that the automata's `useOnBlock` function will return PASS in some specific case +- [#645] Fixed that the inventory functions for the powah integration would always return nil +- Fixed that some entity operations don't have enough range +- [#642] Fixed that some powah integrations clashes with the generic energy peripheral from CC which disables some functions +- [#640] Fixed null pointer exception when invoking `getName` +- [#662] Use tick time instead of epoch time for our chunk manager, fixes an issue where chunks unload if some ticks are skipped (lag) + ## [1.20.1-0.7.40r] - 2024-06-11 ### Added From 04b9c8bdc6ac358aab6a503dc7b769beba24ac05 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Tue, 29 Oct 2024 12:39:46 -0600 Subject: [PATCH 225/228] only clear owner when new empty card is swapped but not after load fix #664 --- .../blockentities/InventoryManagerEntity.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java index c973be0ae..115ea23d2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java @@ -52,11 +52,19 @@ public boolean canPlaceItemThroughFace(int index, @NotNull ItemStack itemStackIn @Override public void setItem(int index, @NotNull ItemStack stack) { - if (stack.getItem() instanceof MemoryCardItem && stack.hasTag() && stack.getTag().contains("ownerId")) { - UUID owner = stack.getTag().getUUID("ownerId"); - this.owner = owner; - stack.getTag().remove("ownerId"); - stack.getTag().remove("owner"); + if (index != 0) { + throw new IndexOutOfBoundsException("Inventory manager's index can only be zero"); + } + if (stack.getItem() instanceof MemoryCardItem) { + if (stack.hasTag() && stack.getTag().contains("ownerId")) { + UUID owner = stack.getTag().getUUID("ownerId"); + this.owner = owner; + stack.getTag().remove("ownerId"); + stack.getTag().remove("owner"); + } else if (stack != this.getItem(index)) { + // Only clear owner when the new card item is not the current item + this.owner = null; + } } else { this.owner = null; } From 54333115eb3e5df8163d68a5ff28ca97853615e3 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Tue, 29 Oct 2024 12:41:39 -0600 Subject: [PATCH 226/228] remove index check --- .../common/blocks/blockentities/InventoryManagerEntity.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java index 115ea23d2..b6dfde03f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java @@ -52,9 +52,6 @@ public boolean canPlaceItemThroughFace(int index, @NotNull ItemStack itemStackIn @Override public void setItem(int index, @NotNull ItemStack stack) { - if (index != 0) { - throw new IndexOutOfBoundsException("Inventory manager's index can only be zero"); - } if (stack.getItem() instanceof MemoryCardItem) { if (stack.hasTag() && stack.getTag().contains("ownerId")) { UUID owner = stack.getTag().getUUID("ownerId"); From 3444a30e75fd12f94470754b9d2410f2b8873a78 Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 4 Nov 2024 10:47:52 +0100 Subject: [PATCH 227/228] Resolve Checkstyle --- .../common/addons/minecolonies/MineColonies.java | 1 - .../common/addons/powah/FurnatorIntegration.java | 1 - .../common/addons/powah/ReactorIntegration.java | 1 - .../de/srendi/advancedperipherals/common/util/ChunkManager.java | 2 -- 4 files changed, 5 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/minecolonies/MineColonies.java b/src/main/java/de/srendi/advancedperipherals/common/addons/minecolonies/MineColonies.java index 3d6d0fdd3..551dcbdad 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/minecolonies/MineColonies.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/minecolonies/MineColonies.java @@ -24,7 +24,6 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.Tuple; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.player.Player; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/FurnatorIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/FurnatorIntegration.java index df4ad0010..b0fc5dff1 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/FurnatorIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/FurnatorIntegration.java @@ -2,7 +2,6 @@ import dan200.computercraft.api.lua.LuaFunction; import de.srendi.advancedperipherals.lib.peripherals.APGenericPeripheral; -import de.srendi.advancedperipherals.lib.peripherals.BlockEntityIntegrationPeripheral; import de.srendi.advancedperipherals.common.util.LuaConverter; import net.minecraft.world.item.ItemStack; import owmii.powah.block.furnator.FurnatorTile; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/ReactorIntegration.java b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/ReactorIntegration.java index 76cb24b78..f5e30ec90 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/powah/ReactorIntegration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/powah/ReactorIntegration.java @@ -2,7 +2,6 @@ import dan200.computercraft.api.lua.LuaFunction; import de.srendi.advancedperipherals.lib.peripherals.APGenericPeripheral; -import de.srendi.advancedperipherals.lib.peripherals.BlockEntityIntegrationPeripheral; import de.srendi.advancedperipherals.common.util.LuaConverter; import net.minecraft.world.item.ItemStack; import owmii.powah.block.reactor.ReactorPartTile; diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java index 437445f92..e5d66d7cb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java @@ -18,8 +18,6 @@ import org.apache.logging.log4j.Level; import org.jetbrains.annotations.NotNull; -import java.time.LocalDateTime; -import java.time.ZoneOffset; import java.util.*; @Mod.EventBusSubscriber(modid = AdvancedPeripherals.MOD_ID) From bf26670b1fc802e3039bf4d23ce6f484aeedd9ee Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 22 Nov 2024 00:18:00 +0100 Subject: [PATCH 228/228] 1.20.4 networking work, I still need to work on a bit, I don't understand every change yet This commit mainly exists because I need to switch machines and for a 1.20.1 merge --- build.gradle | 2 +- .../advancedperipherals/APCreativeTab.java | 3 +- .../client/ClientNetworking.java | 33 +++++++++++++++++++ .../client/KeyBindings.java | 2 +- .../common/setup/Registration.java | 5 ++- .../common/util/fakeplayer/APFakePlayer.java | 16 ++++----- .../network/APNetworking.java | 24 +++++++------- .../network/base/IPacket.java | 15 +++------ .../network/toclient/ToastToClientPacket.java | 30 ++++++++++++++--- 9 files changed, 87 insertions(+), 43 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/client/ClientNetworking.java diff --git a/build.gradle b/build.gradle index 76dfb4c94..5bce83d5e 100644 --- a/build.gradle +++ b/build.gradle @@ -238,7 +238,7 @@ dependencies { runtimeOnly "top.theillusivec4.curios:curios-forge:${curios_version}" // Refined Storage - implementation "com.refinedmods:refinedstorage:${refinedstorage_version}" + //implementation "com.refinedmods:refinedstorage:${refinedstorage_version}" // AE2 Things compileOnly "curse.maven:ae2things-609977:${ae2things_version}-sources" diff --git a/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java b/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java index b5b82889f..7b923bc7a 100644 --- a/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java +++ b/src/main/java/de/srendi/advancedperipherals/APCreativeTab.java @@ -8,6 +8,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.ItemStack; +import net.neoforged.neoforge.registries.DeferredHolder; import java.util.Collection; import java.util.Set; @@ -16,7 +17,7 @@ public class APCreativeTab { public static void populateCreativeTabBuilder(CreativeModeTab.Builder builder) { builder.displayItems((set, out) -> { - Registration.ITEMS.().stream().map(RegistryObject::get).forEach(out::accept); + Registration.ITEMS.getEntries().stream().map(DeferredHolder::get).forEach(out::accept); out.acceptAll(pocketUpgrade(CCRegistration.ID.COLONY_POCKET)); out.acceptAll(pocketUpgrade(CCRegistration.ID.CHATTY_POCKET)); out.acceptAll(pocketUpgrade(CCRegistration.ID.PLAYER_POCKET)); diff --git a/src/main/java/de/srendi/advancedperipherals/client/ClientNetworking.java b/src/main/java/de/srendi/advancedperipherals/client/ClientNetworking.java new file mode 100644 index 000000000..91c39043c --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/client/ClientNetworking.java @@ -0,0 +1,33 @@ +package de.srendi.advancedperipherals.client; + +import dan200.computercraft.shared.network.NetworkMessage; +import dan200.computercraft.shared.network.server.ServerNetworkContext; +import de.srendi.advancedperipherals.network.base.IPacket; +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.ClientPacketListener; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.PacketListener; +import net.minecraft.network.protocol.Packet; +import org.jetbrains.annotations.NotNull; + +public final class ClientNetworking { + private ClientNetworking() { + } + + public static void sendToServer(IPacket message) { + ClientPacketListener connection = Minecraft.getInstance().getConnection(); + if (connection != null) { + connection.send(new Packet<>() { + @Override + public void write(@NotNull FriendlyByteBuf pBuffer) { + message.encode(pBuffer); + } + + @Override + public void handle(@NotNull PacketListener pHandler) { + } + }); + } + + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/client/KeyBindings.java b/src/main/java/de/srendi/advancedperipherals/client/KeyBindings.java index 2b7e02b9f..7bccb2b59 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/KeyBindings.java +++ b/src/main/java/de/srendi/advancedperipherals/client/KeyBindings.java @@ -1,7 +1,7 @@ package de.srendi.advancedperipherals.client; import net.minecraft.client.KeyMapping; -import net.neoforged.client.event.RegisterKeyMappingsEvent; +import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent; import org.lwjgl.glfw.GLFW; public class KeyBindings { diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/Registration.java b/src/main/java/de/srendi/advancedperipherals/common/setup/Registration.java index 6b6432be1..0407a07aa 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/Registration.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/Registration.java @@ -10,13 +10,12 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntityType; import net.neoforged.bus.api.IEventBus; - import net.neoforged.neoforge.registries.DeferredRegister; public class Registration { - public static final DeferredRegister BLOCKS = DeferredRegister.create(Registries.BLOCK, AdvancedPeripherals.MOD_ID); - public static final DeferredRegister ITEMS = DeferredRegister.create(Registries.ITEM, AdvancedPeripherals.MOD_ID); + public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(AdvancedPeripherals.MOD_ID); + public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(AdvancedPeripherals.MOD_ID); public static final DeferredRegister> TILE_ENTITIES = DeferredRegister.create(Registries.BLOCK_ENTITY_TYPE, AdvancedPeripherals.MOD_ID); public static final DeferredRegister> CONTAINER_TYPES = DeferredRegister.create(Registries.MENU, AdvancedPeripherals.MOD_ID); public static final DeferredRegister POI_TYPES = DeferredRegister.create(Registries.POINT_OF_INTEREST_TYPE, AdvancedPeripherals.MOD_ID); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java index 5f02df17c..d33511e10 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java @@ -33,12 +33,10 @@ import net.minecraft.world.level.block.StructureBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.*; -import net.neoforged.common.ForgeHooks; -import net.neoforged.common.ForgeMod; -import net.neoforged.common.util.FakePlayer; -import net.neoforged.event.ForgeEventFactory; -import net.neoforged.event.entity.player.PlayerInteractEvent; -import net.neoforged.eventbus.api.Event; +import net.neoforged.bus.api.Event; +import net.neoforged.neoforge.common.CommonHooks; +import net.neoforged.neoforge.common.util.FakePlayer; +import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -63,7 +61,7 @@ public class APFakePlayer extends FakePlayer { private float currentDamage = 0; public APFakePlayer(ServerLevel world, Entity owner, GameProfile profile) { - super(world, profile != null && profile.isComplete() ? profile : PROFILE); + super(world, PROFILE); if (owner != null) { setCustomName(owner.getName()); this.owner = new WeakReference<>(owner); @@ -220,7 +218,7 @@ public InteractionResult useOnFilteredEntity(Predicate filter) { public InteractionResult useOnSpecificEntity(@NotNull Entity entity, HitResult result) { InteractionResult simpleInteraction = interactOn(entity, InteractionHand.MAIN_HAND); if (simpleInteraction == InteractionResult.SUCCESS) return simpleInteraction; - if (ForgeHooks.onInteractEntityAt(this, entity, result.getLocation(), InteractionHand.MAIN_HAND) != null) { + if (CommonHooks.onInteractEntityAt(this, entity, result.getLocation(), InteractionHand.MAIN_HAND) == InteractionResult.FAIL) { return InteractionResult.FAIL; } @@ -276,7 +274,7 @@ public InteractionResult use(boolean skipEntity, boolean skipBlock, @Nullable Pr ItemStack copyBeforeUse = stack.copy(); InteractionResult result = stack.useOn(new UseOnContext(level(), this, InteractionHand.MAIN_HAND, stack, blockHit)); if (stack.isEmpty()) { - ForgeEventFactory.onPlayerDestroyItem(this, copyBeforeUse, InteractionHand.MAIN_HAND); + CommonHooks.onPlayerDestroyItem(this, copyBeforeUse, InteractionHand.MAIN_HAND); } return result; } else if (hit instanceof EntityHitResult entityHit) { diff --git a/src/main/java/de/srendi/advancedperipherals/network/APNetworking.java b/src/main/java/de/srendi/advancedperipherals/network/APNetworking.java index e3ff5b5f2..bd1ed85ca 100644 --- a/src/main/java/de/srendi/advancedperipherals/network/APNetworking.java +++ b/src/main/java/de/srendi/advancedperipherals/network/APNetworking.java @@ -3,6 +3,7 @@ import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.network.base.IPacket; import de.srendi.advancedperipherals.network.toclient.ToastToClientPacket; +import net.minecraft.client.gui.components.toasts.Toast; import net.minecraft.core.BlockPos; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; @@ -12,8 +13,12 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; +import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.common.util.FakePlayer; import net.neoforged.fml.ModLoadingContext; +import net.neoforged.neoforge.network.connection.ConnectionUtils; +import net.neoforged.neoforge.network.event.RegisterPayloadHandlerEvent; +import net.neoforged.neoforge.network.registration.IPayloadRegistrar; import net.neoforged.network.NetworkDirection; import net.neoforged.network.NetworkRegistry; import net.neoforged.network.PacketDistributor; @@ -24,27 +29,20 @@ public class APNetworking { private static final String PROTOCOL_VERSION = ModLoadingContext.get().getActiveContainer().getModInfo().getVersion().toString(); - private static final SimpleChannel NETWORK_CHANNEL = NetworkRegistry.newSimpleChannel(new ResourceLocation(AdvancedPeripherals.MOD_ID, "main_channel"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals); private static int id = 0; public static void init() { registerServerToClient(ToastToClientPacket.class, ToastToClientPacket::decode); } - public static void registerServerToClient(Class packet, Function decode) { - NETWORK_CHANNEL.registerMessage(id++, packet, IPacket::encode, decode, IPacket::handle, Optional.of(NetworkDirection.PLAY_TO_CLIENT)); - } + @SubscribeEvent + public static void register(final RegisterPayloadHandlerEvent event) { + final IPayloadRegistrar registrar = event.registrar(AdvancedPeripherals.MOD_ID) + .versioned(PROTOCOL_VERSION) + .common(AdvancedPeripherals.getRL("toasttoclient"), ToastToClientPacket::decode, IPacket::handlePacket) + .optional(); - public static void registerClientToServer(Class packet, Function decode) { - NETWORK_CHANNEL.registerMessage(id++, packet, IPacket::encode, decode, IPacket::handle, Optional.of(NetworkDirection.PLAY_TO_SERVER)); - } - /** - * Sends a packet to the server.

- * Must be called Client side. - */ - public static void sendToServer(Object msg) { - NETWORK_CHANNEL.sendToServer(msg); } /** diff --git a/src/main/java/de/srendi/advancedperipherals/network/base/IPacket.java b/src/main/java/de/srendi/advancedperipherals/network/base/IPacket.java index 85815054c..d27395122 100644 --- a/src/main/java/de/srendi/advancedperipherals/network/base/IPacket.java +++ b/src/main/java/de/srendi/advancedperipherals/network/base/IPacket.java @@ -1,20 +1,15 @@ package de.srendi.advancedperipherals.network.base; import net.minecraft.network.FriendlyByteBuf; -import net.neoforged.network.NetworkEvent; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.neoforged.neoforge.network.handling.IPayloadContext; +import net.neoforged.neoforge.network.handling.IPayloadHandler; -import java.util.function.Supplier; +public interface IPacket & CustomPacketPayload> extends IPayloadHandler { -public interface IPacket { - - static void handle(MSG message, Supplier context) { - NetworkEvent.Context ctx = context.get(); - ctx.enqueueWork(() -> message.handle(ctx)); - ctx.setPacketHandled(true); + static > void handlePacket(MSG message) { } - void handle(NetworkEvent.Context context); - void encode(FriendlyByteBuf buffer); } diff --git a/src/main/java/de/srendi/advancedperipherals/network/toclient/ToastToClientPacket.java b/src/main/java/de/srendi/advancedperipherals/network/toclient/ToastToClientPacket.java index ced579df4..ce342da99 100644 --- a/src/main/java/de/srendi/advancedperipherals/network/toclient/ToastToClientPacket.java +++ b/src/main/java/de/srendi/advancedperipherals/network/toclient/ToastToClientPacket.java @@ -5,10 +5,14 @@ import de.srendi.advancedperipherals.network.base.IPacket; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; import net.neoforged.fml.loading.FMLEnvironment; +import net.neoforged.neoforge.network.handling.IPayloadContext; import net.neoforged.network.NetworkEvent; +import org.jetbrains.annotations.NotNull; -public class ToastToClientPacket implements IPacket { +public class ToastToClientPacket implements IPacket, CustomPacketPayload { private final Component title; private final Component component; @@ -19,7 +23,22 @@ public ToastToClientPacket(Component title, Component component) { } @Override - public void handle(NetworkEvent.Context context) { + public void encode(FriendlyByteBuf buffer) { + buffer.writeComponent(this.title); + buffer.writeComponent(this.component); + } + + public static ToastToClientPacket decode(FriendlyByteBuf buffer) { + return new ToastToClientPacket(buffer.readComponent(), buffer.readComponent()); + } + + + /** + * @param payload The payload. + * @param context The context. + */ + @Override + public void handle(@NotNull ToastToClientPacket payload, @NotNull IPayloadContext context) { // Should in the theory not happen, but safe is safe. if (!FMLEnvironment.dist.isClient()) { AdvancedPeripherals.debug("Tried to display toasts on the server, aborting."); @@ -29,12 +48,13 @@ public void handle(NetworkEvent.Context context) { } @Override - public void encode(FriendlyByteBuf buffer) { + public void write(@NotNull FriendlyByteBuf buffer) { buffer.writeComponent(this.title); buffer.writeComponent(this.component); } - public static ToastToClientPacket decode(FriendlyByteBuf buffer) { - return new ToastToClientPacket(buffer.readComponent(), buffer.readComponent()); + @Override + public @NotNull ResourceLocation id() { + return AdvancedPeripherals.getRL("toasttoclient"); } }