Jump to content

Recommended Posts

Posted

 

I got this in mi head

 

 

well not so in mi head alredy much of the code is done

 

i been creating mercenary entityes, you buy their loyalty whith gold

so they help you, follow you and, well at least not kill you 

 

soo i also make a radio item that is sopused (not finish yet) to be used to call the mercenaries, to set target entitys to kill, and to manage the mercernaries equipment

 

well the trouble comes when you close the game, the radio has a Mercenarys List

this entity list i can'not save it as nbt

ad if where posible the entityes are just references dont gonna works when reload the world

 

ArrayList<aldeanoMercenario00> mercenaryList = new ArrayList<aldeanoMercenario00>();

if the radio dont'n have the entitye list the it could not recall my mercenaryes

 

i made an ExtendedPropertieEntityLiving the mercenaryes save the value of "OwnerUUID"

String OwnerUUID = theEntitycompound.getString("OwnerUUID");

 

soo they are still loyal to me

but the radio dont works when reopen minecraft

 

i need a way to save the entityes to the radio item

an was tinking in the pokeball mod from grim3212

this pockeball item is capable of save not only vainilla but also moded entityes

 

i wanna know the idea of how this pockeball works, to see if i can adapt it to mi mercenary radio 

 

some one knows how goes the pockeball code ??

 

thanks for reading

is a little hard to espress complex ideas in english

Posted

e  nop 

the entityes are smart enough to use guns

but dumb to use the radio

 

the radio is an item in the player inventory to manage the mercenaryes

so it must be a list in the radio item of the mercenaries loyal to the player

so it could call and teleport this entities next to the player even those to far or in a unloaded chunck in the world

 

 

Posted

 

hey wait

there is alot of little troubles when i try to do that before.

 

- first of all the entityes continued existence is just an illusion, when you close the game everything dieded and disapear, when you reopen the minecraft it just create new entityes whith the data stored but this entityes has diferents uuid and id's values so you can'not just save entity uuid or id to the players data

it will point to other entityes of to nothing at all

 

- second i can take note of the vainilla entityes classes and save their data

soo if i have a sheep i can save this entity asigning a nunmber to the classes

per example  sheep is number 2    wolf is number 3

 

so if i wana save a sheep

int entiType = 2;

float entiHeal = 10f;

BlockPos entiPos = wever;

 

so later in the load i can say is entiType 2  so this must be a sheep and create a new sheep whith this healt  and pos values

 

but moded entityes clases how i could save a moded entity class to later recreate it

 

#####

 

Or there is and absolutly diferent an easy way to do this, an i not aware ??

 

 

for now this is mi actual IEEP saving some data and here is where sava and recreate the fantasmaMercenario Entity

 

 

 

package mercenarymod.entidades;

import java.util.UUID;

import mercenarymod.utilidades.util;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityGolem;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.IExtendedEntityProperties;
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class ExtendedPropertiesMercenary implements IExtendedEntityProperties {
public final static String extendedPropertiesName = "extendedFantasmaMercenario";
protected EntityLivingBase theEntity;
protected World theWorld;

@Override
public void saveNBTData(NBTTagCompound parCompound) {
	// DEBUG
	//System.out.println(("ExtendedProperties EntityLivingBase saveNBTData()"));

	// good idea to keep your extended properties in a sub-compound to
	// avoid conflicts with other possible extended properties,
	// even from other mods (like if a mod extends all EntityAnimal)

	if ( (theEntity instanceof EntityLivingBase) & !(theEntity instanceof fantasmaMercenario) )   {


		EntityLivingBase shootingEntity = (EntityLivingBase) theEntity;

		if (shootingEntity != null) {

			NBTTagCompound theEntitycompound = theEntity.getEntityData();


			boolean hasStS = theEntitycompound.getBoolean("hasStS"); //has something to save 

			if (hasStS)
			{
			System.out.println("hasStS=true");

			boolean hasGHOST = theEntitycompound.getBoolean("hasGHOST");
			boolean hasFULTON = theEntitycompound.getBoolean("hasFULTON");
			boolean hasC4 = theEntitycompound.getBoolean("hasC4");
			boolean hasRCbullet = theEntitycompound.getBoolean("hasRCbullet");

			int OwnerID = theEntitycompound.getInteger("OwnerID"); 
			String OwnerUUID = theEntitycompound.getString("OwnerUUID");

			int radioSerial = theEntitycompound.getInteger("radioSerial");
			int radioDialN = theEntitycompound.getInteger("radioDialN");

			System.out.println("hasGHOST="+hasGHOST+ theEntity.getName()+" pos="+theEntity.getPosition());


			NBTTagCompound compound = new NBTTagCompound();

                         // the entity has relevant data to save 
			compound.setBoolean("hasStS", true);

                         // the entity has a MercenaryGhost whatching over it 
			compound.setBoolean("hasGHOST", hasGHOST);

                        //the entity is atached to a fulton device WIP
			compound.setBoolean("hasFULTON", hasFULTON);

                        //the entity has atached to c4 WIP
			compound.setBoolean("hasC4", hasC4);

                        //the entity has been damage for redclub munition
			compound.setBoolean("hasRCbullet", hasRCbullet);

                        //the owner id of this entity
			compound.setInteger("OwnerID", OwnerID);

                        //the owner UUid of this entity				
			compound.setString("OwnerUUID", OwnerUUID);


			parCompound.setTag(extendedPropertiesName, compound); // set as sub-compound

			}

		}
	}
}

@Override
public void loadNBTData(NBTTagCompound parCompound)

{
	// DEBUG
	//System.out.println(("ExtendedPropertiesH EntityLivingBase loadNBTData()"));


	// Get the sub-compound
	NBTTagCompound compound = (NBTTagCompound) parCompound.getTag(extendedPropertiesName);

	if (compound != null) {

		NBTTagCompound theEntitycompound = theEntity.getEntityData();




		boolean hasStS = theEntitycompound.getBoolean("hasStS");

		boolean hasGHOST = theEntitycompound.getBoolean("hasGHOST");
		boolean hasFULTON = theEntitycompound.getBoolean("hasFULTON");
		boolean hasC4 = theEntitycompound.getBoolean("hasC4");
		boolean hasRCbullet = theEntitycompound.getBoolean("hasRCbullet");

		int OwnerID = theEntitycompound.getInteger("OwnerID"); 
		String OwnerUUID = theEntitycompound.getString("OwnerUUID");


		if ( OwnerID != 0) //then this has a master, set the UUID 
		{

		theEntitycompound.setString("OwnerUUID", OwnerUUID);	

		theEntitycompound.setInteger("OwnerID", 0);

//get the master ID for this this sesion and save it to entity
		util.getEntityOwnerID(theEntity); 
		System.out.println("OwnerID set to="+util.getEntityOwnerID(theEntity));	
		}


		if (hasGHOST){

		// i notice that loadNBTData() some times run 2  or 3 times over the same creature
		// so this check if the entity has already a ghost before conjuring a new one  

		util.getFantasma(theEntity, null);

		System.out.println("hasGHOST=Conjured for"+ theEntity.getName()+" pos="+theEntity.getPosition() );
		}

	}




}

// ########################################################################################################################3
// conjurar espirito
// @SubscribeEvent


// ########################################################################################################################3
@Override
public void init(Entity entity, World world) {
	// DEBUG
	// System.out.println(("ExtendedProperties EntityLivingBase init()");
	theEntity = (EntityLivingBase) entity;
	theWorld = world;
}

}

 

 

 

 

 

Posted

The entity UUID will NOT change, but the id from #getEntityID will.

 

However, the entities will not exist until the chunk that they are in is loaded, so they will likely be null for a while after loading the game. One way around that is to store their last known coordinates and load that chunk (if not already loaded) when searching for them, but even that's not foolproof - the entity may have moved, died, etc.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Version 1.19 - Forge 41.0.63 I want to create a wolf entity that I can ride, so far it seems to be working, but the problem is that when I get on the wolf, I can’t control it. I then discovered that the issue is that the server doesn’t detect that I’m riding the wolf, so I’m struggling with synchronization. However, it seems to not be working properly. As I understand it, the server receives the packet but doesn’t register it correctly. I’m a bit new to Java, and I’ll try to provide all the relevant code and prints Thank you very much in advance No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. MountableWolfEntity package com.vals.valscraft.entity; import com.vals.valscraft.network.MountSyncPacket; import com.vals.valscraft.network.NetworkHandler; import net.minecraft.client.Minecraft; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.animal.Wolf; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.Entity; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.network.PacketDistributor; public class MountableWolfEntity extends Wolf { private boolean hasSaddle; private static final EntityDataAccessor<Byte> DATA_ID_FLAGS = SynchedEntityData.defineId(MountableWolfEntity.class, EntityDataSerializers.BYTE); public MountableWolfEntity(EntityType<? extends Wolf> type, Level level) { super(type, level); this.hasSaddle = false; } @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(DATA_ID_FLAGS, (byte)0); } public static AttributeSupplier.Builder createAttributes() { return Wolf.createAttributes() .add(Attributes.MAX_HEALTH, 20.0) .add(Attributes.MOVEMENT_SPEED, 0.3); } @Override public InteractionResult mobInteract(Player player, InteractionHand hand) { ItemStack itemstack = player.getItemInHand(hand); if (itemstack.getItem() == Items.SADDLE && !this.hasSaddle()) { if (!player.isCreative()) { itemstack.shrink(1); } this.setSaddle(true); return InteractionResult.SUCCESS; } else if (!level.isClientSide && this.hasSaddle()) { player.startRiding(this); MountSyncPacket packet = new MountSyncPacket(true); // 'true' means the player is mounted NetworkHandler.CHANNEL.sendToServer(packet); // Ensure the server handles the packet return InteractionResult.SUCCESS; } return InteractionResult.PASS; } @Override public void travel(Vec3 travelVector) { if (this.isVehicle() && this.getControllingPassenger() instanceof Player) { System.out.println("The wolf has a passenger."); System.out.println("The passenger is a player."); Player player = (Player) this.getControllingPassenger(); // Ensure the player is the controller this.setYRot(player.getYRot()); this.yRotO = this.getYRot(); this.setXRot(player.getXRot() * 0.5F); this.setRot(this.getYRot(), this.getXRot()); this.yBodyRot = this.getYRot(); this.yHeadRot = this.yBodyRot; float forward = player.zza; float strafe = player.xxa; if (forward <= 0.0F) { forward *= 0.25F; } this.flyingSpeed = this.getSpeed() * 0.1F; this.setSpeed((float) this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 1.5F); this.setDeltaMovement(new Vec3(strafe, travelVector.y, forward).scale(this.getSpeed())); this.calculateEntityAnimation(this, false); } else { // The wolf does not have a passenger or the passenger is not a player System.out.println("No player is mounted, or the passenger is not a player."); super.travel(travelVector); } } public boolean hasSaddle() { return this.hasSaddle; } public void setSaddle(boolean hasSaddle) { this.hasSaddle = hasSaddle; } @Override protected void dropEquipment() { super.dropEquipment(); if (this.hasSaddle()) { this.spawnAtLocation(Items.SADDLE); this.setSaddle(false); } } @SubscribeEvent public static void onServerTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.START) { MinecraftServer server = net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(); if (server != null) { for (ServerPlayer player : server.getPlayerList().getPlayers()) { if (player.isPassenger() && player.getVehicle() instanceof MountableWolfEntity) { MountableWolfEntity wolf = (MountableWolfEntity) player.getVehicle(); System.out.println("Tick: " + player.getName().getString() + " is correctly mounted on " + wolf); } } } } } private boolean lastMountedState = false; @Override public void tick() { super.tick(); if (!this.level.isClientSide) { // Only on the server boolean isMounted = this.isVehicle() && this.getControllingPassenger() instanceof Player; // Only print if the state changed if (isMounted != lastMountedState) { if (isMounted) { Player player = (Player) this.getControllingPassenger(); // Verify the passenger is a player System.out.println("Server: Player " + player.getName().getString() + " is now mounted."); } else { System.out.println("Server: The wolf no longer has a passenger."); } lastMountedState = isMounted; } } } @Override public void addPassenger(Entity passenger) { super.addPassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(true)); } } } @Override public void removePassenger(Entity passenger) { super.removePassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is no longer mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(false)); } } } @Override public boolean isControlledByLocalInstance() { Entity entity = this.getControllingPassenger(); return entity instanceof Player; } @Override public void positionRider(Entity passenger) { if (this.hasPassenger(passenger)) { double xOffset = Math.cos(Math.toRadians(this.getYRot() + 90)) * 0.4; double zOffset = Math.sin(Math.toRadians(this.getYRot() + 90)) * 0.4; passenger.setPos(this.getX() + xOffset, this.getY() + this.getPassengersRidingOffset() + passenger.getMyRidingOffset(), this.getZ() + zOffset); } } } MountSyncPacket package com.vals.valscraft.network; import com.vals.valscraft.entity.MountableWolfEntity; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class MountSyncPacket { private final boolean isMounted; public MountSyncPacket(boolean isMounted) { this.isMounted = isMounted; } public void encode(FriendlyByteBuf buffer) { buffer.writeBoolean(isMounted); } public static MountSyncPacket decode(FriendlyByteBuf buffer) { return new MountSyncPacket(buffer.readBoolean()); } public void handle(NetworkEvent.Context context) { context.enqueueWork(() -> { ServerPlayer player = context.getSender(); // Get the player from the context if (player != null) { // Verifies if the player has dismounted if (!isMounted) { Entity vehicle = player.getVehicle(); if (vehicle instanceof MountableWolfEntity wolf) { // Logic to remove the player as a passenger wolf.removePassenger(player); System.out.println("Server: Player " + player.getName().getString() + " is no longer mounted."); } } } }); context.setPacketHandled(true); // Marks the packet as handled } } networkHandler package com.vals.valscraft.network; import com.vals.valscraft.valscraft; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.simple.SimpleChannel; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class NetworkHandler { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel( new ResourceLocation(valscraft.MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); public static void init() { int packetId = 0; // Register the mount synchronization packet CHANNEL.registerMessage( packetId++, MountSyncPacket.class, MountSyncPacket::encode, MountSyncPacket::decode, (msg, context) -> msg.handle(context.get()) // Get the context with context.get() ); } }  
    • Do you use features of inventory profiles next (ipnext) or is there a change without it?
    • Remove rubidium - you are already using embeddium, which is a fork of rubidium
  • Topics

×
×
  • Create New...

Important Information

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