package email
import com.google.common.collect.Lists;
import email.CPLog;
import email.ChargePadType;
import email.ChargePadType.IconSuffix;
import email.ChargePads;
import email.effects.DamageSourcePad;
import email.item.ItemChargePad;
import email.tileentity.TileEntityChargePad;
import email.util.Util;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.Explosion;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import java.util.*;
public class BlockChargePad extends BlockContainer {
public BlockChargePad() {
super(Material.iron);
this.setBlockTextureName("chargepadsreborn" + ":" + "chargePad");
this.setStepSound(Block.soundTypeMetal);
this.setHardness(1.5F);
setBlockName("chargepadsreborn" + ":" + "chargePad");
this.setTickRandomly(true);
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.25F, 1.0F);
this.setCreativeTab(CreativeTabs.tabCombat);
GameRegistry.registerBlock(this, ItemChargePad.class, "chargePad");
}
@Override
public TileEntity createNewTileEntity(World world, int meta) {
return ChargePadType.makeEntity(meta);
}
public void onBlockClicked(World world, int x, int y, int z, EntityPlayer player) {
}
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float xOffset, float yOffset, float zOffset) {
if(player.isSneaking()) {
return false;
} else if(world.isRemote) {
return true;
} else {
TileEntity te = world.getTileEntity(x, y, z);
if(te != null && te instanceof TileEntityChargePad) {
TileEntityChargePad tecp = (TileEntityChargePad)te;
if((tecp.upgrade_drain || tecp.upgrade_damage) && ForgeDirection.getOrientation(side) != ForgeDirection.DOWN) {
return true;
}
ChargePads.proxy.openGui(player, tecp);
}
return true;
}
}
public boolean isBlockSolidOnSide(World world, int x, int y, int z, ForgeDirection side) {
return side.equals(ForgeDirection.DOWN);
}
public int isProvidingStrongPower(IBlockAccess access, int x, int y, int z, int side) {
return side == ForgeDirection.DOWN.ordinal()?0:(this.isPadActive(access, x, y, z)?15:0);
}
public int isProvidingWeakPower(IBlockAccess access, int x, int y, int z, int side) {
return this.isProvidingStrongPower(access, x, y, z, side);
}
public boolean canProvidePower() {
return true;
}
public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side) {
return side != -1;
}
public void onFallenUpon(World world, int x, int y, int z, Entity entity, float impact) {
if(!world.isRemote && ChargePads.FALLING_ZAP) {
int md = ChargePadType.validateMeta(world.getBlockMetadata(x, y, z));
if(ChargePadType.isImpactDamaging(md, impact)) {
if(entity instanceof EntityLivingBase) {
EntityLivingBase el = (EntityLivingBase)entity;
el.attackEntityFrom(DamageSourcePad.electrocute, (float)(3 + 3 * md));
}
}
}
}
public boolean canHarvestBlock(EntityPlayer player, int meta) {
return false;
}
public boolean removeBlockByPlayer(World world, EntityPlayer player, int x, int y, int z) {
if(!world.isRemote && !player.capabilities.isCreativeMode) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileEntityChargePad) {
TileEntityChargePad tecp = (TileEntityChargePad)te;
boolean nuke = tecp.isExplosionNuclear();
if(ChargePads.DISCHARGE_ZAP) {
if(nuke) {
tecp.explodeMachineAt(world, x, y, z);
} else {
int meta = ChargePadType.validateMeta(world.getBlockMetadata(x, y, z), true);
this.electricalBlast(world, x, y, z, meta);
player.attackEntityFrom(DamageSourcePad.electrocute, (float)((meta & 7) * 2));
}
}
if(!nuke) {
tecp.damageInventoryContent();
}
}
}
return removeBlockByPlayer(world, player, x, y, z);
}
public void breakBlock(World world, int x, int y, int z, Block blockId, int metadata) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileEntityChargePad) {
TileEntityChargePad tecp = (TileEntityChargePad)te;
ArrayList drops = Lists.newArrayList();
if(tecp.getInventoryContent(drops) > 0) {
Iterator i$ = drops.iterator();
while(i$.hasNext()) {
ItemStack stack = (ItemStack)i$.next();
if(stack != null) {
double f = 0.7D;
double dx = (double)world.rand.nextFloat() * f + (1.0D - f) * 0.5D;
double dy = (double)world.rand.nextFloat() * f + (1.0D - f) * 0.5D;
double dz = (double)world.rand.nextFloat() * f + (1.0D - f) * 0.5D;
EntityItem entityItem = new EntityItem(world, (double)x + dx, (double)y + dy, (double)z + dz, stack);
entityItem.delayBeforeCanPickup = 10;
world.spawnEntityInWorld(entityItem);
}
}
}
}
super.breakBlock(world, x, y, z, Block.getBlockById(9), metadata);
}
public void onBlockDestroyedByExplosion(World world, int x, int y, int z, Explosion exp) {
world.removeTileEntity(x, y, z);
}
public void electricalBlast(World world, int x, int y, int z, int metadata) {
if(!world.isRemote) {
TileEntityChargePad tecp = (TileEntityChargePad)world.getTileEntity(x, y, z);
if(tecp == null) {
CPLog.warning("TileEntity.%s missing @%d,%d,%d ?!", new Object[]{ChargePadType.values()[metadata & 7].name(), Integer.valueOf(x), Integer.valueOf(y), Integer.valueOf(z)});
}
int charge = tecp != null?tecp.getStorageLevel():0;
int halfhearts = ChargePadType.getDetonationDamage(metadata, charge);
int maxdist = ChargePadType.getMaxDetonationRange(metadata);
maxdist = Math.max(halfhearts, maxdist);
AxisAlignedBB bb = this.getCollisionBoundingBoxFromPool(world, x, y, z).expand((double) maxdist, (double) maxdist, (double) maxdist);
List ents = world.getEntitiesWithinAABB(EntityLivingBase.class, bb);
Iterator i$ = ents.iterator();
while(i$.hasNext()) {
Object o = i$.next();
EntityLivingBase el = (EntityLivingBase)o;
int dist = MathHelper.floor_double(el.getDistance((double) x, (double) y, (double) z));
el.attackEntityFrom(DamageSourcePad.electrocute, (float) (halfhearts - dist));
}
}
}
public boolean isPadActive(IBlockAccess iBA, int x, int y, int z) {
return ChargePadType.isActive(iBA.getBlockMetadata(x, y, z));
}
public int tickRate(World world) {
return 10;
}
public void updateTick(World world, int x, int y, int z, Random rand) {
if(!world.isRemote) {
if(this.isPadActive(world, x, y, z)) {
this.setStateOnInteraction(world, x, y, z);
}
}
}
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
if(!world.isRemote) {
if(!this.isPadActive(world, x, y, z)) {
this.setStateOnInteraction(world, x, y, z);
}
}
}
private void setStateOnInteraction(World world, int x, int y, int z) {
int meta = ChargePadType.validateMeta(world.getBlockMetadata(x, y, z), true);
boolean active = (meta & != 0;
double margin = 0.125D;
AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox((double) x + margin, (double) y, (double) z + margin, (double) (x + 1) - margin, (double) y + 0.5D, (double) (z + 1) - margin);
List entities = world.getEntitiesWithinAABB(EntityPlayer.class, aabb);
boolean force_disable = false;
TileEntityChargePad tecp = null;
if(active) {
TileEntity hasEntity = world.getTileEntity(x, y, z);
if(hasEntity != null && hasEntity instanceof TileEntityChargePad) {
tecp = (TileEntityChargePad)hasEntity;
if(entities.isEmpty()) {
force_disable = tecp.getForceDisable();
}
if(tecp.upgrade_fieldexp > 0) {
aabb = aabb.expand((double) tecp.upgrade_fieldexp, 0.0D, (double) tecp.upgrade_fieldexp);
entities = world.getEntitiesWithinAABB(EntityPlayer.class, aabb);
}
}
}
boolean hasEntity1 = !entities.isEmpty();
boolean changed = false;
if(hasEntity1 && !active) {
changed = true;
world.setBlockMetadataWithNotify(x, y, z, meta | 8, 2);
world.playSoundEffect((double) x + 0.5D, (double) y + 0.25D, (double) z + 0.5D, "random.click", 0.3F, 0.6F);
}
if(active && (!hasEntity1 || force_disable)) {
changed = true;
if(tecp != null) {
tecp.setForceDisable(false);
}
world.setBlockMetadataWithNotify(x, y, z, meta & 7, 2);
world.playSoundEffect((double) x + 0.5D, (double) y + 0.25D, (double) z + 0.5D, "random.click", 0.3F, 0.5F);
}
if(changed) {
world.notifyBlockOfNeighborChange(x, y - 1, z, getBlockFromName("chargepadsreborn" + ":" + "chargePad"));
world.notifyBlockOfNeighborChange(x - 1, y, z, getBlockFromName("chargepadsreborn" + ":" + "chargePad"));
world.notifyBlockOfNeighborChange(x + 1, y, z, getBlockFromName("chargepadsreborn" + ":" + "chargePad"));
world.notifyBlockOfNeighborChange(x, y, z - 1, getBlockFromName("chargepadsreborn" + ":" + "chargePad"));
world.notifyBlockOfNeighborChange(x, y, z + 1, getBlockFromName("chargepadsreborn" + ":" + "chargePad"));
world.markBlockRangeForRenderUpdate(x, y, z, x, y, z);
}
if(hasEntity1) {
world.scheduleBlockUpdate(x, y, z, getBlockFromName("chargepadsreborn" + ":" + "chargePad"), this.tickRate(world));
}
}
public boolean renderAsNormalBlock() {
return false;
}
public boolean isOpaqueCube() {
return false;
}
@SideOnly(Side.CLIENT)
public void randomDisplayTick(World world, int blockX, int blockY, int blockZ, Random rand) {
if(this.isPadActive(world, blockX, blockY, blockZ)) {
TileEntity te = world.getTileEntity(blockX, blockY, blockZ);
if(te != null && te instanceof TileEntityChargePad) {
((TileEntityChargePad)te).spawnParticles(world, blockX, blockY, blockZ, rand);
}
}
}
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int metadata) {
int meta = ChargePadType.validateMeta(metadata, true);
boolean active = (meta & != 0;
if(meta != metadata) {
CPLog.warning("Invalid meta check: %d/%sactive (ignoring)", new Object[]{Integer.valueOf(metadata), active?"":"in"});
}
ChargePadType type = ChargePadType.getType(meta);
return side == ForgeDirection.DOWN.ordinal()?type.getIcon(IconSuffix.Base):(side == ForgeDirection.UP.ordinal()?type.getIcon(active?IconSuffix.Top1:IconSuffix.Top0):type.getIcon(IconSuffix.Side));
}
public int getMobilityFlag() {
return 1;
}
// public int func_71885_a(int metadata, Random random, int par3) {
//return this.getItem();
public int damageDropped(int metadata) {
return metadata & 7;
}
public int quantityDropped(Random random) {
return 1;
}
public ArrayList<ItemStack> getBlockDropped(World world, int x, int y, int z, int metadata, int fortune) {
ArrayList dropped = super.getDrops(world, x, y, z, metadata, fortune);
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileEntityChargePad) {
TileEntityChargePad tecp = (TileEntityChargePad)te;
tecp.getInventoryContent(dropped);
}
return dropped;
}
@SideOnly(Side.CLIENT)
public void getSubBlocks(int blockId, CreativeTabs tabs, List istacks) {
ChargePadType[] arr$ = ChargePadType.values();
int len$ = arr$.length;
for(int i$ = 0; i$ < len$; ++i$) {
ChargePadType type = arr$[i$];
istacks.add(new ItemStack(this, 1, type.ordinal()));
}
}
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister ireg) {
ChargePadType[] arr$ = ChargePadType.values();
int len$ = arr$.length;
for (int i$ = 0; i$ < len$; ++i$) {
ChargePadType type = arr$[i$];
String prefix = type.name().toLowerCase(Locale.ENGLISH);
IconSuffix[] arr$1 = IconSuffix.values();
int len$1 = arr$1.length;
for (int i$1 = 0; i$1 < len$1; ++i$1) {
IconSuffix suffix = arr$1[i$1];
type.setIcon(suffix, ireg.registerIcon(Util.getTextureNameQ(prefix + suffix.name())));
}
}
}
}
This is an old plugin for ic2 that i did not originally make but Im just messing around with it.
my block isn't showing up and I'm not seeing anything wrong in any of my classes This is my Blocks class is there something wrong here I don't see? (I'm new to posting on forums please tell me anything I did wrong)