Merge remote-tracking branch 'remotes/origin/1.14' into 1.15
This commit is contained in:
commit
6e53132c59
285 changed files with 667 additions and 615 deletions
|
@ -0,0 +1,207 @@
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -24,18 +24,11 @@
|
|||
|
||||
package techreborn.blockentity.machine.iron;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.AbstractFurnaceBlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import reborncore.api.IToolDrop;
|
||||
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.blockentity.MachineBaseBlockEntity;
|
||||
import reborncore.common.blocks.BlockMachineBase;
|
||||
import reborncore.common.crafting.RebornRecipe;
|
||||
import reborncore.common.crafting.ingredient.RebornIngredient;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
|
@ -43,77 +36,15 @@ import techreborn.init.ModRecipes;
|
|||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.init.TRContent;
|
||||
|
||||
public class IronAlloyFurnaceBlockEntity extends MachineBaseBlockEntity
|
||||
implements IToolDrop, InventoryProvider, IContainerProvider {
|
||||
public class IronAlloyFurnaceBlockEntity extends AbstractIronMachineBlockEntity implements IContainerProvider {
|
||||
|
||||
public int tickTime;
|
||||
public RebornInventory<IronAlloyFurnaceBlockEntity> inventory = new RebornInventory<>(4, "IronAlloyFurnaceBlockEntity", 64, this);
|
||||
public int burnTime;
|
||||
public int totalBurnTime;
|
||||
public int cookTime;
|
||||
int input1 = 0;
|
||||
int input2 = 1;
|
||||
int output = 2;
|
||||
int fuel = 3;
|
||||
|
||||
public IronAlloyFurnaceBlockEntity() {
|
||||
super(TRBlockEntities.IRON_ALLOY_FURNACE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public static int getItemBurnTime(ItemStack stack) {
|
||||
if (stack.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
return AbstractFurnaceBlockEntity.createFuelTimeMap().getOrDefault(stack.getItem(), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if(world.isClient){
|
||||
return;
|
||||
}
|
||||
|
||||
boolean isBurning = isBurning();
|
||||
boolean updateInventory = false;
|
||||
if (isBurning) {
|
||||
--burnTime;
|
||||
}
|
||||
if (burnTime != 0 || !inventory.getInvStack(input1).isEmpty() && !inventory.getInvStack(fuel).isEmpty()) {
|
||||
if (burnTime == 0 && canSmelt()) {
|
||||
totalBurnTime = burnTime = getItemBurnTime(inventory.getInvStack(fuel));
|
||||
if (burnTime > 0) {
|
||||
updateInventory = true;
|
||||
if (!inventory.getInvStack(fuel).isEmpty()) {
|
||||
inventory.shrinkSlot(fuel, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isBurning() && canSmelt()) {
|
||||
++cookTime;
|
||||
if (cookTime == 200) {
|
||||
cookTime = 0;
|
||||
smeltItem();
|
||||
updateInventory = true;
|
||||
}
|
||||
} else {
|
||||
cookTime = 0;
|
||||
}
|
||||
}
|
||||
if (isBurning != isBurning()) {
|
||||
updateInventory = true;
|
||||
updateState();
|
||||
}
|
||||
|
||||
if (updateInventory) {
|
||||
markDirty();
|
||||
}
|
||||
super(TRBlockEntities.IRON_ALLOY_FURNACE, 3, TRContent.Machine.IRON_ALLOY_FURNACE.block);
|
||||
this.inventory = new RebornInventory<>(4, "IronAlloyFurnaceBlockEntity", 64, this);
|
||||
}
|
||||
|
||||
public boolean hasAllInputs(RebornRecipe recipeType) {
|
||||
|
@ -133,7 +64,8 @@ public class IronAlloyFurnaceBlockEntity extends MachineBaseBlockEntity
|
|||
return true;
|
||||
}
|
||||
|
||||
private boolean canSmelt() {
|
||||
@Override
|
||||
protected boolean canSmelt() {
|
||||
if (inventory.getInvStack(input1).isEmpty() || inventory.getInvStack(input2).isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -155,11 +87,8 @@ public class IronAlloyFurnaceBlockEntity extends MachineBaseBlockEntity
|
|||
return result <= inventory.getStackLimit() && result <= inventory.getInvStack(output).getMaxCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn one item from the furnace source stack into the appropriate smelted
|
||||
* item in the furnace result stack
|
||||
*/
|
||||
public void smeltItem() {
|
||||
@Override
|
||||
protected void smelt() {
|
||||
if (!canSmelt()) {
|
||||
return;
|
||||
}
|
||||
|
@ -195,87 +124,16 @@ public class IronAlloyFurnaceBlockEntity extends MachineBaseBlockEntity
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Furnace isBurning
|
||||
* @return Boolean True if furnace is burning
|
||||
*/
|
||||
public boolean isBurning() {
|
||||
return burnTime > 0;
|
||||
}
|
||||
|
||||
public int getBurnTimeRemainingScaled(int scale) {
|
||||
if (totalBurnTime == 0) {
|
||||
totalBurnTime = 200;
|
||||
}
|
||||
|
||||
return burnTime * scale / totalBurnTime;
|
||||
}
|
||||
|
||||
public int getCookProgressScaled(int scale) {
|
||||
return cookTime * scale / 200;
|
||||
}
|
||||
|
||||
public 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);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction getFacing() {
|
||||
return getFacingEnum();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getToolDrop(PlayerEntity entityPlayer) {
|
||||
return TRContent.Machine.IRON_ALLOY_FURNACE.getStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RebornInventory<IronAlloyFurnaceBlockEntity> getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public int getBurnTime() {
|
||||
return burnTime;
|
||||
}
|
||||
|
||||
public void setBurnTime(int burnTime) {
|
||||
this.burnTime = burnTime;
|
||||
}
|
||||
|
||||
public int getTotalBurnTime() {
|
||||
return totalBurnTime;
|
||||
}
|
||||
|
||||
public void setTotalBurnTime(int currentItemBurnTime) {
|
||||
this.totalBurnTime = currentItemBurnTime;
|
||||
}
|
||||
|
||||
public int getCookTime() {
|
||||
return cookTime;
|
||||
}
|
||||
|
||||
public void setCookTime(int cookTime) {
|
||||
this.cookTime = cookTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("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).syncIntegerValue(this::getBurnTime, this::setBurnTime)
|
||||
.syncIntegerValue(this::getCookTime, this::setCookTime)
|
||||
.syncIntegerValue(this::getTotalBurnTime, this::setTotalBurnTime).addInventory().create(this, syncID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeUpgraded() {
|
||||
return false;
|
||||
.outputSlot(2, 116, 35).fuelSlot(3, 56, 53)
|
||||
.syncIntegerValue(this::getBurnTime, this::setBurnTime)
|
||||
.syncIntegerValue(this::getProgress, this::setProgress)
|
||||
.syncIntegerValue(this::getTotalBurnTime, this::setTotalBurnTime)
|
||||
.addInventory().create(this, syncID);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,8 +26,6 @@ package techreborn.blockentity.machine.iron;
|
|||
|
||||
import java.util.Optional;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.AbstractFurnaceBlockEntity;
|
||||
import net.minecraft.entity.ExperienceOrbEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -35,89 +33,78 @@ import net.minecraft.nbt.CompoundTag;
|
|||
import net.minecraft.recipe.RecipeType;
|
||||
import net.minecraft.recipe.SmeltingRecipe;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
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.blocks.BlockMachineBase;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
import reborncore.common.util.IInventoryAccess;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import reborncore.common.util.ItemUtils;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.utils.RecipeUtils;
|
||||
|
||||
public class IronFurnaceBlockEntity extends MachineBaseBlockEntity
|
||||
implements InventoryProvider, IContainerProvider {
|
||||
public class IronFurnaceBlockEntity extends AbstractIronMachineBlockEntity implements IContainerProvider {
|
||||
|
||||
public int tickTime;
|
||||
public RebornInventory<IronFurnaceBlockEntity> inventory = new RebornInventory<>(3, "IronFurnaceBlockEntity", 64, this, getInvetoryAccess());
|
||||
public int burnTime;
|
||||
public int totalBurnTime;
|
||||
public int progress;
|
||||
public int fuelScale = 160;
|
||||
int inputSlot = 0;
|
||||
int outputSlot = 1;
|
||||
int fuelSlot = 2;
|
||||
boolean active = false;
|
||||
private float experience;
|
||||
|
||||
public float experience;
|
||||
|
||||
public IronFurnaceBlockEntity() {
|
||||
super(TRBlockEntities.IRON_FURNACE);
|
||||
super(TRBlockEntities.IRON_FURNACE, 2, TRContent.Machine.IRON_FURNACE.block);
|
||||
this.inventory = new RebornInventory<>(3, "IronFurnaceBlockEntity", 64, this);
|
||||
}
|
||||
|
||||
public static IInventoryAccess<IronFurnaceBlockEntity> getInvetoryAccess(){
|
||||
return (slotID, stack, face, direction, blockEntity) -> {
|
||||
if(direction == IInventoryAccess.AccessDirection.INSERT){
|
||||
boolean isFuel = AbstractFurnaceBlockEntity.canUseAsFuel(stack);
|
||||
if(isFuel){
|
||||
ItemStack fuelSlotStack = blockEntity.inventory.getInvStack(blockEntity.fuelSlot);
|
||||
if(fuelSlotStack.isEmpty() || ItemUtils.isItemEqual(stack, fuelSlotStack, true, true) && fuelSlotStack.getMaxCount() != fuelSlotStack.getCount()){
|
||||
return slotID == blockEntity.fuelSlot;
|
||||
}
|
||||
}
|
||||
return slotID != blockEntity.outputSlot;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
public int gaugeProgressScaled(int scale) {
|
||||
return progress * scale / fuelScale;
|
||||
}
|
||||
|
||||
public int gaugeFuelScaled(int scale) {
|
||||
if (totalBurnTime == 0) {
|
||||
totalBurnTime = burnTime;
|
||||
if (totalBurnTime == 0) {
|
||||
totalBurnTime = fuelScale;
|
||||
public void handleGuiInputFromClient(PlayerEntity playerIn) {
|
||||
if (playerIn instanceof ServerPlayerEntity) {
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) playerIn;
|
||||
int totalExperience = (int) experience;
|
||||
while (totalExperience > 0) {
|
||||
int expToDrop = ExperienceOrbEntity.roundToOrbSize(totalExperience);
|
||||
totalExperience -= expToDrop;
|
||||
player.world.spawnEntity(new ExperienceOrbEntity(player.world, player.x, player.y + 0.5D, player.z + 0.5D, expToDrop));
|
||||
}
|
||||
}
|
||||
return burnTime * scale / totalBurnTime;
|
||||
experience = 0;
|
||||
}
|
||||
|
||||
private void cookItems() {
|
||||
private ItemStack getResultFor(ItemStack stack) {
|
||||
ItemStack result = RecipeUtils.getMatchingRecipes(world, RecipeType.SMELTING, stack);
|
||||
if (!result.isEmpty()) {
|
||||
return result.copy();
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
private float getExperienceFor(ItemStack stack) {
|
||||
Optional<SmeltingRecipe> recipe = world.getRecipeManager().getFirstMatch(RecipeType.SMELTING, this, world);
|
||||
if (recipe.isPresent()) {
|
||||
return recipe.get().getExperience();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// AbstractIronMachineBlockEntity
|
||||
@Override
|
||||
protected void smelt() {
|
||||
if (!canSmelt()) {
|
||||
return;
|
||||
}
|
||||
ItemStack inputStack = inventory.getInvStack(inputSlot);
|
||||
ItemStack outputStack = getResultFor(inputStack);
|
||||
float recipeExp = getExperienceFor(inputStack);
|
||||
ItemStack resultStack = getResultFor(inputStack);
|
||||
|
||||
if (inventory.getInvStack(outputSlot).isEmpty()) {
|
||||
inventory.setInvStack(outputSlot, outputStack.copy());
|
||||
} else if (inventory.getInvStack(outputSlot).isItemEqualIgnoreDamage(outputStack)) {
|
||||
inventory.getInvStack(outputSlot).increment(outputStack.getCount());
|
||||
inventory.setInvStack(outputSlot, resultStack.copy());
|
||||
} else if (inventory.getInvStack(outputSlot).isItemEqualIgnoreDamage(resultStack)) {
|
||||
inventory.getInvStack(outputSlot).increment(resultStack.getCount());
|
||||
}
|
||||
experience += getExperienceFor(inputStack);
|
||||
if (inputStack.getCount() > 1) {
|
||||
inventory.shrinkSlot(inputSlot, 1);
|
||||
} else {
|
||||
inventory.setInvStack(inputSlot, ItemStack.EMPTY);
|
||||
}
|
||||
experience += recipeExp;
|
||||
}
|
||||
|
||||
private boolean canSmelt() {
|
||||
|
||||
@Override
|
||||
protected boolean canSmelt() {
|
||||
if (inventory.getInvStack(inputSlot).isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -131,50 +118,7 @@ public class IronFurnaceBlockEntity extends MachineBaseBlockEntity
|
|||
int result = inventory.getInvStack(outputSlot).getCount() + outputStack.getCount();
|
||||
return result <= inventory.getStackLimit() && result <= outputStack.getMaxCount();
|
||||
}
|
||||
|
||||
public boolean isBurning() {
|
||||
return burnTime > 0;
|
||||
}
|
||||
|
||||
private ItemStack getResultFor(ItemStack stack) {
|
||||
ItemStack result = RecipeUtils.getMatchingRecipes(world, RecipeType.SMELTING, stack);
|
||||
if (!result.isEmpty()) {
|
||||
return result.copy();
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
private float getExperienceFor(ItemStack stack) {
|
||||
Optional<SmeltingRecipe> recipe = world.getRecipeManager().getFirstMatch(RecipeType.SMELTING, this, world);
|
||||
if (recipe.isPresent()) {
|
||||
return recipe.get().getExperience();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void handleGuiInputFromClient(PlayerEntity playerIn) {
|
||||
if (playerIn instanceof ServerPlayerEntity) {
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) playerIn;
|
||||
int totalExperience = (int) experience;
|
||||
while (totalExperience > 0) {
|
||||
int expToDrop = ExperienceOrbEntity.roundToOrbSize(totalExperience);
|
||||
totalExperience -= expToDrop;
|
||||
player.world.spawnEntity(new ExperienceOrbEntity(player.world, player.x, player.y + 0.5D, player.z + 0.5D, expToDrop));
|
||||
}
|
||||
experience = 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);
|
||||
|
@ -188,94 +132,24 @@ public class IronFurnaceBlockEntity extends MachineBaseBlockEntity
|
|||
return compoundTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if(world.isClient){
|
||||
return;
|
||||
}
|
||||
boolean isBurning = isBurning();
|
||||
boolean updateInventory = false;
|
||||
if (isBurning) {
|
||||
--burnTime;
|
||||
}
|
||||
|
||||
if (burnTime <= 0 && canSmelt()) {
|
||||
burnTime = totalBurnTime = (int) (AbstractFurnaceBlockEntity.createFuelTimeMap().getOrDefault(inventory.getInvStack(fuelSlot).getItem(), 0) * 1.25);
|
||||
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);
|
||||
}
|
||||
updateInventory = true;
|
||||
}
|
||||
}
|
||||
if (isBurning() && canSmelt()) {
|
||||
progress++;
|
||||
if (progress >= fuelScale) {
|
||||
progress = 0;
|
||||
cookItems();
|
||||
updateInventory = true;
|
||||
}
|
||||
} else {
|
||||
progress = 0;
|
||||
}
|
||||
if (isBurning != isBurning()) {
|
||||
updateInventory = true;
|
||||
updateState();
|
||||
}
|
||||
if (updateInventory) {
|
||||
markDirty();
|
||||
}
|
||||
// IContainerProvider
|
||||
public float getExperience() {
|
||||
return experience;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeUpgraded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// InventoryProvider
|
||||
@Override
|
||||
public RebornInventory<IronFurnaceBlockEntity> getInventory() {
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
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;
|
||||
public void setExperience(float experience) {
|
||||
this.experience = experience;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("ironfurnace").player(player.inventory).inventory().hotbar()
|
||||
.addInventory().blockEntity(this).fuelSlot(2, 56, 53).slot(0, 56, 17).outputSlot(1, 116, 35)
|
||||
.addInventory().blockEntity(this)
|
||||
.fuelSlot(2, 56, 53).slot(0, 56, 17).outputSlot(1, 116, 35)
|
||||
.syncIntegerValue(this::getBurnTime, this::setBurnTime)
|
||||
.syncIntegerValue(this::getProgress, this::setProgress)
|
||||
.syncIntegerValue(this::getTotalBurnTime, this::setTotalBurnTime).addInventory().create(this, syncID);
|
||||
.syncIntegerValue(this::getTotalBurnTime, this::setTotalBurnTime)
|
||||
.sync(this::getExperience, this::setExperience)
|
||||
.addInventory().create(this, syncID);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,32 +24,42 @@
|
|||
|
||||
package techreborn.blockentity.machine.tier3;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.World;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import reborncore.api.IToolDrop;
|
||||
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.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.init.TRContent;
|
||||
import reborncore.common.chunkloading.ChunkLoaderManager;
|
||||
|
||||
public class ChunkLoaderBlockEntity extends PowerAcceptorBlockEntity implements IToolDrop, InventoryProvider, IContainerProvider {
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public RebornInventory<ChunkLoaderBlockEntity> inventory = new RebornInventory<>(1, "ChunkLoaderBlockEntity", 64, this);
|
||||
public class ChunkLoaderBlockEntity extends MachineBaseBlockEntity implements IToolDrop, InventoryProvider, IContainerProvider {
|
||||
|
||||
public RebornInventory<ChunkLoaderBlockEntity> inventory = new RebornInventory<>(0, "ChunkLoaderBlockEntity", 64, this);
|
||||
private int radius;
|
||||
private String ownerUdid;
|
||||
|
||||
public ChunkLoaderBlockEntity() {
|
||||
super(TRBlockEntities.CHUNK_LOADER );
|
||||
this.radius = 1;
|
||||
}
|
||||
|
||||
public void handleGuiInputFromClient(int buttonID) {
|
||||
public void handleGuiInputFromClient(int buttonID, @Nullable PlayerEntity playerEntity) {
|
||||
radius += buttonID;
|
||||
|
||||
if (radius > TechRebornConfig.chunkLoaderMaxRadius) {
|
||||
|
@ -58,17 +68,66 @@ public class ChunkLoaderBlockEntity extends PowerAcceptorBlockEntity implements
|
|||
if (radius <= 1) {
|
||||
radius = 1;
|
||||
}
|
||||
|
||||
reload();
|
||||
|
||||
if(playerEntity != null){
|
||||
ChunkLoaderManager manager = ChunkLoaderManager.get(getWorld());
|
||||
manager.syncChunkLoaderToClient((ServerPlayerEntity) playerEntity, getPos());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getToolDrop(final PlayerEntity entityPlayer) {
|
||||
return TRContent.Machine.CHUNK_LOADER.getStack();
|
||||
}
|
||||
|
||||
|
||||
private void reload(){
|
||||
unloadAll();
|
||||
load();
|
||||
}
|
||||
|
||||
private void load(){
|
||||
ChunkLoaderManager manager = ChunkLoaderManager.get(getWorld());
|
||||
ChunkPos rootPos = getChunkPos();
|
||||
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())){
|
||||
manager.loadChunk(getWorld(), loadPos, getPos(), ownerUdid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
// TODO: chunkload
|
||||
public void onBreak(World world, PlayerEntity playerEntity, BlockPos blockPos, BlockState blockState) {
|
||||
if(world.isClient){
|
||||
return;
|
||||
}
|
||||
unloadAll();
|
||||
ChunkLoaderManager.get(world).clearClient((ServerPlayerEntity) playerEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlace(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
|
||||
if(world.isClient){
|
||||
return;
|
||||
}
|
||||
ownerUdid = placer.getUuidAsString();
|
||||
reload();
|
||||
}
|
||||
|
||||
private void unloadAll(){
|
||||
ChunkLoaderManager manager = ChunkLoaderManager.get(world);
|
||||
manager.unloadChunkLoader(world, getPos());
|
||||
}
|
||||
|
||||
public ChunkPos getChunkPos(){
|
||||
return new ChunkPos(getPos());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -83,39 +142,18 @@ public class ChunkLoaderBlockEntity extends PowerAcceptorBlockEntity implements
|
|||
public void fromTag(CompoundTag nbttagcompound) {
|
||||
super.fromTag(nbttagcompound);
|
||||
this.radius = nbttagcompound.getInt("radius");
|
||||
this.ownerUdid = nbttagcompound.getString("ownerUdid");
|
||||
if(!StringUtils.isBlank(ownerUdid)){
|
||||
nbttagcompound.putString("ownerUdid", this.ownerUdid);
|
||||
}
|
||||
inventory.read(nbttagcompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxPower() {
|
||||
return TechRebornConfig.chunkLoaderMaxEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptEnergy(final Direction direction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(final Direction direction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxInput() {
|
||||
return TechRebornConfig.chunkLoaderMaxInput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RebornInventory<ChunkLoaderBlockEntity> getInventory() {
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
|
||||
public int getRadius() {
|
||||
return radius;
|
||||
}
|
||||
|
@ -127,6 +165,7 @@ public class ChunkLoaderBlockEntity extends PowerAcceptorBlockEntity implements
|
|||
@Override
|
||||
public BuiltContainer createContainer(int syncID, PlayerEntity player) {
|
||||
return new ContainerBuilder("chunkloader").player(player.inventory).inventory().hotbar().addInventory()
|
||||
.blockEntity(this).energySlot(0, 8, 72).syncEnergyValue().syncIntegerValue(this::getRadius, this::setRadius).addInventory().create(this, syncID);
|
||||
.blockEntity(this).syncIntegerValue(this::getRadius, this::setRadius).addInventory().create(this, syncID);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue