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

@ -27,16 +27,16 @@ package techreborn.api.generator;
import javax.annotation.Nonnull;
public enum EFluidGenerator {
THERMAL("TechReborn.ThermalGenerator"),
GAS("TechReborn.GasGenerator"),
DIESEL("TechReborn.DieselGenerator"),
THERMAL("TechReborn.ThermalGenerator"),
GAS("TechReborn.GasGenerator"),
DIESEL("TechReborn.DieselGenerator"),
SEMIFLUID("TechReborn.SemifluidGenerator"),
PLASMA("TechReborn.PlasmaGenerator");
@Nonnull
private final String recipeID;
private EFluidGenerator(@Nonnull String recipeID) {
EFluidGenerator(@Nonnull String recipeID) {
this.recipeID = recipeID;
}

View file

@ -54,7 +54,7 @@ public class FluidGeneratorRecipe {
@Override
public String toString() {
return "FluidGeneratorRecipe [generatorType=" + generatorType + ", fluid=" + fluid + ", energyPerMb="
+ energyPerMb + "]";
+ energyPerMb + "]";
}
@Override
@ -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;
@ -39,17 +38,17 @@ public class GeneratorRecipeHelper {
* FluidGeneratorRecipe.
*/
public static EnumMap<EFluidGenerator, FluidGeneratorRecipeList> fluidRecipes = new EnumMap<>(
EFluidGenerator.class);
EFluidGenerator.class);
/**
* Register a Fluid energy recipe.
*
* @param generatorType A value of the EFluidGenerator type in which the fluid is
* allowed to be consumed.
* allowed to be consumed.
* @param fluidType
* @param energyPerMb Represent the energy / MILLI_BUCKET the fluid will produce.
* Some generators use this value to alter their fluid decay
* speed to match their maximum energy output.
* @param energyPerMb Represent the energy / MILLI_BUCKET the fluid will produce.
* Some generators use this value to alter their fluid decay
* speed to match their maximum energy output.
*/
public static void registerFluidRecipe(EFluidGenerator generatorType, Fluid fluidType, int energyPerMb) {
fluidRecipes.putIfAbsent(generatorType, new FluidGeneratorRecipeList());
@ -58,19 +57,19 @@ public class GeneratorRecipeHelper {
/**
* @param generatorType A value of the EFluidGenerator type in which the fluid is
* allowed to be consumed.
* allowed to be consumed.
* @return An object holding a set of availables recipes for this type of
* FluidGenerator.
*/
public static FluidGeneratorRecipeList getFluidRecipesForGenerator(EFluidGenerator generatorType) {
return fluidRecipes.get(generatorType);
}
/**
* Removes recipe
*
* Removes recipe
*
* @param generatorType A value of the EFluidGenerator type for which we should remove recipe
* @param fluidType Fluid to remove from generator recipes
* @param fluidType Fluid to remove from generator recipes
*/
public static void removeFluidRecipe(EFluidGenerator generatorType, Fluid fluidType) {
FluidGeneratorRecipeList recipeList = getFluidRecipesForGenerator(generatorType);

View file

@ -34,14 +34,13 @@ import java.util.List;
/**
* @author drcrazy
*
*/
public class ScrapboxRecipeCrafter extends RecipeCrafter {
/**
* @param parent Tile having this crafter
* @param inventory Inventory from parent blockEntity
* @param inputSlots Slot IDs for input
* @param parent Tile having this crafter
* @param inventory Inventory from parent blockEntity
* @param inputSlots Slot IDs for input
* @param outputSlots Slot IDs for output
*/
public ScrapboxRecipeCrafter(BlockEntity parent, RebornInventory<?> inventory, int[] inputSlots, int[] outputSlots) {
@ -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

@ -47,7 +47,7 @@ public class BlastFurnaceRecipe extends RebornRecipe {
super(type, name, ingredients, outputs, power, time);
this.heat = heat;
}
public int getHeat() {
return heat;
}

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,10 +37,9 @@ import techreborn.blockentity.machine.multiblock.FusionControlComputerBlockEntit
/**
* @author drcrazy
*
*/
public class FusionReactorRecipe extends RebornRecipe {
private int startE;
private int minSize;
@ -53,11 +52,11 @@ public class FusionReactorRecipe extends RebornRecipe {
this.startE = startE;
this.minSize = minSize;
}
public int getStartEnergy () {
public int getStartEnergy() {
return startE;
}
@Override
public void deserialize(JsonObject jsonObject) {
super.deserialize(jsonObject);
@ -71,7 +70,7 @@ public class FusionReactorRecipe extends RebornRecipe {
jsonObject.addProperty("start-power", startE);
jsonObject.addProperty("min-size", minSize);
}
@Override
public boolean canCraft(final BlockEntity blockEntity) {
if (blockEntity instanceof FusionControlComputerBlockEntity) {

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()) {
continue;
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,16 +173,27 @@ public class CableBlockEntity extends BlockEntity
}
}
if (acceptors.isEmpty()) {
return;
}
Collections.shuffle(acceptors);
if (!acceptors.isEmpty()) {
Collections.shuffle(acceptors);
acceptors.forEach(pair -> {
Energy.of(this)
.into(Energy.of(pair.getLeft()).side(pair.getRight().getOpposite()))
.move();
});
acceptors.forEach(pair -> {
Energy.of(this)
.into(Energy.of(pair.getLeft()).side(pair.getRight().getOpposite()))
.move();
});
}
// 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
@ -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,13 +63,13 @@ 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 {
jsonObject = SerializationUtil.GSON.fromJson(IOUtils.toString(FabricLauncherBase.getLauncher().getResourceAsStream(location), StandardCharsets.UTF_8), JsonObject.class);
} catch (Exception e) {
throw new RuntimeException("failed to read json: " + location, e);
throw new RuntimeException("failed to read json: " + location, e);
}
Identifier id = new Identifier(JsonHelper.getString(jsonObject, "name"));
DataDrivenBEProvider provider = new DataDrivenBEProvider(block, jsonObject);
@ -95,7 +95,7 @@ public class DataDrivenBEProvider extends BlockEntityType<DataDrivenBEProvider.D
public BuiltScreenHandler createScreenHandler(DataDrivenBlockEntity blockEntity, int syncID, PlayerEntity player) {
BlockEntityScreenHandlerBuilder builder = new ScreenHandlerBuilder(identifier.getPath()).player(player.inventory)
.inventory().hotbar().addInventory().blockEntity(blockEntity);
.inventory().hotbar().addInventory().blockEntity(blockEntity);
slots.forEach(dataDrivenSlot -> dataDrivenSlot.add(builder));
@ -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,24 +139,24 @@ 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();
.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)
.toArray();
.filter(slot -> slot.getType() == type)
.mapToInt(DataDrivenSlot::getId)
.toArray();
}
public List<DataDrivenSlot> getSlots() {
return Collections.unmodifiableList(slots);
}
private String getSimpleName(){
private String getSimpleName() {
return WordUtils.capitalize(identifier.getPath());
}
}

View file

@ -41,12 +41,12 @@ 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)
.map(json -> new DataDrivenSlot(idCount.getAndIncrement(), JsonHelper.getInt(json, "x"), JsonHelper.getInt(json, "y"), SlotType.fromString(JsonHelper.getString(json, "type"))))
.collect(Collectors.toList());
.map(JsonElement::getAsJsonObject)
.map(json -> new DataDrivenSlot(idCount.getAndIncrement(), JsonHelper.getInt(json, "x"), JsonHelper.getInt(json, "y"), SlotType.fromString(JsonHelper.getString(json, "type"))))
.collect(Collectors.toList());
}
private final int id;
@ -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);
.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;
}
@ -88,9 +88,8 @@ public abstract class BaseFluidGeneratorBlockEntity extends PowerAcceptorBlockEn
ItemStack inputStack = inventory.getStack(0);
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()) {
FluidUtils.fillContainers(tank, inventory, 0, 1, tank.getFluid());
} 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,15 +54,17 @@ 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;
}
BlockMachineBase machineBaseBlock = (BlockMachineBase) BEBlock;
if (onStatusHoldTicks == 0 || getEnergy() <= 0) {
machineBaseBlock.setActive(false, world, pos);
onStatusHoldTicks = -1;
@ -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

@ -60,10 +60,10 @@ public class PlasmaGeneratorBlockEntity extends BaseFluidGeneratorBlockEntity im
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
return new ScreenHandlerBuilder("plasmagenerator").player(player.inventory).inventory().hotbar().addInventory()
.blockEntity(this).slot(0, 25, 35).outputSlot(1, 25, 55).syncEnergyValue()
.sync(this::getTicksSinceLastChange, this::setTicksSinceLastChange)
.sync(this::getTankAmount, this::setTankAmount)
.sync(tank)
.addInventory().create(this, syncID);
.sync(this::getTicksSinceLastChange, this::setTicksSinceLastChange)
.sync(this::getTankAmount, this::setTankAmount)
.sync(tank)
.addInventory().create(this, syncID);
}
}

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
@ -231,22 +230,22 @@ public class SolarPanelBlockEntity extends PowerAcceptorBlockEntity implements I
info.add(
new TranslatableText("reborncore.tooltip.energy.maxEnergy")
.formatted(Formatting.GRAY)
.append(": ")
.append(
new LiteralText(PowerSystem.getLocaliszedPowerFormatted(getMaxPower()))
.formatted(Formatting.GOLD)
)
.formatted(Formatting.GRAY)
.append(": ")
.append(
new LiteralText(PowerSystem.getLocaliszedPowerFormatted(getMaxPower()))
.formatted(Formatting.GOLD)
)
);
info.add(
new TranslatableText("techreborn.tooltip.generationRate.day")
.formatted(Formatting.GRAY)
.append(": ")
.append(
new LiteralText(PowerSystem.getLocaliszedPowerFormatted(panel.generationRateD))
.formatted(Formatting.GOLD)
)
.formatted(Formatting.GRAY)
.append(": ")
.append(
new LiteralText(PowerSystem.getLocaliszedPowerFormatted(panel.generationRateD))
.formatted(Formatting.GOLD)
)
);
info.add(

View file

@ -60,10 +60,10 @@ public class DieselGeneratorBlockEntity extends BaseFluidGeneratorBlockEntity im
@Override
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
return new ScreenHandlerBuilder("dieselgenerator").player(player.inventory).inventory().hotbar()
.addInventory().blockEntity(this).slot(0, 25, 35).outputSlot(1, 25, 55).syncEnergyValue()
.sync(this::getTicksSinceLastChange, this::setTicksSinceLastChange)
.sync(this::getTankAmount, this::setTankAmount)
.sync(tank)
.addInventory().create(this, syncID);
.addInventory().blockEntity(this).slot(0, 25, 35).outputSlot(1, 25, 55).syncEnergyValue()
.sync(this::getTicksSinceLastChange, this::setTicksSinceLastChange)
.sync(this::getTankAmount, this::setTankAmount)
.sync(tank)
.addInventory().create(this, syncID);
}
}

View file

@ -39,7 +39,7 @@ import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
public class DragonEggSyphonBlockEntity extends PowerAcceptorBlockEntity
implements IToolDrop, InventoryProvider {
implements IToolDrop, InventoryProvider {
public RebornInventory<DragonEggSyphonBlockEntity> inventory = new RebornInventory<>(3, "DragonEggSyphonBlockEntity", 64, this);
private long lastOutput = 0;
@ -47,7 +47,7 @@ public class DragonEggSyphonBlockEntity extends PowerAcceptorBlockEntity
public DragonEggSyphonBlockEntity() {
super(TRBlockEntities.DRAGON_EGG_SYPHON);
}
private boolean tryAddingEnergy(int amount) {
if (this.getMaxPower() - this.getEnergy() >= amount) {
addEnergy(amount);
@ -58,7 +58,7 @@ public class DragonEggSyphonBlockEntity extends PowerAcceptorBlockEntity
}
return false;
}
// TilePowerAcceptor
@Override
public void tick() {
@ -103,7 +103,7 @@ public class DragonEggSyphonBlockEntity extends PowerAcceptorBlockEntity
public double getBaseMaxInput() {
return 0;
}
// IToolDrop
@Override
public ItemStack getToolDrop(PlayerEntity entityPlayer) {

View file

@ -60,10 +60,10 @@ public class GasTurbineBlockEntity extends BaseFluidGeneratorBlockEntity impleme
@Override
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
return new ScreenHandlerBuilder("gasturbine").player(player.inventory).inventory().hotbar()
.addInventory().blockEntity(this).slot(0, 25, 35).outputSlot(1, 25, 55).syncEnergyValue()
.sync(this::getTicksSinceLastChange, this::setTicksSinceLastChange)
.sync(this::getTankAmount, this::setTankAmount)
.sync(tank)
.addInventory().create(this, syncID);
.addInventory().blockEntity(this).slot(0, 25, 35).outputSlot(1, 25, 55).syncEnergyValue()
.sync(this::getTicksSinceLastChange, this::setTicksSinceLastChange)
.sync(this::getTankAmount, this::setTankAmount)
.sync(tank)
.addInventory().create(this, syncID);
}
}

View file

@ -51,7 +51,7 @@ public class SemiFluidGeneratorBlockEntity extends BaseFluidGeneratorBlockEntity
public double getBaseMaxPower() {
return TechRebornConfig.semiFluidGeneratorMaxEnergy;
}
@Override
public double getBaseMaxOutput() {
return TechRebornConfig.semiFluidGeneratorMaxOutput;
@ -60,10 +60,10 @@ public class SemiFluidGeneratorBlockEntity extends BaseFluidGeneratorBlockEntity
@Override
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
return new ScreenHandlerBuilder("semifluidgenerator").player(player.inventory).inventory().hotbar()
.addInventory().blockEntity(this).slot(0, 25, 35).outputSlot(1, 25, 55).syncEnergyValue()
.sync(this::getTicksSinceLastChange, this::setTicksSinceLastChange)
.sync(this::getTankAmount, this::setTankAmount)
.sync(tank)
.addInventory().create(this, syncID);
.addInventory().blockEntity(this).slot(0, 25, 35).outputSlot(1, 25, 55).syncEnergyValue()
.sync(this::getTicksSinceLastChange, this::setTicksSinceLastChange)
.sync(this::getTankAmount, this::setTankAmount)
.sync(tank)
.addInventory().create(this, syncID);
}
}

View file

@ -60,10 +60,10 @@ public class ThermalGeneratorBlockEntity extends BaseFluidGeneratorBlockEntity i
@Override
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
return new ScreenHandlerBuilder("thermalgenerator").player(player.inventory).inventory().hotbar()
.addInventory().blockEntity(this).slot(0, 25, 35).outputSlot(1, 25, 55).syncEnergyValue()
.sync(this::getTicksSinceLastChange, this::setTicksSinceLastChange)
.sync(this::getTankAmount, this::setTankAmount)
.sync(tank)
.addInventory().create(this, syncID);
.addInventory().blockEntity(this).slot(0, 25, 35).outputSlot(1, 25, 55).syncEnergyValue()
.sync(this::getTicksSinceLastChange, this::setTicksSinceLastChange)
.sync(this::getTankAmount, this::setTankAmount)
.sync(tank)
.addInventory().create(this, syncID);
}
}

View file

@ -64,11 +64,11 @@ public class SolidFuelGeneratorBlockEntity extends PowerAcceptorBlockEntity impl
}
public static int getItemBurnTime(@Nonnull ItemStack stack) {
if (stack.isEmpty()){
return 0;
}
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;
@ -183,9 +183,9 @@ public class SolidFuelGeneratorBlockEntity extends PowerAcceptorBlockEntity impl
@Override
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
return new ScreenHandlerBuilder("generator").player(player.inventory).inventory().hotbar().addInventory()
.blockEntity(this).fuelSlot(0, 80, 54).energySlot(1, 8, 72).syncEnergyValue()
.sync(this::getBurnTime, this::setBurnTime)
.sync(this::getTotalBurnTime, this::setTotalBurnTime).addInventory().create(this, syncID);
.blockEntity(this).fuelSlot(0, 80, 54).energySlot(1, 8, 72).syncEnergyValue()
.sync(this::getBurnTime, this::setBurnTime)
.sync(this::getTotalBurnTime, this::setTotalBurnTime).addInventory().create(this, syncID);
}
@Override

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

@ -35,9 +35,9 @@ import techreborn.blocks.lighting.BlockLamp;
import techreborn.init.TRBlockEntities;
public class LampBlockEntity extends PowerAcceptorBlockEntity
implements IToolDrop {
implements IToolDrop {
private static int capacity = 33;
private static final int capacity = 33;
public LampBlockEntity() {
super(TRBlockEntities.LAMP);
@ -61,7 +61,7 @@ public class LampBlockEntity extends PowerAcceptorBlockEntity
} else if (BlockLamp.isActive(state)) {
BlockLamp.setActive(false, world, pos);
}
}
}
}
@Override

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;
@ -50,12 +49,12 @@ public abstract class GenericMachineBlockEntity extends PowerAcceptorBlockEntity
public int energySlot;
public RebornInventory<?> inventory;
public RecipeCrafter crafter;
/**
* @param name String Name for a blockEntity. Do we need it at all?
* @param maxInput int Maximum energy input, value in EU
* @param maxEnergy int Maximum energy buffer, value in EU
* @param toolDrop Block Block to drop with wrench
* @param name String Name for a blockEntity. Do we need it at all?
* @param maxInput int Maximum energy input, value in EU
* @param maxEnergy int Maximum energy buffer, value in EU
* @param toolDrop Block Block to drop with wrench
* @param energySlot int Energy slot to use to charge machine from battery
*/
public GenericMachineBlockEntity(BlockEntityType<?> blockEntityType, String name, int maxInput, int maxEnergy, Block toolDrop, int energySlot) {
@ -67,7 +66,7 @@ public abstract class GenericMachineBlockEntity extends PowerAcceptorBlockEntity
this.energySlot = energySlot;
checkTier();
}
public int getProgressScaled(int scale) {
if (crafter != null && crafter.currentTickTime != 0) {
return crafter.currentTickTime * scale / crafter.currentNeededTicks;
@ -79,11 +78,11 @@ public abstract class GenericMachineBlockEntity extends PowerAcceptorBlockEntity
@Override
public void tick() {
super.tick();
if (!world.isClient) {
if (!world.isClient && energySlot != -1) {
charge(energySlot);
}
}
@Override
public double getBaseMaxPower() {
return maxEnergy;
@ -108,19 +107,19 @@ public abstract class GenericMachineBlockEntity extends PowerAcceptorBlockEntity
public double getBaseMaxInput() {
return maxInput;
}
// IToolDrop
@Override
public ItemStack getToolDrop(PlayerEntity p0) {
return new ItemStack(toolDrop, 1);
}
// InventoryProvider
@Override
public RebornInventory<?> getInventory() {
return inventory;
}
// IRecipeCrafterProvider
@Override
public RecipeCrafter getRecipeCrafter() {

View file

@ -57,9 +57,10 @@ public abstract class AbstractIronMachineBlockEntity extends MachineBaseBlockEnt
this.totalCookingTime = (int) (200 / TechRebornConfig.cookingScale);
this.toolDrop = toolDrop;
}
/**
* 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
*/
@ -82,11 +84,12 @@ public abstract class AbstractIronMachineBlockEntity extends MachineBaseBlockEnt
}
return (int) (AbstractFurnaceBlockEntity.createFuelTimeMap().getOrDefault(stack.getItem(), 0) * TechRebornConfig.fuelScale);
}
/**
* Returns remaining fraction of fuel burn time
* Returns remaining fraction of fuel burn time
*
* @param scale Scale to use for burn time
* @return int scaled remaining fuel burn time
* @return int scaled remaining fuel burn time
*/
public int getBurnTimeRemainingScaled(int scale) {
if (totalBurnTime == 0) {
@ -95,11 +98,12 @@ public abstract class AbstractIronMachineBlockEntity extends MachineBaseBlockEnt
return burnTime * scale / totalBurnTime;
}
/**
* Returns crafting progress
* Returns crafting progress
*
* @param scale Scale to use for crafting progress
* @return int Scaled crafting progress
* @return int Scaled crafting progress
*/
public int getProgressScaled(int scale) {
if (totalCookingTime > 0) {
@ -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() {
@ -136,24 +141,24 @@ public abstract class AbstractIronMachineBlockEntity extends MachineBaseBlockEnt
@Override
public CompoundTag toTag(CompoundTag compoundTag) {
super.toTag(compoundTag);
compoundTag.putInt("BurnTime", burnTime);
compoundTag.putInt("TotalBurnTime", totalBurnTime);
compoundTag.putInt("Progress", progress);
return compoundTag;
super.toTag(compoundTag);
compoundTag.putInt("BurnTime", burnTime);
compoundTag.putInt("TotalBurnTime", totalBurnTime);
compoundTag.putInt("Progress", progress);
return compoundTag;
}
@Override
public void tick() {
super.tick();
if(world.isClient){
if (world.isClient) {
return;
}
boolean isBurning = isBurning();
if (isBurning) {
--burnTime;
}
if (!isBurning && canSmelt()) {
burnTime = totalBurnTime = getItemBurnTime(inventory.getStack(fuelSlot));
if (burnTime > 0) {
@ -168,17 +173,17 @@ public abstract class AbstractIronMachineBlockEntity extends MachineBaseBlockEnt
}
}
}
if (isBurning() && canSmelt()) {
++progress;
if (progress == totalCookingTime) {
progress = 0;
smelt();
}
} else if(!canSmelt()) {
} else if (!canSmelt()) {
progress = 0;
}
if (isBurning != isBurning()) {
inventory.setChanged();
updateState();
@ -198,7 +203,7 @@ public abstract class AbstractIronMachineBlockEntity extends MachineBaseBlockEnt
public RebornInventory<?> getInventory() {
return inventory;
}
// IToolDrop
@Override
public ItemStack getToolDrop(PlayerEntity entityPlayer) {
@ -220,7 +225,7 @@ public abstract class AbstractIronMachineBlockEntity extends MachineBaseBlockEnt
public void setTotalBurnTime(int totalBurnTime) {
this.totalBurnTime = totalBurnTime;
}
public int getProgress() {
return progress;
}

View file

@ -36,7 +36,7 @@ import techreborn.init.ModRecipes;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
public class IronAlloyFurnaceBlockEntity extends AbstractIronMachineBlockEntity implements BuiltScreenHandlerProvider {
public class IronAlloyFurnaceBlockEntity extends AbstractIronMachineBlockEntity implements BuiltScreenHandlerProvider {
int input1 = 0;
int input2 = 1;
@ -84,7 +84,7 @@ public class IronAlloyFurnaceBlockEntity extends AbstractIronMachineBlockEntity
if (!inventory.getStack(output).isItemEqualIgnoreDamage(itemstack))
return false;
int result = inventory.getStack(output).getCount() + itemstack.getCount();
return result <= inventory.getStackLimit() && result <= inventory.getStack(output).getMaxCount();
return result <= inventory.getStackLimit() && result <= inventory.getStack(output).getMaxCount();
}
@Override
@ -121,28 +121,28 @@ public class IronAlloyFurnaceBlockEntity extends AbstractIronMachineBlockEntity
break;
}
}
}
}
}
@Override
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
return new ScreenHandlerBuilder("alloyfurnace").player(player.inventory).inventory().hotbar()
.addInventory().blockEntity(this)
.slot(0, 47, 17)
.slot(1, 65, 17)
.outputSlot(2, 116, 35).fuelSlot(3, 56, 53)
.sync(this::getBurnTime, this::setBurnTime)
.sync(this::getProgress, this::setProgress)
.sync(this::getTotalBurnTime, this::setTotalBurnTime)
.addInventory().create(this, syncID);
.addInventory().blockEntity(this)
.slot(0, 47, 17)
.slot(1, 65, 17)
.outputSlot(2, 116, 35).fuelSlot(3, 56, 53)
.sync(this::getBurnTime, this::setBurnTime)
.sync(this::getProgress, this::setProgress)
.sync(this::getTotalBurnTime, this::setTotalBurnTime)
.addInventory().create(this, syncID);
}
@Override
public boolean isStackValid(int slotID, ItemStack stack) {
return ModRecipes.ALLOY_SMELTER.getRecipes(world).stream()
.anyMatch(rebornRecipe -> rebornRecipe.getRebornIngredients().stream()
.anyMatch(rebornIngredient -> rebornIngredient.test(stack))
);
.anyMatch(rebornRecipe -> rebornRecipe.getRebornIngredients().stream()
.anyMatch(rebornIngredient -> rebornIngredient.test(stack))
);
}
@Override

View file

@ -47,12 +47,12 @@ public class IronFurnaceBlockEntity extends AbstractIronMachineBlockEntity imple
int inputSlot = 0;
int outputSlot = 1;
public float experience;
public IronFurnaceBlockEntity() {
super(TRBlockEntities.IRON_FURNACE, 2, TRContent.Machine.IRON_FURNACE.block);
this.inventory = new RebornInventory<>(3, "IronFurnaceBlockEntity", 64, this);
}
public void handleGuiInputFromClient(PlayerEntity playerIn) {
if (playerIn instanceof ServerPlayerEntity) {
ServerPlayerEntity player = (ServerPlayerEntity) playerIn;
@ -65,7 +65,7 @@ public class IronFurnaceBlockEntity extends AbstractIronMachineBlockEntity imple
}
experience = 0;
}
private ItemStack getResultFor(ItemStack stack) {
ItemStack result = RecipeUtils.getMatchingRecipes(world, RecipeType.SMELTING, stack);
if (!result.isEmpty()) {
@ -81,7 +81,7 @@ public class IronFurnaceBlockEntity extends AbstractIronMachineBlockEntity imple
}
return 0;
}
// AbstractIronMachineBlockEntity
@Override
protected void smelt() {
@ -90,7 +90,7 @@ public class IronFurnaceBlockEntity extends AbstractIronMachineBlockEntity imple
}
ItemStack inputStack = inventory.getStack(inputSlot);
ItemStack resultStack = getResultFor(inputStack);
if (inventory.getStack(outputSlot).isEmpty()) {
inventory.setStack(outputSlot, resultStack.copy());
} else if (inventory.getStack(outputSlot).isItemEqualIgnoreDamage(resultStack)) {
@ -103,12 +103,12 @@ public class IronFurnaceBlockEntity extends AbstractIronMachineBlockEntity imple
inventory.setStack(inputSlot, ItemStack.EMPTY);
}
}
@Override
protected boolean canSmelt() {
if (inventory.getStack(inputSlot).isEmpty()) {
return false;
}
}
ItemStack outputStack = getResultFor(inventory.getStack(inputSlot));
if (outputStack.isEmpty())
return false;
@ -130,19 +130,19 @@ public class IronFurnaceBlockEntity extends AbstractIronMachineBlockEntity imple
super.fromTag(blockState, compoundTag);
experience = compoundTag.getFloat("Experience");
}
@Override
public CompoundTag toTag(CompoundTag compoundTag) {
super.toTag(compoundTag);
compoundTag.putFloat("Experience", experience);
return compoundTag;
super.toTag(compoundTag);
compoundTag.putFloat("Experience", experience);
return compoundTag;
}
// IContainerProvider
public float getExperience() {
return experience;
}
public void setExperience(float experience) {
this.experience = experience;
}

View file

@ -42,30 +42,30 @@ import techreborn.init.TRContent;
import techreborn.utils.MessageIDs;
public class AlarmBlockEntity extends BlockEntity
implements Tickable, IToolDrop {
implements Tickable, IToolDrop {
private int selectedSound = 1;
public AlarmBlockEntity() {
super(TRBlockEntities.ALARM);
}
public void rightClick() {
if (world.isClient) {
return;
}
public void rightClick() {
if (world.isClient) {
return;
}
if (selectedSound < 3) {
selectedSound++;
} else {
selectedSound = 1;
}
if (selectedSound < 3) {
selectedSound++;
} else {
selectedSound = 1;
}
ChatUtils.sendNoSpamMessages(MessageIDs.alarmID, new TranslatableText("techreborn.message.alarm")
ChatUtils.sendNoSpamMessages(MessageIDs.alarmID, new TranslatableText("techreborn.message.alarm")
.formatted(Formatting.GRAY)
.append(" Alarm ")
.append(String.valueOf(selectedSound)));
}
}
// BlockEntity
@Override
public CompoundTag toTag(CompoundTag compound) {
@ -87,12 +87,12 @@ public class AlarmBlockEntity extends BlockEntity
// ITickable
@Override
public void tick() {
if (world.isClient()){
return;
}
if (world.getTime() % 25 != 0) {
return;
}
if (world.isClient()) {
return;
}
if (world.getTime() % 25 != 0) {
return;
}
if (world.isReceivingRedstonePower(getPos())) {
BlockAlarm.setActive(true, world, pos);
switch (selectedSound) {
@ -106,7 +106,7 @@ public class AlarmBlockEntity extends BlockEntity
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), ModSounds.ALARM_3, SoundCategory.BLOCKS, 4F, 1F);
break;
}
} else {
} else {
BlockAlarm.setActive(false, world, pos);
}
}

View file

@ -40,7 +40,7 @@ import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
public class ChargeOMatBlockEntity extends PowerAcceptorBlockEntity
implements IToolDrop, InventoryProvider, BuiltScreenHandlerProvider {
implements IToolDrop, InventoryProvider, BuiltScreenHandlerProvider {
public RebornInventory<ChargeOMatBlockEntity> inventory = new RebornInventory<>(6, "ChargeOMatBlockEntity", 64, this);
@ -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++) {
@ -61,11 +61,11 @@ public class ChargeOMatBlockEntity extends PowerAcceptorBlockEntity
if (Energy.valid(stack)) {
Energy.of(this)
.into(
Energy
.of(stack)
)
.move();
.into(
Energy
.of(stack)
)
.move();
}
}
}
@ -94,7 +94,7 @@ public class ChargeOMatBlockEntity extends PowerAcceptorBlockEntity
public double getBaseMaxInput() {
return TechRebornConfig.chargeOMatBMaxInput;
}
// TileMachineBase
@Override
public boolean canBeUpgraded() {
@ -117,7 +117,7 @@ public class ChargeOMatBlockEntity extends PowerAcceptorBlockEntity
@Override
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
return new ScreenHandlerBuilder("chargebench").player(player.inventory).inventory().hotbar().addInventory()
.blockEntity(this).energySlot(0, 62, 25).energySlot(1, 98, 25).energySlot(2, 62, 45).energySlot(3, 98, 45)
.energySlot(4, 62, 65).energySlot(5, 98, 65).syncEnergyValue().addInventory().create(this, syncID);
.blockEntity(this).energySlot(0, 62, 25).energySlot(1, 98, 25).energySlot(2, 62, 45).energySlot(3, 98, 45)
.energySlot(4, 62, 65).energySlot(5, 98, 65).syncEnergyValue().addInventory().create(this, syncID);
}
}

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) {
@ -92,10 +84,10 @@ public class FluidReplicatorBlockEntity extends GenericMachineBlockEntity implem
super.tick();
}
@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));
}
/**
@ -118,14 +92,14 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
/**
* Checks that ItemStack could be inserted into slot provided, including check
* for existing item in slot and maximum stack size
*
*
* @param stack ItemStack ItemStack to insert
* @param slot int Slot ID to check
* @param tags boolean Should we use tags
* @param slot int Slot ID to check
* @param tags boolean Should we use tags
* @return boolean Returns true if ItemStack will fit into slot
*/
public boolean canFitStack(ItemStack stack, int slot, boolean tags) {// Checks to see if it can
// fit the stack
// fit the stack
if (stack.isEmpty()) {
return true;
}
@ -140,7 +114,7 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
/**
* Returns progress scaled to input value
*
*
* @param scale int Maximum value for progress
* @return int Scale of progress
*/
@ -166,20 +140,20 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
}
}
}
/**
* Validates if reactor has all inputs and can output result
*
*
* @param recipe FusionReactorRecipe Recipe to validate
* @return Boolean True if we have all inputs and can fit output
*/
private boolean validateRecipe(FusionReactorRecipe recipe) {
return hasAllInputs(recipe) && canFitStack(recipe.getOutputs().get(0), outputStackSlot, true);
return hasAllInputs(recipe) && canFitStack(recipe.getOutputs().get(0), outputStackSlot, true);
}
/**
* Check if BlockEntity has all necessary inputs for recipe provided
*
*
* @param recipeType RebornRecipe Recipe to check inputs
* @return Boolean True if reactor has all inputs for recipe
*/
@ -199,10 +173,10 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
}
return true;
}
/**
* Decrease stack size on the given slot according to recipe input
*
*
* @param slot int Slot number
*/
private void useInput(int slot) {
@ -228,7 +202,7 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
}
//Move this to here from the nbt read method, as it now requires the world as of 1.14
if(checkNBTRecipe) {
if (checkNBTRecipe) {
checkNBTRecipe = false;
for (final RebornRecipe reactorRecipe : ModRecipes.FUSION_REACTOR.getRecipes(getWorld())) {
if (validateRecipe((FusionReactorRecipe) reactorRecipe)) {
@ -237,7 +211,7 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
}
}
if(lastTick == world.getTime()){
if (lastTick == world.getTime()) {
//Prevent tick accerators, blame obstinate for this.
return;
}
@ -245,11 +219,10 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
// Force check every second
if (world.getTime() % 20 == 0) {
checkCoils();
inventory.setChanged();
}
if (coilCount == 0) {
if (!isMultiblockValid()) {
resetCrafter();
return;
}
@ -314,7 +287,7 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
@Override
public double getPowerMultiplier() {
double calc = (1F/2F) * Math.pow(size -5, 1.8);
double calc = (1F / 2F) * Math.pow(size - 5, 1.8);
return Math.max(Math.round(calc * 100D) / 100D, 1D);
}
@ -355,10 +328,10 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
this.crafingTickTime = tagCompound.getInt("crafingTickTime");
this.neededPower = tagCompound.getInt("neededPower");
this.hasStartedCrafting = tagCompound.getBoolean("hasStartedCrafting");
if(tagCompound.contains("hasActiveRecipe") && tagCompound.getBoolean("hasActiveRecipe") && this.currentRecipe == null){
if (tagCompound.contains("hasActiveRecipe") && tagCompound.getBoolean("hasActiveRecipe") && this.currentRecipe == null) {
checkNBTRecipe = true;
}
if(tagCompound.contains("size")){
if (tagCompound.contains("size")) {
this.size = tagCompound.getInt("size");
}
this.size = Math.min(size, TechRebornConfig.fusionControlComputerMaxCoilSize);//Done here to force the samller size, will be useful if people lag out on a large one.
@ -375,24 +348,11 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
return tagCompound;
}
// TileLegacyMachineBase
@Override
public void onLoad() {
super.onLoad();
this.checkCoils();
}
@Override
public boolean canBeUpgraded() {
return false;
}
// IToolDrop
@Override
public ItemStack getToolDrop(PlayerEntity playerIn) {
return TRContent.Machine.FUSION_CONTROL_COMPUTER.getStack();
}
// ItemHandlerProvider
@Override
public RebornInventory<FusionControlComputerBlockEntity> getInventory() {
@ -404,7 +364,6 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
return new ScreenHandlerBuilder("fusionreactor").player(player.inventory).inventory().hotbar()
.addInventory().blockEntity(this).slot(0, 34, 47).slot(1, 126, 47).outputSlot(2, 80, 47).syncEnergyValue()
.sync(this::getCoilStatus, this::setCoilStatus)
.sync(this::getCrafingTickTime, this::setCrafingTickTime)
.sync(this::getSize, this::setSize)
.sync(this::getState, this::setState)
@ -414,14 +373,6 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
.create(this, syncID);
}
public int getCoilStatus() {
return coilCount;
}
public void setCoilStatus(int coilStatus) {
this.coilCount = coilStatus;
}
public int getCrafingTickTime() {
return crafingTickTime;
}
@ -446,61 +397,61 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
this.size = size;
}
public void changeSize(int sizeDelta){
public void changeSize(int sizeDelta) {
int newSize = size + sizeDelta;
this.size = Math.max(6, Math.min(TechRebornConfig.fusionControlComputerMaxCoilSize, newSize));
}
public int getState(){
if(currentRecipe == null ){
public int getState() {
if (currentRecipe == null) {
return 0; //No Recipe
}
if(!hasStartedCrafting){
if (!hasStartedCrafting) {
return 1; //Waiting on power
}
return 2; //Crafting
}
public void setState(int state){
public void setState(int state) {
this.state = state;
}
public Identifier getCurrentRecipeID() {
if(currentRecipe == null) {
if (currentRecipe == null) {
return new Identifier("null", "null");
}
return currentRecipe.getId();
}
public void setCurrentRecipeID(Identifier currentRecipeID) {
if(currentRecipeID.getPath().equals("null")) {
if (currentRecipeID.getPath().equals("null")) {
currentRecipeID = null;
}
this.currentRecipeID = currentRecipeID;
}
public FusionReactorRecipe getCurrentRecipeFromID() {
if(currentRecipeID == null) return null;
if (currentRecipeID == null) return null;
return ModRecipes.FUSION_REACTOR.getRecipes(world).stream()
.filter(recipe -> recipe.getId().equals(currentRecipeID))
.findFirst()
.orElse(null);
}
public Text getStateText(){
if(state == -1){
public Text getStateText() {
if (state == -1) {
return LiteralText.EMPTY;
} else if (state == 0){
} else if (state == 0) {
return new LiteralText("No recipe");
} else if (state == 1){
} else if (state == 1) {
FusionReactorRecipe r = getCurrentRecipeFromID();
if(r == null) {
if (r == null) {
return new LiteralText("Charging");
}
int percentage = percentage(r.getStartEnergy(), getEnergy());
return new LiteralText("Charging (")
.append(StringUtils.getPercentageText(percentage));
} else if (state == 2){
} else if (state == 2) {
return new LiteralText("Crafting");
}
return LiteralText.EMPTY;

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,24 +48,49 @@ import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
import techreborn.multiblocks.MultiBlockCasing;
import java.util.function.BiPredicate;
public class IndustrialBlastFurnaceBlockEntity extends GenericMachineBlockEntity implements BuiltScreenHandlerProvider {
public MultiblockChecker multiblockChecker;
private int cachedHeat;
public IndustrialBlastFurnaceBlockEntity() {
super(TRBlockEntities.INDUSTRIAL_BLAST_FURNACE, "IndustrialBlastFurnace", TechRebornConfig.industrialBlastFurnaceMaxInput, TechRebornConfig.industrialBlastFurnaceMaxEnergy, TRContent.Machine.INDUSTRIAL_BLAST_FURNACE.block, 4);
final int[] inputs = new int[] { 0, 1 };
final int[] outputs = new int[] { 2, 3 };
final int[] inputs = new int[]{0, 1};
final int[] outputs = new int[]{2, 3};
this.inventory = new RebornInventory<>(5, "IndustrialBlastFurnaceBlockEntity", 64, this);
this.crafter = new RecipeCrafter(ModRecipes.BLAST_FURNACE, this, 2, 2, this.inventory, inputs, outputs);
}
@Override
public void writeMultiblock(MultiblockWriter writer) {
BlockState basic = TRContent.MachineBlocks.BASIC.getCasing().getDefaultState();
BlockState advanced = TRContent.MachineBlocks.ADVANCED.getCasing().getDefaultState();
BlockState industrial = TRContent.MachineBlocks.INDUSTRIAL.getCasing().getDefaultState();
BlockState lava = Blocks.LAVA.getDefaultState();
BiPredicate<BlockView, BlockPos> casing = (view, pos) -> {
BlockState state = view.getBlockState(pos);
return basic == state || advanced == state || industrial == state;
};
BiPredicate<BlockView, BlockPos> maybeLava = (view, pos) -> {
BlockState state = view.getBlockState(pos);
return state == lava || state.getBlock() == Blocks.AIR;
};
writer.translate(1, 0, -1)
.fill(0, 0, 0, 3, 1, 3, casing, basic)
.ring(Direction.Axis.Y, 3, 1, 3, casing, basic, maybeLava, lava)
.ring(Direction.Axis.Y, 3, 2, 3, casing, basic, maybeLava, lava)
.fill(0, 3, 0, 3, 4, 3, casing, basic);
}
public int getHeat() {
if (!getMutliBlock()){
if (!isMultiblockValid()) {
return 0;
}
// Bottom center of multiblock
final BlockPos location = pos.offset(getFacing().getOpposite(), 2);
final BlockEntity blockEntity = world.getBlockEntity(location);
@ -93,22 +122,7 @@ public class IndustrialBlastFurnaceBlockEntity extends GenericMachineBlockEntity
return 0;
}
public boolean getMutliBlock() {
if(multiblockChecker == null){
return false;
}
final boolean layer0 = multiblockChecker.checkRectY(1, 1, MultiblockChecker.CASING_ANY, MultiblockChecker.ZERO_OFFSET);
final boolean layer1 = multiblockChecker.checkRingY(1, 1, MultiblockChecker.CASING_ANY, new BlockPos(0, 1, 0));
final boolean layer2 = multiblockChecker.checkRingY(1, 1, MultiblockChecker.CASING_ANY, new BlockPos(0, 2, 0));
final boolean layer3 = multiblockChecker.checkRectY(1, 1, MultiblockChecker.CASING_ANY, new BlockPos(0, 3, 0));
final Material centerBlock1 = multiblockChecker.getBlock(0, 1, 0).getMaterial();
final Material centerBlock2 = multiblockChecker.getBlock(0, 2, 0).getMaterial();
final boolean center1 = (centerBlock1 == Material.AIR || centerBlock1 == Material.LAVA);
final boolean center2 = (centerBlock2 == Material.AIR || centerBlock2 == Material.LAVA);
return layer0 && layer1 && layer2 && layer3 && center1 && center2;
}
public void setHeat(final int heat) {
cachedHeat = heat;
}
@ -116,17 +130,7 @@ public class IndustrialBlastFurnaceBlockEntity extends GenericMachineBlockEntity
public int getCachedHeat() {
return cachedHeat;
}
// TileGenericMachine
@Override
public void tick() {
if (multiblockChecker == null) {
final BlockPos downCenter = pos.offset(getFacing().getOpposite(), 2);
multiblockChecker = new MultiblockChecker(world, downCenter);
}
super.tick();
}
// IContainerProvider
@Override
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {

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) {
@ -99,7 +89,7 @@ public class IndustrialSawmillBlockEntity extends GenericMachineBlockEntity impl
super.tick();
}
// TilePowerAcceptor
@Override
public void fromTag(BlockState blockState, final CompoundTag tagCompound) {

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);
}
@ -50,10 +50,10 @@ public class AlloySmelterBlockEntity extends GenericMachineBlockEntity implement
@Override
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
return new ScreenHandlerBuilder("alloysmelter").player(player.inventory).inventory().hotbar()
.addInventory().blockEntity(this)
.slot(0, 34, 47)
.slot(1, 126, 47)
.outputSlot(2, 80, 47).energySlot(3, 8, 72).syncEnergyValue().syncCrafterValue().addInventory()
.create(this, syncID);
.addInventory().blockEntity(this)
.slot(0, 34, 47)
.slot(1, 126, 47)
.outputSlot(2, 80, 47).energySlot(3, 8, 72).syncEnergyValue().syncCrafterValue().addInventory()
.create(this, syncID);
}
}

View file

@ -40,17 +40,17 @@ 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);
}
// IContainerProvider
@Override
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
return new ScreenHandlerBuilder("assemblingmachine").player(player.inventory).inventory().hotbar()
.addInventory().blockEntity(this).slot(0, 55, 35).slot(1, 55, 55).outputSlot(2, 101, 45).energySlot(3, 8, 72)
.syncEnergyValue().syncCrafterValue().addInventory().create(this, syncID);
.addInventory().blockEntity(this).slot(0, 55, 35).slot(1, 55, 55).outputSlot(2, 101, 45).energySlot(3, 8, 72)
.syncEnergyValue().syncCrafterValue().addInventory().create(this, syncID);
}
}

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,8 +321,8 @@ public class AutoCraftingTableBlockEntity extends PowerAcceptorBlockEntity
}
if(!possibleSlots.isEmpty()){
int totalItems = possibleSlots.stream()
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);
}
@ -50,7 +50,7 @@ public class ChemicalReactorBlockEntity extends GenericMachineBlockEntity implem
@Override
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
return new ScreenHandlerBuilder("chemicalreactor").player(player.inventory).inventory().hotbar()
.addInventory().blockEntity(this).slot(0, 34, 47).slot(1, 126, 47).outputSlot(2, 80, 47).energySlot(3, 8, 72)
.syncEnergyValue().syncCrafterValue().addInventory().create(this, syncID);
.addInventory().blockEntity(this).slot(0, 34, 47).slot(1, 126, 47).outputSlot(2, 80, 47).energySlot(3, 8, 72)
.syncEnergyValue().syncCrafterValue().addInventory().create(this, syncID);
}
}

View file

@ -40,12 +40,12 @@ 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);
}
// IContainerProvider
@Override
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {

View file

@ -58,19 +58,19 @@ public class ElectricFurnaceBlockEntity extends PowerAcceptorBlockEntity
private int cookTimeTotal;
// Energy cost per tick of cooking
final int EnergyPerTick = 1;
public ElectricFurnaceBlockEntity() {
super(TRBlockEntities.ELECTRIC_FURNACE );
super(TRBlockEntities.ELECTRIC_FURNACE);
}
private void setInvDirty(boolean isDirty) {
inventory.setChanged(isDirty);
}
private boolean isInvDirty() {
return inventory.hasChanged();
}
private void updateCurrentRecipe() {
if (inventory.getStack(inputSlot).isEmpty()) {
resetCrafter();
@ -99,11 +99,11 @@ public class ElectricFurnaceBlockEntity extends PowerAcceptorBlockEntity
return true;
}
if (ItemUtils.isItemEqual(inventory.getStack(slot), recipeOutput, true, true)) {
return recipeOutput.getCount() + inventory.getStack(slot).getCount() <= recipeOutput.getMaxCount();
return recipeOutput.getCount() + inventory.getStack(slot).getCount() <= recipeOutput.getMaxCount();
}
return false;
}
public boolean canCraftAgain() {
if (inventory.getStack(inputSlot).isEmpty()) {
return false;
@ -114,16 +114,16 @@ public class ElectricFurnaceBlockEntity extends PowerAcceptorBlockEntity
if (!canAcceptOutput(currentRecipe, outputSlot)) {
return false;
}
return !(getEnergy() < currentRecipe.getCookTime() * getEuPerTick(EnergyPerTick));
}
return !(getEnergy() < currentRecipe.getCookTime() * getEuPerTick(EnergyPerTick));
}
private void resetCrafter() {
currentRecipe = null;
cookTime = 0;
cookTimeTotal = 0;
updateState();
}
private void updateState() {
Block furnaceBlock = getWorld().getBlockState(pos).getBlock();
@ -134,7 +134,7 @@ public class ElectricFurnaceBlockEntity extends PowerAcceptorBlockEntity
}
world.updateListeners(pos, world.getBlockState(pos), world.getBlockState(pos), 3);
}
private boolean hasAllInputs(SmeltingRecipe recipe) {
if (recipe == null) {
return false;
@ -143,9 +143,9 @@ public class ElectricFurnaceBlockEntity extends PowerAcceptorBlockEntity
return false;
}
return recipe.matches(inventory, world);
}
return recipe.matches(inventory, world);
}
private void craftRecipe(SmeltingRecipe recipe) {
if (recipe == null) {
return;
@ -156,22 +156,21 @@ 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);
}
inventory.getStack(inputSlot).decrement(1);
}
public int getProgressScaled(int scale) {
if (cookTimeTotal != 0) {
return cookTime * scale / cookTimeTotal;
}
return 0;
return 0;
}
public int getCookTime() {
return cookTime;
}
@ -179,7 +178,7 @@ public class ElectricFurnaceBlockEntity extends PowerAcceptorBlockEntity
public void setCookTime(int cookTime) {
this.cookTime = cookTime;
}
public int getCookTimeTotal() {
return cookTimeTotal;
}
@ -187,12 +186,13 @@ public class ElectricFurnaceBlockEntity extends PowerAcceptorBlockEntity
public void setCookTimeTotal(int cookTimeTotal) {
this.cookTimeTotal = cookTimeTotal;
}
// TilePowerAcceptor
@Override
public void tick() {
super.tick();
charge(2);
if (world.isClient) {
return;
}
@ -206,7 +206,7 @@ public class ElectricFurnaceBlockEntity extends PowerAcceptorBlockEntity
if (isInvDirty()) {
if (currentRecipe == null) {
updateCurrentRecipe();
updateCurrentRecipe();
}
if (currentRecipe != null && (!hasAllInputs(currentRecipe) || !canAcceptOutput(currentRecipe, outputSlot))) {
resetCrafter();

View file

@ -40,12 +40,12 @@ 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);
}
// IContainerProvider
@Override
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {

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;
@ -50,31 +52,34 @@ import java.util.List;
public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
implements IToolDrop, InventoryProvider, BuiltScreenHandlerProvider {
private final RebornInventory<GreenhouseControllerBlockEntity> inventory = new RebornInventory<>(7, "GreenhouseControllerBlockEntity", 64, this);
private BlockPos multiblockCenter;
private int ticksToNextMultiblockCheck = 0;
private boolean growthBoost = false;
public GreenhouseControllerBlockEntity() {
super(TRBlockEntities.GREENHOUSE_CONTROLLER);
}
public boolean getMultiBlock() {
if (multiblockCenter == null || world == null) {
return false;
}
for (int i = -1; i <= 1; i++) {
for (int j = -1; j <= 1; j++) {
BlockState block = world.getBlockState(multiblockCenter.add(i * 3, 3, i * 3));
if (!(block.getBlock() instanceof BlockLamp) || !BlockLamp.isActive(block)) {
return false;
}
@Override
public void writeMultiblock(MultiblockWriter writer) {
BlockState lamp = TRContent.Machine.LAMP_INCANDESCENT.block.getDefaultState().with(Properties.FACING, Direction.DOWN);
BlockState crop = Blocks.CACTUS.getDefaultState();
for (int i = -1; i < 2; i++) {
for (int j = -1; j < 2; j++) {
writer.add(i * 3, 3, j * 3, (world, pos) -> BlockLamp.isActive(world.getBlockState(pos)), lamp);
}
}
for (int i = -4; i <= 4; i++) {
for (int j = -4; j <= 4; j++) {
writer.add(i, 0, j, (world, pos) -> true, crop);
}
}
return true;
}
@Override
public void tick() {
if (multiblockCenter == null) {
@ -82,34 +87,34 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
}
charge(6);
super.tick();
if (world.isClient) {
return;
}
if (useEnergy(getEuPerTick(TechRebornConfig.greenhouseControllerEnergyPerTick)) != getEuPerTick(TechRebornConfig.greenhouseControllerEnergyPerTick)) {
return;
}
if (--ticksToNextMultiblockCheck < 0) {
growthBoost = getMultiBlock();
growthBoost = isMultiblockValid();
ticksToNextMultiblockCheck = 200;
}
if (world.getTime() % 20 == 0) {
double cyclesLimit = getSpeedMultiplier() * 4 + 1;
while (cyclesLimit-- > 0) {
workCycle();
}
}
}
private void workCycle() {
BlockPos blockPos = multiblockCenter.add(world.random.nextInt(9) - 4, 0, world.random.nextInt(9) - 4);
BlockState blockState = world.getBlockState(blockPos);
Block block = blockState.getBlock();
if (growthBoost) {
if (block instanceof Fertilizable
|| block instanceof PlantBlock
@ -122,7 +127,7 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
}
}
}
if (block instanceof CropBlock) {
processAgedCrop(blockState, blockPos, ((CropBlock) block).getAgeProperty(), ((CropBlock) block).getMaxAge(), 0);
} else if (block instanceof NetherWartBlock) {
@ -160,9 +165,9 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
}
}
}
}
private void processAgedCrop(BlockState blockState, BlockPos blockPos, IntProperty ageProperty, int maxAge, int newAge) {
if (blockState.get(ageProperty) >= maxAge) {
if (tryHarvestBlock(blockState, blockPos)) {
@ -170,7 +175,7 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
}
}
}
private boolean tryHarvestBlock(BlockState blockState, BlockPos blockPos) {
if (canUseEnergy(TechRebornConfig.greenhouseControllerEnergyPerHarvest)
&& insertIntoInv(Block.getDroppedStacks(blockState, (ServerWorld) world, blockPos, null))) {
@ -179,7 +184,7 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
}
return false;
}
private boolean insertIntoInv(List<ItemStack> stacks) {
boolean result = false;
for (ItemStack stack : stacks) {
@ -190,7 +195,7 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
}
return result;
}
private boolean insertIntoInv(int slot, ItemStack stack) {
ItemStack targetStack = inventory.getStack(slot);
if (targetStack.isEmpty()) {
@ -210,47 +215,42 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
}
return false;
}
@Override
public boolean canAcceptEnergy(Direction direction) {
return true;
}
@Override
public boolean canProvideEnergy(Direction direction) {
return false;
}
@Override
public double getBaseMaxPower() {
return TechRebornConfig.greenhouseControllerMaxEnergy;
}
@Override
public double getBaseMaxOutput() {
return 0;
}
@Override
public double getBaseMaxInput() {
return TechRebornConfig.greenhouseControllerMaxInput;
}
@Override
public ItemStack getToolDrop(PlayerEntity entityPlayer) {
return TRContent.Machine.GREENHOUSE_CONTROLLER.getStack();
}
@Override
public RebornInventory<GreenhouseControllerBlockEntity> getInventory() {
return this.inventory;
}
@Override
public boolean canBeUpgraded() {
return true;
}
@Override
public BuiltScreenHandler createScreenHandler(int syncID, PlayerEntity player) {
return new ScreenHandlerBuilder("greenhousecontroller").player(player.inventory).inventory().hotbar().addInventory()
@ -261,5 +261,5 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
.energySlot(6, 8, 72).syncEnergyValue()
.addInventory().create(this, syncID);
}
}

View file

@ -42,20 +42,20 @@ 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);
}
// IContainerProvider
@Override
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
return new ScreenHandlerBuilder("industrialelectrolyzer").player(player.inventory).inventory().hotbar()
.addInventory().blockEntity(this)
.filterSlot(1, 47, 72, stack -> ItemUtils.isItemEqual(stack, DynamicCellItem.getEmptyCell(1), true, true))
.filterSlot(0, 81, 72, stack -> !ItemUtils.isItemEqual(stack, DynamicCellItem.getEmptyCell(1), true, true))
.outputSlot(2, 51, 24).outputSlot(3, 71, 24).outputSlot(4, 91, 24).outputSlot(5, 111, 24)
.energySlot(6, 8, 72).syncEnergyValue().syncCrafterValue().addInventory().create(this, syncID);
.addInventory().blockEntity(this)
.filterSlot(1, 47, 72, stack -> ItemUtils.isItemEqual(stack, DynamicCellItem.getEmptyCell(1), true, true))
.filterSlot(0, 81, 72, stack -> !ItemUtils.isItemEqual(stack, DynamicCellItem.getEmptyCell(1), true, true))
.outputSlot(2, 51, 24).outputSlot(3, 71, 24).outputSlot(4, 91, 24).outputSlot(5, 111, 24)
.energySlot(6, 8, 72).syncEnergyValue().syncCrafterValue().addInventory().create(this, syncID);
}
}

View file

@ -47,7 +47,7 @@ public class PlayerDectectorBlockEntity extends PowerAcceptorBlockEntity impleme
public PlayerDectectorBlockEntity() {
super(TRBlockEntities.PLAYER_DETECTOR);
}
public boolean isProvidingPower() {
return redstone;
}
@ -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
@ -84,7 +84,7 @@ public class PlayerDectectorBlockEntity extends PowerAcceptorBlockEntity impleme
}
}
}
@Override
public double getBaseMaxPower() {
return TechRebornConfig.playerDetectorMaxEnergy;

View file

@ -61,7 +61,7 @@ public class RecyclerBlockEntity extends PowerAcceptorBlockEntity
public int gaugeProgressScaled(int scale) {
return progress * scale / time;
}
public int getProgress() {
return progress;
}
@ -69,7 +69,7 @@ public class RecyclerBlockEntity extends PowerAcceptorBlockEntity
public void setProgress(int progress) {
this.progress = progress;
}
public void recycleItems() {
ItemStack itemstack = TRContent.Parts.SCRAP.getStack();
final int randomchance = this.world.random.nextInt(chance);
@ -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;
@ -144,7 +139,7 @@ public class RecyclerBlockEntity extends PowerAcceptorBlockEntity
}
updateState();
if (updateInventory) {
markDirty();
}
@ -174,13 +169,13 @@ public class RecyclerBlockEntity extends PowerAcceptorBlockEntity
public double getBaseMaxInput() {
return TechRebornConfig.recyclerMaxInput;
}
// TileMachineBase
@Override
public boolean canBeUpgraded() {
return true;
}
// IToolDrop
@Override
public ItemStack getToolDrop(PlayerEntity entityPlayer) {

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

@ -59,9 +59,9 @@ import java.util.stream.Collectors;
//TODO add tick and power bars.
public class RollingMachineBlockEntity extends PowerAcceptorBlockEntity
implements IToolDrop, InventoryProvider, BuiltScreenHandlerProvider {
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,32 +223,32 @@ public class RollingMachineBlockEntity extends PowerAcceptorBlockEntity
}
}
if(!possibleSlots.isEmpty()){
int totalItems = possibleSlots.stream()
.mapToInt(value -> inventory.getStack(value).getCount()).sum();
if (!possibleSlots.isEmpty()) {
int totalItems = possibleSlots.stream()
.mapToInt(value -> inventory.getStack(value).getCount()).sum();
int slots = possibleSlots.size();
//This makes an array of ints with the best possible slot EnvTyperibution
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--;
}
}
}
List<Integer> slotEnvTyperubution = possibleSlots.stream()
.mapToInt(value -> inventory.getStack(value).getCount())
.boxed().collect(Collectors.toList());
.mapToInt(value -> inventory.getStack(value).getCount())
.boxed().collect(Collectors.toList());
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 {
@ -276,10 +276,10 @@ public class RollingMachineBlockEntity extends PowerAcceptorBlockEntity
}
}
if (bestSlot == null
|| bestSlot.getLeft() == balanceSlot
|| bestSlot.getRight() == sourceStack.getCount()
|| inventory.getStack(bestSlot.getLeft()).isEmpty()
|| !ItemUtils.isItemEqual(sourceStack, inventory.getStack(bestSlot.getLeft()), true, true)) {
|| bestSlot.getLeft() == balanceSlot
|| bestSlot.getRight() == sourceStack.getCount()
|| inventory.getStack(bestSlot.getLeft()).isEmpty()
|| !ItemUtils.isItemEqual(sourceStack, inventory.getStack(bestSlot.getLeft()), true, true)) {
return Optional.empty();
}
sourceStack.decrement(1);
@ -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();
@ -342,7 +342,7 @@ public class RollingMachineBlockEntity extends PowerAcceptorBlockEntity
}
return null;
}
@Override
public ItemStack getToolDrop(final PlayerEntity entityPlayer) {
return TRContent.Machine.ROLLING_MACHINE.getStack();
@ -379,24 +379,24 @@ 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
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
return new ScreenHandlerBuilder("rollingmachine").player(player.inventory)
.inventory().hotbar()
.addInventory().blockEntity(this)
.slot(0, 30, 22).slot(1, 48, 22).slot(2, 66, 22)
.slot(3, 30, 40).slot(4, 48, 40).slot(5, 66, 40)
.slot(6, 30, 58).slot(7, 48, 58).slot(8, 66, 58)
.onCraft(inv -> this.inventory.setStack(1, findMatchingRecipeOutput(getCraftingMatrix(), this.world)))
.outputSlot(9, 124, 40)
.energySlot(10, 8, 70)
.syncEnergyValue().sync(this::getBurnTime, this::setBurnTime).sync(this::getLockedInt, this::setLockedInt).addInventory().create(this, syncID);
.inventory().hotbar()
.addInventory().blockEntity(this)
.slot(0, 30, 22).slot(1, 48, 22).slot(2, 66, 22)
.slot(3, 30, 40).slot(4, 48, 40).slot(5, 66, 40)
.slot(6, 30, 58).slot(7, 48, 58).slot(8, 66, 58)
.onCraft(inv -> this.inventory.setStack(1, findMatchingRecipeOutput(getCraftingMatrix(), this.world)))
.outputSlot(9, 124, 40)
.energySlot(10, 8, 70)
.syncEnergyValue().sync(this::getBurnTime, this::setBurnTime).sync(this::getLockedInt, this::setLockedInt).addInventory().create(this, syncID);
}
//Easyest way to sync back to the client
@ -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,12 +39,12 @@ 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);
}
// TileMachineBase
@Override
public boolean canBeUpgraded() {

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);
}
@ -50,10 +50,10 @@ public class SoildCanningMachineBlockEntity extends GenericMachineBlockEntity im
@Override
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
return new ScreenHandlerBuilder("solidcanningmachine").player(player.inventory).inventory().hotbar()
.addInventory().blockEntity(this)
.slot(0, 34, 47)
.slot(1, 126, 47)
.outputSlot(2, 80, 47).energySlot(3, 8, 72).syncEnergyValue().syncCrafterValue().addInventory()
.create(this, syncID);
.addInventory().blockEntity(this)
.slot(0, 34, 47)
.slot(1, 126, 47)
.outputSlot(2, 80, 47).energySlot(3, 8, 72).syncEnergyValue().syncCrafterValue().addInventory()
.create(this, syncID);
}
}

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);
}
@ -49,13 +49,13 @@ public class WireMillBlockEntity extends GenericMachineBlockEntity implements Bu
@Override
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
return new ScreenHandlerBuilder("wiremill").player(player.inventory).inventory().hotbar()
.addInventory().blockEntity(this)
.slot(0, 55, 45)
.outputSlot(1, 101, 45)
.energySlot(2, 8, 72)
.syncEnergyValue()
.syncCrafterValue()
.addInventory()
.create(this, syncID);
.addInventory().blockEntity(this)
.slot(0, 55, 45)
.outputSlot(1, 101, 45)
.energySlot(2, 8, 72)
.syncEnergyValue()
.syncCrafterValue()
.addInventory()
.create(this, syncID);
}
}

