Deduplicate multiblock verification from BlockEntities and Guis (#2133)

* Deduplicate multiblock verification from BlockEntities and Guis

* Update REI

* Remove unneeded calls
This commit is contained in:
ramidzkh 2020-07-09 22:45:04 +10:00 committed by GitHub
parent c89d6941ae
commit 4b2042a100
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 275 additions and 939 deletions

View file

@ -62,7 +62,7 @@ public class FluidReplicatorRecipe extends RebornFluidRecipe {
@Override @Override
public boolean canCraft(BlockEntity be) { public boolean canCraft(BlockEntity be) {
FluidReplicatorBlockEntity blockEntity = (FluidReplicatorBlockEntity) be; FluidReplicatorBlockEntity blockEntity = (FluidReplicatorBlockEntity) be;
if (!blockEntity.getMultiBlock()) { if (!blockEntity.isMultiblockValid()) {
return false; return false;
} }
final BlockPos hole = blockEntity.getPos().offset(blockEntity.getFacing().getOpposite(), 2); final BlockPos hole = blockEntity.getPos().offset(blockEntity.getFacing().getOpposite(), 2);

View file

@ -58,7 +58,7 @@ public class IndustrialGrinderRecipe extends RebornFluidRecipe {
@Override @Override
public boolean canCraft(BlockEntity be) { public boolean canCraft(BlockEntity be) {
IndustrialGrinderBlockEntity blockEntity = (IndustrialGrinderBlockEntity) be; IndustrialGrinderBlockEntity blockEntity = (IndustrialGrinderBlockEntity) be;
if (!blockEntity.getMultiBlock()) { if (!blockEntity.isMultiblockValid()) {
return false; return false;
} }
return super.canCraft(be); return super.canCraft(be);

View file

@ -58,7 +58,7 @@ public class IndustrialSawmillRecipe extends RebornFluidRecipe {
@Override @Override
public boolean canCraft(BlockEntity be) { public boolean canCraft(BlockEntity be) {
IndustrialSawmillBlockEntity blockEntity = (IndustrialSawmillBlockEntity) be; IndustrialSawmillBlockEntity blockEntity = (IndustrialSawmillBlockEntity) be;
if (!blockEntity.getMutliBlock()) { if (!blockEntity.isMultiblockValid()) {
return false; return false;
} }
return super.canCraft(be); return super.canCraft(be);

View file

@ -79,7 +79,7 @@ public abstract class GenericMachineBlockEntity extends PowerAcceptorBlockEntity
@Override @Override
public void tick() { public void tick() {
super.tick(); super.tick();
if (!world.isClient) { if (!world.isClient && energySlot != -1) {
charge(energySlot); charge(energySlot);
} }
} }

View file

@ -24,12 +24,12 @@
package techreborn.blockentity.machine.multiblock; package techreborn.blockentity.machine.multiblock;
import net.minecraft.block.Material;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction;
import reborncore.client.screen.BuiltScreenHandlerProvider; import reborncore.client.screen.BuiltScreenHandlerProvider;
import reborncore.client.screen.builder.BuiltScreenHandler; import reborncore.client.screen.builder.BuiltScreenHandler;
import reborncore.client.screen.builder.ScreenHandlerBuilder; import reborncore.client.screen.builder.ScreenHandlerBuilder;
import reborncore.common.blockentity.MultiblockWriter;
import reborncore.common.crafting.RebornRecipe; import reborncore.common.crafting.RebornRecipe;
import reborncore.common.recipes.RecipeCrafter; import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.RebornInventory; import reborncore.common.util.RebornInventory;
@ -41,40 +41,21 @@ import techreborn.init.TRContent;
public class DistillationTowerBlockEntity extends GenericMachineBlockEntity implements BuiltScreenHandlerProvider { public class DistillationTowerBlockEntity extends GenericMachineBlockEntity implements BuiltScreenHandlerProvider {
public MultiblockChecker multiblockChecker;
public DistillationTowerBlockEntity() { public DistillationTowerBlockEntity() {
super(TRBlockEntities.DISTILLATION_TOWER, "DistillationTower", TechRebornConfig.distillationTowerMaxInput, TechRebornConfig.distillationTowerMaxEnergy, TRContent.Machine.DISTILLATION_TOWER.block, 6); super(TRBlockEntities.DISTILLATION_TOWER, "DistillationTower", TechRebornConfig.distillationTowerMaxInput, TechRebornConfig.distillationTowerMaxEnergy, TRContent.Machine.DISTILLATION_TOWER.block, 6);
final int[] inputs = new int[] { 0, 1 }; final int[] inputs = new int[]{0, 1};
final int[] outputs = new int[] { 2, 3, 4, 5 }; final int[] outputs = new int[]{2, 3, 4, 5};
this.inventory = new RebornInventory<>(7, "DistillationTowerBlockEntity", 64, this); this.inventory = new RebornInventory<>(7, "DistillationTowerBlockEntity", 64, this);
this.crafter = new RecipeCrafter(ModRecipes.DISTILLATION_TOWER, this, 2, 4, this.inventory, inputs, outputs); this.crafter = new RecipeCrafter(ModRecipes.DISTILLATION_TOWER, this, 2, 4, this.inventory, inputs, outputs);
} }
public boolean getMutliBlock() {
if (multiblockChecker == null) {
return false;
}
final boolean layer0 = multiblockChecker.checkRectY(1, 1, MultiblockChecker.STANDARD_CASING, MultiblockChecker.ZERO_OFFSET);
final boolean layer1 = multiblockChecker.checkRingY(1, 1, MultiblockChecker.INDUSTRIAL_CASING, new BlockPos(0, 1, 0));
final boolean layer2 = multiblockChecker.checkRingY(1, 1, MultiblockChecker.STANDARD_CASING, new BlockPos(0, 2, 0));
final boolean layer3 = multiblockChecker.checkRectY(1, 1, MultiblockChecker.INDUSTRIAL_CASING, new BlockPos(0, 3, 0));
final Material centerBlock1 = multiblockChecker.getBlock(0, 1, 0).getMaterial();
final Material centerBlock2 = multiblockChecker.getBlock(0, 2, 0).getMaterial();
final boolean center1 = (centerBlock1 == Material.AIR);
final boolean center2 = (centerBlock2 == Material.AIR);
return layer0 && layer1 && layer2 && layer3 && center1 && center2;
}
// TileGenericMachine
@Override @Override
public void tick() { public void writeMultiblock(MultiblockWriter writer) {
if (multiblockChecker == null) { writer .translate(1, 0, -1)
final BlockPos downCenter = pos.offset(getFacing().getOpposite(), 2); .fill(0, 0, 0, 3, 1, 3, TRContent.MachineBlocks.BASIC.getCasing().getDefaultState())
multiblockChecker = new MultiblockChecker(world, downCenter); .ringWithAir(Direction.Axis.Y, 3, 1, 3, TRContent.MachineBlocks.INDUSTRIAL.getCasing().getDefaultState())
} .ringWithAir(Direction.Axis.Y, 3, 2, 3, TRContent.MachineBlocks.BASIC.getCasing().getDefaultState())
.fill(0, 3, 0, 3, 4, 3, TRContent.MachineBlocks.INDUSTRIAL.getCasing().getDefaultState());
super.tick();
} }
// IContainerProvider // IContainerProvider
@ -88,6 +69,6 @@ public class DistillationTowerBlockEntity extends GenericMachineBlockEntity impl
@Override @Override
public boolean canCraft(RebornRecipe rebornRecipe) { public boolean canCraft(RebornRecipe rebornRecipe) {
return getMutliBlock(); return isMultiblockValid();
} }
} }

View file

@ -27,10 +27,11 @@ package techreborn.blockentity.machine.multiblock;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction;
import reborncore.client.screen.BuiltScreenHandlerProvider; import reborncore.client.screen.BuiltScreenHandlerProvider;
import reborncore.client.screen.builder.BuiltScreenHandler; import reborncore.client.screen.builder.BuiltScreenHandler;
import reborncore.client.screen.builder.ScreenHandlerBuilder; import reborncore.client.screen.builder.ScreenHandlerBuilder;
import reborncore.common.blockentity.MultiblockWriter;
import reborncore.common.fluid.FluidValue; import reborncore.common.fluid.FluidValue;
import reborncore.common.recipes.RecipeCrafter; import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.IInventoryAccess; import reborncore.common.util.IInventoryAccess;
@ -47,11 +48,9 @@ import javax.annotation.Nullable;
/** /**
* @author drcrazy * @author drcrazy
*
*/ */
public class FluidReplicatorBlockEntity extends GenericMachineBlockEntity implements BuiltScreenHandlerProvider { public class FluidReplicatorBlockEntity extends GenericMachineBlockEntity implements BuiltScreenHandlerProvider {
public MultiblockChecker multiblockChecker;
public static final FluidValue TANK_CAPACITY = FluidValue.BUCKET.multiply(16); public static final FluidValue TANK_CAPACITY = FluidValue.BUCKET.multiply(16);
public Tank tank; public Tank tank;
int ticksSinceLastChange; int ticksSinceLastChange;
@ -59,27 +58,20 @@ public class FluidReplicatorBlockEntity extends GenericMachineBlockEntity implem
public FluidReplicatorBlockEntity() { public FluidReplicatorBlockEntity() {
super(TRBlockEntities.FLUID_REPLICATOR, "FluidReplicator", TechRebornConfig.fluidReplicatorMaxInput, TechRebornConfig.fluidReplicatorMaxEnergy, TRContent.Machine.FLUID_REPLICATOR.block, 3); super(TRBlockEntities.FLUID_REPLICATOR, "FluidReplicator", TechRebornConfig.fluidReplicatorMaxInput, TechRebornConfig.fluidReplicatorMaxEnergy, TRContent.Machine.FLUID_REPLICATOR.block, 3);
this.inventory = new RebornInventory<>(4, "FluidReplicatorBlockEntity", 64, this, getInventoryAccess()); this.inventory = new RebornInventory<>(4, "FluidReplicatorBlockEntity", 64, this, getInventoryAccess());
this.crafter = new RecipeCrafter(ModRecipes.FLUID_REPLICATOR, this, 1, 0, this.inventory, new int[] {0}, null); this.crafter = new RecipeCrafter(ModRecipes.FLUID_REPLICATOR, this, 1, 0, this.inventory, new int[]{0}, null);
this.tank = new Tank("FluidReplicatorBlockEntity", FluidReplicatorBlockEntity.TANK_CAPACITY, this); this.tank = new Tank("FluidReplicatorBlockEntity", FluidReplicatorBlockEntity.TANK_CAPACITY, this);
} }
public boolean getMultiBlock() { @Override
if (multiblockChecker == null) { public void writeMultiblock(MultiblockWriter writer) {
return false; BlockState state = TRContent.MachineBlocks.ADVANCED.getCasing().getDefaultState();
} writer .translate(1, 0, -1)
final boolean ring = multiblockChecker.checkRingY(1, 1, MultiblockChecker.ADVANCED_CASING, .ring(Direction.Axis.Y, 3, 0, 3, (v, p) -> v.getBlockState(p) == state, state, null, null);
MultiblockChecker.ZERO_OFFSET);
return ring;
} }
// TileGenericMachine // TileGenericMachine
@Override @Override
public void tick() { public void tick() {
if (multiblockChecker == null) {
final BlockPos downCenter = pos.offset(getFacing().getOpposite(), 2);
multiblockChecker = new MultiblockChecker(world, downCenter);
}
ticksSinceLastChange++; ticksSinceLastChange++;
// Check cells input slot 2 time per second // Check cells input slot 2 time per second
if (!world.isClient && ticksSinceLastChange >= 10) { if (!world.isClient && ticksSinceLastChange >= 10) {
@ -112,9 +104,9 @@ public class FluidReplicatorBlockEntity extends GenericMachineBlockEntity implem
return tagCompound; return tagCompound;
} }
private static IInventoryAccess<FluidReplicatorBlockEntity> getInventoryAccess(){ private static IInventoryAccess<FluidReplicatorBlockEntity> getInventoryAccess() {
return (slotID, stack, face, direction, blockEntity) -> { return (slotID, stack, face, direction, blockEntity) -> {
if(slotID == 0){ if (slotID == 0) {
return stack.isItemEqualIgnoreDamage(TRContent.Parts.UU_MATTER.getStack()); return stack.isItemEqualIgnoreDamage(TRContent.Parts.UU_MATTER.getStack());
} }
return true; return true;

View file

@ -33,32 +33,27 @@ import net.minecraft.text.Text;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import reborncore.api.IToolDrop;
import reborncore.api.blockentity.InventoryProvider;
import reborncore.client.screen.BuiltScreenHandlerProvider; import reborncore.client.screen.BuiltScreenHandlerProvider;
import reborncore.client.screen.builder.BuiltScreenHandler; import reborncore.client.screen.builder.BuiltScreenHandler;
import reborncore.client.screen.builder.ScreenHandlerBuilder; import reborncore.client.screen.builder.ScreenHandlerBuilder;
import reborncore.common.blockentity.MultiblockWriter;
import reborncore.common.crafting.RebornRecipe; import reborncore.common.crafting.RebornRecipe;
import reborncore.common.crafting.ingredient.RebornIngredient; import reborncore.common.crafting.ingredient.RebornIngredient;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.util.ItemUtils; import reborncore.common.util.ItemUtils;
import reborncore.common.util.RebornInventory; import reborncore.common.util.RebornInventory;
import reborncore.common.util.StringUtils; import reborncore.common.util.StringUtils;
import reborncore.common.util.Torus; import reborncore.common.util.Torus;
import techreborn.api.recipe.recipes.FusionReactorRecipe; import techreborn.api.recipe.recipes.FusionReactorRecipe;
import techreborn.blockentity.machine.GenericMachineBlockEntity;
import techreborn.config.TechRebornConfig; import techreborn.config.TechRebornConfig;
import techreborn.init.ModRecipes; import techreborn.init.ModRecipes;
import techreborn.init.TRBlockEntities; import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent; import techreborn.init.TRContent;
import java.util.List; public class FusionControlComputerBlockEntity extends GenericMachineBlockEntity implements BuiltScreenHandlerProvider {
public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
implements IToolDrop, InventoryProvider, BuiltScreenHandlerProvider {
public RebornInventory<FusionControlComputerBlockEntity> inventory; public RebornInventory<FusionControlComputerBlockEntity> inventory;
public int coilCount = 0;
public int crafingTickTime = 0; public int crafingTickTime = 0;
public int neededPower = 0; public int neededPower = 0;
public int size = 6; public int size = 6;
@ -73,36 +68,15 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
long lastTick = -1; long lastTick = -1;
public FusionControlComputerBlockEntity() { public FusionControlComputerBlockEntity() {
super(TRBlockEntities.FUSION_CONTROL_COMPUTER); super(TRBlockEntities.FUSION_CONTROL_COMPUTER, "FusionControlComputer", -1, -1, TRContent.Machine.FUSION_CONTROL_COMPUTER.block, -1);
checkOverfill = false; checkOverfill = false;
this.inventory = new RebornInventory<>(3, "FusionControlComputerBlockEntity", 64, this); this.inventory = new RebornInventory<>(3, "FusionControlComputerBlockEntity", 64, this);
} }
/** @Override
* Check that reactor has all necessary coils in place public void writeMultiblock(MultiblockWriter writer) {
* BlockState coil = TRContent.Machine.FUSION_COIL.block.getDefaultState();
* @return boolean Return true if coils are present Torus.generate(BlockPos.ORIGIN, size).forEach(pos -> writer.add(pos.getX(), pos.getY(), pos.getZ(), coil));
*/
public boolean checkCoils() {
List<BlockPos> coils = Torus.generate(pos, size);
for(BlockPos coilPos : coils){
if (!isCoil(coilPos)) {
coilCount = 0;
return false;
}
}
coilCount = coils.size();
return true;
}
/**
* Checks if block is fusion coil
*
* @param pos coordinate for block
* @return boolean Returns true if block is fusion coil
*/
public boolean isCoil(BlockPos pos) {
return world.getBlockState(pos).getBlock() == TRContent.Machine.FUSION_COIL.block;
} }
/** /**
@ -228,7 +202,7 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
} }
//Move this to here from the nbt read method, as it now requires the world as of 1.14 //Move this to here from the nbt read method, as it now requires the world as of 1.14
if(checkNBTRecipe) { if (checkNBTRecipe) {
checkNBTRecipe = false; checkNBTRecipe = false;
for (final RebornRecipe reactorRecipe : ModRecipes.FUSION_REACTOR.getRecipes(getWorld())) { for (final RebornRecipe reactorRecipe : ModRecipes.FUSION_REACTOR.getRecipes(getWorld())) {
if (validateRecipe((FusionReactorRecipe) reactorRecipe)) { if (validateRecipe((FusionReactorRecipe) reactorRecipe)) {
@ -237,7 +211,7 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
} }
} }
if(lastTick == world.getTime()){ if (lastTick == world.getTime()) {
//Prevent tick accerators, blame obstinate for this. //Prevent tick accerators, blame obstinate for this.
return; return;
} }
@ -245,11 +219,10 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
// Force check every second // Force check every second
if (world.getTime() % 20 == 0) { if (world.getTime() % 20 == 0) {
checkCoils();
inventory.setChanged(); inventory.setChanged();
} }
if (coilCount == 0) { if (!isMultiblockValid()) {
resetCrafter(); resetCrafter();
return; return;
} }
@ -314,7 +287,7 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
@Override @Override
public double getPowerMultiplier() { public double getPowerMultiplier() {
double calc = (1F/2F) * Math.pow(size -5, 1.8); double calc = (1F / 2F) * Math.pow(size - 5, 1.8);
return Math.max(Math.round(calc * 100D) / 100D, 1D); return Math.max(Math.round(calc * 100D) / 100D, 1D);
} }
@ -355,10 +328,10 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
this.crafingTickTime = tagCompound.getInt("crafingTickTime"); this.crafingTickTime = tagCompound.getInt("crafingTickTime");
this.neededPower = tagCompound.getInt("neededPower"); this.neededPower = tagCompound.getInt("neededPower");
this.hasStartedCrafting = tagCompound.getBoolean("hasStartedCrafting"); this.hasStartedCrafting = tagCompound.getBoolean("hasStartedCrafting");
if(tagCompound.contains("hasActiveRecipe") && tagCompound.getBoolean("hasActiveRecipe") && this.currentRecipe == null){ if (tagCompound.contains("hasActiveRecipe") && tagCompound.getBoolean("hasActiveRecipe") && this.currentRecipe == null) {
checkNBTRecipe = true; checkNBTRecipe = true;
} }
if(tagCompound.contains("size")){ if (tagCompound.contains("size")) {
this.size = tagCompound.getInt("size"); this.size = tagCompound.getInt("size");
} }
this.size = Math.min(size, TechRebornConfig.fusionControlComputerMaxCoilSize);//Done here to force the samller size, will be useful if people lag out on a large one. this.size = Math.min(size, TechRebornConfig.fusionControlComputerMaxCoilSize);//Done here to force the samller size, will be useful if people lag out on a large one.
@ -375,24 +348,11 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
return tagCompound; return tagCompound;
} }
// TileLegacyMachineBase
@Override
public void onLoad() {
super.onLoad();
this.checkCoils();
}
@Override @Override
public boolean canBeUpgraded() { public boolean canBeUpgraded() {
return false; return false;
} }
// IToolDrop
@Override
public ItemStack getToolDrop(PlayerEntity playerIn) {
return TRContent.Machine.FUSION_CONTROL_COMPUTER.getStack();
}
// ItemHandlerProvider // ItemHandlerProvider
@Override @Override
public RebornInventory<FusionControlComputerBlockEntity> getInventory() { public RebornInventory<FusionControlComputerBlockEntity> getInventory() {
@ -404,7 +364,6 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) { public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
return new ScreenHandlerBuilder("fusionreactor").player(player.inventory).inventory().hotbar() return new ScreenHandlerBuilder("fusionreactor").player(player.inventory).inventory().hotbar()
.addInventory().blockEntity(this).slot(0, 34, 47).slot(1, 126, 47).outputSlot(2, 80, 47).syncEnergyValue() .addInventory().blockEntity(this).slot(0, 34, 47).slot(1, 126, 47).outputSlot(2, 80, 47).syncEnergyValue()
.sync(this::getCoilStatus, this::setCoilStatus)
.sync(this::getCrafingTickTime, this::setCrafingTickTime) .sync(this::getCrafingTickTime, this::setCrafingTickTime)
.sync(this::getSize, this::setSize) .sync(this::getSize, this::setSize)
.sync(this::getState, this::setState) .sync(this::getState, this::setState)
@ -414,14 +373,6 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
.create(this, syncID); .create(this, syncID);
} }
public int getCoilStatus() {
return coilCount;
}
public void setCoilStatus(int coilStatus) {
this.coilCount = coilStatus;
}
public int getCrafingTickTime() { public int getCrafingTickTime() {
return crafingTickTime; return crafingTickTime;
} }
@ -446,61 +397,61 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
this.size = size; this.size = size;
} }
public void changeSize(int sizeDelta){ public void changeSize(int sizeDelta) {
int newSize = size + sizeDelta; int newSize = size + sizeDelta;
this.size = Math.max(6, Math.min(TechRebornConfig.fusionControlComputerMaxCoilSize, newSize)); this.size = Math.max(6, Math.min(TechRebornConfig.fusionControlComputerMaxCoilSize, newSize));
} }
public int getState(){ public int getState() {
if(currentRecipe == null ){ if (currentRecipe == null) {
return 0; //No Recipe return 0; //No Recipe
} }
if(!hasStartedCrafting){ if (!hasStartedCrafting) {
return 1; //Waiting on power return 1; //Waiting on power
} }
return 2; //Crafting return 2; //Crafting
} }
public void setState(int state){ public void setState(int state) {
this.state = state; this.state = state;
} }
public Identifier getCurrentRecipeID() { public Identifier getCurrentRecipeID() {
if(currentRecipe == null) { if (currentRecipe == null) {
return new Identifier("null", "null"); return new Identifier("null", "null");
} }
return currentRecipe.getId(); return currentRecipe.getId();
} }
public void setCurrentRecipeID(Identifier currentRecipeID) { public void setCurrentRecipeID(Identifier currentRecipeID) {
if(currentRecipeID.getPath().equals("null")) { if (currentRecipeID.getPath().equals("null")) {
currentRecipeID = null; currentRecipeID = null;
} }
this.currentRecipeID = currentRecipeID; this.currentRecipeID = currentRecipeID;
} }
public FusionReactorRecipe getCurrentRecipeFromID() { public FusionReactorRecipe getCurrentRecipeFromID() {
if(currentRecipeID == null) return null; if (currentRecipeID == null) return null;
return ModRecipes.FUSION_REACTOR.getRecipes(world).stream() return ModRecipes.FUSION_REACTOR.getRecipes(world).stream()
.filter(recipe -> recipe.getId().equals(currentRecipeID)) .filter(recipe -> recipe.getId().equals(currentRecipeID))
.findFirst() .findFirst()
.orElse(null); .orElse(null);
} }
public Text getStateText(){ public Text getStateText() {
if(state == -1){ if (state == -1) {
return LiteralText.EMPTY; return LiteralText.EMPTY;
} else if (state == 0){ } else if (state == 0) {
return new LiteralText("No recipe"); return new LiteralText("No recipe");
} else if (state == 1){ } else if (state == 1) {
FusionReactorRecipe r = getCurrentRecipeFromID(); FusionReactorRecipe r = getCurrentRecipeFromID();
if(r == null) { if (r == null) {
return new LiteralText("Charging"); return new LiteralText("Charging");
} }
int percentage = percentage(r.getStartEnergy(), getEnergy()); int percentage = percentage(r.getStartEnergy(), getEnergy());
return new LiteralText("Charging (") return new LiteralText("Charging (")
.append(StringUtils.getPercentageText(percentage)); .append(StringUtils.getPercentageText(percentage));
} else if (state == 2){ } else if (state == 2) {
return new LiteralText("Crafting"); return new LiteralText("Crafting");
} }
return LiteralText.EMPTY; return LiteralText.EMPTY;

View file

@ -25,10 +25,11 @@
package techreborn.blockentity.machine.multiblock; package techreborn.blockentity.machine.multiblock;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction;
import reborncore.client.screen.BuiltScreenHandlerProvider; import reborncore.client.screen.BuiltScreenHandlerProvider;
import reborncore.client.screen.builder.BuiltScreenHandler; import reborncore.client.screen.builder.BuiltScreenHandler;
import reborncore.client.screen.builder.ScreenHandlerBuilder; import reborncore.client.screen.builder.ScreenHandlerBuilder;
import reborncore.common.blockentity.MultiblockWriter;
import reborncore.common.crafting.RebornRecipe; import reborncore.common.crafting.RebornRecipe;
import reborncore.common.recipes.RecipeCrafter; import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.RebornInventory; import reborncore.common.util.RebornInventory;
@ -40,34 +41,20 @@ import techreborn.init.TRContent;
public class ImplosionCompressorBlockEntity extends GenericMachineBlockEntity implements BuiltScreenHandlerProvider { public class ImplosionCompressorBlockEntity extends GenericMachineBlockEntity implements BuiltScreenHandlerProvider {
public MultiblockChecker multiblockChecker;
public ImplosionCompressorBlockEntity() { public ImplosionCompressorBlockEntity() {
super(TRBlockEntities.IMPLOSION_COMPRESSOR, "ImplosionCompressor", TechRebornConfig.implosionCompressorMaxInput, TechRebornConfig.implosionCompressorMaxEnergy, TRContent.Machine.IMPLOSION_COMPRESSOR.block, 4); super(TRBlockEntities.IMPLOSION_COMPRESSOR, "ImplosionCompressor", TechRebornConfig.implosionCompressorMaxInput, TechRebornConfig.implosionCompressorMaxEnergy, TRContent.Machine.IMPLOSION_COMPRESSOR.block, 4);
final int[] inputs = new int[] { 0, 1 }; final int[] inputs = new int[]{0, 1};
final int[] outputs = new int[] { 2, 3 }; final int[] outputs = new int[]{2, 3};
this.inventory = new RebornInventory<>(5, "ImplosionCompressorBlockEntity", 64, this); this.inventory = new RebornInventory<>(5, "ImplosionCompressorBlockEntity", 64, this);
this.crafter = new RecipeCrafter(ModRecipes.IMPLOSION_COMPRESSOR, this, 2, 2, this.inventory, inputs, outputs); this.crafter = new RecipeCrafter(ModRecipes.IMPLOSION_COMPRESSOR, this, 2, 2, this.inventory, inputs, outputs);
} }
public boolean getMutliBlock() {
if(multiblockChecker == null){
return false;
}
final boolean down = multiblockChecker.checkRectY(1, 1, MultiblockChecker.ADVANCED_CASING, MultiblockChecker.ZERO_OFFSET);
final boolean up = multiblockChecker.checkRectY(1, 1, MultiblockChecker.ADVANCED_CASING, new BlockPos(0, 2, 0));
final boolean chamber = multiblockChecker.checkRingYHollow(1, 1, MultiblockChecker.ADVANCED_CASING, new BlockPos(0, 1, 0));
return down && chamber && up;
}
// TileGenericMachine
@Override @Override
public void tick() { public void writeMultiblock(MultiblockWriter writer) {
if (multiblockChecker == null) { writer .translate(-1, -3, -1)
multiblockChecker = new MultiblockChecker(world, pos.down(3)); .fill(0, 0, 0, 3, 1, 3, TRContent.MachineBlocks.ADVANCED.getCasing().getDefaultState())
} .ringWithAir(Direction.Axis.Y, 3, 1, 3, TRContent.MachineBlocks.ADVANCED.getCasing().getDefaultState())
.fill(0, 2, 0, 3, 3, 3, TRContent.MachineBlocks.ADVANCED.getCasing().getDefaultState());
super.tick();
} }
// IContainerProvider // IContainerProvider
@ -80,6 +67,6 @@ public class ImplosionCompressorBlockEntity extends GenericMachineBlockEntity im
@Override @Override
public boolean canCraft(RebornRecipe rebornRecipe) { public boolean canCraft(RebornRecipe rebornRecipe) {
return getMutliBlock(); return isMultiblockValid();
} }
} }

View file

@ -24,14 +24,18 @@
package techreborn.blockentity.machine.multiblock; package techreborn.blockentity.machine.multiblock;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.Material; import net.minecraft.block.Material;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
import reborncore.client.screen.BuiltScreenHandlerProvider; import reborncore.client.screen.BuiltScreenHandlerProvider;
import reborncore.client.screen.builder.BuiltScreenHandler; import reborncore.client.screen.builder.BuiltScreenHandler;
import reborncore.client.screen.builder.ScreenHandlerBuilder; import reborncore.client.screen.builder.ScreenHandlerBuilder;
import reborncore.common.blockentity.MultiblockWriter;
import reborncore.common.multiblock.IMultiblockPart; import reborncore.common.multiblock.IMultiblockPart;
import reborncore.common.recipes.RecipeCrafter; import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.RebornInventory; import reborncore.common.util.RebornInventory;
@ -44,21 +48,46 @@ import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent; import techreborn.init.TRContent;
import techreborn.multiblocks.MultiBlockCasing; import techreborn.multiblocks.MultiBlockCasing;
import java.util.function.BiPredicate;
public class IndustrialBlastFurnaceBlockEntity extends GenericMachineBlockEntity implements BuiltScreenHandlerProvider { public class IndustrialBlastFurnaceBlockEntity extends GenericMachineBlockEntity implements BuiltScreenHandlerProvider {
public MultiblockChecker multiblockChecker;
private int cachedHeat; private int cachedHeat;
public IndustrialBlastFurnaceBlockEntity() { public IndustrialBlastFurnaceBlockEntity() {
super(TRBlockEntities.INDUSTRIAL_BLAST_FURNACE, "IndustrialBlastFurnace", TechRebornConfig.industrialBlastFurnaceMaxInput, TechRebornConfig.industrialBlastFurnaceMaxEnergy, TRContent.Machine.INDUSTRIAL_BLAST_FURNACE.block, 4); super(TRBlockEntities.INDUSTRIAL_BLAST_FURNACE, "IndustrialBlastFurnace", TechRebornConfig.industrialBlastFurnaceMaxInput, TechRebornConfig.industrialBlastFurnaceMaxEnergy, TRContent.Machine.INDUSTRIAL_BLAST_FURNACE.block, 4);
final int[] inputs = new int[] { 0, 1 }; final int[] inputs = new int[]{0, 1};
final int[] outputs = new int[] { 2, 3 }; final int[] outputs = new int[]{2, 3};
this.inventory = new RebornInventory<>(5, "IndustrialBlastFurnaceBlockEntity", 64, this); this.inventory = new RebornInventory<>(5, "IndustrialBlastFurnaceBlockEntity", 64, this);
this.crafter = new RecipeCrafter(ModRecipes.BLAST_FURNACE, this, 2, 2, this.inventory, inputs, outputs); this.crafter = new RecipeCrafter(ModRecipes.BLAST_FURNACE, this, 2, 2, this.inventory, inputs, outputs);
} }
@Override
public void writeMultiblock(MultiblockWriter writer) {
BlockState basic = TRContent.MachineBlocks.BASIC.getCasing().getDefaultState();
BlockState advanced = TRContent.MachineBlocks.ADVANCED.getCasing().getDefaultState();
BlockState industrial = TRContent.MachineBlocks.INDUSTRIAL.getCasing().getDefaultState();
BlockState lava = Blocks.LAVA.getDefaultState();
BiPredicate<BlockView, BlockPos> casing = (view, pos) -> {
BlockState state = view.getBlockState(pos);
return basic == state || advanced == state || industrial == state;
};
BiPredicate<BlockView, BlockPos> maybeLava = (view, pos) -> {
BlockState state = view.getBlockState(pos);
return state == lava || state.getBlock() == Blocks.AIR;
};
writer .translate(1, 0, -1)
.fill(0, 0, 0, 3, 1, 3, casing, basic)
.ring(Direction.Axis.Y, 3, 1, 3, casing, basic, maybeLava, lava)
.ring(Direction.Axis.Y, 3, 2, 3, casing, basic, maybeLava, lava)
.fill(0, 3, 0, 3, 4, 3, casing, basic);
}
public int getHeat() { public int getHeat() {
if (!getMutliBlock()){ if (!isMultiblockValid()) {
return 0; return 0;
} }
@ -94,21 +123,6 @@ public class IndustrialBlastFurnaceBlockEntity extends GenericMachineBlockEntity
return 0; return 0;
} }
public boolean getMutliBlock() {
if(multiblockChecker == null){
return false;
}
final boolean layer0 = multiblockChecker.checkRectY(1, 1, MultiblockChecker.CASING_ANY, MultiblockChecker.ZERO_OFFSET);
final boolean layer1 = multiblockChecker.checkRingY(1, 1, MultiblockChecker.CASING_ANY, new BlockPos(0, 1, 0));
final boolean layer2 = multiblockChecker.checkRingY(1, 1, MultiblockChecker.CASING_ANY, new BlockPos(0, 2, 0));
final boolean layer3 = multiblockChecker.checkRectY(1, 1, MultiblockChecker.CASING_ANY, new BlockPos(0, 3, 0));
final Material centerBlock1 = multiblockChecker.getBlock(0, 1, 0).getMaterial();
final Material centerBlock2 = multiblockChecker.getBlock(0, 2, 0).getMaterial();
final boolean center1 = (centerBlock1 == Material.AIR || centerBlock1 == Material.LAVA);
final boolean center2 = (centerBlock2 == Material.AIR || centerBlock2 == Material.LAVA);
return layer0 && layer1 && layer2 && layer3 && center1 && center2;
}
public void setHeat(final int heat) { public void setHeat(final int heat) {
cachedHeat = heat; cachedHeat = heat;
} }
@ -117,16 +131,6 @@ public class IndustrialBlastFurnaceBlockEntity extends GenericMachineBlockEntity
return cachedHeat; return cachedHeat;
} }
// TileGenericMachine
@Override
public void tick() {
if (multiblockChecker == null) {
final BlockPos downCenter = pos.offset(getFacing().getOpposite(), 2);
multiblockChecker = new MultiblockChecker(world, downCenter);
}
super.tick();
}
// IContainerProvider // IContainerProvider
@Override @Override
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) { public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {

View file

@ -25,15 +25,15 @@
package techreborn.blockentity.machine.multiblock; package techreborn.blockentity.machine.multiblock;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.FluidBlock; import net.minecraft.block.Blocks;
import net.minecraft.block.Material; import net.minecraft.block.Material;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import reborncore.client.screen.BuiltScreenHandlerProvider; import reborncore.client.screen.BuiltScreenHandlerProvider;
import reborncore.client.screen.builder.BuiltScreenHandler; import reborncore.client.screen.builder.BuiltScreenHandler;
import reborncore.client.screen.builder.ScreenHandlerBuilder; import reborncore.client.screen.builder.ScreenHandlerBuilder;
import reborncore.common.blockentity.MultiblockWriter;
import reborncore.common.fluid.FluidValue; import reborncore.common.fluid.FluidValue;
import reborncore.common.recipes.RecipeCrafter; import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.RebornInventory; import reborncore.common.util.RebornInventory;
@ -51,41 +51,31 @@ public class IndustrialGrinderBlockEntity extends GenericMachineBlockEntity impl
public static final FluidValue TANK_CAPACITY = FluidValue.BUCKET.multiply(16); public static final FluidValue TANK_CAPACITY = FluidValue.BUCKET.multiply(16);
public Tank tank; public Tank tank;
public MultiblockChecker multiblockChecker;
int ticksSinceLastChange; int ticksSinceLastChange;
public IndustrialGrinderBlockEntity() { public IndustrialGrinderBlockEntity() {
super(TRBlockEntities.INDUSTRIAL_GRINDER, "IndustrialGrinder", TechRebornConfig.industrialGrinderMaxInput, TechRebornConfig.industrialGrinderMaxEnergy, TRContent.Machine.INDUSTRIAL_GRINDER.block, 7); super(TRBlockEntities.INDUSTRIAL_GRINDER, "IndustrialGrinder", TechRebornConfig.industrialGrinderMaxInput, TechRebornConfig.industrialGrinderMaxEnergy, TRContent.Machine.INDUSTRIAL_GRINDER.block, 7);
final int[] inputs = new int[] { 0, 1 }; final int[] inputs = new int[]{0, 1};
final int[] outputs = new int[] {2, 3, 4, 5}; final int[] outputs = new int[]{2, 3, 4, 5};
this.inventory = new RebornInventory<>(8, "IndustrialGrinderBlockEntity", 64, this); this.inventory = new RebornInventory<>(8, "IndustrialGrinderBlockEntity", 64, this);
this.crafter = new RecipeCrafter(ModRecipes.INDUSTRIAL_GRINDER, this, 1, 4, this.inventory, inputs, outputs); this.crafter = new RecipeCrafter(ModRecipes.INDUSTRIAL_GRINDER, this, 1, 4, this.inventory, inputs, outputs);
this.tank = new Tank("IndustrialGrinderBlockEntity", IndustrialGrinderBlockEntity.TANK_CAPACITY, this); this.tank = new Tank("IndustrialGrinderBlockEntity", IndustrialGrinderBlockEntity.TANK_CAPACITY, this);
this.ticksSinceLastChange = 0; this.ticksSinceLastChange = 0;
} }
public boolean getMultiBlock() { @Override
if (multiblockChecker == null) { public void writeMultiblock(MultiblockWriter writer) {
return false; BlockState basic = TRContent.MachineBlocks.BASIC.getCasing().getDefaultState();
} BlockState advanced = TRContent.MachineBlocks.ADVANCED.getCasing().getDefaultState();
final boolean down = multiblockChecker.checkRectY(1, 1, MultiblockChecker.STANDARD_CASING, MultiblockChecker.ZERO_OFFSET); writer .translate(1, -1, -1)
final boolean up = multiblockChecker.checkRectY(1, 1, MultiblockChecker.STANDARD_CASING, new BlockPos(0, 2, 0)); .fill(0, 0, 0, 3, 1, 3, basic)
final boolean blade = multiblockChecker.checkRingY(1, 1, MultiblockChecker.ADVANCED_CASING, new BlockPos(0, 1, 0)); .ring(Direction.Axis.Y, 3, 1, 3, (view, pos) -> view.getBlockState(pos) == advanced, advanced, (view, pos) -> view.getBlockState(pos).getMaterial() == Material.WATER, Blocks.WATER.getDefaultState())
final BlockState centerBlock = multiblockChecker.getBlock(0, 1, 0); .fill(0, 2, 0, 3, 3, 3, basic);
final boolean center = ((centerBlock.getBlock() instanceof FluidBlock
|| centerBlock.getBlock() instanceof FluidBlock)
&& centerBlock.getMaterial() == Material.WATER);
return down && center && blade && up;
} }
// TilePowerAcceptor // TilePowerAcceptor
@Override @Override
public void tick() { public void tick() {
if (multiblockChecker == null) {
final BlockPos downCenter = pos.offset(getFacing().getOpposite(), 2).offset(Direction.DOWN, 1);
multiblockChecker = new MultiblockChecker(world, downCenter);
}
ticksSinceLastChange++; ticksSinceLastChange++;
// Check cells input slot 2 time per second // Check cells input slot 2 time per second
if (!world.isClient && ticksSinceLastChange >= 10) { if (!world.isClient && ticksSinceLastChange >= 10) {

View file

@ -25,15 +25,15 @@
package techreborn.blockentity.machine.multiblock; package techreborn.blockentity.machine.multiblock;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.FluidBlock; import net.minecraft.block.Blocks;
import net.minecraft.block.Material; import net.minecraft.block.Material;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import reborncore.client.screen.BuiltScreenHandlerProvider; import reborncore.client.screen.BuiltScreenHandlerProvider;
import reborncore.client.screen.builder.BuiltScreenHandler; import reborncore.client.screen.builder.BuiltScreenHandler;
import reborncore.client.screen.builder.ScreenHandlerBuilder; import reborncore.client.screen.builder.ScreenHandlerBuilder;
import reborncore.common.blockentity.MultiblockWriter;
import reborncore.common.fluid.FluidValue; import reborncore.common.fluid.FluidValue;
import reborncore.common.recipes.RecipeCrafter; import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.RebornInventory; import reborncore.common.util.RebornInventory;
@ -51,41 +51,31 @@ public class IndustrialSawmillBlockEntity extends GenericMachineBlockEntity impl
public static final FluidValue TANK_CAPACITY = FluidValue.BUCKET.multiply(16); public static final FluidValue TANK_CAPACITY = FluidValue.BUCKET.multiply(16);
public Tank tank; public Tank tank;
public MultiblockChecker multiblockChecker;
int ticksSinceLastChange; int ticksSinceLastChange;
public IndustrialSawmillBlockEntity() { public IndustrialSawmillBlockEntity() {
super(TRBlockEntities.INDUSTRIAL_SAWMILL, "IndustrialSawmill", TechRebornConfig.industrialSawmillMaxInput, TechRebornConfig.industrialSawmillMaxEnergy, TRContent.Machine.INDUSTRIAL_SAWMILL.block, 6); super(TRBlockEntities.INDUSTRIAL_SAWMILL, "IndustrialSawmill", TechRebornConfig.industrialSawmillMaxInput, TechRebornConfig.industrialSawmillMaxEnergy, TRContent.Machine.INDUSTRIAL_SAWMILL.block, 6);
final int[] inputs = new int[] { 0, 1 }; final int[] inputs = new int[]{0, 1};
final int[] outputs = new int[] { 2, 3, 4 }; final int[] outputs = new int[]{2, 3, 4};
this.inventory = new RebornInventory<>(7, "SawmillBlockEntity", 64, this); this.inventory = new RebornInventory<>(7, "SawmillBlockEntity", 64, this);
this.crafter = new RecipeCrafter(ModRecipes.INDUSTRIAL_SAWMILL, this, 1, 3, this.inventory, inputs, outputs); this.crafter = new RecipeCrafter(ModRecipes.INDUSTRIAL_SAWMILL, this, 1, 3, this.inventory, inputs, outputs);
this.tank = new Tank("SawmillBlockEntity", IndustrialSawmillBlockEntity.TANK_CAPACITY, this); this.tank = new Tank("SawmillBlockEntity", IndustrialSawmillBlockEntity.TANK_CAPACITY, this);
this.ticksSinceLastChange = 0; this.ticksSinceLastChange = 0;
} }
public boolean getMutliBlock() { @Override
if (multiblockChecker == null) { public void writeMultiblock(MultiblockWriter writer) {
return false; BlockState basic = TRContent.MachineBlocks.BASIC.getCasing().getDefaultState();
} BlockState advanced = TRContent.MachineBlocks.ADVANCED.getCasing().getDefaultState();
final boolean down = multiblockChecker.checkRectY(1, 1, MultiblockChecker.STANDARD_CASING, MultiblockChecker.ZERO_OFFSET); writer .translate(1, -1, -1)
final boolean up = multiblockChecker.checkRectY(1, 1, MultiblockChecker.STANDARD_CASING, new BlockPos(0, 2, 0)); .fill(0, 0, 0, 3, 1, 3, basic)
final boolean blade = multiblockChecker.checkRingY(1, 1, MultiblockChecker.ADVANCED_CASING, new BlockPos(0, 1, 0)); .ring(Direction.Axis.Y, 3, 1, 3, (view, pos) -> view.getBlockState(pos) == advanced, advanced, (view, pos) -> view.getBlockState(pos).getMaterial() == Material.WATER, Blocks.WATER.getDefaultState())
final BlockState centerBlock = multiblockChecker.getBlock(0, 1, 0); .fill(0, 2, 0, 3, 3, 3, basic);
final boolean center = ((centerBlock.getBlock() instanceof FluidBlock
|| centerBlock.getBlock() instanceof FluidBlock)
&& centerBlock.getMaterial() == Material.WATER);
return down && center && blade && up;
} }
// TileGenericMachine // TileGenericMachine
@Override @Override
public void tick() { public void tick() {
if (multiblockChecker == null) {
final BlockPos downCenter = pos.offset(getFacing().getOpposite(), 2).offset(Direction.DOWN, 1);
multiblockChecker = new MultiblockChecker(world, downCenter);
}
ticksSinceLastChange++; ticksSinceLastChange++;
// Check cells input slot 2 time per second // Check cells input slot 2 time per second
if (!world.isClient && ticksSinceLastChange >= 10) { if (!world.isClient && ticksSinceLastChange >= 10) {

View file

@ -1,134 +0,0 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2020 TechReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package techreborn.blockentity.machine.multiblock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import techreborn.init.TRContent;
public class MultiblockChecker {
public static final BlockPos ZERO_OFFSET = BlockPos.ORIGIN;
public static final String STANDARD_CASING = "standard";
public static final String ADVANCED_CASING = "advanced";
public static final String INDUSTRIAL_CASING = "industrial";
public static final String CASING_ANY = "any";
private final World world;
private final BlockPos downCenter;
public MultiblockChecker(World world, BlockPos downCenter) {
this.world = world;
this.downCenter = downCenter;
}
// TODO: make thid not so ugly
public boolean checkCasing(int offX, int offY, int offZ, String type) {
Block block = getBlock(offX, offY, offZ).getBlock();
if (block == TRContent.MachineBlocks.BASIC.getCasing()|| block == TRContent.MachineBlocks.ADVANCED.getCasing() || block == TRContent.MachineBlocks.INDUSTRIAL.getCasing() ) {
if (type == MultiblockChecker.CASING_ANY) {
return true;
} else if ( type == "standard" && block == TRContent.MachineBlocks.BASIC.getCasing()) {
return true;
}
else if (type == "advanced" && block == TRContent.MachineBlocks.ADVANCED.getCasing()) {
return true;
}
else if (type == "industrial" && block == TRContent.MachineBlocks.INDUSTRIAL.getCasing()) {
return true;
}
}
return false;
}
public boolean checkAir(int offX, int offY, int offZ) {
BlockPos pos = downCenter.add(offX, offY, offZ);
return world.isAir(pos);
}
public BlockState getBlock(int offX, int offY, int offZ) {
BlockPos pos = downCenter.add(offX, offY, offZ);
return world.getBlockState(pos);
}
public boolean checkRectY(int sizeX, int sizeZ, String casingType, BlockPos offset) {
for (int x = -sizeX; x <= sizeX; x++) {
for (int z = -sizeZ; z <= sizeZ; z++) {
if (!checkCasing(x + offset.getX(), offset.getY(), z + offset.getZ(), casingType))
return false;
}
}
return true;
}
public boolean checkRectZ(int sizeX, int sizeY, String casingType, BlockPos offset) {
for (int x = -sizeX; x <= sizeX; x++) {
for (int y = -sizeY; y <= sizeY; y++) {
if (!checkCasing(x + offset.getX(), y + offset.getY(), offset.getZ(), casingType))
return false;
}
}
return true;
}
public boolean checkRectX(int sizeZ, int sizeY, String casingType, BlockPos offset) {
for (int z = -sizeZ; z <= sizeZ; z++) {
for (int y = -sizeY; y <= sizeY; y++) {
if (!checkCasing(offset.getX(), y + offset.getY(), z + offset.getZ(), casingType))
return false;
}
}
return true;
}
public boolean checkRingY(int sizeX, int sizeZ, String casingType, BlockPos offset) {
for (int x = -sizeX; x <= sizeX; x++) {
for (int z = -sizeZ; z <= sizeZ; z++) {
if ((x == sizeX || x == -sizeX) || (z == sizeZ || z == -sizeZ)) {
if (!checkCasing(x + offset.getX(), offset.getY(), z + offset.getZ(), casingType))
return false;
}
}
}
return true;
}
public boolean checkRingYHollow(int sizeX, int sizeZ, String casingType, BlockPos offset) {
for (int x = -sizeX; x <= sizeX; x++) {
for (int z = -sizeZ; z <= sizeZ; z++) {
if ((x == sizeX || x == -sizeX) || (z == sizeZ || z == -sizeZ)) {
if (!checkCasing(x + offset.getX(), offset.getY(), z + offset.getZ(), casingType))
return false;
} else if (!checkAir(x + offset.getX(), offset.getY(), z + offset.getZ()))
return false;
}
}
return true;
}
}

View file

@ -24,12 +24,13 @@
package techreborn.blockentity.machine.multiblock; package techreborn.blockentity.machine.multiblock;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import reborncore.client.screen.BuiltScreenHandlerProvider; import reborncore.client.screen.BuiltScreenHandlerProvider;
import reborncore.client.screen.builder.BuiltScreenHandler; import reborncore.client.screen.builder.BuiltScreenHandler;
import reborncore.client.screen.builder.ScreenHandlerBuilder; import reborncore.client.screen.builder.ScreenHandlerBuilder;
import reborncore.common.blockentity.MultiblockWriter;
import reborncore.common.recipes.RecipeCrafter; import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.RebornInventory; import reborncore.common.util.RebornInventory;
import techreborn.blockentity.machine.GenericMachineBlockEntity; import techreborn.blockentity.machine.GenericMachineBlockEntity;
@ -40,31 +41,23 @@ import techreborn.init.TRContent;
public class VacuumFreezerBlockEntity extends GenericMachineBlockEntity implements BuiltScreenHandlerProvider { public class VacuumFreezerBlockEntity extends GenericMachineBlockEntity implements BuiltScreenHandlerProvider {
public MultiblockChecker multiblockChecker;
public VacuumFreezerBlockEntity() { public VacuumFreezerBlockEntity() {
super(TRBlockEntities.VACUUM_FREEZER, "VacuumFreezer", TechRebornConfig.vacuumFreezerMaxInput, TechRebornConfig.vacuumFreezerMaxEnergy, TRContent.Machine.VACUUM_FREEZER.block, 2); super(TRBlockEntities.VACUUM_FREEZER, "VacuumFreezer", TechRebornConfig.vacuumFreezerMaxInput, TechRebornConfig.vacuumFreezerMaxEnergy, TRContent.Machine.VACUUM_FREEZER.block, 2);
final int[] inputs = new int[] { 0 }; final int[] inputs = new int[]{0};
final int[] outputs = new int[] { 1 }; final int[] outputs = new int[]{1};
this.inventory = new RebornInventory<>(3, "VacuumFreezerBlockEntity", 64, this); this.inventory = new RebornInventory<>(3, "VacuumFreezerBlockEntity", 64, this);
this.crafter = new RecipeCrafter(ModRecipes.VACUUM_FREEZER, this, 2, 1, this.inventory, inputs, outputs); this.crafter = new RecipeCrafter(ModRecipes.VACUUM_FREEZER, this, 2, 1, this.inventory, inputs, outputs);
} }
public boolean getMultiBlock() {
if (multiblockChecker == null) {
return false;
}
final boolean up = multiblockChecker.checkRectY(1, 1, MultiblockChecker.ADVANCED_CASING, MultiblockChecker.ZERO_OFFSET);
final boolean down = multiblockChecker.checkRectY(1, 1, MultiblockChecker.ADVANCED_CASING, new BlockPos(0, -2, 0));
final boolean chamber = multiblockChecker.checkRingYHollow(1, 1, MultiblockChecker.INDUSTRIAL_CASING, new BlockPos(0, -1, 0));
return down && chamber && up;
}
// BlockEntity
@Override @Override
public void cancelRemoval() { public void writeMultiblock(MultiblockWriter writer) {
super.cancelRemoval(); BlockState advanced = TRContent.MachineBlocks.ADVANCED.getCasing().getDefaultState();
multiblockChecker = new MultiblockChecker(world, pos.offset(Direction.DOWN, 1)); BlockState industrial = TRContent.MachineBlocks.INDUSTRIAL.getCasing().getDefaultState();
writer .translate(-1, -3, -1)
.fill(0, 0, 0, 3, 1, 3, advanced)
.ringWithAir(Direction.Axis.Y, 3, 1, 3, industrial)
.fill(0, 2, 0, 3, 3, 3, advanced);
} }
// IContainerProvider // IContainerProvider

View file

@ -29,6 +29,7 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.property.IntProperty; import net.minecraft.state.property.IntProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import reborncore.api.IToolDrop; import reborncore.api.IToolDrop;
@ -36,6 +37,7 @@ import reborncore.api.blockentity.InventoryProvider;
import reborncore.client.screen.BuiltScreenHandlerProvider; import reborncore.client.screen.BuiltScreenHandlerProvider;
import reborncore.client.screen.builder.BuiltScreenHandler; import reborncore.client.screen.builder.BuiltScreenHandler;
import reborncore.client.screen.builder.ScreenHandlerBuilder; import reborncore.client.screen.builder.ScreenHandlerBuilder;
import reborncore.common.blockentity.MultiblockWriter;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity; import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.util.ItemUtils; import reborncore.common.util.ItemUtils;
import reborncore.common.util.RebornInventory; import reborncore.common.util.RebornInventory;
@ -60,19 +62,22 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
super(TRBlockEntities.GREENHOUSE_CONTROLLER); super(TRBlockEntities.GREENHOUSE_CONTROLLER);
} }
public boolean getMultiBlock() { @Override
if (multiblockCenter == null || world == null) { public void writeMultiblock(MultiblockWriter writer) {
return false; BlockState lamp = TRContent.Machine.LAMP_INCANDESCENT.block.getDefaultState().with(Properties.FACING, Direction.DOWN);
} BlockState crop = Blocks.CACTUS.getDefaultState();
for (int i = -1; i <= 1; i++) {
for (int j = -1; j <= 1; j++) { for (int i = -1; i < 2; i++) {
BlockState block = world.getBlockState(multiblockCenter.add(i * 3, 3, i * 3)); for (int j = -1; j < 2; j++) {
if (!(block.getBlock() instanceof BlockLamp) || !BlockLamp.isActive(block)) { writer.add(i * 3, 3, j * 3, (world, pos) -> BlockLamp.isActive(world.getBlockState(pos)), lamp);
return false;
} }
} }
for (int i = -4; i <= 4; i++) {
for (int j = -4; j <= 4; j++) {
writer.add(i, 0, j, (world, pos) -> true, crop);
}
} }
return true;
} }
@Override @Override
@ -92,7 +97,7 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
} }
if (--ticksToNextMultiblockCheck < 0) { if (--ticksToNextMultiblockCheck < 0) {
growthBoost = getMultiBlock(); growthBoost = isMultiblockValid();
ticksToNextMultiblockCheck = 200; ticksToNextMultiblockCheck = 200;
} }
@ -211,11 +216,6 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
return false; return false;
} }
@Override
public boolean canAcceptEnergy(Direction direction) {
return true;
}
@Override @Override
public boolean canProvideEnergy(Direction direction) { public boolean canProvideEnergy(Direction direction) {
return false; return false;

View file

@ -59,7 +59,8 @@ public class BlockFusionControlComputer extends BlockMachineBase {
if(playerIn.getStackInHand(hand).isEmpty()){ if(playerIn.getStackInHand(hand).isEmpty()){
return ActionResult.SUCCESS; return ActionResult.SUCCESS;
} }
if(worldIn.getBlockState(coil).canReplace(new ItemPlacementContext(new ItemUsageContext(playerIn, hand, hitResult))) && !blockEntityFusionControlComputer.isCoil(coil)){ if(worldIn.getBlockState(coil).canReplace(new ItemPlacementContext(new ItemUsageContext(playerIn, hand, hitResult)))
&& worldIn.getBlockState(pos).getBlock() != TRContent.Machine.FUSION_COIL.block) {
worldIn.setBlockState(coil, TRContent.Machine.FUSION_COIL.block.getDefaultState()); worldIn.setBlockState(coil, TRContent.Machine.FUSION_COIL.block.getDefaultState());
if(!playerIn.isCreative()){ if(!playerIn.isCreative()){
playerIn.getStackInHand(hand).decrement(1); playerIn.getStackInHand(hand).decrement(1);
@ -72,7 +73,7 @@ public class BlockFusionControlComputer extends BlockMachineBase {
} }
} }
blockEntityFusionControlComputer.checkCoils(); blockEntityFusionControlComputer.isMultiblockValid();
return super.onUse(state, worldIn, pos, playerIn, hand, hitResult); return super.onUse(state, worldIn, pos, playerIn, hand, hitResult);
} }
@ -86,7 +87,7 @@ public class BlockFusionControlComputer extends BlockMachineBase {
super.onSteppedOn(worldIn, pos, entityIn); super.onSteppedOn(worldIn, pos, entityIn);
if (worldIn.getBlockEntity(pos) instanceof FusionControlComputerBlockEntity) { if (worldIn.getBlockEntity(pos) instanceof FusionControlComputerBlockEntity) {
if (((FusionControlComputerBlockEntity) worldIn.getBlockEntity(pos)).crafingTickTime != 0 if (((FusionControlComputerBlockEntity) worldIn.getBlockEntity(pos)).crafingTickTime != 0
&& ((FusionControlComputerBlockEntity) worldIn.getBlockEntity(pos)).checkCoils()) { && ((FusionControlComputerBlockEntity) worldIn.getBlockEntity(pos)).isMultiblockValid()) {
entityIn.damage(new FusionDamageSource(), 200F); entityIn.damage(new FusionDamageSource(), 200F);
} }
} }

View file

@ -85,7 +85,7 @@ public class BlockLamp extends BaseBlockEntityProvider {
} }
public static boolean isActive(BlockState state) { public static boolean isActive(BlockState state) {
return state.get(ACTIVE); return state.contains(ACTIVE) && state.get(ACTIVE);
} }
public static Direction getFacing(BlockState state) { public static Direction getFacing(BlockState state) {

View file

@ -25,22 +25,17 @@
package techreborn.client.gui; package techreborn.client.gui;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.block.BlockState;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import reborncore.client.gui.builder.GuiBase; import reborncore.client.gui.builder.GuiBase;
import reborncore.client.gui.builder.widget.GuiButtonExtended; import reborncore.client.gui.builder.widget.GuiButtonExtended;
import reborncore.client.gui.guibuilder.GuiBuilder; import reborncore.client.gui.guibuilder.GuiBuilder;
import reborncore.client.multiblock.Multiblock;
import reborncore.client.screen.builder.BuiltScreenHandler; import reborncore.client.screen.builder.BuiltScreenHandler;
import techreborn.blockentity.machine.multiblock.IndustrialBlastFurnaceBlockEntity; import techreborn.blockentity.machine.multiblock.IndustrialBlastFurnaceBlockEntity;
import techreborn.init.TRContent;
public class GuiBlastFurnace extends GuiBase<BuiltScreenHandler> { public class GuiBlastFurnace extends GuiBase<BuiltScreenHandler> {
public IndustrialBlastFurnaceBlockEntity blockEntity; private final IndustrialBlastFurnaceBlockEntity blockEntity;
boolean hasMultiBlock; boolean hasMultiBlock;
public GuiBlastFurnace(int syncID, final PlayerEntity player, final IndustrialBlastFurnaceBlockEntity blockEntity) { public GuiBlastFurnace(int syncID, final PlayerEntity player, final IndustrialBlastFurnaceBlockEntity blockEntity) {
@ -93,62 +88,7 @@ public class GuiBlastFurnace extends GuiBase<BuiltScreenHandler> {
builder.drawMultiEnergyBar(matrixStack, this, 9, 19, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxPower(), mouseX, mouseY, 0, layer); builder.drawMultiEnergyBar(matrixStack, this, 9, 19, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxPower(), mouseX, mouseY, 0, layer);
} }
public void onClick(GuiButtonExtended button, Double x, Double y){ public void onClick(GuiButtonExtended button, Double x, Double y) {
if (hideGuiElements()) return; blockEntity.renderMultiblock ^= !hideGuiElements();
if (blockEntity.renderMultiblock == null) {
{
// This code here makes a basic multiblock and then sets to the selected one.
final Multiblock multiblock = new Multiblock();
BlockState standardCasing = TRContent.MachineBlocks.BASIC.getCasing().getDefaultState();
this.addComponent(0, 0, 0, standardCasing, multiblock);
this.addComponent(1, 0, 0, standardCasing, multiblock);
this.addComponent(0, 0, 1, standardCasing, multiblock);
this.addComponent(-1, 0, 0, standardCasing, multiblock);
this.addComponent(0, 0, -1, standardCasing, multiblock);
this.addComponent(-1, 0, -1, standardCasing, multiblock);
this.addComponent(-1, 0, 1, standardCasing, multiblock);
this.addComponent(1, 0, -1, standardCasing, multiblock);
this.addComponent(1, 0, 1, standardCasing, multiblock);
this.addComponent(1, 1, 0, standardCasing, multiblock);
this.addComponent(0, 1, 1, standardCasing, multiblock);
this.addComponent(-1, 1, 0, standardCasing, multiblock);
this.addComponent(0, 1, -1, standardCasing, multiblock);
this.addComponent(-1, 1, -1, standardCasing, multiblock);
this.addComponent(-1, 1, 1, standardCasing, multiblock);
this.addComponent(1, 1, -1, standardCasing, multiblock);
this.addComponent(1, 1, 1, standardCasing, multiblock);
this.addComponent(1, 2, 0, standardCasing, multiblock);
this.addComponent(0, 2, 1, standardCasing, multiblock);
this.addComponent(-1, 2, 0, standardCasing, multiblock);
this.addComponent(0, 2, -1, standardCasing, multiblock);
this.addComponent(-1, 2, -1, standardCasing, multiblock);
this.addComponent(-1, 2, 1, standardCasing, multiblock);
this.addComponent(1, 2, -1, standardCasing, multiblock);
this.addComponent(1, 2, 1, standardCasing, multiblock);
this.addComponent(0, 3, 0, standardCasing, multiblock);
this.addComponent(1, 3, 0, standardCasing, multiblock);
this.addComponent(0, 3, 1, standardCasing, multiblock);
this.addComponent(-1, 3, 0, standardCasing, multiblock);
this.addComponent(0, 3, -1, standardCasing, multiblock);
this.addComponent(-1, 3, -1, standardCasing, multiblock);
this.addComponent(-1, 3, 1, standardCasing, multiblock);
this.addComponent(1, 3, -1, standardCasing, multiblock);
this.addComponent(1, 3, 1, standardCasing, multiblock);
blockEntity.renderMultiblock = multiblock;
} }
} else {
blockEntity.renderMultiblock = null;
}
}
public void addComponent(final int x, final int y, final int z, final BlockState blockState, final Multiblock multiblock) {
multiblock.addComponent(new BlockPos(x - Direction.byId(blockEntity.getFacingInt()).getOffsetX() * 2,
y,
z - Direction.byId(blockEntity.getFacingInt()).getOffsetZ() * 2), blockState);
}
} }

View file

@ -25,22 +25,17 @@
package techreborn.client.gui; package techreborn.client.gui;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.block.BlockState;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import reborncore.client.gui.builder.GuiBase; import reborncore.client.gui.builder.GuiBase;
import reborncore.client.gui.builder.widget.GuiButtonExtended; import reborncore.client.gui.builder.widget.GuiButtonExtended;
import reborncore.client.gui.guibuilder.GuiBuilder; import reborncore.client.gui.guibuilder.GuiBuilder;
import reborncore.client.multiblock.Multiblock;
import reborncore.client.screen.builder.BuiltScreenHandler; import reborncore.client.screen.builder.BuiltScreenHandler;
import techreborn.blockentity.machine.multiblock.DistillationTowerBlockEntity; import techreborn.blockentity.machine.multiblock.DistillationTowerBlockEntity;
import techreborn.init.TRContent;
public class GuiDistillationTower extends GuiBase<BuiltScreenHandler> { public class GuiDistillationTower extends GuiBase<BuiltScreenHandler> {
public DistillationTowerBlockEntity blockEntity; private final DistillationTowerBlockEntity blockEntity;
public GuiDistillationTower(int syncID, final PlayerEntity player, final DistillationTowerBlockEntity blockEntity) { public GuiDistillationTower(int syncID, final PlayerEntity player, final DistillationTowerBlockEntity blockEntity) {
super(player, blockEntity, blockEntity.createScreenHandler(syncID, player)); super(player, blockEntity, blockEntity.createScreenHandler(syncID, player));
@ -70,7 +65,7 @@ public class GuiDistillationTower extends GuiBase<BuiltScreenHandler> {
final GuiBase.Layer layer = Layer.FOREGROUND; final GuiBase.Layer layer = Layer.FOREGROUND;
builder.drawProgressBar(matrixStack, this, blockEntity.getProgressScaled(100), 100, 55, 40, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer); builder.drawProgressBar(matrixStack, this, blockEntity.getProgressScaled(100), 100, 55, 40, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer);
if (blockEntity.getMutliBlock()) { if (blockEntity.isMultiblockValid()) {
addHologramButton(6, 4, 212, layer).clickHandler(this::onClick); addHologramButton(6, 4, 212, layer).clickHandler(this::onClick);
builder.drawHologramButton(matrixStack, this, 6, 4, mouseX, mouseY, layer); builder.drawHologramButton(matrixStack, this, 6, 4, mouseX, mouseY, layer);
} else { } else {
@ -83,61 +78,6 @@ public class GuiDistillationTower extends GuiBase<BuiltScreenHandler> {
} }
public void onClick(GuiButtonExtended button, Double x, Double y){ public void onClick(GuiButtonExtended button, Double x, Double y){
if (hideGuiElements()) return; blockEntity.renderMultiblock ^= !hideGuiElements();
if (blockEntity.renderMultiblock == null) {
{
// This code here makes a basic multiblock and then sets to the selected one.
final Multiblock multiblock = new Multiblock();
BlockState industrialCasing = TRContent.MachineBlocks.INDUSTRIAL.getCasing().getDefaultState();
BlockState standardCasing = TRContent.MachineBlocks.BASIC.getCasing().getDefaultState();
addComponent(0, 0, 0, standardCasing, multiblock);
addComponent(1, 0, 0, standardCasing, multiblock);
addComponent(0, 0, 1, standardCasing, multiblock);
addComponent(-1, 0, 0, standardCasing, multiblock);
addComponent(0, 0, -1, standardCasing, multiblock);
addComponent(-1, 0, -1, standardCasing, multiblock);
addComponent(-1, 0, 1, standardCasing, multiblock);
addComponent(1, 0, -1, standardCasing, multiblock);
addComponent(1, 0, 1, standardCasing, multiblock);
addComponent(1, 1, 0, industrialCasing, multiblock);
addComponent(0, 1, 1, industrialCasing, multiblock);
addComponent(-1, 1, 0, industrialCasing, multiblock);
addComponent(0, 1, -1, industrialCasing, multiblock);
addComponent(-1, 1, -1, industrialCasing, multiblock);
addComponent(-1, 1, 1, industrialCasing, multiblock);
addComponent(1, 1, -1, industrialCasing, multiblock);
addComponent(1, 1, 1, industrialCasing, multiblock);
addComponent(1, 2, 0, standardCasing, multiblock);
addComponent(0, 2, 1, standardCasing, multiblock);
addComponent(-1, 2, 0, standardCasing, multiblock);
addComponent(0, 2, -1, standardCasing, multiblock);
addComponent(-1, 2, -1, standardCasing, multiblock);
addComponent(-1, 2, 1, standardCasing, multiblock);
addComponent(1, 2, -1, standardCasing, multiblock);
addComponent(1, 2, 1, standardCasing, multiblock);
addComponent(0, 3, 0, industrialCasing, multiblock);
addComponent(1, 3, 0, industrialCasing, multiblock);
addComponent(0, 3, 1, industrialCasing, multiblock);
addComponent(-1, 3, 0, industrialCasing, multiblock);
addComponent(0, 3, -1, industrialCasing, multiblock);
addComponent(-1, 3, -1, industrialCasing, multiblock);
addComponent(-1, 3, 1, industrialCasing, multiblock);
addComponent(1, 3, -1, industrialCasing, multiblock);
addComponent(1, 3, 1, industrialCasing, multiblock);
blockEntity.renderMultiblock = multiblock;
} }
} else {
blockEntity.renderMultiblock = null;
}
}
public void addComponent(final int x, final int y, final int z, final BlockState blockState, final Multiblock multiblock) {
multiblock.addComponent(new BlockPos(x - Direction.byId(blockEntity.getFacingInt()).getOffsetX() * 2, y, z - Direction.byId(blockEntity.getFacingInt()).getOffsetZ() * 2), blockState);
}
} }

View file

@ -24,26 +24,20 @@
package techreborn.client.gui; package techreborn.client.gui;
import net.minecraft.block.BlockState;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import reborncore.client.gui.builder.GuiBase; import reborncore.client.gui.builder.GuiBase;
import reborncore.client.gui.builder.widget.GuiButtonExtended; import reborncore.client.gui.builder.widget.GuiButtonExtended;
import reborncore.client.gui.guibuilder.GuiBuilder; import reborncore.client.gui.guibuilder.GuiBuilder;
import reborncore.client.multiblock.Multiblock;
import reborncore.client.screen.builder.BuiltScreenHandler; import reborncore.client.screen.builder.BuiltScreenHandler;
import techreborn.blockentity.machine.multiblock.FluidReplicatorBlockEntity; import techreborn.blockentity.machine.multiblock.FluidReplicatorBlockEntity;
import techreborn.init.TRContent;
/** /**
* @author drcrazy * @author drcrazy
*
*/ */
public class GuiFluidReplicator extends GuiBase<BuiltScreenHandler> { public class GuiFluidReplicator extends GuiBase<BuiltScreenHandler> {
FluidReplicatorBlockEntity blockEntity; private final FluidReplicatorBlockEntity blockEntity;
public GuiFluidReplicator(int syncID, final PlayerEntity player, final FluidReplicatorBlockEntity blockEntity) { public GuiFluidReplicator(int syncID, final PlayerEntity player, final FluidReplicatorBlockEntity blockEntity) {
super(player, blockEntity, blockEntity.createScreenHandler(syncID, player)); super(player, blockEntity, blockEntity.createScreenHandler(syncID, player));
@ -64,7 +58,7 @@ public class GuiFluidReplicator extends GuiBase<BuiltScreenHandler> {
drawSlot(matrixStack, 124, 55, layer); drawSlot(matrixStack, 124, 55, layer);
// JEI button // JEI button
builder.drawJEIButton(matrixStack, this, 158, 5, layer); builder.drawJEIButton(matrixStack, this, 158, 5, layer);
if (blockEntity.getMultiBlock()) { if (blockEntity.isMultiblockValid()) {
builder.drawHologramButton(matrixStack, this, 6, 4, mouseX, mouseY, layer); builder.drawHologramButton(matrixStack, this, 6, 4, mouseX, mouseY, layer);
} }
} }
@ -76,7 +70,7 @@ public class GuiFluidReplicator extends GuiBase<BuiltScreenHandler> {
builder.drawTank(matrixStack, this, 99, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer); builder.drawTank(matrixStack, this, 99, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer);
builder.drawProgressBar(matrixStack, this, blockEntity.getProgressScaled(100), 100, 76, 48, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer); builder.drawProgressBar(matrixStack, this, blockEntity.getProgressScaled(100), 100, 76, 48, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer);
if (blockEntity.getMultiBlock()) { if (blockEntity.isMultiblockValid()) {
addHologramButton(6, 4, 212, layer).clickHandler(this::onClick); addHologramButton(6, 4, 212, layer).clickHandler(this::onClick);
} else { } else {
builder.drawMultiblockMissingBar(matrixStack, this, layer); builder.drawMultiblockMissingBar(matrixStack, this, layer);
@ -87,35 +81,7 @@ public class GuiFluidReplicator extends GuiBase<BuiltScreenHandler> {
} }
// GuiScreen // GuiScreen
public void onClick(GuiButtonExtended button, Double x, Double y){ public void onClick(GuiButtonExtended button, Double x, Double y) {
if (hideGuiElements()) return; blockEntity.renderMultiblock ^= !hideGuiElements();
if (blockEntity.renderMultiblock == null) {
{
// This code here makes a basic multiblock and then sets to the selected one.
final Multiblock multiblock = new Multiblock();
final BlockState reinforcedCasing = TRContent.MachineBlocks.ADVANCED.getCasing().getDefaultState();
addComponent(1, 0, 0, reinforcedCasing, multiblock);
addComponent(0, 0, 1, reinforcedCasing, multiblock);
addComponent(-1, 0, 0, reinforcedCasing, multiblock);
addComponent(0, 0, -1, reinforcedCasing, multiblock);
addComponent(-1, 0, -1, reinforcedCasing, multiblock);
addComponent(-1, 0, 1, reinforcedCasing, multiblock);
addComponent(1, 0, -1, reinforcedCasing, multiblock);
addComponent(1, 0, 1, reinforcedCasing, multiblock);
blockEntity.renderMultiblock = multiblock;
} }
} else {
blockEntity.renderMultiblock = null;
}
}
public void addComponent(final int x, final int y, final int z, final BlockState blockState, final Multiblock multiblock) {
multiblock.addComponent(new BlockPos(
x - Direction.byId(this.blockEntity.getFacingInt()).getOffsetX() * 2,
y,
z - Direction.byId(this.blockEntity.getFacingInt()).getOffsetZ() * 2), blockState);
}
} }

View file

@ -24,33 +24,29 @@
package techreborn.client.gui; package techreborn.client.gui;
import net.minecraft.block.BlockState;
import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
import net.minecraft.util.math.BlockPos;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import reborncore.client.gui.builder.GuiBase; import reborncore.client.gui.builder.GuiBase;
import reborncore.client.gui.builder.widget.GuiButtonExtended; import reborncore.client.gui.builder.widget.GuiButtonExtended;
import reborncore.client.gui.builder.widget.GuiButtonUpDown; import reborncore.client.gui.builder.widget.GuiButtonUpDown;
import reborncore.client.gui.builder.widget.GuiButtonUpDown.UpDownButtonType; import reborncore.client.gui.builder.widget.GuiButtonUpDown.UpDownButtonType;
import reborncore.client.gui.guibuilder.GuiBuilder; import reborncore.client.gui.guibuilder.GuiBuilder;
import reborncore.client.multiblock.Multiblock;
import reborncore.client.screen.builder.BuiltScreenHandler; import reborncore.client.screen.builder.BuiltScreenHandler;
import reborncore.common.network.NetworkManager; import reborncore.common.network.NetworkManager;
import reborncore.common.powerSystem.PowerSystem; import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.util.Color; import reborncore.common.util.Color;
import reborncore.common.util.Torus; import reborncore.common.util.Torus;
import techreborn.blockentity.machine.multiblock.FusionControlComputerBlockEntity; import techreborn.blockentity.machine.multiblock.FusionControlComputerBlockEntity;
import techreborn.init.TRContent;
import techreborn.packets.ServerboundPackets; import techreborn.packets.ServerboundPackets;
import java.util.List;
import java.util.Optional; import java.util.Optional;
public class GuiFusionReactor extends GuiBase<BuiltScreenHandler> { public class GuiFusionReactor extends GuiBase<BuiltScreenHandler> {
FusionControlComputerBlockEntity blockEntity;
private final FusionControlComputerBlockEntity blockEntity;
public GuiFusionReactor(int syncID, final PlayerEntity player, final FusionControlComputerBlockEntity blockEntity) { public GuiFusionReactor(int syncID, final PlayerEntity player, final FusionControlComputerBlockEntity blockEntity) {
super(player, blockEntity, blockEntity.createScreenHandler(syncID, player)); super(player, blockEntity, blockEntity.createScreenHandler(syncID, player));
@ -76,7 +72,7 @@ public class GuiFusionReactor extends GuiBase<BuiltScreenHandler> {
drawOutputSlot(matrixStack, 80, 47, layer); drawOutputSlot(matrixStack, 80, 47, layer);
builder.drawJEIButton(matrixStack, this, 158, 5, layer); builder.drawJEIButton(matrixStack, this, 158, 5, layer);
if (blockEntity.getCoilStatus() > 0) { if (blockEntity.isMultiblockValid()) {
builder.drawHologramButton(matrixStack, this, 6, 4, mouseX, mouseY, layer); builder.drawHologramButton(matrixStack, this, 6, 4, mouseX, mouseY, layer);
} }
@ -89,10 +85,10 @@ public class GuiFusionReactor extends GuiBase<BuiltScreenHandler> {
builder.drawProgressBar(matrixStack, this, blockEntity.getProgressScaled(100), 100, 55, 51, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer); builder.drawProgressBar(matrixStack, this, blockEntity.getProgressScaled(100), 100, 55, 51, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer);
builder.drawProgressBar(matrixStack, this, blockEntity.getProgressScaled(100), 100, 105, 51, mouseX, mouseY, GuiBuilder.ProgressDirection.LEFT, layer); builder.drawProgressBar(matrixStack, this, blockEntity.getProgressScaled(100), 100, 105, 51, mouseX, mouseY, GuiBuilder.ProgressDirection.LEFT, layer);
if (blockEntity.getCoilStatus() > 0) { if (blockEntity.isMultiblockValid()) {
addHologramButton(6, 4, 212, layer).clickHandler(this::hologramToggle); addHologramButton(6, 4, 212, layer).clickHandler(this::hologramToggle);
drawCentredText(matrixStack, blockEntity.getStateText(), 20, Color.BLUE.darker().getColor(), layer); drawCentredText(matrixStack, blockEntity.getStateText(), 20, Color.BLUE.darker().getColor(), layer);
if(blockEntity.state == 2){ if (blockEntity.state == 2) {
drawCentredText(matrixStack, new LiteralText(PowerSystem.getLocaliszedPowerFormatted((int) blockEntity.getPowerChange())).append("/t"), 30, Color.GREEN.darker().getColor(), layer); drawCentredText(matrixStack, new LiteralText(PowerSystem.getLocaliszedPowerFormatted((int) blockEntity.getPowerChange())).append("/t"), 30, Color.GREEN.darker().getColor(), layer);
} }
} else { } else {
@ -101,8 +97,8 @@ public class GuiFusionReactor extends GuiBase<BuiltScreenHandler> {
builder.drawHologramButton(matrixStack, this, 76, 56, mouseX, mouseY, layer); builder.drawHologramButton(matrixStack, this, 76, 56, mouseX, mouseY, layer);
Optional<Pair<Integer, Integer>> stackSize = getCoilStackCount(); Optional<Pair<Integer, Integer>> stackSize = getCoilStackCount();
if(stackSize.isPresent()){ if (stackSize.isPresent()) {
if(stackSize.get().getLeft() > 0){ if (stackSize.get().getLeft() > 0) {
drawCentredText(matrixStack, drawCentredText(matrixStack,
new LiteralText("Required Coils: ") new LiteralText("Required Coils: ")
@ -117,44 +113,21 @@ public class GuiFusionReactor extends GuiBase<BuiltScreenHandler> {
} }
} }
drawTextWithShadow(matrixStack, client.textRenderer, new LiteralText("Size: ").append(String.valueOf(blockEntity.size)), 83, 81, 0xFFFFFF); drawTextWithShadow(matrixStack, client.textRenderer, new LiteralText("Size: ").append(String.valueOf(blockEntity.size)), 83, 81, 0xFFFFFF);
drawTextWithShadow(matrixStack, client.textRenderer,new LiteralText(String.valueOf(blockEntity.getPowerMultiplier())).append("x"), 10, 81, 0xFFFFFF); drawTextWithShadow(matrixStack, client.textRenderer, new LiteralText(String.valueOf(blockEntity.getPowerMultiplier())).append("x"), 10, 81, 0xFFFFFF);
builder.drawMultiEnergyBar(matrixStack, this, 9, 19, (int) this.blockEntity.getEnergy(), (int) this.blockEntity.getMaxPower(), mouseX, mouseY, 0, layer); builder.drawMultiEnergyBar(matrixStack, this, 9, 19, (int) this.blockEntity.getEnergy(), (int) this.blockEntity.getMaxPower(), mouseX, mouseY, 0, layer);
} }
public void hologramToggle(GuiButtonExtended button, double x, double y){ public void hologramToggle(GuiButtonExtended button, double x, double y) {
if (hideGuiElements()) return; blockEntity.renderMultiblock ^= !hideGuiElements();
if (blockEntity.renderMultiblock == null) {
updateMultiBlockRender();
} else {
blockEntity.renderMultiblock = null;
}
} }
private void sendSizeChange(int sizeDelta){ private void sendSizeChange(int sizeDelta) {
NetworkManager.sendToServer(ServerboundPackets.createPacketFusionControlSize(sizeDelta, blockEntity.getPos())); NetworkManager.sendToServer(ServerboundPackets.createPacketFusionControlSize(sizeDelta, blockEntity.getPos()));
//Reset the multiblock as it will be wrong now.
if(blockEntity.renderMultiblock != null){
updateMultiBlockRender();
}
} }
private void updateMultiBlockRender(){ public Optional<Pair<Integer, Integer>> getCoilStackCount() {
final Multiblock multiblock = new Multiblock(); if (!Torus.TORUS_SIZE_MAP.containsKey(blockEntity.size)) {
BlockState coil = TRContent.Machine.FUSION_COIL.block.getDefaultState();
List<BlockPos> coils = Torus.generate(new BlockPos(0, 0, 0), blockEntity.size);
coils.forEach(pos -> addComponent(pos.getX(), pos.getY(), pos.getZ(), coil, multiblock));
blockEntity.renderMultiblock = multiblock;
}
public void addComponent(final int x, final int y, final int z, final BlockState blockState, final Multiblock multiblock) {
multiblock.addComponent(new BlockPos(x, y, z), blockState);
}
public Optional<Pair<Integer, Integer>> getCoilStackCount(){
if(!Torus.TORUS_SIZE_MAP.containsKey(blockEntity.size)){
return Optional.empty(); return Optional.empty();
} }
int count = Torus.TORUS_SIZE_MAP.get(blockEntity.size); int count = Torus.TORUS_SIZE_MAP.get(blockEntity.size);

View file

@ -25,23 +25,16 @@
package techreborn.client.gui; package techreborn.client.gui;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.resource.language.I18n; import net.minecraft.client.resource.language.I18n;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.state.property.Properties;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import reborncore.client.gui.builder.GuiBase; import reborncore.client.gui.builder.GuiBase;
import reborncore.client.gui.builder.widget.GuiButtonExtended; import reborncore.client.gui.builder.widget.GuiButtonExtended;
import reborncore.client.multiblock.Multiblock;
import reborncore.client.screen.builder.BuiltScreenHandler; import reborncore.client.screen.builder.BuiltScreenHandler;
import techreborn.blockentity.machine.tier1.GreenhouseControllerBlockEntity; import techreborn.blockentity.machine.tier1.GreenhouseControllerBlockEntity;
import techreborn.init.TRContent;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -49,7 +42,7 @@ import java.util.stream.Collectors;
public class GuiGreenhouseController extends GuiBase<BuiltScreenHandler> { public class GuiGreenhouseController extends GuiBase<BuiltScreenHandler> {
GreenhouseControllerBlockEntity blockEntity; private final GreenhouseControllerBlockEntity blockEntity;
public GuiGreenhouseController(int syncID, final PlayerEntity player, final GreenhouseControllerBlockEntity blockEntity) { public GuiGreenhouseController(int syncID, final PlayerEntity player, final GreenhouseControllerBlockEntity blockEntity) {
super(player, blockEntity, blockEntity.createScreenHandler(syncID, player)); super(player, blockEntity, blockEntity.createScreenHandler(syncID, player));
@ -71,7 +64,7 @@ public class GuiGreenhouseController extends GuiBase<BuiltScreenHandler> {
drawSlot(matrixStack, 30, gridYPos + 36, layer); drawSlot(matrixStack, 30, gridYPos + 36, layer);
drawSlot(matrixStack, 48, gridYPos + 36, layer); drawSlot(matrixStack, 48, gridYPos + 36, layer);
if (!blockEntity.getMultiBlock()) { if (!blockEntity.isMultiblockValid()) {
getMinecraft().getTextureManager().bindTexture(new Identifier("techreborn", "textures/item/part/digital_display.png")); getMinecraft().getTextureManager().bindTexture(new Identifier("techreborn", "textures/item/part/digital_display.png"));
drawTexture(matrixStack, x + 68, y + 22, 0, 0, 16, 16, 16, 16); drawTexture(matrixStack, x + 68, y + 22, 0, 0, 16, 16, 16, 16);
if (isPointInRect(68, 22, 16, 16, mouseX, mouseY)) { if (isPointInRect(68, 22, 16, 16, mouseX, mouseY)) {
@ -96,7 +89,7 @@ public class GuiGreenhouseController extends GuiBase<BuiltScreenHandler> {
addHologramButton(90, 24, 212, layer).clickHandler(this::onClick); addHologramButton(90, 24, 212, layer).clickHandler(this::onClick);
builder.drawHologramButton(matrixStack, this, 90, 24, mouseX, mouseY, layer); builder.drawHologramButton(matrixStack, this, 90, 24, mouseX, mouseY, layer);
if (!blockEntity.getMultiBlock()) { if (!blockEntity.isMultiblockValid()) {
if (isPointInRect(68, 22, 16, 16, mouseX, mouseY)) { if (isPointInRect(68, 22, 16, 16, mouseX, mouseY)) {
List<Text> list = Arrays.stream(I18n.translate("techreborn.tooltip.greenhouse.upgrade_available") List<Text> list = Arrays.stream(I18n.translate("techreborn.tooltip.greenhouse.upgrade_available")
.split("\\r?\\n")) .split("\\r?\\n"))
@ -113,41 +106,6 @@ public class GuiGreenhouseController extends GuiBase<BuiltScreenHandler> {
} }
public void onClick(GuiButtonExtended button, Double x, Double y) { public void onClick(GuiButtonExtended button, Double x, Double y) {
if (hideGuiElements()) return; blockEntity.renderMultiblock ^= !hideGuiElements();
if (blockEntity.renderMultiblock == null) {
final Multiblock multiblock = new Multiblock();
BlockState lamp = TRContent.Machine.LAMP_INCANDESCENT.block.getDefaultState().with(Properties.FACING, Direction.DOWN);
BlockState crop = Blocks.CACTUS.getDefaultState();
this.addComponent(-3, 3, -3, lamp, multiblock);
this.addComponent(-3, 3, 0, lamp, multiblock);
this.addComponent(-3, 3, 3, lamp, multiblock);
this.addComponent(0, 3, -3, lamp, multiblock);
this.addComponent(0, 3, 0, lamp, multiblock);
this.addComponent(0, 3, 3, lamp, multiblock);
this.addComponent(3, 3, -3, lamp, multiblock);
this.addComponent(3, 3, 0, lamp, multiblock);
this.addComponent(3, 3, 3, lamp, multiblock);
for (int i = -4; i <= 4; i++) {
for (int j = -4; j <= 4; j++) {
this.addComponent(i, 0, j, crop, multiblock);
} }
}
blockEntity.renderMultiblock = multiblock;
} else {
blockEntity.renderMultiblock = null;
}
}
public void addComponent(final int x, final int y, final int z, final BlockState blockState, final Multiblock multiblock) {
multiblock.addComponent(new BlockPos(
x - Direction.byId(this.blockEntity.getFacingInt()).getOffsetX() * 5,
y,
z - Direction.byId(this.blockEntity.getFacingInt()).getOffsetZ() * 5),
blockState
);
}
} }

View file

@ -25,21 +25,17 @@
package techreborn.client.gui; package techreborn.client.gui;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.block.BlockState;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import reborncore.client.gui.builder.GuiBase; import reborncore.client.gui.builder.GuiBase;
import reborncore.client.gui.builder.widget.GuiButtonExtended; import reborncore.client.gui.builder.widget.GuiButtonExtended;
import reborncore.client.gui.guibuilder.GuiBuilder; import reborncore.client.gui.guibuilder.GuiBuilder;
import reborncore.client.multiblock.Multiblock;
import reborncore.client.screen.builder.BuiltScreenHandler; import reborncore.client.screen.builder.BuiltScreenHandler;
import techreborn.blockentity.machine.multiblock.ImplosionCompressorBlockEntity; import techreborn.blockentity.machine.multiblock.ImplosionCompressorBlockEntity;
import techreborn.init.TRContent;
public class GuiImplosionCompressor extends GuiBase<BuiltScreenHandler> { public class GuiImplosionCompressor extends GuiBase<BuiltScreenHandler> {
ImplosionCompressorBlockEntity blockEntity; private final ImplosionCompressorBlockEntity blockEntity;
public GuiImplosionCompressor(int syncID, final PlayerEntity player, final ImplosionCompressorBlockEntity blockEntity) { public GuiImplosionCompressor(int syncID, final PlayerEntity player, final ImplosionCompressorBlockEntity blockEntity) {
super(player, blockEntity, blockEntity.createScreenHandler(syncID, player)); super(player, blockEntity, blockEntity.createScreenHandler(syncID, player));
@ -60,7 +56,7 @@ public class GuiImplosionCompressor extends GuiBase<BuiltScreenHandler> {
drawSlot(matrixStack, 92, 36, layer); drawSlot(matrixStack, 92, 36, layer);
drawSlot(matrixStack, 110, 36, layer); drawSlot(matrixStack, 110, 36, layer);
if (blockEntity.getMutliBlock()) { if (blockEntity.isMultiblockValid()) {
builder.drawHologramButton(matrixStack, this, 6, 4, mouseX, mouseY, layer); builder.drawHologramButton(matrixStack, this, 6, 4, mouseX, mouseY, layer);
} }
@ -73,7 +69,7 @@ public class GuiImplosionCompressor extends GuiBase<BuiltScreenHandler> {
final GuiBase.Layer layer = Layer.FOREGROUND; final GuiBase.Layer layer = Layer.FOREGROUND;
builder.drawProgressBar(matrixStack, this, blockEntity.getProgressScaled(100), 100, 71, 40, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer); builder.drawProgressBar(matrixStack, this, blockEntity.getProgressScaled(100), 100, 71, 40, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer);
if (blockEntity.getMutliBlock()) { if (blockEntity.isMultiblockValid()) {
addHologramButton(6, 4, 212, layer).clickHandler(this::onClick); addHologramButton(6, 4, 212, layer).clickHandler(this::onClick);
} else { } else {
builder.drawMultiblockMissingBar(matrixStack, this, layer); builder.drawMultiblockMissingBar(matrixStack, this, layer);
@ -84,30 +80,7 @@ public class GuiImplosionCompressor extends GuiBase<BuiltScreenHandler> {
} }
public void onClick(GuiButtonExtended button, Double mouseX, Double mouseY){ public void onClick(GuiButtonExtended button, Double mouseX, Double mouseY) {
if (hideGuiElements()) return; blockEntity.renderMultiblock ^= !hideGuiElements();
if (blockEntity.renderMultiblock == null) {
{
// This code here makes a basic multiblock and then sets to the selected one.
final Multiblock multiblock = new Multiblock();
for (int x = -1; x <= 1; x++) {
for (int y = -4; y <= -2; y++) {
for (int z = -1; z <= 1; z++) {
if (!((x == 0) && (y == -3) && (z == 0))) {
this.addComponent(x, y + 1, z, TRContent.MachineBlocks.ADVANCED.getCasing().getDefaultState(), multiblock);
}
}
}
}
blockEntity.renderMultiblock = multiblock;
}
} else {
blockEntity.renderMultiblock = null;
}
}
public void addComponent(final int x, final int y, final int z, final BlockState blockState, final Multiblock multiblock) {
multiblock.addComponent(new BlockPos(x, y, z), blockState);
} }
} }

View file

@ -24,23 +24,17 @@
package techreborn.client.gui; package techreborn.client.gui;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import reborncore.client.gui.builder.GuiBase; import reborncore.client.gui.builder.GuiBase;
import reborncore.client.gui.builder.widget.GuiButtonExtended; import reborncore.client.gui.builder.widget.GuiButtonExtended;
import reborncore.client.gui.guibuilder.GuiBuilder; import reborncore.client.gui.guibuilder.GuiBuilder;
import reborncore.client.multiblock.Multiblock;
import reborncore.client.screen.builder.BuiltScreenHandler; import reborncore.client.screen.builder.BuiltScreenHandler;
import techreborn.blockentity.machine.multiblock.IndustrialGrinderBlockEntity; import techreborn.blockentity.machine.multiblock.IndustrialGrinderBlockEntity;
import techreborn.init.TRContent;
public class GuiIndustrialGrinder extends GuiBase<BuiltScreenHandler> { public class GuiIndustrialGrinder extends GuiBase<BuiltScreenHandler> {
IndustrialGrinderBlockEntity blockEntity; private final IndustrialGrinderBlockEntity blockEntity;
public GuiIndustrialGrinder(int syncID, final PlayerEntity player, final IndustrialGrinderBlockEntity blockEntity) { public GuiIndustrialGrinder(int syncID, final PlayerEntity player, final IndustrialGrinderBlockEntity blockEntity) {
super(player, blockEntity, blockEntity.createScreenHandler(syncID, player)); super(player, blockEntity, blockEntity.createScreenHandler(syncID, player));
@ -67,7 +61,7 @@ public class GuiIndustrialGrinder extends GuiBase<BuiltScreenHandler> {
drawSlot(matrixStack, 126, 72, layer); drawSlot(matrixStack, 126, 72, layer);
builder.drawJEIButton(matrixStack, this, 158, 5, layer); builder.drawJEIButton(matrixStack, this, 158, 5, layer);
if (blockEntity.getMultiBlock()) { if (blockEntity.isMultiblockValid()) {
builder.drawHologramButton(matrixStack, this, 6, 4, mouseX, mouseY, layer); builder.drawHologramButton(matrixStack, this, 6, 4, mouseX, mouseY, layer);
} }
} }
@ -79,7 +73,7 @@ public class GuiIndustrialGrinder extends GuiBase<BuiltScreenHandler> {
builder.drawProgressBar(matrixStack, this, blockEntity.getProgressScaled(100), 100, 105, 47, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer); builder.drawProgressBar(matrixStack, this, blockEntity.getProgressScaled(100), 100, 105, 47, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer);
builder.drawTank(matrixStack, this, 53, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer); builder.drawTank(matrixStack, this, 53, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer);
if (blockEntity.getMultiBlock()) { if (blockEntity.isMultiblockValid()) {
addHologramButton(6, 4, 212, layer).clickHandler(this::onClick); addHologramButton(6, 4, 212, layer).clickHandler(this::onClick);
} else { } else {
builder.drawMultiblockMissingBar(matrixStack, this, layer); builder.drawMultiblockMissingBar(matrixStack, this, layer);
@ -89,59 +83,7 @@ public class GuiIndustrialGrinder extends GuiBase<BuiltScreenHandler> {
builder.drawMultiEnergyBar(matrixStack, this, 9, 19, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxPower(), mouseX, mouseY, 0, layer); builder.drawMultiEnergyBar(matrixStack, this, 9, 19, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxPower(), mouseX, mouseY, 0, layer);
} }
public void onClick(GuiButtonExtended button, double mouseX, double mouseY){ public void onClick(GuiButtonExtended button, double mouseX, double mouseY) {
if (hideGuiElements()) return; blockEntity.renderMultiblock ^= !hideGuiElements();
if (blockEntity.renderMultiblock == null) {
{
// This code here makes a basic multiblock and then sets to the selected one.
final Multiblock multiblock = new Multiblock();
BlockState standardCasing = TRContent.MachineBlocks.BASIC.getCasing().getDefaultState();
BlockState reinforcedCasing = TRContent.MachineBlocks.ADVANCED.getCasing().getDefaultState();
addComponent(0, -1, 0, standardCasing, multiblock);
addComponent(1, -1, 0, standardCasing, multiblock);
addComponent(0, -1, 1, standardCasing, multiblock);
addComponent(-1, -1, 0, standardCasing, multiblock);
addComponent(0, -1, -1, standardCasing, multiblock);
addComponent(-1, -1, -1, standardCasing, multiblock);
addComponent(-1, -1, 1, standardCasing, multiblock);
addComponent(1, -1, -1, standardCasing, multiblock);
addComponent(1, -1, 1, standardCasing, multiblock);
addComponent(0, 0, 0, Blocks.WATER.getDefaultState(), multiblock);
addComponent(1, 0, 0, reinforcedCasing, multiblock);
addComponent(0, 0, 1, reinforcedCasing, multiblock);
addComponent(-1, 0, 0, reinforcedCasing, multiblock);
addComponent(0, 0, -1, reinforcedCasing, multiblock);
addComponent(-1, 0, -1, reinforcedCasing, multiblock);
addComponent(-1, 0, 1, reinforcedCasing, multiblock);
addComponent(1, 0, -1, reinforcedCasing, multiblock);
addComponent(1, 0, 1, reinforcedCasing, multiblock);
addComponent(0, 1, 0, standardCasing, multiblock);
addComponent(0, 1, 0, standardCasing, multiblock);
addComponent(1, 1, 0, standardCasing, multiblock);
addComponent(0, 1, 1, standardCasing, multiblock);
addComponent(-1, 1, 0, standardCasing, multiblock);
addComponent(0, 1, -1, standardCasing, multiblock);
addComponent(-1, 1, -1, standardCasing, multiblock);
addComponent(-1, 1, 1, standardCasing, multiblock);
addComponent(1, 1, -1, standardCasing, multiblock);
addComponent(1, 1, 1, standardCasing, multiblock);
blockEntity.renderMultiblock = multiblock;
} }
} else {
blockEntity.renderMultiblock = null;
}
}
public void addComponent(final int x, final int y, final int z, final BlockState blockState, final Multiblock multiblock) {
multiblock.addComponent(new BlockPos(
x - Direction.byId(this.blockEntity.getFacingInt()).getOffsetX() * 2,
y,
z - Direction.byId(this.blockEntity.getFacingInt()).getOffsetZ() * 2),
blockState);
}
} }

View file

@ -24,35 +24,23 @@
package techreborn.client.gui; package techreborn.client.gui;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import reborncore.client.gui.builder.GuiBase; import reborncore.client.gui.builder.GuiBase;
import reborncore.client.gui.builder.widget.GuiButtonExtended; import reborncore.client.gui.builder.widget.GuiButtonExtended;
import reborncore.client.gui.guibuilder.GuiBuilder; import reborncore.client.gui.guibuilder.GuiBuilder;
import reborncore.client.multiblock.Multiblock;
import reborncore.client.screen.builder.BuiltScreenHandler; import reborncore.client.screen.builder.BuiltScreenHandler;
import techreborn.blockentity.machine.multiblock.IndustrialSawmillBlockEntity; import techreborn.blockentity.machine.multiblock.IndustrialSawmillBlockEntity;
import techreborn.init.TRContent;
public class GuiIndustrialSawmill extends GuiBase<BuiltScreenHandler> { public class GuiIndustrialSawmill extends GuiBase<BuiltScreenHandler> {
IndustrialSawmillBlockEntity blockEntity; private final IndustrialSawmillBlockEntity blockEntity;
public GuiIndustrialSawmill(int syncID, final PlayerEntity player, final IndustrialSawmillBlockEntity blockEntity) { public GuiIndustrialSawmill(int syncID, final PlayerEntity player, final IndustrialSawmillBlockEntity blockEntity) {
super(player, blockEntity, blockEntity.createScreenHandler(syncID, player)); super(player, blockEntity, blockEntity.createScreenHandler(syncID, player));
this.blockEntity = blockEntity; this.blockEntity = blockEntity;
} }
@Override
public void init() {
super.init();
blockEntity.renderMultiblock = null;
}
@Override @Override
protected void drawBackground(MatrixStack matrixStack, final float partialTicks, final int mouseX, final int mouseY) { protected void drawBackground(MatrixStack matrixStack, final float partialTicks, final int mouseX, final int mouseY) {
super.drawBackground(matrixStack, partialTicks, mouseX, mouseY); super.drawBackground(matrixStack, partialTicks, mouseX, mouseY);
@ -72,7 +60,7 @@ public class GuiIndustrialSawmill extends GuiBase<BuiltScreenHandler> {
drawSlot(matrixStack, 126, 61, layer); drawSlot(matrixStack, 126, 61, layer);
builder.drawJEIButton(matrixStack, this, 158, 5, layer); builder.drawJEIButton(matrixStack, this, 158, 5, layer);
if (blockEntity.getMutliBlock()) { if (blockEntity.isMultiblockValid()) {
builder.drawHologramButton(matrixStack, this, 6, 4, mouseX, mouseY, layer); builder.drawHologramButton(matrixStack, this, 6, 4, mouseX, mouseY, layer);
} }
} }
@ -84,7 +72,7 @@ public class GuiIndustrialSawmill extends GuiBase<BuiltScreenHandler> {
builder.drawProgressBar(matrixStack, this, blockEntity.getProgressScaled(100), 100, 105, 47, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer); builder.drawProgressBar(matrixStack, this, blockEntity.getProgressScaled(100), 100, 105, 47, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer);
builder.drawTank(matrixStack, this, 53, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer); builder.drawTank(matrixStack, this, 53, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer);
if (blockEntity.getMutliBlock()) { if (blockEntity.isMultiblockValid()) {
addHologramButton(6, 4, 212, layer).clickHandler(this::onClick); addHologramButton(6, 4, 212, layer).clickHandler(this::onClick);
} else { } else {
builder.drawMultiblockMissingBar(matrixStack, this, layer); builder.drawMultiblockMissingBar(matrixStack, this, layer);
@ -94,57 +82,7 @@ public class GuiIndustrialSawmill extends GuiBase<BuiltScreenHandler> {
builder.drawMultiEnergyBar(matrixStack, this, 9, 19, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxPower(), mouseX, mouseY, 0, layer); builder.drawMultiEnergyBar(matrixStack, this, 9, 19, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxPower(), mouseX, mouseY, 0, layer);
} }
public void onClick(GuiButtonExtended button, Double mouseX, Double mouseY){ public void onClick(GuiButtonExtended button, Double mouseX, Double mouseY) {
if (hideGuiElements()) return; blockEntity.renderMultiblock ^= !hideGuiElements();
if (blockEntity.renderMultiblock == null) {
{
// This code here makes a basic multiblock and then sets to the selected one.
final Multiblock multiblock = new Multiblock();
BlockState standardCasing = TRContent.MachineBlocks.BASIC.getCasing().getDefaultState();
BlockState reinforcedCasing = TRContent.MachineBlocks.ADVANCED.getCasing().getDefaultState();
addComponent(0, -1, 0, standardCasing, multiblock);
addComponent(1, -1, 0, standardCasing, multiblock);
addComponent(0, -1, 1, standardCasing, multiblock);
addComponent(-1, -1, 0, standardCasing, multiblock);
addComponent(0, -1, -1, standardCasing, multiblock);
addComponent(-1, -1, -1, standardCasing, multiblock);
addComponent(-1, -1, 1, standardCasing, multiblock);
addComponent(1, -1, -1, standardCasing, multiblock);
addComponent(1, -1, 1, standardCasing, multiblock);
addComponent(0, 0, 0, Blocks.WATER.getDefaultState(), multiblock);
addComponent(1, 0, 0, reinforcedCasing, multiblock);
addComponent(0, 0, 1, reinforcedCasing, multiblock);
addComponent(-1, 0, 0, reinforcedCasing, multiblock);
addComponent(0, 0, -1, reinforcedCasing, multiblock);
addComponent(-1, 0, -1, reinforcedCasing, multiblock);
addComponent(-1, 0, 1, reinforcedCasing, multiblock);
addComponent(1, 0, -1, reinforcedCasing, multiblock);
addComponent(1, 0, 1, reinforcedCasing, multiblock);
addComponent(0, 1, 0, standardCasing, multiblock);
addComponent(0, 1, 0, standardCasing, multiblock);
addComponent(1, 1, 0, standardCasing, multiblock);
addComponent(0, 1, 1, standardCasing, multiblock);
addComponent(-1, 1, 0, standardCasing, multiblock);
addComponent(0, 1, -1, standardCasing, multiblock);
addComponent(-1, 1, -1, standardCasing, multiblock);
addComponent(-1, 1, 1, standardCasing, multiblock);
addComponent(1, 1, -1, standardCasing, multiblock);
addComponent(1, 1, 1, standardCasing, multiblock);
blockEntity.renderMultiblock = multiblock;
}
} else {
blockEntity.renderMultiblock = null;
}
}
public void addComponent(final int x, final int y, final int z, final BlockState blockState, final Multiblock multiblock) {
multiblock.addComponent(new BlockPos(
x - Direction.byId(this.blockEntity.getFacingInt()).getOffsetY() * 2,
y,
z- Direction.byId(this.blockEntity.getFacingInt()).getOffsetY() * 2).offset(blockEntity.getFacing().getOpposite(), 2), blockState);
} }
} }

View file

@ -24,21 +24,17 @@
package techreborn.client.gui; package techreborn.client.gui;
import net.minecraft.block.BlockState;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import reborncore.client.gui.builder.GuiBase; import reborncore.client.gui.builder.GuiBase;
import reborncore.client.gui.builder.widget.GuiButtonExtended; import reborncore.client.gui.builder.widget.GuiButtonExtended;
import reborncore.client.gui.guibuilder.GuiBuilder; import reborncore.client.gui.guibuilder.GuiBuilder;
import reborncore.client.multiblock.Multiblock;
import reborncore.client.screen.builder.BuiltScreenHandler; import reborncore.client.screen.builder.BuiltScreenHandler;
import techreborn.blockentity.machine.multiblock.VacuumFreezerBlockEntity; import techreborn.blockentity.machine.multiblock.VacuumFreezerBlockEntity;
import techreborn.init.TRContent;
public class GuiVacuumFreezer extends GuiBase<BuiltScreenHandler> { public class GuiVacuumFreezer extends GuiBase<BuiltScreenHandler> {
VacuumFreezerBlockEntity blockEntity; private final VacuumFreezerBlockEntity blockEntity;
public GuiVacuumFreezer(int syncID, final PlayerEntity player, final VacuumFreezerBlockEntity blockEntity) { public GuiVacuumFreezer(int syncID, final PlayerEntity player, final VacuumFreezerBlockEntity blockEntity) {
super(player, blockEntity, blockEntity.createScreenHandler(syncID, player)); super(player, blockEntity, blockEntity.createScreenHandler(syncID, player));
@ -59,7 +55,7 @@ public class GuiVacuumFreezer extends GuiBase<BuiltScreenHandler> {
drawOutputSlot(matrixStack, 101, 45, layer); drawOutputSlot(matrixStack, 101, 45, layer);
builder.drawJEIButton(matrixStack, this, 158, 5, layer); builder.drawJEIButton(matrixStack, this, 158, 5, layer);
if (blockEntity.getMultiBlock()) { if (blockEntity.isMultiblockValid()) {
builder.drawHologramButton(matrixStack, this, 6, 4, mouseX, mouseY, layer); builder.drawHologramButton(matrixStack, this, 6, 4, mouseX, mouseY, layer);
} }
} }
@ -70,7 +66,7 @@ public class GuiVacuumFreezer extends GuiBase<BuiltScreenHandler> {
final GuiBase.Layer layer = GuiBase.Layer.FOREGROUND; final GuiBase.Layer layer = GuiBase.Layer.FOREGROUND;
builder.drawProgressBar(matrixStack, this, blockEntity.getProgressScaled(100), 100, 76, 48, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer); builder.drawProgressBar(matrixStack, this, blockEntity.getProgressScaled(100), 100, 76, 48, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer);
if (blockEntity.getMultiBlock()) { if (blockEntity.isMultiblockValid()) {
addHologramButton(6, 4, 212, layer).clickHandler(this::onClick); addHologramButton(6, 4, 212, layer).clickHandler(this::onClick);
} else { } else {
builder.drawMultiblockMissingBar(matrixStack, this, layer); builder.drawMultiblockMissingBar(matrixStack, this, layer);
@ -80,52 +76,7 @@ public class GuiVacuumFreezer extends GuiBase<BuiltScreenHandler> {
builder.drawMultiEnergyBar(matrixStack, this, 9, 19, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxPower(), mouseX, mouseY, 0, layer); builder.drawMultiEnergyBar(matrixStack, this, 9, 19, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxPower(), mouseX, mouseY, 0, layer);
} }
public void onClick(GuiButtonExtended button, Double mouseX, Double mouseY){ public void onClick(GuiButtonExtended button, Double mouseX, Double mouseY) {
if (hideGuiElements()) return; blockEntity.renderMultiblock ^= !hideGuiElements();
if (blockEntity.renderMultiblock == null) {
{
// This code here makes a basic multiblock and then sets to the selected one.
final Multiblock multiblock = new Multiblock();
BlockState advancedCasing = TRContent.MachineBlocks.ADVANCED.getCasing().getDefaultState();
BlockState industrialCasing = TRContent.MachineBlocks.INDUSTRIAL.getCasing().getDefaultState();
addComponent(0, -1, 0, advancedCasing, multiblock);
addComponent(1, -1, 0, advancedCasing, multiblock);
addComponent(0, -1, 1, advancedCasing, multiblock);
addComponent(-1, -1, 0, advancedCasing, multiblock);
addComponent(0, -1, -1, advancedCasing, multiblock);
addComponent(-1, -1, -1, advancedCasing, multiblock);
addComponent(-1, -1, 1, advancedCasing, multiblock);
addComponent(1, -1, -1, advancedCasing, multiblock);
addComponent(1, -1, 1, advancedCasing, multiblock);
addComponent(1, -2, 0, industrialCasing, multiblock);
addComponent(0, -2, 1, industrialCasing, multiblock);
addComponent(-1, -2, 0, industrialCasing, multiblock);
addComponent(0, -2, -1, industrialCasing, multiblock);
addComponent(-1, -2, -1, industrialCasing, multiblock);
addComponent(-1, -2, 1, industrialCasing, multiblock);
addComponent(1, -2, -1, industrialCasing, multiblock);
addComponent(1, -2, 1, industrialCasing, multiblock);
addComponent(0, -3, 0, advancedCasing, multiblock);
addComponent(1, -3, 0, advancedCasing, multiblock);
addComponent(0, -3, 1, advancedCasing, multiblock);
addComponent(-1, -3, 0, advancedCasing, multiblock);
addComponent(0, -3, -1, advancedCasing, multiblock);
addComponent(-1, -3, -1, advancedCasing, multiblock);
addComponent(-1, -3, 1, advancedCasing, multiblock);
addComponent(1, -3, -1, advancedCasing, multiblock);
addComponent(1, -3, 1, advancedCasing, multiblock);
blockEntity.renderMultiblock = multiblock;
}
} else {
blockEntity.renderMultiblock = null;
}
}
public void addComponent(final int x, final int y, final int z, final BlockState blockState, final Multiblock multiblock) {
multiblock.addComponent(new BlockPos(x, y, z), blockState);
} }
} }