-
-
Save anonymous/d19441dc5b4ad7a7e4fea8d0e6a2ee83 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.koopamillion.blocks; | |
import java.util.List; | |
import java.util.Random; | |
import com.koopamillion.Main.MainRegistry; | |
import com.koopamillion.api.IWrenchable; | |
import com.koopamillion.creativetabs.MCreativeTabs; | |
import com.koopamillion.lib.Names; | |
import com.koopamillion.lib.RefStrings; | |
import com.koopamillion.tile_entity.TileEntityCreativeEnergyStorage; | |
import com.koopamillion.tile_entity.TileEntityEnergyStorageTier1; | |
import com.koopamillion.util.LogHelper; | |
import net.minecraft.block.Block; | |
import net.minecraft.block.BlockPistonBase; | |
import net.minecraft.block.material.Material; | |
import net.minecraft.client.renderer.texture.IIconRegister; | |
import net.minecraft.entity.EntityLivingBase; | |
import net.minecraft.entity.item.EntityItem; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.inventory.IInventory; | |
import net.minecraft.item.Item; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.nbt.NBTTagCompound; | |
import net.minecraft.tileentity.TileEntity; | |
import net.minecraft.util.IIcon; | |
import net.minecraft.util.MovingObjectPosition; | |
import net.minecraft.world.IBlockAccess; | |
import net.minecraft.world.World; | |
import net.minecraftforge.common.util.ForgeDirection; | |
import net.minecraftforge.common.util.RotationHelper; | |
public class BlockEnergyStorage extends Block implements IWrenchable{ | |
public IIcon output; | |
public IIcon input; | |
public BlockEnergyStorage(){ | |
super(Material.iron); | |
this.setCreativeTab(MCreativeTabs.tabBlocks); | |
this.setBlockName(Names.ENERGYSTORAGE); | |
this.setHardness(3.5F); | |
this.setResistance(17.5F); | |
this.setHarvestLevel("pickaxe", 1); | |
} | |
public TileEntity createTileEntity(World world, int meta){ | |
switch(meta){ | |
case 0: | |
return new TileEntityEnergyStorageTier1(); | |
case 1: | |
return new TileEntityCreativeEnergyStorage(); | |
} | |
return null; | |
} | |
public boolean hasTileEntity(int meta){ | |
return meta <= 1; | |
} | |
public void getSubBlocks(Item item, MCreativeTabs creativeTab, List list) | |
{ | |
list.add(new ItemStack(item, 1, 0)); //meta | |
list.add(new ItemStack(item, 1, 1)); | |
} | |
public int damageDropped(int meta){ | |
return meta; | |
} | |
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z){ | |
int meta = world.getBlockMetadata(x, y, z); | |
return new ItemStack(this, 1, meta); | |
} | |
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side){ | |
int meta = world.getBlockMetadata(x, y, z); | |
switch(meta){ | |
case 0: //CASE 1 =T1 DIFFERENT FOR EACH | |
TileEntityEnergyStorageTier1 tileentity1 = (TileEntityEnergyStorageTier1) world.getTileEntity(x, y, z); | |
if(side == tileentity1.outputSide.ordinal()) return output; | |
case 1: | |
TileEntityEnergyStorageTier1 tileentity11 = (TileEntityEnergyStorageTier1) world.getTileEntity(x, y, z); | |
if(side == tileentity11.outputSide.ordinal()) return output; | |
} | |
return input; | |
} | |
public void registerBlockIcons(IIconRegister iconRegister){ | |
output = iconRegister.registerIcon(RefStrings.MODID + ":energyStorageOutput"); | |
input = iconRegister.registerIcon(RefStrings.MODID + ":energyStorageInput"); | |
} | |
public IIcon getIcon(int side, int meta){ | |
if(side == 3) return output; | |
return input; | |
} | |
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ){ | |
if(!world.isRemote){ | |
int meta = world.getBlockMetadata(x, y, z); | |
if(meta == 0){ | |
player.openGui(MainRegistry.modInstance, 3, world, x, y, z); | |
return true; | |
} | |
} | |
return true; | |
} | |
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack itemstack, EntityPlayer player) | |
{ | |
LogHelper.info("An Energy Storage has been placed by Player: " + player.getDisplayName() + " at X(" + Math.round(x) + ") Y(" + Math.round(y) + ") X(" + Math.round(z) + ")"); | |
int meta = world.getBlockMetadata(x, y, z); | |
if (meta == 0) //0 = t1 //1 = creative | |
{ | |
TileEntityEnergyStorageTier1 tileentity = (TileEntityEnergyStorageTier1) world.getTileEntity(x, y, z); | |
tileentity.rotation = BlockPistonBase.determineOrientation(world, x, y, z, entity); | |
} | |
} | |
@Override | |
public void wrenchRightClick(World world, int x, int y, int z) { | |
ForgeDirection axis = ForgeDirection.UP; | |
RotationHelper.rotateVanillaBlock(this, world, x, y, z, axis); | |
} | |
@Override | |
public void wrenchShiftRightClick(World world, int x, int y, int z) { | |
if(!world.isRemote && world.getTileEntity(x, y, z) != null){ | |
ItemStack itemstack = new ItemStack(Item.getItemFromBlock(this)); | |
dropInventory(world, x, y, z); | |
world.setBlockToAir(x, y, z); | |
world.removeTileEntity(x, y, z); | |
world.notifyBlockChange(x, y, z, this); | |
dropBlockAsItem(world, x, y, z, itemstack); | |
} | |
} | |
protected void dropInventory(World world, int x, int y, int z) | |
{ | |
TileEntity tileEntity = world.getTileEntity(x, y, z); | |
if (!(tileEntity instanceof IInventory)) | |
{ | |
return; | |
} | |
IInventory inventory = (IInventory) tileEntity; | |
for (int i = 0; i < inventory.getSizeInventory(); i++) | |
{ | |
ItemStack itemStack = inventory.getStackInSlot(i); | |
if (itemStack != null && itemStack.stackSize > 0) | |
{ | |
Random rand = new Random(); | |
float dX = rand.nextFloat() * 0.8F + 0.1F; | |
float dY = rand.nextFloat() * 0.8F + 0.1F; | |
float dZ = rand.nextFloat() * 0.8F + 0.1F; | |
EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, itemStack.copy()); | |
if (itemStack.hasTagCompound()) | |
{ | |
entityItem.getEntityItem().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy()); | |
} | |
float factor = 0.05F; | |
entityItem.motionX = rand.nextGaussian() * factor; | |
entityItem.motionY = rand.nextGaussian() * factor + 0.2F; | |
entityItem.motionZ = rand.nextGaussian() * factor; | |
world.spawnEntityInWorld(entityItem); | |
itemStack.stackSize = 0; | |
} | |
} | |
} | |
@Override | |
public void wrenchCutterRightClick(World world, int x, int y, int z) { | |
// TODO Auto-generated method stub | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment