Merge remote-tracking branch 'remotes/origin/1.14' into 1.15
# Conflicts: # build.gradle # src/main/java/techreborn/blocks/misc/BlockRubberLog.java
This commit is contained in:
commit
d5e89c5e20
139 changed files with 1534 additions and 501 deletions
|
@ -32,12 +32,12 @@ import reborncore.api.blockentity.InventoryProvider;
|
|||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.powerSystem.ExternalPowerSystems;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import team.reborn.energy.Energy;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.init.TRContent;
|
||||
|
||||
public class ChargeOMatBlockEntity extends PowerAcceptorBlockEntity
|
||||
implements IToolDrop, InventoryProvider, IContainerProvider {
|
||||
|
@ -59,8 +59,13 @@ public class ChargeOMatBlockEntity extends PowerAcceptorBlockEntity
|
|||
for (int i = 0; i < 6; i++) {
|
||||
ItemStack stack = inventory.getInvStack(i);
|
||||
|
||||
if (!stack.isEmpty()) {
|
||||
ExternalPowerSystems.chargeItem(this, stack);
|
||||
if (Energy.valid(stack)) {
|
||||
Energy.of(this)
|
||||
.into(
|
||||
Energy
|
||||
.of(stack)
|
||||
)
|
||||
.move();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +82,7 @@ public class ChargeOMatBlockEntity extends PowerAcceptorBlockEntity
|
|||
|
||||
@Override
|
||||
public boolean canProvideEnergy(final Direction direction) {
|
||||
return false;
|
||||
return direction == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -24,6 +24,10 @@
|
|||
|
||||
package techreborn.blockentity.cable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.client.network.packet.BlockEntityUpdateS2CPacket;
|
||||
|
@ -35,6 +39,7 @@ import net.minecraft.text.Text;
|
|||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.Tickable;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import reborncore.api.IListInfoProvider;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
|
@ -44,14 +49,10 @@ import team.reborn.energy.Energy;
|
|||
import team.reborn.energy.EnergySide;
|
||||
import team.reborn.energy.EnergyStorage;
|
||||
import team.reborn.energy.EnergyTier;
|
||||
import techreborn.blocks.cable.BlockCable;
|
||||
import techreborn.blocks.cable.CableBlock;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.init.TRContent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 19/05/2017.
|
||||
*/
|
||||
|
@ -60,19 +61,28 @@ public class CableBlockEntity extends BlockEntity
|
|||
implements Tickable, IListInfoProvider, IToolDrop, EnergyStorage {
|
||||
|
||||
private double energy = 0;
|
||||
private int transferRate = 0;
|
||||
private TRContent.Cables cableType = null;
|
||||
private ArrayList<Direction> sendingFace = new ArrayList<Direction>();
|
||||
int ticksSinceLastChange = 0;
|
||||
private ArrayList<EnergySide> sendingFace = new ArrayList<>();
|
||||
|
||||
public CableBlockEntity() {
|
||||
super(TRBlockEntities.CABLE);
|
||||
}
|
||||
|
||||
public CableBlockEntity(TRContent.Cables type) {
|
||||
super(TRBlockEntities.CABLE);
|
||||
this.cableType = type;
|
||||
}
|
||||
|
||||
private TRContent.Cables getCableType() {
|
||||
if (cableType != null) {
|
||||
return cableType;
|
||||
}
|
||||
if (world == null) {
|
||||
return TRContent.Cables.COPPER;
|
||||
}
|
||||
Block block = world.getBlockState(pos).getBlock();
|
||||
if(block instanceof BlockCable){
|
||||
return ((BlockCable) block).type;
|
||||
if(block instanceof CableBlock){
|
||||
return ((CableBlock) block).type;
|
||||
}
|
||||
//Something has gone wrong if this happens
|
||||
return TRContent.Cables.COPPER;
|
||||
|
@ -108,61 +118,57 @@ public class CableBlockEntity extends BlockEntity
|
|||
}
|
||||
return compound;
|
||||
}
|
||||
|
||||
// ITickable
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (world.isClient) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cableType == null) {
|
||||
cableType = getCableType();
|
||||
transferRate = cableType.transferRate;
|
||||
sendingFace.clear();
|
||||
|
||||
if(getEnergy() == 0){
|
||||
return;
|
||||
}
|
||||
|
||||
ticksSinceLastChange++;
|
||||
if (ticksSinceLastChange >= 20) {
|
||||
sendingFace.clear();
|
||||
ticksSinceLastChange = 0;
|
||||
}
|
||||
|
||||
ArrayList<BlockEntity> acceptors = new ArrayList<BlockEntity>();
|
||||
ArrayList<Pair<BlockEntity, Direction>> acceptors = new ArrayList<>();
|
||||
for (Direction face : Direction.values()) {
|
||||
EnergySide side = EnergySide.fromMinecraft(face);
|
||||
BlockEntity blockEntity = world.getBlockEntity(pos.offset(face));
|
||||
|
||||
if (blockEntity == null) {
|
||||
continue;
|
||||
} else if (Energy.valid(blockEntity)) {
|
||||
if (blockEntity != null && Energy.valid(blockEntity)) {
|
||||
if (blockEntity instanceof CableBlockEntity && energy <= Energy.of(blockEntity).side(EnergySide.fromMinecraft(face)).getEnergy()) {
|
||||
continue;
|
||||
}
|
||||
acceptors.add(blockEntity);
|
||||
if (!sendingFace.contains(face)) {
|
||||
sendingFace.add(face);
|
||||
if(Energy.of(blockEntity).side(EnergySide.fromMinecraft(face.getOpposite())).getMaxInput() > 0){
|
||||
acceptors.add(Pair.of(blockEntity, face));
|
||||
if (!sendingFace.contains(side)) {
|
||||
sendingFace.add(side);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (acceptors.size() == 0) {
|
||||
if (acceptors.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Collections.shuffle(acceptors);
|
||||
acceptors.forEach(blockEntity -> Energy.of(this)
|
||||
.into(Energy.of(blockEntity))
|
||||
.move());
|
||||
|
||||
acceptors.forEach(pair -> {
|
||||
Energy.of(this)
|
||||
.into(Energy.of(pair.getLeft()).side(EnergySide.fromMinecraft(pair.getRight().getOpposite())))
|
||||
.move();
|
||||
});
|
||||
}
|
||||
|
||||
// IListInfoProvider
|
||||
@Override
|
||||
public void addInfo(List<Text> info, boolean isReal, boolean hasData) {
|
||||
if (isReal) {
|
||||
info.add(new LiteralText(Formatting.GRAY + StringUtils.t("techreborn.tooltip.transferRate") + ": "
|
||||
+ Formatting.GOLD
|
||||
+ PowerSystem.getLocaliszedPowerFormatted(transferRate) + "/t"));
|
||||
+ PowerSystem.getLocaliszedPowerFormatted(getCableType().transferRate) + "/t"));
|
||||
info.add(new LiteralText(Formatting.GRAY + StringUtils.t("techreborn.tooltip.tier") + ": "
|
||||
+ Formatting.GOLD + StringUtils.toFirstCapitalAllLowercase(cableType.tier.toString())));
|
||||
}
|
||||
+ Formatting.GOLD + StringUtils.toFirstCapitalAllLowercase(getCableType().tier.toString())));
|
||||
}
|
||||
|
||||
// IToolDrop
|
||||
|
@ -190,7 +196,7 @@ public class CableBlockEntity extends BlockEntity
|
|||
return energyOut;
|
||||
}
|
||||
|
||||
public boolean canAcceptEnergy(Direction direction) {
|
||||
public boolean canAcceptEnergy(EnergySide direction) {
|
||||
if (sendingFace.contains(direction)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -199,22 +205,25 @@ public class CableBlockEntity extends BlockEntity
|
|||
|
||||
@Override
|
||||
public double getMaxInput(EnergySide side) {
|
||||
return transferRate;
|
||||
if(!canAcceptEnergy(side)) {
|
||||
return 0;
|
||||
}
|
||||
return getCableType().transferRate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxOutput(EnergySide side) {
|
||||
return transferRate;
|
||||
return getCableType().transferRate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxStoredPower() {
|
||||
return transferRate * 4;
|
||||
return getCableType().transferRate * 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnergyTier getTier() {
|
||||
return PowerAcceptorBlockEntity.getTier(cableType.transferRate);
|
||||
return PowerAcceptorBlockEntity.getTier(getCableType().transferRate);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -54,6 +54,11 @@ public class SolarPanelBlockEntity extends PowerAcceptorBlockEntity implements I
|
|||
public SolarPanelBlockEntity() {
|
||||
super(TRBlockEntities.SOLAR_PANEL);
|
||||
}
|
||||
|
||||
public SolarPanelBlockEntity(SolarPanels panel) {
|
||||
super(TRBlockEntities.SOLAR_PANEL);
|
||||
this.panel = panel;
|
||||
}
|
||||
|
||||
public boolean isSunOut() {
|
||||
return canSeeSky && !world.isRaining() && !world.isThundering() && world.isDaylight();
|
||||
|
@ -145,13 +150,16 @@ public class SolarPanelBlockEntity extends PowerAcceptorBlockEntity implements I
|
|||
|
||||
@Override
|
||||
public void addInfo(List<Text> info, boolean isReal, boolean hasData) {
|
||||
if (panel == SolarPanels.CREATIVE) {
|
||||
return;
|
||||
}
|
||||
info.add(new LiteralText(Formatting.GRAY + StringUtils.t("reborncore.tooltip.energy.maxEnergy") + ": "
|
||||
+ Formatting.GOLD + PowerSystem.getLocaliszedPowerFormatted(getMaxPower())));
|
||||
|
||||
info.add(new LiteralText(Formatting.GRAY + StringUtils.t("techreborn.tooltip.generationRate.day") + ": "
|
||||
+ Formatting.GOLD + PowerSystem.getLocaliszedPowerFormatted(panel.generationRateD)));
|
||||
|
||||
info.add(new LiteralText(Formatting.GRAY + StringUtils.t("techreborn.tooltip.generationRate.day") + ": "
|
||||
info.add(new LiteralText(Formatting.GRAY + StringUtils.t("techreborn.tooltip.generationRate.night") + ": "
|
||||
+ Formatting.GOLD + PowerSystem.getLocaliszedPowerFormatted(panel.generationRateN)));
|
||||
|
||||
info.add(new LiteralText(Formatting.GRAY + StringUtils.t("reborncore.tooltip.energy.tier") + ": "
|
||||
|
|
|
@ -1,207 +1,233 @@
|
|||
package techreborn.blockentity.machine.iron;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.AbstractFurnaceBlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.blockentity.InventoryProvider;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
import reborncore.common.blocks.BlockMachineBase;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
|
||||
public abstract class AbstractIronMachineBlockEntity extends MachineBaseBlockEntity implements InventoryProvider, IToolDrop {
|
||||
|
||||
public RebornInventory<?> inventory;
|
||||
public int burnTime;
|
||||
public int totalBurnTime;
|
||||
public int progress;
|
||||
public int totalCookingTime;
|
||||
int fuelSlot;
|
||||
Block toolDrop;
|
||||
boolean active = false;
|
||||
|
||||
public AbstractIronMachineBlockEntity(BlockEntityType<?> blockEntityTypeIn, int fuelSlot, Block toolDrop) {
|
||||
super(blockEntityTypeIn);
|
||||
this.fuelSlot = fuelSlot;
|
||||
// default value for vanilla smelting recipes is 200
|
||||
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();
|
||||
|
||||
/**
|
||||
* Turn ingredients into the appropriate smelted
|
||||
* item in the output slot
|
||||
*/
|
||||
protected abstract void smelt();
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
private int getItemBurnTime(ItemStack stack) {
|
||||
if (stack.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
return (int) (AbstractFurnaceBlockEntity.createFuelTimeMap().getOrDefault(stack.getItem(), 0) * TechRebornConfig.fuelScale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns remaining fraction of fuel burn time
|
||||
* @param scale Scale to use for burn time
|
||||
* @return int scaled remaining fuel burn time
|
||||
*/
|
||||
public int getBurnTimeRemainingScaled(int scale) {
|
||||
if (totalBurnTime == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return burnTime * scale / totalBurnTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns crafting progress
|
||||
* @param scale Scale to use for crafting progress
|
||||
* @return int Scaled crafting progress
|
||||
*/
|
||||
public int getProgressScaled(int scale) {
|
||||
if (totalCookingTime > 0) {
|
||||
return progress * scale / totalCookingTime;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if Iron Machine is burning fuel thus can do work
|
||||
* @return Boolean True if machine is burning
|
||||
*/
|
||||
public boolean isBurning() {
|
||||
return burnTime > 0;
|
||||
}
|
||||
|
||||
private void updateState() {
|
||||
BlockState state = world.getBlockState(pos);
|
||||
if (state.getBlock() instanceof BlockMachineBase) {
|
||||
BlockMachineBase blockMachineBase = (BlockMachineBase) state.getBlock();
|
||||
if (state.get(BlockMachineBase.ACTIVE) != burnTime > 0)
|
||||
blockMachineBase.setActive(burnTime > 0, world, pos);
|
||||
}
|
||||
}
|
||||
|
||||
// MachineBaseBlockEntity
|
||||
@Override
|
||||
public void fromTag(CompoundTag compoundTag) {
|
||||
super.fromTag(compoundTag);
|
||||
burnTime = compoundTag.getInt("BurnTime");
|
||||
totalBurnTime = compoundTag.getInt("TotalBurnTime");
|
||||
progress = compoundTag.getInt("Progress");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(CompoundTag 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){
|
||||
return;
|
||||
}
|
||||
boolean isBurning = isBurning();
|
||||
if (isBurning) {
|
||||
--burnTime;
|
||||
}
|
||||
|
||||
if (!isBurning && canSmelt()) {
|
||||
burnTime = totalBurnTime = getItemBurnTime(inventory.getInvStack(fuelSlot));
|
||||
if (burnTime > 0) {
|
||||
// Fuel slot
|
||||
ItemStack fuelStack = inventory.getInvStack(fuelSlot);
|
||||
if (fuelStack.getItem().hasRecipeRemainder()) {
|
||||
inventory.setInvStack(fuelSlot, new ItemStack(fuelStack.getItem().getRecipeRemainder()));
|
||||
} else if (fuelStack.getCount() > 1) {
|
||||
inventory.shrinkSlot(fuelSlot, 1);
|
||||
} else if (fuelStack.getCount() == 1) {
|
||||
inventory.setInvStack(fuelSlot, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isBurning() && canSmelt()) {
|
||||
++progress;
|
||||
if (progress == totalCookingTime) {
|
||||
progress = 0;
|
||||
smelt();
|
||||
}
|
||||
} else {
|
||||
progress = 0;
|
||||
}
|
||||
|
||||
if (isBurning != isBurning()) {
|
||||
inventory.setChanged();
|
||||
updateState();
|
||||
}
|
||||
if (inventory.hasChanged()) {
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeUpgraded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// InventoryProvider
|
||||
@Override
|
||||
public RebornInventory<?> getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
// IToolDrop
|
||||
@Override
|
||||
public ItemStack getToolDrop(PlayerEntity entityPlayer) {
|
||||
return new ItemStack(toolDrop);
|
||||
}
|
||||
|
||||
public int getBurnTime() {
|
||||
return this.burnTime;
|
||||
}
|
||||
|
||||
public void setBurnTime(int burnTime) {
|
||||
this.burnTime = burnTime;
|
||||
}
|
||||
|
||||
public int getTotalBurnTime() {
|
||||
return this.totalBurnTime;
|
||||
}
|
||||
|
||||
public void setTotalBurnTime(int totalBurnTime) {
|
||||
this.totalBurnTime = totalBurnTime;
|
||||
}
|
||||
|
||||
public int getProgress() {
|
||||
return progress;
|
||||
}
|
||||
|
||||
public void setProgress(int progress) {
|
||||
this.progress = progress;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 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.iron;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.AbstractFurnaceBlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.blockentity.InventoryProvider;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
import reborncore.common.blockentity.SlotConfiguration;
|
||||
import reborncore.common.blocks.BlockMachineBase;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
|
||||
public abstract class AbstractIronMachineBlockEntity extends MachineBaseBlockEntity implements InventoryProvider, IToolDrop, SlotConfiguration.SlotFilter {
|
||||
|
||||
public RebornInventory<?> inventory;
|
||||
public int burnTime;
|
||||
public int totalBurnTime;
|
||||
public int progress;
|
||||
public int totalCookingTime;
|
||||
int fuelSlot;
|
||||
Block toolDrop;
|
||||
boolean active = false;
|
||||
|
||||
public AbstractIronMachineBlockEntity(BlockEntityType<?> blockEntityTypeIn, int fuelSlot, Block toolDrop) {
|
||||
super(blockEntityTypeIn);
|
||||
this.fuelSlot = fuelSlot;
|
||||
// default value for vanilla smelting recipes is 200
|
||||
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();
|
||||
|
||||
/**
|
||||
* Turn ingredients into the appropriate smelted
|
||||
* item in the output slot
|
||||
*/
|
||||
protected abstract void smelt();
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
private int getItemBurnTime(ItemStack stack) {
|
||||
if (stack.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
return (int) (AbstractFurnaceBlockEntity.createFuelTimeMap().getOrDefault(stack.getItem(), 0) * TechRebornConfig.fuelScale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns remaining fraction of fuel burn time
|
||||
* @param scale Scale to use for burn time
|
||||
* @return int scaled remaining fuel burn time
|
||||
*/
|
||||
public int getBurnTimeRemainingScaled(int scale) {
|
||||
if (totalBurnTime == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return burnTime * scale / totalBurnTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns crafting progress
|
||||
* @param scale Scale to use for crafting progress
|
||||
* @return int Scaled crafting progress
|
||||
*/
|
||||
public int getProgressScaled(int scale) {
|
||||
if (totalCookingTime > 0) {
|
||||
return progress * scale / totalCookingTime;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if Iron Machine is burning fuel thus can do work
|
||||
* @return Boolean True if machine is burning
|
||||
*/
|
||||
public boolean isBurning() {
|
||||
return burnTime > 0;
|
||||
}
|
||||
|
||||
private void updateState() {
|
||||
BlockState state = world.getBlockState(pos);
|
||||
if (state.getBlock() instanceof BlockMachineBase) {
|
||||
BlockMachineBase blockMachineBase = (BlockMachineBase) state.getBlock();
|
||||
if (state.get(BlockMachineBase.ACTIVE) != burnTime > 0)
|
||||
blockMachineBase.setActive(burnTime > 0, world, pos);
|
||||
}
|
||||
}
|
||||
|
||||
// MachineBaseBlockEntity
|
||||
@Override
|
||||
public void fromTag(CompoundTag compoundTag) {
|
||||
super.fromTag(compoundTag);
|
||||
burnTime = compoundTag.getInt("BurnTime");
|
||||
totalBurnTime = compoundTag.getInt("TotalBurnTime");
|
||||
progress = compoundTag.getInt("Progress");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(CompoundTag 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){
|
||||
return;
|
||||
}
|
||||
boolean isBurning = isBurning();
|
||||
if (isBurning) {
|
||||
--burnTime;
|
||||
}
|
||||
|
||||
if (!isBurning && canSmelt()) {
|
||||
burnTime = totalBurnTime = getItemBurnTime(inventory.getInvStack(fuelSlot));
|
||||
if (burnTime > 0) {
|
||||
// Fuel slot
|
||||
ItemStack fuelStack = inventory.getInvStack(fuelSlot);
|
||||
if (fuelStack.getItem().hasRecipeRemainder()) {
|
||||
inventory.setInvStack(fuelSlot, new ItemStack(fuelStack.getItem().getRecipeRemainder()));
|
||||
} else if (fuelStack.getCount() > 1) {
|
||||
inventory.shrinkSlot(fuelSlot, 1);
|
||||
} else if (fuelStack.getCount() == 1) {
|
||||
inventory.setInvStack(fuelSlot, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isBurning() && canSmelt()) {
|
||||
++progress;
|
||||
if (progress == totalCookingTime) {
|
||||
progress = 0;
|
||||
smelt();
|
||||
}
|
||||
} else if(!canSmelt()) {
|
||||
progress = 0;
|
||||
}
|
||||
|
||||
if (isBurning != isBurning()) {
|
||||
inventory.setChanged();
|
||||
updateState();
|
||||
}
|
||||
if (inventory.hasChanged()) {
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeUpgraded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// InventoryProvider
|
||||
@Override
|
||||
public RebornInventory<?> getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
// IToolDrop
|
||||
@Override
|
||||
public ItemStack getToolDrop(PlayerEntity entityPlayer) {
|
||||
return new ItemStack(toolDrop);
|
||||
}
|
||||
|
||||
public int getBurnTime() {
|
||||
return this.burnTime;
|
||||
}
|
||||
|
||||
public void setBurnTime(int burnTime) {
|
||||
this.burnTime = burnTime;
|
||||
}
|
||||
|
||||
public int getTotalBurnTime() {
|
||||
return this.totalBurnTime;
|
||||
}
|
||||
|
||||
public void setTotalBurnTime(int totalBurnTime) {
|
||||
this.totalBurnTime = totalBurnTime;
|
||||
}
|
||||
|
||||
public int getProgress() {
|
||||
return progress;
|
||||
}
|
||||
|
||||
public void setProgress(int progress) {
|
||||
this.progress = progress;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -136,4 +136,17 @@ public class IronAlloyFurnaceBlockEntity extends AbstractIronMachineBlockEntity
|
|||
.syncIntegerValue(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))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getInputSlots() {
|
||||
return new int[]{input1, input2};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,8 +24,6 @@
|
|||
|
||||
package techreborn.blockentity.machine.iron;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import net.minecraft.entity.ExperienceOrbEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -41,6 +39,8 @@ import techreborn.init.TRBlockEntities;
|
|||
import techreborn.init.TRContent;
|
||||
import techreborn.utils.RecipeUtils;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class IronFurnaceBlockEntity extends AbstractIronMachineBlockEntity implements IContainerProvider {
|
||||
|
||||
int inputSlot = 0;
|
||||
|
@ -118,7 +118,12 @@ public class IronFurnaceBlockEntity extends AbstractIronMachineBlockEntity imple
|
|||
int result = inventory.getInvStack(outputSlot).getCount() + outputStack.getCount();
|
||||
return result <= inventory.getStackLimit() && result <= outputStack.getMaxCount();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isStackValid(int slotID, ItemStack stack) {
|
||||
return !getResultFor(stack).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromTag(CompoundTag compoundTag) {
|
||||
super.fromTag(compoundTag);
|
||||
|
@ -141,6 +146,11 @@ public class IronFurnaceBlockEntity extends AbstractIronMachineBlockEntity imple
|
|||
this.experience = experience;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getInputSlots() {
|
||||
return new int[]{inputSlot};
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("ironfurnace").player(player.inventory).inventory().hotbar()
|
||||
|
|
|
@ -30,6 +30,7 @@ import net.minecraft.util.math.BlockPos;
|
|||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.crafting.RebornRecipe;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
|
@ -40,8 +41,6 @@ import techreborn.init.TRContent;
|
|||
|
||||
public class DistillationTowerBlockEntity extends GenericMachineBlockEntity implements IContainerProvider {
|
||||
|
||||
|
||||
|
||||
public MultiblockChecker multiblockChecker;
|
||||
|
||||
public DistillationTowerBlockEntity() {
|
||||
|
@ -74,10 +73,8 @@ public class DistillationTowerBlockEntity extends GenericMachineBlockEntity impl
|
|||
final BlockPos downCenter = pos.method_10079(getFacing().getOpposite(), 2);
|
||||
multiblockChecker = new MultiblockChecker(world, downCenter);
|
||||
}
|
||||
|
||||
if (!world.isClient && getMutliBlock()){
|
||||
super.tick();
|
||||
}
|
||||
|
||||
super.tick();
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
|
@ -88,4 +85,9 @@ public class DistillationTowerBlockEntity extends GenericMachineBlockEntity impl
|
|||
.outputSlot(4, 119, 37).outputSlot(5, 139, 37).energySlot(6, 8, 72).syncEnergyValue().syncCrafterValue()
|
||||
.addInventory().create(this, syncID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCraft(RebornRecipe rebornRecipe) {
|
||||
return getMutliBlock();
|
||||
}
|
||||
}
|
|
@ -29,13 +29,14 @@ import net.minecraft.util.math.BlockPos;
|
|||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.crafting.RebornRecipe;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
import techreborn.init.TRContent;
|
||||
|
||||
public class ImplosionCompressorBlockEntity extends GenericMachineBlockEntity implements IContainerProvider {
|
||||
|
||||
|
@ -65,10 +66,8 @@ public class ImplosionCompressorBlockEntity extends GenericMachineBlockEntity im
|
|||
if (multiblockChecker == null) {
|
||||
multiblockChecker = new MultiblockChecker(world, pos.down(3));
|
||||
}
|
||||
|
||||
if (!world.isClient && getMutliBlock()){
|
||||
super.tick();
|
||||
}
|
||||
|
||||
super.tick();
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
|
@ -78,4 +77,9 @@ public class ImplosionCompressorBlockEntity extends GenericMachineBlockEntity im
|
|||
.blockEntity(this).slot(0, 50, 27).slot(1, 50, 47).outputSlot(2, 92, 36).outputSlot(3, 110, 36)
|
||||
.energySlot(4, 8, 72).syncEnergyValue().syncCrafterValue().addInventory().create(this, syncID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCraft(RebornRecipe rebornRecipe) {
|
||||
return getMutliBlock();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,9 +31,9 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.util.math.Direction;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.blockentity.InventoryProvider;
|
||||
import reborncore.common.powerSystem.ExternalPowerSystems;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import team.reborn.energy.Energy;
|
||||
import team.reborn.energy.EnergyTier;
|
||||
import techreborn.blocks.storage.BlockEnergyStorage;
|
||||
|
||||
|
@ -72,8 +72,13 @@ public class EnergyStorageBlockEntity extends PowerAcceptorBlockEntity
|
|||
if (!inventory.getInvStack(0).isEmpty()) {
|
||||
ItemStack stack = inventory.getInvStack(0);
|
||||
|
||||
if (ExternalPowerSystems.isPoweredItem(stack)) {
|
||||
ExternalPowerSystems.chargeItem(this, stack);
|
||||
if (Energy.valid(stack)) {
|
||||
Energy.of(this)
|
||||
.into(
|
||||
Energy
|
||||
.of(stack)
|
||||
)
|
||||
.move();
|
||||
}
|
||||
}
|
||||
if (!inventory.getInvStack(1).isEmpty()) {
|
||||
|
@ -88,12 +93,12 @@ public class EnergyStorageBlockEntity extends PowerAcceptorBlockEntity
|
|||
|
||||
@Override
|
||||
public boolean canAcceptEnergy(Direction direction) {
|
||||
return getFacing() != direction;
|
||||
return direction == null || getFacing() != direction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(Direction direction) {
|
||||
return getFacing() == direction;
|
||||
return direction == null || getFacing() == direction;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import team.reborn.energy.EnergySide;
|
||||
import team.reborn.energy.EnergyTier;
|
||||
import techreborn.blockentity.storage.EnergyStorageBlockEntity;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
|
@ -48,7 +49,7 @@ public class InterdimensionalSUBlockEntity extends EnergyStorageBlockEntity impl
|
|||
}
|
||||
|
||||
@Override
|
||||
public double getEnergy() {
|
||||
public double getStored(EnergySide face) {
|
||||
if (ownerUdid == null || ownerUdid.isEmpty()) {
|
||||
return 0.0;
|
||||
}
|
||||
|
@ -59,7 +60,7 @@ public class InterdimensionalSUBlockEntity extends EnergyStorageBlockEntity impl
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setEnergy(double energy) {
|
||||
public void setStored(double energy) {
|
||||
if (ownerUdid == null || ownerUdid.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -122,6 +122,9 @@ public class TransformerBlockEntity extends PowerAcceptorBlockEntity
|
|||
// TileMachineBase
|
||||
@Override
|
||||
public Direction getFacingEnum() {
|
||||
if(world == null){
|
||||
return null;
|
||||
}
|
||||
Block block = world.getBlockState(pos).getBlock();
|
||||
if (block instanceof BlockTransformer) {
|
||||
return ((BlockTransformer) block).getFacing(world.getBlockState(pos));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue