Jump to content

[1.16.5] Extending the base class of the player and drawing the screen when entering the world or server


idev

Recommended Posts

Hello. Faced such a problem. I don't even know where to start.

I rendered a new screen, when using the item I open it (temporarily). There are two buttons on this screen.

Type one and type two. (this is the essence of the player so to speak), I need to somehow extend the base class of the player to add a new player type with a new change (the choice takes place on the buttons), but since a lot of functionality will be tied to this change, I do not know what to do. For example, in the future I will need to ignore the damage of other players with the same player type.

Maximum simple screen with two buttons. What is the best way for me to expand the base character class in minecraft. It didn’t work with coremod and I think it’s better to somehow do without it if necessary, in extreme cases it’s not essential, but I don’t know how to work with it and I don’t even know how, I think it’s worth reading a lot.

So how do you call this screen with the buttons for choosing the type of player when you enter the world / server? This is a must for everyone who logs into the world or the server.


Thanks a lot in advance for any help and advice

I apologize for my english. If something is not clear, please ask. I am not a native speaker of this language

Edited by idev
Link to comment
Share on other sites

I'm thinking you can use capabilities. create a clas that has what you want, then attach it to the player with a default value that indicates the player hasn't picked a class yet

next you can listen to the EntityJoinWorldEvent, check if the entity is a player and if the value is the default one, if it is send a packet to the client telling them to render this screen, then from the screen you can update the player capability

Link to comment
Share on other sites

8 minutes ago, kiou.23 said:

I'm thinking you can use capabilities. create a clas that has what you want, then attach it to the player with a default value that indicates the player hasn't picked a class yet

next you can listen to the EntityJoinWorldEvent, check if the entity is a player and if the value is the default one, if it is send a packet to the client telling them to render this screen, then from the screen you can update the player capability

Did not quite understand.
You can read a little more about: "then attach it to the player with a default value"

Link to comment
Share on other sites

13 minutes ago, kiou.23 said:

https://mcforge.readthedocs.io/en/latest/datastorage/capabilities/

Возможности - это способ хранения дополнительных данных для определенных объектов, вы можете создать класс, который будет содержать нужные вам данные и поведение, а затем зарегистрировать его в диспетчере возможностей.

Many thanks. I haven't been in mod for long and didn't know about it. I will definitely study

Link to comment
Share on other sites

54 minutes ago, kiou.23 said:

https://mcforge.readthedocs.io/en/latest/datastorage/capabilities/

Capabilities are a way to store additional data to certain objects, you can create a class that holds the data and behaviour that you want, then register it to the capability manager

Alas, the EntityJoinWorldEvent event does not send me EntityPlayer. I think another event is needed here, but I do not know which one.

Link to comment
Share on other sites

1 hour ago, idev said:

Alas, the EntityJoinWorldEvent event does not send me EntityPlayer. I think another event is needed here, but I do not know which one.

there may be a better event, but event should fire when a player joins the world

you just need to check if the entity is a player entity, I'd think

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • my arrow wont move at all it would stay mid air and show no collision   my Entity class: package net.jeezedboi.epicraft.entity.custom; import net.jeezedboi.epicraft.init.ModItems; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.projectile.AbstractArrowEntity; import net.minecraft.item.ItemStack; import net.minecraft.network.IPacket; import net.minecraft.util.math.EntityRayTraceResult; import net.minecraft.world.Explosion; import net.minecraft.world.World; import net.minecraftforge.fml.network.NetworkHooks; public class ExplosiveArrowEntity extends AbstractArrowEntity { // default constructor, required to register the entity public ExplosiveArrowEntity(EntityType<ExplosiveArrowEntity> entityType, World world) { super(entityType, world); } public ExplosiveArrowEntity(EntityType<ExplosiveArrowEntity> entityType, double x, double y, double z, World world) { super(entityType, x, y, z, world); } // the constructor used by the ArrowItem public ExplosiveArrowEntity(EntityType<ExplosiveArrowEntity> entityType, LivingEntity shooter, World world) { super(entityType, shooter, world); } // the item stack to give the player when they walk over your arrow stuck in the ground @Override protected ItemStack getArrowStack() { return new ItemStack(ModItems.EXPLOSIVE_ARROW.get()); } @Override protected void onEntityHit(EntityRayTraceResult result) { super.onEntityHit(result); // this, x, y, z, explosionStrength, setsFires, breakMode (NONE, BREAK, DESTROY) this.world.createExplosion(this, this.getPosX(), this.getPosY(), this.getPosZ(), 4.0f, true, Explosion.Mode.BREAK); } // called each tick while in the ground @Override public void tick() { if (this.timeInGround > 60){ this.world.createExplosion(this, this.getPosX(), this.getPosY(), this.getPosZ(), 4.0f, true, Explosion.Mode.BREAK); this.remove(); } } // syncs to the client @Override public IPacket<?> createSpawnPacket() { return NetworkHooks.getEntitySpawningPacket(this); } } my item class :   package net.jeezedboi.epicraft.item.custom; import net.jeezedboi.epicraft.entity.custom.ExplosiveArrowEntity; import net.jeezedboi.epicraft.init.ModEntityTypes; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.projectile.AbstractArrowEntity; import net.minecraft.item.ArrowItem; import net.minecraft.item.ItemStack; import net.minecraft.world.World; public class ExplosiveArrowItem extends ArrowItem { public ExplosiveArrowItem(Properties props) { super(props); } @Override public AbstractArrowEntity createArrow(World world, ItemStack ammoStack, LivingEntity shooter) { ExplosiveArrowEntity explosiveArrowEntity = new ExplosiveArrowEntity(ModEntityTypes.EXPLOSIVE_ARROW.get(), shooter, world); return explosiveArrowEntity; } } other stuffs: public static final RegistryObject<Item> EXPLOSIVE_ARROW = ITEMS.register("explosive_arrow", () -> new ExplosiveArrowItem(new Item.Properties().group(ModItemGroup.Epic_Items))); public static final RegistryObject<EntityType<ExplosiveArrowEntity>> EXPLOSIVE_ARROW = ENTITY_TYPES.register("explosive_arrow", () -> EntityType.Builder.create((EntityType.IFactory<ExplosiveArrowEntity>) ExplosiveArrowEntity::new, EntityClassification.MISC) .size(0.5F, 0.5F).build("explosive_arrow")); mappings channel: 'snapshot', version: '20210309-1.16.5'
    • may i ask what it was that fixed it, I'm having the same problem and its frustrating because I'm making an origin.
    • I need to accesses byPath field of net.minecraft.client.renderer.texture.TextureManager. As I found out I need to use accesstransformer.cfg file and make the field public via it. In this file field names look like f_<numbers>. And I was unable to figure out, how to get those. It seems like it is connected to something called mappings (thing left after Minecraft decompile process). How can I get such a name for a class field?
    • The game crashed whilst rendering overlay Error: java.lang.OutOfMemoryError: Java heap space Exit Code: -1   Crash Report:                                              Log: https://pastebin.com/9NMLr5bD       https://pastebin.com/av6Q2jCf Password: gpTq3Gvkc5                     qdF0BeJGYN   Any suggestions what should i do here?
  • Topics

×
×
  • Create New...

Important Information

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