diff --git a/dependencies.gradle b/dependencies.gradle index d476166c..854a873e 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -167,6 +167,12 @@ dependencies { // CoFH Core (compile time dep of Thermal Foundation) (from CurseForge) compileOnly "curse.maven:cofh-core-69162:2920433" // Version 4.6.6.1 + // Betterer P2P (from CurseForge) + compileOnly rfg.deobf("curse.maven:betterer-p2p-943734:4928154") // Version 1.3.2 + + // Forgelin (dep of Betterer P2P) (from CurseForge) + compileOnly "curse.maven:shadowfacts-forgelin-248453:2785465" // Version 1.8.4 + /* -------------------------------- Soft Deps, Multiple Runtime Declaration -------------------------------- */ if (project.enable_draconic.toBoolean() || project.enable_thermal.toBoolean()) { runtimeOnly "curse.maven:redstone-flux-270789:2920436" // Version 2.1.1.1 @@ -209,6 +215,11 @@ dependencies { runtimeOnly "curse.maven:nae2-884359:5380800" // Version 1.6.4 } + if (project.enable_better_p2p.toBoolean()) { + runtimeOnly "curse.maven:shadowfacts-forgelin-248453:2785465" // Version 1.8.4 + runtimeOnly "curse.maven:betterer-p2p-943734:4928154" // Version 1.3.2 + } + if (project.enable_dme.toBoolean()) { // Dep: Patchouli runtimeOnly "curse.maven:patchouli-306770:3162874" // Version 1.0-23.6 diff --git a/gradle.properties b/gradle.properties index 4457c370..37957035 100644 --- a/gradle.properties +++ b/gradle.properties @@ -243,6 +243,9 @@ enable_ae2 = false # Whether to enable NAE2 in runtime. Requires enable_ae2 to be true. enable_nae2 = false +# Whether to enable Betterer P2P in runtime. Requires enable_ae2 to be true. +enable_better_p2p = false + # Whether to enable DME in runtime. Enables the DME Sim Chamber. enable_dme = false diff --git a/src/main/java/com/nomiceu/nomilabs/gregtech/LabsSounds.java b/src/main/java/com/nomiceu/nomilabs/LabsSounds.java similarity index 78% rename from src/main/java/com/nomiceu/nomilabs/gregtech/LabsSounds.java rename to src/main/java/com/nomiceu/nomilabs/LabsSounds.java index 37df094a..1b68013c 100644 --- a/src/main/java/com/nomiceu/nomilabs/gregtech/LabsSounds.java +++ b/src/main/java/com/nomiceu/nomilabs/LabsSounds.java @@ -1,11 +1,9 @@ -package com.nomiceu.nomilabs.gregtech; +package com.nomiceu.nomilabs; import static gregtech.api.GregTechAPI.soundManager; import net.minecraft.util.SoundEvent; -import com.nomiceu.nomilabs.LabsValues; - public class LabsSounds { public static SoundEvent MICROVERSE; diff --git a/src/main/java/com/nomiceu/nomilabs/LabsTextures.java b/src/main/java/com/nomiceu/nomilabs/LabsTextures.java new file mode 100644 index 00000000..05f12340 --- /dev/null +++ b/src/main/java/com/nomiceu/nomilabs/LabsTextures.java @@ -0,0 +1,61 @@ +package com.nomiceu.nomilabs; + +import com.nomiceu.nomilabs.util.LabsNames; + +import gregtech.api.gui.resources.TextureArea; +import gregtech.client.renderer.texture.cube.OrientedOverlayRenderer; +import gregtech.client.renderer.texture.cube.SimpleOverlayRenderer; + +public class LabsTextures { + + /* Overlays (Machine) */ + public static OrientedOverlayRenderer GROWTH_CHAMBER_OVERLAY; + + /* Overlays (Casings) */ + public static SimpleOverlayRenderer MICROVERSE_CASING; + + /* Recipe Map Textures */ + public static TextureArea PROGRESS_BAR_ROCKET; + + /* Gui Textures */ + public static TextureArea[] P2P_CUSTOM_MODES; + public static TextureArea P2P_INPUT_ICON; + public static TextureArea P2P_OUTPUT_ICON; + + public static void preInit() { + GROWTH_CHAMBER_OVERLAY = new OrientedOverlayRenderer("nomilabs:multiblock/growth_chamber"); + MICROVERSE_CASING = new SimpleOverlayRenderer("nomilabs:microverse_casing"); + PROGRESS_BAR_ROCKET = labsFullImage("textures/gui/progress_bar/progress_bar_rocket.png"); + + var imageSizeX = 64; + var imageSizeY = 32; + var imageLoc = "textures/gui/advanced_memory_card/custom_modes.png"; + var spriteSize = 32; + P2P_CUSTOM_MODES = new TextureArea[] { + labsAreaImage(imageLoc, imageSizeX, imageSizeY, 0, 0, spriteSize, spriteSize), + labsAreaImage(imageLoc, imageSizeX, imageSizeY, spriteSize, 0, spriteSize, spriteSize), + }; + + P2P_INPUT_ICON = labsFullImage("textures/gui/advanced_memory_card/input.png"); + P2P_OUTPUT_ICON = labsFullImage("textures/gui/advanced_memory_card/output.png"); + } + + /** + * Like the one in TextureArea, but with Labs Registry. + */ + public static TextureArea labsFullImage(String imageLocation) { + return new TextureArea(LabsNames.makeLabsName(imageLocation), 0.0, 0.0, 1.0, 1.0); + } + + /** + * Almost like the one in TextureArea, but with Labs Registry. + */ + public static TextureArea labsAreaImage(String imageLocation, int imageSizeX, int imageSizeY, int u, int v, + int width, int height) { + return new TextureArea(LabsNames.makeLabsName(imageLocation), + u / (imageSizeX * 1.0), + v / (imageSizeY * 1.0), + width / (imageSizeX * 1.0), + height / (imageSizeY * 1.0)); + } +} diff --git a/src/main/java/com/nomiceu/nomilabs/LabsValues.java b/src/main/java/com/nomiceu/nomilabs/LabsValues.java index 0173ca80..950d0324 100644 --- a/src/main/java/com/nomiceu/nomilabs/LabsValues.java +++ b/src/main/java/com/nomiceu/nomilabs/LabsValues.java @@ -45,4 +45,5 @@ public class LabsValues { public static final String AE2_STUFF_MODID = "ae2stuff"; public static final String BOGOSORT_MODID = "bogosorter"; public static final String THERMAL_FOUNDATION_MODID = "thermalfoundation"; + public static final String BETTER_P2P_MODID = "betterp2p"; } diff --git a/src/main/java/com/nomiceu/nomilabs/core/LabsLateMixin.java b/src/main/java/com/nomiceu/nomilabs/core/LabsLateMixin.java index a517e63b..212ff604 100644 --- a/src/main/java/com/nomiceu/nomilabs/core/LabsLateMixin.java +++ b/src/main/java/com/nomiceu/nomilabs/core/LabsLateMixin.java @@ -49,7 +49,8 @@ public class LabsLateMixin implements ILateMixinLoader { new AbstractMap.SimpleImmutableEntry<>(LabsValues.AA_MODID, true), new AbstractMap.SimpleImmutableEntry<>(LabsValues.BOGOSORT_MODID, true), new AbstractMap.SimpleImmutableEntry<>(LabsValues.THERMAL_FOUNDATION_MODID, true), - new AbstractMap.SimpleImmutableEntry<>(LabsValues.BQU_MODID, true)) + new AbstractMap.SimpleImmutableEntry<>(LabsValues.BQU_MODID, true), + new AbstractMap.SimpleImmutableEntry<>(LabsValues.BETTER_P2P_MODID, true)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); @Override diff --git a/src/main/java/com/nomiceu/nomilabs/event/ClientProxy.java b/src/main/java/com/nomiceu/nomilabs/event/ClientProxy.java index 22a8e6af..b492c01d 100644 --- a/src/main/java/com/nomiceu/nomilabs/event/ClientProxy.java +++ b/src/main/java/com/nomiceu/nomilabs/event/ClientProxy.java @@ -15,11 +15,13 @@ import net.minecraftforge.fml.relauncher.SideOnly; import com.cleanroommc.groovyscript.event.ScriptRunEvent; +import com.nomiceu.nomilabs.LabsTextures; import com.nomiceu.nomilabs.LabsValues; import com.nomiceu.nomilabs.NomiLabs; import com.nomiceu.nomilabs.fluid.registry.LabsFluids; -import com.nomiceu.nomilabs.gregtech.LabsTextures; import com.nomiceu.nomilabs.gregtech.block.registry.LabsMetaBlocks; +import com.nomiceu.nomilabs.integration.betterp2p.LabsBetterMemoryCardModes; +import com.nomiceu.nomilabs.integration.betterp2p.ModeDescriptionsHandler; import com.nomiceu.nomilabs.integration.betterquesting.LabsTierHelper; import com.nomiceu.nomilabs.item.registry.LabsItems; import com.nomiceu.nomilabs.network.LabsNetworkHandler; @@ -78,6 +80,13 @@ public static void addTooltipNormal(ItemTooltipEvent event) { @SubscribeEvent public static void languageChanged(LabsResourcesRefreshedEvent event) { LabsTooltipHelper.onLanguageChange(); + + if (Loader.isModLoaded(LabsValues.BETTER_P2P_MODID)) { + // Make sure Modes is Loaded before Description Refresh + // Doesn't consume any resources or time if class already loaded + LabsBetterMemoryCardModes.preInit(); + ModeDescriptionsHandler.refreshDescriptions(); + } } @SubscribeEvent diff --git a/src/main/java/com/nomiceu/nomilabs/event/CommonProxy.java b/src/main/java/com/nomiceu/nomilabs/event/CommonProxy.java index 845947c9..fd502d6b 100644 --- a/src/main/java/com/nomiceu/nomilabs/event/CommonProxy.java +++ b/src/main/java/com/nomiceu/nomilabs/event/CommonProxy.java @@ -20,6 +20,7 @@ import com.cleanroommc.groovyscript.event.GsHandEvent; import com.cleanroommc.groovyscript.event.ScriptRunEvent; +import com.nomiceu.nomilabs.LabsSounds; import com.nomiceu.nomilabs.LabsValues; import com.nomiceu.nomilabs.block.registry.LabsBlocks; import com.nomiceu.nomilabs.config.LabsConfig; @@ -27,7 +28,6 @@ import com.nomiceu.nomilabs.dimension.LabsDimensions; import com.nomiceu.nomilabs.fluid.FluidRegistryMixinHelper; import com.nomiceu.nomilabs.fluid.registry.LabsFluids; -import com.nomiceu.nomilabs.gregtech.LabsSounds; import com.nomiceu.nomilabs.gregtech.block.registry.LabsMetaBlocks; import com.nomiceu.nomilabs.gregtech.material.registry.LabsMaterials; import com.nomiceu.nomilabs.gregtech.metatileentity.registry.LabsMetaTileEntities; @@ -39,6 +39,7 @@ import com.nomiceu.nomilabs.groovy.GroovyScriptHandManager; import com.nomiceu.nomilabs.groovy.NCActiveCoolerHelper; import com.nomiceu.nomilabs.integration.architecturecraft.LabsShapes; +import com.nomiceu.nomilabs.integration.betterp2p.LabsBetterMemoryCardModes; import com.nomiceu.nomilabs.integration.jei.JEIPlugin; import com.nomiceu.nomilabs.integration.top.LabsTOPManager; import com.nomiceu.nomilabs.item.ItemExcitationCoil; @@ -73,6 +74,9 @@ public static void preInit() { LabsConfig.modIntegration.enableArchitectureCraftIntegration) LabsShapes.preInit(); + if (Loader.isModLoaded(LabsValues.BETTER_P2P_MODID)) + LabsBetterMemoryCardModes.preInit(); + LabsCreativeTabs.preInit(); if (LabsConfig.content.customContent.enableItems) diff --git a/src/main/java/com/nomiceu/nomilabs/gregtech/LabsTextures.java b/src/main/java/com/nomiceu/nomilabs/gregtech/LabsTextures.java deleted file mode 100644 index ca0e620c..00000000 --- a/src/main/java/com/nomiceu/nomilabs/gregtech/LabsTextures.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.nomiceu.nomilabs.gregtech; - -import com.nomiceu.nomilabs.util.LabsNames; - -import gregtech.api.gui.resources.TextureArea; -import gregtech.client.renderer.texture.cube.OrientedOverlayRenderer; -import gregtech.client.renderer.texture.cube.SimpleOverlayRenderer; - -public class LabsTextures { - - /* Overlays (Machine) */ - public static OrientedOverlayRenderer GROWTH_CHAMBER_OVERLAY; - - /* Overlays (Casings) */ - public static SimpleOverlayRenderer MICROVERSE_CASING; - - /* Recipe Map Textures */ - public static TextureArea PROGRESS_BAR_ROCKET; - - public static void preInit() { - GROWTH_CHAMBER_OVERLAY = new OrientedOverlayRenderer("nomilabs:multiblock/growth_chamber"); - MICROVERSE_CASING = new SimpleOverlayRenderer("nomilabs:microverse_casing"); - PROGRESS_BAR_ROCKET = labsFullImage("textures/gui/progress_bar/progress_bar_rocket.png"); - } - - /** - * Like the one in TextureArea, but with Labs Registry. - */ - public static TextureArea labsFullImage(String imageLocation) { - return new TextureArea(LabsNames.makeLabsName(imageLocation), 0.0, 0.0, 1.0, 1.0); - } -} diff --git a/src/main/java/com/nomiceu/nomilabs/gregtech/metatileentity/multiblock/MetaTileEntityGrowthChamber.java b/src/main/java/com/nomiceu/nomilabs/gregtech/metatileentity/multiblock/MetaTileEntityGrowthChamber.java index 31b23c7a..4ec00e43 100755 --- a/src/main/java/com/nomiceu/nomilabs/gregtech/metatileentity/multiblock/MetaTileEntityGrowthChamber.java +++ b/src/main/java/com/nomiceu/nomilabs/gregtech/metatileentity/multiblock/MetaTileEntityGrowthChamber.java @@ -15,7 +15,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import com.nomiceu.nomilabs.gregtech.LabsTextures; +import com.nomiceu.nomilabs.LabsTextures; import com.nomiceu.nomilabs.gregtech.block.BlockUniqueCasing; import com.nomiceu.nomilabs.gregtech.block.registry.LabsMetaBlocks; import com.nomiceu.nomilabs.gregtech.recipe.LabsRecipeMaps; diff --git a/src/main/java/com/nomiceu/nomilabs/gregtech/metatileentity/multiblock/MetaTileEntityMicroverseProjector.java b/src/main/java/com/nomiceu/nomilabs/gregtech/metatileentity/multiblock/MetaTileEntityMicroverseProjector.java index 517cc551..424ec065 100644 --- a/src/main/java/com/nomiceu/nomilabs/gregtech/metatileentity/multiblock/MetaTileEntityMicroverseProjector.java +++ b/src/main/java/com/nomiceu/nomilabs/gregtech/metatileentity/multiblock/MetaTileEntityMicroverseProjector.java @@ -20,9 +20,9 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import com.nomiceu.nomilabs.LabsTextures; import com.nomiceu.nomilabs.LabsValues; import com.nomiceu.nomilabs.block.registry.LabsBlocks; -import com.nomiceu.nomilabs.gregtech.LabsTextures; import com.nomiceu.nomilabs.gregtech.metatileentity.registry.LabsMetaTileEntities; import com.nomiceu.nomilabs.gregtech.recipe.LabsRecipeMaps; diff --git a/src/main/java/com/nomiceu/nomilabs/gregtech/recipe/LabsRecipeMaps.java b/src/main/java/com/nomiceu/nomilabs/gregtech/recipe/LabsRecipeMaps.java index e98afc55..71a62937 100644 --- a/src/main/java/com/nomiceu/nomilabs/gregtech/recipe/LabsRecipeMaps.java +++ b/src/main/java/com/nomiceu/nomilabs/gregtech/recipe/LabsRecipeMaps.java @@ -5,10 +5,10 @@ import net.minecraftforge.fml.common.Loader; +import com.nomiceu.nomilabs.LabsSounds; +import com.nomiceu.nomilabs.LabsTextures; import com.nomiceu.nomilabs.LabsValues; import com.nomiceu.nomilabs.config.LabsConfig; -import com.nomiceu.nomilabs.gregtech.LabsSounds; -import com.nomiceu.nomilabs.gregtech.LabsTextures; import com.nomiceu.nomilabs.util.LabsModeHelper; import gregtech.api.gui.GuiTextures; diff --git a/src/main/java/com/nomiceu/nomilabs/integration/betterp2p/AccessibleGridServerCache.java b/src/main/java/com/nomiceu/nomilabs/integration/betterp2p/AccessibleGridServerCache.java new file mode 100644 index 00000000..61d8439e --- /dev/null +++ b/src/main/java/com/nomiceu/nomilabs/integration/betterp2p/AccessibleGridServerCache.java @@ -0,0 +1,14 @@ +package com.nomiceu.nomilabs.integration.betterp2p; + +import com.projecturanus.betterp2p.network.data.P2PLocation; + +import appeng.parts.p2p.PartP2PTunnel; + +public interface AccessibleGridServerCache { + + PartP2PTunnel labs$changeIsInput(P2PLocation key, boolean isInput); + + boolean labs$addInput(P2PLocation key, short sourceFrequency); + + boolean labs$addOutput(P2PLocation key, short sourceFrequency); +} diff --git a/src/main/java/com/nomiceu/nomilabs/integration/betterp2p/AccessibleGuiAdvancedMemoryCard.java b/src/main/java/com/nomiceu/nomilabs/integration/betterp2p/AccessibleGuiAdvancedMemoryCard.java new file mode 100644 index 00000000..a4ae2432 --- /dev/null +++ b/src/main/java/com/nomiceu/nomilabs/integration/betterp2p/AccessibleGuiAdvancedMemoryCard.java @@ -0,0 +1,14 @@ +package com.nomiceu.nomilabs.integration.betterp2p; + +import com.projecturanus.betterp2p.item.BetterMemoryCardModes; + +public interface AccessibleGuiAdvancedMemoryCard { + + BetterMemoryCardModes labs$getMode(); + + void labs$setMode(BetterMemoryCardModes mode); + + void labs$syncMemoryInfo(); + + void labs$closeTypeSelector(); +} diff --git a/src/main/java/com/nomiceu/nomilabs/integration/betterp2p/ExtendedITypeReceiver.java b/src/main/java/com/nomiceu/nomilabs/integration/betterp2p/ExtendedITypeReceiver.java new file mode 100644 index 00000000..79000fb8 --- /dev/null +++ b/src/main/java/com/nomiceu/nomilabs/integration/betterp2p/ExtendedITypeReceiver.java @@ -0,0 +1,6 @@ +package com.nomiceu.nomilabs.integration.betterp2p; + +public interface ExtendedITypeReceiver { + + void acceptIsInput(boolean isInput); +} diff --git a/src/main/java/com/nomiceu/nomilabs/integration/betterp2p/LabsBetterMemoryCardModes.java b/src/main/java/com/nomiceu/nomilabs/integration/betterp2p/LabsBetterMemoryCardModes.java new file mode 100644 index 00000000..a1ec889f --- /dev/null +++ b/src/main/java/com/nomiceu/nomilabs/integration/betterp2p/LabsBetterMemoryCardModes.java @@ -0,0 +1,44 @@ +package com.nomiceu.nomilabs.integration.betterp2p; + +import java.util.Map; + +import net.minecraftforge.common.util.EnumHelper; + +import com.projecturanus.betterp2p.item.BetterMemoryCardModes; + +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; + +public class LabsBetterMemoryCardModes { + + /** + * Map of Mode to Labs ID. + */ + public static final Map LABS_ADDED_MODES = new Object2ObjectOpenHashMap<>(); + + public static final BetterMemoryCardModes ADD_AS_INPUT = addMode(0, "ADD_AS_INPUT", + "nomilabs.gui.advanced_memory_card.mode.add_input", + "nomilabs.gui.advanced_memory_card.mode.add_input.desc.1", + "nomilabs.gui.advanced_memory_card.mode.add_input.desc.2"); + + public static final BetterMemoryCardModes ADD_AS_OUTPUT = addMode(1, "ADD_AS_OUTPUT", + "nomilabs.gui.advanced_memory_card.mode.add_output", + "nomilabs.gui.advanced_memory_card.mode.add_output.desc.1", + "nomilabs.gui.advanced_memory_card.mode.add_output.desc.2"); + + /** + * Essentially, this loads the class, allowing the above values to be added. + *

+ * If for some reason, the values are needed before this, they will still be loaded, and calling init will have no + * affect on that. + */ + public static void preInit() {} + + private static BetterMemoryCardModes addMode(int labsId, String name, String unlocalizedName, + String... unlocalizedDesc) { + BetterMemoryCardModes result = EnumHelper.addEnum(BetterMemoryCardModes.class, name, + new Class[] { String.class, String[].class }, + unlocalizedName, unlocalizedDesc); + LABS_ADDED_MODES.put(result, labsId); + return result; + } +} diff --git a/src/main/java/com/nomiceu/nomilabs/integration/betterp2p/ModeDescriptionsHandler.java b/src/main/java/com/nomiceu/nomilabs/integration/betterp2p/ModeDescriptionsHandler.java new file mode 100644 index 00000000..34123820 --- /dev/null +++ b/src/main/java/com/nomiceu/nomilabs/integration/betterp2p/ModeDescriptionsHandler.java @@ -0,0 +1,28 @@ +package com.nomiceu.nomilabs.integration.betterp2p; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.nomiceu.nomilabs.mixin.betterp2p.GuiAdvancedMemoryCardKtAccessor; +import com.projecturanus.betterp2p.item.BetterMemoryCardModes; +import com.projecturanus.betterp2p.item.BetterMemoryCardModesKt; + +public class ModeDescriptionsHandler { + + public static final Map> labsModeDescriptions; + + public static void refreshDescriptions() { + labsModeDescriptions.clear(); + for (var mode : BetterMemoryCardModes.values()) { + labsModeDescriptions.put(mode, + GuiAdvancedMemoryCardKtAccessor.fmtTooltips(mode.getUnlocalizedName(), mode.getUnlocalizedDesc(), + BetterMemoryCardModesKt.MAX_TOOLTIP_LENGTH)); + } + } + + static { + labsModeDescriptions = new HashMap<>(); + refreshDescriptions(); + } +} diff --git a/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/BlockStateEnergyCoreStructure.java b/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/BlockStateEnergyCoreStructure.java index b06f6467..3dd50d49 100644 --- a/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/BlockStateEnergyCoreStructure.java +++ b/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/BlockStateEnergyCoreStructure.java @@ -175,9 +175,9 @@ else if (flag == FLAG_FORME) { invis.blockName = Objects.requireNonNull(states.getDefault().getBlock().getRegistryName()).toString(); TileInvisECoreBlockState invisState = (TileInvisECoreBlockState) invis; if (BlockStates.statesEqual(states.getDefault(), states.getDefault().getBlock().getDefaultState())) { - invisState.setIsDefault(); + invisState.labs$setIsDefault(); } else { - invisState.setMetadata(states.getDefault().getBlock().getMetaFromState(states.getDefault())); + invisState.labs$setMetadata(states.getDefault().getBlock().getMetaFromState(states.getDefault())); } invis.setController(core); } @@ -280,11 +280,11 @@ public boolean checkBlock(BlockStates states, World world, BlockPos pos) { if (invis.blockName .equals(Objects.requireNonNull(states.getDefault().getBlock().getRegistryName()).toString())) { TileInvisECoreBlockState invisState = (TileInvisECoreBlockState) invis; - if (invisState.getDefault()) { + if (invisState.labs$getDefault()) { if (BlockStates.statesEqual(states.getDefault(), states.getDefault().getBlock().getDefaultState())) return true; } else if (states.getDefault().getBlock().getMetaFromState(states.getDefault()) == - invisState.getMetadata()) + invisState.labs$getMetadata()) return true; } } diff --git a/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/InvisECoreBlockLogic.java b/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/InvisECoreBlockLogic.java index 3992695e..48e9e7fc 100644 --- a/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/InvisECoreBlockLogic.java +++ b/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/InvisECoreBlockLogic.java @@ -23,14 +23,14 @@ public static void onBlockHarvested(World world, BlockPos pos, EntityPlayer play if (!invis.blockName.isEmpty() && !player.capabilities.isCreativeMode) { Block trueBlock = Block.REGISTRY.getObject(new ResourceLocation(invis.blockName)); if (!trueBlock.equals(Blocks.AIR)) { - if (invisState.getDefault()) { + if (invisState.labs$getDefault()) { if (invis.blockName.equals("draconicevolution:particle_generator")) { Block.spawnAsEntity(world, pos, new ItemStack(trueBlock, 1, 2)); } else { Block.spawnAsEntity(world, pos, new ItemStack(trueBlock)); } } else - Block.spawnAsEntity(world, pos, new ItemStack(trueBlock, 1, invisState.getMetadata())); + Block.spawnAsEntity(world, pos, new ItemStack(trueBlock, 1, invisState.labs$getMetadata())); } } @@ -59,10 +59,10 @@ public static ItemStack getPickBlock(World world, BlockPos pos) { var invisState = (TileInvisECoreBlockState) invis; - if (invisState.getDefault()) + if (invisState.labs$getDefault()) return new ItemStack(block); else - return new ItemStack(block, 1, invisState.getMetadata()); + return new ItemStack(block, 1, invisState.labs$getMetadata()); } return ItemStack.EMPTY; } diff --git a/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/TileInvisECoreBlockLogic.java b/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/TileInvisECoreBlockLogic.java index 7663f030..b439221e 100644 --- a/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/TileInvisECoreBlockLogic.java +++ b/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/TileInvisECoreBlockLogic.java @@ -23,8 +23,8 @@ public static void revert(TileInvisECoreBlock invis) { Block block = Block.REGISTRY.getObject(new ResourceLocation(invis.blockName)); IBlockState state; if (!block.equals(Blocks.AIR)) { - if (!((TileInvisECoreBlockState) invis).getDefault()) - state = block.getStateFromMeta(((TileInvisECoreBlockState) invis).getMetadata()); + if (!((TileInvisECoreBlockState) invis).labs$getDefault()) + state = block.getStateFromMeta(((TileInvisECoreBlockState) invis).labs$getMetadata()); else state = block.getDefaultState(); @@ -37,10 +37,10 @@ public static void revert(TileInvisECoreBlock invis) { public static SPacketUpdateTileEntity getUpdatePacket(TileInvisECoreBlock invis) { NBTTagCompound compound = new NBTTagCompound(); var invisState = (TileInvisECoreBlockState) invis; - if (invisState.getDefault()) + if (invisState.labs$getDefault()) compound.setString("BlockName", invis.blockName); else - compound.setString("BlockName", invis.blockName + " " + invisState.getMetadata()); + compound.setString("BlockName", invis.blockName + " " + invisState.labs$getMetadata()); invis.coreOffset.toNBT(compound); return new SPacketUpdateTileEntity(invis.getPos(), 0, compound); @@ -51,20 +51,20 @@ public static void onDataPacket(TileInvisECoreBlock invis, SPacketUpdateTileEnti var invisState = (TileInvisECoreBlockState) invis; if (input.length != 2) { invis.blockName = input[0]; - invisState.setIsDefault(); + invisState.labs$setIsDefault(); } else { invis.blockName = input[0]; - invisState.setMetadata(Integer.parseInt(input[1])); + invisState.labs$setMetadata(Integer.parseInt(input[1])); } invis.coreOffset.fromNBT(pkt.getNbtCompound()); } public static void writeExtraNBT(TileInvisECoreBlock invis, NBTTagCompound compound) { var invisState = (TileInvisECoreBlockState) invis; - if (invisState.getDefault()) + if (invisState.labs$getDefault()) compound.setString("BlockName", invis.blockName); else - compound.setString("BlockName", invis.blockName + " " + invisState.getMetadata()); + compound.setString("BlockName", invis.blockName + " " + invisState.labs$getMetadata()); } public static void readExtraNBT(TileInvisECoreBlock invis, NBTTagCompound compound) { @@ -72,10 +72,10 @@ public static void readExtraNBT(TileInvisECoreBlock invis, NBTTagCompound compou var invisState = (TileInvisECoreBlockState) invis; if (input.length != 2) { invis.blockName = input[0]; - invisState.setIsDefault(); + invisState.labs$setIsDefault(); } else { invis.blockName = input[0]; - invisState.setMetadata(Integer.parseInt(input[1])); + invisState.labs$setMetadata(Integer.parseInt(input[1])); } } } diff --git a/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/TileInvisECoreBlockState.java b/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/TileInvisECoreBlockState.java index ddce6d3b..67b28bf4 100644 --- a/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/TileInvisECoreBlockState.java +++ b/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/TileInvisECoreBlockState.java @@ -2,17 +2,17 @@ public interface TileInvisECoreBlockState { - boolean getDefault(); + boolean labs$getDefault(); /** * This should also set metadata to 0. */ - void setIsDefault(); + void labs$setIsDefault(); - int getMetadata(); + int labs$getMetadata(); /** * This should also set default to false, if meta set is not 0 (legacy compat) */ - void setMetadata(int metadata); + void labs$setMetadata(int metadata); } diff --git a/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/ClientProxyMixin.java b/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/ClientProxyMixin.java new file mode 100644 index 00000000..83641efa --- /dev/null +++ b/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/ClientProxyMixin.java @@ -0,0 +1,46 @@ +package com.nomiceu.nomilabs.mixin.betterp2p; + +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.common.Loader; +import net.minecraftforge.fml.common.Optional; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import com.llamalad7.mixinextras.sugar.Local; +import com.nomiceu.nomilabs.LabsValues; +import com.projecturanus.betterp2p.ClientProxy; + +import appeng.api.definitions.IItemDefinition; +import appeng.parts.p2p.PartP2PTunnel; +import co.neeve.nae2.NAE2; +import co.neeve.nae2.common.parts.p2p.PartP2PInterface; + +/** + * Loads Interface P2P (Client Side) + */ +@Mixin(value = ClientProxy.class, remap = false) +public abstract class ClientProxyMixin { + + @Shadow + protected abstract void registerTunnel(IItemDefinition def, int type, Class> classType, + ResourceLocation icon); + + @Inject(method = "initTunnels", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILEXCEPTION) + private void addInterface(CallbackInfo ci, @Local(ordinal = 0) int typeId) { + if (!Loader.isModLoaded(LabsValues.NAE2_MODID)) return; + labs$addNae2P2ps(typeId); + } + + @Unique + @Optional.Method(modid = LabsValues.NAE2_MODID) + private void labs$addNae2P2ps(int typeId) { + registerTunnel(NAE2.definitions().parts().p2pTunnelInterface(), typeId++, PartP2PInterface.class, + new ResourceLocation(LabsValues.NAE2_MODID, "textures/part/p2p/interface.png")); + } +} diff --git a/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/CommonProxyMixin.java b/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/CommonProxyMixin.java new file mode 100644 index 00000000..8027dfba --- /dev/null +++ b/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/CommonProxyMixin.java @@ -0,0 +1,43 @@ +package com.nomiceu.nomilabs.mixin.betterp2p; + +import net.minecraftforge.fml.common.Loader; +import net.minecraftforge.fml.common.Optional; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import com.llamalad7.mixinextras.sugar.Local; +import com.nomiceu.nomilabs.LabsValues; +import com.projecturanus.betterp2p.CommonProxy; + +import appeng.api.definitions.IItemDefinition; +import appeng.parts.p2p.PartP2PTunnel; +import co.neeve.nae2.NAE2; +import co.neeve.nae2.common.parts.p2p.PartP2PInterface; + +/** + * Loads Interface P2P (Common Side) + */ +@Mixin(value = CommonProxy.class, remap = false) +public abstract class CommonProxyMixin { + + @Shadow + protected abstract void registerTunnel(IItemDefinition def, int type, Class> classType); + + @Inject(method = "initTunnels", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILEXCEPTION) + private void addInterface(CallbackInfo ci, @Local(ordinal = 0) int typeId) { + if (!Loader.isModLoaded(LabsValues.NAE2_MODID)) return; + labs$addNae2P2ps(typeId); + } + + @Unique + @Optional.Method(modid = LabsValues.NAE2_MODID) + private void labs$addNae2P2ps(int typeId) { + registerTunnel(NAE2.definitions().parts().p2pTunnelInterface(), typeId++, PartP2PInterface.class); + } +} diff --git a/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/GridServerCacheMixin.java b/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/GridServerCacheMixin.java new file mode 100644 index 00000000..9f8f8c37 --- /dev/null +++ b/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/GridServerCacheMixin.java @@ -0,0 +1,167 @@ +package com.nomiceu.nomilabs.mixin.betterp2p; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.text.TextComponentTranslation; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import com.llamalad7.mixinextras.sugar.Local; +import com.nomiceu.nomilabs.integration.betterp2p.AccessibleGridServerCache; +import com.projecturanus.betterp2p.network.data.GridServerCache; +import com.projecturanus.betterp2p.network.data.P2PLocation; +import com.projecturanus.betterp2p.network.data.P2PLocationKt; +import com.projecturanus.betterp2p.util.p2p.TunnelInfo; + +import appeng.api.config.SecurityPermissions; +import appeng.api.networking.IGrid; +import appeng.api.networking.security.ISecurityGrid; +import appeng.helpers.IInterfaceHost; +import appeng.me.GridAccessException; +import appeng.me.cache.P2PCache; +import appeng.parts.p2p.PartP2PTunnel; +import appeng.util.Platform; +import kotlin.Pair; + +/** + * Implements the logic of the new modes and switching output/input. + */ +@Mixin(value = GridServerCache.class, remap = false) +public abstract class GridServerCacheMixin implements AccessibleGridServerCache { + + @Shadow + @Final + private IGrid grid; + + @Shadow + @Final + private EntityPlayer player; + + @Shadow + @Final + private Map> listP2P; + + @Shadow + protected abstract PartP2PTunnel updateP2P(P2PLocation key, PartP2PTunnel tunnel, short frequency, + boolean output, String name); + + @Shadow + protected abstract void handleInterface(IInterfaceHost oldIn, IInterfaceHost oldOut, IInterfaceHost newIn, + IInterfaceHost newOut, List drops); + + @Inject(method = "changeP2PType", at = @At("RETURN"), cancellable = true) + private void restoreName(PartP2PTunnel tunnel, TunnelInfo newType, + CallbackInfoReturnable> cir) { + var result = cir.getReturnValue(); + if (result == null) return; + + if (tunnel.hasCustomInventoryName()) result.setCustomName(tunnel.getCustomInventoryName()); + cir.setReturnValue(result); + } + + @Inject(method = "linkP2P", + at = @At(value = "INVOKE", + target = "Lappeng/me/cache/P2PCache;getInputs(SLjava/lang/Class;)Lappeng/me/cache/helpers/TunnelCollection;", + ordinal = 0), + locals = LocalCapture.CAPTURE_FAILEXCEPTION, + require = 1, + cancellable = true) + private void properlyLinkP2p(P2PLocation inputIndex, P2PLocation outputIndex, + CallbackInfoReturnable, PartP2PTunnel>> cir, + @Local(ordinal = 0) short frequency) { + var input = listP2P.get(inputIndex); + var output = listP2P.get(outputIndex); + + P2PCache cache = null; + try { + cache = input.getProxy().getP2P(); + } catch (GridAccessException e) { + throw new RuntimeException(e); + } + + var inputs = cache.getInputs(frequency, input.getClass()); + if (!inputs.isEmpty()) { + for (var origInput : inputs) { + if (origInput != input) { + updateP2P(P2PLocationKt.toLoc(origInput), origInput, frequency, false, + origInput.hasCustomInventoryName() ? origInput.getCustomInventoryName() : ""); + } + } + + } + + // Perform the link + var inputResult = updateP2P(inputIndex, input, frequency, false, + input.hasCustomInventoryName() ? input.getCustomInventoryName() : ""); + var outputResult = updateP2P(outputIndex, output, frequency, true, + output.hasCustomInventoryName() ? output.getCustomInventoryName() : ""); + + // Special case for interfaces + if (input instanceof IInterfaceHost inputHost && output instanceof IInterfaceHost outputHost) { + List drops = new ArrayList<>(); + handleInterface(inputHost, outputHost, (IInterfaceHost) inputResult, (IInterfaceHost) outputResult, drops); + Platform.spawnDrops(player.world, output.getLocation().getPos(), drops); + } + + cir.setReturnValue(new Pair<>(inputResult, outputResult)); + } + + @Override + @Unique + public PartP2PTunnel labs$changeIsInput(P2PLocation key, boolean isInput) { + if (grid instanceof ISecurityGrid securityGrid && + !securityGrid.hasPermission(player, SecurityPermissions.BUILD)) { + return null; + } + var p2p = listP2P.get(key); + if (p2p == null) return null; + + if (p2p.isOutput() == !isInput) { + player.sendMessage(new TextComponentTranslation("nomilabs.gui.better_p2p.error.same_output", + isInput ? "Input" : "Output")); + return null; + } + + return updateP2P(key, p2p, p2p.getFrequency(), !isInput, + p2p.hasCustomInventoryName() ? p2p.getCustomInventoryName() : ""); + } + + @Override + @Unique + public boolean labs$addInput(P2PLocation key, short sourceFrequency) { + return labs$addAs(key, sourceFrequency, true); + } + + @Override + @Unique + public boolean labs$addOutput(P2PLocation key, short sourceFrequency) { + return labs$addAs(key, sourceFrequency, false); + } + + /** + * Shared Logic + */ + @Unique + private boolean labs$addAs(P2PLocation key, short sourceFrequency, boolean isInput) { + if (grid instanceof ISecurityGrid securityGrid && + !securityGrid.hasPermission(player, SecurityPermissions.BUILD)) { + return false; + } + var p2p = listP2P.get(key); + if (p2p == null) return false; + + return updateP2P(key, p2p, sourceFrequency, !isInput, + p2p.hasCustomInventoryName() ? p2p.getCustomInventoryName() : "") != null; + } +} diff --git a/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/GuiAdvancedMemoryCardKtAccessor.java b/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/GuiAdvancedMemoryCardKtAccessor.java new file mode 100644 index 00000000..15a12fb1 --- /dev/null +++ b/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/GuiAdvancedMemoryCardKtAccessor.java @@ -0,0 +1,21 @@ +package com.nomiceu.nomilabs.mixin.betterp2p; + +import java.util.List; + +import org.apache.commons.lang3.NotImplementedException; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +import com.projecturanus.betterp2p.client.gui.GuiAdvancedMemoryCardKt; + +/** + * Allows Accessing Util Functions. + */ +@Mixin(value = GuiAdvancedMemoryCardKt.class, remap = false) +public interface GuiAdvancedMemoryCardKtAccessor { + + @Invoker("fmtTooltips") + static List fmtTooltips(String title, String[] keys, int maxChars) { + throw new NotImplementedException("GuiAdvancedMemoryCardKt Accessor failed to apply!"); + } +} diff --git a/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/GuiAdvancedMemoryCardMixin.java b/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/GuiAdvancedMemoryCardMixin.java new file mode 100644 index 00000000..0fd89b56 --- /dev/null +++ b/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/GuiAdvancedMemoryCardMixin.java @@ -0,0 +1,52 @@ +package com.nomiceu.nomilabs.mixin.betterp2p; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; + +import com.nomiceu.nomilabs.integration.betterp2p.AccessibleGuiAdvancedMemoryCard; +import com.projecturanus.betterp2p.client.gui.GuiAdvancedMemoryCard; +import com.projecturanus.betterp2p.client.gui.widget.WidgetTypeSelector; +import com.projecturanus.betterp2p.item.BetterMemoryCardModes; + +/** + * Allows accessing needed functions and fields. + */ +@Mixin(value = GuiAdvancedMemoryCard.class, remap = false) +public abstract class GuiAdvancedMemoryCardMixin implements AccessibleGuiAdvancedMemoryCard { + + @Shadow + private BetterMemoryCardModes mode; + + @Shadow + protected abstract void syncMemoryInfo(); + + @Shadow + @Final + private WidgetTypeSelector typeSelector; + + @Override + @Unique + public BetterMemoryCardModes labs$getMode() { + return mode; + } + + @Override + @Unique + public void labs$setMode(BetterMemoryCardModes mode) { + this.mode = mode; + } + + @Override + @Unique + public void labs$syncMemoryInfo() { + syncMemoryInfo(); + } + + @Override + @Unique + public void labs$closeTypeSelector() { + typeSelector.setVisible(false); + } +} diff --git a/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/ModeWidgetButtonMixin.java b/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/ModeWidgetButtonMixin.java new file mode 100644 index 00000000..e77b8601 --- /dev/null +++ b/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/ModeWidgetButtonMixin.java @@ -0,0 +1,134 @@ +package com.nomiceu.nomilabs.mixin.betterp2p; + +import static com.nomiceu.nomilabs.integration.betterp2p.ModeDescriptionsHandler.labsModeDescriptions; +import static com.projecturanus.betterp2p.client.gui.GuiAdvancedMemoryCardKt.*; +import static com.projecturanus.betterp2p.client.gui.GuiHelperKt.drawTexturedQuad; + +import java.util.List; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.Tessellator; + +import org.jetbrains.annotations.NotNull; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import com.nomiceu.nomilabs.LabsTextures; +import com.nomiceu.nomilabs.integration.betterp2p.AccessibleGuiAdvancedMemoryCard; +import com.nomiceu.nomilabs.integration.betterp2p.LabsBetterMemoryCardModes; +import com.projecturanus.betterp2p.client.gui.GuiAdvancedMemoryCard; +import com.projecturanus.betterp2p.client.gui.widget.WidgetButton; +import com.projecturanus.betterp2p.item.BetterMemoryCardModes; + +/** + * Fixes ArrayOutOfBoundsException, Tooltips and Icons with New Modes. + */ +@Mixin(targets = "com.projecturanus.betterp2p.client.gui.GuiAdvancedMemoryCard$2", remap = false) +public abstract class ModeWidgetButtonMixin extends WidgetButton { + + @Unique + private static final double labs$textureSize = 32.0; + + @Unique + protected double labs$texX; + + @Unique + protected double labs$texY; + + @Unique + protected int labs$iconId; + + @Unique + protected boolean labs$useLabsTexture; + + /** + * Mandatory Ignored Constructor + */ + public ModeWidgetButtonMixin(@NotNull GuiAdvancedMemoryCard gui, int x, int y, int width, int height) { + super(gui, x, y, width, height); + } + + @Redirect(method = "", + at = @At(value = "INVOKE", target = "Ljava/util/List;get(I)Ljava/lang/Object;"), + require = 1) + private Object labs$getDescription(List> instance, int index) { + var mode = BetterMemoryCardModes.values()[index]; + return labsModeDescriptions.get(mode); + } + + @Inject(method = "", at = @At("RETURN")) + private void setValues(GuiAdvancedMemoryCard $outer, GuiAdvancedMemoryCard gui, int x, int y, int width, int height, + CallbackInfo ci) { + labs$setTextureDetails(); + } + + @Override + @Unique + public void draw(@NotNull Minecraft mc, int mouseX, int mouseY, float partial) { + Tessellator tessellator = Tessellator.getInstance(); + super.drawBG(tessellator, mouseX, mouseY, partial); + + // If New Labs Mode, Use New Texture + if (labs$useLabsTexture) + LabsTextures.P2P_CUSTOM_MODES[labs$iconId].draw(x + 1.0, y + 1.0, width - 2, height - 2); + else { + drawTexturedQuad(tessellator, + x + 1.0, + y + 1.0, + x + width - 1.0, + y + height - 1.0, + labs$texX / GUI_WIDTH, + labs$texY / GUI_TEX_HEIGHT, + (labs$texX + width) / GUI_WIDTH, + (labs$texY + height) / GUI_TEX_HEIGHT); + } + } + + @Inject(method = "mousePressed", at = @At("HEAD"), cancellable = true) + public void labsMousePressed(int mouseX, int mouseY, int button, CallbackInfoReturnable cir) { + if (!super.mousePressed(getGui().mc, mouseX, mouseY)) { + cir.setReturnValue(false); + return; + } + + var newMode = switch (button) { + case 0 -> labs$getAccessible().labs$getMode().next(false); + case 1 -> labs$getAccessible().labs$getMode().next(true); + default -> BetterMemoryCardModes.INPUT; + }; + labs$getAccessible().labs$setMode(newMode); + + setHoverText(labsModeDescriptions.get(newMode)); + + labs$setTextureDetails(); + + labs$getAccessible().labs$syncMemoryInfo(); + super.playPressSound(getGui().mc.getSoundHandler()); + cir.setReturnValue(true); + } + + @Unique + private AccessibleGuiAdvancedMemoryCard labs$getAccessible() { + return ((AccessibleGuiAdvancedMemoryCard) (Object) getGui()); + } + + @Unique + private void labs$setTextureDetails() { + if (LabsBetterMemoryCardModes.LABS_ADDED_MODES.containsKey(labs$getAccessible().labs$getMode())) { + labs$useLabsTexture = true; + labs$iconId = LabsBetterMemoryCardModes.LABS_ADDED_MODES.get(labs$getAccessible().labs$getMode()); + labs$texX = -1; + labs$texY = -1; + return; + } + labs$texX = (labs$getAccessible().labs$getMode().ordinal() + 3) * labs$textureSize; + labs$texY = 232; + labs$iconId = -1; + labs$useLabsTexture = false; + } +} diff --git a/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/ServerRenameP2PTunnelMixin.java b/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/ServerRenameP2PTunnelMixin.java new file mode 100644 index 00000000..8fb8b95c --- /dev/null +++ b/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/ServerRenameP2PTunnelMixin.java @@ -0,0 +1,61 @@ +package com.nomiceu.nomilabs.mixin.betterp2p; + +import net.minecraftforge.fml.common.network.simpleimpl.IMessage; +import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import com.llamalad7.mixinextras.sugar.Local; +import com.projecturanus.betterp2p.network.ModNetwork; +import com.projecturanus.betterp2p.network.data.P2PLocationKt; +import com.projecturanus.betterp2p.network.packet.C2SRenameP2P; +import com.projecturanus.betterp2p.network.packet.ServerRenameP2PTunnel; + +import appeng.api.parts.IPart; +import appeng.me.GridAccessException; +import appeng.parts.p2p.PartP2PTunnel; + +/** + * Properly handles inputs and unbound P2Ps in renaming. + */ +@Mixin(value = ServerRenameP2PTunnel.class, remap = false) +public class ServerRenameP2PTunnelMixin { + + @Inject(method = "onMessage(Lcom/projecturanus/betterp2p/network/packet/C2SRenameP2P;Lnet/minecraftforge/fml/common/network/simpleimpl/MessageContext;)Lnet/minecraftforge/fml/common/network/simpleimpl/IMessage;", + at = @At(value = "INVOKE", + target = "Lappeng/parts/p2p/PartP2PTunnel;setCustomName(Ljava/lang/String;)V", + shift = At.Shift.AFTER), + require = 1, + cancellable = true) + private void properlyHandleInputs(C2SRenameP2P message, MessageContext ctx, CallbackInfoReturnable cir, + @Local(ordinal = 0) IPart partTunnel) { + var tunnel = (PartP2PTunnel) partTunnel; + var state = ModNetwork.INSTANCE.getPlayerState().get(ctx.getServerHandler().player.getUniqueID()); + + try { + if (tunnel.getInputs().isEmpty() && tunnel.getOutputs().isEmpty()) { + state.getGridCache().markDirty(P2PLocationKt.toLoc(tunnel), tunnel); + ModNetwork.INSTANCE.requestP2PUpdate(ctx.getServerHandler().player); + cir.setReturnValue(null); + return; + } + + for (var input : tunnel.getInputs()) { + // Mark all dirty + for (var output : input.getOutputs()) { + var outputTunnel = (PartP2PTunnel) output; + state.getGridCache().markDirty(P2PLocationKt.toLoc(outputTunnel), outputTunnel); + } + state.getGridCache().markDirty(P2PLocationKt.toLoc(input), input); + } + + ModNetwork.INSTANCE.requestP2PUpdate(ctx.getServerHandler().player); + cir.setReturnValue(null); + } catch (GridAccessException e) { + throw new RuntimeException(e); + } + } +} diff --git a/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/WidgetP2PColumnMixin.java b/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/WidgetP2PColumnMixin.java new file mode 100644 index 00000000..acf4c3f7 --- /dev/null +++ b/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/WidgetP2PColumnMixin.java @@ -0,0 +1,60 @@ +package com.nomiceu.nomilabs.mixin.betterp2p; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import com.nomiceu.nomilabs.integration.betterp2p.LabsBetterMemoryCardModes; +import com.nomiceu.nomilabs.network.LabsNetworkHandler; +import com.nomiceu.nomilabs.network.LabsP2PAddAsInputMessage; +import com.nomiceu.nomilabs.network.LabsP2PAddAsOutputMessage; +import com.projecturanus.betterp2p.client.gui.InfoList; +import com.projecturanus.betterp2p.client.gui.InfoWrapper; +import com.projecturanus.betterp2p.client.gui.widget.IGuiTextField; +import com.projecturanus.betterp2p.client.gui.widget.WidgetP2PColumn; +import com.projecturanus.betterp2p.item.BetterMemoryCardModes; + +import kotlin.jvm.functions.Function0; + +/** + * Trims text before renaming, handles add as input/output. + */ +@Mixin(value = WidgetP2PColumn.class, remap = false) +public class WidgetP2PColumnMixin { + + @Shadow + @Final + private InfoList infos; + + @Shadow + @Final + private Function0 mode; + + @Shadow + @Final + private IGuiTextField renameBar; + + @Inject(method = "finishRename", at = @At("HEAD")) + private void trimText(CallbackInfo ci) { + renameBar.setText(renameBar.getText().trim()); + } + + @Inject(method = "onBindButtonClicked", at = @At("HEAD"), cancellable = true) + private void handleAddAs(InfoWrapper info, CallbackInfo ci) { + if (infos.getSelectedInfo() == null) return; + + var currentMode = mode.invoke(); + if (!LabsBetterMemoryCardModes.LABS_ADDED_MODES.containsKey(currentMode)) return; + + if (currentMode == LabsBetterMemoryCardModes.ADD_AS_INPUT) + LabsNetworkHandler.NETWORK_HANDLER + .sendToServer(new LabsP2PAddAsInputMessage(infos.getSelectedInfo().getLoc(), info.getFrequency())); + else if (currentMode == LabsBetterMemoryCardModes.ADD_AS_OUTPUT) + LabsNetworkHandler.NETWORK_HANDLER + .sendToServer(new LabsP2PAddAsOutputMessage(infos.getSelectedInfo().getLoc(), info.getFrequency())); + ci.cancel(); + } +} diff --git a/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/WidgetP2PDeviceMixin.java b/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/WidgetP2PDeviceMixin.java new file mode 100644 index 00000000..814e455c --- /dev/null +++ b/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/WidgetP2PDeviceMixin.java @@ -0,0 +1,104 @@ +package com.nomiceu.nomilabs.mixin.betterp2p; + +import net.minecraft.client.gui.GuiScreen; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import com.llamalad7.mixinextras.sugar.Local; +import com.nomiceu.nomilabs.integration.betterp2p.AccessibleGuiAdvancedMemoryCard; +import com.nomiceu.nomilabs.integration.betterp2p.ExtendedITypeReceiver; +import com.nomiceu.nomilabs.integration.betterp2p.LabsBetterMemoryCardModes; +import com.nomiceu.nomilabs.network.LabsNetworkHandler; +import com.nomiceu.nomilabs.network.LabsP2PChangeTypeMessage; +import com.projecturanus.betterp2p.client.gui.GuiAdvancedMemoryCard; +import com.projecturanus.betterp2p.client.gui.InfoWrapper; +import com.projecturanus.betterp2p.client.gui.widget.P2PEntryConstants; +import com.projecturanus.betterp2p.client.gui.widget.WidgetP2PDevice; +import com.projecturanus.betterp2p.item.BetterMemoryCardModes; + +import kotlin.jvm.functions.Function0; + +/** + * Changes Background colors, handles button visibilities for new modes. + */ +@Mixin(value = WidgetP2PDevice.class, remap = false) +public abstract class WidgetP2PDeviceMixin implements ExtendedITypeReceiver { + + @Shadow + protected abstract InfoWrapper getSelectedInfo(); + + @Shadow + @Final + private GuiAdvancedMemoryCard gui; + + @Shadow + @Final + private Function0 infoSupplier; + + @Shadow + private int y; + @Shadow + private int x; + @Unique + private static final int LABS_INPUT_COLOR = 0x7f6d9cf8; + + @Unique + private static final int LABS_OUTPUT_COLOR = 0x7fecb36c; + + @Inject(method = "render", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/client/renderer/GlStateManager;color(FFFF)V", + remap = true)) + private void drawNewBackgrounds(int mouseX, int mouseY, float partialTicks, CallbackInfo ci) { + var info = infoSupplier.invoke(); + boolean hasSelected = getSelectedInfo() != null; + + if (hasSelected && getSelectedInfo().getLoc() == info.getLoc()) { + GuiScreen.drawRect(x, y, x + P2PEntryConstants.WIDTH, y + P2PEntryConstants.HEIGHT, + P2PEntryConstants.SELECTED_COLOR); + } else if (info.getError()) { + // P2P output without an input, or unbound + GuiScreen.drawRect(x, y, x + P2PEntryConstants.WIDTH, y + P2PEntryConstants.HEIGHT, + P2PEntryConstants.ERROR_COLOR); + } else if (hasSelected && getSelectedInfo().getFrequency() == info.getFrequency() && info.getFrequency() != 0) { + // Show input/output + GuiScreen.drawRect(x, y, x + P2PEntryConstants.WIDTH, y + P2PEntryConstants.HEIGHT, + info.getOutput() ? LABS_OUTPUT_COLOR : LABS_INPUT_COLOR); + } + } + + @Redirect(method = "render", + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiScreen;drawRect(IIIII)V", remap = true)) + private void cancelOldBackgroundDraws(int left, int top, int right, int bottom, int color) {} + + @Inject(method = "updateButtonVisibility", at = @At("TAIL"), locals = LocalCapture.CAPTURE_FAILEXCEPTION) + private void handleAddInputVisibility(CallbackInfo ci, @Local(ordinal = 0) InfoWrapper info, + @Local(ordinal = 0) BetterMemoryCardModes mode) { + if (info == null || getSelectedInfo() == null) return; + if (mode == LabsBetterMemoryCardModes.ADD_AS_INPUT || mode == LabsBetterMemoryCardModes.ADD_AS_OUTPUT) { + // Bind Button should be visible if the device is not the selected, + // and is bound to different frequency than selected + info.getBindButton().enabled = info.getLoc() != getSelectedInfo().getLoc() && + info.getFrequency() != (short) 0 && + info.getFrequency() != getSelectedInfo().getFrequency(); + info.getUnbindButton().enabled = false; + } + } + + @Override + public void acceptIsInput(boolean isInput) { + var info = infoSupplier.invoke(); + if (info != null) { + LabsNetworkHandler.NETWORK_HANDLER.sendToServer(new LabsP2PChangeTypeMessage(info.getLoc(), isInput)); + } + ((AccessibleGuiAdvancedMemoryCard) (Object) gui).labs$closeTypeSelector(); + } +} diff --git a/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/WidgetTypeSelectorMixin.java b/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/WidgetTypeSelectorMixin.java new file mode 100644 index 00000000..32e4cfaf --- /dev/null +++ b/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/WidgetTypeSelectorMixin.java @@ -0,0 +1,162 @@ +package com.nomiceu.nomilabs.mixin.betterp2p; + +import static com.projecturanus.betterp2p.client.gui.widget.WidgetTypeSelectorKt.ICONS_PER_ROW; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.OpenGlHelper; + +import org.lwjgl.opengl.GL11; +import org.spongepowered.asm.mixin.*; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import com.nomiceu.nomilabs.LabsTextures; +import com.nomiceu.nomilabs.integration.betterp2p.ExtendedITypeReceiver; +import com.nomiceu.nomilabs.util.LabsTranslate; +import com.projecturanus.betterp2p.client.gui.GuiAdvancedMemoryCard; +import com.projecturanus.betterp2p.client.gui.widget.ITypeReceiver; +import com.projecturanus.betterp2p.client.gui.widget.WidgetTypeSelector; +import com.projecturanus.betterp2p.util.p2p.ClientTunnelInfo; + +import gregtech.api.gui.resources.TextureArea; + +/** + * Allows Changing Input/Output P2P. + */ +@Mixin(value = WidgetTypeSelector.class, remap = false) +public class WidgetTypeSelectorMixin { + + @Shadow + public ITypeReceiver parent; + + @Shadow + @Final + @Mutable + private int height; + + @Shadow + private int y; + + @Shadow + private int x; + + @Shadow + private int hoveredIdx; + + @Shadow + @Final + private int width; + + @Unique + private int labs$origHeight; + + @Unique + private List> labs$translated; + + @Unique + private TextureArea[] labs$icons; + + @Unique + private int labs$hovered; + + @Inject(method = "", at = @At("RETURN")) + private void saveOrigHeightAndTranslate(int x, int y, List p2pTypes, CallbackInfo ci) { + labs$origHeight = height; + + labs$translated = new ArrayList<>(); + labs$translated.add(Collections.singletonList(LabsTranslate.translate("nomilabs.gui.better_p2p.input"))); + labs$translated.add(Collections.singletonList(LabsTranslate.translate("nomilabs.gui.better_p2p.output"))); + labs$icons = new TextureArea[] { + LabsTextures.P2P_INPUT_ICON, + LabsTextures.P2P_OUTPUT_ICON, + }; + + labs$hovered = -1; + } + + @Inject(method = "render", at = @At("HEAD")) + private void checkHeight(GuiAdvancedMemoryCard gui, int mouseX, int mouseY, float partialTicks, CallbackInfo ci) { + if (parent instanceof ExtendedITypeReceiver) + height = labs$origHeight + (18 * 2); + } + + @Inject(method = "mousePressed", at = @At("HEAD"), cancellable = true) + private void handleInputOutputPressed(int mouseX, int mouseY, int mouseButton, CallbackInfo ci) { + if (!(parent instanceof ExtendedITypeReceiver extended)) return; + + if (mouseX > x && mouseX < x + width && mouseY > y && mouseY < y + height) { + if (labs$hovered != -1) { + extended.acceptIsInput(labs$hovered == 0); + ci.cancel(); + } + } + } + + /** + * Split across two functions. + *

+ * Must render before text. + * Text might not exist. + */ + @Inject(method = "render", + at = @At(value = "INVOKE", + target = "Lcom/projecturanus/betterp2p/client/gui/GuiAdvancedMemoryCard;drawHoveringText(Ljava/util/List;IILnet/minecraft/client/gui/FontRenderer;)V", + remap = true), + remap = false, + require = 1) + private void renderInputOutput1(GuiAdvancedMemoryCard gui, int mouseX, int mouseY, float partialTicks, + CallbackInfo ci) { + labs$draw(gui, mouseX, mouseY); + } + + @Inject(method = "render", at = @At("TAIL")) + private void renderInputOutput2(GuiAdvancedMemoryCard gui, int mouseX, int mouseY, float partialTicks, + CallbackInfo ci) { + if (hoveredIdx == -1) labs$draw(gui, mouseX, mouseY); + } + + /** + * Shared Logic Function. + */ + @Unique + private void labs$draw(GuiAdvancedMemoryCard gui, int mouseX, int mouseY) { + if (!(parent instanceof ExtendedITypeReceiver)) return; + + labs$hovered = -1; + int iconPosY = y + 4 + ((labs$this().getP2pTypes().size() / ICONS_PER_ROW) + 2) * 18; + + for (int i = 0; i < 2; i++) { + int iconPosX = x + 4 + (i * 18); + boolean iconHover = mouseX > iconPosX && mouseX < iconPosX + 18 && mouseY > iconPosY && + mouseY < iconPosY + 18; + + if (iconHover) { + GuiScreen.drawRect(iconPosX, iconPosY, iconPosX + 18, iconPosY + 18, 0xFF00FF00); + labs$hovered = i; + } + + // Reset Rendering Values + GlStateManager.enableBlend(); + GlStateManager.enableTexture2D(); + GlStateManager.enableAlpha(); + GlStateManager.color(1f, 1f, 1f, 1f); + OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); + labs$icons[i].draw(iconPosX + 1, iconPosY + 1, 18, 18); + } + + if (labs$hovered != -1) { + gui.drawHoveringText(labs$translated.get(labs$hovered), mouseX, mouseY, gui.mc.fontRenderer); + } + } + + @Unique + private WidgetTypeSelector labs$this() { + return (WidgetTypeSelector) (Object) this; + } +} diff --git a/src/main/java/com/nomiceu/nomilabs/mixin/draconicevolution/TileInvisECoreBlockMixin.java b/src/main/java/com/nomiceu/nomilabs/mixin/draconicevolution/TileInvisECoreBlockMixin.java index 1b4b7bf2..88e08567 100644 --- a/src/main/java/com/nomiceu/nomilabs/mixin/draconicevolution/TileInvisECoreBlockMixin.java +++ b/src/main/java/com/nomiceu/nomilabs/mixin/draconicevolution/TileInvisECoreBlockMixin.java @@ -20,29 +20,29 @@ public class TileInvisECoreBlockMixin implements TileInvisECoreBlockState { @Unique - boolean isDefault = true; + boolean labs$isDefault = true; @Unique - int metadata = 0; + int labs$metadata = 0; @Override - public boolean getDefault() { - return isDefault; + public boolean labs$getDefault() { + return labs$isDefault; } @Override - public void setIsDefault() { - this.isDefault = true; - this.metadata = 0; + public void labs$setIsDefault() { + this.labs$isDefault = true; + this.labs$metadata = 0; } - public int getMetadata() { - return metadata; + public int labs$getMetadata() { + return labs$metadata; } @Override - public void setMetadata(int metadata) { - this.metadata = metadata; - this.isDefault = false; + public void labs$setMetadata(int metadata) { + this.labs$metadata = metadata; + this.labs$isDefault = false; } @Inject(method = "revert", at = @At("HEAD"), cancellable = true) diff --git a/src/main/java/com/nomiceu/nomilabs/network/LabsNetworkHandler.java b/src/main/java/com/nomiceu/nomilabs/network/LabsNetworkHandler.java index 07846593..ce667fc8 100644 --- a/src/main/java/com/nomiceu/nomilabs/network/LabsNetworkHandler.java +++ b/src/main/java/com/nomiceu/nomilabs/network/LabsNetworkHandler.java @@ -12,25 +12,31 @@ public class LabsNetworkHandler { public static SimpleNetworkWrapper NETWORK_HANDLER; - private static int CURRENT_ID; public static void onConstruction() { NETWORK_HANDLER = new SimpleNetworkWrapper(LabsValues.LABS_MODID); } public static void preInit() { - CURRENT_ID = 0; - registerMessage(CanEditChunkDataMessage.MessageHandler.class, CanEditChunkDataMessage.class); - registerMessage(LabsDifficultyChangeMessage.MessageHandler.class, LabsDifficultyChangeMessage.class); + registerMessage(0, CanEditChunkDataMessage.MessageHandler.class, CanEditChunkDataMessage.class); + registerMessage(1, LabsDifficultyChangeMessage.MessageHandler.class, LabsDifficultyChangeMessage.class); + if (Loader.isModLoaded(LabsValues.AE2_MODID)) - registerMessage(LabsP2PCycleMessage.MessageHandler.class, LabsP2PCycleMessage.class); + registerMessage(2, LabsP2PCycleMessage.MessageHandler.class, LabsP2PCycleMessage.class); + + if (Loader.isModLoaded(LabsValues.BETTER_P2P_MODID)) { + registerMessage(3, LabsP2PChangeTypeMessage.MessageHandler.class, LabsP2PChangeTypeMessage.class); + registerMessage(4, LabsP2PAddAsInputMessage.MessageHandler.class, LabsP2PAddAsInputMessage.class); + registerMessage(5, LabsP2PAddAsOutputMessage.MessageHandler.class, LabsP2PAddAsOutputMessage.class); + } } @SuppressWarnings("SameParameterValue") private static void registerMessage(Class> messageHandler, + REPLY extends IMessage> void registerMessage(int id, + Class> messageHandler, Class requestMessageType) { - NETWORK_HANDLER.registerMessage(messageHandler, requestMessageType, CURRENT_ID++, Side.CLIENT); - NETWORK_HANDLER.registerMessage(messageHandler, requestMessageType, CURRENT_ID++, Side.SERVER); + NETWORK_HANDLER.registerMessage(messageHandler, requestMessageType, id, Side.CLIENT); + NETWORK_HANDLER.registerMessage(messageHandler, requestMessageType, id, Side.SERVER); } } diff --git a/src/main/java/com/nomiceu/nomilabs/network/LabsP2PAddAsInputMessage.java b/src/main/java/com/nomiceu/nomilabs/network/LabsP2PAddAsInputMessage.java new file mode 100644 index 00000000..e4b1543a --- /dev/null +++ b/src/main/java/com/nomiceu/nomilabs/network/LabsP2PAddAsInputMessage.java @@ -0,0 +1,60 @@ +package com.nomiceu.nomilabs.network; + +import net.minecraftforge.fml.common.network.simpleimpl.IMessage; +import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; +import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; + +import com.nomiceu.nomilabs.integration.betterp2p.AccessibleGridServerCache; +import com.projecturanus.betterp2p.network.ModNetwork; +import com.projecturanus.betterp2p.network.PlayerRequest; +import com.projecturanus.betterp2p.network.data.P2PLocation; +import com.projecturanus.betterp2p.network.data.P2PLocationKt; + +import io.netty.buffer.ByteBuf; + +public class LabsP2PAddAsInputMessage implements IMessage { + + private P2PLocation location; + private short sourceFrequency; + + public LabsP2PAddAsInputMessage() { + location = null; + sourceFrequency = 0; + } + + public LabsP2PAddAsInputMessage(P2PLocation location, short sourceFrequency) { + this.location = location; + this.sourceFrequency = sourceFrequency; + } + + @Override + public void fromBytes(ByteBuf buf) { + location = P2PLocationKt.readP2PLocation(buf); + sourceFrequency = buf.readShort(); + } + + @Override + public void toBytes(ByteBuf buf) { + P2PLocationKt.writeP2PLocation(buf, location); + buf.writeShort(sourceFrequency); + } + + public static class MessageHandler implements IMessageHandler { + + @Override + public IMessage onMessage(LabsP2PAddAsInputMessage message, MessageContext ctx) { + if (!ctx.side.isServer()) return null; + + PlayerRequest state = ModNetwork.INSTANCE.getPlayerState().get(ctx.getServerHandler().player.getUniqueID()); + if (state == null) return null; + + boolean result = ((AccessibleGridServerCache) (Object) state.getGridCache()) + .labs$addInput(message.location, message.sourceFrequency); + + if (result) { + ModNetwork.INSTANCE.requestP2PUpdate(ctx.getServerHandler().player); + } + return null; + } + } +} diff --git a/src/main/java/com/nomiceu/nomilabs/network/LabsP2PAddAsOutputMessage.java b/src/main/java/com/nomiceu/nomilabs/network/LabsP2PAddAsOutputMessage.java new file mode 100644 index 00000000..d10fd74e --- /dev/null +++ b/src/main/java/com/nomiceu/nomilabs/network/LabsP2PAddAsOutputMessage.java @@ -0,0 +1,60 @@ +package com.nomiceu.nomilabs.network; + +import net.minecraftforge.fml.common.network.simpleimpl.IMessage; +import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; +import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; + +import com.nomiceu.nomilabs.integration.betterp2p.AccessibleGridServerCache; +import com.projecturanus.betterp2p.network.ModNetwork; +import com.projecturanus.betterp2p.network.PlayerRequest; +import com.projecturanus.betterp2p.network.data.P2PLocation; +import com.projecturanus.betterp2p.network.data.P2PLocationKt; + +import io.netty.buffer.ByteBuf; + +public class LabsP2PAddAsOutputMessage implements IMessage { + + private P2PLocation location; + private short sourceFrequency; + + public LabsP2PAddAsOutputMessage() { + location = null; + sourceFrequency = 0; + } + + public LabsP2PAddAsOutputMessage(P2PLocation location, short sourceFrequency) { + this.location = location; + this.sourceFrequency = sourceFrequency; + } + + @Override + public void fromBytes(ByteBuf buf) { + location = P2PLocationKt.readP2PLocation(buf); + sourceFrequency = buf.readShort(); + } + + @Override + public void toBytes(ByteBuf buf) { + P2PLocationKt.writeP2PLocation(buf, location); + buf.writeShort(sourceFrequency); + } + + public static class MessageHandler implements IMessageHandler { + + @Override + public IMessage onMessage(LabsP2PAddAsOutputMessage message, MessageContext ctx) { + if (!ctx.side.isServer()) return null; + + PlayerRequest state = ModNetwork.INSTANCE.getPlayerState().get(ctx.getServerHandler().player.getUniqueID()); + if (state == null) return null; + + boolean result = ((AccessibleGridServerCache) (Object) state.getGridCache()) + .labs$addOutput(message.location, message.sourceFrequency); + + if (result) { + ModNetwork.INSTANCE.requestP2PUpdate(ctx.getServerHandler().player); + } + return null; + } + } +} diff --git a/src/main/java/com/nomiceu/nomilabs/network/LabsP2PChangeTypeMessage.java b/src/main/java/com/nomiceu/nomilabs/network/LabsP2PChangeTypeMessage.java new file mode 100644 index 00000000..48fc9349 --- /dev/null +++ b/src/main/java/com/nomiceu/nomilabs/network/LabsP2PChangeTypeMessage.java @@ -0,0 +1,61 @@ +package com.nomiceu.nomilabs.network; + +import net.minecraftforge.fml.common.network.simpleimpl.IMessage; +import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; +import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; + +import com.nomiceu.nomilabs.integration.betterp2p.AccessibleGridServerCache; +import com.projecturanus.betterp2p.network.ModNetwork; +import com.projecturanus.betterp2p.network.PlayerRequest; +import com.projecturanus.betterp2p.network.data.P2PLocation; +import com.projecturanus.betterp2p.network.data.P2PLocationKt; + +import appeng.parts.p2p.PartP2PTunnel; +import io.netty.buffer.ByteBuf; + +public class LabsP2PChangeTypeMessage implements IMessage { + + private P2PLocation location; + private boolean isInput; + + public LabsP2PChangeTypeMessage() { + location = null; + isInput = true; + } + + public LabsP2PChangeTypeMessage(P2PLocation location, boolean isInput) { + this.location = location; + this.isInput = isInput; + } + + @Override + public void fromBytes(ByteBuf buf) { + location = P2PLocationKt.readP2PLocation(buf); + isInput = buf.readBoolean(); + } + + @Override + public void toBytes(ByteBuf buf) { + P2PLocationKt.writeP2PLocation(buf, location); + buf.writeBoolean(isInput); + } + + public static class MessageHandler implements IMessageHandler { + + @Override + public IMessage onMessage(LabsP2PChangeTypeMessage message, MessageContext ctx) { + if (!ctx.side.isServer()) return null; + + PlayerRequest state = ModNetwork.INSTANCE.getPlayerState().get(ctx.getServerHandler().player.getUniqueID()); + if (state == null) return null; + + PartP2PTunnel result = ((AccessibleGridServerCache) (Object) state.getGridCache()) + .labs$changeIsInput(message.location, message.isInput); + + if (result != null) { + ModNetwork.INSTANCE.requestP2PUpdate(ctx.getServerHandler().player); + } + return null; + } + } +} diff --git a/src/main/resources/assets/nomilabs/lang/en_us.lang b/src/main/resources/assets/nomilabs/lang/en_us.lang index 3c32d8f9..4bad832e 100644 --- a/src/main/resources/assets/nomilabs/lang/en_us.lang +++ b/src/main/resources/assets/nomilabs/lang/en_us.lang @@ -143,6 +143,18 @@ nomilabs.gui.language_jei.desc.2=However, Reloading JEI will take a §ccouple se nomilabs.gui.top_override.fluid=Fluid: %s +nomilabs.gui.better_p2p.input=Input +nomilabs.gui.better_p2p.output=Output +nomilabs.gui.better_p2p.error.same_output=P2P is already an {}. + +nomilabs.gui.advanced_memory_card.mode.add_input=Add as Input +nomilabs.gui.advanced_memory_card.mode.add_input.desc.1=Before binding, the §aselected P2P§7 has its connections removed. +nomilabs.gui.advanced_memory_card.mode.add_input.desc.2=The §aselected P2P§7 is set as an §9input§7, with the §bbind target§a's frequency. + +nomilabs.gui.advanced_memory_card.mode.add_output=Add as Output +nomilabs.gui.advanced_memory_card.mode.add_output.desc.1=Before binding, the §aselected P2P§7 has its connections removed. +nomilabs.gui.advanced_memory_card.mode.add_output.desc.2=The §aselected P2P§7 is set as an §6output§7, with the §bbind target§a's frequency. + # Custom Fluids fluid.uranium233=Uranium 233 fluid.plutonium2=Plutonium diff --git a/src/main/resources/assets/nomilabs/textures/gui/advanced_memory_card/custom_modes.png b/src/main/resources/assets/nomilabs/textures/gui/advanced_memory_card/custom_modes.png new file mode 100644 index 00000000..f58d9f6e Binary files /dev/null and b/src/main/resources/assets/nomilabs/textures/gui/advanced_memory_card/custom_modes.png differ diff --git a/src/main/resources/assets/nomilabs/textures/gui/advanced_memory_card/input.png b/src/main/resources/assets/nomilabs/textures/gui/advanced_memory_card/input.png new file mode 100644 index 00000000..39e3ffc5 Binary files /dev/null and b/src/main/resources/assets/nomilabs/textures/gui/advanced_memory_card/input.png differ diff --git a/src/main/resources/assets/nomilabs/textures/gui/advanced_memory_card/output.png b/src/main/resources/assets/nomilabs/textures/gui/advanced_memory_card/output.png new file mode 100644 index 00000000..12ac5396 Binary files /dev/null and b/src/main/resources/assets/nomilabs/textures/gui/advanced_memory_card/output.png differ diff --git a/src/main/resources/mixins.nomilabs.betterp2p.json b/src/main/resources/mixins.nomilabs.betterp2p.json new file mode 100644 index 00000000..b65db0f5 --- /dev/null +++ b/src/main/resources/mixins.nomilabs.betterp2p.json @@ -0,0 +1,22 @@ +{ + "package": "com.nomiceu.nomilabs.mixin.betterp2p", + "refmap": "mixins.nomilabs.refmap.json", + "target": "@env(DEFAULT)", + "minVersion": "0.8", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "CommonProxyMixin", + "GridServerCacheMixin", + "ServerRenameP2PTunnelMixin" + ], + "client": [ + "ClientProxyMixin", + "GuiAdvancedMemoryCardKtAccessor", + "GuiAdvancedMemoryCardMixin", + "ModeWidgetButtonMixin", + "WidgetP2PColumnMixin", + "WidgetP2PDeviceMixin", + "WidgetTypeSelectorMixin" + ], + "server": [] +}