Jump to content

Korantin

Members
  • Posts

    16
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Korantin's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Okay, so, now I've done that : package com.vkorantin.mcmod.init.capabilities; import net.minecraft.nbt.INBT; import net.minecraft.util.Direction; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ICapabilitySerializable; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemStackHandler; public class ModBackpackCapability implements ICapabilitySerializable { ItemStackHandler myItemStackHandler = new ItemStackHandler(9); private LazyOptional<IItemHandler> handler = LazyOptional.of(() -> myItemStackHandler); @Override public INBT serializeNBT() { return myItemStackHandler.serializeNBT(); } @Override public void deserializeNBT(INBT nbt) { myItemStackHandler.deserializeNBT(myItemStackHandler.serializeNBT()); } @Override public <IItemHandler> LazyOptional<IItemHandler> getCapability(Capability<IItemHandler> cap, Direction side) { return (LazyOptional<IItemHandler>) handler; } } But in my other class that manages events, how I open the GUI ? I just have to call the getCapability method, or I have to do something like in ChestBlock's class to open a chest ?
  2. I study Java in my studies, but we are at the very beginnings. I learn a bit more by myself, but just the basics. I don't understand how to write and read data, like if the player was using a chest, when he right click with the item in his main hand. I know how to detect when he right click with the item in his main hand, but no how to open the same gui as the chest gui, an how to write and read data.
  3. How can I do this ? I don't understand anything, I'm sorry...
  4. package com.vkorantin.mcmod.init.capabilities; import net.minecraft.nbt.INBT; import net.minecraft.util.Direction; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ICapabilitySerializable; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemStackHandler; public class ModBackpackCapability implements ICapabilitySerializable { ItemStackHandler myItemStackHandler = new ItemStackHandler(9); private final LazyOptional<IItemHandler> handler = LazyOptional.of(() -> myItemStackHandler); @Override public INBT serializeNBT() { return null; } @Override public void deserializeNBT(INBT nbt) { } @Override public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) { return null; } } Is it something like this for the LazyOptional<ItemHandler> ?
  5. Sorry, but I really don't understand anything about how to use LazyOptinal<IItemHandler>... Could you explain me please ?
  6. I've done that : package com.vkorantin.mcmod.init.capabilities; import net.minecraft.nbt.INBT; import net.minecraft.util.Direction; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.CapabilityInject; import net.minecraftforge.common.capabilities.ICapabilitySerializable; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemStackHandler; public class ModBackpackCapability implements ICapabilitySerializable { ItemStackHandler myItemStackHandler = new ItemStackHandler(9); @CapabilityInject(ItemStackHandler.class) static Capability<ItemStackHandler> ITEM_HANDLER_CAPABILITY = null; @Override public INBT serializeNBT() { return null; } @Override public void deserializeNBT(INBT nbt) { } @Override public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) { return null; } private LazyOptional<IItemHandler> handler = LazyOptional.of(() -> ITEM_HANDLER_CAPABILITY).cast(); @Override public boolean hasCapability(Capability<?> capability) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return true; } return super.hasCapability(capability); } @Override public <T> T getCapability(Capability<T> capability) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return (T) inventory; } return super.getCapability(capability); } } But in the hasCapability methods, hasCapability is written in red, and the IDE says that "Cannot resolve method 'hasCapability' in 'Object'. Please can you help me to fix it ? I don't really understand what goes wrong... Thanks a lot for all the time you spend for me !
  7. I've searched how to expose my ItemStackHandler as a capacity and still don't understand how to do this... Sorry, but could you explain me how to do this please ? My class : package com.vkorantin.mcmod.init.capabilities; import net.minecraft.nbt.INBT; import net.minecraft.util.Direction; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.CapabilityInject; import net.minecraftforge.common.capabilities.ICapabilitySerializable; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.items.ItemStackHandler; public class ModBackpackCapability implements ICapabilitySerializable { ItemStackHandler myItemStackHandler = new ItemStackHandler(9); @CapabilityInject(ItemStackHandler.class) static Capability<ItemStackHandler> myCapability = null; @Override public INBT serializeNBT() { return null; } @Override public void deserializeNBT(INBT nbt) { } @Override public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) { return null; } }
  8. Remove all the methods ? Or just the annotations ?
  9. When I implemented ICapabilitySerializable, there was an error, and my IDE proposes me to implements methods, then it add these methods, with these annotations
  10. package com.vkorantin.mcmod.init.capabilities; import net.minecraft.nbt.INBT; import net.minecraft.util.Direction; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ICapabilitySerializable; import net.minecraftforge.common.util.LazyOptional; public class ModCapabilities implements ICapabilitySerializable { @org.jetbrains.annotations.NotNull @Override public LazyOptional<T> getCapability(@org.jetbrains.annotations.NotNull Capability<T> cap, @org.jetbrains.annotations.Nullable Direction side) { return null; } @Override public INBT serializeNBT() { return null; } @Override public void deserializeNBT(INBT nbt) { } } I've done that, but my IDE underline in red the line where it is written "public LazyOptional<T> getCapability(@org.jetbrains.annotations.NotNull Capability<T> cap, @org.jetbrains.annotations.Nullable Direction side) {" and says me that there is an error. And the word jetbrains is written in red in all the class. What am I supposed to do to fix it ?
  11. I'm not verry familiar with Capabilities, and I don't really understand the official documentation (I tried to understand this by myself before asking you some help), so could you explain me how can I do this please ? Thanks a lot for helping me !
  12. I have another question... How can I do the same thing, but with a normal chest ? I want to create another item, a backpack, that when the player right click with it in the main hand, it open a container like if he was opening a chest. I also want to keep items that are in the container, to access to them in the future if the player right click with the same backpack. I studied the chest code, but I still don't find how to do this.
  13. Thanks for your answer ! I found how to do this with an ender chest ! Thanks very much !
  14. Hi everybody ! I want to create an item which, when the player right click with it in his main hand, open the Ender Chest container, like if he right click in an Ender Chest. @SubscribeEvent public static void onBackpackUsing(PlayerInteractEvent.RightClickItem event) { PlayerEntity player = event.getPlayer(); World world = event.getWorld(); if (player.getHeldItemMainhand().getItem() == ModItems.ENDER_BACKPACK.get()) { world.setBlockState(player.func_233580_cy_().add(0,-1,0), Blocks.ENDER_CHEST.getDefaultState()); } else if (player.getHeldItemMainhand().getItem() == ModItems.BACKPACK.get()) { world.setBlockState(player.func_233580_cy_().add(0,-1,0), Blocks.CHEST.getDefaultState()); } } With this code, I can place an Ender Chest (or a Chest, depending on the item that the player use) under the player, but I don't know how to open the container, instead of placing the chest. Thanks for you help !
  15. Thanks for your answer, you really helped me !
×
×
  • Create New...

Important Information

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