Further refactoring of Iron machines
This commit is contained in:
parent
2b28281d90
commit
6ceb6e69cf
5 changed files with 215 additions and 203 deletions
|
@ -82,7 +82,7 @@ public class DataDrivenSlot {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Environment(EnvType.CLIENT)
|
@Environment(EnvType.CLIENT)
|
||||||
public void draw(GuiBase guiBase, GuiBase.Layer layer){
|
public void draw(GuiBase<?> guiBase, GuiBase.Layer layer){
|
||||||
//TODO find a better way to do this
|
//TODO find a better way to do this
|
||||||
if(getType() == SlotType.OUTPUT){
|
if(getType() == SlotType.OUTPUT){
|
||||||
guiBase.drawOutputSlot(getX(), getY(), layer);
|
guiBase.drawOutputSlot(getX(), getY(), layer);
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
package techreborn.blockentity.machine.iron;
|
package techreborn.blockentity.machine.iron;
|
||||||
|
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.entity.AbstractFurnaceBlockEntity;
|
import net.minecraft.block.entity.AbstractFurnaceBlockEntity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
@ -34,6 +35,7 @@ import reborncore.client.containerBuilder.IContainerProvider;
|
||||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||||
|
import reborncore.common.blocks.BlockMachineBase;
|
||||||
import reborncore.common.crafting.RebornRecipe;
|
import reborncore.common.crafting.RebornRecipe;
|
||||||
import reborncore.common.crafting.ingredient.RebornIngredient;
|
import reborncore.common.crafting.ingredient.RebornIngredient;
|
||||||
import reborncore.common.util.RebornInventory;
|
import reborncore.common.util.RebornInventory;
|
||||||
|
@ -47,7 +49,7 @@ public class IronAlloyFurnaceBlockEntity extends MachineBaseBlockEntity
|
||||||
public int tickTime;
|
public int tickTime;
|
||||||
public RebornInventory<IronAlloyFurnaceBlockEntity> inventory = new RebornInventory<>(4, "IronAlloyFurnaceBlockEntity", 64, this);
|
public RebornInventory<IronAlloyFurnaceBlockEntity> inventory = new RebornInventory<>(4, "IronAlloyFurnaceBlockEntity", 64, this);
|
||||||
public int burnTime;
|
public int burnTime;
|
||||||
public int currentItemBurnTime;
|
public int totalBurnTime;
|
||||||
public int cookTime;
|
public int cookTime;
|
||||||
int input1 = 0;
|
int input1 = 0;
|
||||||
int input2 = 1;
|
int input2 = 1;
|
||||||
|
@ -74,43 +76,47 @@ public class IronAlloyFurnaceBlockEntity extends MachineBaseBlockEntity
|
||||||
@Override
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
super.tick();
|
super.tick();
|
||||||
final boolean flag = this.burnTime > 0;
|
if(world.isClient){
|
||||||
boolean flag1 = false;
|
return;
|
||||||
if (this.burnTime > 0) {
|
|
||||||
--this.burnTime;
|
|
||||||
}
|
}
|
||||||
if (!this.world.isClient) {
|
|
||||||
if (this.burnTime != 0 || !inventory.getInvStack(this.input1).isEmpty()&& !inventory.getInvStack(this.fuel).isEmpty()) {
|
boolean isBurning = isBurning();
|
||||||
if (this.burnTime == 0 && this.canSmelt()) {
|
boolean updateInventory = false;
|
||||||
this.currentItemBurnTime = this.burnTime = IronAlloyFurnaceBlockEntity.getItemBurnTime(inventory.getInvStack(this.fuel));
|
if (isBurning) {
|
||||||
if (this.burnTime > 0) {
|
--burnTime;
|
||||||
flag1 = true;
|
}
|
||||||
if (!inventory.getInvStack(this.fuel).isEmpty()) {
|
if (burnTime != 0 || !inventory.getInvStack(input1).isEmpty() && !inventory.getInvStack(fuel).isEmpty()) {
|
||||||
inventory.shrinkSlot(this.fuel, 1);
|
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 (this.isBurning() && this.canSmelt()) {
|
|
||||||
++this.cookTime;
|
|
||||||
if (this.cookTime == 200) {
|
|
||||||
this.cookTime = 0;
|
|
||||||
this.smeltItem();
|
|
||||||
flag1 = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.cookTime = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (flag != this.burnTime > 0) {
|
if (isBurning() && canSmelt()) {
|
||||||
flag1 = true;
|
++cookTime;
|
||||||
|
if (cookTime == 200) {
|
||||||
|
cookTime = 0;
|
||||||
|
smeltItem();
|
||||||
|
updateInventory = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cookTime = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (flag1) {
|
if (isBurning != isBurning()) {
|
||||||
this.markDirty();
|
updateInventory = true;
|
||||||
|
updateState();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updateInventory) {
|
||||||
|
markDirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasAllInputs(final RebornRecipe recipeType) {
|
public boolean hasAllInputs(RebornRecipe recipeType) {
|
||||||
if (recipeType == null) {
|
if (recipeType == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -128,12 +134,12 @@ public class IronAlloyFurnaceBlockEntity extends MachineBaseBlockEntity
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean canSmelt() {
|
private boolean canSmelt() {
|
||||||
if (inventory.getInvStack(this.input1).isEmpty() || inventory.getInvStack(this.input2).isEmpty()) {
|
if (inventory.getInvStack(input1).isEmpty() || inventory.getInvStack(input2).isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ItemStack itemstack = null;
|
ItemStack itemstack = null;
|
||||||
for (final RebornRecipe recipeType : ModRecipes.ALLOY_SMELTER.getRecipes(world)) {
|
for (RebornRecipe recipeType : ModRecipes.ALLOY_SMELTER.getRecipes(world)) {
|
||||||
if (this.hasAllInputs(recipeType)) {
|
if (hasAllInputs(recipeType)) {
|
||||||
itemstack = recipeType.getOutputs().get(0);
|
itemstack = recipeType.getOutputs().get(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -141,12 +147,12 @@ public class IronAlloyFurnaceBlockEntity extends MachineBaseBlockEntity
|
||||||
|
|
||||||
if (itemstack == null)
|
if (itemstack == null)
|
||||||
return false;
|
return false;
|
||||||
if (inventory.getInvStack(this.output).isEmpty())
|
if (inventory.getInvStack(output).isEmpty())
|
||||||
return true;
|
return true;
|
||||||
if (!inventory.getInvStack(this.output).isItemEqualIgnoreDamage(itemstack))
|
if (!inventory.getInvStack(output).isItemEqualIgnoreDamage(itemstack))
|
||||||
return false;
|
return false;
|
||||||
final int result = inventory.getInvStack(this.output).getCount() + itemstack.getCount();
|
int result = inventory.getInvStack(output).getCount() + itemstack.getCount();
|
||||||
return result <= inventory.getStackLimit() && result <= inventory.getInvStack(this.output).getMaxCount();
|
return result <= inventory.getStackLimit() && result <= inventory.getInvStack(output).getMaxCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -154,44 +160,39 @@ public class IronAlloyFurnaceBlockEntity extends MachineBaseBlockEntity
|
||||||
* item in the furnace result stack
|
* item in the furnace result stack
|
||||||
*/
|
*/
|
||||||
public void smeltItem() {
|
public void smeltItem() {
|
||||||
if (this.canSmelt()) {
|
if (!canSmelt()) {
|
||||||
ItemStack itemstack = ItemStack.EMPTY;
|
return;
|
||||||
for (final RebornRecipe recipeType : ModRecipes.ALLOY_SMELTER.getRecipes(world)) {
|
|
||||||
if (this.hasAllInputs(recipeType)) {
|
|
||||||
itemstack = recipeType.getOutputs().get(0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!itemstack.isEmpty()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inventory.getInvStack(this.output).isEmpty()) {
|
|
||||||
inventory.setInvStack(this.output, itemstack.copy());
|
|
||||||
} else if (inventory.getInvStack(this.output).getItem() == itemstack.getItem()) {
|
|
||||||
inventory.shrinkSlot(this.output, -itemstack.getCount());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (final RebornRecipe recipeType : ModRecipes.ALLOY_SMELTER.getRecipes(world)) {
|
|
||||||
boolean hasAllRecipes = true;
|
|
||||||
if (this.hasAllInputs(recipeType)) {
|
|
||||||
|
|
||||||
} else {
|
|
||||||
hasAllRecipes = false;
|
|
||||||
}
|
|
||||||
if (hasAllRecipes) {
|
|
||||||
for (RebornIngredient ingredient : recipeType.getRebornIngredients()) {
|
|
||||||
for (int inputSlot = 0; inputSlot < 2; inputSlot++) {
|
|
||||||
if (ingredient.test(this.inventory.getInvStack(inputSlot))) {
|
|
||||||
inventory.shrinkSlot(inputSlot, ingredient.getCount());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ItemStack outputStack = ItemStack.EMPTY;
|
||||||
|
RebornRecipe currentRecipe = null;
|
||||||
|
for (RebornRecipe recipeType : ModRecipes.ALLOY_SMELTER.getRecipes(world)) {
|
||||||
|
if (hasAllInputs(recipeType)) {
|
||||||
|
currentRecipe = recipeType;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (currentRecipe == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
outputStack = currentRecipe.getOutputs().get(0);
|
||||||
|
if (outputStack.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (inventory.getInvStack(output).isEmpty()) {
|
||||||
|
inventory.setInvStack(output, outputStack.copy());
|
||||||
|
} else if (inventory.getInvStack(output).getItem() == outputStack.getItem()) {
|
||||||
|
inventory.shrinkSlot(output, -outputStack.getCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (RebornIngredient ingredient : currentRecipe.getRebornIngredients()) {
|
||||||
|
for (int inputSlot = 0; inputSlot < 2; inputSlot++) {
|
||||||
|
if (ingredient.test(inventory.getInvStack(inputSlot))) {
|
||||||
|
inventory.shrinkSlot(inputSlot, ingredient.getCount());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -199,57 +200,66 @@ public class IronAlloyFurnaceBlockEntity extends MachineBaseBlockEntity
|
||||||
* @return Boolean True if furnace is burning
|
* @return Boolean True if furnace is burning
|
||||||
*/
|
*/
|
||||||
public boolean isBurning() {
|
public boolean isBurning() {
|
||||||
return this.burnTime > 0;
|
return burnTime > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getBurnTimeRemainingScaled(final int scale) {
|
public int getBurnTimeRemainingScaled(int scale) {
|
||||||
if (this.currentItemBurnTime == 0) {
|
if (totalBurnTime == 0) {
|
||||||
this.currentItemBurnTime = 200;
|
totalBurnTime = 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.burnTime * scale / this.currentItemBurnTime;
|
return burnTime * scale / totalBurnTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCookProgressScaled(final int scale) {
|
public int getCookProgressScaled(int scale) {
|
||||||
return this.cookTime * scale / 200;
|
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
|
@Override
|
||||||
public Direction getFacing() {
|
public Direction getFacing() {
|
||||||
return this.getFacingEnum();
|
return getFacingEnum();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getToolDrop(final PlayerEntity entityPlayer) {
|
public ItemStack getToolDrop(PlayerEntity entityPlayer) {
|
||||||
return TRContent.Machine.IRON_ALLOY_FURNACE.getStack();
|
return TRContent.Machine.IRON_ALLOY_FURNACE.getStack();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RebornInventory<IronAlloyFurnaceBlockEntity> getInventory() {
|
public RebornInventory<IronAlloyFurnaceBlockEntity> getInventory() {
|
||||||
return this.inventory;
|
return inventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getBurnTime() {
|
public int getBurnTime() {
|
||||||
return this.burnTime;
|
return burnTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBurnTime(final int burnTime) {
|
public void setBurnTime(int burnTime) {
|
||||||
this.burnTime = burnTime;
|
this.burnTime = burnTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCurrentItemBurnTime() {
|
public int getTotalBurnTime() {
|
||||||
return this.currentItemBurnTime;
|
return totalBurnTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCurrentItemBurnTime(final int currentItemBurnTime) {
|
public void setTotalBurnTime(int currentItemBurnTime) {
|
||||||
this.currentItemBurnTime = currentItemBurnTime;
|
this.totalBurnTime = currentItemBurnTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCookTime() {
|
public int getCookTime() {
|
||||||
return this.cookTime;
|
return cookTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCookTime(final int cookTime) {
|
public void setCookTime(int cookTime) {
|
||||||
this.cookTime = cookTime;
|
this.cookTime = cookTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,7 +271,7 @@ public class IronAlloyFurnaceBlockEntity extends MachineBaseBlockEntity
|
||||||
.slot(1, 65, 17)
|
.slot(1, 65, 17)
|
||||||
.outputSlot(2, 116, 35).fuelSlot(3, 56, 53).syncIntegerValue(this::getBurnTime, this::setBurnTime)
|
.outputSlot(2, 116, 35).fuelSlot(3, 56, 53).syncIntegerValue(this::getBurnTime, this::setBurnTime)
|
||||||
.syncIntegerValue(this::getCookTime, this::setCookTime)
|
.syncIntegerValue(this::getCookTime, this::setCookTime)
|
||||||
.syncIntegerValue(this::getCurrentItemBurnTime, this::setCurrentItemBurnTime).addInventory().create(this, syncID);
|
.syncIntegerValue(this::getTotalBurnTime, this::setTotalBurnTime).addInventory().create(this, syncID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -46,31 +46,31 @@ public class IronFurnaceBlockEntity extends MachineBaseBlockEntity
|
||||||
|
|
||||||
public int tickTime;
|
public int tickTime;
|
||||||
public RebornInventory<IronFurnaceBlockEntity> inventory = new RebornInventory<>(3, "IronFurnaceBlockEntity", 64, this, getInvetoryAccess());
|
public RebornInventory<IronFurnaceBlockEntity> inventory = new RebornInventory<>(3, "IronFurnaceBlockEntity", 64, this, getInvetoryAccess());
|
||||||
public int fuel;
|
public int burnTime;
|
||||||
public int fuelGague;
|
public int totalBurnTime;
|
||||||
public int progress;
|
public int progress;
|
||||||
public int fuelScale = 160;
|
public int fuelScale = 160;
|
||||||
int input1 = 0;
|
int inputSlot = 0;
|
||||||
int output = 1;
|
int outputSlot = 1;
|
||||||
int fuelslot = 2;
|
int fuelSlot = 2;
|
||||||
boolean active = false;
|
boolean active = false;
|
||||||
|
|
||||||
public IronFurnaceBlockEntity() {
|
public IronFurnaceBlockEntity() {
|
||||||
super(TRBlockEntities.IRON_FURNACE);
|
super(TRBlockEntities.IRON_FURNACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int gaugeProgressScaled(final int scale) {
|
public int gaugeProgressScaled(int scale) {
|
||||||
return this.progress * scale / this.fuelScale;
|
return progress * scale / fuelScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int gaugeFuelScaled(final int scale) {
|
public int gaugeFuelScaled(int scale) {
|
||||||
if (this.fuelGague == 0) {
|
if (totalBurnTime == 0) {
|
||||||
this.fuelGague = this.fuel;
|
totalBurnTime = burnTime;
|
||||||
if (this.fuelGague == 0) {
|
if (totalBurnTime == 0) {
|
||||||
this.fuelGague = this.fuelScale;
|
totalBurnTime = fuelScale;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.fuel * scale / this.fuelGague;
|
return burnTime * scale / totalBurnTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -79,94 +79,96 @@ public class IronFurnaceBlockEntity extends MachineBaseBlockEntity
|
||||||
if(world.isClient){
|
if(world.isClient){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final boolean burning = this.isBurning();
|
boolean isBurning = isBurning();
|
||||||
boolean updateInventory = false;
|
boolean updateInventory = false;
|
||||||
if (this.fuel > 0) {
|
if (isBurning) {
|
||||||
fuel--;
|
--burnTime;
|
||||||
}
|
}
|
||||||
updateState();
|
|
||||||
if (this.fuel <= 0 && this.canSmelt()) {
|
if (burnTime <= 0 && canSmelt()) {
|
||||||
this.fuel = this.fuelGague = (int) (AbstractFurnaceBlockEntity.createFuelTimeMap().getOrDefault(inventory.getInvStack(this.fuelslot).getItem(), 0) * 1.25);
|
burnTime = totalBurnTime = (int) (AbstractFurnaceBlockEntity.createFuelTimeMap().getOrDefault(inventory.getInvStack(fuelSlot).getItem(), 0) * 1.25);
|
||||||
if (this.fuel > 0) {
|
if (burnTime > 0) {
|
||||||
// Fuel slot
|
// Fuel slot
|
||||||
ItemStack fuelStack = inventory.getInvStack(this.fuelslot);
|
ItemStack fuelStack = inventory.getInvStack(fuelSlot);
|
||||||
if (fuelStack.getItem().hasRecipeRemainder()) {
|
if (fuelStack.getItem().hasRecipeRemainder()) {
|
||||||
inventory.setInvStack(this.fuelslot, new ItemStack(fuelStack.getItem().getRecipeRemainder()));
|
inventory.setInvStack(fuelSlot, new ItemStack(fuelStack.getItem().getRecipeRemainder()));
|
||||||
} else if (fuelStack.getCount() > 1) {
|
} else if (fuelStack.getCount() > 1) {
|
||||||
inventory.shrinkSlot(this.fuelslot, 1);
|
inventory.shrinkSlot(fuelSlot, 1);
|
||||||
} else if (fuelStack.getCount() == 1) {
|
} else if (fuelStack.getCount() == 1) {
|
||||||
inventory.setInvStack(this.fuelslot, ItemStack.EMPTY);
|
inventory.setInvStack(fuelSlot, ItemStack.EMPTY);
|
||||||
}
|
}
|
||||||
updateInventory = true;
|
updateInventory = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.isBurning() && this.canSmelt()) {
|
if (isBurning() && canSmelt()) {
|
||||||
this.progress++;
|
progress++;
|
||||||
if (this.progress >= this.fuelScale) {
|
if (progress >= fuelScale) {
|
||||||
this.progress = 0;
|
progress = 0;
|
||||||
this.cookItems();
|
cookItems();
|
||||||
updateInventory = true;
|
updateInventory = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.progress = 0;
|
progress = 0;
|
||||||
}
|
}
|
||||||
if (burning != this.isBurning()) {
|
if (isBurning != isBurning()) {
|
||||||
updateInventory = true;
|
updateInventory = true;
|
||||||
|
updateState();
|
||||||
}
|
}
|
||||||
if (updateInventory) {
|
if (updateInventory) {
|
||||||
this.markDirty();
|
markDirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cookItems() {
|
public void cookItems() {
|
||||||
if (this.canSmelt()) {
|
if (!canSmelt()) {
|
||||||
final ItemStack itemstack = RecipeUtils.getMatchingRecipes(world, RecipeType.SMELTING, inventory.getInvStack(this.input1));
|
return;
|
||||||
|
}
|
||||||
if (inventory.getInvStack(this.output).isEmpty()) {
|
ItemStack outputStack = getResultFor(inventory.getInvStack(inputSlot));
|
||||||
inventory.setInvStack(this.output, itemstack.copy());
|
if (inventory.getInvStack(outputSlot).isEmpty()) {
|
||||||
} else if (inventory.getInvStack(this.output).isItemEqualIgnoreDamage(itemstack)) {
|
inventory.setInvStack(outputSlot, outputStack.copy());
|
||||||
inventory.getInvStack(this.output).increment(itemstack.getCount());
|
} else if (inventory.getInvStack(outputSlot).isItemEqualIgnoreDamage(outputStack)) {
|
||||||
}
|
inventory.getInvStack(outputSlot).increment(outputStack.getCount());
|
||||||
if (inventory.getInvStack(this.input1).getCount() > 1) {
|
}
|
||||||
inventory.shrinkSlot(this.input1, 1);
|
if (inventory.getInvStack(inputSlot).getCount() > 1) {
|
||||||
} else {
|
inventory.shrinkSlot(inputSlot, 1);
|
||||||
inventory.setInvStack(this.input1, ItemStack.EMPTY);
|
} else {
|
||||||
}
|
inventory.setInvStack(inputSlot, ItemStack.EMPTY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canSmelt() {
|
public boolean canSmelt() {
|
||||||
if (inventory.getInvStack(this.input1).isEmpty())
|
if (inventory.getInvStack(inputSlot).isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
final ItemStack itemstack = RecipeUtils.getMatchingRecipes(world, RecipeType.SMELTING, inventory.getInvStack(this.input1));
|
}
|
||||||
if (itemstack.isEmpty())
|
ItemStack outputStack = getResultFor(inventory.getInvStack(inputSlot));
|
||||||
|
if (outputStack.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
if (inventory.getInvStack(this.output).isEmpty())
|
if (inventory.getInvStack(outputSlot).isEmpty())
|
||||||
return true;
|
return true;
|
||||||
if (!inventory.getInvStack(this.output).isItemEqualIgnoreDamage(itemstack))
|
if (!inventory.getInvStack(outputSlot).isItemEqualIgnoreDamage(outputStack))
|
||||||
return false;
|
return false;
|
||||||
final int result = inventory.getInvStack(this.output).getCount() + itemstack.getCount();
|
int result = inventory.getInvStack(outputSlot).getCount() + outputStack.getCount();
|
||||||
return result <= inventory.getStackLimit() && result <= itemstack.getMaxCount();
|
return result <= inventory.getStackLimit() && result <= outputStack.getMaxCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBurning() {
|
public boolean isBurning() {
|
||||||
return this.fuel > 0;
|
return burnTime > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getResultFor(final ItemStack stack) {
|
private ItemStack getResultFor(ItemStack stack) {
|
||||||
final ItemStack result = RecipeUtils.getMatchingRecipes(world, RecipeType.SMELTING, stack);
|
ItemStack result = RecipeUtils.getMatchingRecipes(world, RecipeType.SMELTING, stack);
|
||||||
if (!result.isEmpty()) {
|
if (!result.isEmpty()) {
|
||||||
return result.copy();
|
return result.copy();
|
||||||
}
|
}
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateState() {
|
private void updateState() {
|
||||||
BlockState state = world.getBlockState(this.pos);
|
BlockState state = world.getBlockState(pos);
|
||||||
if (state.getBlock() instanceof BlockMachineBase) {
|
if (state.getBlock() instanceof BlockMachineBase) {
|
||||||
BlockMachineBase blockMachineBase = (BlockMachineBase) state.getBlock();
|
BlockMachineBase blockMachineBase = (BlockMachineBase) state.getBlock();
|
||||||
if (state.get(BlockMachineBase.ACTIVE) != this.fuel > 0)
|
if (state.get(BlockMachineBase.ACTIVE) != burnTime > 0)
|
||||||
blockMachineBase.setActive(this.fuel > 0, this.world, this.pos);
|
blockMachineBase.setActive(burnTime > 0, world, pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,12 +182,12 @@ public class IronFurnaceBlockEntity extends MachineBaseBlockEntity
|
||||||
if(direction == IInventoryAccess.AccessDirection.INSERT){
|
if(direction == IInventoryAccess.AccessDirection.INSERT){
|
||||||
boolean isFuel = AbstractFurnaceBlockEntity.canUseAsFuel(stack);
|
boolean isFuel = AbstractFurnaceBlockEntity.canUseAsFuel(stack);
|
||||||
if(isFuel){
|
if(isFuel){
|
||||||
ItemStack fuelSlotStack = blockEntity.inventory.getInvStack(blockEntity.fuelslot);
|
ItemStack fuelSlotStack = blockEntity.inventory.getInvStack(blockEntity.fuelSlot);
|
||||||
if(fuelSlotStack.isEmpty() || ItemUtils.isItemEqual(stack, fuelSlotStack, true, true) && fuelSlotStack.getMaxCount() != fuelSlotStack.getCount()){
|
if(fuelSlotStack.isEmpty() || ItemUtils.isItemEqual(stack, fuelSlotStack, true, true) && fuelSlotStack.getMaxCount() != fuelSlotStack.getCount()){
|
||||||
return slotID == blockEntity.fuelslot;
|
return slotID == blockEntity.fuelSlot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return slotID != blockEntity.output;
|
return slotID != blockEntity.outputSlot;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
@ -197,19 +199,19 @@ public class IronFurnaceBlockEntity extends MachineBaseBlockEntity
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getBurnTime() {
|
public int getBurnTime() {
|
||||||
return this.fuel;
|
return this.burnTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBurnTime(final int burnTime) {
|
public void setBurnTime(int burnTime) {
|
||||||
this.fuel = burnTime;
|
this.burnTime = burnTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTotalBurnTime() {
|
public int getTotalBurnTime() {
|
||||||
return this.fuelGague;
|
return this.totalBurnTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTotalBurnTime(final int totalBurnTime) {
|
public void setTotalBurnTime(int totalBurnTime) {
|
||||||
this.fuelGague = totalBurnTime;
|
this.totalBurnTime = totalBurnTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getProgress() {
|
public int getProgress() {
|
||||||
|
@ -222,7 +224,7 @@ public class IronFurnaceBlockEntity extends MachineBaseBlockEntity
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||||
return new ContainerBuilder("ironfurnace").player(player.inventory).inventory(8, 84).hotbar(8, 142)
|
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::getBurnTime, this::setBurnTime)
|
||||||
.syncIntegerValue(this::getProgress, this::setProgress)
|
.syncIntegerValue(this::getProgress, this::setProgress)
|
||||||
|
|
|
@ -32,39 +32,40 @@ import techreborn.blockentity.machine.iron.IronAlloyFurnaceBlockEntity;
|
||||||
|
|
||||||
public class GuiAlloyFurnace extends GuiBase<BuiltContainer> {
|
public class GuiAlloyFurnace extends GuiBase<BuiltContainer> {
|
||||||
|
|
||||||
IronAlloyFurnaceBlockEntity alloyfurnace;
|
IronAlloyFurnaceBlockEntity blockEntity;
|
||||||
|
|
||||||
public GuiAlloyFurnace(int syncID, final PlayerEntity player, final IronAlloyFurnaceBlockEntity alloyFurnace) {
|
public GuiAlloyFurnace(int syncID, PlayerEntity player, IronAlloyFurnaceBlockEntity alloyFurnace) {
|
||||||
super(player, alloyFurnace, alloyFurnace.createContainer(syncID, player));
|
super(player, alloyFurnace, alloyFurnace.createContainer(syncID, player));
|
||||||
this.alloyfurnace = alloyFurnace;
|
this.blockEntity = alloyFurnace;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawBackground(final float f, final int mouseX, final int mouseY) {
|
protected void drawBackground(float lastFrameDuration, int mouseX, int mouseY) {
|
||||||
super.drawBackground(f, mouseX, mouseY);
|
super.drawBackground(lastFrameDuration, mouseX, mouseY);
|
||||||
|
|
||||||
final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND;
|
GuiBase.Layer layer = GuiBase.Layer.BACKGROUND;
|
||||||
|
|
||||||
|
// Input slots
|
||||||
drawSlot(47, 17, layer);
|
drawSlot(47, 17, layer);
|
||||||
drawSlot(65, 17, layer);
|
drawSlot(65, 17, layer);
|
||||||
|
// Fuel slot
|
||||||
drawSlot(56, 53, layer);
|
drawSlot(56, 53, layer);
|
||||||
|
|
||||||
drawOutputSlot(116, 35, layer);
|
drawOutputSlot(116, 35, layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawForeground(final int mouseX, final int mouseY) {
|
protected void drawForeground(int mouseX, int mouseY) {
|
||||||
super.drawForeground(mouseX, mouseY);
|
super.drawForeground(mouseX, mouseY);
|
||||||
final GuiBase.Layer layer = GuiBase.Layer.FOREGROUND;
|
GuiBase.Layer layer = GuiBase.Layer.FOREGROUND;
|
||||||
|
|
||||||
builder.drawProgressBar(this, alloyfurnace.getCookProgressScaled(100), 100, 85, 36, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer);
|
builder.drawProgressBar(this, blockEntity.getCookProgressScaled(100), 100, 85, 36, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer);
|
||||||
builder.drawBurnBar(this, alloyfurnace.getBurnTimeRemainingScaled(100), 100, 56, 36, mouseX, mouseY, layer);
|
builder.drawBurnBar(this, blockEntity.getBurnTimeRemainingScaled(100), 100, 56, 36, mouseX, mouseY, layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(int mouseX, int mouseY, float partialTicks) {
|
public void render(int mouseX, int mouseY, float lastFrameDuration) {
|
||||||
super.render(mouseX, mouseY, partialTicks);
|
super.render(mouseX, mouseY, lastFrameDuration);
|
||||||
this.drawMouseoverTooltip(mouseX, mouseY);
|
this.drawMouseoverTooltip(mouseX, mouseY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,47 +24,46 @@
|
||||||
|
|
||||||
package techreborn.client.gui;
|
package techreborn.client.gui;
|
||||||
|
|
||||||
import com.mojang.blaze3d.platform.GlStateManager;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||||
import reborncore.client.gui.builder.GuiBase;
|
import reborncore.client.gui.builder.GuiBase;
|
||||||
import techreborn.init.TRContent;
|
import reborncore.client.gui.guibuilder.GuiBuilder;
|
||||||
import techreborn.blockentity.machine.iron.IronFurnaceBlockEntity;
|
import techreborn.blockentity.machine.iron.IronFurnaceBlockEntity;
|
||||||
|
|
||||||
public class GuiIronFurnace extends GuiBase<BuiltContainer> {
|
public class GuiIronFurnace extends GuiBase<BuiltContainer> {
|
||||||
|
|
||||||
public static final Identifier texture = new Identifier("minecraft",
|
|
||||||
"textures/gui/container/furnace.png");
|
|
||||||
|
|
||||||
IronFurnaceBlockEntity blockEntity;
|
IronFurnaceBlockEntity blockEntity;
|
||||||
|
|
||||||
public GuiIronFurnace(int syncID, final PlayerEntity player, final IronFurnaceBlockEntity furnace) {
|
public GuiIronFurnace(int syncID, PlayerEntity player, IronFurnaceBlockEntity furnace) {
|
||||||
super(player, furnace, furnace.createContainer(syncID, player));
|
super(player, furnace, furnace.createContainer(syncID, player));
|
||||||
this.blockEntity = furnace;
|
this.blockEntity = furnace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void drawBackground(float lastFrameDuration, int mouseX, int mouseY) {
|
||||||
|
super.drawBackground(lastFrameDuration, mouseX, mouseY);
|
||||||
|
final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND;
|
||||||
|
|
||||||
|
// Input slot
|
||||||
|
drawSlot(56, 17, layer);
|
||||||
|
// Fuel slot
|
||||||
|
drawSlot(56, 53, layer);
|
||||||
|
|
||||||
|
drawOutputSlot(116, 35, layer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void drawForeground(final int mouseX, final int mouseY) {
|
||||||
|
super.drawForeground(mouseX, mouseY);
|
||||||
|
final GuiBase.Layer layer = GuiBase.Layer.FOREGROUND;
|
||||||
|
|
||||||
|
builder.drawProgressBar(this, blockEntity.gaugeProgressScaled(100), 100, 85, 36, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer);
|
||||||
|
builder.drawBurnBar(this, blockEntity.gaugeFuelScaled(100), 100, 56, 36, mouseX, mouseY, layer);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawBackground(float partialTicks, int mouseX, int mouseY) {
|
public void render(int mouseX, int mouseY, float lastFrameDuration) {
|
||||||
renderBackground();
|
super.render(mouseX, mouseY, lastFrameDuration);
|
||||||
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
this.drawMouseoverTooltip(mouseX, mouseY);
|
||||||
builder.drawSlotTab(this, left - 24, top + 6, new ItemStack(TRContent.WRENCH));
|
|
||||||
minecraft.getTextureManager().bindTexture(GuiIronFurnace.texture);
|
|
||||||
final int k = (this.width - containerWidth) / 2;
|
|
||||||
final int l = (this.height - containerHeight) / 2;
|
|
||||||
blit(k, l, 0, 0, containerWidth, containerHeight);
|
|
||||||
|
|
||||||
int j = 0;
|
|
||||||
|
|
||||||
j = blockEntity.gaugeProgressScaled(24);
|
|
||||||
if (j > 0) {
|
|
||||||
blit(k + 78, l + 35, 176, 14, j + 1, 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
j = blockEntity.gaugeFuelScaled(12);
|
|
||||||
if (j > 0) {
|
|
||||||
blit(k + 57, l + 36 + 12 - j, 176, 12 - j, 14, j + 2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue