Jump to content

Recommended Posts

Posted

Main Class:

package me.Wilfsadude.MyMod;

import me.Wilfsadude.MyMod.Proxy.CommonProxy;
import me.Wilfsadude.MyMod.Util.Reference;
import me.Wilfsadude.MyMod.World.ModWorldGen;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;


@Mod(modid = Reference.MOD_ID, name = Reference.NAME, version = Reference.VERSION)
public class MyMod {


    @Instance
    public static MyMod instance;

    @SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.COMMON_PROXY_CLASS)
    public static CommonProxy proxy;

    @EventHandler
    public static void PreInit(FMLPreInitializationEvent event) {
        GameRegistry.registerWorldGenerator(new ModWorldGen(), 3);

    }

    @EventHandler
    public static void init(FMLInitializationEvent event) {

}

    @EventHandler
    public static void PostInit(FMLPostInitializationEvent event) {

    }
}

TileEntityClass

package me.Wilfsadude.MyMod.Blocks.Machines.Sinterer;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ItemStackHelper;
import net.minecraft.item.*;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.CapabilityItemHandler;

public class TileEntitySinteringFurnace extends TileEntity implements IInventory, ITickable {

    private NonNullList<ItemStack> inventory = NonNullList.<ItemStack>withSize(4, ItemStack.EMPTY);
    private String customName;

    private int burnTime;
    private int currentBurnTime;
    private int cookTime;
    private int totalCookTime = 200;

    @Override
    public String getName() {
        return this.hasCustomName() ? this.customName : "container.sintering_furnace";
    }


    public boolean hasCustomName()
    {
        return this.customName != null && !this.customName.isEmpty();
    }

    public void setCustomName(String customName)
    {
        this.customName = customName;
    }

    @Override
    public ITextComponent getDisplayName()
    {
        return this.hasCustomName() ? new TextComponentString(this.getName()) : new TextComponentTranslation(this.getName());
    }

    @Override
    public int getSizeInventory() {
        return this.inventory.size();
    }

    @Override
    public boolean isEmpty() {
        for (ItemStack stack : this.inventory) {
            if (!stack.isEmpty()) return false;
        }
        return true;
    }

    @Override
    public ItemStack getStackInSlot(int index) {
        return (ItemStack)this.inventory.get(index);
    }

    @Override
    public ItemStack decrStackSize(int index, int count) {
        return ItemStackHelper.getAndSplit(this.inventory, index, count);
    }

    @Override
    public ItemStack removeStackFromSlot(int index) {
        return ItemStackHelper.getAndRemove(this.inventory, index);
    }

    @Override
    public void setInventorySlotContents(int index, ItemStack stack) {
        ItemStack itemStack = (ItemStack)this.inventory.get(index);
        boolean flag = !stack.isEmpty() && stack.isItemEqual(itemStack) && ItemStack.areItemStackTagsEqual(stack, itemStack);
        this.inventory.set(index, stack);

        if (stack.getCount() > this.getInventoryStackLimit())
            stack.setCount(this.getInventoryStackLimit());
        if (index == 0 && index + 1 == 1 && !flag) {
            ItemStack stack1 = (ItemStack)this.inventory.get(index + 1);
            this.totalCookTime = this.getCookTime(stack, stack1);
            this.cookTime = 0;
            this.markDirty();
        }
    }

    @Override
    public void readFromNBT(NBTTagCompound compound)
    {
        super.readFromNBT(compound);
        this.inventory = NonNullList.<ItemStack>withSize(this.getSizeInventory(), ItemStack.EMPTY);
        ItemStackHelper.loadAllItems(compound, this.inventory);
        this.burnTime = compound.getInteger("BurnTime");
        this.cookTime = compound.getInteger("CookTime");
        this.totalCookTime = compound.getInteger("CookTimeTotal");
        this.currentBurnTime = getItemBurnTime((ItemStack)this.inventory.get(2));

        if(compound.hasKey("CustomName", 8)) this.setCustomName(compound.getString("CustomName"));
    }

    @Override
    public NBTTagCompound writeToNBT(NBTTagCompound compound)
    {
        super.writeToNBT(compound);
        compound.setInteger("BurnTime", (short)this.burnTime);
        compound.setInteger("CookTime", (short)this.cookTime);
        compound.setInteger("CookTimeTotal", (short)this.totalCookTime);
        ItemStackHelper.saveAllItems(compound, this.inventory);

        if(this.hasCustomName()) compound.setString("CustomName", this.customName);
        return compound;
    }

    @Override
    public int getInventoryStackLimit() {
        return 64;
    }

    public boolean isBurning()
    {
        return this.burnTime > 0;
    }

    @SideOnly(Side.CLIENT)
    public static boolean isBurning(IInventory inventory)
    {
        return inventory.getField(0) > 0;
    }

    public void update()
    {
        boolean flag = this.isBurning();
        boolean flag1 = false;
        if(this.isBurning()) --this.burnTime;

        if (!this.world.isRemote) {
            ItemStack stack = (ItemStack)this.inventory.get(2);

            if (this.isBurning() || !stack.isEmpty() && !((((ItemStack)this.inventory.get(0)).isEmpty()) || ((ItemStack)this.inventory.get(1)).isEmpty())) {
                if (!this.isBurning() && this.canSmelt()) {
                    this.burnTime = getItemBurnTime(stack);
                    this.currentBurnTime = this.burnTime;

                    if (this.isBurning()) {
                        flag1 = true;

                        if (!stack.isEmpty()) {
                            Item item = stack.getItem();
                            stack.shrink(1);

                            if (stack.isEmpty()) {
                                ItemStack item1 = item.getContainerItem(stack);
                                this.inventory.set(2, item1);
                            }
                        }
                    }
                }
                if (this.isBurning() && this.canSmelt()) {
                    ++this.cookTime;

                    if (this.cookTime == this.totalCookTime) {
                        this.cookTime = 0;
                        this.totalCookTime = this.getCookTime((ItemStack)this.inventory.get(0), (ItemStack)this.inventory.get(1));
                        this.smeltItem();
                        flag1 = true;
                    }
                }
                else  this.cookTime = 0;
            }
            else if (!this.isBurning() && this.cookTime > 0) {
                this.cookTime = MathHelper.clamp(this.cookTime - 2, 0, this.totalCookTime);
            }
            if (flag != this.isBurning()) {
                flag1 = true;
                SinteringFurnace.setState(this.isBurning(), this.world, this.pos);
            }
        } if (flag1)
            this.markDirty();
    }

    public int getCookTime(ItemStack input1, ItemStack input2) {
        return 200;
    }

    private boolean canSmelt()
    {
        if(((ItemStack)this.inventory.get(0)).isEmpty() || ((ItemStack)this.inventory.get(1)).isEmpty()) return false;
        else
        {
            ItemStack result = SinteringFurnaceRecipes.getInstance().getSinteringResult((ItemStack)this.inventory.get(0), (ItemStack)this.inventory.get(1));
            if(result.isEmpty()) return false;
            else
            {
                ItemStack output = (ItemStack)this.inventory.get(3);
                if(output.isEmpty()) return true;
                if(!output.isItemEqual(result)) return false;
                int res = output.getCount() + result.getCount();
                return res <= getInventoryStackLimit() && res <= output.getMaxStackSize();
            }
        }
    }

    public void smeltItem() {
        if (this.canSmelt()) {
            ItemStack input1 = (ItemStack)this.inventory.get(0);
            ItemStack input2 = (ItemStack)this.inventory.get(1);
            ItemStack result = SinteringFurnaceRecipes.getInstance().getSinteringResult(input1, input2);
            ItemStack output = (ItemStack)this.inventory.get(3);

            if (output.isEmpty()) this.inventory.set(3, result.copy());
            else if (output.getItem() == result.getItem()) output.grow(result.getCount());

            input1.shrink(1);
            input2.shrink(1);
        }
    }

    public static int getItemBurnTime(ItemStack fuel)
    {
        if(fuel.isEmpty()) return 0;
        else
        {
            Item item = fuel.getItem();

            if (item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.AIR)
            {
                Block block = Block.getBlockFromItem(item);

                if (block == Blocks.WOODEN_SLAB) return 150;
                if (block.getDefaultState().getMaterial() == Material.WOOD) return 300;
                if (block == Blocks.COAL_BLOCK) return 16000;
            }

            if (item instanceof ItemTool && "WOOD".equals(((ItemTool)item).getToolMaterialName())) return 200;
            if (item instanceof ItemSword && "WOOD".equals(((ItemSword)item).getToolMaterialName())) return 200;
            if (item instanceof ItemHoe && "WOOD".equals(((ItemHoe)item).getMaterialName())) return 200;
            if (item == Items.STICK) return 100;
            if (item == Items.COAL) return 1600;
            if (item == Items.LAVA_BUCKET) return 20000;
            if (item == Item.getItemFromBlock(Blocks.SAPLING)) return 100;
            if (item == Items.BLAZE_ROD) return 2400;

            return GameRegistry.getFuelValue(fuel);
        }
    }

    public static boolean isItemFuel(ItemStack fuel)
    {
        return getItemBurnTime(fuel) > 0;
    }

    public boolean isUsableByPlayer(EntityPlayer player)
    {
        return this.world.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
    }

    @Override
    public void openInventory(EntityPlayer player) {}

    @Override
    public void closeInventory(EntityPlayer player) {}

    @Override
    public boolean isItemValidForSlot(int index, ItemStack stack) {
        if (index == 3) return false;
        else if (index != 2) return true;
        else {
            return isItemFuel(stack);
        }
    }

    public String getGuiId() {
        return "mm:sintering_furnace";
    }

    public int getField(int id)
    {
        switch(id)
        {
            case 0:
                return this.burnTime;
            case 1:
                return this.currentBurnTime;
            case 2:
                return this.cookTime;
            case 3:
                return this.totalCookTime;
            default:
                return 0;
        }
    }

    public void setField(int id, int value)
    {
        switch(id)
        {
            case 0:
                this.burnTime = value;
                break;
            case 1:
                this.currentBurnTime = value;
                break;
            case 2:
                this.cookTime = value;
                break;
            case 3:
                this.totalCookTime = value;
        }
    }

    @Override
    public int getFieldCount() {
        return 4;
    }

    @Override
    public void clear() {
        this.inventory.clear();
    }
}

ContainerClass

package me.Wilfsadude.MyMod.Blocks.Machines.Sinterer;

import me.Wilfsadude.MyMod.Blocks.Machines.Sinterer.Slots.SlotSinteringFurnaceFuel;
import me.Wilfsadude.MyMod.Blocks.Machines.Sinterer.Slots.SlotSinteringFurnaceOutput;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class ContainerSinteringFurnace extends Container {

    private final TileEntitySinteringFurnace tileentity;
    private int cookTime, totalCookTime, burnTime, currentBurnTime;

    public ContainerSinteringFurnace(InventoryPlayer player, TileEntitySinteringFurnace tileentity) {
        this.tileentity = tileentity;

        this.addSlotToContainer(new Slot(tileentity, 0, 20, 17));
        this.addSlotToContainer(new Slot(tileentity, 1, 56, 17));
        this.addSlotToContainer(new SlotSinteringFurnaceFuel(tileentity,2, 38,53));
        this.addSlotToContainer(new SlotSinteringFurnaceOutput(player.player, tileentity,3,112,31));

        for (int y = 0; y < 3; y++) {
            for (int x = 0; x < 9; x++) {
                this.addSlotToContainer(new Slot(player, x + y * 9 + 9, 8 + x * 18, 84 + y * 18));
            }
        }

        for (int x = 0; x < 9; x++) {
            this.addSlotToContainer(new Slot(player, x, 8 + x * 18, 142));
        }
    }

    @Override
    public void addListener(IContainerListener listener) {
        super.addListener(listener);
        listener.sendAllWindowProperties(this, this.tileentity);
    }

    @Override
    public void detectAndSendChanges()
    {
        super.detectAndSendChanges();

        for(int i = 0; i < this.listeners.size(); ++i)
        {
            IContainerListener listener = (IContainerListener)this.listeners.get(i);

            if(this.cookTime != this.tileentity.getField(2)) listener.sendWindowProperty(this, 2, this.tileentity.getField(2));
            if(this.burnTime != this.tileentity.getField(0)) listener.sendWindowProperty(this, 0, this.tileentity.getField(0));
            if(this.currentBurnTime != this.tileentity.getField(1)) listener.sendWindowProperty(this, 1, this.tileentity.getField(1));
            if(this.totalCookTime != this.tileentity.getField(3)) listener.sendWindowProperty(this, 3, this.tileentity.getField(3));
        }

        this.cookTime = this.tileentity.getField(2);
        this.burnTime = this.tileentity.getField(0);
        this.currentBurnTime = this.tileentity.getField(1);
        this.totalCookTime = this.tileentity.getField(3);
    }

    @Override
    @SideOnly(Side.CLIENT)
    public void updateProgressBar(int id, int data)
    {
        this.tileentity.setField(id, data);
    }

    @Override
    public boolean canInteractWith(EntityPlayer playerIn)
    {
        return this.tileentity.isUsableByPlayer(playerIn);
    }

    @Override
    public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
    {
        ItemStack stack = ItemStack.EMPTY;
        Slot slot = (Slot)this.inventorySlots.get(index);

        if(slot != null && slot.getHasStack())
        {
            ItemStack stack1 = slot.getStack();
            stack = stack1.copy();

            if(index == 3)
            {
                if(!this.mergeItemStack(stack1, 4, 40, true)) return ItemStack.EMPTY;
                slot.onSlotChange(stack1, stack);
            }
            else if(index != 2 && index != 1 && index != 0)
            {
                Slot slot1 = (Slot)this.inventorySlots.get(index + 1);

                if(!SinteringFurnaceRecipes.getInstance().getSinteringResult(stack1, slot1.getStack()).isEmpty())
                {
                    if(!this.mergeItemStack(stack1, 0, 2, false))
                    {
                        return ItemStack.EMPTY;
                    }
                    else if(TileEntitySinteringFurnace.isItemFuel(stack1))
                    {
                        if(!this.mergeItemStack(stack1, 2, 3, false)) return ItemStack.EMPTY;
                    }
                    else if(TileEntitySinteringFurnace.isItemFuel(stack1))
                    {
                        if(!this.mergeItemStack(stack1, 2, 3, false)) return ItemStack.EMPTY;
                    }
                    else if(TileEntitySinteringFurnace.isItemFuel(stack1))
                    {
                        if(!this.mergeItemStack(stack1, 2, 3, false)) return ItemStack.EMPTY;
                    }
                    else if(index >= 4 && index < 31)
                    {
                        if(!this.mergeItemStack(stack1, 31, 40, false)) return ItemStack.EMPTY;
                    }
                    else if(index >= 31 && index < 40 && !this.mergeItemStack(stack1, 4, 31, false))
                    {
                        return ItemStack.EMPTY;
                    }
                }
            }
            else if(!this.mergeItemStack(stack1, 4, 40, false))
            {
                return ItemStack.EMPTY;
            }
            if(stack1.isEmpty())
            {
                slot.putStack(ItemStack.EMPTY);
            }
            else
            {
                slot.onSlotChanged();

            }
            if(stack1.getCount() == stack.getCount()) return ItemStack.EMPTY;
            slot.onTake(playerIn, stack1);
        }
        return stack;
    }
}

GuiClass

package me.Wilfsadude.MyMod.Blocks.Machines.Sinterer;

import me.Wilfsadude.MyMod.Util.Reference;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;

public class GuiSinteringFurnace extends GuiContainer {

    private static final ResourceLocation TEXTURES = new ResourceLocation(Reference.MOD_ID + ":textures/gui/sintering_furnace.png");
    private final InventoryPlayer player;
    private final TileEntitySinteringFurnace tileentity;

    public GuiSinteringFurnace(InventoryPlayer player, TileEntitySinteringFurnace tileentity) {
        super(new ContainerSinteringFurnace(player, tileentity));
        this.player = player;
        this.tileentity = tileentity;
    }


    @Override
    protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
        String tileName = this.tileentity.getDisplayName().getUnformattedText();
        this.fontRenderer.drawString(tileName, (this.xSize / 2 - this.fontRenderer.getStringWidth(tileName) / 2) + 3,8,4210752);
        this.fontRenderer.drawString(this.player.getDisplayName().getUnformattedText(), 112, this.ySize - 96 + 2, 4210752);
    }

    @Override
    protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
        GlStateManager.color(1.0f,1.0f,1.0f);
        this.mc.getTextureManager().bindTexture(TEXTURES);
        this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);

        if (TileEntitySinteringFurnace.isBurning(tileentity)) {
            int k = this.getBurnLeftScaled(13);
            this.drawTexturedModalRect(this.guiLeft + 41, this.guiTop + 38 + 12 - k, 176, 12 - k, 14, k + 1);
        }

        int l = this.getCookProgressScaled(24);
        this.drawTexturedModalRect(this.guiLeft + 80, this.guiTop + 36, 176, 14, l+1, 16);
    }

    private int getBurnLeftScaled(int pixels) {
        int i = this.tileentity.getField(1);
        if (i == 0) i = 200;
        return  this.tileentity.getField(0);
    }

    private int getCookProgressScaled(int pixels) {
        int i = this.tileentity.getField(2);
        int j = this.tileentity.getField(3);
        return j != 0 && i != 0 ? i * pixels / j : 0;
    }
}

GuiHandler

package me.Wilfsadude.MyMod.Util.Handlers;

import me.Wilfsadude.MyMod.Blocks.Machines.Sinterer.ContainerSinteringFurnace;
import me.Wilfsadude.MyMod.Blocks.Machines.Sinterer.GuiSinteringFurnace;
import me.Wilfsadude.MyMod.Blocks.Machines.Sinterer.TileEntitySinteringFurnace;
import me.Wilfsadude.MyMod.Util.Reference;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.IGuiHandler;


public class GuiHandler  implements IGuiHandler {

    @Override
    public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
        BlockPos pos = new BlockPos(x,y,z);
        TileEntity tileentity = world.getTileEntity(pos);
        if (tileentity instanceof TileEntitySinteringFurnace) return new ContainerSinteringFurnace(player.inventory, (TileEntitySinteringFurnace)world.getTileEntity(new BlockPos(x,y,z)));
        return null;
    }

    @Override
    public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
        BlockPos pos = new BlockPos(x,y,z);
        TileEntity tileentity = world.getTileEntity(pos);
        if (tileentity instanceof TileEntitySinteringFurnace) return new GuiSinteringFurnace(player.inventory, (TileEntitySinteringFurnace)world.getTileEntity(new BlockPos(x,y,z)));
        return null;
    }
}

RegistryHandler

package me.Wilfsadude.MyMod.Util.Handlers;

import me.Wilfsadude.MyMod.Init.ModBlocks;
import me.Wilfsadude.MyMod.Init.ModItems;
import me.Wilfsadude.MyMod.MyMod;
import me.Wilfsadude.MyMod.Util.IHasModel;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;

@Mod.EventBusSubscriber
public class RegistryHandler {

    @SubscribeEvent
    public static void onItemRegister(RegistryEvent.Register<Item> event) {
        event.getRegistry().registerAll(ModItems.ITEMS.toArray(new Item[0]));
    }

    @SubscribeEvent
    public static void onBlockRegister(RegistryEvent.Register<Block> event) {
        event.getRegistry().registerAll(ModBlocks.BLOCKS.toArray(new Block[0]));
        TileEntityHandler.registerTileEntites();
    }

    @SubscribeEvent
    public static void onModelRegister(ModelRegistryEvent event) {
        for (Item item : ModItems.ITEMS) {
            if (item instanceof IHasModel) {
                ((IHasModel)item).registerModels();
            }
        }

        for (Block block : ModBlocks.BLOCKS) {
            if (block instanceof IHasModel) {
                ((IHasModel)block).registerModels();
            }
        }
    }

    public static void initRegistries() {
        NetworkRegistry.INSTANCE.registerGuiHandler(MyMod.instance, new GuiHandler());

    }
}

Recipies

package me.Wilfsadude.MyMod.Blocks.Machines.Sinterer;

import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Maps;
import com.google.common.collect.Table;
import me.Wilfsadude.MyMod.Init.ModBlocks;
import me.Wilfsadude.MyMod.Init.ModItems;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;

import java.util.Map;

public class SinteringFurnaceRecipes {

    private static final SinteringFurnaceRecipes INSTANCE = new SinteringFurnaceRecipes();
    private final Table<ItemStack, ItemStack, ItemStack> smeltingList = HashBasedTable.<ItemStack, ItemStack, ItemStack>create();
    private final Map<ItemStack, Float> experienceList = Maps.<ItemStack, Float>newHashMap();

    public static SinteringFurnaceRecipes getInstance()
    {
        return INSTANCE;
    }

    private SinteringFurnaceRecipes()
    {
        addSinteringRecipe(new ItemStack(ModBlocks.RUBY_ORE), new ItemStack(Items.DIAMOND), new ItemStack(ModItems.RUBY), 5.0F);
    }


    public void addSinteringRecipe(ItemStack input1, ItemStack input2, ItemStack result, float experience)
    {
        if(getSinteringResult(input1, input2) != ItemStack.EMPTY) return;
        this.smeltingList.put(input1, input2, result);
        this.experienceList.put(result, Float.valueOf(experience));
    }

    public ItemStack getSinteringResult(ItemStack input1, ItemStack input2)
    {
        for(Map.Entry<ItemStack, Map<ItemStack, ItemStack>> entry : this.smeltingList.columnMap().entrySet())
        {
            if(this.compareItemStacks(input1, (ItemStack)entry.getKey()))
            {
                for(Map.Entry<ItemStack, ItemStack> ent : entry.getValue().entrySet())
                {
                    if(this.compareItemStacks(input2, (ItemStack)ent.getKey()))
                    {
                        return (ItemStack)ent.getValue();
                    }
                }
            }
        }
        return ItemStack.EMPTY;
    }

    private boolean compareItemStacks(ItemStack stack1, ItemStack stack2)
    {
        return stack2.getItem() == stack1.getItem() && (stack2.getMetadata() == 32767 || stack2.getMetadata() == stack1.getMetadata());
    }

    public Table<ItemStack, ItemStack, ItemStack> getDualSmeltingList()
    {
        return this.smeltingList;
    }

    public float getSinteringExperience(ItemStack stack)
    {
        for (Map.Entry<ItemStack, Float> entry : this.experienceList.entrySet())
        {
            if(this.compareItemStacks(stack, (ItemStack)entry.getKey()))
            {
                return ((Float)entry.getValue()).floatValue();
            }
        }
        return 0.0F;
    }
}

Please help

Posted (edited)
57 minutes ago, Wilfsadude said:

IInventory

I already told you to never use IInventory in your other thread. Fix this. Please at the very least fix this.

 

57 minutes ago, Wilfsadude said:

CommonProxy

Same with this.

 

57 minutes ago, Wilfsadude said:

IHasModel

And this. These are issues that need to be fixed. While they are not the cause of your main issue they still need to be fixed.

 

How do you want your furnace to work? From what I can decode you want a furnace with 2 inputs and 1 output. Is that correct? In that case consider rewriting this mess

57 minutes ago, Wilfsadude said:

for(Map.Entry<ItemStack, Map<ItemStack, ItemStack>> entry : this.smeltingList.columnMap().entrySet())

{

    if(this.compareItemStacks(input1, (ItemStack)entry.getKey()))

    {

        for(Map.Entry<ItemStack, ItemStack> ent : entry.getValue().entrySet())

        {

            if(this.compareItemStacks(input2, (ItemStack)ent.getKey()))

            {

                return (ItemStack)ent.getValue();

            }

       }

    }

}

Instead of using a Table(and having this iterative mess as a result) consider using a List<Triple<ItemStack, ItemStack, ItemStack>>(left: input1, middle:input2, right: output) that is easier to iterate than a table. Or at least iterate your table by Table#cellSet. Tables are used for column - row => value data storage. This is not the use case for a table(in my opinion). I think that your error lies either here...

 

57 minutes ago, Wilfsadude said:

boolean flag = this.isBurning();

Why do you need this if you continue using this.isBurning everywhere else in your code? What's the point in this boolean declaration if you don't use it?

 

57 minutes ago, Wilfsadude said:

this.isBurning() || !stack.isEmpty() && !((((ItemStack)this.inventory.get(0)).isEmpty()) || ((ItemStack)this.inventory.get(1)).isEmpty())

So, continue the burning checks if the furnace is burning or if the coal slot isn't empty and (stack in slot 0 isn't empty or stack in slot 1 is empty)? This doesn't seem right to me. Check your logic. ...or here

 

57 minutes ago, Wilfsadude said:

else if (output.getItem() == result.getItem()) output.grow(result.getCount());

Aren't you forgetting something? Your recipe class checks for something else in addition to just item comparason. Why doesn't your tile do the same?

 

57 minutes ago, Wilfsadude said:

public static int getItemBurnTime(ItemStack fuel)

And the contents of this method. Please do not blindly copy vanilla classes. This method is public and static in TileEntityFurnace and you have changed nothing in it. Why copy it at all? Just use the one TileEntityFurnace provides. Otherwise you are

a)doing unnecessary work

b)making it harder for you to upgrade later

c)breaking compatibility if some modder uses asm to modify the method in TileEntityFurnace(although they really shouldn't)

 

Also your code is impossible to read on the dark theme.

Edited by V0idWa1k3r
Posted
22 minutes ago, Wilfsadude said:

so what do i NEED to change

 

Well stop using IInventory and use capabilities instead(IItemHandler/ItemStackHandler). Do not use CommonProxy but use a shared interface(IProxy, for example). Do not use IHasModel and register your models directly in the ModelRegistryEvent.

 

1 hour ago, Wilfsadude said:

this.isBurning() || !stack.isEmpty() && !((((ItemStack)this.inventory.get(0)).isEmpty()) || ((ItemStack)this.inventory.get(1)).isEmpty())

Make the logic correct on this one, it doesn't seem right to me.

And as I've said switch from using a table to using a list of Triples.

Posted
21 minutes ago, Wilfsadude said:

so what do i NEED to change

Probably all of these things:

51 minutes ago, V0idWa1k3r said:

Fix this.

51 minutes ago, V0idWa1k3r said:

Same with this.

51 minutes ago, V0idWa1k3r said:

And this.

51 minutes ago, V0idWa1k3r said:

I think that your error lies either here...

51 minutes ago, V0idWa1k3r said:

Check your logic. ...or here

51 minutes ago, V0idWa1k3r said:

Instead of using a Table(and having this iterative mess as a result) consider using a List<Triple<ItemStack, ItemStack, ItemStack>>

51 minutes ago, V0idWa1k3r said:

Aren't you forgetting something?

 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
25 minutes ago, Wilfsadude said:

YES BUT WHAT WILL FIX MY PROBLEM.

You need to fix all the issues regardless. Now you have this problem and later you will have an issue of EnderIO pipes not working with your machines and you will come here again asking for help and I will have to tell you for the fourth time to stop using IInventory. I am not telling you to fix those issues just as a friendly advice. Those are issues that need to be fixed or they will create more problems in the long run. It is easier to fix them right now while your codebase is small rather than only fix one specific issue to later find out that you need to rewrite everything to fix some other issue.

 

As I've said I suspect either the broken logic in the condition I've linked 2 times now or in your Table iteration. So the solution to this particular problem would be to fix the logic and switch from a Table to a List<Triple>.

Posted
7 minutes ago, Wilfsadude said:

what you said doesnt really make much sense

What exactly did you not understand? Use X instead of Y means "replace all X with Y", so using a List instead of a table would mean to replace the Table field with a List field and adjust your logic accordingly to the change(iterate the list instead of a table, etc.).

Posted

oh ok i put a variable at the end

List<Triple<ItemStack, ItemStack, ItemStack>> Items;
        {
            if(this.compareItemStacks(input1, (ItemStack)entry.getKey()))
            {
                for(Map.Entry<ItemStack, ItemStack> ent : entry.getValue().entrySet())
                {
                    if(this.compareItemStacks(input2, (ItemStack)ent.getKey()))
                    {
                        return (ItemStack)ent.getValue();
                    }
                }
            }
        }
        return ItemStack.EMPTY;

i know that is like shit but i am so tired ive been working on this all night please help

Posted

/me sighs at the heavy use of the arrow antipattern.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

I can't really type it out for you since that won't help you. I can guide you through the steps needed at most:

  • Replace your Table<ItemStack, ItemStack, ItemStack> field with a List<Triple<ItemStack, ItemStack, ItemStack>> field
  • When adding new things to the list do List#add(Triple.of(input1, input2, output))
  • When iterating through the list do the enhanced for loop (for (Triple<ItemStack, ItemStack, ItemStack> triple : list))
  • When comparing ItemStacks use triple#getLeft and triple#getMiddle. When getting the result use triple#getRight. Or however you choose to represent your items in said triple.
  • Or better yet instead of manually iterating the list you can use java8's Streams - list.stream().filter(...).map(Triple::getRight).findFirst()(pseudo-code) That gets you an Optional<ItemStack>. If that optional has an element then the recipe was found. Otherwise there is no matching recipe. Make sure you cache your recipe that you've found in your TileEntity because streams are relatively expensive(although there is a point to be made that after a certain amount of iteration the JVM will optimize the stream(see this) but caching is still much better)
7 minutes ago, Wilfsadude said:

List<Triple<ItemStack, ItemStack, ItemStack>> Items;
        {
            if(this.compareItemStacks(input1, (ItemStack)entry.getKey()))
            {
                for(Map.Entry<ItemStack, ItemStack> ent : entry.getValue().entrySet())
                {
                    if(this.compareItemStacks(input2, (ItemStack)ent.getKey()))
                    {
                        return (ItemStack)ent.getValue();
                    }
                }
            }
        }
        return ItemStack.EMPTY;

While this is valid java code it changes nothing compared to your previous implementation. You've just initialized a new local List<Triple<ItemStack, ItemStack, ItemStack>> that by default is null and did nothing with that local.

Posted
public class SinteringFurnaceRecipes {

    private static final SinteringFurnaceRecipes INSTANCE = new SinteringFurnaceRecipes();
    private final List<Triple<ItemStack, ItemStack, ItemStack>> smeltingList = new ArrayList<>();
    private final Map<ItemStack, Float> experienceList = Maps.<ItemStack, Float>newHashMap();

    public static SinteringFurnaceRecipes getInstance()
    {
        return INSTANCE;
    }

    private SinteringFurnaceRecipes()
    {
        addSinteringRecipe(new ItemStack(ModBlocks.RUBY_ORE), new ItemStack(Items.DIAMOND), new ItemStack(ModItems.RUBY), 5.0F);
    }


    public void addSinteringRecipe(ItemStack input1, ItemStack input2, ItemStack result, float experience)
    {
        if(getSinteringResult(input1, input2) != ItemStack.EMPTY) return;
        this.smeltingList.add(Triple.of(input1, input2, result));
        this.experienceList.put(result, Float.valueOf(experience));
    }

    public ItemStack getSinteringResult(ItemStack input1, ItemStack input2)
    {
        for(Triple<ItemStack, ItemStack, ItemStack> triple : smeltingList)
        {
            if(this.compareItemStacks(input1, (ItemStack)triple.getLeft()))
            {
                for(Triple<ItemStack, ItemStack, ItemStack> triple1 : smeltingList)
                {
                    if(this.compareItemStacks(input2, (ItemStack)triple.getMiddle()))
                    {
                        return (ItemStack)triple.getRight();
                    }
                }
            }
        }
        return ItemStack.EMPTY;
    }

    private boolean compareItemStacks(ItemStack stack1, ItemStack stack2)
    {
        return stack2.getItem() == stack1.getItem() && (stack2.getMetadata() == 32767 || stack2.getMetadata() == stack1.getMetadata());
    }

    public List<Triple<ItemStack, ItemStack, ItemStack>> getDualSmeltingList()
    {
        return this.smeltingList;
    }

    public float getSinteringExperience(ItemStack stack)
    {
        for (Map.Entry<ItemStack, Float> entry : this.experienceList.entrySet())
        {
            if(this.compareItemStacks(stack, (ItemStack)entry.getKey()))
            {
                return ((Float)entry.getValue()).floatValue();
            }
        }
        return 0.0F;
    }
}

think i have done it all correct please check

Posted
5 minutes ago, Wilfsadude said:

for(Triple<ItemStack, ItemStack, ItemStack> triple : smeltingList)
        {
            if(this.compareItemStacks(input1, (ItemStack)triple.getLeft()))
            {
                for(Triple<ItemStack, ItemStack, ItemStack> triple1 : smeltingList)
                {
                    if(this.compareItemStacks(input2, (ItemStack)triple.getMiddle()))
                    {
                        return (ItemStack)triple.getRight();
                    }
                }
            }
        }

You do not need this iterative mess. You already have both inputs in a triple, that's why I recommended a triple in the first place. This just makes your iterations take O2 instead of O time to complete. Just do

for (Triple<ItemStack, ItemStack, ItemStack> triple : smeltingList)
{
    if (this.compareItemStacks(input1, triple.getLeft()) && this.compareItemStacks(input2, triple.getMiddle()))
    {
        return triple.getRight();
    }
}

Or even better

return smeltingList.stream().filter(t -> this.compareItemStacks(input1, t.getLeft()) && this.compareItemStacks(input2, t.getMiddle())).map(Triple::getRight).findFirst().orElseGet(ItemStack.EMPTY)

 

Posted

sorry to bother you again but i have made a new gui and it crashes when i open the block.

Crash Report:

---- Minecraft Crash Report ----
// Ouch. That hurt :(

Time: 9/9/18 9:46 AM
Description: Ticking player

java.lang.NullPointerException: Ticking player
	at net.minecraftforge.items.SlotItemHandler.getStack(SlotItemHandler.java:79)
	at net.minecraft.inventory.Container.detectAndSendChanges(Container.java:97)
	at me.Wilfsadude.MyMod.Blocks.Energy.ContainerRedstoneGenerator.detectAndSendChanges(ContainerRedstoneGenerator.java:53)
	at net.minecraft.entity.player.EntityPlayerMP.onUpdate(EntityPlayerMP.java:365)
	at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2168)
	at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:871)
	at net.minecraft.world.World.updateEntity(World.java:2127)
	at net.minecraft.world.WorldServer.tickPlayers(WorldServer.java:672)
	at net.minecraft.world.World.updateEntities(World.java:1903)
	at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:643)
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:842)
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743)
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192)
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592)
	at java.lang.Thread.run(Thread.java:748)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Server thread
Stacktrace:
	at net.minecraftforge.items.SlotItemHandler.getStack(SlotItemHandler.java:79)
	at net.minecraft.inventory.Container.detectAndSendChanges(Container.java:97)
	at me.Wilfsadude.MyMod.Blocks.Energy.ContainerRedstoneGenerator.detectAndSendChanges(ContainerRedstoneGenerator.java:53)
	at net.minecraft.entity.player.EntityPlayerMP.onUpdate(EntityPlayerMP.java:365)
	at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2168)
	at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:871)
	at net.minecraft.world.World.updateEntity(World.java:2127)

-- Player being ticked --
Details:
	Entity Type: null (net.minecraft.entity.player.EntityPlayerMP)
	Entity ID: 224
	Entity Name: Player66
	Entity's Exact location: -193.74, 110.00, 420.20
	Entity's Block location: World: (-194,110,420), Chunk: (at 14,6,4 in -13,26; contains blocks -208,0,416 to -193,255,431), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)
	Entity's Momentum: 0.00, -0.08, 0.00
	Entity's Passengers: []
	Entity's Vehicle: ~~ERROR~~ NullPointerException: null
Stacktrace:
	at net.minecraft.world.WorldServer.tickPlayers(WorldServer.java:672)
	at net.minecraft.world.World.updateEntities(World.java:1903)
	at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:643)

-- Affected level --
Details:
	Level name: New World
	All players: 1 total; [EntityPlayerMP['Player66'/224, l='New World', x=-193.74, y=110.00, z=420.20]]
	Chunk stats: ServerChunkCache: 925 Drop: 0
	Level seed: -8751245432881597772
	Level generator: ID 00 - default, ver 1. Features enabled: true
	Level generator options: 
	Level spawn location: World: (203,64,284), Chunk: (at 11,4,12 in 12,17; contains blocks 192,0,272 to 207,255,287), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
	Level time: 88306 game time, 88306 day time
	Level dimension: 0
	Level storage version: 0x04ABD - Anvil
	Level weather: Rain time: 67671 (now: false), thunder time: 103579 (now: false)
	Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: true
Stacktrace:
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:842)
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743)
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192)
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592)
	at java.lang.Thread.run(Thread.java:748)

-- System Details --
Details:
	Minecraft Version: 1.12.2
	Operating System: Windows 10 (amd64) version 10.0
	Java Version: 1.8.0_172, Oracle Corporation
	Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
	Memory: 494818048 bytes (471 MB) / 1469579264 bytes (1401 MB) up to 3787980800 bytes (3612 MB)
	JVM Flags: 0 total; 
	IntCache: cache: 0, tcache: 0, allocated: 12, tallocated: 94
	FML: MCP 9.42 Powered by Forge 14.23.4.2705 5 mods loaded, 5 mods active
	States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

	| State     | ID        | Version      | Source                           | Signature |
	|:--------- |:--------- |:------------ |:-------------------------------- |:--------- |
	| UCHIJAAAA | minecraft | 1.12.2       | minecraft.jar                    | None      |
	| UCHIJAAAA | mcp       | 9.42         | minecraft.jar                    | None      |
	| UCHIJAAAA | FML       | 8.0.99.99    | forgeSrc-1.12.2-14.23.4.2705.jar | None      |
	| UCHIJAAAA | forge     | 14.23.4.2705 | forgeSrc-1.12.2-14.23.4.2705.jar | None      |
	| UCHIJAAAA | mm        | 1.0          | modid-1.0.jar                    | None      |

	Loaded coremods (and transformers): 
	GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread.
	Profiler Position: N/A (disabled)
	Player Count: 1 / 8; [EntityPlayerMP['Player66'/224, l='New World', x=-193.74, y=110.00, z=420.20]]
	Type: Integrated Server (map_client.txt)
	Is Modded: Definitely; Client brand changed to 'fml,forge'

Contianer class:

public class ContainerRedstoneGenerator extends Container {
    private final TileEntityRedstoneGenerator tileentity;
    private int energy, cookTime;

    public ContainerRedstoneGenerator(InventoryPlayer player, TileEntityRedstoneGenerator tileentity)
    {
        this.tileentity = tileentity;
        IItemHandler handler = tileentity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);

        this.addSlotToContainer(new SlotItemHandler(handler, 0, 80, 33));

        for(int y = 0; y < 3; y++)
        {
            for(int x = 0; x < 9; x++)
            {
                this.addSlotToContainer(new Slot(player, x + y*9 + 9, 8 + x*18, 84 + y*18));
            }
        }

        for(int x = 0; x < 9; x++)
        {
            this.addSlotToContainer(new Slot(player, x, 8 + x * 18, 142));
        }
    }

    @Override
    public boolean canInteractWith(EntityPlayer playerIn)
    {
        return this.tileentity.isUsableByPlayer(playerIn);
    }

    @Override
    public void updateProgressBar(int id, int data)
    {
        this.tileentity.setField(id, data);
    }

    @Override
    public void detectAndSendChanges()
    {
        super.detectAndSendChanges();

        for(int i = 0; i < this.listeners.size(); ++i)
        {
            IContainerListener listener = (IContainerListener)this.listeners.get(i);
            if(this.energy != this.tileentity.getField(0)) listener.sendWindowProperty(this, 0, this.tileentity.getField(0));
            if(this.cookTime != this.tileentity.getField(1)) listener.sendWindowProperty(this, 1, this.tileentity.getField(1));
        }

        this.energy = this.tileentity.getField(0);
        this.cookTime = this.tileentity.getField(1);
    }

    @Override
    public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
    {
        ItemStack stack = ItemStack.EMPTY;
        Slot slot = (Slot)this.inventorySlots.get(index);

        if(slot != null && slot.getHasStack())
        {
            ItemStack stack1 = slot.getStack();
            stack = stack1.copy();

            if(index >= 0 && index < 27)
            {
                if(!this.mergeItemStack(stack1, 27, 36, false)) return ItemStack.EMPTY;
            }
            else if(index >= 27 && index < 36)
            {
                if(!this.mergeItemStack(stack1, 0, 27, false)) return ItemStack.EMPTY;
            }
            else if(!this.mergeItemStack(stack1, 0, 36, false))
            {
                return ItemStack.EMPTY;
            }

            if(stack1.isEmpty()) slot.putStack(ItemStack.EMPTY);
            else slot.onSlotChanged();

            if(stack1.getCount() == stack.getCount()) return ItemStack.EMPTY;
            slot.onTake(playerIn, stack1);
        }

        return stack;
    }
}

Gui Class:

public class GuiRedstoneGenerator extends GuiContainer {

    private static final ResourceLocation TEXTURES = new ResourceLocation(Reference.MOD_ID + ":textures/gui/redstone_generator.png");
    private final InventoryPlayer player;
    private final TileEntityRedstoneGenerator tileentity;

    public GuiRedstoneGenerator(InventoryPlayer player, TileEntityRedstoneGenerator tileentity)
    {
        super(new ContainerRedstoneGenerator(player, tileentity));
        this.player = player;
        this.tileentity = tileentity;
    }

    @Override
    protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
    {
        String tileName = this.tileentity.getDisplayName().getUnformattedText();
        this.fontRenderer.drawString(tileName, (this.xSize / 2 - this.fontRenderer.getStringWidth(tileName) / 2) -5, 6, 4210752);
        this.fontRenderer.drawString(this.player.getDisplayName().getUnformattedText(), 7, this.ySize - 96 + 2, 4210752);
        this.fontRenderer.drawString(Integer.toString(this.tileentity.getEnergyStored()), 115, 72, 4210752);
    }

    @Override
    protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
    {
        GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
        this.mc.getTextureManager().bindTexture(TEXTURES);
        this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);

        int l = this.getCookProgressScaled(24);
        this.drawTexturedModalRect(this.guiLeft + 113, this.guiTop + 32, 176, 14, l + 1, 16);

        int k = this.getEnergyStoredScaled(75);
        this.drawTexturedModalRect(this.guiLeft + 152, this.guiTop + 7, 176, 32, 16, 76 - k);
    }

    private int getEnergyStoredScaled(int pixels)
    {
        int i = this.tileentity.getEnergyStored();
        int j = this.tileentity.getMaxEnergyStored();
        return i != 0 && j != 0 ? i * pixels / j : 0;
    }

    private int getCookProgressScaled(int pixels)
    {
        int i = this.tileentity.cookTime;
        return i != 0 ? i * pixels / 25 : 0;
    }
}

Tile Entity Class

public class TileEntityRedstoneGenerator extends TileEntity implements ITickable {

    public ItemStackHandler handler = new ItemStackHandler(1);
    private CustomEnergyStorage storage = new CustomEnergyStorage(100000);
    public int energy = storage.getEnergyStored();
    private String customName;
    public int cookTime;

    @Override
    public void update() {
        if (!handler.getStackInSlot(0).isEmpty() && isItemFuel(handler.getStackInSlot(0))) {
            cookTime++;
            if (cookTime == 25) {
                energy += getFuelValue(handler.getStackInSlot(0));
                handler.getStackInSlot(0).shrink(1);
                cookTime = 0;
            }
        }

    }

    private boolean isItemFuel(ItemStack stack) {
        return getFuelValue(stack) > 0;
    }

    private int getFuelValue(ItemStack stack) {
        if (stack.getItem() == Items.REDSTONE) return 500;
        else return 0;
    }

    @Override
    public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
        if (capability == CapabilityEnergy.ENERGY) return (T)this.storage;
        return super.getCapability(capability, facing);
    }

    @Override
    public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
        if (capability == CapabilityEnergy.ENERGY) return true;
        if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return true;
        return super.hasCapability(capability, facing);
    }

    @Override
    public NBTTagCompound writeToNBT(NBTTagCompound compound) {
        super.writeToNBT(compound);
        compound.setTag("Inventory", this.handler.serializeNBT());
        compound.setInteger("CookTime", cookTime);
        compound.setInteger("GuiEnergy", this.energy);
        compound.setString("Name", getDisplayName().toString());
        this.storage.writeToNBT(compound);
        return compound;
    }

    @Override
    public void readFromNBT(NBTTagCompound compound) {
        super.readFromNBT(compound);
        this.handler.deserializeNBT(compound.getCompoundTag("Inventory"));
        this.cookTime = compound.getInteger("CookTime");
        this.energy = compound.getInteger("Energy");
        this.customName = compound.getString("Name");
        this.storage.readFromNBT(compound);
    }

    @Override
    public ITextComponent getDisplayName() {
        return new TextComponentTranslation("container.redstone_generator");
    }

    public int getEnergyStored() {
        return this.energy;
    }

    public int getMaxEnergyStored() {
        return this.storage.getMaxEnergyStored();
    }

    public int getField(int id) {
        switch (id) {
            case 0:
                return this.energy;
            case 1:
                return this.cookTime;
            default:
                return 0;
        }
    }

    public void setField(int id, int value) {
        switch (id) {
            case 0:
                this.energy = value;
            case 1:
                this.cookTime = value;
        }
    }

    public boolean isUsableByPlayer(EntityPlayer player)
    {
        return this.world.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
    }
}

