Jump to content

[mc 1.12.2 - forge 14.23.5.2768] Item Inventory


Recommended Posts

Posted

I'm back from an old mod i've made for mc 1.11.2

 

I've mostly restart from scratch and just rewrite all my class to create my "Bag".

The problem is ... i havn't any error but nothing happend, so i think io just miss something but can't find what is wrong.

 

Main.java

package com.kporal.mcplus;

import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemArmor.ArmorMaterial;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;

@Mod( modid = Main.MODID, name = Main.NAME, version = Main.VERSION, acceptedMinecraftVersions = Main.MCVERSION )
public class Main {

	public static final String MODID = "mcplus";
	public static final String NAME = "MCPlus";
	public static final String VERSION = "1.0";
	public static final String MCVERSION = "[1.12.2]";
	
	public static final ArmorMaterial armorMCP = EnumHelper.addArmorMaterial( "armorMCP", MODID + ":dragoon", 1600, new int[] { 4, 8, 10, 4 }, 30, SoundEvents.ITEM_ARMOR_EQIIP_ELYTRA, 4 ).setRepairItem( new ItemStack( Items.EMERALD ));
	public static final ToolMaterial emeraldMCP = EnumHelper.addToolMaterial( "emeraldMCP", 4, 10000, 10.0F, 9.0F, 30 ).setRepairItem( new ItemStack( Items.EMERALD ));
	
	public static Item ehaxe, dragoonHelmet, dragoonChest, dragoonLegs, dragoonBoots, kitbag;
	
	@EventHandler
	public void preInit( FMLPreInitializationEvent event ) {
		ehaxe = new Ehaxe( emeraldMCP );
		dragoonHelmet = new DragoonArmor( armorMCP, EntityEquipmentSlot.HEAD, "dragoon_helmet" );
		dragoonChest = new DragoonArmor( armorMCP, EntityEquipmentSlot.CHEST, "dragoon_chest" );
		dragoonLegs = new DragoonArmor( armorMCP, EntityEquipmentSlot.LEGS, "dragoon_legs" );
		dragoonBoots = new DragoonArmor( armorMCP, EntityEquipmentSlot.FEET, "dragoon_boots" );
		kitbag = new Kitbag();
	}

	@EventHandler
	public void init( FMLInitializationEvent event ) {}
	
}

 

Kitbag.java

package com.kporal.mcplus;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.ICapabilityProvider;

public class Kitbag extends Item {
	
	public Kitbag() {
		
		this.setRegistryName( "kitbag" );
		this.setTranslationKey( "kitbag" );
		this.setCreativeTab( CreativeTabs.TOOLS );
		this.setMaxStackSize( 1 );
		
	}

	public ActionResult<ItemStack> onItemRightClick( World w, EntityPlayer p, EnumHand e ) {
		//NBTTagCompound nbt = new NBTTagCompound();
		//inventory.deserializeNBT( nbt );

		return new ActionResult<ItemStack>( EnumActionResult.PASS, p.getHeldItemMainhand() );
	}

	public void onPlayerStoppedUsing( ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft ) {
		//inventory.serializeNBT();
	}
	
	@Override
	public ICapabilityProvider initCapabilities( ItemStack item, NBTTagCompound nbt ) {
		if( item.getItem() == Main.kitbag ) {
			return new KitbagProvider();
		}
		return null;
	}
	
}

 

KitbagProvider.java

package com.kporal.mcplus;

import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.ItemStackHandler;

public class KitbagProvider implements ICapabilityProvider, ICapabilitySerializable<NBTTagCompound> {
	
	private final ItemStackHandler inventory;
	
	public KitbagProvider() {
		inventory = new ItemStackHandler( 54 );
	}
	
	@Override
	public NBTTagCompound serializeNBT() {
		return inventory.serializeNBT();
	}

	public void deserializeNBT( NBTTagCompound nbt ) {
		inventory.deserializeNBT( nbt );
	}

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

	@Override
	public <T> T getCapability( Capability<T> capability, EnumFacing facing ) {
		if( capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY ) {
			return (T) inventory; 
		}
		return null;
	}
	
}

 

KitbagContainer.java

package com.kporal.mcplus;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.SlotItemHandler;

public class KitbagContainer extends Container {

	public KitbagContainer( IItemHandler i, EntityPlayer p ) {
		
		int xPos = 8;
		int yPos = 18;
		int iid = 0;
	
		for( int y = 0; y < 6; ++y ) {
			for( int x = 0; x < 9; ++x ) {
				addSlotToContainer( new SlotItemHandler( i, iid, xPos + x * 18, yPos + y * 18 ));
				iid++;
			}
		}
		
		yPos = 140;
		
		for( int y = 0; y < 3; ++y ) {
			for( int x = 0; x < 9; ++x ) {
				addSlotToContainer( new Slot( p.inventory, x + y * 9 + 9, xPos + x * 18, yPos + y * 18 ));
			}
		}
		
		for( int x = 0; x < 9; ++x ) {
			addSlotToContainer( new Slot( p.inventory, x, xPos + x * 18, 198 ));
		}
		
	}
	
	@Override
	public boolean canInteractWith( EntityPlayer p ) {
		return true;
	}
	
}

 

KitbagGuiHandler.java

package com.kporal.mcplus;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.IGuiHandler;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;

public class KitbagGuiHandler implements IGuiHandler {

	@Override
	public Object getServerGuiElement(int ID, EntityPlayer p, World w, int x, int y, int z) {
		return new KitbagContainer( (IItemHandler) p.getHeldItemMainhand().getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null ), p );
	}

	@Override
	public Object getClientGuiElement(int ID, EntityPlayer p, World w, int x, int y, int z) {
		return new KitbagGui( (IItemHandler) p.getHeldItemMainhand().getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null ), p );
	}
	
}

 

KitbagGui.java

package com.kporal.mcplus;

import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.items.IItemHandler;

public class KitbagGui extends GuiContainer {

	private IItemHandler i;
	
	public KitbagGui( IItemHandler i, EntityPlayer p ) {
		super( new KitbagContainer( i, p ));
		
		this.xSize = 175;
		this.ySize = 221;
		this.i = i;
	}

	@Override
	protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
		GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
		this.mc.getTextureManager().bindTexture( new ResourceLocation( Main.MODID, "textures/gui/container/kitbag.png" ) );
		this.drawTexturedModalRect( this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize );
	}
	
}

 

The game start without any error, my item is registered, i can't take it / craft it, absolutely no issue, but nothing happend on right click, so if any one see where i'm wrong and can tell me what's my error !

Posted

Update to a modern version of Minecraft. Anything under 1.14.4 isn't supported anymore because its too old.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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