Jump to content

Recommended Posts

Posted

hi  ;)

 

i'm trying to make a dual input(technicly quard input) furnace that takes 2 inputs with fuel and 2 inputs of items.

when i put the right fuel in the right slot then it shall be stored in a progress bar thingy,

but when i close the gui and opens it again then it messes up and idk why.

 

package dk.MathiasVO053.RobinsamseCraft.inventory;

 

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.player.InventoryPlayer;

import net.minecraft.inventory.Container;

import net.minecraft.inventory.ICrafting;

import net.minecraft.inventory.Slot;

import net.minecraft.inventory.SlotFurnace;

import net.minecraft.item.ItemStack;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import dk.MathiasVO053.RobinsamseCraft.Crafting.InfuserRecipes;

import dk.MathiasVO053.RobinsamseCraft.tile_entity.TileEntityInfuser2;

 

 

public class InfuserContainer2 extends Container{

 

private TileEntityInfuser2 Infuser;

 

public int fuelCount;

public int infuciumCount;

public int lastCookTime;

 

public InfuserContainer2(InventoryPlayer inventory, TileEntityInfuser2 tileentity) {

this.Infuser = tileentity;

 

this.addSlotToContainer(new Slot(tileentity, 0, 66, 16)); /*input 1*/

this.addSlotToContainer(new Slot(tileentity, 1, 66, 56)); /*input 2*/

this.addSlotToContainer(new SlotFurnace(inventory.player, tileentity, 2, 113, 36)); /*output*/

this.addSlotToContainer(new Slot(tileentity, 3, 150, 65)); /*infucium*/

this.addSlotToContainer(new Slot(tileentity, 4, 10, 65)); /*fuel*/

 

for(int i = 0; i < 3; i++) {

for(int j = 0; j < 9; j++) {

this.addSlotToContainer(new Slot(inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));

}

}

 

for(int i = 0; i < 9; i++) {

this.addSlotToContainer(new Slot(inventory, i, 8 + i * 18, 142));

}

}

 

public void addCraftingToCrafters (ICrafting icrafting) {

super.addCraftingToCrafters(icrafting);

icrafting.sendProgressBarUpdate(this, 1, this.Infuser.cookTime);

icrafting.sendProgressBarUpdate(this, 2, this.Infuser.currentItemBurnTime);

icrafting.sendProgressBarUpdate(this, 3, this.Infuser.FuelCount);

icrafting.sendProgressBarUpdate(this, 4, this.Infuser.InfuciumCount);

}

 

public void detectAndSendChanges() {

super.detectAndSendChanges();

for(int i = 0; i < this.crafters.size(); i++) {

ICrafting icrafting = (ICrafting) this.crafters.get(i);

 

if(this.lastCookTime != this.Infuser.cookTime) {

icrafting.sendProgressBarUpdate(this, 1, this.Infuser.cookTime);

}

 

if(this.fuelCount != this.Infuser.FuelCount) {

icrafting.sendProgressBarUpdate(this, 2, this.Infuser.FuelCount);

}

 

if(this.infuciumCount != this.Infuser.InfuciumCount) {

icrafting.sendProgressBarUpdate(this, 3, this.Infuser.InfuciumCount);

}

 

}

 

this.lastCookTime = this.Infuser.cookTime;

this.infuciumCount = this.Infuser.InfuciumCount;

this.fuelCount = this.Infuser.FuelCount;

 

}

 

@SideOnly(Side.CLIENT)

    public void updateProgressBar(int i, int j){

        if(i == 1){

        Infuser.cookTime = j;

        }

        if(i == 2){

        Infuser.FuelCount = j;

        }

        if(i == 3){

        Infuser.InfuciumCount = j;

        }

    }

 

public boolean canInteractWith(EntityPlayer var1) {

return true;

}

 

}

 

 

 

 

package dk.MathiasVO053.RobinsamseCraft.tile_entity;

 

import cpw.mods.fml.common.registry.GameRegistry;

import dk.MathiasVO053.RobinsamseCraft.ItemReg;

import dk.MathiasVO053.RobinsamseCraft.Crafting.InfuserRecipes;

import dk.MathiasVO053.RobinsamseCraft.blocks.Infuser2;

import net.minecraft.block.Block;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.init.Blocks;

import net.minecraft.init.Items;

import net.minecraft.inventory.ISidedInventory;

import net.minecraft.item.Item;

import net.minecraft.item.ItemBlock;

import net.minecraft.item.ItemStack;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.nbt.NBTTagList;

import net.minecraft.tileentity.TileEntity;

 

