Zap some duplicated code

This commit is contained in:
Vincent Lee committed 2016-06-04 12:06:39 -05:00
1 parent 49a6f00b41
commit d241f95bee
13 files changed
+63 -361

No files matched your search

@@ -44,6 +44,7 @@ import vazkii.botania.api.state.enums.AltarVariant;
import vazkii.botania.common.Botania;
import vazkii.botania.common.block.tile.TileAltar;
import vazkii.botania.common.block.tile.TileSimpleInventory;
import vazkii.botania.common.core.helper.InventoryHelper;
import vazkii.botania.common.item.ModItems;
import vazkii.botania.common.item.block.ItemBlockWithMetadataAndName;
import vazkii.botania.common.item.rod.ItemWaterRod;
@@ -58,8 +59,6 @@ public class BlockAltar extends BlockMod implements ILexiconable {
private static final AxisAlignedBB AABB = new AxisAlignedBB(0.125, 0.125, 0.125, 0.875, 20.0/16, 0.875);
private final Random random = new Random();
protected BlockAltar() {
super(Material.ROCK, LibBlockNames.ALTAR);
setHardness(3.5F);
@@ -147,17 +146,7 @@ public class BlockAltar extends BlockMod implements ILexiconable {
public boolean onBlockActivated(World par1World, BlockPos pos, IBlockState state, EntityPlayer par5EntityPlayer, EnumHand hand, ItemStack stack, EnumFacing par6, float par7, float par8, float par9) {
TileAltar tile = (TileAltar) par1World.getTileEntity(pos);
if(par5EntityPlayer.isSneaking()) {
for(int i = tile.getSizeInventory() - 1; i >= 0; i--) {
ItemStack stackAt = tile.getItemHandler().getStackInSlot(i);
if(stackAt != null) {
ItemStack copy = stackAt.copy();
if(!par5EntityPlayer.inventory.addItemStackToInventory(copy))
par5EntityPlayer.dropItem(copy, false);
tile.getItemHandler().setStackInSlot(i, null);
par1World.updateComparatorOutputLevel(pos, this);
break;
}
}
InventoryHelper.withdrawFromInventory(tile, par5EntityPlayer);
} else if(tile.isEmpty() && tile.hasWater && stack == null)
tile.trySetLastRecipe(par5EntityPlayer);
else {
@@ -276,36 +265,7 @@ public class BlockAltar extends BlockMod implements ILexiconable {
public void breakBlock(@Nonnull World par1World, @Nonnull BlockPos pos, @Nonnull IBlockState state) {
TileSimpleInventory inv = (TileSimpleInventory) par1World.getTileEntity(pos);
if (inv != null) {
for (int j1 = 0; j1 < inv.getSizeInventory(); ++j1) {
ItemStack itemstack = inv.getItemHandler().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, pos.getX() + f, pos.getY() + f1, pos.getZ() + f2, new ItemStack(itemstack.getItem(), 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.updateComparatorOutputLevel(pos, state.getBlock());
}
InventoryHelper.dropInventory(inv, par1World, state, pos);
super.breakBlock(par1World, pos, state);
}
@@ -33,6 +33,7 @@ import vazkii.botania.api.lexicon.LexiconEntry;
import vazkii.botania.api.state.BotaniaStateProps;
import vazkii.botania.common.block.tile.TileAvatar;
import vazkii.botania.common.block.tile.TileSimpleInventory;
import vazkii.botania.common.core.helper.InventoryHelper;
import vazkii.botania.common.lexicon.LexiconData;
import vazkii.botania.common.lib.LibBlockNames;
@@ -44,8 +45,6 @@ public class BlockAvatar extends BlockMod implements ILexiconable {
private static final AxisAlignedBB X_AABB = new AxisAlignedBB(.3125, 0, .21875, 1-.3125, 17/16.0, 1-.21875);
private static final AxisAlignedBB Z_AABB = new AxisAlignedBB(.21875, 0, .3125, 1-.21875, 17/16.0, 1-.3125);
private final Random random = new Random();
protected BlockAvatar() {
super(Material.WOOD, LibBlockNames.AVATAR);
setHardness(2.0F);
@@ -105,36 +104,7 @@ public class BlockAvatar extends BlockMod implements ILexiconable {
public void breakBlock(@Nonnull World par1World, @Nonnull BlockPos pos, @Nonnull IBlockState state) {
TileSimpleInventory inv = (TileSimpleInventory) par1World.getTileEntity(pos);
if (inv != null) {
for (int j1 = 0; j1 < inv.getSizeInventory(); ++j1) {
ItemStack itemstack = inv.getItemHandler().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, pos.getX() + f, pos.getY() + f1, pos.getZ() + f2, new ItemStack(itemstack.getItem(), 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.updateComparatorOutputLevel(pos, state.getBlock());
}
InventoryHelper.dropInventory(inv, par1World, state, pos);
super.breakBlock(par1World, pos, state);
}
@@ -39,6 +39,7 @@ import vazkii.botania.api.wand.IWandHUD;
import vazkii.botania.api.wand.IWandable;
import vazkii.botania.common.block.tile.TileHourglass;
import vazkii.botania.common.block.tile.TileSimpleInventory;
import vazkii.botania.common.core.helper.InventoryHelper;
import vazkii.botania.common.item.ModItems;
import vazkii.botania.common.lexicon.LexiconData;
import vazkii.botania.common.lib.LibBlockNames;
@@ -50,8 +51,6 @@ public class BlockHourglass extends BlockMod implements IManaTrigger, IWandable,
private static final AxisAlignedBB AABB = new AxisAlignedBB(0.25, 0, 0.25, 0.75, 1.15, 0.75);
private final Random random = new Random();
protected BlockHourglass() {
super(Material.IRON, LibBlockNames.HOURGLASS);
setHardness(2.0F);
@@ -137,36 +136,7 @@ public class BlockHourglass extends BlockMod implements IManaTrigger, IWandable,
public void breakBlock(@Nonnull World par1World, @Nonnull BlockPos pos, @Nonnull IBlockState state) {
TileSimpleInventory inv = (TileSimpleInventory) par1World.getTileEntity(pos);
if (inv != null) {
for (int j1 = 0; j1 < inv.getSizeInventory(); ++j1) {
ItemStack itemstack = inv.getItemHandler().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, pos.getX() + f, pos.getY() + f1, pos.getZ() + f2, new ItemStack(itemstack.getItem(), 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.updateComparatorOutputLevel(pos, state.getBlock());
}
InventoryHelper.dropInventory(inv, par1World, state, pos);
super.breakBlock(par1World, pos, state);
}
@@ -40,6 +40,7 @@ import vazkii.botania.api.wand.IWandable;
import vazkii.botania.common.block.tile.TileCraftCrate;
import vazkii.botania.common.block.tile.TileOpenCrate;
import vazkii.botania.common.block.tile.TileSimpleInventory;
import vazkii.botania.common.core.helper.InventoryHelper;
import vazkii.botania.common.item.block.ItemBlockWithMetadataAndName;
import vazkii.botania.common.lexicon.LexiconData;
import vazkii.botania.common.lib.LibBlockNames;
@@ -50,8 +51,6 @@ import java.util.Random;
public class BlockOpenCrate extends BlockMod implements ILexiconable, IWandable, IWandHUD {
final Random random;
public BlockOpenCrate() {
super(Material.WOOD, LibBlockNames.OPEN_CRATE);
setHardness(2.0F);
@@ -59,7 +58,6 @@ public class BlockOpenCrate extends BlockMod implements ILexiconable, IWandable,
setDefaultState(blockState.getBaseState()
.withProperty(BotaniaStateProps.CRATE_VARIANT, CrateVariant.OPEN)
.withProperty(BotaniaStateProps.CRATE_PATTERN, CratePattern.NONE));
random = new Random();
}
@Nonnull
@@ -127,36 +125,7 @@ public class BlockOpenCrate extends BlockMod implements ILexiconable, IWandable,
public void breakBlock(@Nonnull World par1World, @Nonnull BlockPos pos, @Nonnull IBlockState state) {
TileSimpleInventory inv = (TileSimpleInventory) par1World.getTileEntity(pos);
if (inv != null) {
for (int j1 = 0; j1 < inv.getSizeInventory(); ++j1) {
ItemStack itemstack = inv.getItemHandler().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, pos.getX() + f, pos.getY() + f1, pos.getZ() + f2, new ItemStack(itemstack.getItem(), 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.updateComparatorOutputLevel(pos, state.getBlock());
}
InventoryHelper.dropInventory(inv, par1World, state, pos);
super.breakBlock(par1World, pos, state);
}
@@ -31,6 +31,7 @@ import vazkii.botania.api.lexicon.LexiconEntry;
import vazkii.botania.api.state.BotaniaStateProps;
import vazkii.botania.common.block.tile.TileSimpleInventory;
import vazkii.botania.common.block.tile.TileSparkChanger;
import vazkii.botania.common.core.helper.InventoryHelper;
import vazkii.botania.common.item.ModItems;
import vazkii.botania.common.lexicon.LexiconData;
import vazkii.botania.common.lib.LibBlockNames;
@@ -42,8 +43,6 @@ public class BlockSparkChanger extends BlockMod implements ILexiconable {
private static final AxisAlignedBB AABB = new AxisAlignedBB(0, 0, 0, 1, 3.0/16, 1);
private final Random random = new Random();
public BlockSparkChanger() {
super(Material.ROCK, LibBlockNames.SPARK_CHANGER);
setHardness(2.0F);
@@ -132,36 +131,7 @@ public class BlockSparkChanger extends BlockMod implements ILexiconable {
public void breakBlock(@Nonnull World par1World, @Nonnull BlockPos pos, @Nonnull IBlockState state) {
TileSimpleInventory inv = (TileSimpleInventory) par1World.getTileEntity(pos);
if (inv != null) {
for (int j1 = 0; j1 < inv.getSizeInventory(); ++j1) {
ItemStack itemstack = inv.getItemHandler().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, pos.getX() + f, pos.getY() + f1, pos.getZ() + f2, new ItemStack(itemstack.getItem(), 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.updateComparatorOutputLevel(pos, state.getBlock());
}
InventoryHelper.dropInventory(inv, par1World, state, pos);
super.breakBlock(par1World, pos, state);
}
@@ -24,14 +24,13 @@ import vazkii.botania.common.achievement.ICraftAchievement;
import vazkii.botania.common.achievement.ModAchievements;
import vazkii.botania.common.block.BlockMod;
import vazkii.botania.common.block.tile.TileSimpleInventory;
import vazkii.botania.common.core.helper.InventoryHelper;
import javax.annotation.Nonnull;
import java.util.Random;
public abstract class BlockCorporeaBase extends BlockMod implements ICraftAchievement {
private final Random random = new Random();
public BlockCorporeaBase(Material material, String name) {
super(material, name);
}
@@ -40,36 +39,7 @@ public abstract class BlockCorporeaBase extends BlockMod implements ICraftAchiev
public void breakBlock(@Nonnull World par1World, @Nonnull BlockPos pos, @Nonnull IBlockState state) {
TileSimpleInventory inv = (TileSimpleInventory) par1World.getTileEntity(pos);
if (inv != null) {
for (int j1 = 0; j1 < inv.getSizeInventory(); ++j1) {
ItemStack itemstack = inv.getItemHandler().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, pos.getX() + f, pos.getY() + f1, pos.getZ() + f2, new ItemStack(itemstack.getItem(), 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.notifyNeighborsOfStateChange(pos, state.getBlock());
}
InventoryHelper.dropInventory(inv, par1World, state, pos);
super.breakBlock(par1World, pos, state);
}
@@ -35,6 +35,7 @@ import vazkii.botania.api.wand.IWandHUD;
import vazkii.botania.common.block.BlockMod;
import vazkii.botania.common.block.tile.TileBrewery;
import vazkii.botania.common.block.tile.TileSimpleInventory;
import vazkii.botania.common.core.helper.InventoryHelper;
import vazkii.botania.common.lexicon.LexiconData;
import vazkii.botania.common.lib.LibBlockNames;
@@ -45,8 +46,6 @@ public class BlockBrewery extends BlockMod implements ILexiconable, IWandHUD {
private static final AxisAlignedBB AABB = new AxisAlignedBB(0.375, 0.05, 0.375, 0.625, 0.95, 0.625);
private final Random random = new Random();
public BlockBrewery() {
super(Material.ROCK, LibBlockNames.BREWERY);
setHardness(2.0F);
@@ -84,17 +83,7 @@ public class BlockBrewery extends BlockMod implements ILexiconable, IWandHUD {
if(par5EntityPlayer.isSneaking()) {
if(brew.recipe == null && !state.getValue(BotaniaStateProps.POWERED))
for(int i = brew.getSizeInventory() - 1; i >= 0; i--) {
ItemStack stackAt = brew.getItemHandler().getStackInSlot(i);
if(stackAt != null) {
ItemStack copy = stackAt.copy();
if(!par5EntityPlayer.inventory.addItemStackToInventory(copy))
par5EntityPlayer.dropItem(copy, false);
brew.getItemHandler().setStackInSlot(i, null);
par1World.updateComparatorOutputLevel(pos, this);
break;
}
}
InventoryHelper.withdrawFromInventory(brew, par5EntityPlayer);
} else {
if(stack != null)
return brew.addItem(par5EntityPlayer, stack);
@@ -106,36 +95,7 @@ public class BlockBrewery extends BlockMod implements ILexiconable, IWandHUD {
public void breakBlock(@Nonnull World par1World, @Nonnull BlockPos pos, @Nonnull IBlockState state) {
TileSimpleInventory inv = (TileSimpleInventory) par1World.getTileEntity(pos);
if (inv != null) {
for (int j1 = 0; j1 < inv.getSizeInventory(); ++j1) {
ItemStack itemstack = inv.getItemHandler().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, pos.getX() + f, pos.getY() + f1, pos.getZ() + f2, new ItemStack(itemstack.getItem(), 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.updateComparatorOutputLevel(pos, state.getBlock());
}
InventoryHelper.dropInventory(inv, par1World, state, pos);
super.breakBlock(par1World, pos, state);
}
@@ -39,6 +39,7 @@ import vazkii.botania.api.state.BotaniaStateProps;
import vazkii.botania.common.block.BlockMod;
import vazkii.botania.common.block.tile.TileSimpleInventory;
import vazkii.botania.common.block.tile.mana.TilePrism;
import vazkii.botania.common.core.helper.InventoryHelper;
import vazkii.botania.common.lexicon.LexiconData;
import vazkii.botania.common.lib.LibBlockNames;
@@ -153,42 +154,9 @@ public class BlockPrism extends BlockMod implements IManaTrigger, ILexiconable,
@Override
public void breakBlock(@Nonnull World par1World, @Nonnull BlockPos pos, @Nonnull IBlockState state) {
TileEntity tile = par1World.getTileEntity(pos);
if(!(tile instanceof TileSimpleInventory))
return;
TileSimpleInventory inv = (TileSimpleInventory) par1World.getTileEntity(pos);
TileSimpleInventory inv = (TileSimpleInventory) tile;
if (inv != null) {
for (int j1 = 0; j1 < inv.getSizeInventory(); ++j1) {
ItemStack itemstack = inv.getItemHandler().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, pos.getX() + f, pos.getY() + f1, pos.getZ() + f2, new ItemStack(itemstack.getItem(), 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.updateComparatorOutputLevel(pos, state.getBlock());
}
InventoryHelper.dropInventory(inv, par1World, state, pos);
super.breakBlock(par1World, pos, state);
}
@@ -31,6 +31,7 @@ import vazkii.botania.api.wand.IWandable;
import vazkii.botania.common.block.BlockMod;
import vazkii.botania.common.block.tile.TileRuneAltar;
import vazkii.botania.common.block.tile.TileSimpleInventory;
import vazkii.botania.common.core.helper.InventoryHelper;
import vazkii.botania.common.lexicon.LexiconData;
import vazkii.botania.common.lib.LibBlockNames;
@@ -41,8 +42,6 @@ public class BlockRuneAltar extends BlockMod implements IWandable, ILexiconable
private static final AxisAlignedBB AABB = new AxisAlignedBB(0, 0, 0, 1, 0.75, 1);
private final Random random = new Random();
public BlockRuneAltar() {
super(Material.ROCK, LibBlockNames.RUNE_ALTAR);
setHardness(2.0F);
@@ -73,17 +72,7 @@ public class BlockRuneAltar extends BlockMod implements IWandable, ILexiconable
if(par5EntityPlayer.isSneaking()) {
if(altar.manaToGet == 0)
for(int i = altar.getSizeInventory() - 1; i >= 0; i--) {
ItemStack stackAt = altar.getItemHandler().getStackInSlot(i);
if(stackAt != null) {
ItemStack copy = stackAt.copy();
if(!par5EntityPlayer.inventory.addItemStackToInventory(copy))
par5EntityPlayer.dropItem(copy, false);
altar.getItemHandler().setStackInSlot(i, null);
par1World.updateComparatorOutputLevel(pos, this);
break;
}
}
InventoryHelper.withdrawFromInventory(altar, par5EntityPlayer);
} else if(altar.isEmpty() && stack == null)
altar.trySetLastRecipe(par5EntityPlayer);
else if(stack != null)
@@ -95,36 +84,7 @@ public class BlockRuneAltar extends BlockMod implements IWandable, ILexiconable
public void breakBlock(@Nonnull World par1World, @Nonnull BlockPos pos, @Nonnull IBlockState state) {
TileSimpleInventory inv = (TileSimpleInventory) par1World.getTileEntity(pos);
if (inv != null) {
for (int j1 = 0; j1 < inv.getSizeInventory(); ++j1) {
ItemStack itemstack = inv.getItemHandler().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, pos.getX() + f, pos.getY() + f1, pos.getZ() + f2, new ItemStack(itemstack.getItem(), 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.updateComparatorOutputLevel(pos, state.getBlock());
}
InventoryHelper.dropInventory(inv, par1World, state, pos);
super.breakBlock(par1World, pos, state);
}
@@ -19,12 +19,10 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
@@ -43,6 +41,7 @@ import vazkii.botania.api.wand.IWandable;
import vazkii.botania.api.wand.IWireframeAABBProvider;
import vazkii.botania.common.block.BlockMod;
import vazkii.botania.common.block.tile.mana.TileSpreader;
import vazkii.botania.common.core.helper.InventoryHelper;
import vazkii.botania.common.item.ModItems;
import vazkii.botania.common.item.block.ItemBlockWithMetaNameAndColor;
import vazkii.botania.common.lexicon.LexiconData;
@@ -54,8 +53,6 @@ import java.util.Random;
public class BlockSpreader extends BlockMod implements IWandable, IWandHUD, ILexiconable, IWireframeAABBProvider {
private final Random random = new Random();
public BlockSpreader() {
super(Material.WOOD, LibBlockNames.SPREADER);
setHardness(2.0F);
@@ -195,37 +192,12 @@ public class BlockSpreader extends BlockMod implements IWandable, IWandHUD, ILex
TileSpreader inv = (TileSpreader) tile;
if (inv != null) {
for (int j1 = 0; j1 < inv.getSizeInventory() + 1; ++j1) {
ItemStack itemstack = j1 >= inv.getSizeInventory() ? inv.paddingColor == -1 ? null : new ItemStack(Blocks.WOOL, 1, inv.paddingColor) : inv.getItemHandler().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, pos.getX() + f, pos.getY() + f1, pos.getZ() + f2, new ItemStack(itemstack.getItem(), 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.updateComparatorOutputLevel(pos, state.getBlock());
if(inv.paddingColor != -1) {
net.minecraft.inventory.InventoryHelper.spawnItemStack(par1World, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Blocks.WOOL, 1, inv.paddingColor));
}
InventoryHelper.dropInventory(inv, par1World, state, pos);
super.breakBlock(par1World, pos, state);
}
@@ -226,7 +226,7 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary {
}
}
public void craftingFanciness() {
private void craftingFanciness() {
worldObj.playSound(null, pos, BotaniaSoundEvents.altarCraft, SoundCategory.BLOCKS, 1F, 1F);
for(int i = 0; i < 25; i++) {
float red = (float) Math.random();
@@ -272,7 +272,7 @@ public class TileEnchanter extends TileMod implements ISparkAttachable {
sync();
}
public void craftingFanciness() {
private void craftingFanciness() {
worldObj.playSound(null, pos, BotaniaSoundEvents.enchanterEnchant, SoundCategory.BLOCKS, 1F, 1F);
for(int i = 0; i < 25; i++) {
float red = (float) Math.random();
@@ -10,6 +10,8 @@
*/
package vazkii.botania.common.core.helper;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
@@ -26,19 +28,22 @@ import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.items.VanillaDoubleChestItemHandler;
import vazkii.botania.api.corporea.InvWithLocation;
import vazkii.botania.common.block.tile.TileSimpleInventory;
import javax.annotation.Nonnull;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
//From OpenBlocksLib: https://github.com/OpenMods/OpenModsLib
// Some methods from OpenBlocksLib: https://github.com/OpenMods/OpenModsLib
public class InventoryHelper {
protected static boolean areMergeCandidates(ItemStack source, ItemStack target) {
@@ -334,4 +339,32 @@ public class InventoryHelper {
@Override
public void closeInventory(@Nonnull EntityPlayer player) { }
}
public static void dropInventory(TileSimpleInventory inv, World world, IBlockState state, BlockPos pos) {
if(inv != null) {
for(int j1 = 0; j1 < inv.getSizeInventory(); ++j1) {
ItemStack itemstack = inv.getItemHandler().getStackInSlot(j1);
if(itemstack != null) {
net.minecraft.inventory.InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), itemstack);
}
}
world.updateComparatorOutputLevel(pos, state.getBlock());
}
}
public static void withdrawFromInventory(TileSimpleInventory inv, EntityPlayer player) {
for(int i = inv.getSizeInventory() - 1; i >= 0; i--) {
ItemStack stackAt = inv.getItemHandler().getStackInSlot(i);
if(stackAt != null) {
ItemStack copy = stackAt.copy();
ItemHandlerHelper.giveItemToPlayer(player, copy);
inv.getItemHandler().setStackInSlot(i, null);
player.worldObj.updateComparatorOutputLevel(inv.getPos(), null);
break;
}
}
}
}