Jump to content

Kporal

Members
  • Posts

    48
  • Joined

  • Last visited

Everything posted by Kporal

  1. Hello, i'm looking for a way to execute a command server side when a player interaction event. For now in single player or LAN i used : FMLCommonHandler.instance().getMinecraftServerInstance().getCommandManager().executeCommand() But idk how to tell the server to do that, i'm looking on some other thread and it should be done with packet ?
  2. How did you get values next ?
  3. Ok thank you, just copied the method from ContainerChest and it work !
  4. I don't found anything to make it work ... nobody has this issue ? maybe i missed something in my code ?
  5. hum come back because theire is one weird thing, my inventory work fine, persistent etc all work, but ... about shift clicking ... this cause the game crash each time
  6. Holy crap it work ... thank for your help <3 ( basicaly i've just made some little mistake but it work without problem now ) package com.kporal.lau.items.kitbag; 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; } }
  7. Yes i'm on it actually : package com.kporal.lau.items.kitbag; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraftforge.items.CapabilityItemHandler; 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; for( int y = 0; y < 6; ++y ) { for( int x = 0; x < 9; ++x ) { addSlotToContainer( new SlotItemHandler( p.getHeldItemMainhand().getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null ), x + y * 9 + 9, xPos + x * 18, yPos + y * 18 )); } } 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; } } All should be fine but not for ID, i get an error and a crash after opening the GUI : java.util.concurrent.ExecutionException: java.lang.RuntimeException: Slot 54 not in valid range - [0,54), so this is certainly due to the dynamic SlotItemHandler ID, maybe like other i need to create each slot with ID manually ..
  8. KitbagContainer.java package com.kporal.lau.items.kitbag; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; public class KitbagContainer extends Container { public KitbagContainer( IInventory i, EntityPlayer p ) { int xPos = 8; int yPos = 18; for( int y = 0; y < 6; ++y ) { for( int x = 0; x < 9; ++x ) { addSlotToContainer( new Slot( i, x + y * 9 + 9, xPos + x * 18, yPos + y * 18 )); } } 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; } } KitbagGui.java package com.kporal.lau.items.kitbag; import com.kporal.lau.LAU; 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; public class KitbagGui extends GuiContainer { @SuppressWarnings("unused") private IInventory i; public KitbagGui( IInventory 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( LAU.MODID, "textures/gui/container/kitbag.png" ) ); this.drawTexturedModalRect( this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize ); } } KitbagGuiHandler.java package com.kporal.lau.items.kitbag; 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; public class KitbagGuiHandler implements IGuiHandler { @Override public Object getServerGuiElement(int ID, EntityPlayer p, World w, int x, int y, int z) { return new KitbagContainer( (IInventory) 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( (IInventory) p.getHeldItemMainhand().getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null ), p ); } } I think i'm nearly done but ... something weird i'm stuck, i know where is my problem but idk how to proceed
  9. Omg : public KitbagContainer( IItemHandler iItemHandler, EntityPlayer p ) I implement IItemHandler rather than IInventory ... should be that my error
  10. Ok really thank for your help !!! I've test something and it work fine, reworking my "inventory" to match my 54 slot wanted, but now the only last thing i'm wronk is here : package com.kporal.lau.items.kitbag; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraftforge.items.IItemHandler; public class KitbagContainer extends Container { public KitbagContainer( IItemHandler iItemHandler, EntityPlayer p ) { int xPos = 8; int yPos = 18; for( int y = 0; y < 6; ++y ) { for( int x = 0; x < 9; ++x ) { addSlotToContainer( new Slot( (IInventory) iItemHandler, x + y * 9 + 9, xPos + x * 18, yPos + y * 18 )); } } 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; } } At line 18 ( addSlotToContainer( new Slot( (IInventory) iItemHandler, x + y * 9 + 9, xPos + x * 18, yPos + y * 18 )); ), i know it's wrong, but i need to understand 2 thing before editing corectly my code, first, if i'm right i need to read the inventory of ItemStackHandler ? or IInventory ? not sure at all and the second points is about ID of slots ... actually i've just copied the other line so now the game crash but without this line, all work corectly. java.lang.ClassCastException: net.minecraftforge.items.ItemStackHandler cannot be cast to net.minecraft.inventory.IInventory at com.kporal.lau.items.kitbag.KitbagContainer.<init>(KitbagContainer.java:18)
  11. Yes sorry i've never used gihtub and actually used it only to show my code without rewriting it here ... so i'm going to try something else ... again
  12. Ok to allow me to work nicer, i've made a github, so like i said i'm wrong in some way, actually i've that : https://github.com/Kp0ral/java/tree/mcforge_1.11.2
  13. Ok now i'm here ( but i'm doing soemthing wrong for sure and don't know how to proceed corectly because i'm looking at # for help me, but this tuto is made from a tileentity and not an item ): ItemKitbag.class package com.kporal.lau.items; import com.kporal.lau.LAU; import com.kporal.lau.items.kitbag.KitbagProvider; 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 ItemKitbag extends Item { public ItemKitbag() { setUnlocalizedName( LAU.LAUItems.KITBAG.getUnlocalizedName() ); setRegistryName( LAU.LAUItems.KITBAG.getRegistryName() ); 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() == LAU.kitbag ) { return new KitbagProvider(); } return null; } } KitbagProvider.class package com.kporal.lau.items.kitbag; import net.minecraft.nbt.NBTBase; 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 { private final ItemStackHandler inventory; public KitbagProvider() { inventory = new ItemStackHandler( 9 ); } @Override public NBTBase serializeNBT() { // TODO Auto-generated method stub return null; } @Override public void deserializeNBT( NBTBase nbt ) { // TODO Auto-generated method stub } @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.class package com.kporal.lau.items.kitbag; import com.kporal.lau.items.ItemKitbag; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.SlotItemHandler; public class KitbagContainer extends Container { private KitbagProvider kp; public KitbagContainer( IInventory i, ItemKitbag kg ) { IItemHandler handler = kp.getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null ); this.addSlotToContainer( new SlotItemHandler( handler, 0, 62, 17 ) ); this.addSlotToContainer( new SlotItemHandler( handler, 1, 80, 17 ) ); this.addSlotToContainer( new SlotItemHandler( handler, 2, 98, 17 ) ); this.addSlotToContainer( new SlotItemHandler( handler, 3, 62, 35 ) ); this.addSlotToContainer( new SlotItemHandler( handler, 4, 80, 35 ) ); this.addSlotToContainer( new SlotItemHandler( handler, 5, 98, 35 ) ); this.addSlotToContainer( new SlotItemHandler( handler, 6, 62, 53 ) ); this.addSlotToContainer( new SlotItemHandler( handler, 7, 80, 53 ) ); this.addSlotToContainer( new SlotItemHandler( handler, 8, 62, 53 ) ); int xPos = 8; int yPos = 84; for( int y = 0; y < 3; ++y ) { for( int x = 0; x < 9; ++x ) { this.addSlotToContainer( new Slot( i , x + y * 9 + 9, xPos + x * 18, yPos + y * 18 )); } } for( int x = 0; x < 9; ++x ) { this.addSlotToContainer( new Slot( i, x, xPos + x * 18, 99 )); } } @Override public boolean canInteractWith( EntityPlayer p ) { // TODO Auto-generated method stub return false; } } KitbagGuiHandler.class package com.kporal.lau.items.kitbag; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.fml.common.network.IGuiHandler; public class KitbagGuiHandler implements IGuiHandler { public static final int ITEM_KITBAG = 0; @Override public Object getServerGuiElement(int ID, EntityPlayer p, World w, int x, int y, int z) { if( ID == ITEM_KITBAG ) { return new KitbagContainer( p.inventory, ... ); } return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { // TODO Auto-generated method stub return null; } } And NetworkRegistry.INSTANCE.registerGuiHandler( LAU.instance, new KitbagGuiHandler() ); is defined on the main class. So i now where is my problem at KitbagGuiHandler.class line 15 ( return new KitbagContainer( p.inventory, ... ); ), the second argument needed is ... so ItemKitbag and i think i've made a mistake somewhere ... trying to search where and why but ... f*** myself
  14. KitbagProvider: package com.kporal.lau.items.kitbag; import net.minecraft.nbt.NBTBase; 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 { private final ItemStackHandler inventory; public KitbagProvider() { inventory = new ItemStackHandler( 9 ); } @Override public NBTBase serializeNBT() { // TODO Auto-generated method stub return null; } @Override public void deserializeNBT( NBTBase nbt ) { // TODO Auto-generated method stub } @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; } } ItemKitbag: package com.kporal.lau.items; import com.kporal.lau.LAU; import com.kporal.lau.items.kitbag.KitbagProvider; 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 ItemKitbag extends Item { public ItemKitbag() { setUnlocalizedName( LAU.LAUItems.KITBAG.getUnlocalizedName() ); setRegistryName( LAU.LAUItems.KITBAG.getRegistryName() ); 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() == LAU.kitbag ) { return new KitbagProvider(); } return null; } } So should be "better" now, like you said i need to use NBT and GUI to finish this one, i know it but first i need to understand this before continue
  15. So if i understand corectly my problem, i've made a new class : Provider.class package com.kporal.lau.items.kitbag; import net.minecraft.nbt.NBTBase; 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 Provider implements ICapabilityProvider, ICapabilitySerializable { private ItemStackHandler inventory; public void Init() { inventory = new ItemStackHandler( 9 ); } @Override public NBTBase serializeNBT() { // TODO Auto-generated method stub return null; } @Override public void deserializeNBT(NBTBase nbt) { // TODO Auto-generated method stub } @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; } } So ItemKitgab.class should be like that : package com.kporal.lau.items; import com.kporal.lau.LAU; 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; public class ItemKitbag extends Item { public ItemKitbag() { setUnlocalizedName( LAU.LAUItems.KITBAG.getUnlocalizedName() ); setRegistryName( LAU.LAUItems.KITBAG.getRegistryName() ); 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(); } } And on my main class, on FML event, registering the capability with : CapabilityManager.INSTANCE.register(capability interface class, storage, default implementation factory); ? should be good to iterate my item with a unique instance of ItemStackHandler ?
  16. My last try and fail for tonight ... getting bored by my lake of knowledge hope to found my problem tomorow package com.kporal.lau.items; import com.kporal.lau.Ref; import com.kporal.lau.init.ItemsInit; 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.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.world.World; 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 ItemKitbag extends Item { private ItemStackHandler inventory; public ItemKitbag() { setUnlocalizedName( Ref.LAUItems.KITBAG.getUnlocalizedName() ); setRegistryName( Ref.LAUItems.KITBAG.getRegistryName() ); setCreativeTab( CreativeTabs.TOOLS ); this.setMaxStackSize( 1 ); } public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { NBTTagCompound nbt = new NBTTagCompound(); inventory.deserializeNBT( nbt ); //initCapabilities( playerIn.getHeldItemMainhand(), nbt.getCompoundTag( "ItemStackHandler" ) ).getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null ); return new ActionResult<ItemStack>(EnumActionResult.PASS, playerIn.getHeldItem(handIn)); } public void onPlayerStoppedUsing( ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft ) { inventory.serializeNBT(); } @Override public ICapabilityProvider initCapabilities( ItemStack item, NBTTagCompound nbt ) { if( item.getItem() == ItemsInit.kitbag ) { return new KitBagProvider(); } return null; } public class KitBagProvider implements ICapabilityProvider, ICapabilitySerializable { @Override public NBTBase serializeNBT() { // TODO Auto-generated method stub return null; } @Override public void deserializeNBT( NBTBase nbt ) { // TODO Auto-generated method stub } @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) new ItemStackHandler( 9 ); } return null; } } /*public NBTBase serializeNBT( NBTTagCompound nbt ) { nbt.setTag( "ItemStackHandler", inventory.serializeNBT() ); return null; } public void deserializeNBT( NBTBase nbt ) { this.inventory.deserializeNBT( (( NBTTagCompound ) nbt).getCompoundTag( "ItemStackHandler" ) ); }*/ }
  17. I help me from this thread, and i understand but i really don't know how to proceed, this system is so confusing for me, my problem is where to call the initCapabilities ? so i've removed my "inventory = new ItemStackHandler( 9 );" ok but now ? did i need to write something like that : @Override public ICapabilityProvider initCapabilities( ItemStack item, NBTTagCompound nbt ) { if( item.getItem() instanceof ItemsInit.kitbag ) { return new KitBagProvider(); } return null; } and then on it putting the "ItemStackHandler" ? i'm so confused sorry ... trying to do my best
  18. Ok thank for your help now i've rewrite a little bit of code and do that : package com.kporal.lau.items; import com.kporal.lau.Ref; 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.NBTBase; 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.items.CapabilityItemHandler; import net.minecraftforge.items.ItemStackHandler; public class ItemKitbag extends Item { private ItemStackHandler inventory; public ItemKitbag() { setUnlocalizedName( Ref.LAUItems.KITBAG.getUnlocalizedName() ); setRegistryName( Ref.LAUItems.KITBAG.getRegistryName() ); setCreativeTab( CreativeTabs.TOOLS ); this.setMaxStackSize( 1 ); inventory = new ItemStackHandler( 9 ); } public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { NBTTagCompound nbt = new NBTTagCompound(); inventory.deserializeNBT( nbt ); initCapabilities( playerIn.getHeldItemMainhand(), null ).getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null ); return new ActionResult<ItemStack>(EnumActionResult.PASS, playerIn.getHeldItem(handIn)); } public void onPlayerStoppedUsing( ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft ) { inventory.serializeNBT(); } public NBTBase serializeNBT( NBTTagCompound nbt ) { nbt.setTag( "ItemStackHandler", inventory.serializeNBT() ); return null; } public void deserializeNBT( NBTBase nbt ) { this.inventory.deserializeNBT( (( NBTTagCompound ) nbt).getCompoundTag( "ItemStackHandler" ) ); } } But now, ( and i think maybe i'm on the good way ) because the game crash after right click my item with a null pointer exception ... i must be wrong in some way ...
  19. Ok now i'm working on an ITEM Inventory, not a block ! package com.kporal.lau.items; import com.kporal.lau.Ref; 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.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.world.World; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.ItemStackHandler; public class ItemKitbag extends Item implements ICapabilityProvider { private ItemStackHandler inventory; public ItemKitbag() { setUnlocalizedName( Ref.LAUItems.KITBAG.getUnlocalizedName() ); setRegistryName( Ref.LAUItems.KITBAG.getRegistryName() ); setCreativeTab( CreativeTabs.TOOLS ); this.setMaxStackSize( 1 ); inventory = new ItemStackHandler( 9 ); } public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { NBTTagCompound nbt = new NBTTagCompound(); inventory.deserializeNBT( nbt ); return new ActionResult<ItemStack>(EnumActionResult.PASS, playerIn.getHeldItem(handIn)); } public void onPlayerStoppedUsing( ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft ) { inventory.serializeNBT(); } public NBTBase serializeNBT( NBTTagCompound nbt ) { nbt.setTag( "ItemStackHandler", inventory.serializeNBT() ); return null; } public void deserializeNBT( NBTBase nbt ) { this.inventory.deserializeNBT( (( NBTTagCompound ) nbt).getCompoundTag( "ItemStackHandler" ) ); } @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) this.inventory; } return null; } } So i'm here, but ... i've no error when i start the game, no error on right click etc but nothing happend, maybe i've just fuked up anywhere ... or forgot something. I still learn about forge modding, so ... maybe i need to create a GUI too ? I'm really confused now don't know how to continue this ...
  20. Ok, i've made some mistake ... now it work without cheat mode enabled ( should work too in MP ) : package com.kporal.lau.events; import com.kporal.lau.init.ItemsInit; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.server.MinecraftServer; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextFormatting; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class OnPlayerInteract { @SubscribeEvent ( priority = EventPriority.HIGH ) public void onPlayerRightClick( PlayerInteractEvent.RightClickBlock e ) { EntityPlayer p = e.getEntityPlayer(); if( p.getHeldItemMainhand().getItem() == ItemsInit.windstaff ) { p.setSpawnPoint( e.getPos(), true ); p.sendStatusMessage( new TextComponentString( TextFormatting.RED + "#LAU:" + TextFormatting.WHITE + " Teleport point set at " + e.getPos() ), true ); } } @SubscribeEvent ( priority = EventPriority.HIGH ) public void onPlayerLeftClick( PlayerInteractEvent.LeftClickEmpty e ) { EntityPlayer p = e.getEntityPlayer(); if( p.getHeldItemMainhand().getItem() == ItemsInit.windstaff ) { BlockPos c = p.getBedLocation( p.dimension ); double px = c.getX() + 0.5; double py = c.getY() + 1; double pz = c.getZ() + 0.5; MinecraftServer s = FMLCommonHandler.instance().getMinecraftServerInstance(); s.getCommandManager().executeCommand( s, "/tp " + p.getName() + " " + px + " " + py + " " + pz ); p.sendStatusMessage( new TextComponentString( TextFormatting.RED + "#LAU:" + TextFormatting.WHITE + " Telporting to " + c ), true ); } } } Hope this can help someone else
  21. This way work but only in singleplayer with cheat allowed ... : @SubscribeEvent ( priority = EventPriority.HIGH ) public void onPlayerLeftClick( PlayerInteractEvent.LeftClickEmpty e ) { EntityPlayer p = e.getEntityPlayer(); if( p.getHeldItemMainhand().getItem() == ItemsInit.windstaff ) { BlockPos c = p.getBedLocation( p.dimension ); double px = c.getX() + 0.5; double py = c.getY(); double pz = c.getZ() + 0.5; Minecraft.getMinecraft().player.sendChatMessage( "/tp " + px + " " + py + " " + pz ); } } So i would like to be able to teleport, in singleplayer but also in MP ( i know how to proceed for MP ), but keeping stuck at how teleport the player without cheat enabled with command ( from server no client to bypass cheat mode )
  22. I think you mean : setCreativeTab( CreativeTabs.MATERIALS ); ? About create a tab i know it's possible, i've seen a tuto to do it, but idk how to proceed, if i found the link i post it here.
  23. Hello, i'm back from so far to mod on minecraft ( 1.6.4 ... on bukkit ) SO FAR. I'm writting a similar version of my bukkit plugin with forge for 1.11.2 ( forge-1.11.2-13.20.1.2530-mdk ). So one of the main thing of my mod is about one way teleport for player ( with a custom item and rightclick / leftclick event ) on single player, survival no cheat. package com.kporal.lau.events; import com.kporal.lau.init.ItemsInit; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.server.MinecraftServer; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextFormatting; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class OnPlayerInteract { @SubscribeEvent ( priority = EventPriority.HIGH ) public void onPlayerRightClick( PlayerInteractEvent.RightClickBlock e ) { EntityPlayer p = e.getEntityPlayer(); if( p.getHeldItemMainhand().getItem() == ItemsInit.windstaff ) { p.setSpawnPoint( e.getPos(), true ); p.sendStatusMessage( new TextComponentString( TextFormatting.RED + "#LAU:" + TextFormatting.WHITE + " Teleport point set at " + e.getPos() ), true ); } } @SubscribeEvent ( priority = EventPriority.HIGH ) public void onPlayerLeftClick( PlayerInteractEvent.LeftClickEmpty e ) { EntityPlayer p = e.getEntityPlayer(); if( p.getHeldItemMainhand().getItem() == ItemsInit.windstaff ) { BlockPos c = p.getBedLocation( p.dimension ); //p.sendStatusMessage( new TextComponentString( TextFormatting.RED + "#LAU:" + TextFormatting.WHITE + " Telporting to " + c ), true ); //c = p.getLookVec(). //p.capabilities.allowFlying = true; //p.velocityChanged = true; //p.setPositionAndUpdate( c.getX(), c.getY(), c.getZ() ); //net.minecraftforge.event.entity.living.EnderTeleportEvent tp = new net.minecraftforge.event.entity.living.EnderTeleportEvent(p, c.getX(), c.getY(), c.getZ(), 0); //if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(tp)) return; //p.attemptTeleport( c.getX(), c.getY(), c.getZ() ); //(( EntityPlayerMP ) p).connection.setPlayerLocation( c.getX(), c.getY(), c.getZ(), p.rotationYaw, p.rotationPitch ); //p.velocityChanged = false; //p.capabilities.allowFlying = false; //p.setGameType( GameType.CREATIVE ); //if( !p.world.isRemote ) { //(( EntityPlayerMP ) p).connection.setPlayerLocation( c.getX(), c.getY(), c.getZ() + 1, p.rotationYaw, p.rotationPitch ); //(( EntityPlayerMP ) p).respawnPlayer(); //} //p.respawnPlayer(); //p.capabilities.isCreativeMode = true; //p.setPositionAndUpdate( c.getX(), c.getY(), c.getZ() + 1 ); //p.capabilities.isCreativeMode = false; //p.setGameType( GameType.SURVIVAL ); //p.getServer().getCommandManager().executeCommand( p.getServer(), "tp " + c.getX() + " " + c.getY() + " " + c.getZ() ); //p.getServer().getCommandManager(). //p.getEntityWorld().getMinecraftServer().getCommandManager().executeCommand( p.getServer(), "/tp " + c.getX() + " " + c.getY() + " " + c.getZ() ); p.sendStatusMessage( new TextComponentString( p.getEntityWorld().getMinecraftServer() + " " + p.getServer() + " " + p.getEntityWorld() ), true ); //MinecraftServer.getCommandManager().executeCommand( p, "/tp 0 0 0"); } } } Like you can see, i've tryed a lot of method to teleport the player, but nothing work or getting "player moved wrongly" every time, so rather than trying to do something weird in my code, i simply try a send a /tp command but ... I think ... my error is here : p.getEntityWorld().getMinecraftServer() / p.getServer(), where each time return a null pointer, i'm stuck 2 day i'm trying to teleport my little boy without succes, if anyone can help me ... thank a lot !
×
×
  • Create New...

Important Information

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