From d125453c4a1bf94111b5756c7236b6b755c8fb71 Mon Sep 17 00:00:00 2001 From: IntegerLimit <103940576+IntegerLimit@users.noreply.github.com> Date: Fri, 12 Jan 2024 14:15:02 +1100 Subject: [PATCH] Draconic Evolution Energy Core & Pylon Improvements and Fixes Log Improvements Localise 'Error at' messages Improve Energy Pylon Validation and Update Logic --- dependencies.gradle | 4 +- .../BlockStateEnergyCoreStructure.java | 29 ++++--------- .../BlockStateMultiblockStorage.java | 24 ++--------- .../draconicevolution/BlockStates.java | 24 +++++++---- .../draconicevolution/DraconicHelpers.java | 4 +- .../EnergyCoreBuilderLogic.java | 5 ++- .../draconicevolution/GuiEnergyCoreLogic.java | 4 +- .../ImprovedTileEnergyCore.java | 11 +++++ .../TileEnergyStorageCoreLogic.java | 11 +++-- .../draconicevolution/EnergyPylonMixin.java | 31 ++++++++++++++ .../draconicevolution/GuiEnergyCoreMixin.java | 5 +++ .../TileEnergyStorageCoreMixin.java | 42 +++++++++++++++++++ .../assets/draconicevolution/lang/en_us.lang | 4 +- .../mixins.nomilabs.draconicevolution.json | 1 + 14 files changed, 138 insertions(+), 61 deletions(-) create mode 100644 src/main/java/com/nomiceu/nomilabs/mixin/draconicevolution/EnergyPylonMixin.java diff --git a/dependencies.gradle b/dependencies.gradle index 102aa10b..8f88b414 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -84,12 +84,12 @@ dependencies { // Solar Flux Reborn, need to be patched for Cleanroom compatibility (from CurseForge) compileOnly rfg.deobf("curse.maven:solar-flux-reborn-246974:3050838") // Version 12.4.11 - // Brandon Core, Runtime and Compile Dep of Draconic Evolution (from CurseForge) + // Brandon Core & Redstone Flux, Runtime and Compile Dep of Draconic Evolution (from CurseForge) compileOnly rfg.deobf("curse.maven:brandons-core-231382:3408276") // Version 2.4.20 + compileOnly rfg.deobf("curse.maven:redstone-flux-270789:2920436") // Version 2.1.1.1 /* -------------------------------- Soft Deps, Multiple Runtime Declaration -------------------------------- */ if (project.enable_draconic.toBoolean() || project.enable_thermal.toBoolean()) { - // Redstone Flux, runtime only dep for Draconic Evolution (from CurseForge) runtimeOnly "curse.maven:redstone-flux-270789:2920436" // Version 2.1.1.1 } 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 9919ae2b..c9e7bec2 100644 --- a/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/BlockStateEnergyCoreStructure.java +++ b/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/BlockStateEnergyCoreStructure.java @@ -83,7 +83,7 @@ public boolean checkTier(int tier) { return false; } if (tier > 8) { - NomiLabs.LOGGER.error("[EnergyCoreStructure#checkTeir] What exactly were you expecting after Tier 8? Infinity.MAX_VALUE?"); + NomiLabs.LOGGER.error("[EnergyCoreStructure] What exactly were you expecting after Tier 8? Infinity.MAX_VALUE?"); return false; } @@ -99,7 +99,7 @@ public void placeTier(int tier) { return; } if (tier > 8) { - NomiLabs.LOGGER.error("[EnergyCoreStructure#checkTeir] What exactly were you expecting after Tier 8? Infinity.MAX_VALUE?"); + NomiLabs.LOGGER.error("[EnergyCoreStructure] What exactly were you expecting after Tier 8? Infinity.MAX_VALUE?"); return; } structureTiers[tier - 1].placeStructure(core.getWorld(), core.getPos().add(offset)); @@ -165,10 +165,10 @@ else if (flag == FLAG_FORME) { if (tile instanceof TileInvisECoreBlock invis) { invis.blockName = Objects.requireNonNull(states.getDefault().getBlock().getRegistryName()).toString(); TileInvisECoreBlockState invisState = (TileInvisECoreBlockState) invis; - if (states.getDefault().equals(states.getDefault().getBlock().getDefaultState())){ + if (BlockStates.statesEqual(states.getDefault(), states.getDefault().getBlock().getDefaultState())){ invisState.setIsDefault(); } - else{ + else { invisState.setMetadata(states.getDefault().getBlock().getMetaFromState(states.getDefault())); } invis.setController(core); @@ -273,25 +273,14 @@ public boolean checkBlock(BlockStates states, World world, BlockPos pos) { if (tile instanceof TileInvisECoreBlock invis){ if (invis.blockName.equals(Objects.requireNonNull(states.getDefault().getBlock().getRegistryName()).toString())) { TileInvisECoreBlockState invisState = (TileInvisECoreBlockState) invis; - if (invisState.getDefault()){ - if (states.getDefault().equals(states.getDefault().getBlock().getDefaultState())) + if (invisState.getDefault()) { + if (BlockStates.statesEqual(states.getDefault(), states.getDefault().getBlock().getDefaultState())) return true; - - return helper.checkBlock(states, world, pos); - } - else { - if (states.getDefault().getBlock().getMetaFromState(states.getDefault()) == invisState.getMetadata()) + } else if (states.getDefault().getBlock().getMetaFromState(states.getDefault()) == invisState.getMetadata()) return true; - - return helper.checkBlock(states, world, pos); - } - } else - return helper.checkBlock(states, world, pos); - - } - else { - return helper.checkBlock(states, world, pos); + } } + return helper.checkBlock(states, world, pos); } public BlockPos getCoreOffset(int tier) { diff --git a/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/BlockStateMultiblockStorage.java b/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/BlockStateMultiblockStorage.java index ea40912a..b0720bca 100644 --- a/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/BlockStateMultiblockStorage.java +++ b/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/BlockStateMultiblockStorage.java @@ -41,7 +41,7 @@ public void addRow(BlockStates... zRow) { */ public void mirrorLayers(int minY, int maxY) { if (yPos < maxY) { - throw new IllegalArgumentException("[MultiBlockStorage] Cannot mirror from minY " + minY + "to maxY" + maxY + "as have not reached maxY yet!"); + throw new IllegalArgumentException("[MultiBlockStorage] Cannot mirror from minY " + minY + " to maxY " + maxY + " as have not reached maxY yet!"); } // Loop from last to first (mirror), excluding maxY, including minY for (int y = maxY - 1; y >= minY; y--) { @@ -93,30 +93,12 @@ public boolean checkStructure(World world, BlockPos startPos) { @Override public void placeStructure(World world, BlockPos startPos) { - for (int x = 0; x < size; x++) { - for (int y = 0; y < size; y++) { - for (int z = 0; z < size; z++) { - if (structure[x][y][z].isWildcard()) - continue; - BlockPos pos = new BlockPos(x, y, z); - energyCoreStructure.setBlock(structure[x][y][z], world, pos.add(startPos)); - } - } - } + forEachBlockStates(startPos, (pos, states) -> energyCoreStructure.setBlock(states, world, pos)); } @Override public void forEachInStructure(World world, BlockPos startPos, int flag) { - for (int x = 0; x < size; x++) { - for (int y = 0; y < size; y++) { - for (int z = 0; z < size; z++) { - if (!structure[x][y][z].isWildcard()) { - BlockPos pos = new BlockPos(x, y, z); - energyCoreStructure.forBlock(structure[x][y][z], world, pos.add(startPos), startPos, flag); - } - } - } - } + forEachBlockStates(startPos, (pos, states) -> energyCoreStructure.forBlock(states, world, pos, startPos, flag)); } public void forEachBlockStates(BlockPos startPos, BiConsumer consumer) { diff --git a/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/BlockStates.java b/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/BlockStates.java index a6c813c5..4eeb72d2 100644 --- a/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/BlockStates.java +++ b/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/BlockStates.java @@ -6,6 +6,7 @@ import net.minecraft.item.ItemStack; import java.util.Arrays; +import java.util.Objects; /** * Class allowing matching multiple block states. @@ -68,13 +69,6 @@ public boolean isWildcard() { return wildcard; } - @SuppressWarnings("deprecation") - public static IBlockState transformStackToState(ItemStack stack) { - if (!(stack.getItem() instanceof ItemBlock block)) - throw new IllegalArgumentException("[LabsDraconicEvolution] Stack's Item must extend ItemBlock!"); - return block.getBlock().getStateFromMeta(stack.getMetadata()); - } - /** * Returns an itemstack list, with the first item being the default, and then the substitutes. * Returns empty list if wildcard. @@ -88,14 +82,26 @@ public ItemStack[] transformToStack() { return stacks; } - public ItemStack transformStateToStack(IBlockState state) { + public static ItemStack transformStateToStack(IBlockState state) { return new ItemStack(state.getBlock(), 1, state.getBlock().getMetaFromState(state)); } + @SuppressWarnings("deprecation") + public static IBlockState transformStackToState(ItemStack stack) { + if (!(stack.getItem() instanceof ItemBlock block)) + throw new IllegalArgumentException("[LabsDraconicEvolution] Stack's Item must extend ItemBlock!"); + return block.getBlock().getStateFromMeta(stack.getMetadata()); + } + @Override public boolean equals(Object obj) { if (!(obj instanceof BlockStates states)) return false; - return (states.isWildcard() && this.isWildcard()) || (states.getDefault().equals(this.getDefault())); + return (states.isWildcard() && this.isWildcard()) || statesEqual(states.getDefault(), this.getDefault()); + } + + public static boolean statesEqual(IBlockState a, IBlockState b) { + return Objects.equals(a.getBlock().getRegistryName(), b.getBlock().getRegistryName()) + && a.getBlock().getMetaFromState(a) == b.getBlock().getMetaFromState(b); } } diff --git a/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/DraconicHelpers.java b/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/DraconicHelpers.java index be765a4a..6c5d6d69 100644 --- a/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/DraconicHelpers.java +++ b/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/DraconicHelpers.java @@ -174,11 +174,11 @@ public static boolean validState(BlockStates allowedStates, IBlockState state, b return true; } - if (allowedStates.getDefault().equals(state)) return true; + if (BlockStates.statesEqual(allowedStates.getDefault(), state)) return true; if (!allowedStates.hasSubstitutes()) return false; for (var substitute : allowedStates.getSubstitutes()) { - if (substitute.equals(state)) return true; + if (BlockStates.statesEqual(substitute, state)) return true; } return false; } diff --git a/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/EnergyCoreBuilderLogic.java b/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/EnergyCoreBuilderLogic.java index 7122a76e..7b6925d6 100644 --- a/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/EnergyCoreBuilderLogic.java +++ b/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/EnergyCoreBuilderLogic.java @@ -1,9 +1,11 @@ package com.nomiceu.nomilabs.integration.draconicevolution; import com.brandon3055.draconicevolution.blocks.tileentity.TileEnergyStorageCore; +import com.nomiceu.nomilabs.NomiLabs; import com.nomiceu.nomilabs.config.LabsConfig; import net.minecraft.block.SoundType; import net.minecraft.block.state.IBlockState; +import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.SoundCategory; @@ -49,7 +51,8 @@ private static boolean buildWorklist(TileEnergyStorageCore core, EntityPlayer pl } IBlockState state = world.getBlockState(key); if (!DraconicHelpers.validState(neededStates, state, false)) { - player.sendMessage(new TextComponentTranslation("ecore.de.assemble_found_invalid.txt", state.getBlock().getLocalizedName(), key.toString()).setStyle(new Style().setColor(TextFormatting.RED))); + player.sendMessage(new TextComponentTranslation("ecore.de.assemble_found_invalid.txt", + BlockStates.transformStateToStack(state).getDisplayName(), key.toString()).setStyle(new Style().setColor(TextFormatting.RED))); return true; } } diff --git a/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/GuiEnergyCoreLogic.java b/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/GuiEnergyCoreLogic.java index cea18076..2fbc5032 100644 --- a/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/GuiEnergyCoreLogic.java +++ b/src/main/java/com/nomiceu/nomilabs/integration/draconicevolution/GuiEnergyCoreLogic.java @@ -26,6 +26,7 @@ public static GuiButton addDestructButtonToList(GuiContainer gui, List + * Prevents instances when replacing of glass is needed. + */ +@Mixin(value = EnergyPylon.class, remap = false) +public abstract class EnergyPylonMixin extends BlockBCore { + @Override + @Unique + public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { + super.onBlockPlacedBy(world, pos, state, placer, stack); + if (world.getTileEntity(pos) instanceof TileEnergyPylon tile) { + NomiLabs.LOGGER.info("Success!"); + tile.validateStructure(); + } else NomiLabs.LOGGER.info("Fail!"); + } +} diff --git a/src/main/java/com/nomiceu/nomilabs/mixin/draconicevolution/GuiEnergyCoreMixin.java b/src/main/java/com/nomiceu/nomilabs/mixin/draconicevolution/GuiEnergyCoreMixin.java index e34fd5db..394ce982 100644 --- a/src/main/java/com/nomiceu/nomilabs/mixin/draconicevolution/GuiEnergyCoreMixin.java +++ b/src/main/java/com/nomiceu/nomilabs/mixin/draconicevolution/GuiEnergyCoreMixin.java @@ -36,6 +36,9 @@ public abstract class GuiEnergyCoreMixin extends GuiContainer { @Shadow private GuiButton assembleCore; + @Shadow + private GuiButton activate; + @Unique private GuiButton destructCore; @@ -73,6 +76,8 @@ private void updateButtonStates(CallbackInfo ci) { destructCore.visible = (guiCore.tile.coreValid.value || improvedTile.hasActiveDestructor()) && !guiCore.tile.active.value && guiCore.tile.tier.value != 1; toggleGuide.enabled = guiCore.tile.tier.value != 1; + activate.enabled = guiCore.tile.coreValid.value && guiCore.tile.stabilizersOK.value; + assembleCore.enabled = !improvedTile.hasActiveDestructor(); if (DraconicHelpers.instantBuilder()) assembleCore.displayString = I18n.format("button.de.assembleCore.instant.txt"); diff --git a/src/main/java/com/nomiceu/nomilabs/mixin/draconicevolution/TileEnergyStorageCoreMixin.java b/src/main/java/com/nomiceu/nomilabs/mixin/draconicevolution/TileEnergyStorageCoreMixin.java index a874feef..3056cb10 100644 --- a/src/main/java/com/nomiceu/nomilabs/mixin/draconicevolution/TileEnergyStorageCoreMixin.java +++ b/src/main/java/com/nomiceu/nomilabs/mixin/draconicevolution/TileEnergyStorageCoreMixin.java @@ -2,7 +2,11 @@ import codechicken.lib.data.MCDataInput; import com.brandon3055.brandonscore.blocks.TileBCBase; +import com.brandon3055.brandonscore.lib.Vec3I; import com.brandon3055.brandonscore.lib.datamanager.ManagedBool; +import com.brandon3055.brandonscore.lib.datamanager.ManagedString; +import com.brandon3055.brandonscore.lib.datamanager.ManagedVec3D; +import com.brandon3055.brandonscore.lib.datamanager.ManagedVec3I; import com.brandon3055.draconicevolution.blocks.tileentity.TileEnergyStorageCore; import com.brandon3055.draconicevolution.lib.EnergyCoreBuilder; import com.nomiceu.nomilabs.integration.draconicevolution.EnergyCoreDestructor; @@ -12,6 +16,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.util.ITickable; +import net.minecraft.util.math.BlockPos; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; @@ -28,6 +33,11 @@ public abstract class TileEnergyStorageCoreMixin extends TileBCBase implements I @Unique private static final String ACTIVE_DESTRUCTOR = "activeDestructor"; + @Unique + private static final String EXPECTED_STRING = "expectedBlock"; + @Unique + private static final String EXPECTED_POS = "expectedPos"; + @Shadow protected abstract long getCapacity(); @@ -46,10 +56,18 @@ public abstract class TileEnergyStorageCoreMixin extends TileBCBase implements I @Unique public ManagedBool hasActiveDestructor; + @Unique + public ManagedString expectedBlockString; + + @Unique + public ManagedVec3I expectedBlockPos; + @Inject(method = "", at = @At("TAIL")) public void initFields(CallbackInfo ci) { hasActiveBuilder = register(ACTIVE_BUILDER, new ManagedBool(false)).syncViaTile().saveToTile().trigerUpdate().finish(); hasActiveDestructor = register(ACTIVE_DESTRUCTOR, new ManagedBool(false)).syncViaTile().saveToTile().trigerUpdate().finish(); + expectedBlockString = register(EXPECTED_STRING, new ManagedString("")).syncViaTile().saveToTile().trigerUpdate().finish(); + expectedBlockPos = register(EXPECTED_POS, new ManagedVec3I(new Vec3I(0, 0, 0))).syncViaTile().saveToTile().trigerUpdate().finish(); } @Inject(method = "activateCore", at = @At("HEAD"), cancellable = true) @@ -231,4 +249,28 @@ public void onLoad() { hasActiveBuilder.value = activeBuilder != null; hasActiveDestructor.value = activeDestructor != null; } + + @Override + @Unique + public void setExpectedBlockString(String string) { + expectedBlockString.value = string; + } + + @Override + @Unique + public void setExpectedBlockPos(BlockPos pos) { + expectedBlockPos.vec = new Vec3I(pos); + } + + @Override + @Unique + public String getExpectedBlockString() { + return expectedBlockString.value; + } + + @Override + @Unique + public Vec3I getExpectedBlockPos() { + return expectedBlockPos.vec; + } } diff --git a/src/main/resources/assets/draconicevolution/lang/en_us.lang b/src/main/resources/assets/draconicevolution/lang/en_us.lang index 3df3bef6..3cfe0f9a 100644 --- a/src/main/resources/assets/draconicevolution/lang/en_us.lang +++ b/src/main/resources/assets/draconicevolution/lang/en_us.lang @@ -5,4 +5,6 @@ button.de.destructCore.stop.txt=Stop Disassembling Core button.de.assembleCore.start.txt=Start Assembling Core button.de.assembleCore.instant.txt=Assemble Core button.de.assembleCore.stop.txt=Stop Assembling Core -ecore.de.assemble_missing_required_new.txt=Unable to complete structure! Missing required block(s): %s. \ No newline at end of file +ecore.de.assemble_missing_required_new.txt=Unable to complete structure! Missing required block(s): %s. + +ecore.gui.invalid_block.txt=Invalid Block: X: %s, Y: %s, Z: %s. Expected: %s. \ No newline at end of file diff --git a/src/main/resources/mixins.nomilabs.draconicevolution.json b/src/main/resources/mixins.nomilabs.draconicevolution.json index 50879d93..b3b97efc 100644 --- a/src/main/resources/mixins.nomilabs.draconicevolution.json +++ b/src/main/resources/mixins.nomilabs.draconicevolution.json @@ -7,6 +7,7 @@ "mixins": [ "EnergyCoreBuilderMixin", "EnergyCoreStructureMixin", + "EnergyPylonMixin", "InvisECoreBlockMixin", "ReactorIntegration", "ReactorSlotIntegration",