#how to make a keepinventory for one player

57 messages ยท Page 1 of 1 (latest)

dense elbow
#

the titles a bit vauge, im currently trying to make it only work if you have a specific item, but my best guess on how im gonna do this is

  • before players death, save their inventory
  • once they respawn, load that inventory back (im pretty sure you can also just turn keepinventory on before the player dies then when they die turn it back off but there is no way that wouldnt cause bugs)
    but i can not find ANY way to save or load the inventory
solid spoke
#

you can probably use the existing keep inventory system
mixin where the keepinventory gamerule is checked, and make it also keep the inventory if the player that died had your item

dense elbow
solid spoke
#
  • find the KEEP_INVENTORY gamerule (double-tap shift to open the 'search everywhere' dialogue in intellij) (I think gamerules are all declared in a GameRules class)
  • then once you've found KEEP_INVENTORY, search for usages (middle click it in intellij)
    find the usage where it's checked and vanilla does vanilla's keep inventory logic
  • once you've found that check, mixin there to make it keep inventory if the player that died had your item

see pinned messages in #mod-dev-mixin to get started with mixins

dense elbow
dense elbow
visual rapids
dense elbow
visual rapids
dense elbow
dense elbow
visual rapids
dense elbow
visual rapids
dense elbow
visual rapids
#

!!learnjava may be helpful to you

sour belfryBOT
#

To start modding Minecraft using Fabric, it's strongly recommended to know Java.
Minecraft, in its codebase, and mods, using Fabric API, use more advanced Java concepts like lambdas, generics and polymorphism.
If you don't know all of these concepts, you may have some difficulties modding.

Here are some online resources that will help learning Java
JetBrains Academy (free online course): https://www.jetbrains.com/academy/
Codecademy (free online course): https://www.codecademy.com/learn/learn-java
University of Helsinki (free online course): https://java-programming.mooc.fi/
Basic Java Tutorials: https://docs.oracle.com/javase/tutorial/
Introduction to Programming using Java by David J. Eck (free online textbook): http://math.hws.edu/javanotes/

After Learning Java
For most mods you will want to make, you will have to use the Spongepowered Mixin Java library.
To learn more about Mixin, you can use the faq/mixin bot tag by typing !!faq/mixin in #bot-posting .

dense elbow
#

but to me too much of it is about variables and the variable names are horrible

visual rapids
#

I may In a few hours though

dense elbow
visual rapids
#

!!llm as a precaution

sour belfryBOT
#

Whilst LLMs (Large Language Models) like ChatGPT and Gemini are impressive tools, **they are not recommended for first-time Fabric mod developers due to their inconsistency and potential for generating inaccurate code. **

LLMs may generate incorrect code that:

  • Targets the wrong Minecraft version, leading to outdated or incompatible features.
  • Uses incorrect mappings, causing errors or unexpected behavior.
  • Is designed for the wrong loader (NeoForge vs. Fabric), resulting in incompatibility.
  • Relies on non-existent Fabric API modules, creating code that references features that don't exist (called LLM hallucinations)

It's crucial to remember that LLMs should be seen as problem-solving aids, not code-generating machines. The output they provide often requires significant modification and understanding of Java before it can be implemented as a functional mod.

Therefore, learning Java is an absolute necessity before attempting to use any LLM-generated code in your mod. Knowing how the generated code works is key to using it effectively and fixing any problems that may arise.

dense elbow
dense elbow
visual rapids
#

It looks like player inventory has a set stack method

dense elbow
#

im also trying to make it check if the players inventory has my item

visual rapids
#

This is probably the point where you need mixin, regardless of how much fapi has done

dense elbow
dense elbow
#

im trying to get this mod finished by today this is not going good

visual rapids
#

it would just be an accessor to allow you to set it

#

!!accessor

sour belfryBOT
#

io/github/mymod/mixin/MyClassAccess

@Mixin(MyClass.class)
public interface MyClassAccess {
  @Invoker void callAccess();
  @Accessor int getMyField();
}

to use it

public class Container {
  public void slapHaykam(MyClass instance) {
     ((MyClassAccess)instance).callAccess();
  }
}
visual rapids
#

!!mixinthis

sour belfryBOT
#

Missing arguments, 0/1 present

visual rapids
#

!!mixinthis PlayerEntity

sour belfryBOT
#

((PlayerEntity) (Object) this)
This can be used to pass in this to a method that requires a PlayerEntity as a parameter.

A @Shadow should be used to access methods and fields of PlayerEntity, but ((PlayerEntity) (Object) this) can be used to get access to public methods and fields and should be used in limitation.

visual rapids
dense elbow
visual rapids
#

create an PlayerInventory mixin to allow you to get and set all the items of a particular player inventory

#

actually, for a beginner, i think the best approach would be to iterate each time and use setStack getStack

#

it looks like the playerinventory class is a large abstraction

visual rapids
#

you can use a for loop

solid spoke
dense elbow
#

i got this to work btw