Skip to content
This repository has been archived by the owner on Mar 9, 2020. It is now read-only.

Commit

Permalink
Merge pull request #12 from jjtParadox/networking-cleanup
Browse files Browse the repository at this point in the history
Networking cleanup & some feature re-enable
  • Loading branch information
jjtParadox authored Nov 27, 2017
2 parents 1205aac + 63bf25b commit d9da180
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 188 deletions.
2 changes: 1 addition & 1 deletion src/main/java/am2/gui/AuraCustomizationMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void onGuiClosed(){

byte[] data = writer.generate();

AMNetHandler.INSTANCE.sendPacketToServer(AMPacketIDs.SYNC_BETA_PARTICLES, data);
// AMNetHandler.INSTANCE.sendPacketToServer(AMPacketIDs.SYNC_BETA_PARTICLES, data);

ArsMagica2.config.save();

Expand Down
9 changes: 5 additions & 4 deletions src/main/java/am2/handler/EntityHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public void playerTick (EntityPlayer player) {
}
}
if (player.worldObj.isRemote)
AMNetHandler.INSTANCE.sendPacketToServer(AMPacketIDs.PLAYER_FLIP, new AMDataWriter().add(ext.getIsFlipped()).generate());
AMNetHandler.INSTANCE.sendPacketToServer(AMPacketIDs.PLAYER_FLIP, new AMDataWriter().add(ext.getIsFlipped()).generate()); // This needs optimizing
if (ext.getIsFlipped()){
if ((player).motionY < 2 && !player.capabilities.isFlying)
(player).motionY += 0.15f;
Expand Down Expand Up @@ -503,9 +503,10 @@ public void onItemPickup(ItemPickupEvent event) {

if (!event.player.worldObj.isRemote && EntityExtension.For(event.player).getCurrentLevel() <= 0 && event.pickedUp.getEntityItem().getItem() == ItemDefs.arcaneCompendium){
event.player.addChatMessage(new TextComponentString("You have unlocked the secrets of the arcane!"));
AMNetHandler.INSTANCE.sendCompendiumUnlockPacket((EntityPlayerMP)event.player, "shapes", true);
AMNetHandler.INSTANCE.sendCompendiumUnlockPacket((EntityPlayerMP)event.player, "components", true);
AMNetHandler.INSTANCE.sendCompendiumUnlockPacket((EntityPlayerMP)event.player, "modifiers", true);
// Not implemented client side
// AMNetHandler.INSTANCE.sendCompendiumUnlockPacket((EntityPlayerMP)event.player, "shapes", true);
// AMNetHandler.INSTANCE.sendCompendiumUnlockPacket((EntityPlayerMP)event.player, "components", true);
// AMNetHandler.INSTANCE.sendCompendiumUnlockPacket((EntityPlayerMP)event.player, "modifiers", true);
EntityExtension.For(event.player).setMagicLevelWithMana(1);
return;
}
Expand Down
120 changes: 60 additions & 60 deletions src/main/java/am2/packet/AMNetHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,20 @@ public void sendVelocityAddPacket(World world, EntityLivingBase target, double v
sendPacketToAllClientsNear(world.provider.getDimension(), target.posX, target.posY, target.posZ, 50, AMPacketIDs.PLAYER_VELOCITY_ADD, data);
}

@SideOnly(Side.CLIENT)
public void requestAuras(EntityPlayer player){
AMDataWriter writer = new AMDataWriter();
EntityPlayer localPlayer = Minecraft.getMinecraft().thePlayer;
if (localPlayer == null) return;
writer.add(localPlayer.getEntityId());
writer.add(player.getEntityId());

sendPacketToServer(AMPacketIDs.REQUEST_BETA_PARTICLES, writer.generate());
}

public void requestClientAuras(EntityPlayerMP player){
sendPacketToClientPlayer((EntityPlayerMP)player, AMPacketIDs.SYNC_BETA_PARTICLES, new byte[0]);
}
// @SideOnly(Side.CLIENT)
// public void requestAuras(EntityPlayer player){
// AMDataWriter writer = new AMDataWriter();
// EntityPlayer localPlayer = Minecraft.getMinecraft().thePlayer;
// if (localPlayer == null) return;
// writer.add(localPlayer.getEntityId());
// writer.add(player.getEntityId());
//
// sendPacketToServer(AMPacketIDs.REQUEST_BETA_PARTICLES, writer.generate());
// }
//
// public void requestClientAuras(EntityPlayerMP player){
// sendPacketToClientPlayer((EntityPlayerMP)player, AMPacketIDs.SYNC_BETA_PARTICLES, new byte[0]);
// }

public void syncWorldName(EntityPlayerMP player, String name){
sendPacketToClientPlayer((EntityPlayerMP)player, AMPacketIDs.SYNC_WORLD_NAME, new AMDataWriter().add(name).generate());
Expand Down Expand Up @@ -158,21 +158,21 @@ public void sendStarImpactToClients(double x, double y, double z, World world, I
sendPacketToAllClientsNear(world.provider.getDimension(), x, y, z, 64, AMPacketIDs.STAR_FALL, writer.generate());
}

public void sendSilverSkillPointPacket(EntityPlayerMP player){
sendPacketToClientPlayer(player, AMPacketIDs.HIDDEN_COMPONENT_UNLOCK, new byte[0]);
}

public void sendSpellApplyEffectToAllAround(EntityLivingBase caster, Entity target, double x, double y, double z, World world, ItemStack spellStack){
AMDataWriter writer = new AMDataWriter().add(x).add(y).add(z);
if (spellStack != null)
writer.add(true).add(spellStack);
else
writer.add(false);
writer.add(caster.getEntityId());
writer.add(target.getEntityId());

sendPacketToAllClientsNear(world.provider.getDimension(), x, y, z, 64, AMPacketIDs.SPELL_APPLY_EFFECT, writer.generate());
}
// public void sendSilverSkillPointPacket(EntityPlayerMP player){
// sendPacketToClientPlayer(player, AMPacketIDs.HIDDEN_COMPONENT_UNLOCK, new byte[0]);
// }

// public void sendSpellApplyEffectToAllAround(EntityLivingBase caster, Entity target, double x, double y, double z, World world, ItemStack spellStack){
// AMDataWriter writer = new AMDataWriter().add(x).add(y).add(z);
// if (spellStack != null)
// writer.add(true).add(spellStack);
// else
// writer.add(false);
// writer.add(caster.getEntityId());
// writer.add(target.getEntityId());
//
// sendPacketToAllClientsNear(world.provider.getDimension(), x, y, z, 64, AMPacketIDs.SPELL_APPLY_EFFECT, writer.generate());
// }

public void sendHecateDeathToAllAround(EntityHecate hecate){
AMDataWriter writer = new AMDataWriter();
Expand Down Expand Up @@ -233,34 +233,34 @@ public void sendPowerResponseToClient(NBTTagCompound powerData, EntityPlayerMP p
sendPacketToClientPlayer(player, AMPacketIDs.REQUEST_PWR_PATHS, writer.generate());
}

/**
* Sets a property remotely for capabilities
*
* @param player The player
* @param capability The capability. 1 == AllowFlying, 2 == IsFlying
* @param state True or False
*/
public void sendCapabilityChangePacket(EntityPlayerMP player, int capability, boolean state){
AMDataWriter writer = new AMDataWriter();
writer.add(capability);
writer.add(state);

sendPacketToClientPlayer(player, AMPacketIDs.CAPABILITY_CHANGE, writer.generate());
}

public void sendExPropCommandToServer(int flag){
AMDataWriter writer = new AMDataWriter();
writer.add(flag);
sendPacketToServer(AMPacketIDs.SYNC_EXTENDED_PROPS, writer.generate());
}

public void sendCompendiumUnlockPacket(EntityPlayerMP player, String id, boolean isCategory){
AMDataWriter writer = new AMDataWriter();
writer.add(id);
writer.add(isCategory);

sendPacketToClientPlayer(player, AMPacketIDs.COMPENDIUM_UNLOCK, writer.generate());
}
// /**
// * Sets a property remotely for capabilities
// *
// * @param player The player
// * @param capability The capability. 1 == AllowFlying, 2 == IsFlying
// * @param state True or False
// */
// public void sendCapabilityChangePacket(EntityPlayerMP player, int capability, boolean state){
// AMDataWriter writer = new AMDataWriter();
// writer.add(capability);
// writer.add(state);
//
// sendPacketToClientPlayer(player, AMPacketIDs.CAPABILITY_CHANGE, writer.generate());
// }
//
// public void sendExPropCommandToServer(int flag){
// AMDataWriter writer = new AMDataWriter();
// writer.add(flag);
// sendPacketToServer(AMPacketIDs.SYNC_EXTENDED_PROPS, writer.generate());
// }

// public void sendCompendiumUnlockPacket(EntityPlayerMP player, String id, boolean isCategory){
// AMDataWriter writer = new AMDataWriter();
// writer.add(id);
// writer.add(isCategory);
//
// sendPacketToClientPlayer(player, AMPacketIDs.COMPENDIUM_UNLOCK, writer.generate());
// }

public void sendCalefactorCookUpdate(TileEntityCalefactor calefactor, byte[] data){
AMDataWriter writer = new AMDataWriter();
Expand All @@ -280,9 +280,9 @@ public void sendObeliskUpdate(TileEntityObelisk obelisk, byte[] data){
sendPacketToAllClientsNear(obelisk.getWorld().provider.getDimension(), obelisk.getPos().getX(), obelisk.getPos().getY(), obelisk.getPos().getZ(), 32, AMPacketIDs.OBELISK_DATA, writer.generate());
}

public void sendAffinityActivate(){
sendPacketToServer(AMPacketIDs.AFFINITY_ACTIVATE, new byte[0]);
}
// public void sendAffinityActivate(){
// sendPacketToServer(AMPacketIDs.AFFINITY_ACTIVATE, new byte[0]);
// }

public void sendAbilityToggle(String str){
sendPacketToServer(AMPacketIDs.TOGGLE_ABILITY, new AMDataWriter().add(str).generate());
Expand Down
41 changes: 21 additions & 20 deletions src/main/java/am2/packet/AMPacketIDs.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@

public class AMPacketIDs{
public static final byte SPELL_SHAPE_GROUP_CHANGE = 1;
public static final byte SPELL_CAST = 2;
public static final byte MAGIC_LEVEL_UP = 3;
// public static final byte SPELL_CAST = 2;
// public static final byte MAGIC_LEVEL_UP = 3;
public static final byte CRAFTING_ALTAR_DATA = 4;
public static final byte PARTICLE_SPAWN_SPECIAL = 5;
public static final byte PLAYER_VELOCITY_ADD = 7;
public static final byte PLAYER_REMOVE_ALL_BUFFS = 8;
// public static final byte PLAYER_REMOVE_ALL_BUFFS = 8;
public static final byte FLASH_ARMOR_PIECE = 9;
public static final byte ADD_BUFF_EFFECT = 12;
public static final byte REMOVE_BUFF_EFFECT = 13;
// public static final byte ADD_BUFF_EFFECT = 12;
// public static final byte REMOVE_BUFF_EFFECT = 13;
public static final byte SPELLBOOK_CHANGE_ACTIVE_SLOT = 14;
public static final byte CHAIN_LIGHTNING_CAST = 15;
public static final byte SYNC_EXTENDED_PROPS = 16;
public static final byte SYNC_BETA_PARTICLES = 17;
public static final byte SYNC_SPELL_KNOWLEDGE = 27;
public static final byte POSSIBLE_CLIENT_EXPROP_DESYNC = 29;
public static final byte REQUEST_BETA_PARTICLES = 31;
// public static final byte CHAIN_LIGHTNING_CAST = 15;
// public static final byte SYNC_EXTENDED_PROPS = 16;
// public static final byte SYNC_BETA_PARTICLES = 17;
// public static final byte SYNC_SPELL_KNOWLEDGE = 27;
// public static final byte POSSIBLE_CLIENT_EXPROP_DESYNC = 29;
// public static final byte REQUEST_BETA_PARTICLES = 31;
public static final byte SPELL_CUSTOMIZE = 32;
public static final byte SYNC_AIR_CHANGE = 33;
public static final byte SYNC_AFFINITY_DATA = 34;
// public static final byte SYNC_AIR_CHANGE = 33;
// public static final byte SYNC_AFFINITY_DATA = 34;
public static final byte DECO_BLOCK_UPDATE = 35;
public static final byte INSCRIPTION_TABLE_UPDATE = 36;
//No longer needed
Expand All @@ -30,23 +30,24 @@ public class AMPacketIDs{
public static final byte SAVE_KEYSTONE_COMBO = 40;
public static final byte SET_KEYSTONE_COMBO = 41;
public static final byte PLAYER_LOGIN_DATA = 42;
public static final byte NBT_DUMP = 43;
public static final byte SPELL_APPLY_EFFECT = 44;
// public static final byte NBT_DUMP = 43;
// public static final byte SPELL_APPLY_EFFECT = 44;
public static final byte SET_MAG_WORK_REC = 45;
public static final byte COMPENDIUM_UNLOCK = 46;
// public static final byte COMPENDIUM_UNLOCK = 46;
public static final byte SYNC_WORLD_NAME = 47;
public static final byte STAR_FALL = 48;
public static final byte HIDDEN_COMPONENT_UNLOCK = 49;
// public static final byte HIDDEN_COMPONENT_UNLOCK = 49;
public static final byte HECATE_DEATH = 50;
public static final byte RUNE_BAG_GUI_OPEN = 51;
//Superseded by FMLNetworkHandler
//public static final byte RUNE_BAG_GUI_OPEN = 51;
public static final byte M_BENCH_LOCK_RECIPE = 52;
public static final byte REQUEST_PWR_PATHS = 53;
public static final byte IMBUE_ARMOR = 54;
public static final byte CAPABILITY_CHANGE = 55;
// public static final byte CAPABILITY_CHANGE = 55;
public static final byte LECTERN_DATA = 56;
public static final byte CALEFACTOR_DATA = 57;
public static final byte OBELISK_DATA = 58;
public static final byte AFFINITY_ACTIVATE = 59;
// public static final byte AFFINITY_ACTIVATE = 59;
public static final byte MANA_LINK_UPDATE = 60;
public static final byte PLAYER_FLIP = 61;
public static final byte SYNC_CLIENT = 62;
Expand Down
73 changes: 37 additions & 36 deletions src/main/java/am2/packet/AMPacketProcessorClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import am2.api.power.IPowerNode;
import am2.api.spell.SpellModifier;
import am2.api.spell.SpellModifiers;
import am2.blocks.tileentity.TileEntityCalefactor;
import am2.blocks.tileentity.TileEntityCraftingAltar;
import am2.blocks.tileentity.TileEntityLectern;
import am2.blocks.tileentity.TileEntityObelisk;
Expand Down Expand Up @@ -69,9 +70,9 @@ public void onPacketData(ClientCustomPacketEvent event){
case AMPacketIDs.PARTICLE_SPAWN_SPECIAL:
ArsMagica2.proxy.particleManager.handleClientPacketData(Minecraft.getMinecraft().theWorld, remaining);
break;
// case AMPacketIDs.PLAYER_VELOCITY_ADD:
// handleVelocityAdd(remaining);
// break;
case AMPacketIDs.PLAYER_VELOCITY_ADD:
handleVelocityAdd(remaining);
break;
case AMPacketIDs.FLASH_ARMOR_PIECE:
handleFlashArmor(remaining);
break;
Expand Down Expand Up @@ -135,9 +136,9 @@ public void onPacketData(ClientCustomPacketEvent event){
case AMPacketIDs.LECTERN_DATA:
handleLecternData(remaining);
break;
// case AMPacketIDs.CALEFACTOR_DATA:
// handleCalefactorData(remaining);
// break;
case AMPacketIDs.CALEFACTOR_DATA:
handleCalefactorData(remaining);
break;
case AMPacketIDs.OBELISK_DATA:
handleObeliskData(remaining);
break;
Expand Down Expand Up @@ -188,14 +189,14 @@ private void handleObeliskData(byte[] remaining){
if (te == null || !(te instanceof TileEntityObelisk)) return;
((TileEntityObelisk)te).handlePacket(rdr.getRemainingBytes());
}
//
// private void handleCalefactorData(byte[] remaining){
// AMDataReader rdr = new AMDataReader(remaining, false);
// TileEntity te = Minecraft.getMinecraft().theWorld.getTileEntity(rdr.getInt(), rdr.getInt(), rdr.getInt());
// if (te == null || !(te instanceof TileEntityCalefactor)) return;
// ((TileEntityCalefactor)te).handlePacket(rdr.getRemainingBytes());
// }
//

private void handleCalefactorData(byte[] remaining){
AMDataReader rdr = new AMDataReader(remaining, false);
TileEntity te = Minecraft.getMinecraft().theWorld.getTileEntity(new BlockPos (rdr.getInt(), rdr.getInt(), rdr.getInt()));
if (te == null || !(te instanceof TileEntityCalefactor)) return;
((TileEntityCalefactor)te).handlePacket(rdr.getRemainingBytes());
}

private void handleLecternData(byte[] data){
AMDataReader rdr = new AMDataReader(data, false);
TileEntity te = Minecraft.getMinecraft().theWorld.getTileEntity(new BlockPos(rdr.getInt(), rdr.getInt(), rdr.getInt()));
Expand Down Expand Up @@ -459,10 +460,10 @@ private void handleSkillDataUpdate(byte[] data, EntityPlayer player){
// int entityID = rdr.getInt();
// byte[] expropData = rdr.getRemainingBytes();
//
// EntityLivingBase ent = AMCore.proxy.getEntityByID(entityID);
// EntityLivingBase ent = getEntityByID(entityID);
// if (ent == null) return;
//
// ExtendedProperties.For(ent).readAuraData(expropData);
// EntityExtension.For(ent).readAuraData(expropData);
// }
//
// private void handleKeystoneGuiOpen(byte[] data){
Expand Down Expand Up @@ -493,10 +494,10 @@ private void handleSkillDataUpdate(byte[] data, EntityPlayer player){
//
// private void handleSyncBetaParticles(byte[] data){
// EntityPlayer localPlayer = Minecraft.getMinecraft().thePlayer;
// if (!AMCore.proxy.playerTracker.hasAA(localPlayer))
// if (!ArsMagica2.proxy.playerTracker.hasAA(localPlayer))
// return;
//
// ExtendedProperties e = ExtendedProperties.For(localPlayer);
// EntityExtension e = EntityExtension.For(localPlayer);
//
// AMDataWriter writer = new AMDataWriter();
// writer.add(e.getAuraIndex());
Expand Down Expand Up @@ -542,24 +543,24 @@ private void handleFlashArmor(byte[] data){
AMDataReader rdr = new AMDataReader(data, false);
AMGuiHelper.instance.blackoutArmorPiece(rdr.getInt(), rdr.getInt());
}
//
// private void handleVelocityAdd(byte[] data){
// AMDataReader rdr = new AMDataReader(data, false);
// int entityID = rdr.getInt();
// double velX = rdr.getDouble();
// double velY = rdr.getDouble();
// double velZ = rdr.getDouble();
//
// Entity ent = AMCore.proxy.getEntityByID(entityID);
// EntityLivingBase localPlayer = Minecraft.getMinecraft().thePlayer;
// //this is only really required for the local player, as other entities seem to work across the network.
// if (ent.getEntityId() != localPlayer.getEntityId()){
// return;
// }
// if (localPlayer.motionY > 0) return;
//
// localPlayer.addVelocity(velX, velY, velZ);
// }

private void handleVelocityAdd(byte[] data){
AMDataReader rdr = new AMDataReader(data, false);
int entityID = rdr.getInt();
double velX = rdr.getDouble();
double velY = rdr.getDouble();
double velZ = rdr.getDouble();

Entity ent = getEntityByID(entityID);
EntityLivingBase localPlayer = Minecraft.getMinecraft().thePlayer;
//this is only really required for the local player, as other entities seem to work across the network.
if (ent.getEntityId() != localPlayer.getEntityId()){
return;
}
if (localPlayer.motionY > 0) return;

localPlayer.addVelocity(velX, velY, velZ);
}
//
// private void handleMagicLevelUpResponse(byte[] data){
// AMDataReader rdr = new AMDataReader(data, false);
Expand Down
Loading

0 comments on commit d9da180

Please sign in to comment.