Posted September 1, 20196 yr I am trying to have an item, when right clicked on an entity, spawn my custom entity. Problem is, I need to pass the UUID of the player and the type of entity clicked for rendering/AI. What I tried: MyEntity entity = new MyEntity(); entity.setType(type) entity.setOwner(owner) entity.setPosition(position) world.addEntity(entity) Problem is, that entity is replaced with another one server-side which has no data. Next I tried: CompoundNBT nbt = new CompoundNBT(); nbt.putInt("type", type.ordinal()); nbt.putUniqueId("owner", player.getGameProfile().getId()); if (tameable != null) nbt.putBoolean("sitting", tameable.isSitting()); ITextComponent name = null; if (target.getCustomName() != null) name = target.getCustomName(); PetEntity pet = EntityRegistry.PETENTITY.spawn(target.getEntityWorld(), nbt, null, player, target.getPosition(), SpawnReason.EVENT, false, false); target.remove(); target.getEntityWorld().addEntity(pet); Then I read the NBT data by overriding AnimalEntity#readAdditional(NBTCompound), but that is never called. Edited September 3, 20196 yr by Big_Bad_E
September 1, 20196 yr 1 minute ago, Big_Bad_E said: Problem is, that entity is replaced with another one server-side which has no data. Spawn entities only on the server. 2 minutes ago, Big_Bad_E said: What I tried: We need more than just that snippet of code. Where is it being called from? VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
September 1, 20196 yr Author 1 minute ago, Animefan8888 said: Spawn entities only on the server. We need more than just that snippet of code. Where is it being called from? It is being called on the server, I use if(!world.isRemote) The entity is being spawned from Item#hitEntity(ItemStack, LivingEntity, LivingEntity). https://github.com/BigBadE/BattlePets/blob/master/src/main/java/bigbade/battlepets/items/ConverterItem.java (Just remembered GitHub exists).
September 1, 20196 yr 43 minutes ago, Big_Bad_E said: AnimalEntity#readAdditional(NBTCompound), but that is never called. Because you never told it to get called btw. Are you sure that what you tried the first time didn't work? How did you test it? VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
September 1, 20196 yr Author 1 minute ago, Animefan8888 said: Because you never told it to get called btw. Are you sure that what you tried the first time didn't work? How did you test it? You're right, it turns out I forgot to check the side with the first method, cause all the values were set to the default fail safe values.
September 1, 20196 yr Author Nevermind, it seems that somehow two instances are being created, one on Client one on Server. problem is the Client one doesn't have the data the Server one does. The only solution I can think of is somehow canceling the spawn of the client one, sending a packet over with all the data, and spawning it client side with that. IDK if that works though, or if there is an easier solution. I'm pretty sure the entity is summoned client side on this line: net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.EntityEvent.EntityConstructing(this)); I know the client side entity is spawned with AnimalEntity#init
September 1, 20196 yr 4 minutes ago, Big_Bad_E said: problem is the Client one doesn't have the data the Server one does. Sync it with a packet or the DataManager that entities use. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
September 1, 20196 yr Author Just now, Animefan8888 said: Sync it with a packet or the DataManager that entities use. THATS WHAT DATAMANAGER DOES! Ohh... I'm so stupid. Thanks for telling me that.
September 2, 20196 yr Author Okay, so I started using DataManager. Problem is, when the server registers the datamanager values, the datamanagers values aren't sync'd to the client, so the client tries to get values from default datamanagers values (Do I register them client side?) instead of the correct ones set. I tried setting every datamanager to dirty but that changed nothing. I tried to use the Packet SEntityMetadataPacket, but got this error: Spoiler java.lang.IllegalArgumentException: Invalid message net.minecraft.network.play.server.SEntityMetadataPacket at net.minecraftforge.fml.network.simple.IndexedMessageCodec.build(IndexedMessageCodec.java:131) ~[forge-1.14.2-26.0.62_mapped_snapshot_20190621-1.14.2-recomp.jar:?] {} at net.minecraftforge.fml.network.simple.SimpleChannel.encodeMessage(SimpleChannel.java:68) ~[forge-1.14.2-26.0.62_mapped_snapshot_20190621-1.14.2-recomp.jar:?] {} at net.minecraftforge.fml.network.simple.SimpleChannel.toBuffer(SimpleChannel.java:76) ~[forge-1.14.2-26.0.62_mapped_snapshot_20190621-1.14.2-recomp.jar:?] {} at net.minecraftforge.fml.network.simple.SimpleChannel.toVanillaPacket(SimpleChannel.java:107) ~[forge-1.14.2-26.0.62_mapped_snapshot_20190621-1.14.2-recomp.jar:?] {} at net.minecraftforge.fml.network.simple.SimpleChannel.send(SimpleChannel.java:102) ~[forge-1.14.2-26.0.62_mapped_snapshot_20190621-1.14.2-recomp.jar:?] {} at bigbade.battlepets.entities.PetEntity.<init>(PetEntity.java:93) ~[main/:?] {} at bigbade.battlepets.items.ConverterItem.convertPet(ConverterItem.java:148) ~[main/:?] {} at bigbade.battlepets.items.ConverterItem.hitEntity(ConverterItem.java:55) ~[main/:?] {} at bigbade.battlepets.listeners.HitProtector.onAttack(HitProtector.java:23) ~[main/:?] {} at net.minecraftforge.eventbus.ASMEventHandler_0_HitProtector_onAttack_AttackEntityEvent.invoke(.dynamic) ~[?:?] {} at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:80) ~[eventbus-0.10.1-service.jar:?] {} at net.minecraftforge.eventbus.EventBus.post(EventBus.java:258) ~[eventbus-0.10.1-service.jar:?] {} at net.minecraftforge.common.ForgeHooks.onPlayerAttackTarget(ForgeHooks.java:722) ~[?:?] {} at net.minecraft.entity.player.PlayerEntity.attackTargetEntityWithCurrentItem(PlayerEntity.java:1060) ~[?:?] {pl:accesstransformer:B} at net.minecraft.entity.player.ServerPlayerEntity.attackTargetEntityWithCurrentItem(ServerPlayerEntity.java:1324) ~[?:?] {pl:accesstransformer:B} at net.minecraft.network.play.ServerPlayNetHandler.processUseEntity(ServerPlayNetHandler.java:1145) ~[?:?] {} at net.minecraft.network.play.client.CUseEntityPacket.processPacket(CUseEntityPacket.java:82) ~[?:?] {} at net.minecraft.network.play.client.CUseEntityPacket.processPacket(CUseEntityPacket.java:15) ~[?:?] {} at net.minecraft.network.PacketThreadUtil.lambda$checkThreadAndEnqueue$0(PacketThreadUtil.java:14) ~[?:?] {} at net.minecraft.util.concurrent.TickDelayedTask.run(TickDelayedTask.java:20) ~[?:?] {} at net.minecraft.util.concurrent.ThreadTaskExecutor.run(ThreadTaskExecutor.java:131) [?:?] {pl:accesstransformer:B} at net.minecraft.util.concurrent.RecursiveEventLoop.run(RecursiveEventLoop.java:22) [?:?] {} at net.minecraft.util.concurrent.ThreadTaskExecutor.driveOne(ThreadTaskExecutor.java:106) [?:?] {pl:accesstransformer:B} at net.minecraft.server.MinecraftServer.func_213205_aW(MinecraftServer.java:708) [?:?] {pl:accesstransformer:B} at net.minecraft.server.MinecraftServer.driveOne(MinecraftServer.java:702) [?:?] {pl:accesstransformer:B} at net.minecraft.util.concurrent.ThreadTaskExecutor.drainTasks(ThreadTaskExecutor.java:93) [?:?] {pl:accesstransformer:B} at net.minecraft.server.MinecraftServer.runScheduledTasks(MinecraftServer.java:687) [?:?] {pl:accesstransformer:B} at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:635) [?:?] {pl:accesstransformer:B} at java.lang.Thread.run(Thread.java:748) [?:1.8.0_201] {} Edited September 2, 20196 yr by Big_Bad_E
September 2, 20196 yr 4 minutes ago, Big_Bad_E said: Okay, so I started using DataManager. Dont register them in your constructor, do it in the registerData method. 8 minutes ago, Big_Bad_E said: Do I register them client side? Yes of course the entity needs to know that those values exist. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
September 2, 20196 yr Author 1 hour ago, Animefan8888 said: Dont register them in your constructor, do it in the registerData method. Yes of course the entity needs to know that those values exist. Thanks for telling me about registerData, that fixed all my problems!
September 3, 20196 yr Author Nevermind, data still isn't sync'd. I set the collar color on the server, but the collar color is never sync'd to the client. GitHub: https://github.com/BigBadE/BattlePets How I register the collar color to the datamanager: @Override public void registerData() { super.registerData(); collar = EntityDataManager.createKey(PetEntity.class, DataSerializers.VARINT) dataManager.register(collar, DyeColor.RED.getId()); } I then set it to a different color in the interact (server-side) (I change it to 3) and confirm that it is set server-side (it is), but in my entity renderer (client side) it is still set to red (14). The same thing happens with all other data sent over.
September 3, 20196 yr Author 11 hours ago, diesieben07 said: That's not how you use teh data manager. createKey must be called once, vanilla uses a static initializer for this, you should do the same. Pretty much look at how vanilla uses it. That was it, I didn't realize datamanager was called multiple times. Thanks for that, now it is all working.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.