Merge remote-tracking branch 'origin/1.16' into 1.16

# Conflicts:
#	src/main/java/techreborn/init/TRContent.java
This commit is contained in:
modmuss50 2020-07-25 00:23:59 +01:00
commit 18a08b798e
235 changed files with 3995 additions and 3065 deletions

View file

@ -49,7 +49,7 @@ repositories {
}
}
version = "3.4.2"
version = "3.4.3"
configurations {
shade
@ -80,7 +80,7 @@ dependencies {
//Fabric api
modImplementation "net.fabricmc.fabric-api:fabric-api:0.16.0+build.384-1.16.1"
optionalDependency ("me.shedaniel:RoughlyEnoughItems:4.5.4")
optionalDependency ("me.shedaniel:RoughlyEnoughItems:4.10.2")
disabledOptionalDependency ('io.github.cottonmc:LibCD:2.4.1+1.15.2')
disabledOptionalDependency ('com.github.emilyploszaj:trinkets:2.6.0')

View file

@ -148,6 +148,7 @@ public class TechRebornClient implements ClientModInitializer {
BlockRenderLayerMap.INSTANCE.putBlock(TRContent.Machine.ALARM.block, RenderLayer.getCutout());
BlockRenderLayerMap.INSTANCE.putBlock(TRContent.RUBBER_SAPLING, RenderLayer.getCutout());
BlockRenderLayerMap.INSTANCE.putBlock(TRContent.REINFORCED_GLASS, RenderLayer.getCutout());
BlockRenderLayerMap.INSTANCE.putBlock(TRContent.Machine.RESIN_BASIN.block, RenderLayer.getCutout());
BlockRenderLayerMap.INSTANCE.putBlock(TRContent.RUBBER_LEAVES, RenderLayer.getCutoutMipped());

View file

@ -36,7 +36,7 @@ public enum EFluidGenerator {
@Nonnull
private final String recipeID;
private EFluidGenerator(@Nonnull String recipeID) {
EFluidGenerator(@Nonnull String recipeID) {
this.recipeID = recipeID;
}

View file

@ -83,8 +83,6 @@ public class FluidGeneratorRecipe {
return false;
} else if (!FluidUtils.fluidEquals(other.fluid, fluid))
return false;
if (generatorType != other.generatorType)
return false;
return true;
return generatorType == other.generatorType;
}
}

View file

@ -83,10 +83,7 @@ public class FluidGeneratorRecipeList {
return false;
FluidGeneratorRecipeList other = (FluidGeneratorRecipeList) obj;
if (recipes == null) {
if (other.recipes != null)
return false;
} else if (!recipes.equals(other.recipes))
return false;
return true;
return other.recipes == null;
} else return recipes.equals(other.recipes);
}
}

View file

@ -25,7 +25,6 @@
package techreborn.api.generator;
import net.minecraft.fluid.Fluid;
import java.util.EnumMap;

View file

@ -34,7 +34,6 @@ import java.util.List;
/**
* @author drcrazy
*
*/
public class ScrapboxRecipeCrafter extends RecipeCrafter {
@ -49,9 +48,9 @@ public class ScrapboxRecipeCrafter extends RecipeCrafter {
}
@Override
public void updateCurrentRecipe(){
public void updateCurrentRecipe() {
List<RebornRecipe> scrapboxRecipeList = ModRecipes.SCRAPBOX.getRecipes(blockEntity.getWorld());
if(scrapboxRecipeList.isEmpty()){
if (scrapboxRecipeList.isEmpty()) {
setCurrentRecipe(null);
return;
}
@ -62,4 +61,4 @@ public class ScrapboxRecipeCrafter extends RecipeCrafter {
this.currentTickTime = 0;
setIsActive();
}
}
}

View file

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

View file

@ -37,7 +37,6 @@ import techreborn.blockentity.machine.multiblock.FusionControlComputerBlockEntit
/**
* @author drcrazy
*
*/
public class FusionReactorRecipe extends RebornRecipe {
@ -54,7 +53,7 @@ public class FusionReactorRecipe extends RebornRecipe {
this.minSize = minSize;
}
public int getStartEnergy () {
public int getStartEnergy() {
return startE;
}

View file

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

View file

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

View file

@ -58,7 +58,7 @@ public class RollingMachineRecipe extends RebornRecipe {
@Override
public void deserialize(JsonObject jsonObject) {
if(jsonObject.has("shaped")) {
if (jsonObject.has("shaped")) {
JsonObject json = JsonHelper.getObject(jsonObject, "shaped");
shapedRecipe = RecipeSerializer.SHAPED.read(getId(), json);
} else {

View file

@ -143,13 +143,27 @@ public class CableBlockEntity extends BlockEntity
}
ArrayList<Pair<BlockEntity, Direction>> acceptors = new ArrayList<>();
ArrayList<CableBlockEntity> cables = new ArrayList<>();
for (Direction face : Direction.values()) {
BlockEntity blockEntity = world.getBlockEntity(pos.offset(face));
if (blockEntity != null && Energy.valid(blockEntity)) {
if (blockEntity instanceof CableBlockEntity && energy <= Energy.of(blockEntity).side(face).getEnergy()) {
if (blockEntity instanceof CableBlockEntity ) {
CableBlockEntity cableBlockEntity = (CableBlockEntity)blockEntity;
if(cableBlockEntity.getTier() == this.getTier()) {
// Only need ones with energy stores less than ours
if (cableBlockEntity.getEnergy() < this.getEnergy()) {
cables.add(cableBlockEntity);
}
continue;
}else if(energy <= Energy.of(blockEntity).side(face).getEnergy()){
continue;
}
}
if(Energy.of(blockEntity).side(face.getOpposite()).getMaxInput() > 0){
acceptors.add(Pair.of(blockEntity, face));
if (!sendingFace.contains(face)) {
@ -159,9 +173,7 @@ public class CableBlockEntity extends BlockEntity
}
}
if (acceptors.isEmpty()) {
return;
}
if (!acceptors.isEmpty()) {
Collections.shuffle(acceptors);
acceptors.forEach(pair -> {
@ -171,6 +183,19 @@ public class CableBlockEntity extends BlockEntity
});
}
// Distribute energy between cables (TODO DIRTY FIX, until we game network cables)
if(!cables.isEmpty()) {
cables.add(this);
double energyTotal = cables.stream().mapToDouble(CableBlockEntity::getEnergy).sum();
double energyPer = energyTotal / cables.size();
cables.forEach(cableBlockEntity -> cableBlockEntity.setEnergy(energyPer));
}
}
// IListInfoProvider
@Override
public void addInfo(List<Text> info, boolean isReal, boolean hasData) {
@ -223,6 +248,25 @@ public class CableBlockEntity extends BlockEntity
return energyOut;
}
public double addEnergy(double energyIn) {
if(this.isFull()){
return energyIn;
}
double maxStore = this.getMaxStoredPower();
if (energyIn + energy <= maxStore) {
setEnergy(energyIn + energy);
return 0;
}
// Can't fit energy fully, add part of it
double amountCanAdd = (maxStore - energy);
setEnergy(amountCanAdd + energy);
return energyIn - amountCanAdd;
}
public boolean canAcceptEnergy(EnergySide direction) {
if (sendingFace.contains(direction)) {
return false;
@ -230,6 +274,10 @@ public class CableBlockEntity extends BlockEntity
return getMaxStoredPower() != getEnergy();
}
public boolean isFull(){
return getMaxStoredPower() == getEnergy();
}
@Override
public double getMaxInput(EnergySide side) {
if(!canAcceptEnergy(side)) {

View file

@ -63,7 +63,7 @@ public class DataDrivenBEProvider extends BlockEntityType<DataDrivenBEProvider.D
private final List<DataDrivenSlot> slots;
public static DataDrivenBEProvider create(Block block, Identifier identifier){
public static DataDrivenBEProvider create(Block block, Identifier identifier) {
String location = String.format("%s/machines/%s.json", identifier.getNamespace(), identifier.getPath());
JsonObject jsonObject;
try {
@ -127,7 +127,7 @@ public class DataDrivenBEProvider extends BlockEntityType<DataDrivenBEProvider.D
@Override
public BuiltScreenHandler createScreenHandler(int syncID, PlayerEntity player) {
return provider.createScreenHandler(this,syncID, player);
return provider.createScreenHandler(this, syncID, player);
}
public DataDrivenBEProvider getProvider() {
@ -139,13 +139,13 @@ public class DataDrivenBEProvider extends BlockEntityType<DataDrivenBEProvider.D
return slots.stream().filter(slot -> slot.getType() == SlotType.ENERGY).findFirst().orElse(null).getId();
}
private int countOfSlotType(SlotType type){
private int countOfSlotType(SlotType type) {
return (int) slots.stream()
.filter(slot -> slot.getType() == type)
.count();
}
private int[] slotIds(SlotType type){
private int[] slotIds(SlotType type) {
return slots.stream()
.filter(slot -> slot.getType() == type)
.mapToInt(DataDrivenSlot::getId)
@ -156,7 +156,7 @@ public class DataDrivenBEProvider extends BlockEntityType<DataDrivenBEProvider.D
return Collections.unmodifiableList(slots);
}
private String getSimpleName(){
private String getSimpleName() {
return WordUtils.capitalize(identifier.getPath());
}
}

View file

@ -41,7 +41,7 @@ import java.util.stream.Collectors;
public class DataDrivenSlot {
public static List<DataDrivenSlot> read(JsonArray jsonArray){
public static List<DataDrivenSlot> read(JsonArray jsonArray) {
AtomicInteger idCount = new AtomicInteger();
return SerializationUtil.stream(jsonArray)
.map(JsonElement::getAsJsonObject)
@ -78,14 +78,14 @@ public class DataDrivenSlot {
return type;
}
public void add(BlockEntityScreenHandlerBuilder inventoryBuilder){
public void add(BlockEntityScreenHandlerBuilder inventoryBuilder) {
type.getSlotBiConsumer().accept(inventoryBuilder, this);
}
@Environment(EnvType.CLIENT)
public void draw(MatrixStack matrixStack, GuiBase<?> guiBase, GuiBase.Layer layer){
public void draw(MatrixStack matrixStack, GuiBase<?> guiBase, GuiBase.Layer layer) {
//TODO find a better way to do this
if(getType() == SlotType.OUTPUT){
if (getType() == SlotType.OUTPUT) {
guiBase.drawOutputSlot(matrixStack, getX(), getY(), layer);
} else {
guiBase.drawSlot(matrixStack, getX(), getY(), layer);

View file

@ -41,14 +41,14 @@ public enum SlotType {
builder.energySlot(slot.getId(), slot.getX(), slot.getY());
});
public static SlotType fromString(String string){
public static SlotType fromString(String string) {
return Arrays.stream(values())
.filter(slotType -> slotType.name().equalsIgnoreCase(string))
.findFirst()
.orElse(null);
}
private BiConsumer<BlockEntityScreenHandlerBuilder, DataDrivenSlot> slotBiConsumer;
private final BiConsumer<BlockEntityScreenHandlerBuilder, DataDrivenSlot> slotBiConsumer;
SlotType(BiConsumer<BlockEntityScreenHandlerBuilder, DataDrivenSlot> slotBiConsumer) {
this.slotBiConsumer = slotBiConsumer;

View file

@ -79,7 +79,7 @@ public abstract class BaseFluidGeneratorBlockEntity extends PowerAcceptorBlockEn
super.tick();
ticksSinceLastChange++;
if(world.isClient){
if (world.isClient) {
return;
}
@ -89,8 +89,7 @@ public abstract class BaseFluidGeneratorBlockEntity extends PowerAcceptorBlockEn
if (!inputStack.isEmpty()) {
if (FluidUtils.isContainerEmpty(inputStack) && !tank.getFluidAmount().isEmpty()) {
FluidUtils.fillContainers(tank, inventory, 0, 1, tank.getFluid());
}
else if (inputStack.getItem() instanceof ItemFluidInfo && getRecipes().getRecipeForFluid(((ItemFluidInfo) inputStack.getItem()).getFluid(inputStack)).isPresent()) {
} else if (inputStack.getItem() instanceof ItemFluidInfo && getRecipes().getRecipeForFluid(((ItemFluidInfo) inputStack.getItem()).getFluid(inputStack)).isPresent()) {
FluidUtils.drainContainers(tank, inventory, 0, 1);
}
}
@ -118,14 +117,13 @@ public abstract class BaseFluidGeneratorBlockEntity extends PowerAcceptorBlockEn
if (world.getTime() - lastOutput < 30 && !isActive()) {
world.setBlockState(pos, world.getBlockState(pos).with(BlockMachineBase.ACTIVE, true));
}
else if (world.getTime() - lastOutput > 30 && isActive()) {
} else if (world.getTime() - lastOutput > 30 && isActive()) {
world.setBlockState(pos, world.getBlockState(pos).with(BlockMachineBase.ACTIVE, false));
}
}
public int getProgressScaled(int scale) {
if (isActive()){
if (isActive()) {
return ticksSinceLastChange * scale;
}
return 0;
@ -207,11 +205,11 @@ public abstract class BaseFluidGeneratorBlockEntity extends PowerAcceptorBlockEn
this.ticksSinceLastChange = ticksSinceLastChange;
}
public FluidValue getTankAmount(){
public FluidValue getTankAmount() {
return tank.getFluidAmount();
}
public void setTankAmount(FluidValue amount){
public void setTankAmount(FluidValue amount) {
tank.setFluidAmount(amount);
}

View file

@ -54,10 +54,12 @@ public class LightningRodBlockEntity extends PowerAcceptorBlockEntity implements
public void tick() {
super.tick();
if (onStatusHoldTicks > 0) { --onStatusHoldTicks; }
if (onStatusHoldTicks > 0) {
--onStatusHoldTicks;
}
Block BEBlock = getCachedState().getBlock();
if (! (BEBlock instanceof BlockMachineBase)) {
if (!(BEBlock instanceof BlockMachineBase)) {
return;
}
@ -83,7 +85,7 @@ public class LightningRodBlockEntity extends PowerAcceptorBlockEntity implements
lightningBolt.method_29495(Vec3d.ofBottomCenter(world.getTopPosition(Heightmap.Type.MOTION_BLOCKING, getPos())));
if (!world.isClient) {
((ServerWorld) world).spawnEntity(lightningBolt);
world.spawnEntity(lightningBolt);
}
addEnergy(TechRebornConfig.lightningRodBaseEnergyStrike * (0.3F + weatherStrength));
machineBaseBlock.setActive(true, world, pos);
@ -110,10 +112,7 @@ public class LightningRodBlockEntity extends PowerAcceptorBlockEntity implements
public boolean isValidIronFence(int y) {
Block block = this.world.getBlockState(new BlockPos(pos.getX(), y, pos.getZ())).getBlock();
if(block == TRContent.REFINED_IRON_FENCE){
return true;
}
return false;
return block == TRContent.REFINED_IRON_FENCE;
}
@Override

View file

@ -26,7 +26,6 @@ package techreborn.blockentity.generator;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
@ -151,7 +150,7 @@ public class SolarPanelBlockEntity extends PowerAcceptorBlockEntity implements I
public void tick() {
super.tick();
if (world == null){
if (world == null) {
return;
}
@ -191,7 +190,7 @@ public class SolarPanelBlockEntity extends PowerAcceptorBlockEntity implements I
@Override
public double getBaseMaxOutput() {
if (getPanel() == TRContent.SolarPanels.CREATIVE){
if (getPanel() == TRContent.SolarPanels.CREATIVE) {
return EnergyTier.INSANE.getMaxOutput();
}
// Solar panel output will only be limited by the cables the users use

View file

@ -64,11 +64,11 @@ public class SolidFuelGeneratorBlockEntity extends PowerAcceptorBlockEntity impl
}
public static int getItemBurnTime(@Nonnull ItemStack stack) {
if (stack.isEmpty()){
if (stack.isEmpty()) {
return 0;
}
Map<Item, Integer> burnMap = AbstractFurnaceBlockEntity.createFuelTimeMap();
if(burnMap.containsKey(stack.getItem())){
if (burnMap.containsKey(stack.getItem())) {
return burnMap.get(stack.getItem()) / 4;
}
return 0;

View file

@ -55,8 +55,7 @@ public class WaterMillBlockEntity extends PowerAcceptorBlockEntity implements IT
if (waterblocks > 0) {
addEnergy(waterblocks * TechRebornConfig.waterMillEnergyMultiplier);
world.setBlockState(pos, world.getBlockState(pos).with(BlockMachineBase.ACTIVE, true));
}
else {
} else {
world.setBlockState(pos, world.getBlockState(pos).with(BlockMachineBase.ACTIVE, false));
}
}

View file

@ -52,7 +52,7 @@ public class WindMillBlockEntity extends PowerAcceptorBlockEntity implements ITo
boolean generating = pos.getY() > 64;
if(world.isClient) {
if (world.isClient) {
bladeAngle += spinSpeed;
if (generating) {

View file

@ -37,7 +37,7 @@ import techreborn.init.TRBlockEntities;
public class LampBlockEntity extends PowerAcceptorBlockEntity
implements IToolDrop {
private static int capacity = 33;
private static final int capacity = 33;
public LampBlockEntity() {
super(TRBlockEntities.LAMP);

View file

@ -38,10 +38,9 @@ import reborncore.common.util.RebornInventory;
/**
* @author drcrazy
*
*/
public abstract class GenericMachineBlockEntity extends PowerAcceptorBlockEntity
implements IToolDrop, InventoryProvider, IRecipeCrafterProvider{
implements IToolDrop, InventoryProvider, IRecipeCrafterProvider {
public String name;
public int maxInput;
@ -79,7 +78,7 @@ public abstract class GenericMachineBlockEntity extends PowerAcceptorBlockEntity
@Override
public void tick() {
super.tick();
if (!world.isClient) {
if (!world.isClient && energySlot != -1) {
charge(energySlot);
}
}

View file

@ -60,6 +60,7 @@ public abstract class AbstractIronMachineBlockEntity extends MachineBaseBlockEnt
/**
* Checks that we have all inputs and can put output into slot
*
* @return
*/
protected abstract boolean canSmelt();
@ -73,6 +74,7 @@ public abstract class AbstractIronMachineBlockEntity extends MachineBaseBlockEnt
/**
* Returns the number of ticks that the supplied fuel item will keep the
* furnace burning, or 0 if the item isn't fuel
*
* @param stack Itemstack of fuel
* @return Integer Number of ticks
*/
@ -85,6 +87,7 @@ public abstract class AbstractIronMachineBlockEntity extends MachineBaseBlockEnt
/**
* Returns remaining fraction of fuel burn time
*
* @param scale Scale to use for burn time
* @return int scaled remaining fuel burn time
*/
@ -98,6 +101,7 @@ public abstract class AbstractIronMachineBlockEntity extends MachineBaseBlockEnt
/**
* Returns crafting progress
*
* @param scale Scale to use for crafting progress
* @return int Scaled crafting progress
*/
@ -110,6 +114,7 @@ public abstract class AbstractIronMachineBlockEntity extends MachineBaseBlockEnt
/**
* Returns true if Iron Machine is burning fuel thus can do work
*
* @return Boolean True if machine is burning
*/
public boolean isBurning() {
@ -146,7 +151,7 @@ public abstract class AbstractIronMachineBlockEntity extends MachineBaseBlockEnt
@Override
public void tick() {
super.tick();
if(world.isClient){
if (world.isClient) {
return;
}
boolean isBurning = isBurning();
@ -175,7 +180,7 @@ public abstract class AbstractIronMachineBlockEntity extends MachineBaseBlockEnt
progress = 0;
smelt();
}
} else if(!canSmelt()) {
} else if (!canSmelt()) {
progress = 0;
}

View file

@ -87,7 +87,7 @@ public class AlarmBlockEntity extends BlockEntity
// ITickable
@Override
public void tick() {
if (world.isClient()){
if (world.isClient()) {
return;
}
if (world.getTime() % 25 != 0) {

View file

@ -53,7 +53,7 @@ public class ChargeOMatBlockEntity extends PowerAcceptorBlockEntity
public void tick() {
super.tick();
if(world.isClient){
if (world.isClient) {
return;
}
for (int i = 0; i < 6; i++) {

View file

@ -43,7 +43,7 @@ public class DrainBlockEntity extends MachineBaseBlockEntity {
protected Tank internalTank = new Tank("tank", FluidValue.BUCKET, this);
public DrainBlockEntity(){
public DrainBlockEntity() {
this(TRBlockEntities.DRAIN);
}
@ -54,13 +54,13 @@ public class DrainBlockEntity extends MachineBaseBlockEntity {
@Override
public void tick() {
super.tick();
if(world.isClient){
if (world.isClient) {
return;
}
if (world.getTime() % 10 == 0) {
if(internalTank.isEmpty()) {
if (internalTank.isEmpty()) {
tryDrain();
}
}
@ -72,7 +72,7 @@ public class DrainBlockEntity extends MachineBaseBlockEntity {
return internalTank;
}
private void tryDrain(){
private void tryDrain() {
// Position above drain
BlockPos above = this.getPos().up();

View file

@ -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();
}
}

View file

@ -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) {
@ -95,7 +87,7 @@ public class FluidReplicatorBlockEntity extends GenericMachineBlockEntity implem
@Override
public RecipeCrafter getRecipeCrafter() {
return (RecipeCrafter) crafter;
return crafter;
}
// TilePowerAcceptor
@ -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;

View file

@ -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));
}
/**
@ -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;

View file

@ -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();
}
}

View file

@ -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,21 +48,46 @@ 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;
}
@ -94,21 +123,6 @@ 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;
}
@ -117,16 +131,6 @@ public class IndustrialBlastFurnaceBlockEntity extends GenericMachineBlockEntity
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) {

View file

@ -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) {

View file

@ -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) {

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,14 @@
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.crafting.RebornRecipe;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.RebornInventory;
import techreborn.blockentity.machine.GenericMachineBlockEntity;
@ -40,31 +42,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
@ -74,4 +68,13 @@ public class VacuumFreezerBlockEntity extends GenericMachineBlockEntity implemen
.blockEntity(this).slot(0, 55, 45).outputSlot(1, 101, 45).energySlot(2, 8, 72).syncEnergyValue()
.syncCrafterValue().addInventory().create(this, syncID);
}
@Override
public boolean canCraft(RebornRecipe rebornRecipe) {
if (!this.isMultiblockValid()) {
return false;
}
return super.canCraft(rebornRecipe);
}
}

View file

@ -40,8 +40,8 @@ public class AlloySmelterBlockEntity extends GenericMachineBlockEntity implement
public AlloySmelterBlockEntity() {
super(TRBlockEntities.ALLOY_SMELTER, "AlloySmelter", TechRebornConfig.alloySmelterMaxInput, TechRebornConfig.alloySmelterMaxEnergy, TRContent.Machine.ALLOY_SMELTER.block, 3);
final int[] inputs = new int[] { 0, 1 };
final int[] outputs = new int[] { 2 };
final int[] inputs = new int[]{0, 1};
final int[] outputs = new int[]{2};
this.inventory = new RebornInventory<>(4, "AlloySmelterBlockEntity", 64, this);
this.crafter = new RecipeCrafter(ModRecipes.ALLOY_SMELTER, this, 2, 1, this.inventory, inputs, outputs);
}

View file

@ -40,8 +40,8 @@ public class AssemblingMachineBlockEntity extends GenericMachineBlockEntity impl
public AssemblingMachineBlockEntity() {
super(TRBlockEntities.ASSEMBLY_MACHINE, "AssemblingMachine", TechRebornConfig.assemblingMachineMaxInput, TechRebornConfig.assemblingMachineMaxEnergy, TRContent.Machine.ASSEMBLY_MACHINE.block, 3);
final int[] inputs = new int[] { 0, 1 };
final int[] outputs = new int[] { 2 };
final int[] inputs = new int[]{0, 1};
final int[] outputs = new int[]{2};
this.inventory = new RebornInventory<>(4, "AssemblingMachineBlockEntity", 64, this);
this.crafter = new RecipeCrafter(ModRecipes.ASSEMBLING_MACHINE, this, 2, 2, this.inventory, inputs, outputs);
}

View file

@ -127,7 +127,7 @@ public class AutoCraftingTableBlockEntity extends PowerAcceptorBlockEntity
if (ingredient != Ingredient.EMPTY && !(ingredient.test(ItemStack.EMPTY))) {
boolean foundIngredient = false;
for (int i = 0; i < 9; i++) {
if(checkedSlots.contains(i)) {
if (checkedSlots.contains(i)) {
continue;
}
ItemStack stack = inventory.getStack(i);
@ -150,9 +150,7 @@ public class AutoCraftingTableBlockEntity extends PowerAcceptorBlockEntity
}
}
if (!missingOutput) {
if (hasOutputSpace(recipe.getOutput(), 9)) {
return true;
}
return hasOutputSpace(recipe.getOutput(), 9);
}
return false;
}
@ -173,9 +171,7 @@ public class AutoCraftingTableBlockEntity extends PowerAcceptorBlockEntity
return true;
}
if (ItemUtils.isItemEqual(stack, output, true, true)) {
if (stack.getMaxCount() > stack.getCount() + output.getCount()) {
return true;
}
return stack.getMaxCount() > stack.getCount() + output.getCount();
}
return false;
}
@ -191,7 +187,7 @@ public class AutoCraftingTableBlockEntity extends PowerAcceptorBlockEntity
ItemStack bestSlot = inventory.getStack(i);
if (ingredient.test(bestSlot)) {
ItemStack remainderStack = getRemainderItem(bestSlot);
if(remainderStack.isEmpty()) {
if (remainderStack.isEmpty()) {
bestSlot.decrement(1);
} else {
inventory.setStack(i, remainderStack);
@ -202,7 +198,7 @@ public class AutoCraftingTableBlockEntity extends PowerAcceptorBlockEntity
ItemStack stack = inventory.getStack(j);
if (ingredient.test(stack)) {
ItemStack remainderStack = getRemainderItem(stack);
if(remainderStack.isEmpty()) {
if (remainderStack.isEmpty()) {
stack.decrement(1);
} else {
inventory.setStack(j, remainderStack);
@ -223,7 +219,7 @@ public class AutoCraftingTableBlockEntity extends PowerAcceptorBlockEntity
}
private ItemStack getRemainderItem(ItemStack stack) {
if(stack.getItem() instanceof ExtendedRecipeRemainder) {
if (stack.getItem() instanceof ExtendedRecipeRemainder) {
return ((ExtendedRecipeRemainder) stack.getItem()).getRemainderStack(stack);
} else if (stack.getItem().hasRecipeRemainder()) {
@ -310,7 +306,7 @@ public class AutoCraftingTableBlockEntity extends PowerAcceptorBlockEntity
List<Integer> possibleSlots = new ArrayList<>();
for (int s = 0; s < currentRecipe.getPreviewInputs().size(); s++) {
for (int i = 0; i < 9; i++) {
if(possibleSlots.contains(i)) {
if (possibleSlots.contains(i)) {
continue;
}
ItemStack stackInSlot = inventory.getStack(i);
@ -325,7 +321,7 @@ public class AutoCraftingTableBlockEntity extends PowerAcceptorBlockEntity
}
if(!possibleSlots.isEmpty()){
if (!possibleSlots.isEmpty()) {
int totalItems = possibleSlots.stream()
.mapToInt(value -> inventory.getStack(value).getCount()).sum();
int slots = possibleSlots.size();
@ -334,11 +330,11 @@ public class AutoCraftingTableBlockEntity extends PowerAcceptorBlockEntity
int[] split = new int[slots];
int remainder = totalItems % slots;
Arrays.fill(split, totalItems / slots);
while (remainder > 0){
while (remainder > 0) {
for (int i = 0; i < split.length; i++) {
if(remainder > 0){
split[i] +=1;
remainder --;
if (remainder > 0) {
split[i] += 1;
remainder--;
}
}
}
@ -350,7 +346,7 @@ public class AutoCraftingTableBlockEntity extends PowerAcceptorBlockEntity
boolean needsBalance = false;
for (int i = 0; i < split.length; i++) {
int required = split[i];
if(slotEnvTyperubution.contains(required)){
if (slotEnvTyperubution.contains(required)) {
//We need to remove the int, not at the int, this seems to work around that
slotEnvTyperubution.remove(new Integer(required));
} else {

View file

@ -40,8 +40,8 @@ public class ChemicalReactorBlockEntity extends GenericMachineBlockEntity implem
public ChemicalReactorBlockEntity() {
super(TRBlockEntities.CHEMICAL_REACTOR, "ChemicalReactor", TechRebornConfig.chemicalReactorMaxInput, TechRebornConfig.chemicalReactorMaxEnergy, TRContent.Machine.CHEMICAL_REACTOR.block, 3);
final int[] inputs = new int[] { 0, 1 };
final int[] outputs = new int[] { 2 };
final int[] inputs = new int[]{0, 1};
final int[] outputs = new int[]{2};
this.inventory = new RebornInventory<>(4, "ChemicalReactorBlockEntity", 64, this);
this.crafter = new RecipeCrafter(ModRecipes.CHEMICAL_REACTOR, this, 2, 2, this.inventory, inputs, outputs);
}

View file

@ -40,8 +40,8 @@ public class CompressorBlockEntity extends GenericMachineBlockEntity implements
public CompressorBlockEntity() {
super(TRBlockEntities.COMPRESSOR, "Compressor", TechRebornConfig.compressorMaxInput, TechRebornConfig.compressorMaxEnergy, TRContent.Machine.COMPRESSOR.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, "CompressorBlockEntity", 64, this);
this.crafter = new RecipeCrafter(ModRecipes.COMPRESSOR, this, 2, 1, this.inventory, inputs, outputs);
}

View file

@ -60,7 +60,7 @@ public class ElectricFurnaceBlockEntity extends PowerAcceptorBlockEntity
final int EnergyPerTick = 1;
public ElectricFurnaceBlockEntity() {
super(TRBlockEntities.ELECTRIC_FURNACE );
super(TRBlockEntities.ELECTRIC_FURNACE);
}
private void setInvDirty(boolean isDirty) {
@ -156,8 +156,7 @@ public class ElectricFurnaceBlockEntity extends PowerAcceptorBlockEntity
ItemStack outputStack = inventory.getStack(outputSlot);
if (outputStack.isEmpty()) {
inventory.setStack(outputSlot, recipe.getOutput().copy());
}
else {
} else {
// Just increment. We already checked stack match and stack size
outputStack.increment(1);
}
@ -187,6 +186,7 @@ public class ElectricFurnaceBlockEntity extends PowerAcceptorBlockEntity
public void setCookTimeTotal(int cookTimeTotal) {
this.cookTimeTotal = cookTimeTotal;
}
// TilePowerAcceptor
@Override
public void tick() {

View file

@ -40,8 +40,8 @@ public class ExtractorBlockEntity extends GenericMachineBlockEntity implements B
public ExtractorBlockEntity() {
super(TRBlockEntities.EXTRACTOR, "Extractor", TechRebornConfig.extractorMaxInput, TechRebornConfig.extractorMaxEnergy, TRContent.Machine.EXTRACTOR.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, "ExtractorBlockEntity", 64, this);
this.crafter = new RecipeCrafter(ModRecipes.EXTRACTOR, this, 2, 1, this.inventory, inputs, outputs);
}

View file

@ -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;
@ -60,19 +62,22 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
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
@ -92,7 +97,7 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
}
if (--ticksToNextMultiblockCheck < 0) {
growthBoost = getMultiBlock();
growthBoost = isMultiblockValid();
ticksToNextMultiblockCheck = 200;
}
@ -211,11 +216,6 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
return false;
}
@Override
public boolean canAcceptEnergy(Direction direction) {
return true;
}
@Override
public boolean canProvideEnergy(Direction direction) {
return false;

View file

@ -42,8 +42,8 @@ public class IndustrialElectrolyzerBlockEntity extends GenericMachineBlockEntity
public IndustrialElectrolyzerBlockEntity() {
super(TRBlockEntities.INDUSTRIAL_ELECTROLYZER, "IndustrialElectrolyzer", TechRebornConfig.industrialElectrolyzerMaxInput, TechRebornConfig.industrialElectrolyzerMaxEnergy, TRContent.Machine.INDUSTRIAL_ELECTROLYZER.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, "IndustrialElectrolyzerBlockEntity", 64, this);
this.crafter = new RecipeCrafter(ModRecipes.INDUSTRIAL_ELECTROLYZER, this, 2, 4, this.inventory, inputs, outputs);
}

View file

@ -60,7 +60,7 @@ public class PlayerDectectorBlockEntity extends PowerAcceptorBlockEntity impleme
boolean lastRedstone = redstone;
redstone = false;
if (canUseEnergy(TechRebornConfig.playerDetectorEuPerTick)) {
for(PlayerEntity player : world.getPlayers()){
for (PlayerEntity player : world.getPlayers()) {
if (player.distanceTo(player) <= 256.0D) {
PlayerDetectorType type = world.getBlockState(pos).get(BlockPlayerDetector.TYPE);
if (type == PlayerDetectorType.ALL) {// ALL

View file

@ -77,8 +77,7 @@ public class RecyclerBlockEntity extends PowerAcceptorBlockEntity
if (randomchance == 1) {
if (inventory.getStack(1).isEmpty()) {
inventory.setStack(1, itemstack.copy());
}
else {
} else {
inventory.getStack(1).increment(itemstack.getCount());
}
}
@ -86,16 +85,13 @@ public class RecyclerBlockEntity extends PowerAcceptorBlockEntity
}
public boolean canRecycle() {
return !inventory.getStack(0) .isEmpty() && hasSlotGotSpace(1);
return !inventory.getStack(0).isEmpty() && hasSlotGotSpace(1);
}
public boolean hasSlotGotSpace(int slot) {
if (inventory.getStack(slot).isEmpty()) {
return true;
} else if (inventory.getStack(slot).getCount() < inventory.getStack(slot).getMaxCount()) {
return true;
}
return false;
} else return inventory.getStack(slot).getCount() < inventory.getStack(slot).getMaxCount();
}
public boolean isBurning() {
@ -129,13 +125,12 @@ public class RecyclerBlockEntity extends PowerAcceptorBlockEntity
boolean updateInventory = false;
if (canRecycle() && !isBurning() && getEnergy() != 0) {
setBurning(true);
}
else if (isBurning()) {
} else if (isBurning()) {
if (useEnergy(getEuPerTick(cost)) != getEuPerTick(cost)) {
this.setBurning(false);
}
progress++;
if (progress >= Math.max((int) (time* (1.0 - getSpeedMultiplier())), 1)) {
if (progress >= Math.max((int) (time * (1.0 - getSpeedMultiplier())), 1)) {
progress = 0;
recycleItems();
updateInventory = true;

View file

@ -0,0 +1,248 @@
/*
* 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.tier1;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.HopperBlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.util.WorldUtils;
import techreborn.blocks.machine.tier1.ResinBasinBlock;
import techreborn.blocks.misc.BlockRubberLog;
import techreborn.config.TechRebornConfig;
import techreborn.init.ModSounds;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
import static reborncore.api.items.InventoryUtils.getInventoryAt;
public class ResinBasinBlockEntity extends MachineBaseBlockEntity {
private Direction direction = Direction.NORTH;
// State
private boolean isPouring = false;
private boolean isFull = false;
private int pouringTimer = 0;
public ResinBasinBlockEntity() {
super(TRBlockEntities.RESIN_BASIN);
}
@Override
public void tick() {
super.tick();
if (world == null || world.isClient) return;
boolean shouldUpdateState = false;
if (isPouring) {
pouringTimer--;
// Play pouring audio
if (world.getTime() % 20 == 0) {
world.playSound(null, pos, ModSounds.SAP_EXTRACT, SoundCategory.BLOCKS, 1F, 1F);
}
if (pouringTimer <= 0) {
isPouring = false;
isFull = true;
shouldUpdateState = true;
}
}
// Try and deposit
if (isFull) {
// Get inventory
Inventory invBelow = getInventoryBelow();
if (invBelow != null) {
ItemStack out = new ItemStack(TRContent.Parts.SAP, (Math.random() <= 0.5) ? 1 : 2);
out = HopperBlockEntity.transfer(null, invBelow, out, Direction.UP);
if (out.isEmpty()) {
// Successfully deposited
isFull = false;
shouldUpdateState = true;
}
}
}
boolean readyToHarvest = !isFull && !isPouring;
// Ensuring it's placed on a log
if ((readyToHarvest || world.getTime() % 20 == 0) && !validPlacement()) {
// Not placed on log, drop on ground
world.setBlockState(pos, Blocks.AIR.getDefaultState());
WorldUtils.dropItem(TRContent.Machine.RESIN_BASIN.asItem(), world, pos);
return;
}
if (readyToHarvest) {
// Check for rubber
if (world.getTime() % TechRebornConfig.checkForSapTime == 0) {
BlockPos targetRubber = getLogWithSap();
if (targetRubber != null) {
// We have a valid sap log, harvest it
world.setBlockState(targetRubber, world.getBlockState(targetRubber).with(BlockRubberLog.HAS_SAP, false).with(BlockRubberLog.SAP_SIDE, Direction.fromHorizontal(0)));
isPouring = true;
pouringTimer = TechRebornConfig.sapTimeTicks;
shouldUpdateState = true;
}
}
}
if (shouldUpdateState) {
setPouringState(isPouring);
setFullState(isFull);
}
}
@Override
public void onBreak(World world, PlayerEntity playerEntity, BlockPos blockPos, BlockState blockState) {
super.onBreak(world, playerEntity, blockPos, blockState);
// Drop a sap if full
if (this.isFull) {
ItemStack out = new ItemStack(TRContent.Parts.SAP, (Math.random() <= 0.6) ? 1 : 2);
WorldUtils.dropItem(out, world, pos);
}
}
@Override
public CompoundTag toTag(CompoundTag tagCompound) {
super.toTag(tagCompound);
return tagCompound;
}
@Override
public void fromTag(BlockState blockState, CompoundTag tagCompound) {
super.fromTag(blockState, tagCompound);
this.isFull = blockState.get(ResinBasinBlock.FULL);
if (blockState.get(ResinBasinBlock.POURING)) {
this.isPouring = true;
pouringTimer = TechRebornConfig.sapTimeTicks;
}
}
@Override
public void onLoad() {
super.onLoad();
if (world == null || world.isClient) return;
// Set facing
direction = world.getBlockState(pos).get(ResinBasinBlock.FACING).getOpposite();
}
private Inventory getInventoryBelow() {
return getInventoryAt(this.getWorld(), this.pos.offset(Direction.DOWN));
}
private boolean validPlacement() {
return world.getBlockState(this.pos.offset(direction)).getBlock() == TRContent.RUBBER_LOG;
}
private BlockPos getLogWithSap() {
// Checking origin block
BlockPos originPos = this.pos.offset(direction);
BlockState originState = world.getBlockState(originPos);
if (originState.get(BlockRubberLog.HAS_SAP)) {
return originPos;
}
boolean shouldExit = false;
BlockPos current = originPos;
// Progress Up
while (!shouldExit) {
current = current.offset(Direction.UP);
BlockState state = world.getBlockState(current);
if (state.getBlock() == TRContent.RUBBER_LOG) {
if (state.get(BlockRubberLog.HAS_SAP)) {
return current;
}
} else {
shouldExit = true;
}
}
current = originPos;
shouldExit = false;
// Progress Down
while (!shouldExit) {
current = current.offset(Direction.DOWN);
BlockState state = world.getBlockState(current);
if (state.getBlock() == TRContent.RUBBER_LOG) {
if (state.get(BlockRubberLog.HAS_SAP)) {
return current;
}
} else {
shouldExit = true;
}
}
// Could not find a rubber log with sap
return null;
}
private void setPouringState(boolean value) {
if (world != null) {
world.setBlockState(pos, world.getBlockState(pos).with(ResinBasinBlock.POURING, value));
}
}
private void setFullState(boolean value) {
if (world != null) {
world.setBlockState(pos, world.getBlockState(pos).with(ResinBasinBlock.FULL, value));
}
}
@Override
public boolean hasSlotConfig() {
return false;
}
@Override
public boolean canBeUpgraded() {
return false;
}
}

View file

@ -61,7 +61,7 @@ import java.util.stream.Collectors;
public class RollingMachineBlockEntity extends PowerAcceptorBlockEntity
implements IToolDrop, InventoryProvider, BuiltScreenHandlerProvider {
public int[] craftingSlots = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
public int[] craftingSlots = new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8};
private CraftingInventory craftCache;
public RebornInventory<RollingMachineBlockEntity> inventory = new RebornInventory<>(12, "RollingMachineBlockEntity", 64, this);
public boolean isRunning;
@ -69,7 +69,7 @@ public class RollingMachineBlockEntity extends PowerAcceptorBlockEntity
@Nonnull
public ItemStack currentRecipeOutput;
public RollingMachineRecipe currentRecipe;
private int outputSlot;
private final int outputSlot;
public boolean locked = false;
public int balanceSlot = 0;
@ -177,12 +177,12 @@ public class RollingMachineBlockEntity extends PowerAcceptorBlockEntity
}
public void setIsActive(boolean active) {
if (active == isRunning){
if (active == isRunning) {
return;
}
isRunning = active;
if (this.getWorld().getBlockState(this.getPos()).getBlock() instanceof BlockMachineBase) {
BlockMachineBase blockMachineBase = (BlockMachineBase)this.getWorld().getBlockState(this.getPos()).getBlock();
BlockMachineBase blockMachineBase = (BlockMachineBase) this.getWorld().getBlockState(this.getPos()).getBlock();
blockMachineBase.setActive(active, this.getWorld(), this.getPos());
}
this.getWorld().updateListeners(this.getPos(), this.getWorld().getBlockState(this.getPos()), this.getWorld().getBlockState(this.getPos()), 3);
@ -213,7 +213,7 @@ public class RollingMachineBlockEntity extends PowerAcceptorBlockEntity
List<Integer> possibleSlots = new ArrayList<>();
for (int s = 0; s < currentRecipe.getPreviewInputs().size(); s++) {
ItemStack stackInSlot = inventory.getStack(s);
Ingredient ingredient = (Ingredient) currentRecipe.getPreviewInputs().get(s);
Ingredient ingredient = currentRecipe.getPreviewInputs().get(s);
if (ingredient != Ingredient.EMPTY && ingredient.test(sourceStack)) {
if (stackInSlot.isEmpty()) {
possibleSlots.add(s);
@ -223,7 +223,7 @@ public class RollingMachineBlockEntity extends PowerAcceptorBlockEntity
}
}
if(!possibleSlots.isEmpty()){
if (!possibleSlots.isEmpty()) {
int totalItems = possibleSlots.stream()
.mapToInt(value -> inventory.getStack(value).getCount()).sum();
int slots = possibleSlots.size();
@ -232,11 +232,11 @@ public class RollingMachineBlockEntity extends PowerAcceptorBlockEntity
int[] split = new int[slots];
int remainder = totalItems % slots;
Arrays.fill(split, totalItems / slots);
while (remainder > 0){
while (remainder > 0) {
for (int i = 0; i < split.length; i++) {
if(remainder > 0){
split[i] +=1;
remainder --;
if (remainder > 0) {
split[i] += 1;
remainder--;
}
}
}
@ -248,7 +248,7 @@ public class RollingMachineBlockEntity extends PowerAcceptorBlockEntity
boolean needsBalance = false;
for (int i = 0; i < split.length; i++) {
int required = split[i];
if(slotEnvTyperubution.contains(required)){
if (slotEnvTyperubution.contains(required)) {
//We need to remove the int, not at the int, this seems to work around that
slotEnvTyperubution.remove(new Integer(required));
} else {
@ -322,13 +322,13 @@ public class RollingMachineBlockEntity extends PowerAcceptorBlockEntity
return ItemUtils.isItemEqual(stack, output, true, true);
}
public List<RollingMachineRecipe> getAllRecipe(World world){
public List<RollingMachineRecipe> getAllRecipe(World world) {
return ModRecipes.ROLLING_MACHINE.getRecipes(world);
}
public ItemStack findMatchingRecipeOutput(CraftingInventory inv, World world) {
RollingMachineRecipe recipe = findMatchingRecipe(inv, world);
if(recipe == null){
if (recipe == null) {
return ItemStack.EMPTY;
}
return recipe.getOutput();
@ -379,10 +379,10 @@ public class RollingMachineBlockEntity extends PowerAcceptorBlockEntity
}
public int getBurnTimeRemainingScaled(final int scale) {
if (tickTime == 0 || Math.max((int) (TechRebornConfig.rollingMachineRunTime* (1.0 - getSpeedMultiplier())), 1) == 0) {
if (tickTime == 0 || Math.max((int) (TechRebornConfig.rollingMachineRunTime * (1.0 - getSpeedMultiplier())), 1) == 0) {
return 0;
}
return tickTime * scale / Math.max((int) (TechRebornConfig.rollingMachineRunTime* (1.0 - getSpeedMultiplier())), 1);
return tickTime * scale / Math.max((int) (TechRebornConfig.rollingMachineRunTime * (1.0 - getSpeedMultiplier())), 1);
}
@Override
@ -409,8 +409,8 @@ public class RollingMachineBlockEntity extends PowerAcceptorBlockEntity
}
public int getProgressScaled(final int scale) {
if (tickTime != 0 && Math.max((int) (TechRebornConfig.rollingMachineRunTime* (1.0 - getSpeedMultiplier())), 1) != 0) {
return tickTime * scale / Math.max((int) (TechRebornConfig.rollingMachineRunTime* (1.0 - getSpeedMultiplier())), 1);
if (tickTime != 0 && Math.max((int) (TechRebornConfig.rollingMachineRunTime * (1.0 - getSpeedMultiplier())), 1) != 0) {
return tickTime * scale / Math.max((int) (TechRebornConfig.rollingMachineRunTime * (1.0 - getSpeedMultiplier())), 1);
}
return 0;
}

View file

@ -39,8 +39,8 @@ public class ScrapboxinatorBlockEntity extends GenericMachineBlockEntity impleme
public ScrapboxinatorBlockEntity() {
super(TRBlockEntities.SCRAPBOXINATOR, "Scrapboxinator", TechRebornConfig.scrapboxinatorMaxInput, TechRebornConfig.scrapboxinatorMaxEnergy, TRContent.Machine.SCRAPBOXINATOR.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, "ScrapboxinatorBlockEntity", 64, this);
this.crafter = new ScrapboxRecipeCrafter(this, this.inventory, inputs, outputs);
}

View file

@ -40,8 +40,8 @@ public class SoildCanningMachineBlockEntity extends GenericMachineBlockEntity im
public SoildCanningMachineBlockEntity() {
super(TRBlockEntities.SOLID_CANNING_MACHINE, "SolidCanningMachine", TechRebornConfig.solidCanningMachineMaxInput, TechRebornConfig.solidCanningMachineMaxEnergy, TRContent.Machine.SOLID_CANNING_MACHINE.block, 3);
final int[] inputs = new int[] { 0, 1 };
final int[] outputs = new int[] { 2 };
final int[] inputs = new int[]{0, 1};
final int[] outputs = new int[]{2};
this.inventory = new RebornInventory<>(4, "SolidCanningMachineBlockEntity", 64, this);
this.crafter = new RecipeCrafter(ModRecipes.SOLID_CANNING_MACHINE, this, 2, 1, this.inventory, inputs, outputs);
}

View file

@ -39,8 +39,8 @@ public class WireMillBlockEntity extends GenericMachineBlockEntity implements Bu
public WireMillBlockEntity() {
super(TRBlockEntities.WIRE_MILL, "WireMill", 32, 1000, TRContent.Machine.WIRE_MILL.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, "WireMillBlockEntity", 64, this);
this.crafter = new RecipeCrafter(ModRecipes.WIRE_MILL, this, 1, 1, this.inventory, inputs, outputs);
}

View file

@ -55,7 +55,7 @@ public class ChunkLoaderBlockEntity extends MachineBaseBlockEntity implements IT
private String ownerUdid;
public ChunkLoaderBlockEntity() {
super(TRBlockEntities.CHUNK_LOADER );
super(TRBlockEntities.CHUNK_LOADER);
this.radius = 1;
}
@ -71,7 +71,7 @@ public class ChunkLoaderBlockEntity extends MachineBaseBlockEntity implements IT
reload();
if(playerEntity != null){
if (playerEntity != null) {
ChunkLoaderManager manager = ChunkLoaderManager.get(getWorld());
manager.syncChunkLoaderToClient((ServerPlayerEntity) playerEntity, getPos());
}
@ -82,20 +82,20 @@ public class ChunkLoaderBlockEntity extends MachineBaseBlockEntity implements IT
return TRContent.Machine.CHUNK_LOADER.getStack();
}
private void reload(){
private void reload() {
unloadAll();
load();
}
private void load(){
private void load() {
ChunkLoaderManager manager = ChunkLoaderManager.get(getWorld());
ChunkPos rootPos = getChunkPos();
int loadRadius = radius -1;
int loadRadius = radius - 1;
for (int i = -loadRadius; i <= loadRadius; i++) {
for (int j = -loadRadius; j <= loadRadius; j++) {
ChunkPos loadPos = new ChunkPos(rootPos.x + i, rootPos.z + j);
if(!manager.isChunkLoaded(getWorld(), loadPos, getPos())){
if (!manager.isChunkLoaded(getWorld(), loadPos, getPos())) {
manager.loadChunk(getWorld(), loadPos, getPos(), ownerUdid);
}
}
@ -105,7 +105,7 @@ public class ChunkLoaderBlockEntity extends MachineBaseBlockEntity implements IT
@Override
public void onBreak(World world, PlayerEntity playerEntity, BlockPos blockPos, BlockState blockState) {
if(world.isClient){
if (world.isClient) {
return;
}
unloadAll();
@ -114,19 +114,19 @@ public class ChunkLoaderBlockEntity extends MachineBaseBlockEntity implements IT
@Override
public void onPlace(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
if(world.isClient){
if (world.isClient) {
return;
}
ownerUdid = placer.getUuidAsString();
reload();
}
private void unloadAll(){
private void unloadAll() {
ChunkLoaderManager manager = ChunkLoaderManager.get(world);
manager.unloadChunkLoader(world, getPos());
}
public ChunkPos getChunkPos(){
public ChunkPos getChunkPos() {
return new ChunkPos(getPos());
}
@ -144,7 +144,7 @@ public class ChunkLoaderBlockEntity extends MachineBaseBlockEntity implements IT
super.fromTag(blockState, nbttagcompound);
this.radius = nbttagcompound.getInt("radius");
this.ownerUdid = nbttagcompound.getString("ownerUdid");
if(!StringUtils.isBlank(ownerUdid)){
if (!StringUtils.isBlank(ownerUdid)) {
nbttagcompound.putString("ownerUdid", this.ownerUdid);
}
inventory.read(nbttagcompound);

View file

@ -48,8 +48,8 @@ public class IndustrialCentrifugeBlockEntity extends GenericMachineBlockEntity i
public IndustrialCentrifugeBlockEntity() {
super(TRBlockEntities.INDUSTRIAL_CENTRIFUGE, "IndustrialCentrifuge", TechRebornConfig.industrialCentrifugeMaxInput, TechRebornConfig.industrialCentrifugeMaxEnergy, TRContent.Machine.INDUSTRIAL_CENTRIFUGE.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, "IndustrialCentrifugeBlockEntity", 64, this);
this.crafter = new RecipeCrafter(ModRecipes.CENTRIFUGE, this, 2, 4, this.inventory, inputs, outputs);
}
@ -70,7 +70,7 @@ public class IndustrialCentrifugeBlockEntity extends GenericMachineBlockEntity i
@Override
public void addInfo(final List<Text> info, final boolean isReal, boolean hasData) {
super.addInfo(info, isReal, hasData);
if(Screen.hasControlDown()) {
if (Screen.hasControlDown()) {
info.add(new LiteralText("Round and round it goes"));
}
}

View file

@ -46,7 +46,7 @@ public class MatterFabricatorBlockEntity extends PowerAcceptorBlockEntity
private int amplifier = 0;
public MatterFabricatorBlockEntity() {
super(TRBlockEntities.MATTER_FABRICATOR );
super(TRBlockEntities.MATTER_FABRICATOR);
}
private boolean spaceForOutput() {
@ -76,8 +76,7 @@ public class MatterFabricatorBlockEntity extends PowerAcceptorBlockEntity
private void addOutputProducts(int slot) {
if (inventory.getStack(slot).isEmpty()) {
inventory.setStack(slot, TRContent.Parts.UU_MATTER.getStack());
}
else if (ItemUtils.isItemEqual(this.inventory.getStack(slot), TRContent.Parts.UU_MATTER.getStack(), true, true)) {
} else if (ItemUtils.isItemEqual(this.inventory.getStack(slot), TRContent.Parts.UU_MATTER.getStack(), true, true)) {
inventory.getStack(slot).setCount((Math.min(64, 1 + inventory.getStack(slot).getCount())));
}
}

View file

@ -49,19 +49,19 @@ public class AdjustableSUBlockEntity extends EnergyStorageBlockEntity implements
super(TRBlockEntities.ADJUSTABLE_SU, "ADJUSTABLE_SU", 4, TRContent.Machine.ADJUSTABLE_SU.block, EnergyTier.INSANE, TechRebornConfig.aesuMaxEnergy);
}
public int getMaxConfigOutput(){
public int getMaxConfigOutput() {
int extra = 0;
if(superconductors > 0){
if (superconductors > 0) {
extra = (int) Math.pow(2, (superconductors + 2)) * maxOutput;
}
return maxOutput + extra;
}
public void handleGuiInputFromClient(int id, boolean shift, boolean ctrl) {
if(shift){
if (shift) {
id *= 4;
}
if(ctrl){
if (ctrl) {
id *= 8;
}
@ -88,14 +88,14 @@ public class AdjustableSUBlockEntity extends EnergyStorageBlockEntity implements
@Override
public void tick() {
super.tick();
if (world == null){
if (world == null) {
return;
}
if (OUTPUT > getMaxConfigOutput()) {
OUTPUT = getMaxConfigOutput();
}
if(world.getTime() % 20 == 0){
if (world.getTime() % 20 == 0) {
checkTier();
}
}
@ -118,7 +118,7 @@ public class AdjustableSUBlockEntity extends EnergyStorageBlockEntity implements
@Override
public double getBaseMaxInput() {
//If we have super conductors increase the max input of the machine
if(getMaxConfigOutput() > maxOutput){
if (getMaxConfigOutput() > maxOutput) {
return getMaxConfigOutput();
}
return maxInput;

View file

@ -113,13 +113,15 @@ public class EnergyStorageBlockEntity extends PowerAcceptorBlockEntity
// MachineBaseBlockEntity
@Override
public void setFacing(Direction enumFacing) {
if (world == null) { return; }
if (world == null) {
return;
}
world.setBlockState(pos, world.getBlockState(pos).with(EnergyStorageBlock.FACING, enumFacing));
}
@Override
public Direction getFacingEnum() {
if(world == null){
if (world == null) {
return null;
}
Block block = world.getBlockState(pos).getBlock();

View file

@ -34,7 +34,6 @@ import techreborn.init.TRContent;
/**
* Created by modmuss50 on 14/03/2016.
*
*/
public class HighVoltageSUBlockEntity extends EnergyStorageBlockEntity implements BuiltScreenHandlerProvider {

View file

@ -34,7 +34,6 @@ import techreborn.init.TRContent;
/**
* Created by modmuss50 on 14/03/2016.
*
*/
public class MediumVoltageSUBlockEntity extends EnergyStorageBlockEntity implements BuiltScreenHandlerProvider {

View file

@ -42,11 +42,11 @@ public class IDSUManager extends PersistentState {
}
@Nonnull
public static IDSUPlayer getPlayer(World world, String uuid){
public static IDSUPlayer getPlayer(World world, String uuid) {
return get(world).getPlayer(uuid);
}
public static IDSUManager get(World world){
public static IDSUManager get(World world) {
ServerWorld serverWorld = (ServerWorld) world;
return serverWorld.getPersistentStateManager().getOrCreate(IDSUManager::new, KEY);
}
@ -54,13 +54,13 @@ public class IDSUManager extends PersistentState {
private final HashMap<String, IDSUPlayer> playerHashMap = new HashMap<>();
@Nonnull
public IDSUPlayer getPlayer(String uuid){
public IDSUPlayer getPlayer(String uuid) {
return playerHashMap.computeIfAbsent(uuid, s -> new IDSUPlayer());
}
@Override
public void fromTag(CompoundTag tag) {
for(String uuid : tag.getKeys()){
for (String uuid : tag.getKeys()) {
playerHashMap.put(uuid, new IDSUPlayer(tag.getCompound(uuid)));
}
}
@ -78,7 +78,7 @@ public class IDSUManager extends PersistentState {
private IDSUPlayer() {
}
private IDSUPlayer(CompoundTag compoundTag){
private IDSUPlayer(CompoundTag compoundTag) {
read(compoundTag);
}

View file

@ -54,7 +54,7 @@ public class InterdimensionalSUBlockEntity extends EnergyStorageBlockEntity impl
if (ownerUdid == null || ownerUdid.isEmpty()) {
return 0.0;
}
if(world.isClient){
if (world.isClient) {
return clientEnergy;
}
return IDSUManager.getPlayer(world, ownerUdid).getEnergy();
@ -65,7 +65,7 @@ public class InterdimensionalSUBlockEntity extends EnergyStorageBlockEntity impl
if (ownerUdid == null || ownerUdid.isEmpty()) {
return;
}
if(world.isClient){
if (world.isClient) {
clientEnergy = energy;
} else {
IDSUManager.getPlayer(world, ownerUdid).setEnergy(energy);
@ -77,7 +77,7 @@ public class InterdimensionalSUBlockEntity extends EnergyStorageBlockEntity impl
if (ownerUdid == null || ownerUdid.isEmpty()) {
return 0.0;
}
if(world.isClient){
if (world.isClient) {
throw new UnsupportedOperationException("cannot set energy on the client!");
}
double energy = IDSUManager.getPlayer(world, ownerUdid).getEnergy();
@ -95,7 +95,7 @@ public class InterdimensionalSUBlockEntity extends EnergyStorageBlockEntity impl
if (ownerUdid == null || ownerUdid.isEmpty()) {
return false;
}
if(world.isClient){
if (world.isClient) {
throw new UnsupportedOperationException("cannot set energy on the client!");
}
return input <= IDSUManager.getPlayer(world, ownerUdid).getEnergy();

View file

@ -43,7 +43,7 @@ import java.util.ArrayList;
public class LapotronicSUBlockEntity extends EnergyStorageBlockEntity implements BuiltScreenHandlerProvider {
private int connectedBlocks = 0;
private ArrayList<LesuNetwork> countedNetworks = new ArrayList<>();
private final ArrayList<LesuNetwork> countedNetworks = new ArrayList<>();
public LapotronicSUBlockEntity() {
super(TRBlockEntities.LAPOTRONIC_SU, "LESU", 2, TRContent.Machine.LAPOTRONIC_SU.block, EnergyTier.LOW, TechRebornConfig.lesuStoragePerBlock);
@ -51,22 +51,20 @@ public class LapotronicSUBlockEntity extends EnergyStorageBlockEntity implements
this.maxOutput = TechRebornConfig.lesuBaseOutput;
}
private void setMaxStorage(){
private void setMaxStorage() {
maxStorage = (connectedBlocks + 1) * TechRebornConfig.lesuStoragePerBlock;
if (maxStorage < 0 || maxStorage > Integer.MAX_VALUE) {
maxStorage = Integer.MAX_VALUE;
}
}
private void setIORate(){
private void setIORate() {
maxOutput = TechRebornConfig.lesuBaseOutput + (connectedBlocks * TechRebornConfig.lesuExtraIOPerBlock);
if (connectedBlocks < 32) {
return;
}
else if (connectedBlocks < 128) {
} else if (connectedBlocks < 128) {
maxInput = EnergyTier.MEDIUM.getMaxInput();
}
else {
} else {
maxInput = EnergyTier.HIGH.getMaxInput();
}
}

View file

@ -25,7 +25,6 @@
package techreborn.blockentity.storage.fluid;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;

View file

@ -25,7 +25,6 @@
package techreborn.blockentity.storage.item;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
@ -34,6 +33,7 @@ import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import reborncore.api.IListInfoProvider;
import reborncore.api.IToolDrop;
@ -48,22 +48,21 @@ import reborncore.common.util.WorldUtils;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
import javax.annotation.Nullable;
import java.util.List;
public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity
implements InventoryProvider, IToolDrop, IListInfoProvider, BuiltScreenHandlerProvider {
public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implements InventoryProvider, IToolDrop, IListInfoProvider, BuiltScreenHandlerProvider {
// Inventory constants
private static final int INPUT_SLOT = 0;
private static final int OUTPUT_SLOT = 1;
public static final int INPUT_SLOT = 0;
public static final int OUTPUT_SLOT = 1;
// Client sync variables for GUI, what and how much stored
public int storedAmount = 0;
protected RebornInventory<StorageUnitBaseBlockEntity> inventory;
private int maxCapacity;
private boolean shouldUpdate = true;
private int prevCount = -1;
private ItemStack storeItemStack;
private TRContent.StorageUnit type;
@ -93,45 +92,29 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity
@Override
public void tick() {
super.tick();
if (world.isClient) {
if (world == null || world.isClient) {
return;
}
// If there is an item in the input AND stored is less than max capacity
if (!inventory.getStack(INPUT_SLOT).isEmpty() && !isFull()) {
inventory.setStack(INPUT_SLOT, processInput(inventory.getStack(INPUT_SLOT)));
shouldUpdate = true;
}
// Fill output slot with goodies when stored has items and output count is less than max stack size
if (storeItemStack.getCount() > 0 && inventory.getStack(OUTPUT_SLOT).getCount() < getStoredStack().getMaxCount()) {
populateOutput();
shouldUpdate = true;
}
if (type == TRContent.StorageUnit.CREATIVE) {
if (!isFull() && !isEmpty()) {
fillToCapacity();
shouldUpdate = true;
}
}
// Update for locked item for clients
if(isLocked() && prevCount != this.getCurrentCapacity()){
prevCount = this.getCurrentCapacity();
if (inventory.hasChanged()) {
syncWithAll();
}
if (shouldUpdate) {
inventory.setChanged();
markDirty();
syncWithAll();
shouldUpdate = false;
inventory.resetChanged();
}
}
@ -171,6 +154,10 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity
return storeItemStack.isEmpty() ? inventory.getStack(OUTPUT_SLOT) : storeItemStack;
}
public void setStoredStack(ItemStack itemStack) {
storeItemStack = itemStack;
}
// Returns the ItemStack to be displayed to the player via UI / model
public ItemStack getDisplayedStack() {
if (!isLocked()) {
@ -192,15 +179,11 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity
return returnStack;
}
public void setStoredStack(ItemStack itemStack) {
storeItemStack = itemStack;
}
public ItemStack processInput(ItemStack inputStack) {
boolean isSameStack = isSameType(inputStack);
if (storeItemStack == ItemStack.EMPTY && (isSameStack || getCurrentCapacity() == 0)) {
if (storeItemStack == ItemStack.EMPTY && (isSameStack || (getCurrentCapacity() == 0 && !isLocked()))) {
// Check if storage is empty, NOT including the output slot
storeItemStack = inputStack.copy();
@ -229,6 +212,7 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity
}
}
inventory.setChanged();
return inputStack;
}
@ -259,6 +243,11 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity
return getCurrentCapacity() == 0;
}
@Override
public boolean canInsert(int index, ItemStack stack, @Nullable Direction direction) {
return super.canInsert(index, stack, direction) && (this.isEmpty() && !isLocked() || isSameType(stack));
}
public int getCurrentCapacity() {
return storeItemStack.getCount() + inventory.getStack(OUTPUT_SLOT).getCount();
}
@ -296,6 +285,11 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity
storeItemStack.setCount(Math.min(tagCompound.getInt("storedQuantity"), this.maxCapacity));
}
// Renderer only
if (tagCompound.contains("totalStoredAmount")) {
storedAmount = tagCompound.getInt("totalStoredAmount");
}
if (tagCompound.contains("lockedItem")) {
lockedItemStack = ItemStack.fromTag(tagCompound.getCompound("lockedItem"));
}
@ -320,6 +314,9 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity
tagCompound.putInt("storedQuantity", 0);
}
// Renderer only
tagCompound.putInt("totalStoredAmount", getCurrentCapacity());
if (isLocked()) {
tagCompound.put("lockedItem", lockedItemStack.toTag(new CompoundTag()));
}
@ -433,7 +430,9 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity
}
// Only set lockedItem in response to user input
lockedItemStack = value ? getStoredStack().copy() : ItemStack.EMPTY;
ItemStack stack = getStoredStack().copy();
stack.setCount(1);
lockedItemStack = value ? stack : ItemStack.EMPTY;
syncWithAll();
}
@ -447,11 +446,37 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity
return !isEmpty();
}
public int getStoredAmount() {
return this.getCurrentCapacity();
}
public void setStoredAmount(int storedAmount) {
this.storedAmount = storedAmount;
}
public void setStoredStackFromNBT(CompoundTag tag) {
storeItemStack = ItemStack.fromTag(tag);
}
public CompoundTag getStoredStackNBT() {
CompoundTag tag = new CompoundTag();
getStoredStack().toTag(tag);
return tag;
}
@Override
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity playerEntity) {
return new ScreenHandlerBuilder("chest").player(playerEntity.inventory).inventory().hotbar().addInventory()
.blockEntity(this).slot(0, 100, 53).outputSlot(1, 140, 53)
.sync(this::isLockedInt, this::setLockedInt).addInventory().create(this, syncID);
.blockEntity(this)
.slot(INPUT_SLOT, 100, 53)
.outputSlot(OUTPUT_SLOT, 140, 53)
.sync(this::isLockedInt, this::setLockedInt)
.sync(this::getStoredStackNBT, this::setStoredStackFromNBT)
.sync(this::getStoredAmount, this::setStoredAmount)
.addInventory().create(this, syncID);
// Note that inventory is synced, and it gets the stack from that
}
@Override

View file

@ -85,7 +85,7 @@ public class TransformerBlockEntity extends PowerAcceptorBlockEntity
@Override
public boolean canAcceptEnergy(Direction direction) {
if (TechRebornConfig.IC2TransformersStyle){
if (TechRebornConfig.IC2TransformersStyle) {
return getFacingEnum() == direction;
}
return getFacingEnum() != direction;
@ -93,7 +93,7 @@ public class TransformerBlockEntity extends PowerAcceptorBlockEntity
@Override
public boolean canProvideEnergy(Direction direction) {
if (TechRebornConfig.IC2TransformersStyle){
if (TechRebornConfig.IC2TransformersStyle) {
return getFacingEnum() != direction;
}
return getFacing() == direction;
@ -122,7 +122,7 @@ public class TransformerBlockEntity extends PowerAcceptorBlockEntity
// TileMachineBase
@Override
public Direction getFacingEnum() {
if(world == null){
if (world == null) {
return null;
}
Block block = world.getBlockState(pos).getBlock();

View file

@ -30,13 +30,12 @@ import techreborn.client.GuiType;
/**
* @author modmuss50
*
*/
public class DataDrivenMachineBlock extends GenericMachineBlock {
private final DataDrivenBEProvider provider;
public DataDrivenMachineBlock(String ident){
public DataDrivenMachineBlock(String ident) {
super(GuiType.DATA_DRIVEN, null);
provider = DataDrivenBEProvider.create(this, new Identifier(ident));
blockEntityClass = provider;

View file

@ -34,11 +34,10 @@ import java.util.function.Supplier;
/**
* @author drcrazy
*
*/
public class GenericMachineBlock extends BlockMachineBase {
private IMachineGuiHandler gui;
private final IMachineGuiHandler gui;
Supplier<BlockEntity> blockEntityClass;
public GenericMachineBlock(IMachineGuiHandler gui, Supplier<BlockEntity> blockEntityClass) {
@ -62,7 +61,6 @@ public class GenericMachineBlock extends BlockMachineBase {
}
@Override
public IMachineGuiHandler getGui() {
return gui;

View file

@ -56,8 +56,8 @@ public final class CableShapeUtil {
final VoxelShape baseShape = Block.createCuboidShape(size, size, size, 16.0D - size, 16.0D - size, 16.0D - size);
final List<VoxelShape> connections = new ArrayList<>();
for(Direction dir : Direction.values()){
if(state.get(CableBlock.PROPERTY_MAP.get(dir))) {
for (Direction dir : Direction.values()) {
if (state.get(CableBlock.PROPERTY_MAP.get(dir))) {
double x = dir == Direction.WEST ? 0 : dir == Direction.EAST ? 16D : size;
double z = dir == Direction.NORTH ? 0 : dir == Direction.SOUTH ? 16D : size;
double y = dir == Direction.DOWN ? 0 : dir == Direction.UP ? 16D : size;

View file

@ -52,27 +52,28 @@ public class BlockFusionControlComputer extends BlockMachineBase {
public ActionResult onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity playerIn,
Hand hand, BlockHitResult hitResult) {
final FusionControlComputerBlockEntity blockEntityFusionControlComputer = (FusionControlComputerBlockEntity) worldIn.getBlockEntity(pos);
if(!playerIn.getStackInHand(hand).isEmpty() && (playerIn.getStackInHand(hand).getItem() == TRContent.Machine.FUSION_COIL.asItem())){
if (!playerIn.getStackInHand(hand).isEmpty() && (playerIn.getStackInHand(hand).getItem() == TRContent.Machine.FUSION_COIL.asItem())) {
List<BlockPos> coils = Torus.generate(blockEntityFusionControlComputer.getPos(), blockEntityFusionControlComputer.size);
boolean placed = false;
for(BlockPos coil : coils){
if(playerIn.getStackInHand(hand).isEmpty()){
for (BlockPos coil : coils) {
if (playerIn.getStackInHand(hand).isEmpty()) {
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());
if(!playerIn.isCreative()){
if (!playerIn.isCreative()) {
playerIn.getStackInHand(hand).decrement(1);
}
placed = true;
}
}
if(placed){
if (placed) {
return ActionResult.SUCCESS;
}
}
blockEntityFusionControlComputer.checkCoils();
blockEntityFusionControlComputer.isMultiblockValid();
return super.onUse(state, worldIn, pos, playerIn, hand, hitResult);
}
@ -86,7 +87,7 @@ public class BlockFusionControlComputer extends BlockMachineBase {
super.onSteppedOn(worldIn, pos, entityIn);
if (worldIn.getBlockEntity(pos) instanceof FusionControlComputerBlockEntity) {
if (((FusionControlComputerBlockEntity) worldIn.getBlockEntity(pos)).crafingTickTime != 0
&& ((FusionControlComputerBlockEntity) worldIn.getBlockEntity(pos)).checkCoils()) {
&& ((FusionControlComputerBlockEntity) worldIn.getBlockEntity(pos)).isMultiblockValid()) {
entityIn.damage(new FusionDamageSource(), 200F);
}
}

View file

@ -55,7 +55,7 @@ public class BlockSolarPanel extends BlockMachineBase {
@Override
public IMachineGuiHandler getGui() {
if(this.panelType == SolarPanels.CREATIVE){
if (this.panelType == SolarPanels.CREATIVE) {
return null;
}
return GuiType.SOLAR_PANEL;

View file

@ -56,8 +56,8 @@ public class BlockLamp extends BaseBlockEntityProvider {
public static BooleanProperty ACTIVE;
protected final VoxelShape[] shape;
private int cost;
private static int brightness = 15;
private final int cost;
private static final int brightness = 15;
public BlockLamp(int cost, double depth, double width) {
super(FabricBlockSettings.of(Material.REDSTONE_LAMP).strength(2f, 2f).lightLevel(brightness));
@ -68,7 +68,7 @@ public class BlockLamp extends BaseBlockEntityProvider {
}
private VoxelShape[] genCuboidShapes(double depth, double width) {
double culling = (16.0D - width) / 2 ;
double culling = (16.0D - width) / 2;
return new VoxelShape[]{
createCuboidShape(culling, 16.0 - depth, culling, 16.0 - culling, 16.0D, 16.0 - culling),
createCuboidShape(culling, 0.0D, culling, 16.0D - culling, depth, 16.0 - culling),
@ -85,7 +85,7 @@ public class BlockLamp extends BaseBlockEntityProvider {
}
public static boolean isActive(BlockState state) {
return state.get(ACTIVE);
return state.contains(ACTIVE) && state.get(ACTIVE);
}
public static Direction getFacing(BlockState state) {
@ -97,7 +97,7 @@ public class BlockLamp extends BaseBlockEntityProvider {
}
public static void setActive(Boolean active, World world, BlockPos pos) {
Direction facing = (Direction)world.getBlockState(pos).get(FACING);
Direction facing = world.getBlockState(pos).get(FACING);
BlockState state = world.getBlockState(pos).with(ACTIVE, active).with(FACING, facing);
world.setBlockState(pos, state, 3);
}

View file

@ -59,7 +59,7 @@ public class IronAlloyFurnaceBlock extends GenericMachineBlock {
worldIn.playSound(x, y, z, SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, SoundCategory.BLOCKS, 1.0F, 1.0F, false);
}
Direction facing = (Direction) stateIn.get(FACING);
Direction facing = stateIn.get(FACING);
Direction.Axis facing$Axis = facing.getAxis();
double double_5 = rand.nextDouble() * 0.6D - 0.3D;
double deltaX = facing$Axis == Direction.Axis.X ? (double) facing.getOffsetX() * 0.52D : double_5;

View file

@ -59,7 +59,7 @@ public class IronFurnaceBlock extends GenericMachineBlock {
worldIn.playSound(x, y, z, SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, SoundCategory.BLOCKS, 1.0F, 1.0F, false);
}
Direction facing = (Direction) stateIn.get(FACING);
Direction facing = stateIn.get(FACING);
Direction.Axis facing$Axis = facing.getAxis();
double double_5 = rand.nextDouble() * 0.6D - 0.3D;
double deltaX = facing$Axis == Direction.Axis.X ? (double) facing.getOffsetX() * 0.52D : double_5;

View file

@ -177,7 +177,7 @@ public class BlockPlayerDetector extends BlockMachineBase {
private final String name;
private PlayerDetectorType(String name) {
PlayerDetectorType(String name) {
this.name = name;
}

View file

@ -0,0 +1,97 @@
package techreborn.blocks.machine.tier1;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import reborncore.common.BaseBlockEntityProvider;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.util.WorldUtils;
import techreborn.init.TRContent;
import java.util.UUID;
import java.util.function.Supplier;
public class ResinBasinBlock extends BaseBlockEntityProvider {
public static DirectionProperty FACING = Properties.HORIZONTAL_FACING;
public static BooleanProperty POURING = BooleanProperty.of("pouring");
public static BooleanProperty FULL = BooleanProperty.of("full");
Supplier<BlockEntity> blockEntityClass;
public ResinBasinBlock(Supplier<BlockEntity> blockEntityClass) {
super(Block.Settings.of(Material.WOOD).strength(2F, 2F));
this.blockEntityClass = blockEntityClass;
this.setDefaultState(
this.getStateManager().getDefaultState().with(FACING, Direction.NORTH).with(POURING, false).with(FULL, false));
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return VoxelShapes.cuboid(0, 0, 0, 1, 15 / 16f, 1);
}
public void setFacing(Direction facing, World world, BlockPos pos) {
world.setBlockState(pos, world.getBlockState(pos).with(FACING, facing));
}
// Block
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
FACING = DirectionProperty.of("facing", Direction.Type.HORIZONTAL);
POURING = BooleanProperty.of("pouring");
FULL = BooleanProperty.of("full");
builder.add(FACING, POURING, FULL);
}
public Direction getFacing(BlockState state) {
return state.get(FACING);
}
@Override
public void onPlaced(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
super.onPlaced(worldIn, pos, state, placer, stack);
if (worldIn.isClient) return;
Direction facing = placer.getHorizontalFacing().getOpposite();
setFacing(facing, worldIn, pos);
// Drop item if not next to log and yell at user
if (worldIn.getBlockState(pos.offset(facing.getOpposite())).getBlock() != TRContent.RUBBER_LOG) {
worldIn.setBlockState(pos, Blocks.AIR.getDefaultState());
WorldUtils.dropItem(this.asItem(), worldIn, pos);
placer.sendSystemMessage(new TranslatableText("techreborn.tooltip.invalid_basin_placement"), UUID.randomUUID());
}
}
@Override
public BlockEntity createBlockEntity(BlockView worldIn) {
if (blockEntityClass == null) {
return null;
}
return blockEntityClass.get();
}
@Override
public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof MachineBaseBlockEntity) {
((MachineBaseBlockEntity) blockEntity).onBreak(world, player, pos, state);
}
super.onBreak(world, pos, state, player);
}
}

View file

@ -67,7 +67,7 @@ public class BlockAlarm extends BaseBlockEntityProvider {
}
private VoxelShape[] GenCuboidShapes(double depth, double width) {
double culling = (16.0D - width) / 2 ;
double culling = (16.0D - width) / 2;
VoxelShape[] shapes = {
Block.createCuboidShape(culling, 16.0 - depth, culling, 16.0 - culling, 16.0D, 16.0 - culling),
Block.createCuboidShape(culling, 0.0D, culling, 16.0D - culling, depth, 16.0 - culling),
@ -84,7 +84,7 @@ public class BlockAlarm extends BaseBlockEntityProvider {
}
public static Direction getFacing(BlockState state) {
return (Direction) state.get(FACING);
return state.get(FACING);
}
public static void setFacing(Direction facing, World world, BlockPos pos) {

View file

@ -63,8 +63,7 @@ public class BlockComputerCube extends BlockMachineBase {
worldIn.setBlockState(pos, Blocks.AIR.getDefaultState(), 2);
}
return ActionResult.SUCCESS;
}
else {
} else {
rotate(worldIn.getBlockState(pos), BlockRotation.CLOCKWISE_90);
return ActionResult.SUCCESS;
}

View file

@ -56,10 +56,10 @@ public class BlockNuke extends BaseBlock {
public void ignite(World worldIn, BlockPos pos, BlockState state, LivingEntity igniter) {
if (!worldIn.isClient) {
EntityNukePrimed entitynukeprimed = new EntityNukePrimed(worldIn, (double) ((float) pos.getX() + 0.5F),
(double) pos.getY(), (double) ((float) pos.getZ() + 0.5F), igniter);
EntityNukePrimed entitynukeprimed = new EntityNukePrimed(worldIn, (float) pos.getX() + 0.5F,
pos.getY(), (float) pos.getZ() + 0.5F, igniter);
worldIn.spawnEntity(entitynukeprimed);
worldIn.playSound((PlayerEntity) null, entitynukeprimed.getX(), entitynukeprimed.getY(), entitynukeprimed.getZ(),
worldIn.playSound(null, entitynukeprimed.getX(), entitynukeprimed.getY(), entitynukeprimed.getZ(),
SoundEvents.ENTITY_TNT_PRIMED, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
}
@ -67,8 +67,8 @@ public class BlockNuke extends BaseBlock {
@Override
public void onDestroyedByExplosion(World worldIn, BlockPos pos, Explosion explosionIn) {
if (!worldIn.isClient) {
EntityNukePrimed entitynukeprimed = new EntityNukePrimed(worldIn, (double) ((float) pos.getX() + 0.5F),
(double) pos.getY(), (double) ((float) pos.getZ() + 0.5F), explosionIn.getCausingEntity());
EntityNukePrimed entitynukeprimed = new EntityNukePrimed(worldIn, (float) pos.getX() + 0.5F,
pos.getY(), (float) pos.getZ() + 0.5F, explosionIn.getCausingEntity());
entitynukeprimed.setFuse(worldIn.random.nextInt(TechRebornConfig.nukeFuseTime / 4) + TechRebornConfig.nukeFuseTime / 8);
worldIn.spawnEntity(entitynukeprimed);
}

View file

@ -24,7 +24,8 @@
package techreborn.blocks.misc;
import net.fabricmc.fabric.api.block.FabricBlockSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.registry.FlammableBlockRegistry;
import net.minecraft.block.LeavesBlock;
import net.minecraft.block.Material;
@ -33,7 +34,7 @@ import net.minecraft.sound.BlockSoundGroup;
public class BlockRubberLeaves extends LeavesBlock {
public BlockRubberLeaves() {
super(FabricBlockSettings.of(Material.LEAVES).hardness(0.2F).ticksRandomly().sounds(BlockSoundGroup.GRASS).build().nonOpaque());
super(FabricBlockSettings.of(Material.LEAVES).hardness(0.2F).ticksRandomly().sounds(BlockSoundGroup.GRASS).nonOpaque());
FlammableBlockRegistry.getDefaultInstance().add(this, 30, 60);
}

View file

@ -134,7 +134,9 @@ public class BlockRubberLog extends PillarBlock {
if (Energy.valid(stack)) {
Energy.of(stack).use(20);
} else {
stack.damage(1, playerIn, player -> { player.sendToolBreakStatus(hand); });
stack.damage(1, playerIn, player -> {
player.sendToolBreakStatus(hand);
});
}
if (!playerIn.inventory.insertStack(TRContent.Parts.SAP.getStack())) {
WorldUtils.dropItem(TRContent.Parts.SAP.getStack(), worldIn, pos.offset(hitResult.getSide()));

View file

@ -29,7 +29,6 @@ import techreborn.utils.InitUtils;
/**
* @author drcrazy
*
*/
public class RubberButtonBlock extends WoodButtonBlock {

View file

@ -29,7 +29,6 @@ import techreborn.utils.InitUtils;
/**
* @author drcrazy
*
*/
public class RubberDoorBlock extends DoorBlock {

View file

@ -29,7 +29,6 @@ import techreborn.utils.InitUtils;
/**
* @author drcrazy
*
*/
public class RubberPressurePlateBlock extends PressurePlateBlock {

View file

@ -29,7 +29,6 @@ import techreborn.utils.InitUtils;
/**
* @author drcrazy
*
*/
public class RubberTrapdoorBlock extends TrapdoorBlock {

View file

@ -24,10 +24,24 @@
package techreborn.blocks.storage.fluid;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.Fluid;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import reborncore.api.blockentity.IMachineGuiHandler;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.fluid.FluidValue;
import reborncore.common.fluid.container.FluidInstance;
import reborncore.common.fluid.container.ItemFluidInfo;
import reborncore.common.util.Tank;
import techreborn.blockentity.storage.fluid.TankUnitBaseBlockEntity;
import techreborn.client.GuiType;
import techreborn.init.TRContent;
@ -46,6 +60,44 @@ public class TankUnitBlock extends BlockMachineBase {
return new TankUnitBaseBlockEntity(unitType);
}
@Override
public ActionResult onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity playerIn, Hand hand, BlockHitResult hitResult) {
if (unitType == TRContent.TankUnit.CREATIVE || worldIn.isClient) {
return super.onUse(state, worldIn, pos, playerIn, hand, hitResult);
}
final TankUnitBaseBlockEntity tankUnitEntity = (TankUnitBaseBlockEntity) worldIn.getBlockEntity(pos);
ItemStack stackInHand = playerIn.getStackInHand(Hand.MAIN_HAND);
Item itemInHand = stackInHand.getItem();
// Assuming ItemFluidInfo is 1 BUCKET, for now only allow exact amount or less
if (tankUnitEntity != null && itemInHand instanceof ItemFluidInfo) {
ItemFluidInfo itemFluid = (ItemFluidInfo) itemInHand;
Fluid fluid = itemFluid.getFluid(stackInHand);
int amount = stackInHand.getCount();
FluidValue fluidValue = FluidValue.BUCKET.multiply(amount);
Tank tankInstance = tankUnitEntity.getTank();
if (tankInstance.canFit(fluid, fluidValue)) {
if (tankInstance.getFluidInstance().isEmptyFluid()) {
tankInstance.setFluidInstance(new FluidInstance(fluid, fluidValue));
} else {
tankInstance.getFluidInstance().addAmount(fluidValue);
}
ItemStack returnStack = itemFluid.getEmpty();
returnStack.setCount(amount);
playerIn.setStackInHand(Hand.MAIN_HAND, returnStack);
}
return ActionResult.SUCCESS;
}
return super.onUse(state, worldIn, pos, playerIn, hand, hitResult);
}
@Override
public IMachineGuiHandler getGui() {
return GuiType.TANK_UNIT;

View file

@ -27,7 +27,10 @@ package techreborn.blocks.storage.item;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.ToolItem;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
@ -36,6 +39,8 @@ import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import reborncore.api.blockentity.IMachineGuiHandler;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.util.RebornInventory;
import reborncore.common.util.WorldUtils;
import techreborn.blockentity.storage.item.StorageUnitBaseBlockEntity;
import techreborn.client.GuiType;
import techreborn.init.TRContent;
@ -56,19 +61,21 @@ public class StorageUnitBlock extends BlockMachineBase {
@Override
public ActionResult onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity playerIn, Hand hand, BlockHitResult hitResult) {
if (unitType == TRContent.StorageUnit.CREATIVE) {
if (unitType == TRContent.StorageUnit.CREATIVE || worldIn.isClient) {
return super.onUse(state, worldIn, pos, playerIn, hand, hitResult);
}
final StorageUnitBaseBlockEntity storageEntity = (StorageUnitBaseBlockEntity) worldIn.getBlockEntity(pos);
ItemStack stackInHand = playerIn.getStackInHand(Hand.MAIN_HAND);
Item itemInHand = stackInHand.getItem();
if (storageEntity != null && storageEntity.isSameType(stackInHand)) {
if (storageEntity != null && itemInHand != Items.AIR && (storageEntity.isSameType(stackInHand) && !storageEntity.isFull() ||
(!storageEntity.isLocked() && storageEntity.isEmpty() && (!(itemInHand instanceof ToolItem))))) {
// Add item which is the same type (in users inventory) into storage
for (int i = 0; i < playerIn.inventory.size() && !storageEntity.isFull(); i++) {
ItemStack curStack = playerIn.inventory.getStack(i);
if (storageEntity.isSameType(curStack)) {
if (curStack.getItem() == itemInHand) {
playerIn.inventory.setStack(i, storageEntity.processInput(curStack));
}
}
@ -78,6 +85,34 @@ public class StorageUnitBlock extends BlockMachineBase {
return super.onUse(state, worldIn, pos, playerIn, hand, hitResult);
}
@Override
public void onBlockBreakStart(BlockState state, World world, BlockPos pos, PlayerEntity player) {
super.onBlockBreakStart(state, world, pos, player);
if (world.isClient) return;
final StorageUnitBaseBlockEntity storageEntity = (StorageUnitBaseBlockEntity) world.getBlockEntity(pos);
ItemStack stackInHand = player.getStackInHand(Hand.MAIN_HAND);
if (storageEntity != null && (stackInHand.isEmpty() || storageEntity.isSameType(stackInHand)) && !storageEntity.isEmpty()) {
RebornInventory<StorageUnitBaseBlockEntity> inventory = storageEntity.getInventory();
ItemStack out = inventory.getStack(StorageUnitBaseBlockEntity.OUTPUT_SLOT);
// Drop stack if sneaking
if (player.isSneaking()) {
WorldUtils.dropItem(new ItemStack(out.getItem()), world, player.getBlockPos());
out.decrement(1);
} else {
WorldUtils.dropItem(out, world, player.getBlockPos());
out.setCount(0);
}
inventory.setChanged();
}
}
@Override
public IMachineGuiHandler getGui() {
return GuiType.STORAGE_UNIT;

View file

@ -1,40 +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.client;
public class ClientEventHandler {
//TODO 1.14
// @SubscribeEvent
// public static void renderPlayer(RenderPlayerEvent.Pre event) {
// PlayerEntity player = event.getEntityPlayer();
// Item chestslot = !player.getEquippedStack(EquipmentSlot.CHEST).isEmpty()
// ? player.getEquippedStack(EquipmentSlot.CHEST).getItem() : null;
// if (chestslot != null && chestslot == TRContent.CLOAKING_DEVICE) {
// event.setCanceled(true);
// }
// }
}

View file

@ -24,7 +24,6 @@
package techreborn.client;
import io.netty.buffer.Unpooled;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.screenhandler.v1.ScreenRegistry;
@ -172,7 +171,7 @@ public final class GuiType<T extends BlockEntity> implements IMachineGuiHandler
@Override
public void open(PlayerEntity player, BlockPos pos, World world) {
if(!world.isClient){
if (!world.isClient) {
//This is awful
player.openHandledScreen(new ExtendedScreenHandlerFactory() {
@Override

View file

@ -73,7 +73,7 @@ public class GuiAESU extends GuiBase<BuiltScreenHandler> {
super.drawForeground(matrixStack, mouseX, mouseY);
final Layer layer = Layer.FOREGROUND;
if(!hideGuiElements()){
if (!hideGuiElements()) {
RenderSystem.pushMatrix();
RenderSystem.scaled(0.6, 0.6, 1);
Text text = new LiteralText(PowerSystem.getLocaliszedPowerFormattedNoSuffix((int) blockEntity.getEnergy()))
@ -89,7 +89,7 @@ public class GuiAESU extends GuiBase<BuiltScreenHandler> {
builder.drawMultiEnergyBar(matrixStack, this, 81, 28, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxPower(), mouseX, mouseY, 0, layer);
}
public void onClick(int amount){
public void onClick(int amount) {
NetworkManager.sendToServer(ServerboundPackets.createPacketAesu(amount, Screen.hasShiftDown(), Screen.hasControlDown(), blockEntity));
}
}

View file

@ -57,7 +57,7 @@ public class GuiBatbox extends GuiBase<BuiltScreenHandler> {
super.drawForeground(matrixStack, mouseX, mouseY);
final Layer layer = Layer.FOREGROUND;
if(!hideGuiElements()){
if (!hideGuiElements()) {
RenderSystem.pushMatrix();
RenderSystem.scaled(0.6, 0.6, 5);
Text text = new LiteralText(PowerSystem.getLocaliszedPowerFormattedNoSuffix((int) blockEntity.getEnergy()))

View file

@ -25,22 +25,17 @@
package techreborn.client.gui;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.block.BlockState;
import net.minecraft.client.util.math.MatrixStack;
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.widget.GuiButtonExtended;
import reborncore.client.gui.guibuilder.GuiBuilder;
import reborncore.client.multiblock.Multiblock;
import reborncore.client.screen.builder.BuiltScreenHandler;
import techreborn.blockentity.machine.multiblock.IndustrialBlastFurnaceBlockEntity;
import techreborn.init.TRContent;
public class GuiBlastFurnace extends GuiBase<BuiltScreenHandler> {
public IndustrialBlastFurnaceBlockEntity blockEntity;
private final IndustrialBlastFurnaceBlockEntity blockEntity;
boolean hasMultiBlock;
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);
}
public void onClick(GuiButtonExtended button, Double x, Double y){
if (hideGuiElements()) return;
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;
public void onClick(GuiButtonExtended button, Double x, Double y) {
blockEntity.renderMultiblock ^= !hideGuiElements();
}
} 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

@ -69,7 +69,7 @@ public class GuiChunkLoader extends GuiBase<BuiltScreenHandler> {
drawCentredText(matrixStack, text, 25, 4210752, layer);
}
public void onClick(int amount){
public void onClick(int amount) {
NetworkManager.sendToServer(ServerboundPackets.createPacketChunkloader(amount, blockEntity, ClientChunkManager.hasChunksForLoader(blockEntity.getPos())));
}
}

View file

@ -25,22 +25,17 @@
package techreborn.client.gui;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.block.BlockState;
import net.minecraft.client.util.math.MatrixStack;
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.widget.GuiButtonExtended;
import reborncore.client.gui.guibuilder.GuiBuilder;
import reborncore.client.multiblock.Multiblock;
import reborncore.client.screen.builder.BuiltScreenHandler;
import techreborn.blockentity.machine.multiblock.DistillationTowerBlockEntity;
import techreborn.init.TRContent;
public class GuiDistillationTower extends GuiBase<BuiltScreenHandler> {
public DistillationTowerBlockEntity blockEntity;
private final DistillationTowerBlockEntity blockEntity;
public GuiDistillationTower(int syncID, final PlayerEntity player, final DistillationTowerBlockEntity blockEntity) {
super(player, blockEntity, blockEntity.createScreenHandler(syncID, player));
@ -70,7 +65,7 @@ public class GuiDistillationTower extends GuiBase<BuiltScreenHandler> {
final GuiBase.Layer layer = Layer.FOREGROUND;
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);
builder.drawHologramButton(matrixStack, this, 6, 4, mouseX, mouseY, layer);
} else {
@ -82,62 +77,7 @@ public class GuiDistillationTower extends GuiBase<BuiltScreenHandler> {
}
public void onClick(GuiButtonExtended button, Double x, Double y){
if (hideGuiElements()) return;
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;
public void onClick(GuiButtonExtended button, Double x, Double y) {
blockEntity.renderMultiblock ^= !hideGuiElements();
}
} 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;
import net.minecraft.block.BlockState;
import net.minecraft.client.util.math.MatrixStack;
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.widget.GuiButtonExtended;
import reborncore.client.gui.guibuilder.GuiBuilder;
import reborncore.client.multiblock.Multiblock;
import reborncore.client.screen.builder.BuiltScreenHandler;
import techreborn.blockentity.machine.multiblock.FluidReplicatorBlockEntity;
import techreborn.init.TRContent;
/**
* @author drcrazy
*
*/
public class GuiFluidReplicator extends GuiBase<BuiltScreenHandler> {
FluidReplicatorBlockEntity blockEntity;
private final FluidReplicatorBlockEntity blockEntity;
public GuiFluidReplicator(int syncID, final PlayerEntity player, final FluidReplicatorBlockEntity blockEntity) {
super(player, blockEntity, blockEntity.createScreenHandler(syncID, player));
@ -64,7 +58,7 @@ public class GuiFluidReplicator extends GuiBase<BuiltScreenHandler> {
drawSlot(matrixStack, 124, 55, layer);
// JEI button
builder.drawJEIButton(matrixStack, this, 158, 5, layer);
if (blockEntity.getMultiBlock()) {
if (blockEntity.isMultiblockValid()) {
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.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);
} else {
builder.drawMultiblockMissingBar(matrixStack, this, layer);
@ -87,35 +81,7 @@ public class GuiFluidReplicator extends GuiBase<BuiltScreenHandler> {
}
// GuiScreen
public void onClick(GuiButtonExtended button, Double x, Double y){
if (hideGuiElements()) return;
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;
public void onClick(GuiButtonExtended button, Double x, Double y) {
blockEntity.renderMultiblock ^= !hideGuiElements();
}
} 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;
import net.minecraft.block.BlockState;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.LiteralText;
import net.minecraft.util.math.BlockPos;
import org.apache.commons.lang3.tuple.Pair;
import reborncore.client.gui.builder.GuiBase;
import reborncore.client.gui.builder.widget.GuiButtonExtended;
import reborncore.client.gui.builder.widget.GuiButtonUpDown;
import reborncore.client.gui.builder.widget.GuiButtonUpDown.UpDownButtonType;
import reborncore.client.gui.guibuilder.GuiBuilder;
import reborncore.client.multiblock.Multiblock;
import reborncore.client.screen.builder.BuiltScreenHandler;
import reborncore.common.network.NetworkManager;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.util.Color;
import reborncore.common.util.Torus;
import techreborn.blockentity.machine.multiblock.FusionControlComputerBlockEntity;
import techreborn.init.TRContent;
import techreborn.packets.ServerboundPackets;
import java.util.List;
import java.util.Optional;
public class GuiFusionReactor extends GuiBase<BuiltScreenHandler> {
FusionControlComputerBlockEntity blockEntity;
private final FusionControlComputerBlockEntity blockEntity;
public GuiFusionReactor(int syncID, final PlayerEntity player, final FusionControlComputerBlockEntity blockEntity) {
super(player, blockEntity, blockEntity.createScreenHandler(syncID, player));
@ -76,7 +72,7 @@ public class GuiFusionReactor extends GuiBase<BuiltScreenHandler> {
drawOutputSlot(matrixStack, 80, 47, layer);
builder.drawJEIButton(matrixStack, this, 158, 5, layer);
if (blockEntity.getCoilStatus() > 0) {
if (blockEntity.isMultiblockValid()) {
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, 105, 51, mouseX, mouseY, GuiBuilder.ProgressDirection.LEFT, layer);
if (blockEntity.getCoilStatus() > 0) {
if (blockEntity.isMultiblockValid()) {
addHologramButton(6, 4, 212, layer).clickHandler(this::hologramToggle);
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);
}
} else {
@ -101,8 +97,8 @@ public class GuiFusionReactor extends GuiBase<BuiltScreenHandler> {
builder.drawHologramButton(matrixStack, this, 76, 56, mouseX, mouseY, layer);
Optional<Pair<Integer, Integer>> stackSize = getCoilStackCount();
if(stackSize.isPresent()){
if(stackSize.get().getLeft() > 0){
if (stackSize.isPresent()) {
if (stackSize.get().getLeft() > 0) {
drawCentredText(matrixStack,
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(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);
}
public void hologramToggle(GuiButtonExtended button, double x, double y){
if (hideGuiElements()) return;
if (blockEntity.renderMultiblock == null) {
updateMultiBlockRender();
} else {
blockEntity.renderMultiblock = null;
}
public void hologramToggle(GuiButtonExtended button, double x, double y) {
blockEntity.renderMultiblock ^= !hideGuiElements();
}
private void sendSizeChange(int sizeDelta){
private void sendSizeChange(int sizeDelta) {
NetworkManager.sendToServer(ServerboundPackets.createPacketFusionControlSize(sizeDelta, blockEntity.getPos()));
//Reset the multiblock as it will be wrong now.
if(blockEntity.renderMultiblock != null){
updateMultiBlockRender();
}
}
private void updateMultiBlockRender(){
final Multiblock multiblock = new Multiblock();
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)){
public Optional<Pair<Integer, Integer>> getCoilStackCount() {
if (!Torus.TORUS_SIZE_MAP.containsKey(blockEntity.size)) {
return Optional.empty();
}
int count = Torus.TORUS_SIZE_MAP.get(blockEntity.size);

View file

@ -25,23 +25,16 @@
package techreborn.client.gui;
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.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.state.property.Properties;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
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.widget.GuiButtonExtended;
import reborncore.client.multiblock.Multiblock;
import reborncore.client.screen.builder.BuiltScreenHandler;
import techreborn.blockentity.machine.tier1.GreenhouseControllerBlockEntity;
import techreborn.init.TRContent;
import java.util.Arrays;
import java.util.List;
@ -49,7 +42,7 @@ import java.util.stream.Collectors;
public class GuiGreenhouseController extends GuiBase<BuiltScreenHandler> {
GreenhouseControllerBlockEntity blockEntity;
private final GreenhouseControllerBlockEntity blockEntity;
public GuiGreenhouseController(int syncID, final PlayerEntity player, final GreenhouseControllerBlockEntity blockEntity) {
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, 48, gridYPos + 36, layer);
if (!blockEntity.getMultiBlock()) {
if (!blockEntity.isMultiblockValid()) {
getMinecraft().getTextureManager().bindTexture(new Identifier("techreborn", "textures/item/part/digital_display.png"));
drawTexture(matrixStack, x + 68, y + 22, 0, 0, 16, 16, 16, 16);
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);
builder.drawHologramButton(matrixStack, this, 90, 24, mouseX, mouseY, layer);
if (!blockEntity.getMultiBlock()) {
if (!blockEntity.isMultiblockValid()) {
if (isPointInRect(68, 22, 16, 16, mouseX, mouseY)) {
List<Text> list = Arrays.stream(I18n.translate("techreborn.tooltip.greenhouse.upgrade_available")
.split("\\r?\\n"))
@ -113,41 +106,6 @@ public class GuiGreenhouseController extends GuiBase<BuiltScreenHandler> {
}
public void onClick(GuiButtonExtended button, Double x, Double y) {
if (hideGuiElements()) return;
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 ^= !hideGuiElements();
}
}
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;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.block.BlockState;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import reborncore.client.gui.builder.GuiBase;
import reborncore.client.gui.builder.widget.GuiButtonExtended;
import reborncore.client.gui.guibuilder.GuiBuilder;
import reborncore.client.multiblock.Multiblock;
import reborncore.client.screen.builder.BuiltScreenHandler;
import techreborn.blockentity.machine.multiblock.ImplosionCompressorBlockEntity;
import techreborn.init.TRContent;
public class GuiImplosionCompressor extends GuiBase<BuiltScreenHandler> {
ImplosionCompressorBlockEntity blockEntity;
private final ImplosionCompressorBlockEntity blockEntity;
public GuiImplosionCompressor(int syncID, final PlayerEntity player, final ImplosionCompressorBlockEntity blockEntity) {
super(player, blockEntity, blockEntity.createScreenHandler(syncID, player));
@ -60,7 +56,7 @@ public class GuiImplosionCompressor extends GuiBase<BuiltScreenHandler> {
drawSlot(matrixStack, 92, 36, layer);
drawSlot(matrixStack, 110, 36, layer);
if (blockEntity.getMutliBlock()) {
if (blockEntity.isMultiblockValid()) {
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;
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);
} else {
builder.drawMultiblockMissingBar(matrixStack, this, layer);
@ -84,30 +80,7 @@ public class GuiImplosionCompressor extends GuiBase<BuiltScreenHandler> {
}
public void onClick(GuiButtonExtended button, Double mouseX, Double mouseY){
if (hideGuiElements()) return;
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);
public void onClick(GuiButtonExtended button, Double mouseX, Double mouseY) {
blockEntity.renderMultiblock ^= !hideGuiElements();
}
}

View file

@ -24,23 +24,17 @@
package techreborn.client.gui;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.util.math.MatrixStack;
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.widget.GuiButtonExtended;
import reborncore.client.gui.guibuilder.GuiBuilder;
import reborncore.client.multiblock.Multiblock;
import reborncore.client.screen.builder.BuiltScreenHandler;
import techreborn.blockentity.machine.multiblock.IndustrialGrinderBlockEntity;
import techreborn.init.TRContent;
public class GuiIndustrialGrinder extends GuiBase<BuiltScreenHandler> {
IndustrialGrinderBlockEntity blockEntity;
private final IndustrialGrinderBlockEntity blockEntity;
public GuiIndustrialGrinder(int syncID, final PlayerEntity player, final IndustrialGrinderBlockEntity blockEntity) {
super(player, blockEntity, blockEntity.createScreenHandler(syncID, player));
@ -67,7 +61,7 @@ public class GuiIndustrialGrinder extends GuiBase<BuiltScreenHandler> {
drawSlot(matrixStack, 126, 72, layer);
builder.drawJEIButton(matrixStack, this, 158, 5, layer);
if (blockEntity.getMultiBlock()) {
if (blockEntity.isMultiblockValid()) {
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.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);
} else {
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);
}
public void onClick(GuiButtonExtended button, double mouseX, double mouseY){
if (hideGuiElements()) return;
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;
public void onClick(GuiButtonExtended button, double mouseX, double mouseY) {
blockEntity.renderMultiblock ^= !hideGuiElements();
}
} 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;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.util.math.MatrixStack;
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.widget.GuiButtonExtended;
import reborncore.client.gui.guibuilder.GuiBuilder;
import reborncore.client.multiblock.Multiblock;
import reborncore.client.screen.builder.BuiltScreenHandler;
import techreborn.blockentity.machine.multiblock.IndustrialSawmillBlockEntity;
import techreborn.init.TRContent;
public class GuiIndustrialSawmill extends GuiBase<BuiltScreenHandler> {
IndustrialSawmillBlockEntity blockEntity;
private final IndustrialSawmillBlockEntity blockEntity;
public GuiIndustrialSawmill(int syncID, final PlayerEntity player, final IndustrialSawmillBlockEntity blockEntity) {
super(player, blockEntity, blockEntity.createScreenHandler(syncID, player));
this.blockEntity = blockEntity;
}
@Override
public void init() {
super.init();
blockEntity.renderMultiblock = null;
}
@Override
protected void drawBackground(MatrixStack matrixStack, final float partialTicks, final int mouseX, final int mouseY) {
super.drawBackground(matrixStack, partialTicks, mouseX, mouseY);
@ -72,7 +60,7 @@ public class GuiIndustrialSawmill extends GuiBase<BuiltScreenHandler> {
drawSlot(matrixStack, 126, 61, layer);
builder.drawJEIButton(matrixStack, this, 158, 5, layer);
if (blockEntity.getMutliBlock()) {
if (blockEntity.isMultiblockValid()) {
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.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);
} else {
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);
}
public void onClick(GuiButtonExtended button, Double mouseX, Double mouseY){
if (hideGuiElements()) return;
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);
public void onClick(GuiButtonExtended button, Double mouseX, Double mouseY) {
blockEntity.renderMultiblock ^= !hideGuiElements();
}
}

Some files were not shown because too many files have changed in this diff Show more