Jump to content

kiou.23

Members
  • Posts

    444
  • Joined

  • Last visited

  • Days Won

    5

Posts posted by kiou.23

  1. I'm pretty sure that you could override the Container#slotClick method, it handles what happens when, well, you click on a slot... the logic for it is quite obfuscated and confusing however... so there may be a better way to do it

    EDIT: If I'm not mistaken, the code between lines 290 and 342 of the Container class are the ones which handles when the player is holding an ItemStack, and clicks on a slot of the container

  2. I encourage you to look at the code for the BlockStateProvider class and the simpleBlock method, see the helper functions and what they call internally

     

    simpleBlock simply defines a model for a Block regardless of blockstate.

    so if it is a grass block that you want to make: it doesn't have a block state, you use the simpleBlock method

     

    if you only give the simpleBlock one parameter, a block, it generates a model with all faces with the same texture

    if that's not what you want tho, you can pass a custom model as the second parameter

    you can call models() to get the default BlockModelProvider, it has a bunch of methods for the common model files

    the one that you want is the BlockModelProvider#cubeBottomTop()

  3. [main/FATAL] [ne.mi.fo.la.MavenVersionAdapter/]: Failed to parse version spec [1.16.5)
    org.apache.maven.artifact.versioning.InvalidVersionSpecificationException: Single version must be surrounded by []: [1.16.5)

    This is the line telling you the error, [1.16.5) is not a valid version range

     

    Look at section 7.3 on the documentation: https://docs.oracle.com/middleware/1212/core/MAVEN/maven_version.htm#MAVEN402

    it tells you how to write a semantically valid version range

  4. 3 hours ago, [email protected] said:

    I cant figure out how to calll it in this case as it is inside of createHandler()

    and why are you initializing the ItemStackHandler in a method?

    that would make it so every call to get the handler would return a new handler, instead of the same handler

     

    you don't need to override insertItem and extractItem, just call them from the your block method... get the TE at the blockpos, from there it's simple

     

    as Die said, please learn Java and OOP

  5. 23 minutes ago, [email protected] said:

    ive done that atm but it only works with hoppers idk what in that adds the item to the inventory tho

    hoppers use the capability, so they are getting the ItemStackHandler you are returning in getCapability

     

    24 minutes ago, [email protected] said:

    What is the method or line of code that adds the item to an "inventory" 

    to add an item to the ItemStackHandler you can use ItemStackHandler#setStackInSlot, or ItemStackHandler#insertItem

    to get something you can use ItemStackHandler#extractItem

     

    plus, I don't think you need to lazily load the ItemStackHandler

  6. 3 minutes ago, jonathanpecany said:

    Alright, thanks. I will do that. Still probably going to be a pain though

    it's not that bad, modding felt impossible when I started too, but the modularity that it has makes it much easier to handle

     

    3 minutes ago, jonathanpecany said:

    Can I add my own custom comments to the source, I really hope so. But I think I can do it.

    nope, those classes are read-only, you can add comments to your own code tho

    plus lots of the methods have javadocs too

  7. 16 minutes ago, jonathanpecany said:

    Really? That is way to much, to do that would take months. There has to be an easier way that doesn't make someone discourage.

    you don't need to read ALL the code, just the parts that concern your needs

     

    plus the forge docs has information on all the fundamentals that you need, such as registries, events, capabilities...

    from there you kind of have to figure things out for yourself... by reading the minecraft source code, or other mods source codes

    there are a lot of example mods out there aimed at helping begginers

    this is one that helped me a lot: https://github.com/TheGreyGhost/MinecraftByExample

     

    and if you can't figure out how to do something, you can always ask for help in the forum or in the discord

  8. 2 minutes ago, [email protected] said:

    So do i make a list for what i have right clicked in then save it using onChunkUnload? then i retrive it with the read and write methods. I it smth like that??

    it depends on how you want this chest to work.

    don't worry too much about the read, write, and onChunkUnload methods, they do not concern your block or TE logic.

    the preferred interface to store Items is an IItemHandler, with the default implementation of the ItemStackHandler

     

    but if the amount is arbitrary, and it may only hold one type of item, you could store an Item reference, and an integer that tells the amount of the item in the TE. you'd have to think about when the ItemStack has nbt tho...

  9. 7 minutes ago, EWM said:

    How do I access it though? MainWindow.getHeight() doesn't work/exist

    these methods aren't static, you need to call them on an instance, the Minecraft instance has an instance of MainWindow

    edit: actually, the RenderGameOverlayEvent also has the MainWindow

     

    7 minutes ago, EWM said:

    I'm quite new to modding in minecraft.

    if you're also quite new to programming, you may want to take some time learn some Object Oriented Programming concepts

  10. 1 hour ago, [email protected] said:

    under write and read method how do i make it store up to 9 items?

    the read and write methods are use for nbt serialization, so that the game can save the data when the player closes the game.

    the write method has a CompoundNBT as a parameter, you can write to it using CompoundNBT#put.

    create a static final String in your TE class, to be the "key" of the data you want to keep, something like "inventory" (this will be the tag for referencing the inventory in NBT)

    then you can call put, give it this tag, and then give it the inventory. you can use ItemStackHandler#serializeNBT to get an nbt object, that you can put in the tag

     

    in the read method, you get the nbt that you saved in the write method. call nbt.getCompound(), to get an nbt object that you saved, using the string you saved it at.

    then use ItemStackHandler#deserializeNBT, to recover the data from the nbt into the TE data.

     

    this may sound a bit complex, so here's an example:

        private static final String INVENTORY_TAG = "inventory";
        private static final String CHARGE_TIME_LEFT_TAG = "chargeTimeLeft";
        private static final String CHARGE_TAG = "charge";
        private static final String MAX_CHARGE_TAG = "maxCharge";
        private static final String CHARGING_TAG = "charging";
    
        @Override
        public CompoundNBT write(CompoundNBT nbt) {
            super.write(nbt);
    
            nbt.put(INVENTORY_TAG, this.inventory.serializeNBT());
            nbt.putShort(CHARGE_TIME_LEFT_TAG, this.chargeTimeLeft);
            nbt.putShort(CHARGE_TAG, this.charge);
            nbt.putShort(MAX_CHARGE_TAG, this.maxCharge);
            nbt.putBoolean(CHARGING_TAG, this.charging);
    
            return nbt;
        }
    
        @Override
        public void read(BlockState state, CompoundNBT nbt) {
            super.read(state, nbt);
    
            this.inventory.deserializeNBT(nbt.getCompound(INVENTORY_TAG));
            this.chargeTimeLeft = nbt.getShort(CHARGE_TIME_LEFT_TAG);
            this.charge = nbt.getShort(CHARGE_TAG);
            this.maxCharge = nbt.getShort(MAX_CHARGE_TAG);
            this.charging = nbt.getBoolean(CHARGING_TAG);
        }

     

  11. 1 minute ago, Zemelua said:

    Although it is not the purpose, I tried to use the mcmeta file instead of modelJSON by referring to ConnectedTexturesMod to organize the code, but even if I go back to Loader etc., it seems that I am using modelJSON only. Don't know where the code you're reading from mcmeta is ...?

    https://github.com/Chisel-Team/ConnectedTexturesMod

    I'm not sure I understood what you mean by this... could you elaborate?

  12. getQuads receive an IModelData parameter, which is the return value in getModelData.

    getModelData has the world, blockstate, and blockpos

    you can override it and return the data you need through a ModelDataMap.

     

    I'm not sure, however, if you need to store those values in either blockstate or a tile entity. since they're only relevant to the client, and you can calculate them on getModelData (for optimization you could cache the data in the BakedModel, and have a boolean blockstate in the block which tells wether or not you need to update the cached value)

     

    EDIT: I just realized that this topic is for 1.15, not 1.16. I'm not sure if the interfaces are the same... but I don't think they should be much different (my bad)

  13. You'll want to register a tile entity, in it you can have a field for the inventory, by instantiating an ItemStackHandler

    you'll want to bind it to a block, by overriding hasTileEntity (to return true) and createTileEntity (to call create on the instance of the tile entity that you registered)

    to open the gui when the player right clicks you'll need to call NetworkHooks.openGui, and pass an INamedContainerProvider, which you can implement in the tile entity (for the container provider you'll just need to make createMenu to return a new instance of a Container)

    so you'll also need to register a container, in it you'll add the slots corresponding to the player inventory, and your tile entity inventory

    and lastly you'll need a containerScreen for the gui

     

    you can see some example here: https://github.com/TheGreyGhost/MinecraftByExample/tree/master/src/main/java/minecraftbyexample/mbe30_inventory_basic

     

×
×
  • Create New...

Important Information

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