public class TileEntityInfuser2 extends TileEntity implements ISidedInventory {

 

private String localizedName;

 

private static final int[] slots_top = new int[]{0};

private static final int[] slots_bottom = new int[]{2, 1};

private static final int[] slots_side = new int[]{1};

 

public static final int maxInfucium = 900;

public static final int maxFuel = 900;

 

private ItemStack[] slots = new ItemStack [5];

 

public int furnaceSpeed = 150;

public int currentItemBurnTime;

public int cookTime;

public int FuelCount;

public int InfuciumCount;

 

 

public void setGuiDisplayName(String displayName) {

this.localizedName = displayName;

}

 

public String getInventoryName() {

return this.hasCustomInventoryName() ? this.localizedName : "container.Infuser";

}

 

public boolean hasCustomInventoryName() {

return this.localizedName != null && this.localizedName.length() > 0;

}

 

public int getSizeInventory() {

return this.slots.length;

}

 

@Override

public ItemStack getStackInSlot(int var1) {

return this.slots[var1];

}

 

@Override

public ItemStack decrStackSize(int var1, int var2) {

if(this.slots[var1] != null){

ItemStack itemstack;

 

if(this.slots[var1].stackSize <= var2 ){

itemstack = this.slots[var1];

this.slots[var1] = null;

return itemstack;

}else{

itemstack = this.slots[var1].splitStack(var2);

 

if(this.slots[var1].stackSize == 0) {

this.slots[var1] = null;

}

 

return itemstack;

}

}else{

return null;

}

}

 

 

@Override

public ItemStack getStackInSlotOnClosing(int i) {

if(this.slots!= null) {

ItemStack itemstack = this.slots;

this.slots = null;

return itemstack;

}

return null;

}

 

@Override

public void setInventorySlotContents(int i, ItemStack itemstack) {

this.slots = itemstack;

 

if(itemstack != null && itemstack.stackSize > this.getInventoryStackLimit()) {

itemstack.stackSize = this.getInventoryStackLimit();

}

 

}

 

@Override

public int getInventoryStackLimit() {

return 64;

}

 

@Override

public boolean isUseableByPlayer(EntityPlayer entityplayer) {

return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : entityplayer.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D;

}

 

public void openInventory() {}

public void closeInventory() {}

 

@Override

public boolean isItemValidForSlot(int i, ItemStack itemstack) {

return i == 2 ? false : (i == 1 ? hasItemPower(itemstack) : true);

}

 

private static int getItemInfucium(ItemStack itemstack) {

if(itemstack == null){

return 0;

}else{

Item item = itemstack.getItem();

 

if(item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.air) {

Block block = Block.getBlockFromItem(item);

 

//if(block == Blocks.sapling) return 100;

}

 

if(item == ItemReg.InfuciumMk2) return 100;

 

}

return GameRegistry.getFuelValue(itemstack);

}

 

private static int getItemPower(ItemStack itemstack) {

if(itemstack == null){

return 0;

}else{

Item item = itemstack.getItem();

 

if(item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.air) {

Block block = Block.getBlockFromItem(item);

 

//if(block == Blocks.sapling) return 100;

}

 

if(item == ItemReg.RainbowPowder) return 100;

 

}

return GameRegistry.getFuelValue(itemstack);

}

 

public boolean hasItemPower(ItemStack itemstack) {

return getItemPower(itemstack) > 0;

}

 

public boolean hasItemInfucium(ItemStack itemstack) {

return getItemInfucium(itemstack) > 0;

}

 

 

public int getFuelRemainingScaled(int i) {

return (FuelCount * i) / maxFuel;

}

 

public int getInfuciumRemainingScaled(int i) {

return (InfuciumCount * i) / maxInfucium;

}

 

 

public boolean hasEnergy() {

return FuelCount > 0;

}

public boolean hasInfucium() {

return InfuciumCount > 0;

}

 

public void updateEntity() {

boolean flag = this.hasEnergy();

boolean flag1 = false;

boolean flag2 = false;

 

if(hasEnergy() && this.isBurning()){

this.FuelCount--;

this.InfuciumCount--;

}

 

if(!worldObj.isRemote){

if(this.hasItemInfucium(this.slots[3]) && this.InfuciumCount < (this.maxInfucium - this.getItemInfucium(this.slots[3]))){

this.InfuciumCount +=  getItemInfucium(this.slots[3]);

 

if(this.slots[3] != null){

flag2 = true;

 

this.slots[3].stackSize--;

 

if(this.slots[3].stackSize  == 0){

this.slots[3] = this.slots[3].getItem().getContainerItem(this.slots[3]);

}

}

}

 

if(!worldObj.isRemote){

if(this.hasItemPower(this.slots[4]) && this.FuelCount < (this.maxFuel - this.getItemPower(this.slots[4]))){

this.FuelCount +=  getItemPower(this.slots[4]);

 

if(this.slots[4] != null){

flag1 = true;

 

this.slots[4].stackSize--;

 

if(this.slots[4].stackSize  == 0){

this.slots[4] = this.slots[4].getItem().getContainerItem(this.slots[4]);

}

}

}

if(hasEnergy() && canSmelt()){

cookTime++;

 

if(this.cookTime == this.furnaceSpeed){

this.cookTime = 0;

this.smeltItem();

flag1 = true;

flag2 = true;

}else{

cookTime = 0;

}

if(flag != this.hasEnergy()){

flag1 = true;

flag2 = true;

Infuser2.updateInfuserBlockState(this.hasEnergy(), worldObj, xCoord, yCoord, zCoord);

}

}

if(flag1 && flag2){

this.markDirty();

}

}

}

}

 

public boolean canSmelt() {

if (this.slots[0] == null) {

return false;

}else{

ItemStack itemstack = InfuserRecipes.smelting().getSmeltingResult(this.slots[0]);

 

if(itemstack == null) return false;

if(this.slots[2] == null) return true;

if(!this.slots[2].isItemEqual(itemstack)) return false;

 

int result = this.slots[2].stackSize + itemstack.stackSize;

 

return (result <= getInventoryStackLimit() && result <= itemstack.getMaxStackSize());

}

}

 

public void smeltItem() {

if(this.canSmelt()) {

ItemStack itemstack = InfuserRecipes.smelting().getSmeltingResult(this.slots[0]);

 

if(this.slots[2] == null) {

this.slots[2] = itemstack.copy();

}else if(this.slots[2].isItemEqual(itemstack)) {

this.slots[2].stackSize += itemstack.stackSize;

}

 

this.slots[0].stackSize--;

 

if(this.slots[0].stackSize <= 0) {

this.slots[0] = null;

}

}

}

 

@Override

public int[] getAccessibleSlotsFromSide(int var1) {

return var1 == 0 ? slots_bottom : (var1 == 1 ? slots_top : slots_side);

}

 

@Override

public boolean canInsertItem(int i, ItemStack itemstack, int j) {

return this.isItemValidForSlot(i, itemstack);

}

 

@Override

public boolean canExtractItem(int i, ItemStack itemstack, int j) {

return j != 0 || i != 1 || itemstack.getItem() == Items.bucket;

}

 

public boolean isBurning(){

return this.cookTime > 0;

}

 

public int getCookProgressScaled(int i) {

return this.cookTime * i / this.furnaceSpeed;

}

 

public void readFromNBT(NBTTagCompound nbt) {

super.readFromNBT(nbt);

 

NBTTagList list = nbt.getTagList("Items", 10);

this.slots = new ItemStack[this.getSizeInventory()];

 

for(int i = 0; i < list.tagCount(); i++) {

NBTTagCompound compound = (NBTTagCompound) list.getCompoundTagAt(i);

byte b = compound.getByte("Slot");

 

if(b >= 0 && b < this.slots.length) {

this.slots = ItemStack.loadItemStackFromNBT(compound);

}

}

this.cookTime = (int)nbt.getShort("CookTime");

this.currentItemBurnTime = (int)nbt.getShort("CurrentBurnTime");

this.InfuciumCount = (int)nbt.getShort("InfuciumCount");

this.FuelCount = (int)nbt.getShort("FuelCount");

 

 

if(nbt.hasKey("CustomName")) {

this.localizedName = nbt.getString("CustomName");

}

}

 

public void writeToNBT(NBTTagCompound nbt) {

super.writeToNBT(nbt);

 

nbt.setShort("CookTime", (short)this.cookTime);

nbt.setShort("CurrentBurnTime", (short)this.currentItemBurnTime);

nbt.setShort("InfuciumCount", (short)this.InfuciumCount);

nbt.setShort("FuelCount", (short)this.FuelCount);

 

NBTTagList list = new NBTTagList();

 

for (int i = 0; i < this.slots.length; i++) {

if(this.slots != null) {

NBTTagCompound compound = new NBTTagCompound();

compound.setByte("Slot", (byte)i);

this.slots.writeToNBT(compound);

list.appendTag(compound);

}

}

 

nbt.setTag("Items", list);

 

if (this.hasCustomInventoryName()) {

nbt.setString("CustomName", this.localizedName);

}

}

}

 

