-
Notifications
You must be signed in to change notification settings - Fork 25
/
EntityRadiation.java
168 lines (137 loc) · 4.27 KB
/
EntityRadiation.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*******************************************************************************
* @author Reika Kalseki
*
* Copyright 2017
*
* All rights reserved.
* Distribution of the software in any form is only allowed with
* explicit, prior permission from the owner.
******************************************************************************/
package Reika.ReactorCraft.Entities;
import java.util.List;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import Reika.DragonAPI.Base.InertEntity;
import Reika.DragonAPI.Libraries.Java.ReikaRandomHelper;
import Reika.DragonAPI.Libraries.MathSci.ReikaMathLibrary;
import Reika.ReactorCraft.Auxiliary.RadiationEffects;
import Reika.ReactorCraft.Auxiliary.RadiationEffects.RadiationIntensity;
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
import io.netty.buffer.ByteBuf;
public class EntityRadiation extends InertEntity implements IEntityAdditionalSpawnData {
private int effectRange;
private RadiationIntensity intensity;
public boolean requireLOS = false;
public EntityRadiation(World par1World) {
super(par1World);
}
public EntityRadiation(World world, int range, RadiationIntensity ri) {
super(world);
effectRange = range;
intensity = ri;
}
@Override
protected void entityInit() {
}
@Override
protected void readEntityFromNBT(NBTTagCompound NBT) {
effectRange = NBT.getInteger("effrange");
intensity = RadiationIntensity.radiationList[NBT.getInteger("intensity")];
requireLOS = NBT.getBoolean("los");
}
@Override
protected void writeEntityToNBT(NBTTagCompound NBT) {
NBT.setInteger("effrange", effectRange);
NBT.setInteger("intensity", intensity.ordinal());
NBT.setBoolean("los", requireLOS);
}
@Override
public void onUpdate() {
this.onEntityUpdate();
this.applyRadiation();
if (effectRange <= 0)
this.setDead();
if (this.decays()) {
if (rand.nextInt(360000) == 0) {
this.clean();
}
}
if (this.rainCleanable()) {
if (worldObj.isRaining()) {
if (rand.nextInt(36000) == 0) {
if (worldObj.getBiomeGenForCoords(this.getBlockX(), this.getBlockZ()).canSpawnLightningBolt()) {
this.clean();
}
}
}
}
}
protected boolean decays() {
return true;
}
protected boolean rainCleanable() {
return true;
}
public final int getBlockX() {
return (int)Math.floor(posX);
}
public final int getBlockY() {
return (int)Math.floor(posY);
}
public final int getBlockZ() {
return (int)Math.floor(posZ);
}
protected void applyRadiation() {
World world = worldObj;
double x = posX;
double y = posY;
double z = posZ;
AxisAlignedBB box = AxisAlignedBB.getBoundingBox(x, y, z, x, y, z).expand(effectRange, effectRange, effectRange);
List<EntityLivingBase> inbox = world.getEntitiesWithinAABB(EntityLivingBase.class, box);
for (EntityLivingBase e : inbox) {
double dd = ReikaMathLibrary.py3d(e.posX-x, e.posY-y, e.posZ-z);
if (dd <= effectRange) {
RadiationEffects.instance.applyEffects(e, intensity);
}
}
int c = 1;//20
//if (r.nextInt(c) == 0) {
int dx = ReikaRandomHelper.getRandomPlusMinus(MathHelper.floor_double(x), effectRange);
int dy = ReikaRandomHelper.getRandomPlusMinus(MathHelper.floor_double(y), effectRange);
int dz = ReikaRandomHelper.getRandomPlusMinus(MathHelper.floor_double(z), effectRange);
RadiationEffects.instance.transformBlock(world, dx, dy, dz, intensity);
//}
}
public void clean() {
if (effectRange > 0)
effectRange--;
else
this.setDead();
}
public int getRange() {
return effectRange;
}
@Override
public void writeSpawnData(ByteBuf data) {
data.writeInt(effectRange);
data.writeInt(intensity.ordinal());
}
@Override
public void readSpawnData(ByteBuf data) {
effectRange = data.readInt();
intensity = RadiationIntensity.radiationList[data.readInt()];
}
@Override
public boolean attackEntityFrom(DamageSource src, float par2) {
if (src.isExplosion()) {
RadiationEffects.instance.contaminateArea(worldObj, this.getBlockX(), this.getBlockY(), this.getBlockZ(), effectRange, 0.65F, 0.5, true, intensity);
this.setDead();
return true;
}
return super.attackEntityFrom(src, par2);
}
}