Jump to content

[1.7.10] How would you sync a mobs inventory Server n Client side


Thornack

Recommended Posts

Hi everyone, I have a method that gives my mob attacks which are basically customized items (it works). But I need to sync the mobs inventory so that the attack items also exist on the client. Im not sure how to do this. (And Dont just say "Packets" I know that it requires packets or use of a datawatcher but I am stumped how to do this) Currently I have tried the following see below).

 

This method is called server side only when my entity gets constructed and then again whenever my entity levels up (this works)

public void attacks(EntityCustom customEntity){
	if(customEntity instanceof EntityMyMob){
		int lvl = customEntity.getStats().level;
		if(lvl <= 5){
		customEntity.attacks[0] = new ItemStack(CommonProxy.itemAttack_Primary);
		PacketOverlord.sendToAll(new PacketSyncAttacks(customEntity)); <- need to update the attacks when they are given
		}
		if(lvl > 5){
		customEntity.attacks[1] = new ItemStack(CommonProxy.itemAttack_Secondary);
                         PacketOverlord.sendToAll(new PacketSyncAttacks(customEntity)); <- need to update the attacks when they are given
		  	}
		if (lvl >= 12){
		customEntity.attacks[2] = new ItemStack(CommonProxy.itemAttack_Tertiary);
                        PacketOverlord.sendToAll(new PacketSyncAttacks(customEntity)); <- need to update the attacks when they are given
		}
		if(lvl >= 18){
		customEntity.attacks[3] = new ItemStack(CommonProxy.itemAttack_Quaternary);
                        PacketOverlord.sendToAll(new PacketSyncAttacks(customEntity)); <- need to update the attacks when they are given
		}

	}
}

 

My packet class - The issue is my entity is null when I send the packet for some reason, So I am unsure how to update the entity on its client side so that it has the attacks on both sides. Currently the attacks are only present on server side

public class PacketSyncAttacks extends AbstractMessageToClient<PacketSyncAttacks> {

private NBTTagCompound data;
EntityCustom custom;

public PacketSyncAttacks() {}

public PacketSyncAttacks(EntityCustom custom) {

	this.custom= custom; <- Entity is not null here
	data = new NBTTagCompound();
	custom.writeEntityToNBT(data);
}

@Override
protected void read(PacketBuffer buffer) throws IOException {

	data = buffer.readNBTTagCompoundFromBuffer();
}

@Override
protected void write(PacketBuffer buffer) throws IOException {
	System.out.println("FUCK3");
	buffer.writeNBTTagCompoundToBuffer(data);
}

@Override
public void process(EntityPlayer player, Side side) {
//But my entity is null here. So I am unsure what to do to update my entities inventory
	if(data != null && custom!= null){ <- this is never called since entity is null here on client side
	this.custom.readFromNBT(data);
	}
}
}

 

My Packet Handler class

 

 

public class PacketOverlord {
private static byte packetId = 0;

private static final SimpleNetworkWrapper dispatcher = NetworkRegistry.INSTANCE
		.newSimpleChannel(CustomMod.CHANNEL);

/**
 * Register all packets and handlers here - this should be called during
 * {@link FMLPreInitializationEvent}
 */
public static final void preInit() {

           registerMessage(PacketSyncAttacks.class);

	}

/**
 * Register an {@link AbstractMessageOverlord} to the correct side
 */
private static final <T extends AbstractMessageOverlord<T> & IMessageHandler<T, IMessage>> void registerMessage(
		Class<T> clazz) {
	if (AbstractMessageOverlord.AbstractMessageToClient.class.isAssignableFrom(clazz)) {
		PacketOverlord.dispatcher.registerMessage(clazz, clazz,	packetId++, Side.CLIENT);
	} else if (AbstractMessageOverlord.AbstractMessageToServer.class.isAssignableFrom(clazz)) {
		PacketOverlord.dispatcher.registerMessage(clazz, clazz,	packetId++, Side.SERVER);
	} else {
		PacketOverlord.dispatcher.registerMessage(clazz, clazz, packetId,Side.CLIENT);
		PacketOverlord.dispatcher.registerMessage(clazz, clazz,	packetId++, Side.SERVER);
	}
}

/**
 * This message is sent to the specified player's client-side counterpart. See
 * {@link SimpleNetworkWrapper#sendTo(IMessage, EntityPlayerMP)}
 */
public static final void sendTo(IMessage message, EntityPlayerMP player) {
	PacketOverlord.dispatcher.sendTo(message, player);
}

public static final void sendToPlayers(IMessage message, Set<EntityPlayer> players) {
	for(EntityPlayer player : players) {
		//System.out.println("player"+player);
		//System.out.println("players"+players);
	 PacketOverlord.dispatcher.sendTo(message, (EntityPlayerMP) player);
	}
	}



/**This sends a message to everyone. See
 * {@link SimpleNetworkWrapper#sendToAll(IMessage)}
 */
public static void sendToAll(IMessage message) {
	PacketOverlord.dispatcher.sendToAll(message);
}

/**
 * This sends a message to everyone within a specified range of a specified point. See
 * {@link SimpleNetworkWrapper#sendToAllAround(IMessage, NetworkRegistry.TargetPoint)}
 */
public static final void sendToAllAround(IMessage message,
		NetworkRegistry.TargetPoint point) {
	PacketOverlord.dispatcher.sendToAllAround(message, point);
}

/**
 * This sends a message to everyone within a specified range of the passed in coordinates in
 * the same MC dimension. Shortcut to
 * {@link SimpleNetworkWrapper#sendToAllAround(IMessage, NetworkRegistry.TargetPoint)}
 */
public static final void sendToAllAroundCoordinates(IMessage message, int dimension, double x, double y, double z, double range) {
	PacketOverlord.sendToAllAround(message,	new NetworkRegistry.TargetPoint(dimension, x, y, z, range));
}

/**
 * This sends a message to everyone within a specified range of the passed in player
 * Shortcut to
 * {@link SimpleNetworkWrapper#sendToAllAround(IMessage, NetworkRegistry.TargetPoint)}
 */
public static final void sendToAllAround(IMessage message, EntityPlayer player, double range) {
	PacketOverlord.sendToAllAroundCoordinates(message,	player.worldObj.provider.dimensionId, player.posX, player.posY,	player.posZ, range);
}

/**
 * This sends a message to everyone within a specified range of the passed in pkmn
 * Shortcut to
 * {@link SimpleNetworkWrapper#sendToAllAround(IMessage, NetworkRegistry.TargetPoint)}
 */
public static final void sendToAllAround(IMessage message, EntityCustom entityCustom, double range) {
	PacketOverlord.sendToAllAroundCoordinates(message,	entityCustom.worldObj.provider.dimensionId, entityCustom.posX, entityCustom.posY, entityCustom.posZ, range);
}

/**
 * this sends a message to everyone within the passed in dimension that is denoted by its id. See
 * {@link SimpleNetworkWrapper#sendToDimension(IMessage, int)}
 */
public static final void sendToDimension(IMessage message, int dimensionId) {
	PacketOverlord.dispatcher.sendToDimension(message, dimensionId);
}

/**
 * This sends a message to the server. See
 * {@link SimpleNetworkWrapper#sendToServer(IMessage)}
 */
public static final void sendToServer(IMessage message) {
	PacketOverlord.dispatcher.sendToServer(message);
}

public static final SimpleNetworkWrapper getInstance()
{
	return dispatcher;
}
}

 

 

 