View file

@ -55,10 +55,10 @@ public class ChunkLoaderBlockEntity extends MachineBaseBlockEntity implements IT
private String ownerUdid;
public ChunkLoaderBlockEntity() {
super(TRBlockEntities.CHUNK_LOADER );
super(TRBlockEntities.CHUNK_LOADER);
this.radius = 1;
}
public void handleGuiInputFromClient(int buttonID, @Nullable PlayerEntity playerEntity) {
radius += buttonID;
@ -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);
@ -158,7 +158,7 @@ public class ChunkLoaderBlockEntity extends MachineBaseBlockEntity implements IT
public int getRadius() {
return radius;
}
public void setRadius(int radius) {
this.radius = radius;
}

View file

@ -48,29 +48,29 @@ 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);
}
// IContainerProvider
@Override
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
return new ScreenHandlerBuilder("centrifuge").player(player.inventory).inventory().hotbar()
.addInventory().blockEntity(this)
.filterSlot(1, 40, 54, stack -> ItemUtils.isItemEqual(stack, DynamicCellItem.getEmptyCell(1), true, true))
.filterSlot(0, 40, 34, stack -> !ItemUtils.isItemEqual(stack, DynamicCellItem.getEmptyCell(1), true, true))
.outputSlot(2, 82, 44).outputSlot(3, 101, 25)
.outputSlot(4, 120, 44).outputSlot(5, 101, 63).energySlot(6, 8, 72).syncEnergyValue()
.syncCrafterValue().addInventory().create(this, syncID);
.addInventory().blockEntity(this)
.filterSlot(1, 40, 54, stack -> ItemUtils.isItemEqual(stack, DynamicCellItem.getEmptyCell(1), true, true))
.filterSlot(0, 40, 34, stack -> !ItemUtils.isItemEqual(stack, DynamicCellItem.getEmptyCell(1), true, true))
.outputSlot(2, 82, 44).outputSlot(3, 101, 25)
.outputSlot(4, 120, 44).outputSlot(5, 101, 63).energySlot(6, 8, 72).syncEnergyValue()
.syncCrafterValue().addInventory().create(this, syncID);
}
// IListInfoProvider
@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() {
@ -61,7 +61,7 @@ public class MatterFabricatorBlockEntity extends PowerAcceptorBlockEntity
private boolean spaceForOutput(int slot) {
return inventory.getStack(slot).isEmpty()
|| ItemUtils.isItemEqual(inventory.getStack(slot), TRContent.Parts.UU_MATTER.getStack(), true, true)
&& inventory.getStack(slot).getCount() < 64;
&& inventory.getStack(slot).getCount() < 64;
}
private void addOutputProducts() {
@ -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

@ -84,7 +84,7 @@ public class EnergyStorageBlockEntity extends PowerAcceptorBlockEntity
charge(1);
}
}
@Override
public double getBaseMaxPower() {
return maxStorage;
@ -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();
@ -128,7 +130,7 @@ public class EnergyStorageBlockEntity extends PowerAcceptorBlockEntity
}
return null;
}
@Override
public boolean canBeUpgraded() {
return false;
@ -139,7 +141,7 @@ public class EnergyStorageBlockEntity extends PowerAcceptorBlockEntity
public ItemStack getToolDrop(PlayerEntity entityPlayer) {
return new ItemStack(wrenchDrop);
}
// InventoryProvider
@Override
public RebornInventory<EnergyStorageBlockEntity> getInventory() {

View file

@ -34,12 +34,11 @@ import techreborn.init.TRContent;
/**
* Created by modmuss50 on 14/03/2016.
*
*/
public class HighVoltageSUBlockEntity extends EnergyStorageBlockEntity implements BuiltScreenHandlerProvider {
/**
* MFSU should store 4M Energy with 512 E/t I/O
* MFSU should store 4M Energy with 512 E/t I/O
*/
public HighVoltageSUBlockEntity() {
super(TRBlockEntities.HIGH_VOLTAGE_SU, "HIGH_VOLTAGE_SU", 2, TRContent.Machine.HIGH_VOLTAGE_SU.block, EnergyTier.HIGH, 4_000_000);
@ -48,7 +47,7 @@ public class HighVoltageSUBlockEntity extends EnergyStorageBlockEntity implement
@Override
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
return new ScreenHandlerBuilder("mfsu").player(player.inventory).inventory().hotbar().armor()
.complete(8, 18).addArmor().addInventory().blockEntity(this).energySlot(0, 62, 45).energySlot(1, 98, 45)
.syncEnergyValue().addInventory().create(this, syncID);
.complete(8, 18).addArmor().addInventory().blockEntity(this).energySlot(0, 62, 45).energySlot(1, 98, 45)
.syncEnergyValue().addInventory().create(this, syncID);
}
}

View file

@ -44,6 +44,6 @@ public class LowVoltageSUBlockEntity extends EnergyStorageBlockEntity implements
@Override
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
return new ScreenHandlerBuilder("batbox").player(player.inventory).inventory().hotbar().addInventory()
.blockEntity(this).energySlot(0, 62, 45).energySlot(1, 98, 45).syncEnergyValue().addInventory().create(this, syncID);
.blockEntity(this).energySlot(0, 62, 45).energySlot(1, 98, 45).syncEnergyValue().addInventory().create(this, syncID);
}
}

View file

@ -34,12 +34,11 @@ import techreborn.init.TRContent;
/**
* Created by modmuss50 on 14/03/2016.
*
*/
public class MediumVoltageSUBlockEntity extends EnergyStorageBlockEntity implements BuiltScreenHandlerProvider {
/**
* MFE should store 300k energy with 128 E/t I/O
* MFE should store 300k energy with 128 E/t I/O
*/
public MediumVoltageSUBlockEntity() {
super(TRBlockEntities.MEDIUM_VOLTAGE_SU, "MEDIUM_VOLTAGE_SU", 2, TRContent.Machine.MEDIUM_VOLTAGE_SU.block, EnergyTier.MEDIUM, 300_000);
@ -48,8 +47,8 @@ public class MediumVoltageSUBlockEntity extends EnergyStorageBlockEntity impleme
@Override
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
return new ScreenHandlerBuilder("mfe").player(player.inventory).inventory().hotbar().armor()
.complete(8, 18).addArmor().addInventory().blockEntity(this).energySlot(0, 62, 45).energySlot(1, 98, 45)
.syncEnergyValue().addInventory().create(this, syncID);
.complete(8, 18).addArmor().addInventory().blockEntity(this).energySlot(0, 62, 45).energySlot(1, 98, 45)
.syncEnergyValue().addInventory().create(this, syncID);
}
}

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,19 +65,19 @@ 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);
}
}
@Override
public double useEnergy(double extract, boolean simulate) {
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();
@ -89,13 +89,13 @@ public class InterdimensionalSUBlockEntity extends EnergyStorageBlockEntity impl
}
return extract;
}
@Override
public boolean canUseEnergy(double input) {
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();
@ -120,8 +120,8 @@ public class InterdimensionalSUBlockEntity extends EnergyStorageBlockEntity impl
@Override
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
return new ScreenHandlerBuilder("idsu").player(player.inventory).inventory().hotbar().armor()
.complete(8, 18).addArmor().addInventory().blockEntity(this).energySlot(0, 62, 45).energySlot(1, 98, 45)
.syncEnergyValue().addInventory().create(this, syncID);
.complete(8, 18).addArmor().addInventory().blockEntity(this).energySlot(0, 62, 45).energySlot(1, 98, 45)
.syncEnergyValue().addInventory().create(this, syncID);
}
@Override

