Jump to content

Saucier

Members
  • Posts

    10
  • Joined

  • Last visited

Everything posted by Saucier

  1. Setting item properties like durability / max stack size. Or should I use getters like Item#getMaxDamage(ItemStack) for that?
  2. I have some values in my config which are relevant for my items. Now I would like to pass those settings as an argument at item registration. Like this: event.getRegistry().register(itemFoo = new ItemFoo(Config.testvalue.get())); But using the get() method to get the config value will result in a crash: java.lang.NullPointerException: Cannot get config value without assigned Config object present at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:787) When should I register my config to make sure, that all config values are set (not null) when the item registration triggers? I tried the FMLCommonSetupEvent at first, but it seems like that one actually fires after item registration. (By the way is there some kind of info graphic to see the event order?)
  3. Thank you. Could you tell me the right way to return my overridden methods at getCapability? That's what I have so far: private final IItemHandler inv = new ItemStackHandler(4) { @Override protected void onContentsChanged(int slot) { super.onContentsChanged(slot); markDirty(); } @Override public boolean isItemValid(int slot, @Nonnull ItemStack stack) { // My checks to see if an item is valid in the slot } }; private final LazyOptional<IItemHandler> capItemHandler = LazyOptional.of(() -> createCapabilityHandler()); protected IItemHandler createCapabilityHandler() { return new CombinedInvWrapper(this.inv) { @Override public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) { // Only insert, if stack is valid for the slot return (isItemValid(slot, stack)) ? super.insertItem(slot, stack, simulate) : stack; } @Override public ItemStack extractItem(int slot, int amount, boolean simulate) { // Only pull items from the output slots return (slot == 2 || slot == 3) ? super.extractItem(slot, amount, simulate) : ItemStack.EMPTY; } }; } public <T> LazyOptional<T> getCapability(Capability<T> cap, @Nullable EnumFacing side) { return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.orEmpty(cap, capItemHandler); } It's working so far, but I used the CombinedInvWrapper even tho I'm just using one IItemHandler. I figured I don't need to use different sides, I'll allow inserting/extracting on every side. Is there any better way to do this or is my attempt fine? Thanks so far.
  4. I'm trying to setup my tile entity capabilities for automation, but I'm a bit stuck. I have a tile with an inventory of 4 slots. Two slots (0, 1) for input items from the side and two slots (2, 3) for output items to the bottom. I'm using an ItemStackHandler for my inventory. private final IItemHandler inv = new ItemStackHandler(4) { @Override protected void onContentsChanged(int slot) { super.onContentsChanged(slot); markDirty(); } }; How would I implement the ITEM_HANDLER_CAPABILITY here? My problem: - A hopper/pipe that is inserting items should only access slots 0,1 and a hopper/pipe that is extracting items should only access slots 2,3 If I'm returning my inv directly, it is returning all 4 slots. Do I need to separate my ItemStackHandler into two inventories like invInput and invOutput or can I still use one ItemStackHandler and return only half of the inventory at the getCapability method?
  5. I know, that's why I'm looking for a solution for 1.10.
  6. I'm currently trying to get an item by its registry name and return all subtypes which are registered for said item as ItemStacks. Example: I use Item.getByNameOrId("minecraft:log") to get an instance of minecrafts log item. Now I want to get all registered subtypes as ItemStacks and store them in a list. The output would be: [1xtile.log@0, 1xtile.log@1, 1xtile.log@2, 1xtile.log@3] (Oak Wood, Spruce Wood, Birch Wood, Jungle Wood) Getting the subtypes is kind of a problem. I tried to use the item#getSubItems function which works fine, but the function is marked as client-only for Minecraft versions 1.7 to 1.11 which means it would crash the server. Test code (Works client-side but not server-side): public static void printSubtypes(String regname) { Item item = Item.getByNameOrId(regname); if (item != null) { List<ItemStack> subtypes = new ArrayList<ItemStack>(); item.getSubItems(item, null, subtypes); System.out.println(subtypes); } else { System.out.println("Item does not exist: " + regname); } } Is there any other easy workaround? Thanks.
  7. So I basically just need to create a new NBTTagCompound, get the data from a stack and use StreamTools to write it to the FileOutputStream, right? I used the following code to save a single stack to disc (Currently test.dat in the root directory). Anything wrong with it? public static void saveStackToFile(ItemStack stack) { if (stack != null) { NBTTagCompound nbt = new NBTTagCompound(); stack.writeToNBT(nbt); String file = "test.dat"; try { FileOutputStream fileoutputstream = new FileOutputStream(file); CompressedStreamTools.writeCompressed(nbt, fileoutputstream); fileoutputstream.close(); } catch (Exception exception) { exception.printStackTrace(); } } } Output (Added some custom NBTTag data for testing purposes): If I want to load the stack I just have to get the file by CompressedStreamTools#readCompressed and create the stack with ItemStack#loadItemStackFromNBT, correct?
  8. Try to update chisel and see if it works.
  9. Hey. I'm trying to save a set of data to a file (client-side only). The set consists of Strings, Integers and ItemStacks. I used a JSON file at first, but I need a good way to save the NBT data of each ItemStack as well which doesn't seem to be a good way if I use JSON files(?). So I'm looking for a good way to store such data. My first consideration was to use a .dat file, but I have no experience with them and don't know if that is the best choice here. The data should be able to be saved at any time, not just after loading/exiting the world/server. For example, the player should be able to type in "/savedata" or "/loaddata" into the chat and the file gets saved/loaded instantly. The file will be saved on client-side only. It's basically like a global config file which should be the same on any server the client is on. So I looked around and found the WorldSavedData class which seems to handle dat files(?), but I'm not sure if that's the right one and if you can save those at any time. Thank you for your time.
×
×
  • Create New...

Important Information

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