Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @ForgeSubscribe
- public void onEntityConstructing(EntityConstructing event)
- {
- /*
- Be sure to check if the entity being constructed is the correct type for the extended properties you're about to add! The null check may not be necessary - I only use it to make sure properties are only registered once per entity
- */
- if (event.entity instanceof EntityPlayer && ExtendedPlayer.get((EntityPlayer) event.entity) == null)
- // This is how extended properties are registered using our convenient method from earlier
- ExtendedPlayer.register((EntityPlayer) event.entity);
- // That will call the constructor as well as cause the init() method
- // to be called automatically
- // If you didn't make the two convenient methods from earlier, your code would be
- // much uglier:
- if (event.entity instanceof EntityPlayer && event.entity.getExtendedProperties(ExtendedPlayer.EXT_PROP_NAME) == null)
- event.entity.registerExtendedProperties(ExtendedPlayer.EXT_PROP_NAME, new ExtendedPlayer((EntityPlayer) event.entity));
- }
- // we need to add this new event - it is called for every living entity upon death
- @ForgeSubscribe
- public void onLivingDeathEvent(LivingDeathEvent event)
- {
- // we only want to save data for players (most likely, anyway)
- if (!event.entity.worldObj.isRemote && event.entity instanceof EntityPlayer)
- {
- // NOTE: See step 6 for a way to do this all in one line!!!
- // create a new NBT Tag Compound to store the IExtendedEntityProperties data
- NBTTagCompound playerData = new NBTTagCompound();
- // write the data to the new compound
- ((ExtendedPlayer)(event.entity.getExtendedProperties(ExtendedPlayer.EXT_PROP_NAME))).saveNBTData(playerData);
- // and store it in our proxy
- FGM3.proxy.storeEntityData(((EntityPlayer) event.entity).username, playerData);
- // call our handy static one-liner to save custom data to the proxy
- ExtendedPlayer.saveProxyData((EntityPlayer) event.entity);
- ExtendedPlayer prop = (ExtendedPlayer)event.entity.getExtendedProperties(ExtendedPlayer.EXT_PROP_NAME);
- prop.setRad(0);
- prop.setWeight(0);
- prop.setbWeight(0);
- EntityPlayer player = (EntityPlayer)event.entity;
- player.inventory.clearInventory(ArtefactCore.knife.itemID, -1);
- ExtendedPlayer props = ExtendedPlayer.get(player);
- for(int i = 0; i < 9; ++i)
- {
- if(i < 5 || i > 8)
- {
- if(props.inventory.getStackInSlot(i) != null)
- {
- //System.out.println(i);
- ItemStack is = props.inventory.getStackInSlot(i);
- player.inventory.clearInventory(is.itemID, -1);
- player.worldObj.spawnEntityInWorld(new EntityItem(player.worldObj, player.posX, player.posY, player.posZ, is));
- }
- }
- }
- }
- }
- // we already have this event, but we need to modify it some
- @ForgeSubscribe
- public void onEntityJoinWorld(EntityJoinWorldEvent event)
- {
- if(!event.entity.worldObj.isRemote && event.entity instanceof EntityLivingBase)
- {
- EntityLivingBase entity = (EntityLivingBase)event.entity;
- entity.getEntityAttribute(SharedMonsterAttributes.knockbackResistance).setAttribute(2D);
- }
- if (!event.entity.worldObj.isRemote && event.entity instanceof EntityPlayer)
- ExtendedPlayer.get((EntityPlayer) event.entity).sync();
- }
Advertisement
Add Comment
Please, Sign In to add comment