mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-23 03:49:22 +01:00
Something something powered furnace.
This commit is contained in:
parent
0e48b0444d
commit
38daf28115
4 changed files with 37 additions and 21 deletions
|
@ -14,6 +14,7 @@ import static net.minecraft.state.properties.BlockStateProperties.HORIZONTAL_FAC
|
|||
import static net.minecraft.state.properties.BlockStateProperties.LIT;
|
||||
|
||||
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase;
|
||||
import de.ellpeck.actuallyadditions.mod.blocks.base.DirectionalBlock;
|
||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityPoweredFurnace;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
|
@ -33,9 +34,10 @@ import net.minecraft.world.IBlockReader;
|
|||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Random;
|
||||
|
||||
public class BlockPoweredFurnace extends BlockContainerBase {
|
||||
public class BlockPoweredFurnace extends DirectionalBlock.Container {
|
||||
public BlockPoweredFurnace() {
|
||||
// TODO: [port] confirm this is correct for light level... Might not be reactive.
|
||||
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));
|
||||
}
|
||||
|
||||
//@Override
|
||||
public TileEntity newBlockEntity(IBlockReader worldIn) {
|
||||
@Nullable
|
||||
@Override
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
||||
return new TileEntityPoweredFurnace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTileEntity(BlockState state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomTick(BlockState state, ServerWorld worldIn, BlockPos pos, Random random) {
|
||||
if (state.getValue(LIT)) {
|
||||
|
@ -59,6 +67,8 @@ public class BlockPoweredFurnace extends BlockContainerBase {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public ActionResultType use(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
|
||||
return this.openGui(worldIn, player, pos, TileEntityPoweredFurnace.class);
|
||||
|
|
|
@ -272,7 +272,7 @@ public abstract class BlockContainerBase extends Block {
|
|||
|
||||
@Override
|
||||
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)) {
|
||||
this.dropInventory(world, pos);
|
||||
}
|
||||
|
|
|
@ -12,19 +12,25 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui;
|
|||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||
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.util.AssetUtil;
|
||||
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.fml.client.gui.GuiUtils;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collections;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class GuiFurnaceDouble extends AAScreen<ContainerFurnaceDouble> {
|
||||
|
@ -47,20 +53,21 @@ public class GuiFurnaceDouble extends AAScreen<ContainerFurnaceDouble> {
|
|||
super.render(matrices, x, y, f);
|
||||
this.energy.render(matrices, x, y);
|
||||
|
||||
// if (this.buttonAutoSplit.isMouseOver(x, y)) {
|
||||
// this.drawHoveringText(Collections.singletonList(TextFormatting.BOLD + (this.tileFurnace.isAutoSplit
|
||||
// ? StringUtil.localize("info." + ActuallyAdditions.MODID + ".gui.autoSplitItems.on")
|
||||
// : StringUtil.localize("info." + ActuallyAdditions.MODID + ".gui.autoSplitItems.off"))), x, y);
|
||||
// }
|
||||
if (this.buttonAutoSplit.isMouseOver(x, y)) {
|
||||
GuiUtils.drawHoveringText(matrices, Collections.singletonList(this.tileFurnace.isAutoSplit
|
||||
? new TranslationTextComponent("info." + ActuallyAdditions.MODID + ".gui.autoSplitItems.on").withStyle(TextFormatting.BOLD)
|
||||
: new TranslationTextComponent("info." + ActuallyAdditions.MODID + ".gui.autoSplitItems.off").withStyle(TextFormatting.BOLD)), x, y, this.width, this.height, 64, font);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
super.init();
|
||||
this.energy = new EnergyDisplay(this.leftPos + 27, this.topPos + 5, this.tileFurnace.storage);
|
||||
|
||||
// this.buttonAutoSplit = new GuiInputter.SmallerButton(0, this.leftPos, this.topPos, "S");
|
||||
// this.addButton(this.buttonAutoSplit);
|
||||
titleLabelX = (int) (imageWidth / 2.0f - font.width(title) / 2.0f);
|
||||
titleLabelY = -10;
|
||||
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
|
||||
public void renderBg(MatrixStack matrices, float f, int x, int y) {
|
||||
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
|
|
@ -21,14 +21,18 @@ import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
|||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipeType;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.datafix.fixes.FurnaceRecipes;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.energy.IEnergyStorage;
|
||||
|
@ -179,7 +183,7 @@ public class TileEntityPoweredFurnace extends TileEntityInventoryBase implements
|
|||
|
||||
@Override
|
||||
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
|
||||
|
@ -189,7 +193,7 @@ public class TileEntityPoweredFurnace extends TileEntityInventoryBase implements
|
|||
|
||||
public boolean canSmeltOn(int theInput, int theOutput) {
|
||||
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(this.inv.getStackInSlot(theOutput)) || this.inv.getStackInSlot(theOutput).sameItem(output) && this.inv.getStackInSlot(theOutput).getCount() <= this.inv.getStackInSlot(theOutput).getMaxStackSize() - output.getCount()) {
|
||||
return true;
|
||||
|
@ -201,7 +205,7 @@ public class TileEntityPoweredFurnace extends TileEntityInventoryBase implements
|
|||
}
|
||||
|
||||
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))) {
|
||||
this.inv.setStackInSlot(theOutput, output.copy());
|
||||
} else if (this.inv.getStackInSlot(theOutput).getItem() == output.getItem()) {
|
||||
|
@ -234,7 +238,7 @@ public class TileEntityPoweredFurnace extends TileEntityInventoryBase implements
|
|||
|
||||
@Override
|
||||
public ITextComponent getDisplayName() {
|
||||
return StringTextComponent.EMPTY;
|
||||
return new TranslationTextComponent("container.actuallyadditions.furnaceDouble");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
Loading…
Reference in a new issue