Jump to content

Alpvax

Members
  • Posts

    297
  • Joined

  • Last visited

  • Days Won

    3

Posts posted by Alpvax

  1. On 2/19/2023 at 5:14 PM, Jontom Xire said:
    Attempted to load class net/minecraft/client/player/LocalPlayer for invalid dist DEDICATED_SERVER

    Classes in the client package don't exist on the server.

    On 2/19/2023 at 5:56 PM, Jontom Xire said:

    public static void handler(SyncMsg msg, Supplier<NetworkEvent.Context> ctx)
        {
            ctx.get().enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> safe_handler(msg)));
            ctx.get().setPacketHandled(true);
        }

        public static void safe_handler(SyncMsg msg)
        {
            Player      player = (Player)(Minecraft.getInstance().player);
            PlayerData  data   = PlayerData.get(player);

            ...

    Are those methods in the same class? Any code that interacts with client only code should be in a seperate class.

    Minecraft#player is an instance of LocalPlayer, so the game tries to load that class in order to cast it.

    Please provide a complete stacktrace and git repo.

  2. Only register the event handler one way, not both.

    IntelliJ thinks the functions aren't called because the code that calls them is not normal code. You can safely ignore the warnings, as long as the methods are being called in-game (which you could check by setting a breakpoint and running debug).

  3. C is a generic parameter. You need to pass in an instance of C, which will be a subclass of Container which supports the RecipeType.

    With the Generic parameters `<C extends Container, T extends Recipe<C>>`: if you look at the type of RecipeType.CRAFTING, you find it is a RecipeType<CraftingRecipe>, meaning the generic T is `CraftingRecipe`, which extends Recipe<CraftingContainer>, so your C type is CraftingContainer. So you need to provide an instance of CraftingContainer to match the items and get an output.

  4. You should be using events, there is an event for "Player right clicked with an item" (PlayerUseEvent or InteractEvent or something along those lines), and an event to add text to existing item tooltips, although I can't remember what the events actually are off the top of my head.

    In your event handler, you need to check that the item is a stick, then perform your logic. It means that you don't have to replace the vanilla stick.

    • Like 1
    • Thanks 1
  5. @BogieninYou almost definitely shouldn't be setting the base value, that pretty much completely negates the point of the attribute system. You should add attribute modifiers to the entity instead.

     

    @FantaLaToneI think you should be able to just add multiple attribute modifiers to the effect, although I haven't actually done it before. If not you can override the methods in the effect class to add/remove the modifiers (by UUID) when the effect is added/removed from an entity.

  6. There isn't one, you have to loop through all the (shapeless) recipes and check them yourself (i.e. check that there is a single ingredient and it is in the logs tag (and probably also check the output is something sensible, as I mentioned before)).

    Alternatively, you might be able to look up the recipes manually by looping through the items in the logs tag, converting them to a single ingredient, then looking up the recipe for that single ingredient. I haven't ever tried, so I don't know how that would work, but it is probably more efficient.

  7. There is no "Exact code".

    You need to loop through the list of logs (that you got from the tag), and then compare those blocks with recipes which you can find from the recipemanager.

    Minecraft doesn't make any links between logs and planks other than the recipes. There is no good way to do what you want, because there is no way to define "Block Y is a plank version of log X". Just "If you craft log X by itself, you get block Y". If someone adds a recipe for a single log to a diamond block, does that make a diamond block a plank?

  8. 14 hours ago, LeeCrafts said:
    Field field = Entity.class.getDeclaredField("dimensions");
                field.setAccessible(true);

    You should save this somewhere static, instead of computing it every time.

    15 hours ago, LeeCrafts said:

    I tried manually firing EntityEvent.Size on my overridden removeAttributeModifiers(), but to no avail.

    That's not how forge events work. The event doesn't fire to set the size, it fires when the size is changed to allow mods to override it. It is called from the (mojmap) method `Entity#refreshDimensions`, so if you call that method you should restore the entity size. Alternatively, if you don't want to allow other mods to react to the change in size, just recompute the AABB as vanilla does (either setPos, or setBoundingBox(makeBoundingBox())), but I would strongly suggest using the first method.

    • Thanks 1
  9. 7 hours ago, Koolade446 said:

    the issue with this is if a player gets on a saw and player.tickCount % 20 is 14 the player could have 19 ticks or almost a whole second to get off the saw before a tick of damage would be delt so if they like ran across it they may not take damage.

    There are 2 approaches to fix that: either increase the frequency and reduce the damage (e.g. % 10 do 0.75 damage) so that they have less chance to escape (but don't die instantly).

    Alternatively, perform the check every tick, but save whether or not the player was on the blade the previous tick, and if not, start damaging once/sec. This approach requires you to save the tick that the player stepped on the blade however (and check that `(current tick - start tick) % 20 = 0`) as well as whether or not the player was previously on the blade. I would suggest using capabilities (or at the minimum an NBT tag containing your modid) for this approach

  10. Unfortunately I haven't actually looked at particles before, so can't be much help.

    However, if you look at the source of the constructor you are using you can see that it divides the velocity by the magnitude of the velocity (plus some other maths) so the particles won't move very far/fast.

    I would suggest experimenting with the `setParticleSpeed` method, which just sets the raw values.

×
×
  • Create New...

Important Information

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