Please help. I am guessing it is something wrong with the container class but i dont know what

Posted

Your TileEntity never returns an IItemHandler in it's getCapability method, although it claims to have one in it's hasCapability method. That causes the slot to initialize with a null capability and crash as a result.

Posted (edited)

So I need to put in 

if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)return (T)this.handler
Edited by Wilfsadude
Posted

[main/ERROR] [FML]: Exception loading model for variant mm:redstone_generator#normal for blockstate "mm:redstone_generator"
net.minecraftforge.client.model.ModelLoaderRegistry$LoaderException: Exception loading model mm:redstone_generator#normal with loader VariantLoader.INSTANCE, skipping
    at net.minecraftforge.client.model.ModelLoaderRegistry.getModel(ModelLoaderRegistry.java:153) ~[ModelLoaderRegistry.class:?]
    at net.minecraftforge.client.model.ModelLoader.registerVariant(ModelLoader.java:237) ~[ModelLoader.class:?]
    at net.minecraft.client.renderer.block.model.ModelBakery.loadBlock(ModelBakery.java:153) ~[ModelBakery.class:?]
    at net.minecraftforge.client.model.ModelLoader.loadBlocks(ModelLoader.java:225) ~[ModelLoader.class:?]
    at net.minecraftforge.client.model.ModelLoader.setupModelRegistry(ModelLoader.java:152) ~[ModelLoader.class:?]
    at net.minecraft.client.renderer.block.model.ModelManager.onResourceManagerReload(ModelManager.java:28) [ModelManager.class:?]
    at net.minecraft.client.resources.SimpleReloadableResourceManager.registerReloadListener(SimpleReloadableResourceManager.java:121) [SimpleReloadableResourceManager.class:?]
    at net.minecraft.client.Minecraft.init(Minecraft.java:559) [Minecraft.class:?]
    at net.minecraft.client.Minecraft.run(Minecraft.java:421) [Minecraft.class:?]
    at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_172]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_172]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_172]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_172]
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_172]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_172]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_172]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_172]
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
    at GradleStart.main(GradleStart.java:25) [start/:?]
Caused by: net.minecraft.client.renderer.block.model.ModelBlockDefinition$MissingVariantException
    at net.minecraft.client.renderer.block.model.ModelBlockDefinition.getVariant(ModelBlockDefinition.java:83) ~[ModelBlockDefinition.class:?]
    at net.minecraftforge.client.model.ModelLoader$VariantLoader.loadModel(ModelLoader.java:1182) ~[ModelLoader$VariantLoader.class:?]
    at net.minecraftforge.client.model.ModelLoaderRegistry.getModel(ModelLoaderRegistry.java:149) ~[ModelLoaderRegistry.class:?]
    ... 21 more

 

i get this error when trying to launch and my block is un textured. How do i fix

Posted

Block State

{
   "parent": "block/orientable",
   "textures": {
     "particle": "mm:blocks/sintering_furnace_side",
     "up": "mm:blocks/sintering_furnace_side",
     "down": "mm:blocks/sintering_furnace_side",
     "north": "mm:blocks/redstone_generator_front_off",
     "east": "mm:blocks/sintering_furnace_side",
     "south": "mm:blocks/sintering_furnace_side",
     "west": "mm:blocks/sintering_furnace_side"
   }
 }

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I am having some issues starting an RLCraft server on a minimal install of Debian 12. I have Java installed and I'm able to start the vanilla Minecraft server jar no problem and people can join and play without any issues, as soon as I try to create a new directory with the Forge jar the initial install with the INSTALLER jar works when I use the java command with the --installServer flag, but as soon as I try to start the server using the forge jar that is NOT labelled with installer I get the following error: A problem occurred running the Server launcher.java.lang.reflect.InvocationTargetException         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)         at java.base/java.lang.reflect.Method.invoke(Method.java:569)         at net.minecraftforge.fml.relauncher.ServerLaunchWrapper.run(ServerLaunchWrapper.java:70)         at net.minecraftforge.fml.relauncher.ServerLaunchWrapper.main(ServerLaunchWrapper.java:34) Caused by: java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap')         at net.minecraft.launchwrapper.Launch.<init>(Launch.java:34)         at net.minecraft.launchwrapper.Launch.main(Launch.java:28)         ... 6 more   I have tried using newer versions of Java directly from Oracle as well. Has anybody been successful in starting and running a RLCraft server from the terminal on a Linux machine? I cannot figure out why it doesn't want to work but the vanilla jar works without issue. Thank you in advance!
    • This is my latest attempt :  public class ManaScreen extends Screen { Mana mana = new Mana(); boolean removeManaBar = false; ResourceLocation manaBar = ResourceLocation.fromNamespaceAndPath(RSGArmoury.MOD_ID, "/textures/block/spawnable_arena_wall.png"); public ManaScreen() { super(Component.literal("Mana")); } @Override protected void init() { super.init(); Minecraft.getInstance().setScreen(this); } @Override public boolean isPauseScreen() { return false; } @Override public void render(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) { pGuiGraphics.blit(manaBar, 10, -10, 0, 0, mana.getMana(), 10, mana.getMana(), 10); if (removeManaBar) { this.onClose(); return; } super.render(pGuiGraphics, pMouseX, pMouseY, pPartialTick); } public void addManaBar() { removeManaBar = false; Minecraft.getInstance().setScreen(new ManaScreen()); } public boolean removeManaBar() { return removeManaBar = true; } }
    • I tried a few different things that all didnt work. Right now I have nothing but what I had that seemed most likely to work was just a guiOverlay.blit(x, y, z, vx, vy, getMana()). I dont remember the exact code but it was somthing along those lines. It was in a new class extending screen I believe.
    • yo help pls  i get this error message The game crashed whilst rendering screen Error: java.lang.NullPointerException: Rendering screen https://pastebin.com/fHwr7nXA
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.