Something something powered furnace.

This commit is contained in:
Flanks255 2022-01-01 13:28:15 -06:00
parent 0e48b0444d
commit 38daf28115
4 changed files with 37 additions and 21 deletions

View file

@ -14,6 +14,7 @@ import static net.minecraft.state.properties.BlockStateProperties.HORIZONTAL_FAC
import static net.minecraft.state.properties.BlockStateProperties.LIT; import static net.minecraft.state.properties.BlockStateProperties.LIT;
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase; import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase;
import de.ellpeck.actuallyadditions.mod.blocks.base.DirectionalBlock;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityPoweredFurnace; import de.ellpeck.actuallyadditions.mod.tile.TileEntityPoweredFurnace;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
@ -33,9 +34,10 @@ import net.minecraft.world.IBlockReader;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld; import net.minecraft.world.server.ServerWorld;
import javax.annotation.Nullable;
import java.util.Random; import java.util.Random;
public class BlockPoweredFurnace extends BlockContainerBase { public class BlockPoweredFurnace extends DirectionalBlock.Container {
public BlockPoweredFurnace() { public BlockPoweredFurnace() {
// TODO: [port] confirm this is correct for light level... Might not be reactive. // TODO: [port] confirm this is correct for light level... Might not be reactive.
super(ActuallyBlocks.defaultPickProps(0).randomTicks().lightLevel(state -> state.getValue(LIT) super(ActuallyBlocks.defaultPickProps(0).randomTicks().lightLevel(state -> state.getValue(LIT)
@ -45,11 +47,17 @@ public class BlockPoweredFurnace extends BlockContainerBase {
registerDefaultState(getStateDefinition().any().setValue(HORIZONTAL_FACING, Direction.NORTH).setValue(LIT, false)); registerDefaultState(getStateDefinition().any().setValue(HORIZONTAL_FACING, Direction.NORTH).setValue(LIT, false));
} }
//@Override @Nullable
public TileEntity newBlockEntity(IBlockReader worldIn) { @Override
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
return new TileEntityPoweredFurnace(); return new TileEntityPoweredFurnace();
} }
@Override
public boolean hasTileEntity(BlockState state) {
return true;
}
@Override @Override
public void randomTick(BlockState state, ServerWorld worldIn, BlockPos pos, Random random) { public void randomTick(BlockState state, ServerWorld worldIn, BlockPos pos, Random random) {
if (state.getValue(LIT)) { if (state.getValue(LIT)) {
@ -59,6 +67,8 @@ public class BlockPoweredFurnace extends BlockContainerBase {
} }
} }
@Override @Override
public ActionResultType use(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) { public ActionResultType use(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
return this.openGui(worldIn, player, pos, TileEntityPoweredFurnace.class); return this.openGui(worldIn, player, pos, TileEntityPoweredFurnace.class);

View file

@ -272,7 +272,7 @@ public abstract class BlockContainerBase extends Block {
@Override @Override
public void onRemove(BlockState state, World world, BlockPos pos, BlockState newState, boolean isMoving) { public void onRemove(BlockState state, World world, BlockPos pos, BlockState newState, boolean isMoving) {
if (state != newState) { if (state.getBlock() != newState.getBlock()) {
if (this.shouldDropInventory(world, pos)) { if (this.shouldDropInventory(world, pos)) {
this.dropInventory(world, pos); this.dropInventory(world, pos);
} }

View file

@ -12,19 +12,25 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui;
import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.inventory.ContainerFurnaceDouble; import de.ellpeck.actuallyadditions.mod.inventory.ContainerFurnaceDouble;
import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityPoweredFurnace; import de.ellpeck.actuallyadditions.mod.tile.TileEntityPoweredFurnace;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.client.gui.widget.button.Button; import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.client.gui.GuiUtils;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.Collections;
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public class GuiFurnaceDouble extends AAScreen<ContainerFurnaceDouble> { public class GuiFurnaceDouble extends AAScreen<ContainerFurnaceDouble> {
@ -47,20 +53,21 @@ public class GuiFurnaceDouble extends AAScreen<ContainerFurnaceDouble> {
super.render(matrices, x, y, f); super.render(matrices, x, y, f);
this.energy.render(matrices, x, y); this.energy.render(matrices, x, y);
// if (this.buttonAutoSplit.isMouseOver(x, y)) { if (this.buttonAutoSplit.isMouseOver(x, y)) {
// this.drawHoveringText(Collections.singletonList(TextFormatting.BOLD + (this.tileFurnace.isAutoSplit GuiUtils.drawHoveringText(matrices, Collections.singletonList(this.tileFurnace.isAutoSplit
// ? StringUtil.localize("info." + ActuallyAdditions.MODID + ".gui.autoSplitItems.on") ? new TranslationTextComponent("info." + ActuallyAdditions.MODID + ".gui.autoSplitItems.on").withStyle(TextFormatting.BOLD)
// : StringUtil.localize("info." + ActuallyAdditions.MODID + ".gui.autoSplitItems.off"))), x, y); : new TranslationTextComponent("info." + ActuallyAdditions.MODID + ".gui.autoSplitItems.off").withStyle(TextFormatting.BOLD)), x, y, this.width, this.height, 64, font);
// } }
} }
@Override @Override
public void init() { public void init() {
super.init(); super.init();
this.energy = new EnergyDisplay(this.leftPos + 27, this.topPos + 5, this.tileFurnace.storage); this.energy = new EnergyDisplay(this.leftPos + 27, this.topPos + 5, this.tileFurnace.storage);
titleLabelX = (int) (imageWidth / 2.0f - font.width(title) / 2.0f);
// this.buttonAutoSplit = new GuiInputter.SmallerButton(0, this.leftPos, this.topPos, "S"); titleLabelY = -10;
// this.addButton(this.buttonAutoSplit); this.buttonAutoSplit = new Buttons.SmallerButton(this.leftPos, this.topPos, new StringTextComponent("S"), (button) -> PacketHandlerHelper.sendButtonPacket(this.tileFurnace, 0));
this.addButton(this.buttonAutoSplit);
} }
@ -80,11 +87,6 @@ public class GuiFurnaceDouble extends AAScreen<ContainerFurnaceDouble> {
// } // }
// } // }
@Override
public void renderLabels(@Nonnull MatrixStack matrices, int x, int y) {
AssetUtil.displayNameString(matrices, this.font, this.imageWidth, -10, this.tileFurnace);
}
@Override @Override
public void renderBg(MatrixStack matrices, float f, int x, int y) { public void renderBg(MatrixStack matrices, float f, int x, int y) {
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);

View file

@ -21,14 +21,18 @@ import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventory;
import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.INamedContainerProvider; import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipeType;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.datafix.fixes.FurnaceRecipes;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.common.util.Constants; import net.minecraftforge.common.util.Constants;
import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.energy.IEnergyStorage; import net.minecraftforge.energy.IEnergyStorage;
@ -179,7 +183,7 @@ public class TileEntityPoweredFurnace extends TileEntityInventoryBase implements
@Override @Override
public IAcceptor getAcceptor() { public IAcceptor getAcceptor() {
return (slot, stack, automation) -> !automation || (slot == SLOT_INPUT_1 || slot == SLOT_INPUT_2); //&& StackUtil.isValid(FurnaceRecipes.instance().getSmeltingResult(stack)); //TODO return (slot, stack, automation) -> !automation || (slot == SLOT_INPUT_1 || slot == SLOT_INPUT_2) && StackUtil.isValid(level.getServer().getRecipeManager().getRecipeFor(IRecipeType.SMELTING, new Inventory(stack), this.level).map(recipe -> recipe.getResultItem()).orElse(ItemStack.EMPTY));
} }
@Override @Override
@ -189,7 +193,7 @@ public class TileEntityPoweredFurnace extends TileEntityInventoryBase implements
public boolean canSmeltOn(int theInput, int theOutput) { public boolean canSmeltOn(int theInput, int theOutput) {
if (StackUtil.isValid(this.inv.getStackInSlot(theInput))) { if (StackUtil.isValid(this.inv.getStackInSlot(theInput))) {
ItemStack output = ItemStack.EMPTY; //FurnaceRecipes.instance().getSmeltingResult(this.inv.getStackInSlot(theInput)); //TODO ItemStack output = level.getServer().getRecipeManager().getRecipeFor(IRecipeType.SMELTING, new Inventory(this.inv.getStackInSlot(theInput)), this.level).map(recipe -> recipe.getResultItem()).orElse(ItemStack.EMPTY);
if (StackUtil.isValid(output)) { if (StackUtil.isValid(output)) {
if (!StackUtil.isValid(this.inv.getStackInSlot(theOutput)) || this.inv.getStackInSlot(theOutput).sameItem(output) && this.inv.getStackInSlot(theOutput).getCount() <= this.inv.getStackInSlot(theOutput).getMaxStackSize() - output.getCount()) { if (!StackUtil.isValid(this.inv.getStackInSlot(theOutput)) || this.inv.getStackInSlot(theOutput).sameItem(output) && this.inv.getStackInSlot(theOutput).getCount() <= this.inv.getStackInSlot(theOutput).getMaxStackSize() - output.getCount()) {
return true; return true;
@ -201,7 +205,7 @@ public class TileEntityPoweredFurnace extends TileEntityInventoryBase implements
} }
public void finishBurning(int theInput, int theOutput) { public void finishBurning(int theInput, int theOutput) {
ItemStack output = ItemStack.EMPTY; //FurnaceRecipe.instance().getSmeltingResult(this.inv.getStackInSlot(theInput)); //TODO ItemStack output = level.getServer().getRecipeManager().getRecipeFor(IRecipeType.SMELTING, new Inventory(this.inv.getStackInSlot(theInput)), this.level).map(recipe -> recipe.getResultItem()).orElse(ItemStack.EMPTY);
if (!StackUtil.isValid(this.inv.getStackInSlot(theOutput))) { if (!StackUtil.isValid(this.inv.getStackInSlot(theOutput))) {
this.inv.setStackInSlot(theOutput, output.copy()); this.inv.setStackInSlot(theOutput, output.copy());
} else if (this.inv.getStackInSlot(theOutput).getItem() == output.getItem()) { } else if (this.inv.getStackInSlot(theOutput).getItem() == output.getItem()) {
@ -234,7 +238,7 @@ public class TileEntityPoweredFurnace extends TileEntityInventoryBase implements
@Override @Override
public ITextComponent getDisplayName() { public ITextComponent getDisplayName() {
return StringTextComponent.EMPTY; return new TranslationTextComponent("container.actuallyadditions.furnaceDouble");
} }
@Nullable @Nullable