Anyone know of a good way to do this I am stumped atm

Link to comment
Share on other sites

I don't think you need custom packets for this. Inventories can be synced by built in methods if you make them part of a Container along with an IGuiHandler. The IGuiHandler is what syncs up the client and server for you. I have a tutorial for inventory GUIs for blocks, but I'm fairly certain it would work same way for any inventory: http://jabelarminecraft.blogspot.com/p/minecraft-modding-blocks-with-guis.html

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Thornack, you are misunderstanding how packets work.

 

A packet is created on one side, populating all the class fields as needed and then writing those to an output stream so it can be sent to the other side; when this data is received on the other side, a COMPLETELY NEW instance of the packet is created, meaning NONE of your class fields have any information in them yet.

 

The data is then parsed by the packet's read method, which is generally where you initialize class fields, and then those fields can be used when the handler processes the packet.

 

That said, Jabelar is correct - you shouldn't need to manually sync inventory information, as that is done by the Container class. If you don't have a Container class, you probably don't have a GUI, and if you don't have a GUI, then why does the client need to know the information anyway?

Link to comment
Share on other sites

Ok Thanks for clarifying that up, coolAlias I think I understand packets a bit better now, but I still need to send my packet and still have the same problem. I dont know how to sync my attack items client and server side.. I dont have a gui for my entity, I need to make my items exist on client side also so that my mob entity can use them. Currently what I have is the following.

 

Entity is spawned -> Entities level is generated -> Entities attacks are calculated based on level -> This is done server side -> Entity can be added to players party -> Entity can then be spawned by player as an ownable entity -> Player can become this entity by morphing into it -> Player gets all entity stats, inventory and items in inventory -> Items are attacks that the player can then use.

 

All of that works great. Im trying ot now write an AI to use my entities attack items so that the untamed entity can attack other entities using the attack items (just like the player can).

 

my partial entity class (sorry  alot of the code is pretty complicated so I omitted the crazy stuff cause this entity can do a lot atm) Hopefully this is sufficient to help grasp the issue. I need this entity to be able to use my attack items with onItem Right Click and on Item Use -> and onUsingTick-> to spawn custom particles and deal custom damage from a custom DamageSource.

 

I left in every line related to my attack items. The attacks only exist on server side however for my entity. Currently My entity spawns the attack item particles but the attack does no damage (for some reason)

 

 

 

public class EntityCustom extends EntityAnimal implements IEntityAdditionalSpawnData
{

    public ItemStack[] attacks = new ItemStack[4];
    public int currentAttack;
    private ItemStack attackInUse;
    private int attackInUseCount;
    
    
public CustomStats stats;

public EntityCustom(World world)
{
	super(world);
	this.setSize(0.9F, 0.9F);

	this.setupAI();		

	this.stats = new CustomStats(this);
	if(!world.isRemote){
		stats.calculateNewStats();
		stats.recalculateStats(this);
	}		
}


public CustomStats getStats()
{
	return this.stats;
}



  public ItemStack getCurrentAttack()
    {
        return this.currentAttack < 4 && this.currentAttack >= 0 ? this.attacks[this.currentAttack] : null;
    }
  
  public void setAttackItemInUse(ItemStack itemStack, int maxItemUseDuration)
    {  
        if (itemStack != this.attackInUse)
        {  
            if (maxItemUseDuration <= 0){ 
            	return;
            }
            
            this.attackInUse = itemStack;
            this.attackInUseCount = maxItemUseDuration;
            
            if (!this.worldObj.isRemote)
            {
                this.setEating(true);
            }
        }
    }
  
  public void clearAttackInUse()
    {
        this.attackInUse = null;
        this.attackInUseCount = 0;

        if (!this.worldObj.isRemote)
        {
            this.setEating(false);
        }
    }
  
  protected void onAttackUseFinish()
    {
        if (this.attackInUse != null)
        {
            int i = this.attackInUse.stackSize;
            /**may cause problems*/
            ItemStack itemstack = this.attackInUse.onFoodEaten(this.worldObj, null);

           if (itemstack != this.attackInUse || itemstack != null && itemstack.stackSize != i)
            {
            	this.attacks[this.currentAttack] = itemstack;

                if (itemstack != null && itemstack.stackSize == 0)
                {
                    this.attacks[this.currentAttack] = null;
                }
            }

            this.clearAttackInUse();
        }
    }
  
  
  
@Override
 public void onLivingUpdate(){
	super.onLivingUpdate();
	///////////////////////////////////

	Attack att = (Attack)  attacks[0].getItem();
	att.onItemRightClick( attacks[0], this.worldObj, this);

        if (this.attackInUse != null)
        {
        	ItemStack itemstack = this.getCurrentAttack();

            if (itemstack == this.attackInUse)
            {
            	
            	if (attackInUseCount <= 0)
                {
            		this.onAttackUseFinish();
                }
                else
                {
                	
                	if(attackInUse.getItem() instanceof PWItem){
                		
                		PWItem attack = (PWItem) attackInUse.getItem();
                		attack.onUsingTick(attackInUse, this, attackInUseCount);
                	}
                	                      
                    if (--this.attackInUseCount == 0 && !this.worldObj.isRemote)
                    {
                    	this.onAttackUseFinish();
                    }
                }
            }
            else
            {            	
                this.clearAttackInUse();
            }
            
        }
        /////////////////////////////////////+

 }
   

@Override
protected void entityInit()
{
	super.entityInit();

}

@Override
public boolean attackEntityFrom(DamageSource damageSource, float damageAmount)
{
	if (!this.worldObj.isRemote)
	{
		if(this.stats.currentHp > 0)
		{
			this.stats.currentHp = (int) this.getHealth() - (int) damageAmount;
		}
		else
		{
			this.stats.currentHp = 0;
		}
		MessageUpdateCustomStats msg = new MessageUpdateCustomStats(this);
		msg.sendToAll();
	}
	return super.attackEntityFrom(damageSource, damageAmount);
}

@Override
public boolean isAIEnabled()
{
	return true;
}

@Override
protected void updateAITasks()
{
	super.updateAITasks();
}

private void setupAI()
{	
	this.getNavigator().setAvoidsWater(true);
	clearAITasks();
	double speed = 0.5F;
	//this.tasks.addTask(0, new EntityAISwimming(this));
	this.tasks.addTask(1, new EntityAIWander(this, speed));
	this.tasks.addTask(2, new EntityAIWatchClosest(this, EntityPlayer.class, 12.0F));
	this.tasks.addTask(3, new EntityAIPanic(this, speed)); // speed is the second parameter
	this.tasks.addTask(4, new EntityAILookIdle(this));
	this.tasks.addTask(5, new EntityAIWatchClosest(this, EntityCustom.class, 6.0F));
}

private void clearAITasks()
{
	tasks.taskEntries.clear();
	targetTasks.taskEntries.clear();
}

@Override
public void writeSpawnData(ByteBuf buffer)
{
	this.stats.toBytes(buffer);
}

@Override
public void readSpawnData(ByteBuf additionalData)
{
	this.stats.fromBytes(additionalData);
}

  /**
     * Returns the item that this EntityLiving is holding, if any.
     */
    public ItemStack getFirstAttack()
    {
        return this.attacks[0];
    }
    
    public ItemStack getAttackFromSlot(int slot)
    {
        return this.attacks[slot];
    }
    
    public ItemStack deleteAttackInSlot(int slot)
    {
        return this.attacks[slot] = null;
    }

    @Override
public void writeEntityToNBT(NBTTagCompound nbt)
{ 
	super.writeEntityToNBT(nbt);

	NBTTagList nbttaglist = new NBTTagList();
        NBTTagCompound attackNBT;
        
	  
	for (int i = 0; i < this.attacks.length; ++i) {
		attackNBT = new NBTTagCompound();

		if (this.attacks[i] != null) {
			this.attacks[i].writeToNBT(attackNBT);
		}

		nbttaglist.appendTag(attackNBT);
	}
	nbt.setTag("Attacks", nbttaglist);
	this.stats.saveNBT(nbt);

	}

@Override
public void readEntityFromNBT(NBTTagCompound nbt)
{   super.readEntityFromNBT(nbt);

	NBTTagList nbttaglist;
	 if (nbt.hasKey("Attacks", 9)){
            nbttaglist = nbt.getTagList("Attacks", 10);

            for (int i = 0; i < this.attacks.length; ++i)
            {
                this.attacks[i] = ItemStack.loadItemStackFromNBT(nbttaglist.getCompoundTagAt(i));
            }
        }
	this.stats.loadNBT(nbt);

	}



}

 

 

 

When I get the entities that the attack is supposed to target (they return correctly Sorry I also removed a lot of logic here cause its kinda huge atm) BUT for some reason

List<EntityLivingBase> targets = TargetingHelper.acquireAllLookTargets(customEntity, Math.round(damageRadius), 1.0F);
		for (EntityLivingBase target : targets) {
                                System.out.println("Damage Done: " + appliedDmg + " target " + target);
			target.attackEntityFrom(getDamageSource(customEntity), appliedDmg);

}

The damage isnt done since when I call

 target.attackEntityFrom(getDamageSource(customEntity), appliedDmg); 

the appliedDmg variable is there and calculated correctly, the entity is there, the damage source is there, but the attackEntityFrom bit is never called (I checked with a break point)!! But for the player (when player is morphed into the entity and gets the entities attack) everything is there and damage does get dealt...So I checked whether or not my item exists client side for my entity and it does not, I suspect this is the problem. The onLivingUpdate method crashes the game when I allow it to call the following on client side because the item is null when I call.

if(this.worldObj.isRemote){
	System.out.println(attacks[0]); <- this is null on client side but not null on server side
	Attack att = (Attack)  attacks[0].getItem();
	att.onItemRightClick( attacks[0], this.worldObj, this);
	}

 

So my item is only there on server side and this is probably why I am having issues.

 

Its basically driving me crazy how hard this "get mobs to use my items" is to implement ugh. The good thing though if I get this one class implemented then all of my attacks will work because they are all set up the same. Any ideas anybody?

 

I am basically trying to take all of the onItemRightClick stuff and onItemUse, and onUsingTick etc etc and implement it for my entity so that it can use my item. I believe the important classes/methods have already been posted

Link to comment
Share on other sites

Why do you care if the code runs on the client side, though? Only the server side should care about whether an attack or action is performed - the only exception is if you need some animation or something to happen on the client, and then you can just send a packet or health update flag saying 'this action was done on the server, so do your thing now client'.

 

So the solution is to only run the code on the server side - there is no reason to run it on both sides for a non-player entity.

Link to comment
Share on other sites

My customized onItemRightClick method from my attack item class that I changed to work for my custom entity (it works for the player). Currently just trying to get the else if(ball ==false){} attacks done and working as they represent the majority of my attacks (the last else statement in this method). The ball type attacks are kind of like a snowball projectile but they do damage and have a trailing particle behind them and use a custom model. For now the non ball attacks is what I am looking at.

 

 

public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityCustom entityCustom) {
				int fatigueMultiplier = 1;

				if(ball == true && (getCooldown(itemStack) == 0)){
				 fatigueMultiplier = 2;

				EntityRangedAttackBase distanceAttack = new EntityRangedAttack(world, entityCustom).setType(attackType).setArea(damageRadius);
      				distanceAttack.setBaseDamageForProjectileAttack(baseDmg);
      				setCooldown(itemStack, 30);

      				if (!world.isRemote) {//spawn the bomb entity if your on the server
      					WorldHelper.playSoundAtEntity(entityCustom,BattleSoundsList.WHOOSH, 0.4F, 0.5F);
      					world.spawnEntityInWorld(distanceAttack);
      				}

      				
		      }	else if(ball ==false){	
		    	 //This is the bit that I care about atm as these are the main attacks
		    	  entityCustom.setAttackItemInUse(itemStack,getMaxItemUseDuration(itemStack));
			    }


	return itemStack;
}

 

 

 

My onUsingTickMethod inside my attack item class (atm I only care about the non stationary attacks (again since they represent the majority) (last else statement in this method

 

 

public void onUsingTick(ItemStack itemStack, EntityCustom entityCustom, int count) {

	if(entityCustom.worldObj.isRemote){
		System.out.println("NEVER CALLED"); //This is never called because my item is serverside only so the aiming logic for the attack doesnt work properly atm.
		MovingObjectPosition mop = entityCustom.rayTrace(15, 1F);
		if (mop != null && !entityCustom.worldObj.isAirBlock(mop.blockX, mop.blockY, mop.blockZ) && (mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK || mop.typeOfHit == MovingObjectPosition.MovingObjectType.ENTITY)) {
			PacketOverlord.sendToServer(new PacketUpdateOnUsingTickTargetCoord(mop.blockX, mop.blockY, mop.blockZ));
		}
	}

	if (!entityCustom.worldObj.isRemote) {

               int ticksInUse = getMaxItemUseDuration(itemStack) - count;
			// Spawn stationary particle attack on right click
			if (this == CommonProxy.itemAttack_Stationary) {

				if (ticksInUse % 10 == 0) {

				EntityStationary entityStationary = new EntityStationary(entityCustom.worldObj, xTargetCoord + 0.5, yTargetCoord + 1, zTargetCoord + 0.5).disableGriefing();
				entityStationary .thrower = entityCustom;
				entityStationary .setBaseDamageForProjectileAttack(baseDmg);
				entityCustom.worldObj.spawnEntityInWorld(entityStationary);
				}
			} else {
				//This is what I care about here because I want to deal with the non stationary attacks
				handleUpdateTick(itemStack, entityCustom.worldObj, entityCustom, ticksInUse);
			}

	}
}

 

 

 

The handleUpdateTick method  inside my attack item class that I use for my main attacks. The non ball non stationary attacks (these are the majority of my particle attacks and they behave like a flamethrower essentially but all have different particles that are set elsewhere. All particles spawn normally but damage isnt done ever

 

 

private void handleUpdateTick(ItemStack itemStack, World world, EntityCustom entityCustom, int ticksInUse) {
	PacketOverlord.sendToAllAround(new PacketISpawnParticles(entityCustom, this, (float) (damageRadius)), entityCustom, 64.0D); <- works to spawn my particles (and they do actually show up)
	if (ticksInUse % 4 == 3) {
		float radius = 1;
		if(entityCustom.entID != -1){
			 radius = 10;
			}		
		List<EntityLivingBase> targets = TargetingHelper.acquireAllLookTargets(entityCustom, Math.round(1*damageRadius), 1.0F);
		for (EntityLivingBase target : targets) {
		//////////DAMAGE LOGIC FOR NON BALL TYPE ATTACKS////////////
			int defense = 1;
			if(target instanceof EntityCustom){
				defense = ((EntityCustom) target).stats.currentDef;
			} else if (target instanceof EntityPlayer){
					defense = 1;
			  }

			if(entityCustom.entID != -1){

			float calcPartTwo = ((float)entityCustom.stats.currentAtt/defense);
			float modifier = 1.0F;
			float appliedDmg = ((calcPartTwo*baseDmg)+2.0F)*modifier;
			System.out.println("Damage Done: " + appliedDmg); <-This prints correctly
			target.attackEntityFrom(getDamageSource(entityCustom), appliedDmg); //BUT DAMAGE ISNT ACTUALLY DONE!!!!!!!!!!
			System.out.println("damage source "+getDamageSource(entityCustom)); <-This prints correctly
			System.out.println(entityCustom);<-This prints correctly
			}	
	         ////////////////////////////////////////////////////////////////////
		}
	}

}

 

 

Link to comment
Share on other sites

Ok I got my damage working but now I still need the targeting to work. It was a simple fix ish where I passed in the the target as an entity player so that the player into the

target.attackEntityFrom(getDamageSource((EntityPlayer) target), appliedDmg); 

can take damage from the wild entities. Im not sure if the damage is the correct damage but the player can now be hurt by the entity so that seems to work good.

Link to comment
Share on other sites

I still need to figure out how to get the aiming code working (that would require the invnetory to be on client side also so that the onItemRightClick method can be called on client and server just like the player one does

Is the aiming code the reason you think you need the code to run client side? If so, you don't. You can write aiming code that works just fine on the server - the only reason the player has code running on the client side is because that's where player input (i.e. mouse and keyboard) comes from, so it makes sense to say 'hey client, where is the player's mouse pointing right now?'.

 

In the context of a non-player entity, however, that doesn't make much sense. Much better to use the server side values for the entity to determine if it can attack the player or not, using the entity's look vector to determine what it is looking at, geometry based on the entity's rotation vs. the player's position, or even just proximity as most vanilla mobs do.

Link to comment
Share on other sites

Its not just the aiming however but ok ill try youre suggestion and maybe see if i can only use server side values

Okay, so what other reasons do you have for wanting your code to run on the client side?

 

Keep in mind that the client is ONLY responsible for things like rendering the world, displaying GUIs on the screen, and taking input from the player and sending it to the server. Some methods run on both sides to make the interaction smoother, but the server is the final arbiter of the outcome.

 

E.g. when you (a player) attack an entity, the client also runs the code so that the player can immediately see the visible result of their action (the attacked entity appearing to take damage, the sword losing durability, etc.) without waiting for a response from the server, but that is only for visuals - the server is the one that actually determines if the entity takes damage, how much, etc., and the sword's new durability, etc. The client side values are irrelevant except for that immediate feedback to the player.

 

Look at every other mob's AI / attack code and you will see it only runs on the server. At most, the entity will send a packet to notify the client that it is attacking so that it can perform an animation or spawn particles, nothing more.

 

LivingAttackEvent, LivingHurtEvent, etc. all only fire on the server side, with the sole exception of when the aggressor is an EntityPlayer, in which case some of those events fire on both sides.

 

My point is that even if you allow the code to run on both sides, it sounds like you are using it wrong. 'Aiming' only occurs due to player input on the client - every other entity determines what it can strike on the server.

 

If you have animations or particles that you want to happen, use #setEntityState on the server at the appropriate time to send a custom flag to #handleHealthUpdate - open up the call hierarchy of both methods to see how they are used in many entities, e.g. EntityIronGolem, EntityVillager, etc.

Link to comment
Share on other sites

One of the main reasons really is so I dont have to rewrite a ton of logic that works currently if it is called client and server side for the player. My attacks recalculate an effective distance based on a ray trace (that bit isnt shown but ray trace needs to be client side only), they can "affect blocks" ie set blocks on fire, or spawn ice blocks to freeze things... etc etc and they also have a few visual effects. The aiming code works for me atm I like the ray trace since it lets me control the max distance,  etc etc... But out of curiosity in case I do feel like rewriting a bunch of stuff how would you suggest I do the aiming bit

Link to comment
Share on other sites

Ray tracing is available on the server side as well...

MovingObjectPosition mop = world.rayTraceBlocks(vec3OriginPosition, vec3TargetPosition);

Where both arguments are a Vec3, the first being the point of origin, and the second being some location off in the distance you are trying to reach - if the mop is null, there is nothing in the way; otherwise it will have information about the first block encountered between the two positions.

 

Like I mentioned above, you don't want any of your logic that is responsible for affecting the world to run on the client - this includes setting blocks on fire, spawning blocks, etc. Do ALL of that on the server.

 

For your visuals, if you don't need them to be super precise, you can do what the Explosion class does and allow the code to run on the client, too, for the sole purpose of spawning particles. The affected block positions will not necessarily be identical to what the server decides was affected, so there can/will be some mismatch. If you need the positions to be exact, then you will probably need to send a packet with each or all of the affected positions to notify the client where to spawn the particles.

 

Note how the above solution is 'server affects blocks, sends notification to client' rather than 'client determines affected blocks, sends list to server'. That is always the flow you should aim for.

 

As for targeting code, what exactly are you trying to do? What I mean is, non-player entities don't aim, they target whatever you tell them to target, so I'm not sure what problem you are trying to solve here. Do you only want your entity to be able to attack players in front of it? Are you having issues finding a player to attack? I need more information.

Link to comment
Share on other sites

Currently i got my entity to "use the attack item" this works, it spawns a stream of particles infront of it and anything within the calculated radius of effect (directly in front of my entity) will take damage. that is working. But when my mob rotates the "aiming" for the attack is incorrect. currently the particles are spawned along one set direction and the attack happens in that direction only. Im looking for a way to get my attack to follow the entities rotation. Just like for my player, if my player rotates the attack follows his look vector and the particles get spawned along that vector. Currently this is what I am trying to fix. I am going to implement a targeting AI later that will determine the ttack frequency and all of that. but for now I just made it so the attack pulses as so.

 

@Override
 public void onLivingUpdate(){
	super.onLivingUpdate();

	////////////////////////The pulsing code///////////////////////////////////////////////////
	if(!this.worldObj.isRemote){

		if(attackInUse == null && this.ticksExisted % 20 == 0){
			Attack att = (Attack)  attacks[0].getItem();
			att.onItemRightClick( attacks[0], this.worldObj, this);
		} else {
			if(this.ticksExisted % 20 == 0){
				attackInUse = null;
			}
		    }
	}
	///////////////////////////////////////////////////////////////////////////
        if (this.attackInUse != null)
        {
        	ItemStack itemstack = this.getCurrentAttack();

            if (itemstack == this.attackInUse)
            {
            	
            	if (attackInUseCount <= 0)
                {
            		this.onAttackUseFinish();
                }
                else
                {
                	
                	if(attackInUse.getItem() instanceof PWItem){
                		
                		PWItem attack = (PWItem) attackInUse.getItem();
                		attack.onUsingTick(attackInUse, this, attackInUseCount);
                	}
                	                      
                    if (--this.attackInUseCount == 0 && !this.worldObj.isRemote)
                    {
                    	this.onAttackUseFinish();
                    }
                }
            }
            else
            {            	
                this.clearAttackInUse();
            }
            
        }
        /////////////////////////////////////+

 

This bit of code is the part I need to change since my method never gets called on client

if(customEntity.worldObj.isRemote){
		System.out.println("NEVER CALLED");
		MovingObjectPosition mop = customEntity.rayTrace(15, 1F);
		if (mop != null && !customEntity.worldObj.isAirBlock(mop.blockX, mop.blockY, mop.blockZ) && (mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK || mop.typeOfHit == MovingObjectPosition.MovingObjectType.ENTITY)) {
			PacketOverlord.sendToServer(new PacketUpdateOnUsingTickTargetCoord(mop.blockX, mop.blockY, mop.blockZ));
		}
	}

 

it is located inside my onUsingTick method. Basically I need the look vector of the entities model so that when the model rotates inside its collision box the attack also rotates accordingly.

Link to comment
Share on other sites

I cant seem to just be able to use the entities look vector coordinates directly to determine my attack coordinates since the look vector coordinates are all really really small values like

 X is -1.2246468525851679E-16 Y is 0.0 Z is 1.0 

That is the output I get from

 

inside my onUsingTick method

System.out.println(" X is "+customEntity.getLookVec().xCoord + " Y is "+ customEntity.getLookVec().yCoord + " Z is "+customEntity.getLookVec().zCoord)

Link to comment
Share on other sites

Entity#getLookVec returns a normalized vector, which means the 'length' of the vector should equal 1. X, Y, and Z should all be values between -1.0F and 1.0F, i.e. values on the unit circle.

 

The look vector is determined using the entity's head rotation, not their body rotation - these are separate values. If you want to use the entity's body rotation to determine the path of the attack, you will need to copy the Entity#getLook method and swap in this.rotationYaw in place of this.rotationYawHead:

// from Entity#getLook(float) when the parameter = 1.0F, which is what is called from #getLookVec
return this.getVectorForRotation(this.rotationPitch, this.rotationYawHead); // note it uses HEAD yaw

Using #getVectorForRotation with the entity's body rotation should work, I would imagine.

Link to comment
Share on other sites

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

    • I'm trying to play Minecraft 1.20.4 on Forge using mods, but when Minecraft loads, it says there are non-Forge mods, whereas they are Forge mods. This problem is happening in Forge version 1.20.4 - 49.0.46. I am only able to play with all mods in Forge version 1.20.4 - 49.0.43.
    • I had the same issue. The only thing I could do is to remove parchment mappings entirely from config files and replace config files from the MDK: 1. replace build.gradle from MDK 2. restore official mapping in build.properties 3. replace src\main\resources\META-INF\mods.toml from MDK sample.
    • ---- Minecraft Crash Report ---- I sent a error report i just cant understand it, the game as been running fine intill today i loaded it https://pastebin.com/gWVFh4Fe   WARNING: coremods are present:   ForgelinPlugin (Forgelin-1.8.3.jar)   PatchingFixRtmCorePlugin (fixRtm-2.0.28.jar)   IELoadingPlugin (ImmersiveEngineering-core-0.12-98.jar)   FixRtmCorePlugin (fixRtm-2.0.28.jar)   JarInJarLoaderCoreMod (fixRtm-2.0.28.jar)   BetterFoliageLoader (BetterFoliage-MC1.12-2.3.2.jar)   SecurityCraftLoadingPlugin ([1.12.2] SecurityCraft v1.9.9.jar)   OpenModsCorePlugin (OpenModsLib-1.12.2-0.12.2.jar)   MalisisCorePlugin (MalisisCore-1.12.2.jar)   ObfuscatePlugin (obfuscate-0.4.2-1.12.2.jar)   CTMCorePlugin (CTM-MC1.12.2-1.0.2.31.jar)   HookingFixRtmCorePlugin (fixRtm-2.0.28.jar) Contact their authors BEFORE contacting forge // Hey, that tickles! Hehehe! Time: 4/19/24 4:05 PM Description: Updating screen events java.lang.RuntimeException: Failed to check session lock, aborting     at net.minecraft.world.storage.SaveHandler.func_75766_h(SaveHandler.java:76)     at net.minecraft.world.storage.SaveHandler.<init>(SaveHandler.java:54)     at net.minecraft.world.chunk.storage.AnvilSaveHandler.<init>(AnvilSaveHandler.java:18)     at net.minecraft.world.chunk.storage.AnvilSaveConverter.func_75804_a(SourceFile:84)     at net.minecraft.client.Minecraft.func_71371_a(Minecraft.java:2346)     at net.minecraftforge.fml.client.FMLClientHandler.tryLoadExistingWorld(FMLClientHandler.java:734)     at net.minecraft.client.gui.GuiListWorldSelectionEntry.func_186777_e(GuiListWorldSelectionEntry.java:249)     at net.minecraft.client.gui.GuiListWorldSelectionEntry.func_186774_a(GuiListWorldSelectionEntry.java:199)     at net.minecraft.client.gui.GuiListWorldSelectionEntry.func_148278_a(GuiListWorldSelectionEntry.java:163)     at net.minecraft.client.gui.GuiListExtended.func_148179_a(SourceFile:41)     at net.minecraft.client.gui.GuiWorldSelection.func_73864_a(SourceFile:117)     at net.minecraft.client.gui.GuiScreen.func_146274_d(GuiScreen.java:533)     at net.minecraft.client.gui.GuiWorldSelection.func_146274_d(SourceFile:49)     at net.minecraft.client.gui.GuiScreen.func_146269_k(GuiScreen.java:501)     at net.minecraft.client.Minecraft.func_71407_l(Minecraft.java:1759)     at net.minecraft.client.Minecraft.func_71411_J(Minecraft.java:1098)     at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:398)     at net.minecraft.client.main.Main.main(SourceFile:123)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:497)     at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)     at net.minecraft.launchwrapper.Launch.main(Launch.java:28) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Client thread Stacktrace:     at net.minecraft.world.storage.SaveHandler.func_75766_h(SaveHandler.java:76)     at net.minecraft.world.storage.SaveHandler.<init>(SaveHandler.java:54)     at net.minecraft.world.chunk.storage.AnvilSaveHandler.<init>(AnvilSaveHandler.java:18)     at net.minecraft.world.chunk.storage.AnvilSaveConverter.func_75804_a(SourceFile:84)     at net.minecraft.client.Minecraft.func_71371_a(Minecraft.java:2346)     at net.minecraftforge.fml.client.FMLClientHandler.tryLoadExistingWorld(FMLClientHandler.java:734)     at net.minecraft.client.gui.GuiListWorldSelectionEntry.func_186777_e(GuiListWorldSelectionEntry.java:249)     at net.minecraft.client.gui.GuiListWorldSelectionEntry.func_186774_a(GuiListWorldSelectionEntry.java:199)     at net.minecraft.client.gui.GuiListWorldSelectionEntry.func_148278_a(GuiListWorldSelectionEntry.java:163)     at net.minecraft.client.gui.GuiListExtended.func_148179_a(SourceFile:41)     at net.minecraft.client.gui.GuiWorldSelection.func_73864_a(SourceFile:117)     at net.minecraft.client.gui.GuiScreen.func_146274_d(GuiScreen.java:533)     at net.minecraft.client.gui.GuiWorldSelection.func_146274_d(SourceFile:49)     at net.minecraft.client.gui.GuiScreen.func_146269_k(GuiScreen.java:501) -- Affected screen -- Details:     Screen name: net.minecraft.client.gui.GuiWorldSelection Stacktrace:     at net.minecraft.client.Minecraft.func_71407_l(Minecraft.java:1759)     at net.minecraft.client.Minecraft.func_71411_J(Minecraft.java:1098)     at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:398)     at net.minecraft.client.main.Main.main(SourceFile:123)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:497)     at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)     at net.minecraft.launchwrapper.Launch.main(Launch.java:28) -- System Details -- Details:     Minecraft Version: 1.12.2     Operating System: Windows 10 (amd64) version 10.0     Java Version: 1.8.0_51, Oracle Corporation     Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation     Memory: 5013709368 bytes (4781 MB) / 11274289152 bytes (10752 MB) up to 12884901888 bytes (12288 MB)     JVM Flags: 8 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -Xmx12G -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M     IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0     FML: MCP 9.42 Powered by Forge 14.23.5.2859 Optifine OptiFine_1.12.2_HD_U_G5 99 mods loaded, 99 mods active     States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored     | State  | ID                          | Version               | Source                                            | Signature                                |     |:------ |:--------------------------- |:--------------------- |:------------------------------------------------- |:---------------------------------------- |     | LCHIJA | minecraft                   | 1.12.2                | minecraft.jar                                     | None                                     |     | LCHIJA | mcp                         | 9.42                  | minecraft.jar                                     | None                                     |     | LCHIJA | FML                         | 8.0.99.99             | forge-1.12.2-14.23.5.2859.jar                     | e3c3d50c7c986df74c645c0ac54639741c90a557 |     | LCHIJA | forge                       | 14.23.5.2859          | forge-1.12.2-14.23.5.2859.jar                     | e3c3d50c7c986df74c645c0ac54639741c90a557 |     | LCHIJA | openmodscore                | 0.12.2                | minecraft.jar                                     | None                                     |     | LCHIJA | obfuscate                   | 0.4.2                 | minecraft.jar                                     | None                                     |     | LCHIJA | securitycraft               | v1.9.9                | [1.12.2] SecurityCraft v1.9.9.jar                 | None                                     |     | LCHIJA | mts                         | 22.14.2               | Immersive Vehicles-1.12.2-22.14.2.jar             | None                                     |     | LCHIJA | mtsaircooled                | 1.0.1                 | Air-Cooled Pack [MTS] 1.10.2-14.0.0-1.0.1.jar     | None                                     |     | LCHIJA | codechickenlib              | 3.2.3.358             | CodeChickenLib-1.12.2-3.2.3.358-universal.jar     | f1850c39b2516232a2108a7bd84d1cb5df93b261 |     | LCHIJA | ancientwarfare              | 1.12.2-2.7.0.1038     | ancientwarfare-1.12.2-2.7.0.1038.jar              | None                                     |     | LCHIJA | redstoneflux                | 2.1.1                 | RedstoneFlux-1.12-2.1.1.1-universal.jar           | None                                     |     | LCHIJA | ancientwarfareautomation    | 1.12.2-2.7.0.1038     | ancientwarfare-1.12.2-2.7.0.1038.jar              | None                                     |     | LCHIJA | ancientwarfarenpc           | 1.12.2-2.7.0.1038     | ancientwarfare-1.12.2-2.7.0.1038.jar              | None                                     |     | LCHIJA | ancientwarfarestructure     | 1.12.2-2.7.0.1038     | ancientwarfare-1.12.2-2.7.0.1038.jar              | None                                     |     | LCHIJA | ancientwarfarevehicle       | 1.12.2-2.7.0.1038     | ancientwarfare-1.12.2-2.7.0.1038.jar              | None                                     |     | LCHIJA | craftstudioapi              | 1.0.0                 | CraftStudio-1.0.0.93-mc1.12-alpha.jar             | None                                     |     | LCHIJA | animania                    | 2.0.3.28              | animania-1.12.2-base-2.0.3.28.jar                 | None                                     |     | LCHIJA | architecturecraft           | @VERSION@             | architecturecraft-1.12-3.108.jar                  | None                                     |     | LCHIJA | betteranimationscollection2 | 1.0.2                 | BetterAnimationsCollection2-v1.0.2-1.12.2.jar     | 12d137bcc36051a1c2c8ea7211cfc1da1c6e9dea |     | LCHIJA | forgelin                    | 1.8.3                 | Forgelin-1.8.3.jar                                | None                                     |     | LCHIJA | betterfoliage               | 2.3.1                 | BetterFoliage-MC1.12-2.3.2.jar                    | None                                     |     | LCHIJA | bibliocraft                 | 2.4.6                 | BiblioCraft[v2.4.6][MC1.12.2].jar                 | None                                     |     | LCHIJA | biomestaff                  | 1.0.0                 | BiomeStaff-1.12.2-1.0.0.jar                       | None                                     |     | LCHIJA | blockcraftery               | 1.12.2-1.3.1          | blockcraftery-1.12.2-1.3.1.jar                    | None                                     |     | LCHIJA | bookshelf                   | 2.3.590               | Bookshelf-1.12.2-2.3.590.jar                      | d476d1b22b218a10d845928d1665d45fce301b27 |     | LCHIJA | bookworm                    | 1.12.2-2.5.2.1        | Bookworm-Library-Mod-1.12.2.jar                   | None                                     |     | LCHIJA | brandonscore                | 2.4.20                | BrandonsCore-1.12.2-2.4.20.162-universal.jar      | None                                     |     | LCHIJA | bspkrscore                  | 8.0.0                 | BspkrsCore-1.12.2.jar                             | None                                     |     | LCHIJA | carpentersblocks            | 3.4.0-poc.6           | Carpenters-Blocks-v3.4.0-poc.6-MC-1.12.2.jar      | None                                     |     | LCHIJA | ctm                         | MC1.12.2-1.0.2.31     | CTM-MC1.12.2-1.0.2.31.jar                         | None                                     |     | LCHIJA | jei                         | 4.16.1.1012           | jei_1.12.2-4.16.1.1012.jar                        | None                                     |     | LCHIJA | chisel                      | MC1.12.2-1.0.2.45     | Chisel-Mod-1.12.2.jar                             | None                                     |     | LCHIJA | chiselsandbits              | 14.33                 | chiselsandbits-14.33.jar                          | None                                     |     | LCHIJA | customspawner               | 3.11.4                | CustomMobSpawner-3.11.5.jar                       | None                                     |     | LCHIJA | customsignposts             | 1.0                   | customsignposts-1.12.2-1.0.1.jar                  | None                                     |     | LCHIJA | ptrmodellib                 | 1.0.5                 | PTRLib-1.0.5.jar                                  | None                                     |     | LCHIJA | props                       | 2.6.3.7               | Decocraft-2.6.3.7_1.12.2.jar                      | None                                     |     | LCHIJA | mocreatures                 | 12.0.5                | DrZharks MoCreatures Mod-12.0.5.jar               | None                                     |     | LCHIJA | engineersdecor              | 1.1.5                 | engineersdecor-1.12.2-1.1.5.jar                   | ed58ed655893ced6280650866985abcae2bf7559 |     | LCHIJA | exoticbirds                 | 1.0                   | Exotic Birds 1.12.2-3.2.0.jar                     | None                                     |     | LCHIJA | unuparts                    | 6.5.0                 | UNU Parts Pack [MTS] 1.12.2-22.13.0-6.5.0.jar     | None                                     |     | LCHIJA | unuverse                    | 2.0.0                 | ExpandedUNUversePack[MTS]1.12.2-19.15.5-2.0.0.jar | None                                     |     | LCHIJA | fairylights                 | 2.1.10                | fairylights-2.2.0-1.12.2.jar                      | None                                     |     | LCHIJA | fcl                         | 1.12.82               | FCL-1.12.82c.jar                                  | None                                     |     | LCHIJA | net/fexcraft/lib/frl        | 1.2                   | FCL-1.12.82c.jar                                  | None                                     |     | LCHIJA | net/fexcraft/lib/tmt        | 1.15                  | FCL-1.12.82c.jar                                  | None                                     |     | LCHIJA | famm                        | 3.4.0                 | Fexs-Alphabet-and-More-Mod-Forge-1.12.2.jar       | None                                     |     | LCHIJA | forgemultipartcbe           | 2.6.2.83              | ForgeMultipart-1.12.2-2.6.2.83-universal.jar      | f1850c39b2516232a2108a7bd84d1cb5df93b261 |     | LCHIJA | microblockcbe               | 2.6.2.83              | ForgeMultipart-1.12.2-2.6.2.83-universal.jar      | None                                     |     | LCHIJA | minecraftmultipartcbe       | 2.6.2.83              | ForgeMultipart-1.12.2-2.6.2.83-universal.jar      | None                                     |     | LCHIJA | funkylocomotion             | 1.0                   | funky-locomotion-1.12.2-1.1.2.jar                 | None                                     |     | LCHIJA | furenikusroads              | 1.2.5                 | Furenikus_Roads-1.2.5.jar                         | None                                     |     | LCHIJA | cfm                         | 6.3.0                 | furniture-6.3.2-1.12.2.jar                        | None                                     |     | LCHIJA | waila                       | 1.8.22                | Hwyla-1.8.22-B37_1.12.jar                         | None                                     |     | LCHIJA | trackapi                    | 1.2                   | TrackAPI-1.2.jar                                  | None                                     |     | LCHIJA | universalmodcore            | 1.2.1                 | UniversalModCore-1.12.2-forge-1.2.1.jar           | None                                     |     | LCHIJA | immersiverailroading        | 1.10.0                | ImmersiveRailroading-1.12.2-forge-1.10.0.jar      | None                                     |     | LCHIJA | journeymap                  | 1.12.2-5.7.1p2        | journeymap-1.12.2-5.7.1p2.jar                     | None                                     |     | LCHIJA | zawa                        | 1.12.2-2.1.3          | zawa-1.12.2-2.1.3.jar                             | 3ee471ded1bba54aa82f4f5ca5ca82dd67b8ef42 |     | LCHIJA | lilcritters                 | 1.12.2-1.1.0.0        | Lil-Critters-Mod-Forge-1.12.2.jar                 | None                                     |     | LCHIJA | malisiscore                 | 1.12.2-6.5.1-SNAPSHOT | MalisisCore-1.12.2.jar                            | None                                     |     | LCHIJA | malisisdoors                | 1.12.2-7.3.0          | MalisisDoors-Mod-1.12.2.jar                       | None                                     |     | LCHIJA | mcwbridges                  | 1.0.6                 | mcw-bridges-1.0.6b-mc1.12.2.jar                   | None                                     |     | LCHIJA | mcwfences                   | 1.0.0                 | mcw-fences-1.0.0-mc1.12.2.jar                     | None                                     |     | LCHIJA | mcwroofs                    | 1.0.2                 | mcw-roofs-1.0.2-mc1.12.2.jar                      | None                                     |     | LCHIJA | moon-core                   | 7.0                   | Moons-Core-Forge-1.12.2.jar                       | None                                     |     | LCHIJA | mrtjpcore                   | 2.1.4.43              | MrTJPCore-1.12.2-2.1.4.43-universal.jar           | None                                     |     | LCHIJA | railcraft                   | 12.0.0                | railcraft-12.0.0.jar                              | a0c255ac501b2749537d5824bb0f0588bf0320fa |     | LCHIJA | mtr                         | 3.0.0                 | MTR-1.12.2-alpha-test-0.0.1.jar                   | None                                     |     | LCHIJA | kadwinjpvehicles            | 2.0.0                 | MTS_Kadwin_JP_Vehicles_Pack_4.1.jar               | None                                     |     | LCHIJA | ngtlib                      | 2.4.21                | NGTLib2.4.21-38_forge-1.12.2-14.23.2.2611.jar     | None                                     |     | LCHIJA | projectintelligence         | 1.0.9                 | ProjectIntelligence-1.12.2-1.0.9.28-universal.jar | None                                     |     | LCHIJA | nei                         | 2.4.3                 | NotEnoughItems-1.12.2-2.4.3.245-universal.jar     | f1850c39b2516232a2108a7bd84d1cb5df93b261 |     | LCHIJA | oe                          | 1.0.7                 | OceanicExpanse-1.0.7.jar                          | None                                     |     | LCHIJA | openmods                    | 0.12.2                | OpenModsLib-1.12.2-0.12.2.jar                     | d2a9a8e8440196e26a268d1f3ddc01b2e9c572a5 |     | LCHIJA | openblocks                  | 1.8.1                 | OpenBlocks-1.12.2-1.8.1.jar                       | d2a9a8e8440196e26a268d1f3ddc01b2e9c572a5 |     | LCHIJA | placeableitems              | 3.3                   | placeableitems-3.3.jar                            | None                                     |     | LCHIJA | projectred-core             | 4.9.4.120             | ProjectRed-1.12.2-4.9.4.120-Base.jar              | None                                     |     | LCHIJA | projectred-integration      | 4.9.4.120             | ProjectRed-1.12.2-4.9.4.120-integration.jar       | None                                     |     | LCHIJA | projectred-transmission     | 4.9.4.120             | ProjectRed-1.12.2-4.9.4.120-integration.jar       | None                                     |     | LCHIJA | projectred-illumination     | 4.9.4.120             | ProjectRed-1.12.2-4.9.4.120-lighting.jar          | None                                     |     | LCHIJA | projectred-expansion        | 4.9.4.120             | ProjectRed-1.12.2-4.9.4.120-mechanical.jar        | None                                     |     | LCHIJA | projectred-relocation       | 4.9.4.120             | ProjectRed-1.12.2-4.9.4.120-mechanical.jar        | None                                     |     | LCHIJA | projectred-transportation   | 4.9.4.120             | ProjectRed-1.12.2-4.9.4.120-mechanical.jar        | None                                     |     | LCHIJA | rtm                         | 2.4.24                | RTM2.4.24-43_forge-1.12.2-14.23.2.2611.jar        | None                                     |     | LCHIJA | trafficcontrol              | 1.1.1                 | trafficcontrol-1.1.1.jar                          | None                                     |     | LCHIJA | travelersbackpack           | 1.0.35                | TravelersBackpack-1.12.2-1.0.35.jar               | None                                     |     | LCHIJA | iv_tpp                      | 2.22.0                | Trin Parts Pack-1.12.2-2.23.1.jar                 | None                                     |     | LCHIJA | unucivil                    | 6.3.0                 | UNU Civilian Pack [MTS] 1.12.2-22.13.0-6.3.0.jar  | None                                     |     | LCHIJA | vehicle                     | 0.44.1                | vehicle-mod-0.44.1-1.12.2.jar                     | None                                     |     | LCHIJA | wawla                       | 2.6.275               | Wawla-1.12.2-2.6.275.jar                          | d476d1b22b218a10d845928d1665d45fce301b27 |     | LCHIJA | worldedit                   | 6.1.10                | worldedit-forge-mc1.12.2-6.1.10-dist.jar          | None                                     |     | LCHIJA | worldstatecheckpoints       | 1.12.2.1.2.1          | WorldStateCheckpoints-client-1.12.2.1.2.1.jar     | None                                     |     | LCHIJA | wrcbe                       | 2.3.2                 | WR-CBE-1.12.2-2.3.2.33-universal.jar              | f1850c39b2516232a2108a7bd84d1cb5df93b261 |     | LCHIJA | zoocraftdiscoveries         | 1.0                   | Zoocraft+Discoveries+1.12.2-1.3.0.jar             | None                                     |     | LCHIJA | immersiveengineering        | 0.12-98               | ImmersiveEngineering-0.12-98.jar                  | None                                     |     | LCHIJA | fix-rtm                     | 2.0.28                | fixRtm-2.0.28.jar                                 | None                                     |     | LCHIJA | mysticallib                 | 1.12.2-1.13.0         | mysticallib-1.12.2-1.13.0.jar                     | None                                     |     Loaded coremods (and transformers): ForgelinPlugin (Forgelin-1.8.3.jar)   PatchingFixRtmCorePlugin (fixRtm-2.0.28.jar)   com.anatawa12.fixRtm.asm.patching.PatchApplier IELoadingPlugin (ImmersiveEngineering-core-0.12-98.jar)   blusunrize.immersiveengineering.common.asm.IEClassTransformer FixRtmCorePlugin (fixRtm-2.0.28.jar)   JarInJarLoaderCoreMod (fixRtm-2.0.28.jar)   com.anatawa12.fixRtm.jarInJar.JarInJarPatcher BetterFoliageLoader (BetterFoliage-MC1.12-2.3.2.jar)   mods.betterfoliage.loader.BetterFoliageTransformer SecurityCraftLoadingPlugin ([1.12.2] SecurityCraft v1.9.9.jar)   OpenModsCorePlugin (OpenModsLib-1.12.2-0.12.2.jar)   openmods.core.OpenModsClassTransformer MalisisCorePlugin (MalisisCore-1.12.2.jar)   ObfuscatePlugin (obfuscate-0.4.2-1.12.2.jar)   com.mrcrayfish.obfuscate.asm.ObfuscateTransformer CTMCorePlugin (CTM-MC1.12.2-1.0.2.31.jar)   team.chisel.ctm.client.asm.CTMTransformer HookingFixRtmCorePlugin (fixRtm-2.0.28.jar)   com.anatawa12.fixRtm.asm.hooking.HookingTransformer     GL info: ' Vendor: 'NVIDIA Corporation' Version: '4.6.0 NVIDIA 551.86' Renderer: 'NVIDIA GeForce RTX 3070/PCIe/SSE2'     OpenModsLib class transformers: [llama_null_fix:FINISHED],[horse_base_null_fix:FINISHED],[pre_world_render_hook:FINISHED],[player_render_hook:FINISHED],[horse_null_fix:FINISHED]     RTM Model Status: Initialized 1048 models, Using 0 models     I = Initialized, C = Constructed, SMP = SMP includeds     | model pack                                      | all | I | C   | SMP |     |:----------------------------------------------- |:--- |:- |:--- |:--- |     | mods\ModelPack_Nak_5_Structure_240313.zip       | 458 | 0 | 458 | 0   |     | mods\RTM2.4.24-43_forge-1.12.2-14.23.2.2611.jar | 281 | 0 | 281 | 0   |     | mods\rtm_Saracalias Pack v0.2.01.zip            | 309 | 0 | 309 | 0   |     Launched Version: 1.12.2-forge-14.23.5.2859     LWJGL: 2.9.4     OpenGL: NVIDIA GeForce RTX 3070/PCIe/SSE2 GL version 4.6.0 NVIDIA 551.86, NVIDIA Corporation     GL Caps: Using GL 1.3 multitexturing. Using GL 1.3 texture combiners. Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported. Shaders are available because OpenGL 2.1 is supported. VBOs are available because OpenGL 1.5 is supported.     Using VBOs: Yes     Is Modded: Definitely; Client brand changed to 'fml,forge'     Type: Client (map_client.txt)     Resource Packs: NickMiner69V2.zip, MPT-4.zip, feldbahnpackv1-3.zip, G_P_Narrow_Gauge_Texel_Pack_V1.0.3.zip     Current Language: English (US)     Profiler Position: N/A (disabled)     CPU: 8x Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz     OptiFine Version: OptiFine_1.12.2_HD_U_G5     OptiFine Build: 20210124-142939     Render Distance Chunks: 12     Mipmaps: 4     Anisotropic Filtering: 1     Antialiasing: 0     Multitexture: false     Shaders: null     OpenGlVersion: 4.6.0 NVIDIA 551.86     OpenGlRenderer: NVIDIA GeForce RTX 3070/PCIe/SSE2     OpenGlVendor: NVIDIA Corporation     CpuCount: 8
    • i notice a change if i add the min and max ram in the line like this for example:    # Xmx and Xms set the maximum and minimum RAM usage, respectively. # They can take any number, followed by an M or a G. # M means Megabyte, G means Gigabyte. # For example, to set the maximum to 3GB: -Xmx3G # To set the minimum to 2.5GB: -Xms2500M # A good default for a modded server is 4GB. # Uncomment the next line to set it. -Xmx10240M -Xms8192M    i need to make more experiments but for now this apparently works.
    • This honestly might just work for you @SubscribeEvent public static void onScreenRender(ScreenEvent.Render.Post event) { final var player = Minecraft.getInstance().player; final var options = Minecraft.getInstance().options; if(!hasMyEffect(player)) return; // TODO: You provide hasMyEffect float f = Mth.lerp(event.getPartialTick(), player.oSpinningEffectIntensity, player.spinningEffectIntensity); float f1 = ((Double)options.screenEffectScale().get()).floatValue(); if(f <= 0F || f1 >= 1F) return; float p_282656_ = f * (1.0F - f1); final var p_282460_ = event.getGuiGraphics(); int i = p_282460_.guiWidth(); int j = p_282460_.guiHeight(); p_282460_.pose().pushPose(); float f5 = Mth.lerp(p_282656_, 2.0F, 1.0F); p_282460_.pose().translate((float)i / 2.0F, (float)j / 2.0F, 0.0F); p_282460_.pose().scale(f5, f5, f5); p_282460_.pose().translate((float)(-i) / 2.0F, (float)(-j) / 2.0F, 0.0F); float f4 = 0.2F * p_282656_; float f2 = 0.4F * p_282656_; float f3 = 0.2F * p_282656_; RenderSystem.disableDepthTest(); RenderSystem.depthMask(false); RenderSystem.enableBlend(); RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE); p_282460_.setColor(f4, f2, f3, 1.0F); p_282460_.blit(new ResourceLocation("textures/misc/nausea.png"), 0, 0, -90, 0.0F, 0.0F, i, j, i, j); p_282460_.setColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.defaultBlendFunc(); RenderSystem.disableBlend(); RenderSystem.depthMask(true); RenderSystem.enableDepthTest(); p_282460_.pose().popPose(); }   Note: Most of this is directly copied from GameRenderer as you pointed out you found. The only thing you'll have to likely do is update the `oSpinningEffectIntensity` + `spinningEffectIntensity` variables on the player when your effect is applied. Which values should be there? Not 100% sure, might be a game of guess and check, but `handleNetherPortalClient` in LocalPlayer has some hard coded you might be able to start with.
  • Topics

×
×
  • Create New...

Important Information

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