package dk.MathiasVO053.RobinsamseCraft.inventory;

 

import org.lwjgl.opengl.GL11;

 

import dk.MathiasVO053.RobinsamseCraft.Strings;

import dk.MathiasVO053.RobinsamseCraft.tile_entity.TileEntityInfuser2;

import net.minecraft.client.Minecraft;

import net.minecraft.client.gui.inventory.GuiContainer;

import net.minecraft.client.resources.I18n;

import net.minecraft.entity.player.InventoryPlayer;

import net.minecraft.util.ResourceLocation;

 

public class InfuserGui2 extends GuiContainer {

 

public static final ResourceLocation bground = new ResourceLocation(Strings.MODID + ":" + "textures/gui/InfuserMk2Gui.png");

 

public TileEntityInfuser2 Infuser;

 

public InfuserGui2(InventoryPlayer inventoryPlayer, TileEntityInfuser2 entity) {

super(new InfuserContainer2(inventoryPlayer, entity));

 

this.Infuser = entity;

 

this.xSize = 176;

this.ySize = 166;

}

 

 

public void drawGuiContainerForegroundLayer(int par1, int par2) {

 

String name = "InfuserMk2";

this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6, 4210752);

this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 118, this.ySize - 96 + 2, 4210752);

}

 

@Override

protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) {

GL11.glColor4f(1F, 1F, 1F, 1F);

 

Minecraft.getMinecraft().getTextureManager().bindTexture(bground);

drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);

 

if (Infuser.hasEnergy())

        {

            int i1 = Infuser.getFuelRemainingScaled(48);

            drawTexturedModalRect(guiLeft + 10, guiTop + 62 - i1, 180, 101 - i1, 16, i1);

        }

 

if (Infuser.hasInfucium())

        {

            int i2 = Infuser.getInfuciumRemainingScaled(48);

            drawTexturedModalRect(guiLeft + 150, guiTop + 62 - i2, 198, 101 - i2, 16, i2);

        }

 

int k = this.Infuser.getCookProgressScaled(52);

drawTexturedModalRect(guiLeft + 82, guiTop + 19, 176, 0, k + 1, 50);

}

 

}

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 know that this may be a basic question, but I am very new to modding. I am trying to have it so that I can create modified Vanilla loot tables that use a custom enchantment as a condition (i.e. enchantment present = item). However, I am having trouble trying to implement this; the LootItemRandomChanceWithEnchantedBonusCondition constructor needs a Holder<Enchantment> and I am unable to use the getOrThrow() method on the custom enchantment declared in my mod's enchantments class. Here is what I have so far in the GLM:   protected void start(HolderLookup.Provider registries) { HolderLookup.RegistryLookup<Enchantment> registrylookup = registries.lookupOrThrow(Registries.ENCHANTMENT); LootItemRandomChanceWithEnchantedBonusCondition lootItemRandomChanceWithEnchantedBonusCondition = new LootItemRandomChanceWithEnchantedBonusCondition(0.0f, LevelBasedValue.perLevel(0.07f), registrylookup.getOrThrow(*enchantment here*)); this.add("nebu_from_deepslate", new AddItemModifier(new LootItemCondition[]{ LootItemBlockStatePropertyCondition.hasBlockStateProperties(Blocks.DEEPSLATE).build(), LootItemRandomChanceCondition.randomChance(0.25f).build(), lootItemRandomChanceWithEnchantedBonusCondition }, OrichalcumItems.NEBU.get())); }   Inserting Enchantments.[vanilla enchantment here] actually works but trying to declare an enchantment from my custom enchantments class as [mod enchantment class].[custom enchantment] does not work even though they are both a ResourceKey and are registered in Registries.ENCHANTMENT. Basically, how would I go about making it so that a custom enchantment declared as a ResourceKey<Enchantment> of value ResourceKey.create(Registries.ENCHANTMENT, ResourceLocation.fromNamespaceAndPath([modid], [name])), declared in a seperate enchantments class, can be used in the LootItemRandomChanceWithEnchantedBonusCondition constructor as a Holder? I can't use getOrThrow() because there is no level or block entity/entity in the start() method and it is running as datagen. It's driving me nuts.
    • Hi here is an update. I was able to fix the code so my mod does not crash Minecraft. Please understand that I am new to modding but I honestly am having a hard time understanding how anyone can get this to work without having extensive programming and debugging experience as well as searching across the Internet, multiple gen AI bots (claude, grok, openai), and examining source code hidden in the gradle directory and in various github repositories. I guess I am wrong because clearly there are thousands of mods so maybe I am just a newbie. Ok, rant over, here is a step by step summary so others can save the 3 days it took me to figure this out.   1. First, I am using forge 54.1.0 and Minecraft 1.21.4 2. I am creating a mod to add a shotgun to Minecraft 3. After creating the mod and compiling it, I installed the .jar file to the proper directory in Minecraft and used 1.21.4-forge-54.1.0 4. The mod immediately crashed with the error: Caused by: java.lang.NullPointerException: Item id not set 5. Using the stack trace, I determined that the Exception was being thrown from the net.minecraft.world.item.Item.Properties class 6. It seems that there are no javadocs for this class, so I used IntelliJ which was able to provide a decompiled version of the class, which I then examined to see the source of the error. Side question: Are there javadocs? 7. This method, specifically, was the culprit: protected String effectiveDescriptionId() {      return this.descriptionId.get(Objects.requireNonNull(this.id, "Item id not set"));  } 8. Now my quest was to determine how to set this.id. Looking at the same source file, I determined there was another method:  public Item.Properties setId(ResourceKey<Item> pId) {             this.id = pId;             return this;   } 9. So now, I need to figure out how to call setId(). This required working backwards a bit. Starting from the constructor, I stubbed out the variable p which is of type Item.Properties public static final RegistryObject<Item> SHOTGUN = ITEMS.register("shotgun", () -> new ShotgunItem(p)); Rather than putting this all on one line, I split it up for readability like this: private static final Item.Properties p = new Item.Properties().useItemDescriptionPrefix().setId(rk); Here is was the missing function, setId(), which takes a type of ResourceKey<Item>. My next problem is that due to the apparent lack of documentation (I tried searching the docs on this site) I could not determine the full import path to ResourceKey. I did some random searching on the Internet and stumbled across a Github repository which gave two clues: import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; Then I created the rk variable like this: private static ResourceKey<Item> rk = ResourceKey.create(Registries.ITEM, ResourceLocation.parse("modid:shotgunmod")); And now putting it all together in order: private static ResourceKey<Item> rk = ResourceKey.create(Registries.ITEM, ResourceLocation.parse("modid:shotgunmod")); private static final Item.Properties p = new Item.Properties().useItemDescriptionPrefix().setId(rk); public static final RegistryObject<Item> SHOTGUN = ITEMS.register("shotgun", () -> new ShotgunItem(p)); This compiled and the mod no longer crashes. I still have more to do on it, but hopefully this will save someone hours. I welcome any feedback and if I missed some obvious modding resource or tutorial that has this information. If not, I might suggest we add it somewhere for people trying to write a mod that doesn't crash. Thank you !!!  
    • I will keep adding to this thread with more information in case anyone can help, or at the very least I can keep my troubleshooting organized. I decided to downgrade to 54.1.0 in the hopes that this would fix the issue but it didn't. At least now I am on a "recommended" version. The crash report did confirm my earlier post that the Exception is coming from effectiveDescriptionId(). I'll continue to see if I can find a way to set the ID manually.   Caused by: java.lang.NullPointerException: Item id not set         at java.base/java.util.Objects.requireNonNull(Objects.java:259) ~[?:?]         at TRANSFORMER/[email protected]/net.minecraft.world.item.Item$Properties.effectiveDescriptionId(Item.java:465) ~[forge-1.21.4-54.1.0-client.jar!/:?]         at TRANSFORMER/[email protected]/net.minecraft.world.item.Item.<init>(Item.java:111) ~[forge-1.21.4-54.1.0-client.jar!/:?]         at TRANSFORMER/[email protected]/com.example.shotgunmod.ShotgunItem.<init>(ShotgunItem.java:19) ~[shotgunmod-1.0.0.jar!/:1.0.0]         at TRANSFORMER/[email protected]/com.example.shotgunmod.ModItems.lambda$static$0(ModItems.java:15) ~[shotgunmod-1.0.0.jar!/:1.0.0]         at TRANSFORMER/[email protected]/net.minecraftforge.registries.DeferredRegister$EventDispatcher.lambda$handleEvent      
    • It just randomly stop working after a rebooted my dedicated server PLEASE HELP!   com.google.gson   Failed to start the minecraft server com.google.gson.JsonSyntaxException: Expected a com.google.gson.JsonObject but was com.google.gson.JsonPrimitive; at path $  
  • Topics

×
×
  • Create New...

Important Information

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