forked from NightKosh/Gravestone-mod-Graves
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EventHookGSGraveStone.java
79 lines (72 loc) · 3.51 KB
/
EventHookGSGraveStone.java
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
70
71
72
73
74
75
76
77
78
79
package GraveStone;
import GraveStone.block.BlockGSGraveStone;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.passive.EntityOcelot;
import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.entity.passive.EntityWolf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MathHelper;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
/**
* GraveStone mod
*
* @author NightKosh
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
*
*/
public class EventHookGSGraveStone {
@ForgeSubscribe
public void onEntityLivingDeath(LivingDeathEvent event) {
if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
if (!GraveStoneConfig.generateGravesInLava && event.source.damageType.equals("lava")) {
return;
}
if (GraveStoneConfig.generatePlayerGraves && event.entityLiving instanceof EntityPlayer) {
createPlayerGrave((EntityPlayer) event.entity, event);
} else {
if (GraveStoneConfig.generateVillagerGraves && event.entity instanceof EntityVillager) {
createGrave(event.entity, event, null, ((EntityVillager) event.entity).getAge(), (byte) 0);
}
if (GraveStoneConfig.generatePetGraves && event.entity instanceof EntityTameable) {
createPetGrave(event.entity, event);
}
}
// drop creeper statue if entity is a charged creeper
if (event.entity instanceof EntityCreeper && ((EntityCreeper) event.entity).getPowered()) {
ModGraveStone.memorial.dropCreeperMemorial(event.entity.worldObj, (int) event.entity.posX,
(int) event.entity.posY, (int) event.entity.posZ);
}
}
}
private void createPlayerGrave(EntityPlayer player, LivingDeathEvent event) {
if (player.worldObj != null && !player.worldObj.getGameRules().getGameRuleBooleanValue("keepInventory")) {
ItemStack[] items = new ItemStack[40];
System.arraycopy(player.inventory.mainInventory, 0, items, 0, 36);
System.arraycopy(player.inventory.armorInventory, 0, items, 36, 4);
player.inventory.clearInventory(-1, -1);
createGrave(player, event, items, player.getAge(), (byte) 0);
} else {
createGrave(player, event, null, player.getAge(), (byte) 0);
}
}
private void createGrave(Entity entity, LivingDeathEvent event, ItemStack[] items, int age, byte entityType) {
BlockGSGraveStone.createOnDeath(entity.worldObj, (int) entity.posX, (int) entity.posY, (int) entity.posZ - 1,
event.source.getDeathMessage((EntityLiving) entity), MathHelper.floor_float(entity.rotationYaw), items, age, entityType);
}
private void createPetGrave(Entity entity, LivingDeathEvent event) {
EntityTameable pet = (EntityTameable) entity;
if (pet.isTamed()) {
if (pet instanceof EntityWolf) {
createGrave(entity, event, null, pet.getAge(), (byte) 1);
} else if (pet instanceof EntityOcelot) {
createGrave(entity, event, null, pet.getAge(), (byte) 2);
}
}
}
}