mirror of
https://github.com/GTNewHorizons/BloodArsenal.git
synced 2026-10-25 20:22:31 +00:00
Blood TNT Dispenser + Cleanup (#46)
This commit is contained in:
1 parent
e8873ee170
commit
ff7c3b62ea
5 files changed
+123
-167
No files matched your search
+22
-44
@@ -17,51 +17,42 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class RenderBloodTNTPrimed extends Render {
|
||||
|
||||
private RenderBlocks blockRenderer = new RenderBlocks();
|
||||
private final RenderBlocks blockRenderer = new RenderBlocks();
|
||||
|
||||
public RenderBloodTNTPrimed() {
|
||||
this.shadowSize = 0.5F;
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
|
||||
* handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
|
||||
* (Render<T extends Entity) and this method has signature public void func_76986_a(T entity, double d, double d1,
|
||||
* double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.
|
||||
*/
|
||||
public void doRender(EntityBloodTNT p_76986_1_, double p_76986_2_, double p_76986_4_, double p_76986_6_,
|
||||
float p_76986_8_, float p_76986_9_) {
|
||||
public void doRender(EntityBloodTNT entity, double x, double y, double z, float renderTicks) {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef((float) p_76986_2_, (float) p_76986_4_, (float) p_76986_6_);
|
||||
float f2;
|
||||
GL11.glTranslatef((float) x, (float) y, (float) z);
|
||||
|
||||
if ((float) p_76986_1_.fuse - p_76986_9_ + 1.0F < 10.0F) {
|
||||
f2 = 1.0F - ((float) p_76986_1_.fuse - p_76986_9_ + 1.0F) / 10.0F;
|
||||
float timer = entity.fuse - renderTicks + 1.0F;
|
||||
if (timer < 10.0F) {
|
||||
float s = 1.0F - timer / 10.0F;
|
||||
|
||||
if (f2 < 0.0F) {
|
||||
f2 = 0.0F;
|
||||
if (s < 0.0F) {
|
||||
s = 0.0F;
|
||||
}
|
||||
|
||||
if (f2 > 1.0F) {
|
||||
f2 = 1.0F;
|
||||
if (s > 1.0F) {
|
||||
s = 1.0F;
|
||||
}
|
||||
|
||||
f2 *= f2;
|
||||
f2 *= f2;
|
||||
float f3 = 1.0F + f2 * 0.3F;
|
||||
GL11.glScalef(f3, f3, f3);
|
||||
float scale = 1.0F + s * s * s * 0.3F;
|
||||
GL11.glScalef(scale, scale, scale);
|
||||
}
|
||||
|
||||
f2 = (1.0F - ((float) p_76986_1_.fuse - p_76986_9_ + 1.0F) / 100.0F) * 0.8F;
|
||||
this.bindEntityTexture(p_76986_1_);
|
||||
this.blockRenderer.renderBlockAsItem(ModBlocks.blood_tnt, 0, p_76986_1_.getBrightness(p_76986_9_));
|
||||
this.bindEntityTexture(entity);
|
||||
this.blockRenderer.renderBlockAsItem(ModBlocks.blood_tnt, 0, entity.getBrightness(renderTicks));
|
||||
|
||||
if (p_76986_1_.fuse / 5 % 2 == 0) {
|
||||
if (entity.fuse / 5 % 2 == 0) {
|
||||
float flashAlpha = (1.0F - timer / 100.0F) * 0.8F;
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_DST_ALPHA);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, f2);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, flashAlpha);
|
||||
this.blockRenderer.renderBlockAsItem(ModBlocks.blood_tnt, 0, 1.0F);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
@@ -72,28 +63,15 @@ public class RenderBloodTNTPrimed extends Render {
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
|
||||
*/
|
||||
protected ResourceLocation getEntityTexture(EntityBloodTNT p_110775_1_) {
|
||||
protected ResourceLocation getEntityTexture() {
|
||||
return TextureMap.locationBlocksTexture;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
|
||||
*/
|
||||
protected ResourceLocation getEntityTexture(Entity p_110775_1_) {
|
||||
return this.getEntityTexture((EntityBloodTNT) p_110775_1_);
|
||||
protected ResourceLocation getEntityTexture(Entity entity) {
|
||||
return this.getEntityTexture();
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
|
||||
* handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
|
||||
* (Render<T extends Entity) and this method has signature public void func_76986_a(T entity, double d, double d1,
|
||||
* double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.
|
||||
*/
|
||||
public void doRender(Entity p_76986_1_, double p_76986_2_, double p_76986_4_, double p_76986_6_, float p_76986_8_,
|
||||
float p_76986_9_) {
|
||||
this.doRender((EntityBloodTNT) p_76986_1_, p_76986_2_, p_76986_4_, p_76986_6_, p_76986_8_, p_76986_9_);
|
||||
public void doRender(Entity entity, double x, double y, double z, float ignored, float renderTicks) {
|
||||
this.doRender((EntityBloodTNT) entity, x, y, z, renderTicks);
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,17 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Calendar;
|
||||
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
|
||||
import net.minecraft.dispenser.IBlockSource;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemArmor;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.EnumHelper;
|
||||
|
||||
@@ -17,6 +23,7 @@ import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.arc.bloodarsenal.common.block.ModBlocks;
|
||||
import com.arc.bloodarsenal.common.entity.EntityBloodTNT;
|
||||
import com.arc.bloodarsenal.common.entity.ModLivingDropsEvent;
|
||||
import com.arc.bloodarsenal.common.gui.GuiHandler;
|
||||
import com.arc.bloodarsenal.common.items.ModItems;
|
||||
@@ -190,5 +197,28 @@ public class BloodArsenal {
|
||||
}
|
||||
|
||||
BloodArsenalConfig.postInit();
|
||||
registerDispenserBehavior();
|
||||
}
|
||||
|
||||
public static void registerDispenserBehavior() {
|
||||
BlockDispenser.dispenseBehaviorRegistry
|
||||
.putObject(Item.getItemFromBlock(ModBlocks.blood_tnt), new BehaviorDefaultDispenseItem() {
|
||||
|
||||
@Override
|
||||
protected ItemStack dispenseStack(IBlockSource dispenser, ItemStack dispensedItem) {
|
||||
EnumFacing enumfacing = BlockDispenser.func_149937_b(dispenser.getBlockMetadata());
|
||||
World world = dispenser.getWorld();
|
||||
int x = dispenser.getXInt() + enumfacing.getFrontOffsetX();
|
||||
int y = dispenser.getYInt() + enumfacing.getFrontOffsetY();
|
||||
int z = dispenser.getZInt() + enumfacing.getFrontOffsetZ();
|
||||
|
||||
EntityBloodTNT tnt = new EntityBloodTNT(world, x + 0.5F, y + 0.5F, z + 0.5F, null);
|
||||
world.spawnEntityInWorld(tnt);
|
||||
world.playSoundEffect(x + 0.5, y + 0.5, z + 0.5, "game.tnt.primed", 1.0F, 1.0F);
|
||||
|
||||
dispensedItem.stackSize--;
|
||||
return dispensedItem;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.arc.bloodarsenal.common.block;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockTNT;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
@@ -36,105 +34,91 @@ public class BlockBloodTNT extends BlockTNT {
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIcon(int par1, int par2) {
|
||||
return par1 == 0 ? bottom : (par1 == 1 ? top : blockIcon);
|
||||
public IIcon getIcon(int side, int meta) {
|
||||
return side == 0 ? bottom : (side == 1 ? top : blockIcon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockAdded(World par1World, int par2, int par3, int par4) {
|
||||
super.onBlockAdded(par1World, par2, par3, par4);
|
||||
public void onBlockAdded(World world, int x, int y, int z) {
|
||||
super.onBlockAdded(world, x, y, z);
|
||||
|
||||
if (par1World.isBlockIndirectlyGettingPowered(par2, par3, par4)) {
|
||||
onBlockDestroyedByPlayer(par1World, par2, par3, par4, 1);
|
||||
par1World.setBlockToAir(par2, par3, par4);
|
||||
if (world.isBlockIndirectlyGettingPowered(x, y, z)) {
|
||||
onBlockDestroyedByPlayer(world, x, y, z, 1);
|
||||
world.setBlockToAir(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, Block par5Block) {
|
||||
if (par1World.isBlockIndirectlyGettingPowered(par2, par3, par4)) {
|
||||
onBlockDestroyedByPlayer(par1World, par2, par3, par4, 1);
|
||||
par1World.setBlockToAir(par2, par3, par4);
|
||||
public void onNeighborBlockChange(World world, int x, int y, int z, Block block) {
|
||||
if (world.isBlockIndirectlyGettingPowered(x, y, z)) {
|
||||
onBlockDestroyedByPlayer(world, x, y, z, 1);
|
||||
world.setBlockToAir(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int quantityDropped(Random par1Random) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockDestroyedByExplosion(World par1World, int par2, int par3, int par4, Explosion par5Explosion) {
|
||||
if (!par1World.isRemote) {
|
||||
public void onBlockDestroyedByExplosion(World world, int x, int y, int z, Explosion explosion) {
|
||||
if (!world.isRemote) {
|
||||
EntityBloodTNT entitytntprimed = new EntityBloodTNT(
|
||||
par1World,
|
||||
(double) ((float) par2 + 0.5F),
|
||||
(double) ((float) par3 + 0.5F),
|
||||
(double) ((float) par4 + 0.5F),
|
||||
par5Explosion.getExplosivePlacedBy());
|
||||
entitytntprimed.fuse = par1World.rand.nextInt(entitytntprimed.fuse / 4) + entitytntprimed.fuse / 8;
|
||||
par1World.spawnEntityInWorld(entitytntprimed);
|
||||
world,
|
||||
(float) x + 0.5F,
|
||||
(float) y + 0.5F,
|
||||
(float) z + 0.5F,
|
||||
explosion.getExplosivePlacedBy());
|
||||
entitytntprimed.fuse = world.rand.nextInt(entitytntprimed.fuse / 4) + entitytntprimed.fuse / 8;
|
||||
world.spawnEntityInWorld(entitytntprimed);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5) {
|
||||
spawnTNT(par1World, par2, par3, par4, par5, null);
|
||||
public void onBlockDestroyedByPlayer(World world, int x, int y, int z, int meta) {
|
||||
spawnTNT(world, x, y, z, meta, null);
|
||||
}
|
||||
|
||||
public void spawnTNT(World par1World, int par2, int par3, int par4, int par5,
|
||||
EntityLivingBase par6EntityLivingBase) {
|
||||
if (!par1World.isRemote) {
|
||||
if ((par5 & 1) == 1) {
|
||||
public void spawnTNT(World world, int x, int y, int z, int meta, EntityLivingBase entity) {
|
||||
if (!world.isRemote) {
|
||||
if ((meta & 1) == 1) {
|
||||
EntityBloodTNT entitytntprimed = new EntityBloodTNT(
|
||||
par1World,
|
||||
(double) ((float) par2 + 0.5F),
|
||||
(double) ((float) par3 + 0.5F),
|
||||
(double) ((float) par4 + 0.5F),
|
||||
par6EntityLivingBase);
|
||||
par1World.spawnEntityInWorld(entitytntprimed);
|
||||
par1World.playSoundAtEntity(entitytntprimed, "game.tnt.primed", 1.0F, 1.0F);
|
||||
world,
|
||||
(float) x + 0.5F,
|
||||
(float) y + 0.5F,
|
||||
(float) z + 0.5F,
|
||||
entity);
|
||||
world.spawnEntityInWorld(entitytntprimed);
|
||||
world.playSoundAtEntity(entitytntprimed, "game.tnt.primed", 1.0F, 1.0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5, int par6,
|
||||
float par7, float par8, float par9) {
|
||||
if (par5.getCurrentEquippedItem() != null && (par5.getCurrentEquippedItem().getItem() == Items.flint_and_steel
|
||||
|| par5.getCurrentEquippedItem().getItem() == ModItems.bound_igniter)) {
|
||||
spawnTNT(par1World, par2, par3, par4, 1, par5);
|
||||
par1World.setBlockToAir(par2, par3, par4);
|
||||
par5.getCurrentEquippedItem().damageItem(1, par5);
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float subX,
|
||||
float subY, float subZ) {
|
||||
if (player.getCurrentEquippedItem() != null
|
||||
&& (player.getCurrentEquippedItem().getItem() == Items.flint_and_steel
|
||||
|| player.getCurrentEquippedItem().getItem() == ModItems.bound_igniter)) {
|
||||
spawnTNT(world, x, y, z, 1, player);
|
||||
world.setBlockToAir(x, y, z);
|
||||
player.getCurrentEquippedItem().damageItem(1, player);
|
||||
return true;
|
||||
} else {
|
||||
return super.onBlockActivated(par1World, par2, par3, par4, par5, par6, par7, par8, par9);
|
||||
return super.onBlockActivated(world, x, y, z, player, side, subX, subY, subZ);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity) {
|
||||
if (par5Entity instanceof EntityArrow && !par1World.isRemote) {
|
||||
EntityArrow entityarrow = (EntityArrow) par5Entity;
|
||||
|
||||
if (entityarrow.isBurning()) {
|
||||
spawnTNT(
|
||||
par1World,
|
||||
par2,
|
||||
par3,
|
||||
par4,
|
||||
1,
|
||||
entityarrow.shootingEntity instanceof EntityLivingBase
|
||||
? (EntityLivingBase) entityarrow.shootingEntity
|
||||
: null);
|
||||
par1World.setBlockToAir(par2, par3, par4);
|
||||
}
|
||||
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
|
||||
if (!(entity instanceof EntityArrow entityarrow) || world.isRemote || !entityarrow.isBurning()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDropFromExplosion(Explosion par1Explosion) {
|
||||
return false;
|
||||
spawnTNT(
|
||||
world,
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
1,
|
||||
entityarrow.shootingEntity instanceof EntityLivingBase ? (EntityLivingBase) entityarrow.shootingEntity
|
||||
: null);
|
||||
world.setBlockToAir(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,65 +1,42 @@
|
||||
package com.arc.bloodarsenal.common.entity;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.entity.item.EntityTNTPrimed;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
public class EntityBloodTNT extends EntityTNTPrimed {
|
||||
|
||||
public class EntityBloodTNT extends Entity {
|
||||
|
||||
public int fuse;
|
||||
private EntityLivingBase tntPlacedBy;
|
||||
|
||||
public EntityBloodTNT(World par1World) {
|
||||
super(par1World);
|
||||
preventEntitySpawning = true;
|
||||
setSize(0.98F, 0.98F);
|
||||
yOffset = height / 2.0F;
|
||||
@SuppressWarnings("unused")
|
||||
public EntityBloodTNT(World world) {
|
||||
super(world);
|
||||
fuse = 60;
|
||||
}
|
||||
|
||||
public EntityBloodTNT(World par1World, double par2, double par4, double par6,
|
||||
EntityLivingBase par8EntityLivingBase) {
|
||||
this(par1World);
|
||||
setPosition(par2, par4, par6);
|
||||
float f = (float) (Math.random() * Math.PI * 2.0D);
|
||||
motionX = (double) (-((float) Math.sin((double) f)) * 0.02F);
|
||||
motionY = 0.20000000298023224D;
|
||||
motionZ = (double) (-((float) Math.cos((double) f)) * 0.02F);
|
||||
public EntityBloodTNT(World world, double x, double y, double z, EntityLivingBase owner) {
|
||||
super(world, x, y, z, owner);
|
||||
fuse = 60;
|
||||
prevPosX = par2;
|
||||
prevPosY = par4;
|
||||
prevPosZ = par6;
|
||||
tntPlacedBy = par8EntityLivingBase;
|
||||
tntPlacedBy = owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void entityInit() {}
|
||||
|
||||
@Override
|
||||
public boolean canTriggerWalking() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeCollidedWith() {
|
||||
return !isDead;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
prevPosX = posX;
|
||||
prevPosY = posY;
|
||||
prevPosZ = posZ;
|
||||
motionY -= 0.03999999910593033D;
|
||||
motionY -= 0.04D;
|
||||
moveEntity(motionX, motionY, motionZ);
|
||||
motionX *= 0.9800000190734863D;
|
||||
motionY *= 0.9800000190734863D;
|
||||
motionZ *= 0.9800000190734863D;
|
||||
motionX *= 0.98D;
|
||||
motionY *= 0.98D;
|
||||
motionZ *= 0.98D;
|
||||
|
||||
if (onGround) {
|
||||
motionX *= 0.7D;
|
||||
motionZ *= 0.7D;
|
||||
motionY *= -0.5D;
|
||||
}
|
||||
|
||||
@@ -79,22 +56,6 @@ public class EntityBloodTNT extends Entity {
|
||||
worldObj.createExplosion(this, posX, posY, posZ, f, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeEntityToNBT(NBTTagCompound par1) {
|
||||
par1.setByte("Fuse", (byte) fuse);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readEntityFromNBT(NBTTagCompound par1) {
|
||||
fuse = par1.getByte("Fuse");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getShadowSize() {
|
||||
return 0.0F;
|
||||
}
|
||||
|
||||
public EntityLivingBase getTntPlacedBy() {
|
||||
return tntPlacedBy;
|
||||
}
|
||||
|
||||
@@ -111,6 +111,9 @@ item.wand_cores.blood_wood_staff.name=Blood Infused Wooden Staff Of Doom
|
||||
item.Wand.blood_iron.cap=Blood Iron Topped
|
||||
item.Wand.blood_wood.rod=Blood Wood
|
||||
|
||||
#Entities
|
||||
entity.bloodTNT.name=Blood TNT
|
||||
|
||||
#Death Texts
|
||||
death.attack.deathFromBlood=%1$s lost too much blood
|
||||
|
||||
|
||||
Reference in new issue
Block a user