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:
parent
c89d6941ae
commit
4b2042a100
25 changed files with 275 additions and 939 deletions
|
@ -79,7 +79,7 @@ public abstract class GenericMachineBlockEntity extends PowerAcceptorBlockEntity
|
|||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (!world.isClient) {
|
||||
if (!world.isClient && energySlot != -1) {
|
||||
charge(energySlot);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,12 +24,12 @@
|
|||
|
||||
package techreborn.blockentity.machine.multiblock;
|
||||
|
||||
import net.minecraft.block.Material;
|
||||
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.builder.BuiltScreenHandler;
|
||||
import reborncore.client.screen.builder.ScreenHandlerBuilder;
|
||||
import reborncore.common.blockentity.MultiblockWriter;
|
||||
import reborncore.common.crafting.RebornRecipe;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
|
@ -41,40 +41,21 @@ import techreborn.init.TRContent;
|
|||
|
||||
public class DistillationTowerBlockEntity extends GenericMachineBlockEntity implements BuiltScreenHandlerProvider {
|
||||
|
||||
public MultiblockChecker multiblockChecker;
|
||||
|
||||
public DistillationTowerBlockEntity() {
|
||||
super(TRBlockEntities.DISTILLATION_TOWER, "DistillationTower", TechRebornConfig.distillationTowerMaxInput, TechRebornConfig.distillationTowerMaxEnergy, TRContent.Machine.DISTILLATION_TOWER.block, 6);
|
||||
final int[] inputs = new int[] { 0, 1 };
|
||||
final int[] outputs = new int[] { 2, 3, 4, 5 };
|
||||
final int[] inputs = new int[]{0, 1};
|
||||
final int[] outputs = new int[]{2, 3, 4, 5};
|
||||
this.inventory = new RebornInventory<>(7, "DistillationTowerBlockEntity", 64, this);
|
||||
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
|
||||
public void tick() {
|
||||
if (multiblockChecker == null) {
|
||||
final BlockPos downCenter = pos.offset(getFacing().getOpposite(), 2);
|
||||
multiblockChecker = new MultiblockChecker(world, downCenter);
|
||||
}
|
||||
|
||||
super.tick();
|
||||
public void writeMultiblock(MultiblockWriter writer) {
|
||||
writer .translate(1, 0, -1)
|
||||
.fill(0, 0, 0, 3, 1, 3, TRContent.MachineBlocks.BASIC.getCasing().getDefaultState())
|
||||
.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());
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
|
@ -88,6 +69,6 @@ public class DistillationTowerBlockEntity extends GenericMachineBlockEntity impl
|
|||
|
||||
@Override
|
||||
public boolean canCraft(RebornRecipe rebornRecipe) {
|
||||
return getMutliBlock();
|
||||
return isMultiblockValid();
|
||||
}
|
||||
}
|
|
@ -27,10 +27,11 @@ package techreborn.blockentity.machine.multiblock;
|
|||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
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.builder.BuiltScreenHandler;
|
||||
import reborncore.client.screen.builder.ScreenHandlerBuilder;
|
||||
import reborncore.common.blockentity.MultiblockWriter;
|
||||
import reborncore.common.fluid.FluidValue;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.util.IInventoryAccess;
|
||||
|
@ -47,11 +48,9 @@ import javax.annotation.Nullable;
|
|||
|
||||
/**
|
||||
* @author drcrazy
|
||||
*
|
||||
*/
|
||||
public class FluidReplicatorBlockEntity extends GenericMachineBlockEntity implements BuiltScreenHandlerProvider {
|
||||
|
||||
public MultiblockChecker multiblockChecker;
|
||||
public static final FluidValue TANK_CAPACITY = FluidValue.BUCKET.multiply(16);
|
||||
public Tank tank;
|
||||
int ticksSinceLastChange;
|
||||
|
@ -59,27 +58,20 @@ public class FluidReplicatorBlockEntity extends GenericMachineBlockEntity implem
|
|||
public FluidReplicatorBlockEntity() {
|
||||
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.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);
|
||||
}
|
||||
|
||||
public boolean getMultiBlock() {
|
||||
if (multiblockChecker == null) {
|
||||
return false;
|
||||
}
|
||||
final boolean ring = multiblockChecker.checkRingY(1, 1, MultiblockChecker.ADVANCED_CASING,
|
||||
MultiblockChecker.ZERO_OFFSET);
|
||||
return ring;
|
||||
@Override
|
||||
public void writeMultiblock(MultiblockWriter writer) {
|
||||
BlockState state = TRContent.MachineBlocks.ADVANCED.getCasing().getDefaultState();
|
||||
writer .translate(1, 0, -1)
|
||||
.ring(Direction.Axis.Y, 3, 0, 3, (v, p) -> v.getBlockState(p) == state, state, null, null);
|
||||
}
|
||||
|
||||
// TileGenericMachine
|
||||
@Override
|
||||
public void tick() {
|
||||
if (multiblockChecker == null) {
|
||||
final BlockPos downCenter = pos.offset(getFacing().getOpposite(), 2);
|
||||
multiblockChecker = new MultiblockChecker(world, downCenter);
|
||||
}
|
||||
|
||||
ticksSinceLastChange++;
|
||||
// Check cells input slot 2 time per second
|
||||
if (!world.isClient && ticksSinceLastChange >= 10) {
|
||||
|
@ -92,7 +84,7 @@ public class FluidReplicatorBlockEntity extends GenericMachineBlockEntity implem
|
|||
super.tick();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RecipeCrafter getRecipeCrafter() {
|
||||
return (RecipeCrafter) crafter;
|
||||
|
@ -112,9 +104,9 @@ public class FluidReplicatorBlockEntity extends GenericMachineBlockEntity implem
|
|||
return tagCompound;
|
||||
}
|
||||
|
||||
private static IInventoryAccess<FluidReplicatorBlockEntity> getInventoryAccess(){
|
||||
private static IInventoryAccess<FluidReplicatorBlockEntity> getInventoryAccess() {
|
||||
return (slotID, stack, face, direction, blockEntity) -> {
|
||||
if(slotID == 0){
|
||||
if (slotID == 0) {
|
||||
return stack.isItemEqualIgnoreDamage(TRContent.Parts.UU_MATTER.getStack());
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -33,32 +33,27 @@ import net.minecraft.text.Text;
|
|||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.blockentity.InventoryProvider;
|
||||
import reborncore.client.screen.BuiltScreenHandlerProvider;
|
||||
import reborncore.client.screen.builder.BuiltScreenHandler;
|
||||
import reborncore.client.screen.builder.ScreenHandlerBuilder;
|
||||
import reborncore.common.blockentity.MultiblockWriter;
|
||||
import reborncore.common.crafting.RebornRecipe;
|
||||
import reborncore.common.crafting.ingredient.RebornIngredient;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.util.ItemUtils;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import reborncore.common.util.StringUtils;
|
||||
import reborncore.common.util.Torus;
|
||||
import techreborn.api.recipe.recipes.FusionReactorRecipe;
|
||||
import techreborn.blockentity.machine.GenericMachineBlockEntity;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.init.TRContent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
|
||||
implements IToolDrop, InventoryProvider, BuiltScreenHandlerProvider {
|
||||
public class FusionControlComputerBlockEntity extends GenericMachineBlockEntity implements BuiltScreenHandlerProvider {
|
||||
|
||||
public RebornInventory<FusionControlComputerBlockEntity> inventory;
|
||||
|
||||
public int coilCount = 0;
|
||||
public int crafingTickTime = 0;
|
||||
public int neededPower = 0;
|
||||
public int size = 6;
|
||||
|
@ -73,36 +68,15 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
|
|||
long lastTick = -1;
|
||||
|
||||
public FusionControlComputerBlockEntity() {
|
||||
super(TRBlockEntities.FUSION_CONTROL_COMPUTER);
|
||||
super(TRBlockEntities.FUSION_CONTROL_COMPUTER, "FusionControlComputer", -1, -1, TRContent.Machine.FUSION_CONTROL_COMPUTER.block, -1);
|
||||
checkOverfill = false;
|
||||
this.inventory = new RebornInventory<>(3, "FusionControlComputerBlockEntity", 64, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that reactor has all necessary coils in place
|
||||
*
|
||||
* @return boolean Return true if coils are present
|
||||
*/
|
||||
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;
|
||||
@Override
|
||||
public void writeMultiblock(MultiblockWriter writer) {
|
||||
BlockState coil = TRContent.Machine.FUSION_COIL.block.getDefaultState();
|
||||
Torus.generate(BlockPos.ORIGIN, size).forEach(pos -> writer.add(pos.getX(), pos.getY(), pos.getZ(), coil));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -118,14 +92,14 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
|
|||
/**
|
||||
* Checks that ItemStack could be inserted into slot provided, including check
|
||||
* for existing item in slot and maximum stack size
|
||||
*
|
||||
*
|
||||
* @param stack ItemStack ItemStack to insert
|
||||
* @param slot int Slot ID to check
|
||||
* @param tags boolean Should we use tags
|
||||
* @param slot int Slot ID to check
|
||||
* @param tags boolean Should we use tags
|
||||
* @return boolean Returns true if ItemStack will fit into slot
|
||||
*/
|
||||
public boolean canFitStack(ItemStack stack, int slot, boolean tags) {// Checks to see if it can
|
||||
// fit the stack
|
||||
// fit the stack
|
||||
if (stack.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
@ -140,7 +114,7 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
|
|||
|
||||
/**
|
||||
* Returns progress scaled to input value
|
||||
*
|
||||
*
|
||||
* @param scale int Maximum value for progress
|
||||
* @return int Scale of progress
|
||||
*/
|
||||
|
@ -166,20 +140,20 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validates if reactor has all inputs and can output result
|
||||
*
|
||||
*
|
||||
* @param recipe FusionReactorRecipe Recipe to validate
|
||||
* @return Boolean True if we have all inputs and can fit output
|
||||
*/
|
||||
private boolean validateRecipe(FusionReactorRecipe recipe) {
|
||||
return hasAllInputs(recipe) && canFitStack(recipe.getOutputs().get(0), outputStackSlot, true);
|
||||
return hasAllInputs(recipe) && canFitStack(recipe.getOutputs().get(0), outputStackSlot, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if BlockEntity has all necessary inputs for recipe provided
|
||||
*
|
||||
*
|
||||
* @param recipeType RebornRecipe Recipe to check inputs
|
||||
* @return Boolean True if reactor has all inputs for recipe
|
||||
*/
|
||||
|
@ -199,10 +173,10 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Decrease stack size on the given slot according to recipe input
|
||||
*
|
||||
*
|
||||
* @param slot int Slot number
|
||||
*/
|
||||
private void useInput(int slot) {
|
||||
|
@ -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
|
||||
if(checkNBTRecipe) {
|
||||
if (checkNBTRecipe) {
|
||||
checkNBTRecipe = false;
|
||||
for (final RebornRecipe reactorRecipe : ModRecipes.FUSION_REACTOR.getRecipes(getWorld())) {
|
||||
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.
|
||||
return;
|
||||
}
|
||||
|
@ -245,11 +219,10 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
|
|||
|
||||
// Force check every second
|
||||
if (world.getTime() % 20 == 0) {
|
||||
checkCoils();
|
||||
inventory.setChanged();
|
||||
}
|
||||
|
||||
if (coilCount == 0) {
|
||||
if (!isMultiblockValid()) {
|
||||
resetCrafter();
|
||||
return;
|
||||
}
|
||||
|
@ -314,7 +287,7 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
|
|||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -355,10 +328,10 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
|
|||
this.crafingTickTime = tagCompound.getInt("crafingTickTime");
|
||||
this.neededPower = tagCompound.getInt("neededPower");
|
||||
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;
|
||||
}
|
||||
if(tagCompound.contains("size")){
|
||||
if (tagCompound.contains("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.
|
||||
|
@ -375,24 +348,11 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
|
|||
return tagCompound;
|
||||
}
|
||||
|
||||
// TileLegacyMachineBase
|
||||
@Override
|
||||
public void onLoad() {
|
||||
super.onLoad();
|
||||
this.checkCoils();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeUpgraded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// IToolDrop
|
||||
@Override
|
||||
public ItemStack getToolDrop(PlayerEntity playerIn) {
|
||||
return TRContent.Machine.FUSION_CONTROL_COMPUTER.getStack();
|
||||
}
|
||||
|
||||
// ItemHandlerProvider
|
||||
@Override
|
||||
public RebornInventory<FusionControlComputerBlockEntity> getInventory() {
|
||||
|
@ -404,7 +364,6 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
|
|||
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
|
||||
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()
|
||||
.sync(this::getCoilStatus, this::setCoilStatus)
|
||||
.sync(this::getCrafingTickTime, this::setCrafingTickTime)
|
||||
.sync(this::getSize, this::setSize)
|
||||
.sync(this::getState, this::setState)
|
||||
|
@ -414,14 +373,6 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
|
|||
.create(this, syncID);
|
||||
}
|
||||
|
||||
public int getCoilStatus() {
|
||||
return coilCount;
|
||||
}
|
||||
|
||||
public void setCoilStatus(int coilStatus) {
|
||||
this.coilCount = coilStatus;
|
||||
}
|
||||
|
||||
public int getCrafingTickTime() {
|
||||
return crafingTickTime;
|
||||
}
|
||||
|
@ -446,61 +397,61 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
|
|||
this.size = size;
|
||||
}
|
||||
|
||||
public void changeSize(int sizeDelta){
|
||||
public void changeSize(int sizeDelta) {
|
||||
int newSize = size + sizeDelta;
|
||||
this.size = Math.max(6, Math.min(TechRebornConfig.fusionControlComputerMaxCoilSize, newSize));
|
||||
}
|
||||
|
||||
public int getState(){
|
||||
if(currentRecipe == null ){
|
||||
public int getState() {
|
||||
if (currentRecipe == null) {
|
||||
return 0; //No Recipe
|
||||
}
|
||||
if(!hasStartedCrafting){
|
||||
if (!hasStartedCrafting) {
|
||||
return 1; //Waiting on power
|
||||
}
|
||||
return 2; //Crafting
|
||||
}
|
||||
|
||||
public void setState(int state){
|
||||
public void setState(int state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public Identifier getCurrentRecipeID() {
|
||||
if(currentRecipe == null) {
|
||||
if (currentRecipe == null) {
|
||||
return new Identifier("null", "null");
|
||||
}
|
||||
return currentRecipe.getId();
|
||||
}
|
||||
|
||||
public void setCurrentRecipeID(Identifier currentRecipeID) {
|
||||
if(currentRecipeID.getPath().equals("null")) {
|
||||
if (currentRecipeID.getPath().equals("null")) {
|
||||
currentRecipeID = null;
|
||||
}
|
||||
this.currentRecipeID = currentRecipeID;
|
||||
}
|
||||
|
||||
public FusionReactorRecipe getCurrentRecipeFromID() {
|
||||
if(currentRecipeID == null) return null;
|
||||
if (currentRecipeID == null) return null;
|
||||
return ModRecipes.FUSION_REACTOR.getRecipes(world).stream()
|
||||
.filter(recipe -> recipe.getId().equals(currentRecipeID))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public Text getStateText(){
|
||||
if(state == -1){
|
||||
public Text getStateText() {
|
||||
if (state == -1) {
|
||||
return LiteralText.EMPTY;
|
||||
} else if (state == 0){
|
||||
} else if (state == 0) {
|
||||
return new LiteralText("No recipe");
|
||||
} else if (state == 1){
|
||||
} else if (state == 1) {
|
||||
FusionReactorRecipe r = getCurrentRecipeFromID();
|
||||
if(r == null) {
|
||||
if (r == null) {
|
||||
return new LiteralText("Charging");
|
||||
}
|
||||
int percentage = percentage(r.getStartEnergy(), getEnergy());
|
||||
return new LiteralText("Charging (")
|
||||
.append(StringUtils.getPercentageText(percentage));
|
||||
} else if (state == 2){
|
||||
} else if (state == 2) {
|
||||
return new LiteralText("Crafting");
|
||||
}
|
||||
return LiteralText.EMPTY;
|
||||
|
|
|
@ -25,10 +25,11 @@
|
|||
package techreborn.blockentity.machine.multiblock;
|
||||
|
||||
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.builder.BuiltScreenHandler;
|
||||
import reborncore.client.screen.builder.ScreenHandlerBuilder;
|
||||
import reborncore.common.blockentity.MultiblockWriter;
|
||||
import reborncore.common.crafting.RebornRecipe;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
|
@ -40,34 +41,20 @@ import techreborn.init.TRContent;
|
|||
|
||||
public class ImplosionCompressorBlockEntity extends GenericMachineBlockEntity implements BuiltScreenHandlerProvider {
|
||||
|
||||
public MultiblockChecker multiblockChecker;
|
||||
|
||||
public ImplosionCompressorBlockEntity() {
|
||||
super(TRBlockEntities.IMPLOSION_COMPRESSOR, "ImplosionCompressor", TechRebornConfig.implosionCompressorMaxInput, TechRebornConfig.implosionCompressorMaxEnergy, TRContent.Machine.IMPLOSION_COMPRESSOR.block, 4);
|
||||
final int[] inputs = new int[] { 0, 1 };
|
||||
final int[] outputs = new int[] { 2, 3 };
|
||||
final int[] inputs = new int[]{0, 1};
|
||||
final int[] outputs = new int[]{2, 3};
|
||||
this.inventory = new RebornInventory<>(5, "ImplosionCompressorBlockEntity", 64, this);
|
||||
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
|
||||
public void tick() {
|
||||
if (multiblockChecker == null) {
|
||||
multiblockChecker = new MultiblockChecker(world, pos.down(3));
|
||||
}
|
||||
|
||||
super.tick();
|
||||
public void writeMultiblock(MultiblockWriter writer) {
|
||||
writer .translate(-1, -3, -1)
|
||||
.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());
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
|
@ -80,6 +67,6 @@ public class ImplosionCompressorBlockEntity extends GenericMachineBlockEntity im
|
|||
|
||||
@Override
|
||||
public boolean canCraft(RebornRecipe rebornRecipe) {
|
||||
return getMutliBlock();
|
||||
return isMultiblockValid();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,14 +24,18 @@
|
|||
|
||||
package techreborn.blockentity.machine.multiblock;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.BlockView;
|
||||
import reborncore.client.screen.BuiltScreenHandlerProvider;
|
||||
import reborncore.client.screen.builder.BuiltScreenHandler;
|
||||
import reborncore.client.screen.builder.ScreenHandlerBuilder;
|
||||
import reborncore.common.blockentity.MultiblockWriter;
|
||||
import reborncore.common.multiblock.IMultiblockPart;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
|
@ -44,24 +48,49 @@ import techreborn.init.TRBlockEntities;
|
|||
import techreborn.init.TRContent;
|
||||
import techreborn.multiblocks.MultiBlockCasing;
|
||||
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
public class IndustrialBlastFurnaceBlockEntity extends GenericMachineBlockEntity implements BuiltScreenHandlerProvider {
|
||||
|
||||
public MultiblockChecker multiblockChecker;
|
||||
private int cachedHeat;
|
||||
|
||||
public IndustrialBlastFurnaceBlockEntity() {
|
||||
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[] outputs = new int[] { 2, 3 };
|
||||
final int[] inputs = new int[]{0, 1};
|
||||
final int[] outputs = new int[]{2, 3};
|
||||
this.inventory = new RebornInventory<>(5, "IndustrialBlastFurnaceBlockEntity", 64, this);
|
||||
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() {
|
||||
if (!getMutliBlock()){
|
||||
if (!isMultiblockValid()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Bottom center of multiblock
|
||||
final BlockPos location = pos.offset(getFacing().getOpposite(), 2);
|
||||
final BlockEntity blockEntity = world.getBlockEntity(location);
|
||||
|
@ -93,22 +122,7 @@ public class IndustrialBlastFurnaceBlockEntity extends GenericMachineBlockEntity
|
|||
|
||||
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) {
|
||||
cachedHeat = heat;
|
||||
}
|
||||
|
@ -116,17 +130,7 @@ public class IndustrialBlastFurnaceBlockEntity extends GenericMachineBlockEntity
|
|||
public int getCachedHeat() {
|
||||
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
|
||||
@Override
|
||||
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
|
||||
|
|
|
@ -25,15 +25,15 @@
|
|||
package techreborn.blockentity.machine.multiblock;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.FluidBlock;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
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.builder.BuiltScreenHandler;
|
||||
import reborncore.client.screen.builder.ScreenHandlerBuilder;
|
||||
import reborncore.common.blockentity.MultiblockWriter;
|
||||
import reborncore.common.fluid.FluidValue;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
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 Tank tank;
|
||||
public MultiblockChecker multiblockChecker;
|
||||
int ticksSinceLastChange;
|
||||
|
||||
public IndustrialGrinderBlockEntity() {
|
||||
super(TRBlockEntities.INDUSTRIAL_GRINDER, "IndustrialGrinder", TechRebornConfig.industrialGrinderMaxInput, TechRebornConfig.industrialGrinderMaxEnergy, TRContent.Machine.INDUSTRIAL_GRINDER.block, 7);
|
||||
final int[] inputs = new int[] { 0, 1 };
|
||||
final int[] outputs = new int[] {2, 3, 4, 5};
|
||||
final int[] inputs = new int[]{0, 1};
|
||||
final int[] outputs = new int[]{2, 3, 4, 5};
|
||||
this.inventory = new RebornInventory<>(8, "IndustrialGrinderBlockEntity", 64, this);
|
||||
this.crafter = new RecipeCrafter(ModRecipes.INDUSTRIAL_GRINDER, this, 1, 4, this.inventory, inputs, outputs);
|
||||
this.tank = new Tank("IndustrialGrinderBlockEntity", IndustrialGrinderBlockEntity.TANK_CAPACITY, this);
|
||||
this.ticksSinceLastChange = 0;
|
||||
}
|
||||
|
||||
public boolean getMultiBlock() {
|
||||
if (multiblockChecker == null) {
|
||||
return false;
|
||||
}
|
||||
final boolean down = multiblockChecker.checkRectY(1, 1, MultiblockChecker.STANDARD_CASING, MultiblockChecker.ZERO_OFFSET);
|
||||
final boolean up = multiblockChecker.checkRectY(1, 1, MultiblockChecker.STANDARD_CASING, new BlockPos(0, 2, 0));
|
||||
final boolean blade = multiblockChecker.checkRingY(1, 1, MultiblockChecker.ADVANCED_CASING, new BlockPos(0, 1, 0));
|
||||
final BlockState centerBlock = multiblockChecker.getBlock(0, 1, 0);
|
||||
final boolean center = ((centerBlock.getBlock() instanceof FluidBlock
|
||||
|| centerBlock.getBlock() instanceof FluidBlock)
|
||||
&& centerBlock.getMaterial() == Material.WATER);
|
||||
return down && center && blade && up;
|
||||
@Override
|
||||
public void writeMultiblock(MultiblockWriter writer) {
|
||||
BlockState basic = TRContent.MachineBlocks.BASIC.getCasing().getDefaultState();
|
||||
BlockState advanced = TRContent.MachineBlocks.ADVANCED.getCasing().getDefaultState();
|
||||
writer .translate(1, -1, -1)
|
||||
.fill(0, 0, 0, 3, 1, 3, basic)
|
||||
.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())
|
||||
.fill(0, 2, 0, 3, 3, 3, basic);
|
||||
}
|
||||
|
||||
// TilePowerAcceptor
|
||||
@Override
|
||||
public void tick() {
|
||||
if (multiblockChecker == null) {
|
||||
final BlockPos downCenter = pos.offset(getFacing().getOpposite(), 2).offset(Direction.DOWN, 1);
|
||||
multiblockChecker = new MultiblockChecker(world, downCenter);
|
||||
}
|
||||
|
||||
ticksSinceLastChange++;
|
||||
// Check cells input slot 2 time per second
|
||||
if (!world.isClient && ticksSinceLastChange >= 10) {
|
||||
|
|
|
@ -25,15 +25,15 @@
|
|||
package techreborn.blockentity.machine.multiblock;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.FluidBlock;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
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.builder.BuiltScreenHandler;
|
||||
import reborncore.client.screen.builder.ScreenHandlerBuilder;
|
||||
import reborncore.common.blockentity.MultiblockWriter;
|
||||
import reborncore.common.fluid.FluidValue;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
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 Tank tank;
|
||||
public MultiblockChecker multiblockChecker;
|
||||
int ticksSinceLastChange;
|
||||
|
||||
public IndustrialSawmillBlockEntity() {
|
||||
super(TRBlockEntities.INDUSTRIAL_SAWMILL, "IndustrialSawmill", TechRebornConfig.industrialSawmillMaxInput, TechRebornConfig.industrialSawmillMaxEnergy, TRContent.Machine.INDUSTRIAL_SAWMILL.block, 6);
|
||||
final int[] inputs = new int[] { 0, 1 };
|
||||
final int[] outputs = new int[] { 2, 3, 4 };
|
||||
final int[] inputs = new int[]{0, 1};
|
||||
final int[] outputs = new int[]{2, 3, 4};
|
||||
this.inventory = new RebornInventory<>(7, "SawmillBlockEntity", 64, this);
|
||||
this.crafter = new RecipeCrafter(ModRecipes.INDUSTRIAL_SAWMILL, this, 1, 3, this.inventory, inputs, outputs);
|
||||
this.tank = new Tank("SawmillBlockEntity", IndustrialSawmillBlockEntity.TANK_CAPACITY, this);
|
||||
this.ticksSinceLastChange = 0;
|
||||
}
|
||||
|
||||
public boolean getMutliBlock() {
|
||||
if (multiblockChecker == null) {
|
||||
return false;
|
||||
}
|
||||
final boolean down = multiblockChecker.checkRectY(1, 1, MultiblockChecker.STANDARD_CASING, MultiblockChecker.ZERO_OFFSET);
|
||||
final boolean up = multiblockChecker.checkRectY(1, 1, MultiblockChecker.STANDARD_CASING, new BlockPos(0, 2, 0));
|
||||
final boolean blade = multiblockChecker.checkRingY(1, 1, MultiblockChecker.ADVANCED_CASING, new BlockPos(0, 1, 0));
|
||||
final BlockState centerBlock = multiblockChecker.getBlock(0, 1, 0);
|
||||
final boolean center = ((centerBlock.getBlock() instanceof FluidBlock
|
||||
|| centerBlock.getBlock() instanceof FluidBlock)
|
||||
&& centerBlock.getMaterial() == Material.WATER);
|
||||
return down && center && blade && up;
|
||||
@Override
|
||||
public void writeMultiblock(MultiblockWriter writer) {
|
||||
BlockState basic = TRContent.MachineBlocks.BASIC.getCasing().getDefaultState();
|
||||
BlockState advanced = TRContent.MachineBlocks.ADVANCED.getCasing().getDefaultState();
|
||||
writer .translate(1, -1, -1)
|
||||
.fill(0, 0, 0, 3, 1, 3, basic)
|
||||
.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())
|
||||
.fill(0, 2, 0, 3, 3, 3, basic);
|
||||
}
|
||||
|
||||
// TileGenericMachine
|
||||
@Override
|
||||
public void tick() {
|
||||
if (multiblockChecker == null) {
|
||||
final BlockPos downCenter = pos.offset(getFacing().getOpposite(), 2).offset(Direction.DOWN, 1);
|
||||
multiblockChecker = new MultiblockChecker(world, downCenter);
|
||||
}
|
||||
|
||||
ticksSinceLastChange++;
|
||||
// Check cells input slot 2 time per second
|
||||
if (!world.isClient && ticksSinceLastChange >= 10) {
|
||||
|
@ -99,7 +89,7 @@ public class IndustrialSawmillBlockEntity extends GenericMachineBlockEntity impl
|
|||
super.tick();
|
||||
|
||||
}
|
||||
|
||||
|
||||
// TilePowerAcceptor
|
||||
@Override
|
||||
public void fromTag(BlockState blockState, final CompoundTag tagCompound) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -24,12 +24,13 @@
|
|||
|
||||
package techreborn.blockentity.machine.multiblock;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
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.builder.BuiltScreenHandler;
|
||||
import reborncore.client.screen.builder.ScreenHandlerBuilder;
|
||||
import reborncore.common.blockentity.MultiblockWriter;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.blockentity.machine.GenericMachineBlockEntity;
|
||||
|
@ -40,31 +41,23 @@ import techreborn.init.TRContent;
|
|||
|
||||
public class VacuumFreezerBlockEntity extends GenericMachineBlockEntity implements BuiltScreenHandlerProvider {
|
||||
|
||||
public MultiblockChecker multiblockChecker;
|
||||
|
||||
public VacuumFreezerBlockEntity() {
|
||||
super(TRBlockEntities.VACUUM_FREEZER, "VacuumFreezer", TechRebornConfig.vacuumFreezerMaxInput, TechRebornConfig.vacuumFreezerMaxEnergy, TRContent.Machine.VACUUM_FREEZER.block, 2);
|
||||
final int[] inputs = new int[] { 0 };
|
||||
final int[] outputs = new int[] { 1 };
|
||||
final int[] inputs = new int[]{0};
|
||||
final int[] outputs = new int[]{1};
|
||||
this.inventory = new RebornInventory<>(3, "VacuumFreezerBlockEntity", 64, this);
|
||||
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
|
||||
public void cancelRemoval() {
|
||||
super.cancelRemoval();
|
||||
multiblockChecker = new MultiblockChecker(world, pos.offset(Direction.DOWN, 1));
|
||||
public void writeMultiblock(MultiblockWriter writer) {
|
||||
BlockState advanced = TRContent.MachineBlocks.ADVANCED.getCasing().getDefaultState();
|
||||
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
|
||||
|
|
|
@ -29,6 +29,7 @@ import net.minecraft.entity.player.PlayerEntity;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.state.property.IntProperty;
|
||||
import net.minecraft.state.property.Properties;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import reborncore.api.IToolDrop;
|
||||
|
@ -36,6 +37,7 @@ import reborncore.api.blockentity.InventoryProvider;
|
|||
import reborncore.client.screen.BuiltScreenHandlerProvider;
|
||||
import reborncore.client.screen.builder.BuiltScreenHandler;
|
||||
import reborncore.client.screen.builder.ScreenHandlerBuilder;
|
||||
import reborncore.common.blockentity.MultiblockWriter;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.util.ItemUtils;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
|
@ -50,31 +52,34 @@ import java.util.List;
|
|||
|
||||
public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
|
||||
implements IToolDrop, InventoryProvider, BuiltScreenHandlerProvider {
|
||||
|
||||
|
||||
private final RebornInventory<GreenhouseControllerBlockEntity> inventory = new RebornInventory<>(7, "GreenhouseControllerBlockEntity", 64, this);
|
||||
private BlockPos multiblockCenter;
|
||||
private int ticksToNextMultiblockCheck = 0;
|
||||
private boolean growthBoost = false;
|
||||
|
||||
|
||||
public GreenhouseControllerBlockEntity() {
|
||||
super(TRBlockEntities.GREENHOUSE_CONTROLLER);
|
||||
}
|
||||
|
||||
public boolean getMultiBlock() {
|
||||
if (multiblockCenter == null || world == null) {
|
||||
return false;
|
||||
}
|
||||
for (int i = -1; i <= 1; i++) {
|
||||
for (int j = -1; j <= 1; j++) {
|
||||
BlockState block = world.getBlockState(multiblockCenter.add(i * 3, 3, i * 3));
|
||||
if (!(block.getBlock() instanceof BlockLamp) || !BlockLamp.isActive(block)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeMultiblock(MultiblockWriter writer) {
|
||||
BlockState lamp = TRContent.Machine.LAMP_INCANDESCENT.block.getDefaultState().with(Properties.FACING, Direction.DOWN);
|
||||
BlockState crop = Blocks.CACTUS.getDefaultState();
|
||||
|
||||
for (int i = -1; i < 2; i++) {
|
||||
for (int j = -1; j < 2; j++) {
|
||||
writer.add(i * 3, 3, j * 3, (world, pos) -> BlockLamp.isActive(world.getBlockState(pos)), lamp);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
public void tick() {
|
||||
if (multiblockCenter == null) {
|
||||
|
@ -82,34 +87,34 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
|
|||
}
|
||||
charge(6);
|
||||
super.tick();
|
||||
|
||||
|
||||
if (world.isClient) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (useEnergy(getEuPerTick(TechRebornConfig.greenhouseControllerEnergyPerTick)) != getEuPerTick(TechRebornConfig.greenhouseControllerEnergyPerTick)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (--ticksToNextMultiblockCheck < 0) {
|
||||
growthBoost = getMultiBlock();
|
||||
growthBoost = isMultiblockValid();
|
||||
ticksToNextMultiblockCheck = 200;
|
||||
}
|
||||
|
||||
|
||||
if (world.getTime() % 20 == 0) {
|
||||
double cyclesLimit = getSpeedMultiplier() * 4 + 1;
|
||||
while (cyclesLimit-- > 0) {
|
||||
workCycle();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void workCycle() {
|
||||
BlockPos blockPos = multiblockCenter.add(world.random.nextInt(9) - 4, 0, world.random.nextInt(9) - 4);
|
||||
BlockState blockState = world.getBlockState(blockPos);
|
||||
Block block = blockState.getBlock();
|
||||
|
||||
|
||||
if (growthBoost) {
|
||||
if (block instanceof Fertilizable
|
||||
|| block instanceof PlantBlock
|
||||
|
@ -122,7 +127,7 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (block instanceof CropBlock) {
|
||||
processAgedCrop(blockState, blockPos, ((CropBlock) block).getAgeProperty(), ((CropBlock) block).getMaxAge(), 0);
|
||||
} else if (block instanceof NetherWartBlock) {
|
||||
|
@ -160,9 +165,9 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void processAgedCrop(BlockState blockState, BlockPos blockPos, IntProperty ageProperty, int maxAge, int newAge) {
|
||||
if (blockState.get(ageProperty) >= maxAge) {
|
||||
if (tryHarvestBlock(blockState, blockPos)) {
|
||||
|
@ -170,7 +175,7 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean tryHarvestBlock(BlockState blockState, BlockPos blockPos) {
|
||||
if (canUseEnergy(TechRebornConfig.greenhouseControllerEnergyPerHarvest)
|
||||
&& insertIntoInv(Block.getDroppedStacks(blockState, (ServerWorld) world, blockPos, null))) {
|
||||
|
@ -179,7 +184,7 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private boolean insertIntoInv(List<ItemStack> stacks) {
|
||||
boolean result = false;
|
||||
for (ItemStack stack : stacks) {
|
||||
|
@ -190,7 +195,7 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private boolean insertIntoInv(int slot, ItemStack stack) {
|
||||
ItemStack targetStack = inventory.getStack(slot);
|
||||
if (targetStack.isEmpty()) {
|
||||
|
@ -210,47 +215,42 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptEnergy(Direction direction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(Direction direction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double getBaseMaxPower() {
|
||||
return TechRebornConfig.greenhouseControllerMaxEnergy;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double getBaseMaxInput() {
|
||||
return TechRebornConfig.greenhouseControllerMaxInput;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ItemStack getToolDrop(PlayerEntity entityPlayer) {
|
||||
return TRContent.Machine.GREENHOUSE_CONTROLLER.getStack();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RebornInventory<GreenhouseControllerBlockEntity> getInventory() {
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canBeUpgraded() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BuiltScreenHandler createScreenHandler(int syncID, PlayerEntity player) {
|
||||
return new ScreenHandlerBuilder("greenhousecontroller").player(player.inventory).inventory().hotbar().addInventory()
|
||||
|
@ -261,5 +261,5 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
|
|||
.energySlot(6, 8, 72).syncEnergyValue()
|
||||
.addInventory().create(this, syncID);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue