-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDeathEventHook.java
More file actions
69 lines (56 loc) · 2.37 KB
/
DeathEventHook.java
File metadata and controls
69 lines (56 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package TombStone;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.logging.Level;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.relauncher.SideOnly;
import cpw.mods.fml.relauncher.Side;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.NetClientHandler;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet130UpdateSign;
import net.minecraft.network.packet.Packet132TileEntityData;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.player.PlayerDropsEvent;
public class DeathEventHook {
public DeathEventHook()
{
}
@ForgeSubscribe
public void onEntityDeath(PlayerDropsEvent event)
{
EntityPlayer deadPlayer = event.entityPlayer;
DamageSource attackSource = event.source;
ArrayList<EntityItem> drops = event.drops;
World world = deadPlayer.worldObj;
//DEBUG//
//FMLLog.log(Level.WARNING, "[TombStone] onEntityDeath(): " + attackSource.getDeathMessage(deadPlayer));
//Calculate the spot to put the tombstone
//TODO - Make this more intelligent
int tombX = (int) Math.floor(deadPlayer.posX);
int tombY = (int) Math.floor(deadPlayer.posY);
int tombZ = (int) Math.floor(deadPlayer.posZ);
String dateOfDeath = world.getCurrentDate().get(Calendar.MONTH) + "/" + world.getCurrentDate().get(Calendar.DAY_OF_MONTH) + "/" + world.getCurrentDate().get(Calendar.YEAR);
String deathMessage = attackSource.getDeathMessage(deadPlayer) + " here\n Died " + dateOfDeath;
//Place the tombstone
world.setBlock(tombX, tombY, tombZ, TombStone.instance.tombStoneBlockId, 0, 1 | 2);
TombStoneTileEntity blockTileEntity = (TombStoneTileEntity) world.getBlockTileEntity(tombX, tombY, tombZ);
//Move all items from the list to the tombstone inventory
for(int i=0; i<drops.size(); i++)
{
ItemStack playerItem = drops.get(i).getEntityItem();
blockTileEntity.setInventorySlotContents(i, playerItem);
}
//Set the other meta-data for the tile entity
blockTileEntity.setOwner(deadPlayer.getEntityName());
blockTileEntity.setDeathText(deathMessage);
blockTileEntity.setIsCrafted(false);
event.setCanceled(true);
}
}