Jump to content

GsE-26

Members
  • Posts

    6
  • Joined

  • Last visited

  • Days Won

    1

GsE-26 last won the day on April 1

GsE-26 had the most liked content!

GsE-26's Achievements

Tree Puncher

Tree Puncher (2/8)

2

Reputation

  1. Something still goes wrong. I've changed my code: added new field Variant, which also is set randomly in constructor. Here are my write/readSpawnData: @Override public void writeSpawnData(FriendlyByteBuf friendlyByteBuf) { System.out.print("WRITING"); friendlyByteBuf.writeEnum(this.getVariant()); } @Override public void readSpawnData(FriendlyByteBuf friendlyByteBuf) { System.out.print("READING"); friendlyByteBuf.readEnum(MyEntityType.class); } But in my log WRITING or READING never appears. So when these methods should be called?
  2. Thank you! So I mustn't to use EntityData to store the variant? Also, when implementing IEntityAdditionalSpawnData I must override two additional methods (write/readSpawnData). Should I write and read my string in two places (write/readSpawnData and read/addAdditionalSaveData)?
  3. Hello! I was trying to create a mob which has two different textures: "red" and "black". It should be chosen randomly when the mob spawns and then never change. I had to find some way to save data about the variant of the mob when player go out from the game. I thought that using read/addAdditionalSaveData can help, but nothing has changed, it still doesn't remember what color each mob had. Did I something wrong? Here are methods in MyEntity class, related to the problem: private final static EntityDataAccessor<String> DATA_VARIANT_NAME = SynchedEntityData.defineId(MyEntity.class, EntityDataSerializers.STRING); //Entity variant is set in constructor public MyEntity(EntityType<? extends Animal> pEntityType, Level pLevel) { super(pEntityType, pLevel); setMyEntityVariant(RandomMyEntityVariant()); } @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(DATA_VARIANT_NAME, RandomMyEntityVariant().getSerializedName()); } public static enum MyEntityVariant implements StringRepresentable{ RED("red"), BLACK("black"); private final String name; private MyEntityVariant(String name){ this.name = name; } @Override public String getSerializedName() { return name; } public static MyEntityVariant byName(String pName) { if (Objects.equals(pName, "black")){ return BLACK; } else return RED; } } private MyEntityVariant RandomMyEntityVariant(){ switch (this.random.nextIntBetweenInclusive(1,2)){ case 1: return MyEntityVariant.BLACK; default: return MyEntityVariant.RED; } } public MyEntityVariant getMyEntityVariant(){ return MyEntityVariant.byName(this.entityData.get(DATA_VARIANT_NAME)); } public void setMyEntityVariant(MyEntityVariant variant){ this.entityData.set(DATA_VARIANT_NAME,variant.getSerializedName()); } @Override public void addAdditionalSaveData(CompoundTag pCompound) { super.addAdditionalSaveData(pCompound); pCompound.putString("MyEntityVariant",this.getVariant().getSerializedName()); } @Override public void readAdditionalSaveData(CompoundTag pCompound) { super.readAdditionalSaveData(pCompound); this.setMyEntityVariant(MyEntityVariant.byName(pCompound.getString("MyEntityVariant"))); } Maybe, I should call SetMyEntityVariant somewhere in another place?
  4. Hello! I need to check is it night for some featues of my new mob. I planned to use the MyMob.level.isNight() method, but it seems to work kinda odd for some reason. So I'd wrote down a function in MyMob.tick() which prints value returned by level.isNight(): The result was: "True" and "False" values is alternating while it is obviously night in the world. So, what does the method actually return?..
  5. Thank you very much! If it is kinda weird that I answered so lately... Ok, here is the story. When I'd got this problem I was really frustrated so I gave up and dropped to learn mod developing. Now I decided to return to the problem, searched the interned, found this thread "oh, this guy has exactly the same problem, wow". My face when I've realised that the topicstarter is me is just incredible. Upd. And yes, it helped! Thank you very much again!
  6. Hello! I've made a block, it is displaying with a black texture, but I haven't found anything wrong in the mod files. Here is my files: link to the texture: https://i.ibb.co/ck4nJ8L/tea.png
×
×
  • Create New...

Important Information

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