View file

@ -36,7 +36,7 @@ import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
public class LSUStorageBlockEntity extends MachineBaseBlockEntity
implements IToolDrop {
implements IToolDrop {
public LesuNetwork network;
@ -93,7 +93,7 @@ public class LSUStorageBlockEntity extends MachineBaseBlockEntity
} else {
if (network.master != null
&& network.master.getWorld().getBlockEntity(new BlockPos(network.master.getPos().getX(),
network.master.getPos().getY(), network.master.getPos().getZ())) != network.master) {
network.master.getPos().getY(), network.master.getPos().getZ())) != network.master) {
network.master = null;
}
}

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(){
maxStorage = (connectedBlocks + 1) * TechRebornConfig.lesuStoragePerBlock;
private void setMaxStorage() {
maxStorage = (connectedBlocks + 1) * TechRebornConfig.lesuStoragePerBlock;
if (maxStorage < 0 || maxStorage > Integer.MAX_VALUE) {
maxStorage = Integer.MAX_VALUE;
}
}
private void setIORate(){
maxOutput = TechRebornConfig.lesuBaseOutput + (connectedBlocks * TechRebornConfig.lesuExtraIOPerBlock);
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;
@ -81,7 +80,7 @@ public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements I
}
if (FluidUtils.drainContainers(tank, inventory, 0, 1)
|| FluidUtils.fillContainers(tank, inventory, 0, 1, tank.getFluid())) {
|| FluidUtils.fillContainers(tank, inventory, 0, 1, tank.getFluid())) {
if (type == TRContent.TankUnit.CREATIVE) {
if (!tank.isEmpty() && !tank.isFull()) {
@ -137,8 +136,8 @@ public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements I
if (!this.tank.getFluidInstance().isEmpty()) {
info.add(
new LiteralText(String.valueOf(this.tank.getFluidAmount()))
.append(new TranslatableText("techreborn.tooltip.unit.divider"))
.append(WordUtils.capitalize(FluidUtil.getFluidName(this.tank.getFluid())))
.append(new TranslatableText("techreborn.tooltip.unit.divider"))
.append(WordUtils.capitalize(FluidUtil.getFluidName(this.tank.getFluid())))
);
} else {
info.add(new TranslatableText("techreborn.tooltip.unit.empty"));
@ -146,14 +145,14 @@ public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements I
}
info.add(
new TranslatableText("techreborn.tooltip.unit.capacity")
.formatted(Formatting.GRAY)
.append(
new LiteralText(String.valueOf(this.tank.getCapacity()))
.formatted(Formatting.GOLD)
.append(" (")
.append(String.valueOf(this.tank.getCapacity().getRawValue() / 1000))
.append(")")
)
.formatted(Formatting.GRAY)
.append(
new LiteralText(String.valueOf(this.tank.getCapacity()))
.formatted(Formatting.GOLD)
.append(" (")
.append(String.valueOf(this.tank.getCapacity().getRawValue() / 1000))
.append(")")
)
);
}
@ -161,8 +160,8 @@ public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements I
@Override
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
return new ScreenHandlerBuilder("tank").player(player.inventory).inventory().hotbar()
.addInventory().blockEntity(this).fluidSlot(0, 100, 53).outputSlot(1, 140, 53)
.sync(tank).addInventory().create(this, syncID);
.addInventory().blockEntity(this).fluidSlot(0, 100, 53).outputSlot(1, 140, 53)
.sync(tank).addInventory().create(this, syncID);
}
@Nonnull

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()));
}
@ -357,9 +354,9 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity
if (isReal || hasData) {
if (!this.isEmpty()) {
info.add(
new LiteralText(String.valueOf(this.getCurrentCapacity()))
.append(new TranslatableText("techreborn.tooltip.unit.divider"))
.append(this.getStoredStack().getName())
new LiteralText(String.valueOf(this.getCurrentCapacity()))
.append(new TranslatableText("techreborn.tooltip.unit.divider"))
.append(this.getStoredStack().getName())
);
} else {
info.add(new TranslatableText("techreborn.tooltip.unit.empty"));
@ -368,14 +365,14 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity
info.add(
new TranslatableText("techreborn.tooltip.unit.capacity")
.formatted(Formatting.GRAY)
.append(
new LiteralText(String.valueOf(this.getMaxCapacity()))
.formatted(Formatting.GOLD)
.append(" items (")
.append(String.valueOf(this.getMaxCapacity() / 64))
.append(")")
)
.formatted(Formatting.GRAY)
.append(
new LiteralText(String.valueOf(this.getMaxCapacity()))
.formatted(Formatting.GOLD)
.append(" items (")
.append(String.valueOf(this.getMaxCapacity() / 64))
.append(")")
)
);
}
@ -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

@ -76,7 +76,7 @@ public class TransformerBlockEntity extends PowerAcceptorBlockEntity
// Should always be 4, except if we're tier MICRO, in which it will be 1.
super.setMaxPacketsPerTick(tier.getMaxOutput() / ouputTier.getMaxInput());
}
// TilePowerAcceptor
@Override
public double getBaseMaxPower() {
@ -85,15 +85,15 @@ public class TransformerBlockEntity extends PowerAcceptorBlockEntity
@Override
public boolean canAcceptEnergy(Direction direction) {
if (TechRebornConfig.IC2TransformersStyle){
if (TechRebornConfig.IC2TransformersStyle) {
return getFacingEnum() == direction;
}
return getFacingEnum() != direction;
}
@Override
public boolean canProvideEnergy(Direction direction) {
if (TechRebornConfig.IC2TransformersStyle){
if (TechRebornConfig.IC2TransformersStyle) {
return getFacingEnum() != direction;
}
return getFacing() == direction;
@ -108,7 +108,7 @@ public class TransformerBlockEntity extends PowerAcceptorBlockEntity
public double getBaseMaxInput() {
return inputTier.getMaxInput();
}
@Override
public EnergyTier getPushingTier() {
return ouputTier;
@ -118,11 +118,11 @@ public class TransformerBlockEntity extends PowerAcceptorBlockEntity
public void checkTier() {
//Nope
}
// 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

@ -52,12 +52,12 @@ public final class CableShapeUtil {
}
private VoxelShape getStateShape(BlockState state) {
final double size = cableBlock.type != null ? cableBlock.type.cableThickness : 6;
final double size = cableBlock.type != null ? cableBlock.type.cableThickness : 6;
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

@ -81,7 +81,7 @@ public class BlockFusionCoil extends Block {
@Environment(EnvType.CLIENT)
@Override
public void buildTooltip(ItemStack stack, @Nullable BlockView worldIn, List<Text> tooltip,
TooltipContext flagIn) {
TooltipContext flagIn) {
super.buildTooltip(stack, worldIn, tooltip, flagIn);
// TODO: Translate
tooltip.add(new LiteralText("Right click Fusion Control computer to auto place"));

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);
}
}
@ -96,7 +97,7 @@ public class BlockFusionControlComputer extends BlockMachineBase {
public BlockEntity createBlockEntity(BlockView worldIn) {
return new FusionControlComputerBlockEntity();
}
@Override
public boolean isAdvanced() {
return true;

View file

@ -40,14 +40,14 @@ import techreborn.init.TRContent.SolarPanels;
* Created by modmuss50 on 25/02/2016.
*/
public class BlockSolarPanel extends BlockMachineBase {
public final SolarPanels panelType;
public BlockSolarPanel(SolarPanels panel) {
super();
this.panelType = panel;
}
@Override
public BlockEntity createBlockEntity(BlockView worldIn) {
return new SolarPanelBlockEntity(panelType);
@ -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

@ -39,17 +39,17 @@ import java.util.function.Supplier;
* for generators, like comparator output based on energy.
*/
public class GenericGeneratorBlock extends GenericMachineBlock {
public GenericGeneratorBlock(IMachineGuiHandler gui, Supplier<BlockEntity> blockEntityClass) {
super(gui, blockEntityClass);
}
public GenericGeneratorBlock(IMachineGuiHandler gui, Supplier<BlockEntity> blockEntityClass) {
super(gui, blockEntityClass);
}
@Override
public boolean hasComparatorOutput(BlockState state) {
return true;
}
@Override
public boolean hasComparatorOutput(BlockState state) {
return true;
}
@Override
public int getComparatorOutput(BlockState state, World world, BlockPos pos) {
return PowerAcceptorBlockEntity.calculateComparatorOutputFromEnergy(world.getBlockEntity(pos));
}
@Override
public int getComparatorOutput(BlockState state, World world, BlockPos pos) {
return PowerAcceptorBlockEntity.calculateComparatorOutputFromEnergy(world.getBlockEntity(pos));
}
}

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));
@ -66,9 +66,9 @@ public class BlockLamp extends BaseBlockEntityProvider {
this.setDefaultState(this.getStateManager().getDefaultState().with(FACING, Direction.NORTH).with(ACTIVE, false));
BlockWrenchEventHandler.wrenableBlocks.add(this);
}
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),
@ -76,7 +76,7 @@ public class BlockLamp extends BaseBlockEntityProvider {
createCuboidShape(culling, culling, 0.0D, 16.0 - culling, 16.0 - culling, depth),
createCuboidShape(16.0 - depth, culling, culling, 16.0D, 16.0 - culling, 16.0 - culling),
createCuboidShape(0.0D, culling, culling, depth, 16.0 - culling, 16.0 - culling)
};
};
}
@Override
@ -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);
}
@ -105,12 +105,12 @@ public class BlockLamp extends BaseBlockEntityProvider {
public int getCost() {
return cost;
}
// BaseTileBlock
@Override
public BlockEntity createBlockEntity(BlockView worldIn) {
return new LampBlockEntity();
}
}
// Block
@Override
@ -118,7 +118,7 @@ public class BlockLamp extends BaseBlockEntityProvider {
ACTIVE = BooleanProperty.of("active");
builder.add(FACING, ACTIVE);
}
@Nullable
@Override
public BlockState getPlacementState(ItemPlacementContext context) {
@ -135,7 +135,7 @@ public class BlockLamp extends BaseBlockEntityProvider {
public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.MODEL;
}
@Override
public ActionResult onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity playerIn, Hand hand, BlockHitResult hitResult) {
ItemStack stack = playerIn.getStackInHand(Hand.MAIN_HAND);

View file

@ -40,7 +40,7 @@ import techreborn.client.GuiType;
import java.util.Random;
public class IronAlloyFurnaceBlock extends GenericMachineBlock {
public IronAlloyFurnaceBlock() {
super(GuiType.ALLOY_FURNACE, IronAlloyFurnaceBlockEntity::new);
}
@ -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

@ -40,11 +40,11 @@ import techreborn.client.GuiType;
import java.util.Random;
public class IronFurnaceBlock extends GenericMachineBlock {
public IronFurnaceBlock() {
super(GuiType.IRON_FURNACE, IronFurnaceBlockEntity::new);
}
// Block
@Environment(EnvType.CLIENT)
public void randomDisplayTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) {
@ -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

@ -68,30 +68,30 @@ public class BlockPlayerDetector extends BlockMachineBase {
public BlockEntity createBlockEntity(BlockView worldIn) {
return new PlayerDectectorBlockEntity();
}
@Override
public void onPlaced(World worldIn, BlockPos pos, BlockState state, LivingEntity placer,
ItemStack stack) {
ItemStack stack) {
super.onPlaced(worldIn, pos, state, placer, stack);
BlockEntity blockEntity = worldIn.getBlockEntity(pos);
if (blockEntity instanceof PlayerDectectorBlockEntity) {
((PlayerDectectorBlockEntity) blockEntity).owenerUdid = placer.getUuid().toString();
}
}
@Override
public ActionResult onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity playerIn, Hand hand, BlockHitResult hitResult) {
ItemStack stack = playerIn.getStackInHand(Hand.MAIN_HAND);
BlockEntity blockEntity = worldIn.getBlockEntity(pos);
if (blockEntity == null) {
return super.onUse(state, worldIn, pos, playerIn, hand, hitResult);
}
PlayerDetectorType type = state.get(TYPE);
PlayerDetectorType newType = type;
Formatting color = Formatting.GREEN;
if (!stack.isEmpty() && ToolManager.INSTANCE.canHandleTool(stack)) {
if (ToolManager.INSTANCE.handleTool(stack, pos, worldIn, playerIn, hitResult.getSide(), false)) {
if (playerIn.isSneaking()) {
@ -126,22 +126,22 @@ public class BlockPlayerDetector extends BlockMachineBase {
if (worldIn.isClient) {
ChatUtils.sendNoSpamMessages(MessageIDs.playerDetectorID,
new TranslatableText("techreborn.message.detects")
.formatted(Formatting.GRAY)
.append(" ")
.append(
new LiteralText(StringUtils.toFirstCapital(newType.asString()))
.formatted(color)
)
.formatted(Formatting.GRAY)
.append(" ")
.append(
new LiteralText(StringUtils.toFirstCapital(newType.asString()))
.formatted(color)
)
);
}
return ActionResult.SUCCESS;
}
@Override
public IMachineGuiHandler getGui() {
return null;
}
// Block
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
@ -171,13 +171,13 @@ public class BlockPlayerDetector extends BlockMachineBase {
}
return 0;
}
public enum PlayerDetectorType implements StringIdentifiable {
ALL("all"), OTHERS("others"), YOU("you");
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

@ -55,7 +55,7 @@ import javax.annotation.Nullable;
import java.util.List;
public class BlockAlarm extends BaseBlockEntityProvider {
public static DirectionProperty FACING = Properties.FACING;
public static DirectionProperty FACING = Properties.FACING;
public static BooleanProperty ACTIVE;
protected final VoxelShape[] shape;
@ -65,9 +65,9 @@ public class BlockAlarm extends BaseBlockEntityProvider {
this.shape = GenCuboidShapes(3, 10);
BlockWrenchEventHandler.wrenableBlocks.add(this);
}
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),
@ -78,13 +78,13 @@ public class BlockAlarm extends BaseBlockEntityProvider {
};
return shapes;
}
public static boolean isActive(BlockState state) {
return state.get(ACTIVE);
}
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) {
@ -96,21 +96,21 @@ public class BlockAlarm extends BaseBlockEntityProvider {
BlockState state = world.getBlockState(pos).with(ACTIVE, active).with(FACING, facing);
world.setBlockState(pos, state, 3);
}
// BaseTileBlock
@Nullable
@Override
public BlockEntity createBlockEntity(BlockView worldIn) {
return new AlarmBlockEntity();
}
// Block
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
ACTIVE = BooleanProperty.of("active");
builder.add(FACING, ACTIVE);
}
@Nullable
@Override
public BlockState getPlacementState(ItemPlacementContext context) {

View file

@ -47,7 +47,7 @@ public class BlockComputerCube extends BlockMachineBase {
public IMachineGuiHandler getGui() {
return null;
}
@Override
public ActionResult onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity playerIn, Hand hand, BlockHitResult hitResult) {
@ -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);
}
@ -105,7 +105,7 @@ public class BlockNuke extends BaseBlock {
worldIn.setBlockState(pos, Blocks.AIR.getDefaultState());
}
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(OVERLAY);

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

@ -30,7 +30,7 @@ import techreborn.blockentity.storage.energy.AdjustableSUBlockEntity;
import techreborn.client.GuiType;
public class AdjustableSUBlock extends EnergyStorageBlock {
public AdjustableSUBlock() {
super("AESU", GuiType.AESU);
}

View file

@ -93,7 +93,7 @@ public abstract class EnergyStorageBlock extends BaseBlockEntityProvider {
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(FACING);
}
@SuppressWarnings("deprecation")
@Override
public ActionResult onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity playerIn, Hand hand, BlockHitResult hitResult) {

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