mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
178 lines
5.2 KiB
Java
178 lines
5.2 KiB
Java
package com.hbm.potion;
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
import com.hbm.blocks.ModBlocks;
|
|
import com.hbm.blocks.bomb.BlockTaint;
|
|
import com.hbm.entity.mob.EntityTaintCrab;
|
|
import com.hbm.entity.mob.EntityTaintedCreeper;
|
|
import com.hbm.explosion.ExplosionLarge;
|
|
import com.hbm.lib.Library;
|
|
import com.hbm.lib.ModDamageSource;
|
|
import com.hbm.main.MainRegistry;
|
|
|
|
import cpw.mods.fml.relauncher.ReflectionHelper;
|
|
import cpw.mods.fml.relauncher.Side;
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
import net.minecraft.client.Minecraft;
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.potion.Potion;
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
public class HbmPotion extends Potion {
|
|
|
|
public static HbmPotion taint;
|
|
public static HbmPotion radiation;
|
|
public static HbmPotion bang;
|
|
public static HbmPotion mutation;
|
|
public static HbmPotion radx;
|
|
public static HbmPotion lead;
|
|
public static HbmPotion radaway;
|
|
public static HbmPotion telekinesis;
|
|
public static HbmPotion phosphorus;
|
|
|
|
public HbmPotion(int id, boolean isBad, int color) {
|
|
super(id, isBad, color);
|
|
}
|
|
|
|
public static void init() {
|
|
taint = registerPotion(MainRegistry.taintID, true, 8388736, "potion.hbm_taint", 0, 0);
|
|
radiation = registerPotion(MainRegistry.radiationID, true, 8700200, "potion.hbm_radiation", 1, 0);
|
|
bang = registerPotion(MainRegistry.bangID, true, 1118481, "potion.hbm_bang", 3, 0);
|
|
mutation = registerPotion(MainRegistry.mutationID, false, 8388736, "potion.hbm_mutation", 2, 0);
|
|
radx = registerPotion(MainRegistry.radxID, false, 0xBB4B00, "potion.hbm_radx", 5, 0);
|
|
lead = registerPotion(MainRegistry.leadID, true, 0x767682, "potion.hbm_lead", 6, 0);
|
|
radaway = registerPotion(MainRegistry.radawayID, false, 0xBB4B00, "potion.hbm_radaway", 7, 0);
|
|
telekinesis = registerPotion(MainRegistry.telekinesisID, true, 0x00F3FF, "potion.hbm_telekinesis", 0, 1);
|
|
phosphorus = registerPotion(MainRegistry.phosphorusID, true, 0xFFFF00, "potion.hbm_phosphorus", 1, 1);
|
|
}
|
|
|
|
public static HbmPotion registerPotion(int id, boolean isBad, int color, String name, int x, int y) {
|
|
|
|
if (id >= Potion.potionTypes.length) {
|
|
|
|
Potion[] newArray = new Potion[Math.max(256, id)];
|
|
System.arraycopy(Potion.potionTypes, 0, newArray, 0, Potion.potionTypes.length);
|
|
|
|
Field field = ReflectionHelper.findField(Potion.class, new String[] { "field_76425_a", "potionTypes" });
|
|
field.setAccessible(true);
|
|
|
|
try {
|
|
|
|
Field modfield = Field.class.getDeclaredField("modifiers");
|
|
modfield.setAccessible(true);
|
|
modfield.setInt(field, field.getModifiers() & 0xFFFFFFEF);
|
|
field.set(null, newArray);
|
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
}
|
|
|
|
HbmPotion effect = new HbmPotion(id, isBad, color);
|
|
effect.setPotionName(name);
|
|
effect.setIconIndex(x, y);
|
|
|
|
return effect;
|
|
}
|
|
|
|
@Override
|
|
@SideOnly(Side.CLIENT)
|
|
public int getStatusIconIndex() {
|
|
ResourceLocation loc = new ResourceLocation("hbm","textures/gui/potions.png");
|
|
Minecraft.getMinecraft().renderEngine.bindTexture(loc);
|
|
return super.getStatusIconIndex();
|
|
}
|
|
|
|
public void performEffect(EntityLivingBase entity, int level) {
|
|
|
|
if(this == taint) {
|
|
|
|
if(!(entity instanceof EntityTaintedCreeper) && !(entity instanceof EntityTaintCrab) && entity.worldObj.rand.nextInt(40) == 0)
|
|
entity.attackEntityFrom(ModDamageSource.taint, (level + 1));
|
|
|
|
if(MainRegistry.enableHardcoreTaint && !entity.worldObj.isRemote) {
|
|
|
|
int x = (int)(entity.posX - 1);
|
|
int y = (int)entity.posY;
|
|
int z = (int)(entity.posZ);
|
|
|
|
if(entity.worldObj.getBlock(x, y, z)
|
|
.isReplaceable(entity.worldObj, x, y, z) &&
|
|
BlockTaint.hasPosNeightbour(entity.worldObj, x, y, z)) {
|
|
|
|
entity.worldObj.setBlock(x, y, z, ModBlocks.taint, 14, 2);
|
|
}
|
|
}
|
|
}
|
|
if(this == radiation) {
|
|
|
|
Library.applyRadData(entity, (float)(level + 1F) * 0.05F);
|
|
}
|
|
if(this == radaway) {
|
|
|
|
float rad = entity.getEntityData().getFloat("hfr_radiation");
|
|
rad -= (level + 1);
|
|
if(rad < 0) rad = 0;
|
|
|
|
entity.getEntityData().setFloat("hfr_radiation", rad);
|
|
|
|
}
|
|
if(this == bang) {
|
|
|
|
entity.attackEntityFrom(ModDamageSource.bang, 1000);
|
|
entity.setHealth(0.0F);
|
|
|
|
if (!(entity instanceof EntityPlayer))
|
|
entity.setDead();
|
|
|
|
entity.worldObj.playSoundEffect(entity.posX, entity.posY, entity.posZ, "hbm:weapon.laserBang", 100.0F, 1.0F);
|
|
ExplosionLarge.spawnParticles(entity.worldObj, entity.posX, entity.posY, entity.posZ, 10);
|
|
}
|
|
if(this == lead) {
|
|
|
|
entity.attackEntityFrom(ModDamageSource.lead, (level + 1));
|
|
}
|
|
if(this == telekinesis) {
|
|
|
|
int remaining = entity.getActivePotionEffect(this).getDuration();
|
|
|
|
if(remaining > 1) {
|
|
entity.motionY = 0.5;
|
|
} else {
|
|
entity.motionY = -2;
|
|
entity.fallDistance = 50;
|
|
}
|
|
}
|
|
if(this == phosphorus && !entity.worldObj.isRemote) {
|
|
|
|
entity.setFire(1);
|
|
}
|
|
}
|
|
|
|
public boolean isReady(int par1, int par2) {
|
|
|
|
if(this == taint) {
|
|
|
|
return par1 % 2 == 0;
|
|
}
|
|
if(this == radiation || this == radaway || this == telekinesis || this == phosphorus) {
|
|
|
|
return true;
|
|
}
|
|
if(this == bang) {
|
|
|
|
return par1 <= 10;
|
|
}
|
|
if(this == lead) {
|
|
|
|
int k = 60;
|
|
return k > 0 ? par1 % k == 0 : true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
}
|