Making things safer, better and all that.

This commit is contained in:
Vasco Lavos committed 2014-02-01 01:03:34 +00:00
1 parent 73d1a1bfe9
commit 95bd5392ab
6 files changed
+151 -66

No files matched your search

@@ -11,6 +11,8 @@
*/
package vazkii.botania.common.block;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
@@ -18,6 +20,7 @@ import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
@@ -25,6 +28,7 @@ import vazkii.botania.api.ILexiconable;
import vazkii.botania.api.LexiconEntry;
import vazkii.botania.client.lib.LibRenderIDs;
import vazkii.botania.common.block.tile.TileAltar;
import vazkii.botania.common.block.tile.TileSimpleInventory;
import vazkii.botania.common.lexicon.LexiconData;
import vazkii.botania.common.lib.LibBlockIDs;
import vazkii.botania.common.lib.LibBlockNames;
@@ -32,6 +36,8 @@ import cpw.mods.fml.common.network.PacketDispatcher;
public class BlockAltar extends BlockModContainer implements ILexiconable {
Random random;
protected BlockAltar() {
super(LibBlockIDs.idAltar, Material.rock);
setHardness(3.5F);
@@ -40,6 +46,8 @@ public class BlockAltar extends BlockModContainer implements ILexiconable {
float f = 1F / 16F * 2F;
setBlockBounds(f, f, f, 1F - f, 1F / 16F * 20F, 1F - f);
random = new Random();
}
@Override
@@ -90,6 +98,44 @@ public class BlockAltar extends BlockModContainer implements ILexiconable {
public TileEntity createNewTileEntity(World world) {
return new TileAltar();
}
@Override
public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6) {
TileSimpleInventory inv = (TileSimpleInventory) par1World.getBlockTileEntity(par2, par3, par4);
if (inv != null) {
for (int j1 = 0; j1 < inv.getSizeInventory(); ++j1) {
ItemStack itemstack = inv.getStackInSlot(j1);
if (itemstack != null) {
float f = random.nextFloat() * 0.8F + 0.1F;
float f1 = random.nextFloat() * 0.8F + 0.1F;
EntityItem entityitem;
for (float f2 = random.nextFloat() * 0.8F + 0.1F; itemstack.stackSize > 0; par1World.spawnEntityInWorld(entityitem)) {
int k1 = random.nextInt(21) + 10;
if (k1 > itemstack.stackSize)
k1 = itemstack.stackSize;
itemstack.stackSize -= k1;
entityitem = new EntityItem(par1World, par2 + f, par3 + f1, par4 + f2, new ItemStack(itemstack.itemID, k1, itemstack.getItemDamage()));
float f3 = 0.05F;
entityitem.motionX = (float)random.nextGaussian() * f3;
entityitem.motionY = (float)random.nextGaussian() * f3 + 0.2F;
entityitem.motionZ = (float)random.nextGaussian() * f3;
if (itemstack.hasTagCompound())
entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
}
}
}
par1World.func_96440_m(par2, par3, par4, par5);
}
super.breakBlock(par1World, par2, par3, par4, par5, par6);
}
@Override
public LexiconEntry getEntry(World world, int x, int y, int z, EntityPlayer player, ItemStack lexicon) {
@@ -11,11 +11,15 @@
*/
package vazkii.botania.common.block;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
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.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
@@ -23,6 +27,7 @@ import vazkii.botania.api.IWandable;
import vazkii.botania.api.mana.ILens;
import vazkii.botania.client.core.handler.HUDHandler.IHUD;
import vazkii.botania.client.lib.LibRenderIDs;
import vazkii.botania.common.block.tile.TileSimpleInventory;
import vazkii.botania.common.block.tile.TileSpreader;
import vazkii.botania.common.item.ModItems;
import vazkii.botania.common.lib.LibBlockIDs;
@@ -30,11 +35,15 @@ import vazkii.botania.common.lib.LibBlockNames;
public class BlockSpreader extends BlockModContainer implements IWandable, IHUD {
Random random;
protected BlockSpreader() {
super(LibBlockIDs.idSpreader, Material.wood);
setHardness(2.0F);
setStepSound(soundWoodFootstep);
setUnlocalizedName(LibBlockNames.SPREADER);
random = new Random();
}
@Override
@@ -82,6 +91,45 @@ public class BlockSpreader extends BlockModContainer implements IWandable, IHUD
return true;
}
@Override
public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6) {
TileSimpleInventory inv = (TileSimpleInventory) par1World.getBlockTileEntity(par2, par3, par4);
if (inv != null) {
for (int j1 = 0; j1 < inv.getSizeInventory(); ++j1) {
ItemStack itemstack = inv.getStackInSlot(j1);
if (itemstack != null) {
float f = random.nextFloat() * 0.8F + 0.1F;
float f1 = random.nextFloat() * 0.8F + 0.1F;
EntityItem entityitem;
for (float f2 = random.nextFloat() * 0.8F + 0.1F; itemstack.stackSize > 0; par1World.spawnEntityInWorld(entityitem)) {
int k1 = random.nextInt(21) + 10;
if (k1 > itemstack.stackSize)
k1 = itemstack.stackSize;
itemstack.stackSize -= k1;
entityitem = new EntityItem(par1World, par2 + f, par3 + f1, par4 + f2, new ItemStack(itemstack.itemID, k1, itemstack.getItemDamage()));
float f3 = 0.05F;
entityitem.motionX = (float)random.nextGaussian() * f3;
entityitem.motionY = (float)random.nextGaussian() * f3 + 0.2F;
entityitem.motionZ = (float)random.nextGaussian() * f3;
if (itemstack.hasTagCompound())
entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
}
}
}
par1World.func_96440_m(par2, par3, par4, par5);
}
super.breakBlock(par1World, par2, par3, par4, par5, par6);
}
@Override
public boolean onUsedByWand(EntityPlayer player, ItemStack stack, World world, int x, int y, int z, int side) {
((TileSpreader) world.getBlockTileEntity(x, y, z)).onWanded(player, stack);
@@ -31,7 +31,7 @@ import vazkii.botania.common.lib.LibBlockNames;
import cpw.mods.fml.common.network.PacketDispatcher;
import cpw.mods.fml.common.network.Player;
public class TilePool extends TileSimpleInventory implements IManaPool {
public class TilePool extends TileMod implements IManaPool {
public static final int MAX_MANA = 1000000;
@@ -157,19 +157,4 @@ public class TilePool extends TileSimpleInventory implements IManaPool {
public int getCurrentMana() {
return mana;
}
@Override
public int getSizeInventory() {
return 1;
}
@Override
public int getInventoryStackLimit() {
return 1;
}
@Override
public String getInvName() {
return LibBlockNames.POOL;
}
}
@@ -198,17 +198,13 @@ public class TileSpreader extends TileSimpleInventory implements IManaCollector
}
if(receiver != null) {
TileEntity tile = (TileEntity) receiver;
TileEntity tileAt = worldObj.getBlockTileEntity(tile.xCoord, tile.yCoord, tile.zCoord);
if(tileAt instanceof IManaReceiver)
receiver = (IManaReceiver) tileAt;
else receiver = null;
forceCheckReceiver();
if(receiver != null) {
if(canShootBurst && receiver.canRecieveManaFromBursts() && !receiver.isFull()) {
EntityManaBurst burst = getBurst(false);
if(burst != null) {
mana -= burst.getMana();
mana -= burst.getStartingMana();
worldObj.spawnEntityInWorld(burst);
canShootBurst = false;
PacketDispatcher.sendPacketToAllInDimension(getDescriptionPacket(), worldObj.provider.dimensionId);
@@ -217,6 +213,14 @@ public class TileSpreader extends TileSimpleInventory implements IManaCollector
}
}
}
public void forceCheckReceiver() {
EntityManaBurst fakeBurst = getBurst(true);
TileEntity receiver = fakeBurst.getCollidedTile(true);
if(receiver != null && receiver instanceof IManaReceiver)
this.receiver = (IManaReceiver) receiver;
else this.receiver = null;
}
public EntityManaBurst getBurst(boolean fake) {
EntityManaBurst burst = new EntityManaBurst(worldObj, this, fake);
@@ -346,6 +350,7 @@ public class TileSpreader extends TileSimpleInventory implements IManaCollector
@Override
public void onInventoryChanged() {
forceCheckReceiver();
PacketDispatcher.sendPacketToAllInDimension(getDescriptionPacket(), worldObj.provider.dimensionId);
}
}
@@ -39,11 +39,11 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
private static final String TAG_SPREADER_Y = "spreaderY";
private static final String TAG_SPREADER_Z = "spreaderZ";
private static final String TAG_GRAVITY = "gravity";
double lastXMotion, lastYMotion, lastZMotion;
boolean fake = false;
final int dataWatcherEntries = 10;
final int dataWatcherStart = 32 - dataWatcherEntries;
@@ -82,36 +82,32 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
@Override
public void onUpdate() {
try {
motionX = lastXMotion;
motionY = lastYMotion;
motionZ = lastZMotion;
super.onUpdate();
ILens lens = getLensInstance();
if(lens != null)
lens.updateBurst(this, getSourceLens());
motionX = lastXMotion;
motionY = lastYMotion;
motionZ = lastZMotion;
particles();
super.onUpdate();
int mana = getMana();
if(ticksExisted >= getMinManaLoss()) {
accumulatedManaLoss += getManaLossPerTick();
int loss = (int) accumulatedManaLoss;
setMana(mana - loss);
accumulatedManaLoss -= loss;
ILens lens = getLensInstance();
if(lens != null)
lens.updateBurst(this, getSourceLens());
if(getMana() <= 0)
setDead();
}
lastXMotion = motionX;
lastYMotion = motionY;
lastZMotion = motionZ;
} catch(NullPointerException e) {
// Apparently this can happen on some weird occasions on clients.
particles();
int mana = getMana();
if(ticksExisted >= getMinManaLoss()) {
accumulatedManaLoss += getManaLossPerTick();
int loss = (int) accumulatedManaLoss;
setMana(mana - loss);
accumulatedManaLoss -= loss;
if(getMana() <= 0)
setDead();
}
lastXMotion = motionX;
lastYMotion = motionY;
lastZMotion = motionZ;
}
TileEntity collidedTile = null;
@@ -124,6 +120,7 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
++ticksExisted;
onUpdate();
}
return collidedTile;
}
@@ -152,7 +149,7 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
setMinManaLoss(par1nbtTagCompound.getInteger(TAG_MIN_MANA_LOSS));
setManaLossPerTick(par1nbtTagCompound.getFloat(TAG_TICK_MANA_LOSS));
setGravity(par1nbtTagCompound.getFloat(TAG_GRAVITY));
int x = par1nbtTagCompound.getInteger(TAG_SPREADER_X);
int y = par1nbtTagCompound.getInteger(TAG_SPREADER_Y);
int z = par1nbtTagCompound.getInteger(TAG_SPREADER_Z);
@@ -181,7 +178,7 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
@Override
protected void onImpact(MovingObjectPosition movingobjectposition) {
boolean mana = false;
if(movingobjectposition.entityHit == null) {
TileEntity tile = worldObj.getBlockTileEntity(movingobjectposition.blockX, movingobjectposition.blockY, movingobjectposition.blockZ);
@@ -190,16 +187,16 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
collidedTile = tile;
if(tile == null || tile.xCoord != coords.posX || tile.yCoord != coords.posY || tile.zCoord != coords.posZ) {
if((!fake || noParticles) && !worldObj.isRemote && tile != null && tile instanceof IManaReceiver && ((IManaReceiver) tile).canRecieveManaFromBursts()) {
if(!fake && !noParticles && !worldObj.isRemote && tile != null && tile instanceof IManaReceiver && ((IManaReceiver) tile).canRecieveManaFromBursts()) {
mana = true;
((IManaReceiver) tile).recieveMana(getMana());
PacketDispatcher.sendPacketToAllInDimension(tile.getDescriptionPacket(), worldObj.provider.dimensionId);
}
setDead();
}
}
ILens lens = getLensInstance();
if(lens != null)
lens.collideBurst(this, movingobjectposition, mana, getSourceLens());
@@ -221,7 +218,7 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
protected float getGravityVelocity() {
return getGravity();
}
@Override
public boolean isFake() {
return fake;
@@ -261,7 +258,7 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
public int getMinManaLoss() {
return dataWatcher.getWatchableObjectInt(dataWatcherStart + 3);
}
@Override
public void setMinManaLoss(int minManaLoss) {
dataWatcher.updateObject(dataWatcherStart + 3, minManaLoss);
@@ -276,7 +273,7 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
public void setManaLossPerTick(float mana) {
dataWatcher.updateObject(dataWatcherStart + 4, mana);
}
@Override
public float getGravity() {
@@ -288,9 +285,9 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
dataWatcher.updateObject(dataWatcherStart + 5, gravity);
}
final int coordsStart = dataWatcherStart + 6;
@Override
public ChunkCoordinates getBurstSourceChunkCoordinates() {
int x = dataWatcher.getWatchableObjectInt(coordsStart);
@@ -316,12 +313,12 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
public void setSourceLens(ItemStack lens) {
dataWatcher.updateObject(dataWatcherStart + 9, lens == null ? new ItemStack(1, 0, 0) : lens);
}
public ILens getLensInstance() {
ItemStack lens = getSourceLens();
if(lens != null && lens.getItem() instanceof ILens)
return (ILens) lens.getItem();
return null;
}
@@ -109,6 +109,8 @@ public class ItemLens extends ItemMod implements ILens {
switch(stack.getItemDamage()) {
case 1 : { // Speed
props.motionModifier = 2F;
props.maxMana *= 0.75F;
props.ticksBeforeManaLoss *= 0.5F;
break;
}
case 2 : { // Potency
@@ -124,7 +126,7 @@ public class ItemLens extends ItemMod implements ILens {
break;
}
case 6 : { // Gravity
props.gravity = 0.003F;
props.gravity = 0.0015F;
break;
}
}
@@ -137,7 +139,9 @@ public class ItemLens extends ItemMod implements ILens {
@Override
public void updateBurst(IManaBurst burst, ItemStack stack) {
// NO-OP
int storedColor = getStoredColor(stack);
if(storedColor == 16)
burst.setColor(getLensColor(stack));
}
@Override