Jump to content
Search In
  • More options...
Find results that contain...
Find results in...


  • Posts

  • Joined

  • Last visited

  • Days Won


Posts posted by Alpvax

  1. In the "tick" method , you need to set the y component of the deltaMovement to be positive (to rise) or negative (to fall). The exact value that you use will determine how fast.

    //FallingBlockEntity uses the following values (when gravity is not disabled)
    //by adding the velocity, it allows the entity to have smooth movement and allows directions other than straight down
    this.setDeltaMovement(this.getDeltaMovement().add(0.0D, -0.04D, 0.0D));

    Looking at the tick method of the FallingBlockEntity class it may give you a better idea of how it works.

  2. I would do it by creating a subclass of FallingBlock (if it is still called that) and adding a targetHeight field, then making the block "fall" or "rise" to meet that height, before turning into the specified block. That way most of the code should be reusable from the parent class.

    You will have to register it as a new EntityType.

    Then when your block rises, you create a new instance of your entity, with the targetHeight one block higher than the current y position.

  3. You must have a licence to drive a car. "Must is a strong word, the car runs without it".

    Just because it works doesn't mean that it won't cause you problems down the line. And if you do it correctly from the start, you won't have to spend the time finding and fixing bugs later on.

  4. On 10/15/2021 at 3:55 PM, jayxo said:
    public class StatsManager extends WorldSavedData implements Supplier

    Why are you implementing Supplier? (Also, you should include the generic type of Supplier).

    You probably want to add a getter for a specific player. something like the following:

    public DefaultStatsCapability getStats(UUID playerID) {
        // Bear in mind this can return null if the player stats have not been added yet.
        // You might want to use computeIfAbsent instead.
        return players.get(playerID);

    Then wherever you need the DefaultStatsCapability (for example in your book update function), get your instance of StatsManager, then get the DSC from it using the new getter.

    On 10/15/2021 at 3:55 PM, jayxo said:
    public PlayerEntity player = Minecraft.getInstance().player;

    A) This will crash on servers (which is where loading and saving of data occurs)

    B) What is this for? All the players should be saved in the map.

  5. 18 minutes ago, jayxo said:

    it stores the players uuid if that would work?

    Yes, I think that is linked to the player's GameProfile, so should never change.

    13 minutes ago, jayxo said:

    in response to the level/world capability, how would i actually do that? im not sure if it’s useful, also eventually wanted to be able to use a command to get a players book even if they’re offline.

    The same way you attach the capability to the player, but just attach a capability with a Map<player id, your current player capability data> to the overworld Level instead of attaching the data to the player directly. Then when you want to modify the data, get the capability from the overworld (which is always loaded) and get the data for the player with the given id.

    Alternatively, you could use Saved Data (which used to be WorldSavedData), again using the overworld to access the player data.

    That way it doesn't matter if the player is offline, because the data is saved to the overworld, so you just need to look up the data for the player by player id.

    • Thanks 1
  6. What do you mean? that you want the player to be able to have creative  style flying when you activate an item? Or more like how fireworks work with elytra?

    You need to override Item#useOn (for using on a block) or Item#use (for using the item on air (and possibly blocks with no right click action, I can't really remember)).

    For the first approach, you need to set Player#getAbilities().mayfly to true (mojmap mappings). Remember to set it back to false when you want to stop.

    For the second approach, you need to get the current Player#getDeltaMovement(), add a vec3 to it (either just a y component for straight up, or based on the Player#getViewVector() for "forwards")

  7. On 10/11/2021 at 4:21 PM, jayxo said:

    it would always show the player who opened it info.


    I assumed that was what you wanted. Currently you get the capability of the player opening the book:

    public void onUse(PlayerInteractEvent.RightClickItem event) {
        PlayerEntity player = event.getPlayer();

    You need to use the player who "owns" the book instead. So store the "owner's" id in the book somehow (NBT/capablility), then when the book is opened, get the player from the id (they may not exist/be offline, in which case you can't reasonably update), then update the data.

    It might be a better idea to change to a level (overworld) capability / saveddata if you need to access the data for offline players, then retrieve that data for displaying in your book.

    As die7 says, it will probably be better to create a custom gui (based on the vanilla book screen, you can possibly subclass it, although I'm not sure), then retrieve the latest data on demand, rather than updating the item nbt each time.

  8. 7 minutes ago, zlappedx3 said:

    Should I make StatusProvider an instance?

    What? You use StatusProvider exactly the same way you did before (attaching it in the AttachCapabilitiesEvent). The only thing you change is in your StatusProvider, you move the old code from your CapabilityRegistry.register(cap_class, storage, default_factory) and put the code from the storage class inside your StatusProvider save/load methods, and the code from your default_factory inside your LazyOptional.

    Literally just getting rid of the stuff that no longer exists and calling it directly, instead of through the capability.

  9. You don't create an instance of the `Capability` class, that is still handled behind the scenes (and the `@CapabilityInject` annotation still works as before).

    Where you called `Capability#getDefaultInstance()` before, just create your new instance (of your Capability type, i.e. `new Status()`).

    Where you called your Storage class methods (from your Capability Provider), just move your saving/loading stuff directly into those methods of your `StatusProvider`.

  10. I'm assuming that it is just a vanilla book with custom NBT, not your own custom item?

    If that is the case you could listen to the use item event (sorry, I can't remember the name of it off the top of my head), check for the book being used (opened) and sync the data with the item.

  11. On 9/17/2021 at 11:41 PM, FireTamer81 said:

    While chugging along making the JSONs by hand (to get an idea of how they need to be generated for each type of block), I cam up with a possibly brilliant idea.

    Could I somehow make template JSONs and when a new block of a certain type is being generated it will just pull the template and replace certain keywords like "NAME" and "COLOR" instead of all of this getVariantBuilder stuff

    Make a method which has the parameters that change (name, colour etc.) and perform the datagen logic inside that method. You can even have a method which generates each of the blocks (regular cube, wall, stairs etc.) for a single name.

    Unfortunately I don't have a good example of datagen as the mod I am working on using it for uses either simple cubes or a custom model loader. When I was learning how to use the datagen I spent a lot of time looking through the source and IIRC Tropicraft was my starting point, although I cannot remember what that was like. 

  12. The book is still rendered in a BlockEntityRenderer, not a json model. That means that the only thing you can change is the texture, which you can find in the minecraft.jar file at the path "assets/minecraft/textures/entity/enchanting_table_book.png" (use any program that handles .zip files to open the jar and extract the texture).

  13. You could look into how commands handle finding and filtering entities, and either use the same method, or call the required methods.

    The class which handles it is net.minecraft.command.arguments.EntitySelector

  14. On 7/16/2021 at 3:00 PM, Anrza said:


    Thanks for your answers!

    For the record, I'm not listening for any sleep events. Since AFAIK it's not fired if time is set by a command, I'm using a more general approach.


    Thanks for your reply! I am indeed looking to use an offset variable. It's a good point that I shouldn't have to store any other time variable, and I'll look into that.

    The `dayTime` value is set by the command, so you could listen for the command event, check the daytime before, subtract it from the daytime after (wait 1 tick to get the "after" time) and add that difference to your offset if you wanted. It depends how accurate you want to be.

    Alternatively, when your offset changes, you could check the difference between `gameTime` and `dayTime` (you would then have to track a second offset to check when it changes, but it might give you a bit more accuracy).


    On 7/15/2021 at 3:26 PM, Alpvax said:

    offset between gametime and your gametime + sleeptime

    I meant that you should just save the offset, as poopoodice suggested

  15. 1,2: It depends exactly what you are after. I would recommend using WorldTickEvent, and saving the time in a capability attached to the world. If you want to track each dimension independently, use the specific world#getGameTime, otherwise just use the overworld (using specific worlds the time will only increment when the world is loaded).

    1&2: I would suggest listening to ServerTickEvent (with Phase END), and keeping the data attached to a capability attached to the Overworld. you can get the time using overworld#getGameTime. To keep track of time sleeping, subscribe to SleepFinishedTimeEvent (at EventPriority.LOWEST to run after all other listeners) and add the time difference.

    3: packets, it depends what you need on the client. If it is just for rendering in a GUI, you could use a containerscreen to sync it, otherwise I believe you will need packets (sent whenever the offset between gametime and your gametime + sleeptime changes.

    4: Yes, but the sleep event is only fired on the server, so you will have to manually sync your offset.

    5: Yes, all worlds other than the Overworld use a DerivedWorldInfo, which just passes both times through from the overworld info. (I didn't realise this until I just looked).

  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.