pull in extra heart stuffs from 1.6 warning: probably will fail serverside

This commit is contained in:
Progwml6 committed 2014-02-25 19:48:18 -05:00
1 parent 58bf2934be
commit d6372a79ae
13 files changed
+284 -113

No files matched your search

@@ -9,7 +9,9 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.IEntityLivingData;
import net.minecraft.entity.boss.EntityDragon;
import net.minecraft.entity.boss.EntityWither;
import net.minecraft.entity.boss.IBossDisplayData;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.monster.EntityCreeper;
@@ -47,6 +49,7 @@ import tconstruct.achievements.TAchievements;
import tconstruct.blocks.LiquidMetalFinite;
import tconstruct.blocks.TankAirBlock;
import tconstruct.common.TRepo;
import tconstruct.entity.BlueSlime;
import tconstruct.items.tools.FryingPan;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.event.PartBuilderEvent;
@@ -275,15 +278,25 @@ public class TEventHandler
}
}
if (random.nextInt(500) == 0 && event.entityLiving instanceof IMob)
if (random.nextInt(200) == 0 && event.entityLiving instanceof IMob && event.source.damageType.equals("player"))
{
ItemStack dropStack = new ItemStack(TRepo.heartCanister, 1, 1);
EntityItem entityitem = new EntityItem(event.entityLiving.worldObj, event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ, dropStack);
entityitem.delayBeforeCanPickup = 10;
event.drops.add(entityitem);
if (event.entityLiving instanceof BlueSlime)
{
BlueSlime slime = (BlueSlime) event.entityLiving;
if (slime.getSlimeSize() < 8)
return;
}
int count = event.entityLiving instanceof EntityDragon ? 5 : 1;
for (int i = 0; i < count; i++)
{
ItemStack dropStack = new ItemStack(TRepo.heartCanister, 1, 3);
EntityItem entityitem = new EntityItem(event.entityLiving.worldObj, event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ, dropStack);
entityitem.delayBeforeCanPickup = 10;
event.drops.add(entityitem);
}
}
if (event.entityLiving instanceof EntityWither && random.nextInt(5) == 0)
if (event.entityLiving instanceof IBossDisplayData)
{
ItemStack dropStack = new ItemStack(TRepo.heartCanister, 1, 1);
EntityItem entityitem = new EntityItem(event.entityLiving.worldObj, event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ, dropStack);
@@ -293,19 +306,16 @@ public class TEventHandler
if (!event.entityLiving.isChild() && event.entityLiving.worldObj.getGameRules().getGameRuleBooleanValue("doMobLoot"))
{
if (event.entityLiving.getClass() == EntityCow.class)
{
int amount = random.nextInt(3) + random.nextInt(1 +
event.lootingLevel) + random.nextInt(3) + random.nextInt(1 +
event.lootingLevel) + 1;
for (int iter = 0; iter < amount; ++iter)
{
addDrops(event, new ItemStack(Items.leather, 1));
}
if (event.entityLiving.getClass() == EntityCow.class)
{
int amount = random.nextInt(3) + random.nextInt(1 + event.lootingLevel) + random.nextInt(3) + random.nextInt(1 + event.lootingLevel) + 1;
for (int iter = 0; iter < amount; ++iter)
{
addDrops(event, new ItemStack(Items.leather, 1));
}
}
if (event.entityLiving.getClass() == EntityChicken.class)
{
@@ -364,13 +374,12 @@ public class TEventHandler
addDrops(event, new ItemStack(Items.skull, 1, 2));
}
}
if (stack.getItem() == TRepo.cleaver &&
random.nextInt(100) < 10) //Swap out for real beheading
{
addDrops(event, new ItemStack(Items.skull, 1, 2));
}
if (stack.getItem() == TRepo.cleaver && random.nextInt(100) < 10) //Swap out for real beheading
{
addDrops(event, new ItemStack(Items.skull, 1, 2));
}
}
}
@@ -613,31 +622,29 @@ public class TEventHandler
}
// TODO 1.7 Fix this -- for ticking stuffs in extra armor slots
@SubscribeEvent
public void livingUpdate (LivingUpdateEvent event)
{ if (event.entityLiving instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer) event.entityLiving;
TPlayerStats stats = TConstruct.playerTracker.getPlayerStats(player.getDisplayName());
if (stats != null && stats.armor != null)
{
ArmorExtended armor = stats.armor;
for (int i = 0; i < armor.getSizeInventory(); i++)
{
if (armor.getStackInSlot(i) != null)
{
armor.getStackInSlot(i).getItem().onUpdate(armor.getStackInSlot(i),
player.worldObj, player, i, false);
armor.getStackInSlot(i).getItem().onArmorTick(player.worldObj, player,
armor.getStackInSlot(i));
}
}
}
}
}
@SubscribeEvent
public void livingUpdate (LivingUpdateEvent event)
{
if (event.entityLiving instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer) event.entityLiving;
TPlayerStats stats = TConstruct.playerTracker.getPlayerStats(player.getDisplayName());
if (stats != null && stats.armor != null)
{
ArmorExtended armor = stats.armor;
for (int i = 0; i < armor.getSizeInventory(); i++)
{
if (armor.getStackInSlot(i) != null)
{
armor.getStackInSlot(i).getItem().onUpdate(armor.getStackInSlot(i), player.worldObj, player, i, false);
armor.getStackInSlot(i).getItem().onArmorTick(player.worldObj, player, armor.getStackInSlot(i));
}
}
}
}
}
// Player interact event - prevent breaking of tank air blocks in creative
@SubscribeEvent
@@ -0,0 +1,62 @@
package tconstruct.util.network.packet;
import java.io.IOException;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import tconstruct.TConstruct;
import tconstruct.client.TProxyClient;
import tconstruct.common.TProxyCommon;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import net.minecraft.entity.player.EntityPlayer;
public class PacketArmorSync extends AbstractPacket
{
ByteBuf b;
@Override
public void encodeInto (ChannelHandlerContext ctx, ByteBuf buffer)
{
}
@Override
public void decodeInto (ChannelHandlerContext ctx, ByteBuf buffer)
{
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
{
try
{
byte packetID = buffer.readByte();
}
catch (Exception e)
{
TConstruct.logger.warn("Failed at reading server packet for TConstruct.");
e.printStackTrace();
}
try
{
TProxyClient.armorExtended.readInventoryFromStream(buffer);
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
@Override
public void handleClientSide (EntityPlayer player)
{
}
@Override
public void handleServerSide (EntityPlayer player)
{
TProxyClient.armorExtended.recalculateHealth(player, TConstruct.playerTracker.getPlayerStats(player.getDisplayName()));
}
}
@@ -141,6 +141,7 @@ public class PacketPipeline extends MessageToMessageCodec<FMLProxyPacket, Abstra
registerPacket(PacketSmeltery.class);
registerPacket(PacketStencilTable.class);
registerPacket(PacketToolStation.class);
registerPacket(PacketArmorSync.class);
}
// Method to call from FMLPostInitializationEvent
@@ -1,5 +1,8 @@
package tconstruct.util.player;
import io.netty.buffer.ByteBuf;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.UUID;
@@ -12,8 +15,9 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import tconstruct.TConstruct;
import tconstruct.common.TRepo;
import tconstruct.library.armor.IHealthAccessory;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.ByteBufUtils;
import cpw.mods.fml.relauncher.Side;
public class ArmorExtended implements IInventory
@@ -139,40 +143,39 @@ public class ArmorExtended implements IInventory
{
Side side = FMLCommonHandler.instance().getEffectiveSide();
if (inventory[6] != null && inventory[6].getItem() == TRepo.heartCanister)
{
ItemStack stack = inventory[6];
int meta = stack.getItemDamage();
// TConstruct.logger.info("Calculating HP on side " +
// FMLCommonHandler.instance().getEffectiveSide());
if (meta == 2)
if (inventory[4] != null || inventory[5] != null || inventory[6] != null) {
int bonusHP = 0;
for (int i = 0; i < 3; i++)
{
int prevHealth = stats.bonusHealth;
if (side == Side.CLIENT)
prevHealth = stats.bonusHealthClient;
int bonusHP = stack.stackSize * 2;
if (side == Side.CLIENT)
stats.bonusHealthClient = bonusHP;
else
stats.bonusHealth = bonusHP;
int healthChange = bonusHP - prevHealth;
// TConstruct.logger.info("healthChange: "+healthChange+" on side "+FMLCommonHandler.instance().getEffectiveSide());
if (healthChange != 0)
ItemStack stack = inventory[i + 4];
if (stack != null && stack.getItem() instanceof IHealthAccessory)
{
IAttributeInstance attributeinstance = player.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.maxHealth);
try
{
attributeinstance.removeModifier(attributeinstance.getModifier(globalID));
}
catch (Exception e)
{
}
attributeinstance.applyModifier(new AttributeModifier(globalID, "tconstruct.heartCanister", bonusHP, 0));
bonusHP += ((IHealthAccessory) stack.getItem()).getHealthBoost(stack);
}
}
int prevHealth = stats.bonusHealth;
if (side == Side.CLIENT)
prevHealth = stats.bonusHealthClient;
if (side == Side.CLIENT)
stats.bonusHealthClient = bonusHP;
else
stats.bonusHealth = bonusHP;
int healthChange = bonusHP - prevHealth;
if (healthChange != 0)
{
IAttributeInstance attributeinstance = player.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.maxHealth);
try
{
attributeinstance.removeModifier(attributeinstance.getModifier(globalID));
}
catch (Exception e)
{
}
attributeinstance.applyModifier(new AttributeModifier(globalID, "tconstruct.heartCanister", bonusHP, 0));
}
}
else if (parent != null && parent.get() != null)
{
@@ -279,4 +282,16 @@ public class ArmorExtended implements IInventory
public void closeInventory ()
{
}
public void writeInventoryToStream (ByteBuf os) throws IOException
{
for (int i = 0; i < 7; i++)
ByteBufUtils.writeItemStack(os,inventory[i]);
}
public void readInventoryFromStream (ByteBuf is) throws IOException
{
for (int i = 0; i < 7; i++)
inventory[i] = ByteBufUtils.readItemStack(is);
}
}
@@ -1,5 +1,8 @@
package tconstruct.util.player;
import static io.netty.buffer.Unpooled.*;
import io.netty.buffer.ByteBuf;
import java.io.ByteArrayOutputStream;
import java.lang.ref.WeakReference;
import java.util.Random;
@@ -54,6 +57,7 @@ public class TPlayerHandler
public void onPlayerChangedDimension (PlayerChangedDimensionEvent event)
{
savePlayerStats(event.player, false);
updatePlayerInventory(event.player, getPlayerStats(event.player.getDisplayName()));
}
@SubscribeEvent
@@ -150,26 +154,32 @@ public class TPlayerHandler
updatePlayerInventory(entityplayer, stats);
}
void updatePlayerInventory (EntityPlayer entityplayer, TPlayerStats stats)
void updatePlayerInventory (EntityPlayer player, TPlayerStats stats)
{
}
void updateClientPlayer (ByteArrayOutputStream bos, EntityPlayer player)
{
/*
* Packet250CustomPayload packet = new Packet250CustomPayload();
* packet.channel = "TConstruct"; packet.data = bos.toByteArray();
* packet.length = bos.size();
*
* PacketDispatcher.sendPacketToPlayer(packet, (Player) player);
*/
// TODO find out what packet needs to be used here (and make sure that
// player actually is a playerMP and this gets called)
ByteBuf outputStream = buffer(8);
try
{
outputStream.writeByte(4);
stats.armor.writeInventoryToStream(outputStream);
}
catch (Exception ex)
{
ex.printStackTrace();
}
if (player instanceof EntityPlayerMP)
{
TConstruct.packetPipeline.sendTo(new PacketDoubleJump(), (EntityPlayerMP) player);
}
/*
* Packet250CustomPayload packet = new Packet250CustomPayload();
* packet.channel = "TConstruct"; packet.data = bos.toByteArray();
* packet.length = bos.size();
*
* PacketDispatcher.sendPacketToPlayer(packet, (Player) player);
*/
// TODO find out what packet needs to be used here (and make sure that
// player actually is a playerMP and this gets called)
}
void savePlayerStats (EntityPlayer player, boolean clean)
@@ -221,6 +231,7 @@ public class TPlayerHandler
if (PHConstruct.keepHunger)
entityplayer.getFoodStats().setFoodLevel(stats.hunger);
}
updatePlayerInventory(entityplayer, getPlayerStats(entityplayer.getDisplayName()));
}
@SubscribeEvent