Skip to content

Commit

Permalink
Draconic Evolution Energy Core & Pylon Improvements and Fixes
Browse files Browse the repository at this point in the history
Log Improvements
Localise 'Error at'  messages
Improve Energy Pylon Validation and Update Logic
  • Loading branch information
IntegerLimit committed Jan 12, 2024
1 parent ca73b12 commit d125453
Show file tree
Hide file tree
Showing 14 changed files with 138 additions and 61 deletions.
4 changes: 2 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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--) {
Expand Down Expand Up @@ -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<BlockPos, BlockStates> consumer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.item.ItemStack;

import java.util.Arrays;
import java.util.Objects;

/**
* Class allowing matching multiple block states.
Expand Down Expand Up @@ -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.
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static GuiButton addDestructButtonToList(GuiContainer gui, List<GuiButton
* Changes the wrap text parameters of the invalid message.
*/
public static void drawBackground(GuiEnergyCore gui, FontRenderer fontRenderer) {
var improvedTile = (ImprovedTileEnergyCore) gui.tile;
GuiHelper.drawGuiBaseBackground(gui, gui.guiLeft, gui.guiTop, gui.xSize, gui.ySize);
GuiHelper.drawPlayerSlots(gui, gui.guiLeft + (gui.xSize / 2), gui.guiTop + 115 + 10, true);
gui.drawCenteredString(fontRenderer, I18n.format("gui.de.energyStorageCore.name", gui.tile.tier.toString()),
Expand All @@ -41,7 +42,8 @@ public static void drawBackground(GuiEnergyCore gui, FontRenderer fontRenderer)
String coreText = I18n.format("gui.de.core.txt") + ": " + (gui.tile.coreValid.value ? I18n.format("gui.de.valid.txt") : I18n.format("gui.de.invalid.txt"));
GuiHelper.drawCenteredString(fontRenderer, coreText, gui.guiLeft + gui.xSize / 2, gui.guiTop + 36, coreColour, gui.tile.coreValid.value);
if (!gui.tile.coreValid.value) {
GuiHelper.drawCenteredSplitString(fontRenderer, gui.tile.invalidMessage.value, gui.guiLeft + gui.xSize / 2, gui.guiTop + 46, 150, coreColour, false);
var pos = improvedTile.getExpectedBlockPos();
GuiHelper.drawCenteredSplitString(fontRenderer, I18n.format("ecore.gui.invalid_block.txt", pos.x, pos.y, pos.z, improvedTile.getExpectedBlockString()), gui.guiLeft + gui.xSize / 2, gui.guiTop + 46, 150, coreColour, false);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.nomiceu.nomilabs.integration.draconicevolution;

import com.brandon3055.brandonscore.lib.Vec3I;
import net.minecraft.util.math.BlockPos;

public interface ImprovedTileEnergyCore {
/**
* @return True if the core has an active builder, false otherwise.
Expand All @@ -10,4 +13,12 @@ public interface ImprovedTileEnergyCore {
* @return True if the core has an active destructor, false otherwise.
*/
boolean hasActiveDestructor();

void setExpectedBlockString(String string);

void setExpectedBlockPos(BlockPos pos);

String getExpectedBlockString();

Vec3I getExpectedBlockPos();
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ public static void deactivateCore(TileEnergyStorageCore tile) {
public static boolean validateStructure(TileEnergyStorageCore tile) {
boolean valid = tile.checkStabilizers();
var helper = ((BlockStateEnergyCoreStructure) tile.coreStructure).getHelper();
var improvedTile = (ImprovedTileEnergyCore) tile;
if (!(tile.coreValid.value = tile.coreStructure.checkTier(tile.tier.value))) {
BlockPos pos = helper.invalidBlock;
String expectedString = helper.expectedBlockState == null

improvedTile.setExpectedBlockString(helper.expectedBlockState == null
? "null"
: new ItemStack(helper.expectedBlockState.getBlock(), 1,
helper.expectedBlockState.getBlock().getMetaFromState(helper.expectedBlockState)).getDisplayName();
tile.invalidMessage.value = "Error At: x:" + pos.getX() + ", y:" + pos.getY() + ", z:" + pos.getZ() + " Expected: " + expectedString;
helper.expectedBlockState.getBlock().getMetaFromState(helper.expectedBlockState)).getDisplayName());

improvedTile.setExpectedBlockPos(pos);
valid = false;
}

Expand All @@ -46,7 +49,7 @@ public static boolean validateStructure(TileEnergyStorageCore tile) {

tile.structureValid.value = valid;
if (valid) {
tile.invalidMessage.value = "";
improvedTile.setExpectedBlockString("");
}

return valid;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.nomiceu.nomilabs.mixin.draconicevolution;

import com.brandon3055.brandonscore.blocks.BlockBCore;
import com.brandon3055.draconicevolution.blocks.machines.EnergyPylon;
import com.brandon3055.draconicevolution.blocks.tileentity.TileEnergyPylon;
import com.nomiceu.nomilabs.NomiLabs;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;

/**
* Checks if the pylon is valid on place, instead of after block update.
* <br>
* 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!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public abstract class GuiEnergyCoreMixin extends GuiContainer {
@Shadow
private GuiButton assembleCore;

@Shadow
private GuiButton activate;

@Unique
private GuiButton destructCore;

Expand Down Expand Up @@ -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");
Expand Down
Loading

0 comments on commit d125453

Please sign in to comment.