Jump to content

DarkGuardsman

Forge Modder
  • Posts

    1479
  • Joined

  • Last visited

Everything posted by DarkGuardsman

  1. ok i took a look at both client & server code for the Wolf. I found i'm using datawatchers already in the same way wolf.class does. So is there a special way to use datawatcher to get them to link from server to client. here is client side EntityGuard class package net.minecraft.src.GSM; import java.util.*; import net.minecraft.src.*; public class EntityGuardBase extends EntityCreature { /** How much damage this mob's attacks deal */ protected static int attackStrength; public static int team; public static int type; public EntityGuardBase(World par1World) { this(par1World,1, 1); } public EntityGuardBase(World par1World, int Team, int Type) { super(par1World); attackStrength = 5; experienceValue = 5; this.moveSpeed = 0.3F; team = Team; type = Type; this.setProfession(Type); this.setTeam(Team); this.setTextureTeamType(); //tasks this.tasks.addTask(1, new EntityAISwimming(this)); this.tasks.addTask(2, new EntityAIAvoidEntity(this, EntityCreeper.class, 2.0F, 0.3F, 0.35F)); if(Type == 1){this.tasks.addTask(3, new EntityAIArrowAttack(this, this.moveSpeed, 1, 50));} this.tasks.addTask(9, new EntityAIWander(this, this.moveSpeed)); this.tasks.addTask(10, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F)); this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false)); this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityMob.class, 16.0F, 0, true)); this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 16.0F, 0, false)); } public void setTextureTeamType() { texture = "/mob/char.png"; if(this.getTeam() ==1) { texture = "/GSM/NPC/Red" + this.getProfession() + ".png"; } if(this.getTeam() == 2) { texture = "/GSM/NPC/Blue" + this.getProfession() + ".png"; } } protected boolean canDespawn() { return false; } public void onLivingUpdate(){super.onLivingUpdate();} public void onUpdate(){ super.onUpdate(); if(worldObj.isRemote) { updateFromSmp(); } } public boolean getCanSpawnHere(){return true;} public int getMaxHealth(){return 50;} public boolean isAIEnabled(){return true;} protected Entity findPlayerToAttack() { EntityPlayer entityplayer = worldObj.getClosestVulnerablePlayerToEntity(this, 16D); if (entityplayer != null && canEntityBeSeen(entityplayer)) { return entityplayer; } else { return null; } } public boolean attackEntityFrom(DamageSource par1DamageSource, int par2) { if (super.attackEntityFrom(par1DamageSource, par2)) { Entity entity = par1DamageSource.getEntity(); if (riddenByEntity == entity || ridingEntity == entity) { return true; } if (entity != this || entity.entityId != this.entityId ) { entityToAttack = entity; } return true; } else { return false; } } public boolean attackEntityAsMob(Entity par1Entity) { int i = attackStrength; if (isPotionActive(Potion.damageBoost)) { i += 3 << getActivePotionEffect(Potion.damageBoost).getAmplifier(); } if (isPotionActive(Potion.weakness)) { i -= 2 << getActivePotionEffect(Potion.weakness).getAmplifier(); } return par1Entity.attackEntityFrom(DamageSource.causeMobDamage(this), i); } protected void attackEntity(Entity par1Entity, float par2) { if (attackTime <= 0 && par2 < 2.0F && par1Entity.boundingBox.maxY > boundingBox.minY && par1Entity.boundingBox.minY < boundingBox.maxY) { attackTime = 20; attackEntityAsMob(par1Entity); } } public float getBlockPathWeight(int par1, int par2, int par3) { return 0.5F + worldObj.getLightBrightness(par1, par2, par3); } //Write public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) { super.writeEntityToNBT(par1NBTTagCompound); par1NBTTagCompound.setInteger("Profession", this.getProfession()); par1NBTTagCompound.setInteger("Team", this.getTeam()); } //Read public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) { super.readEntityFromNBT(par1NBTTagCompound); this.setProfession(par1NBTTagCompound.getInteger("Profession")); this.setTeam(par1NBTTagCompound.getInteger("Team")); this.setTextureTeamType(); this.getHeldItem(); } public void updateFromSmp() { setTeam(net.minecraft.src.mod_Guardsman.coords[0]); setProfession(net.minecraft.src.mod_Guardsman.coords[1]); } protected void entityInit() { super.entityInit(); this.dataWatcher.addObject(20, Integer.valueOf(0)); this.dataWatcher.addObject(21, Integer.valueOf(0)); } public void setProfession(int par1) { this.dataWatcher.updateObject(20, Integer.valueOf(par1)); } public int getProfession() { return this.dataWatcher.getWatchableObjectInt(20); } public void setTeam(int par1) { this.dataWatcher.updateObject(21, Integer.valueOf(par1)); } public int getTeam() { return this.dataWatcher.getWatchableObjectInt(21); } @Override public ItemStack getHeldItem() { if(this.getProfession() == 1) { return new ItemStack(Item.bow, 1); } else { return null; } } } And here is the server side package net.minecraft.src.GSM; import java.io.*; import java.util.*; import net.minecraft.src.*; public class EntityGuardBase extends EntityCreature implements IAnimals { /** How much damage this mob's attacks deal */ protected static int attackStrength; public static int team; public static int type; public EntityGuardBase(World par1World) { this(par1World,1, 1); } public EntityGuardBase(World par1World, int Team, int Type) { super(par1World); attackStrength = 5; experienceValue = 5; this.moveSpeed = 0.3F; team = Team; type = Type; this.setProfession(Type); this.setTeam(Team); //tasks this.tasks.addTask(2, new EntityAISwimming(this)); this.tasks.addTask(2, new EntityAIAvoidEntity(this, EntityCreeper.class, 2.0F, 0.3F, 0.35F)); if(Type == 1){this.tasks.addTask(3, new EntityAIArrowAttack(this, this.moveSpeed, 1, 50));} this.tasks.addTask(9, new EntityAIWander(this, this.moveSpeed)); this.tasks.addTask(10, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F)); this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false)); this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, IMob.class, 16.0F, 0, true)); this.targetTasks.addTask(1, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 16.0F, 0, false)); } private String[] getTeamList() { if(getTeam() == 1) { return net.minecraft.src.GSM.ConfigMaker.red; } if(getTeam() == 2) { return net.minecraft.src.GSM.ConfigMaker.blue; } return null; } public void SendType(int i, int j, Entity entity) { int k = entity.entityId; ByteArrayOutputStream bytes = new ByteArrayOutputStream(); DataOutputStream data = new DataOutputStream(bytes); try { int[] coords = {i, j, k}; for(int a = 0; a < 3; a++) { data.writeInt(coords[a]); } } catch(IOException e) { e.printStackTrace(); } Packet250CustomPayload packet = new Packet250CustomPayload(); packet.channel = "mod_Guardsman"; // CHANNEL MAX 16 CHARS packet.data = bytes.toByteArray(); packet.length = packet.data.length; ModLoader.getMinecraftServerInstance().configManager.sendPacketToAllPlayers(packet); } protected boolean canDespawn() { return false; } public void onLivingUpdate(){super.onLivingUpdate();} public void onUpdate(){ super.onUpdate(); findPlayerToAttack(); SendType(getTeam(), getProfession(), this); } public boolean getCanSpawnHere(){return true;} public int getMaxHealth(){return 50;} public boolean isAIEnabled(){return true;} protected Entity findPlayerToAttack() { EntityPlayer entityplayer = worldObj.getClosestVulnerablePlayerToEntity(this, 16D); if (entityplayer != null && canEntityBeSeen(entityplayer)) { if(getTeam() == 1) { for(int j = 0; j > 21; j++) { if (entityplayer.username.equals(net.minecraft.src.GSM.ConfigMaker.red[j])) { return null; } } } if(getTeam() == 2) { for(int j = 0; j > 21; j++) { if (entityplayer.username.equals(net.minecraft.src.GSM.ConfigMaker.blue[j])) { return null; } } } } return entityplayer; } private boolean compareNameToTeam (String name, String[] Team) { if (Team != null && name != null ) { } return true; } public boolean attackEntityFrom(DamageSource par1DamageSource, int par2) { if (super.attackEntityFrom(par1DamageSource, par2)) { Entity entity = par1DamageSource.getEntity(); if (riddenByEntity == entity || ridingEntity == entity) { return true; } if (entity != this || entity.entityId != this.entityId ) { entityToAttack = entity; } return true; } else { return false; } } public boolean attackEntityAsMob(Entity par1Entity) { int i = attackStrength; if (isPotionActive(Potion.damageBoost)) { i += 3 << getActivePotionEffect(Potion.damageBoost).getAmplifier(); } if (isPotionActive(Potion.weakness)) { i -= 2 << getActivePotionEffect(Potion.weakness).getAmplifier(); } return par1Entity.attackEntityFrom(DamageSource.causeMobDamage(this), i); } protected void attackEntity(Entity par1Entity, float par2) { if (attackTime <= 0 && par2 < 2.0F && par1Entity.boundingBox.maxY > boundingBox.minY && par1Entity.boundingBox.minY < boundingBox.maxY) { attackTime = 20; attackEntityAsMob(par1Entity); } } public float getBlockPathWeight(int par1, int par2, int par3) { return 0.5F + worldObj.getLightBrightness(par1, par2, par3); } //Write public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) { super.writeEntityToNBT(par1NBTTagCompound); par1NBTTagCompound.setInteger("Profession", this.getProfession()); par1NBTTagCompound.setInteger("Team", this.getTeam()); } //Read public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) { super.readEntityFromNBT(par1NBTTagCompound); this.setProfession(par1NBTTagCompound.getInteger("Profession")); this.setTeam(par1NBTTagCompound.getInteger("Team")); this.getHeldItem(); } protected void entityInit() { super.entityInit(); this.dataWatcher.addObject(20, Integer.valueOf(0)); this.dataWatcher.addObject(21, Integer.valueOf(0)); } public void setProfession(int par1) { this.dataWatcher.updateObject(20, Integer.valueOf(par1)); } public int getProfession() { return this.dataWatcher.getWatchableObjectInt(20); } public void setTeam(int par1) { this.dataWatcher.updateObject(21, Integer.valueOf(par1)); } public int getTeam() { return this.dataWatcher.getWatchableObjectInt(21); } public ItemStack getHeldItem() { if(this.getProfession() == 1) { return new ItemStack(Item.bow, 1); } else { return null; } } }
  2. Doing an if statement that compares the player's keyboard input might be what you need.
  3. thank you for the responce My code is based off a tuturial i read up on how to move from Modloadermp to Forge network. So some of my code is about a complete match at the moment. When i do code clean up when the mod works i'll go threw and rename/recode everything cleaner. Later on i'll build on the send data to have more than 2 int so thats why i keep the loop. Makes things easier when i start to send data that will be used in GUIs used to interface with the guard. Also i think the data has to be stored as a byte array inorder to be sent without overriding the first number. The properties are set as ints to make it possible to send and store as an array. Int (i) is the team id and Int(j) is the weapon type. Both are set when SendType is called during updating of the entity. Texture is done client side by picking first the team color then the profession texture to go with the weapon.
  4. In my mod i have a single EntityGuard.class that does everything related to that Entity. Part of the class is picking the weapon, team and texture of the Entity to be displayed to the player. The problem is that on smp every guard show up the same. Too fix this i'm trying to use Forge network packet system but nothing seem to be changing. Could someone help me with the code needed to send that data required for the guard entities to update correctly. here the what i'm using to send the packet public void SendType(int i, int j, Entity entity) { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); DataOutputStream data = new DataOutputStream(bytes); try { int[] coords = {i, j}; for(int a = 0; a < 2; a++) { data.writeInt(coords[a]); } } catch(IOException e) { e.printStackTrace(); } Packet250CustomPayload packet = new Packet250CustomPayload(); packet.channel = "mod_Guardsman"; packet.data = bytes.toByteArray(); packet.length = packet.data.length; ModLoader.getMinecraftServerInstance().configManager.sendPacketToAllPlayers(packet); } and here is what is reciving it public void onPacketData(NetworkManager network, String channel, byte[] bytes) { DataInputStream dataStream = new DataInputStream(new ByteArrayInputStream(bytes)); try { for(int i = 0; i < 3; i++) { coords[i] = dataStream.readInt(); } } catch(IOException e) { e.printStackTrace(); } }
×
×
  • Create New...

Important Information

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