Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package waDelma.tinyblocks.block;
- import java.util.ArrayList;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Random;
- import java.util.Set;
- import net.minecraft.client.Minecraft;
- import net.minecraft.client.particle.EffectRenderer;
- import net.minecraft.client.particle.EntityDiggingFX;
- import net.minecraft.creativetab.CreativeTabs;
- import net.minecraft.block.Block;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.item.EntityItem;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.stats.StatList;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.AxisAlignedBB;
- import net.minecraft.util.EnumMovingObjectType;
- import net.minecraft.util.MathHelper;
- import net.minecraft.util.MovingObjectPosition;
- import net.minecraft.util.Vec3;
- import net.minecraft.world.ChunkPosition;
- import net.minecraft.world.IBlockAccess;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemDye;
- import net.minecraft.item.ItemStack;
- import net.minecraft.world.World;
- import net.minecraftforge.common.ForgeDirection;
- import waDelma.tinyblocks.Bound;
- import waDelma.tinyblocks.TrayTracer;
- import waDelma.tinyblocks.mod_tinyblock;
- import waDelma.tinyblocks.handlers.WaterHandler;
- import waDelma.tinyblocks.helpers.HelperItem;
- import waDelma.tinyblocks.helpers.HelperWorld;
- public class BlockTinyblock extends Block {
- private WaterHandler waterhandler;
- private Bound bound;
- private Set<ChunkPosition> blocksNeedingUpdate;
- private boolean wiresProvidePower;
- public BlockTinyblock(int i) {
- super(i, new MaterialTinyBlocks());
- setTickRandomly(true);
- setCreativeTab(CreativeTabs.tabBlock);
- setTextureFile(mod_tinyblock.instance().defaultTexturesPath);
- waterhandler = new WaterHandler();
- blocksNeedingUpdate = new HashSet<ChunkPosition>();
- isBlockContainer = true;
- // setLightOpacity(255);
- }
- @Override
- public ItemStack getPickBlock(MovingObjectPosition target, World world,
- int x, int y, int z) {
- TileEntityTinyblock tile = HelperWorld.getTile(world, target.blockX,
- target.blockY, target.blockZ);
- if (tile != null) {
- int ID = HelperItem.swapID(tile.getIDs()[target.subHit]);
- int MD = tile.getMDs()[target.subHit];
- return new ItemStack(blockID, 1, HelperItem.merge(ID, MD));
- }
- return null;
- }
- @Override
- public void harvestBlock(World world, EntityPlayer player, int x, int y,
- int z, int MD) {
- player.addStat(StatList.mineBlockStatArray[this.blockID], 1);
- player.addExhaustion(0.025F);
- }
- @Override
- public boolean removeBlockByPlayer(World world, EntityPlayer player, int x,
- int y, int z) {
- MovingObjectPosition mop = getMovingObjectPositionFromPlayer(world,
- player, false);
- if (mop != null && mop.typeOfHit == EnumMovingObjectType.TILE) {
- TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
- MovingObjectPosition tray = TrayTracer.traceTinyblock(world,
- mop.blockX, mop.blockY, mop.blockZ, player, 1.0F);
- if (tray != null) {
- if (!player.capabilities.isCreativeMode) {
- int damage = HelperItem.merge(tile.getIDs()[tray.subHit],
- tile.getMDs()[tray.subHit]);
- ItemStack stack = new ItemStack(
- mod_tinyblock.instance().tinyblock, 1, damage);
- dropBlockAsItem_do(world, x, y, z, stack);
- }
- if (world.isRemote) {
- destructionEffect(world, x, y, z, tray.subHit);
- }
- tile.removeBlock(tray.subHit);
- // removeRedstone(world, player, x, y, z, tile, tray, ii, jj,
- // kk);
- if (tile.isEmpty()) {
- world.removeBlockTileEntity(x, y, z);
- return world.setBlockWithNotify(x, y, z, 0);
- }
- HelperWorld.notifyBlockChange(world, x, y, z, blockID);
- tile.dirtyfy();
- return false;
- }
- }
- return false;
- }
- @Override
- public void onBlockDestroyedByPlayer(World world, int x, int y, int z,
- int MD) {
- }
- @Override
- public void breakBlock(World world, int x, int y, int z, int par5, int par6) {
- }
- @Override
- public ArrayList<ItemStack> getBlockDropped(World world, int x, int y,
- int z, int metadata, int fortune) {
- ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
- TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
- if (tile != null) {
- for (int n = 0; n < tile.getIDs().length; n++) {
- int damage = HelperItem.merge(tile.getIDs()[n],
- tile.getMDs()[n]);
- ret.add(new ItemStack(blockID, 1, damage));
- }
- }
- return ret;
- }
- @Override
- public boolean addBlockHitEffects(World world, MovingObjectPosition target,
- EffectRenderer effect) {
- int x = target.blockX;
- int y = target.blockY;
- int z = target.blockZ;
- TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
- int sub = target.subHit;
- int ID = tile.getIDs()[sub]; // world.getBlockId(x, y, z);
- if (ID != 0) {
- Block block = Block.blocksList[ID];
- double border = 0.1;
- Random rand = new Random();
- double xx = x + rand.nextDouble()
- * (0.5 - (border * 2.0F)) + border;
- double yy = y + rand.nextDouble()
- * (0.5 - (border * 2.0F)) + border;
- double zz = z + rand.nextDouble()
- * (0.5 - (border * 2.0F)) + border;
- double amount = (target.sideHit % 2 == 0 ? -border : border + 0.5);
- switch (target.sideHit) {
- case 0:
- case 1:
- yy = y + amount;
- break;
- case 2:
- case 3:
- zz = z + amount;
- break;
- case 4:
- case 5:
- xx = x + amount;
- break;
- }
- if (HelperWorld.isTinyblockInDirection(sub, ForgeDirection.UP)) {
- yy += 0.5;
- }
- if (HelperWorld.isTinyblockInDirection(sub, ForgeDirection.SOUTH)) {
- zz += 0.5;
- }
- if (HelperWorld.isTinyblockInDirection(sub, ForgeDirection.EAST)) {
- xx += 0.5;
- }
- effect.addEffect(
- (new EntityDiggingFX(world, xx, yy, zz, 0.0D, 0.0D, 0.0D,
- block, target.sideHit, world.getBlockMetadata(x, y,
- z))).func_70596_a(x, y, z)
- .multiplyVelocity(0.2F)
- .multipleParticleScaleBy(0.6F), block);
- }
- return true;
- }
- @Override
- public boolean addBlockDestroyEffects(World world, int x, int y, int z,
- int meta, EffectRenderer effectRenderer) {
- return true;
- }
- public void destructionEffect(World world, int x, int y, int z, int n) {
- TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
- int ID = tile.getIDs()[n];
- int MD = tile.getMDs()[n];
- Minecraft minecraft = mod_tinyblock.instance().client;
- Block block = Block.blocksList[ID];
- Random rand = new Random();
- if (block != null) {
- double x1 = x;
- double y1 = y;
- double z1 = z;
- byte size = 4;
- if (HelperWorld.isTinyblockInDirection(n, ForgeDirection.UP)) {
- y1 += 0.5;
- }
- if (HelperWorld.isTinyblockInDirection(n, ForgeDirection.EAST)) {
- x1 += 0.5;
- }
- if (HelperWorld.isTinyblockInDirection(n, ForgeDirection.SOUTH)) {
- z1 += 0.5;
- }
- for (int i = 0; i < size; ++i) {
- for (int j = 0; j < size; ++j) {
- for (int k = 0; k < size; ++k) {
- double xx = x1 + (i / 2D + 0.5D) / size;
- double yy = y1 + (j / 2D + 0.5D) / size;
- double zz = z1 + (k / 2D + 0.5D) / size;
- int direction = rand.nextInt(6);
- minecraft.effectRenderer.addEffect(
- (new EntityDiggingFX(world, xx, yy, zz, xx - x1
- - 0.5D, yy - y1 - 0.5D, zz - z1 - 0.5D,
- block, direction, MD)).func_70596_a(x,
- y, z).multipleParticleScaleBy(0.8F),
- block);
- }
- }
- }
- }
- }
- // public boolean isProvidingWeakPower(IBlockAccess par1IBlockAccess, int
- // par2, int par3, int par4, int par5)
- // {
- // return false;
- // }
- // public boolean isProvidingStrongPower(IBlockAccess par1IBlockAccess, int
- // par2, int par3, int par4, int par5)
- // {
- // return false;
- // }
- // public void onBlockEventReceived(World par1World, int par2, int par3, int
- // par4, int par5, int par6) {}
- @Override
- public void getSubBlocks(int ID, CreativeTabs tabs, List list) {
- for (Block block : Block.blocksList) {
- if (block != null && block.blockID != 0
- && block.getClass() != this.getClass()
- && !block.blockMaterial.isLiquid()) {
- List<ItemStack> subBlocks = new ArrayList<ItemStack>();
- block.getSubBlocks(block.blockID, tabs, subBlocks);
- for (ItemStack stack : subBlocks) {
- list.add(new ItemStack(ID, 1, HelperItem.merge(
- stack.itemID, stack.getItemDamage())));
- }
- }
- }
- list.add(new ItemStack(ID, 1, HelperItem.merge(
- Block.redstoneWire.blockID, 0)));
- }
- @Override
- public String getBlockName() {
- return mod_tinyblock.instance().TinyblockTag;
- }
- @Override
- public boolean onBlockActivated(World world, int x, int y, int z,
- EntityPlayer player, int n, float xx, float yy, float zz) {
- // if (world.isRemote)
- // return false;
- TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
- boolean sneaking = player.isSneaking();
- MovingObjectPosition tray = TrayTracer.traceTinyblock(world, x, y, z,
- player, 1.0F);
- if (tray == null) {
- return false;
- }
- // MovingObjectPosition mop = player.rayTrace(par1, par3);
- ItemStack stack = player.getCurrentEquippedItem();
- if (stack != null) {
- int id = stack.itemID;
- if (id == Item.dyePowder.itemID) {
- tile.getCOLOR()[tray.subHit] = ItemDye.dyeColors[stack
- .getItemDamage()];
- HelperWorld.notifyBlockChange(world, x, y, z, blockID);
- return true;
- } else {
- mod_tinyblock.instance();
- if (id == mod_tinyblock.opticTransformer.itemID) {
- if (sneaking) {
- } else if (tile.getTINY()[tray.subHit]) {
- tile.getTINY()[tray.subHit] = false;
- } else {
- tile.getTINY()[tray.subHit] = true;
- }
- if (!player.capabilities.isCreativeMode) {
- stack.damageItem(1, player);
- }
- HelperWorld.notifyBlockChange(world, x, y, z, blockID);
- return true;
- } else if (id == Item.redstone.itemID) {// TODO: Redstone
- // behaviour
- // setRedstone(tray, tile);
- // mod_tinyblock.instance().notifyBlockChange(world, i, j,
- // k,
- // Block.redstoneWire.blockID);
- // tile.setBlock(tray.subHit, Block.redstoneWire.blockID,
- // 0);
- // System.out.println("Redstone wire");
- }
- }
- }
- return false;
- }
- public boolean setAll(TileEntityTinyblock tile, int n, int ID, int MD,
- boolean tiny) {
- if (tile.getIDs()[n] == 0) {
- tile.setAll(n, ID, MD, mod_tinyblock.instance().defaultColor, tiny);
- return true;
- }
- return false;
- }
- @Override
- public float getPlayerRelativeBlockHardness(EntityPlayer player,
- World world, int x, int y, int z) {
- // System.out.println("blockStrength");
- MovingObjectPosition mop = HelperWorld
- .getMOP(mod_tinyblock.instance().client);
- if (mop == null) {
- return 1.0f;
- }
- if (mop.typeOfHit == EnumMovingObjectType.TILE) {
- TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
- MovingObjectPosition tray = TrayTracer.traceTinyblock(world,
- mop.blockX, mop.blockY, mop.blockZ, player, 1.0F);
- if (tray != null) {
- Block block = Block.blocksList[tile.getIDs()[tray.subHit]];
- if (block != null) {
- stepSound = block.stepSound;
- return player.getCurrentPlayerStrVsBlock(block, 0)
- / block.getBlockHardness(world, x, y, z) / 30F * 4F;
- }
- }
- }
- return 1.0F;
- }
- @Override
- public boolean canCollideCheck(int i, boolean flag) {
- return true;
- }
- @Override
- public MovingObjectPosition collisionRayTrace(World world, int x, int y,
- int z, Vec3 vec3d, Vec3 vec3d1) {
- if (world.getBlockMetadata(x, y, z) == 1)
- return super.collisionRayTrace(world, x, y, z, vec3d, vec3d1);
- EntityPlayer entityplayer = mod_tinyblock.instance().client.thePlayer;
- TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
- MovingObjectPosition temp;
- double shortestDistance = Float.MAX_VALUE;
- MovingObjectPosition result = null;
- for (int n = 0; n < tile.getIDs().length; n++)
- if (tile.getIDs()[n] != 0) {
- Block block = Block.blocksList[tile.getIDs()[n]];
- if (block != null && !block.blockMaterial.isLiquid()) {
- bound = TrayTracer.setBounds(tile, n);
- temp = TrayTracer.rayTrace(world, x, y, z, vec3d, vec3d1,
- bound);
- if (temp != null) {
- temp.subHit = n;
- if (temp.hitVec.distanceTo(entityplayer
- .getPosition(1.0F)) < shortestDistance) {
- result = temp;
- shortestDistance = temp.hitVec
- .distanceTo(entityplayer.getPosition(1.0F));
- }
- }
- }
- }
- return result;
- }
- @Override
- public TileEntity createTileEntity(World world, int metadata) {
- return new TileEntityTinyblock();
- }
- @Override
- public void addCollidingBlockToList(World world, int x, int y, int z,
- AxisAlignedBB axis, List list, Entity entity) {
- if (world.getBlockMetadata(x, y, z) != 1) {
- TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
- if (tile.getIDs() == null)
- return;
- for (int n = 0; n < tile.getIDs().length; n++)
- if (tile.getIDs()[n] != 0
- && !Block.blocksList[tile.getIDs()[n]].blockMaterial
- .isLiquid()
- && tile.getIDs()[n] != Block.redstoneWire.blockID) {
- bound = TrayTracer.setBounds(tile, n);
- AxisAlignedBB ax = AxisAlignedBB.getAABBPool()
- .addOrModifyAABBInPool(x + bound.minX,
- y + bound.minY, z + bound.minZ,
- x + bound.maxX, y + bound.maxY,
- z + bound.maxZ);
- if (ax != null && axis.intersectsWith(ax)) {
- list.add(ax);
- }
- }
- return;
- }
- super.addCollidingBlockToList(world, x, y, z, axis, list, entity);
- }
- @Override
- public int getLightValue(IBlockAccess access, int x, int y, int z) {
- TileEntityTinyblock tile = HelperWorld.getTile(access, x, y, z);
- if (tile == null || access.getBlockMetadata(x, y, z) == 1)
- return 0;
- float light = 0;
- int finallight = 0;
- int numberblocks = 1;
- for (int ID : tile.getIDs())
- if (ID != 0) {
- light += Block.lightValue[ID];
- numberblocks++;
- }
- finallight = (int) (light / numberblocks) * 2;
- return finallight;
- }
- @Override
- public int getBlockTexture(IBlockAccess blockAccess, int x, int y, int z,
- int side) {
- net.minecraft.client.Minecraft minecraft = mod_tinyblock.instance().client;
- MovingObjectPosition mop = HelperWorld.getMOP(minecraft);
- EntityPlayer player = minecraft.thePlayer;
- World world = player.worldObj;
- MovingObjectPosition tray = TrayTracer.traceTinyblock(world, x, y, z,
- player, 1.0F);
- TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
- if (tile != null)
- if (tray != null) {
- Block block = Block.blocksList[tile.getIDs()[tray.subHit]];
- if (block != null)
- return block.getBlockTextureFromSideAndMetadata(side,
- tile.getMDs()[tray.subHit]);
- }
- return super.getBlockTexture(blockAccess, x, y, z, side);
- }
- @Override
- public int colorMultiplier(IBlockAccess access, int x, int y, int z) {
- EntityPlayer player = mod_tinyblock.instance().client.thePlayer;
- MovingObjectPosition tray = TrayTracer.traceTinyblock(access, x, y, z,
- player, 1.0F);
- TileEntityTinyblock tile = HelperWorld.getTile(access, x, y, z);
- if (tray != null) {
- int color = tile.getCOLOR()[tray.subHit];
- boolean liquid = false;
- if (blockMaterial != null)
- liquid = blockMaterial.isLiquid();
- if (color == mod_tinyblock.instance().defaultColor) {
- color = Block.blocksList[tile.getIDs()[tray.subHit]]
- .colorMultiplier(access, x, y, z);
- } else if (liquid)
- color = mod_tinyblock.instance().defaultColor;
- return color;
- }
- return super.colorMultiplier(access, x, y, z);
- }
- @Override
- public int getRenderType() {
- return mod_tinyblock.instance().tinyBlockRenderID;
- }
- // @Override
- // public boolean isBlockReplaceable(World world, int x, int y, int z) {
- // // System.out.println("replace");
- // return true;//world.getBlockId(x, y, z) == blockID;
- // }
- @Override
- public boolean canPlaceBlockAt(World world, int x, int y, int z) {
- int ID = world.getBlockId(x, y, z);
- return ID == 0 || blocksList[ID].blockMaterial.isReplaceable()
- || ID == blockID;
- }
- @Override
- public boolean isBlockSolidOnSide(World world, int x, int y, int z,
- ForgeDirection side) {
- TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
- switch (side) {
- case DOWN:
- return sideIsFull(tile, 0, 1, 2, 3);
- case UP:
- return sideIsFull(tile, 4, 5, 6, 7);
- case NORTH:
- return sideIsFull(tile, 0, 1, 4, 5);
- case SOUTH:
- return sideIsFull(tile, 2, 3, 6, 7);
- case WEST:
- return sideIsFull(tile, 0, 2, 4, 6);
- case EAST:
- return sideIsFull(tile, 1, 3, 5, 7);
- }
- return false;
- }
- private boolean sideIsFull(TileEntityTinyblock tile, int a, int b, int c,
- int d) {
- return tile.isFullBlock(a) && tile.isFullBlock(b)
- && tile.isFullBlock(c) && tile.isFullBlock(d);
- }
- @Override
- public boolean isOpaqueCube() {
- return false;
- }
- @Override
- public void onBlockAdded(World world, int x, int y, int z) {
- super.onBlockAdded(world, x, y, z);
- if (world.getBlockId(x, y, z) == blockID)
- world.scheduleBlockUpdate(x, y, z, blockID, tickRate());
- // System.out.println("added at: i: " + i + " j: " + j + " k: " + k);
- }
- @Override
- public int getLightOpacity(World world, int x, int y, int z) {
- TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
- return lightOpacity[blockID];
- }
- @Override
- public void onEntityWalking(World world, int x, int y, int z, Entity entity) {
- boolean diffX = entity.posX - x < 0.5F;
- boolean diffY = entity.posY - y - entity.height < 0.5F;
- boolean diffZ = entity.posZ - z < 0.5F;
- // System.out.println(diffX + " " + diffY + " " + diffZ);
- TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
- Block block;
- int ID;
- if (diffX) {
- if (diffY) {
- if (diffZ) {
- ID = tile.getIDs()[0];
- } else {
- ID = tile.getIDs()[2];
- }
- } else {
- if (diffZ) {
- ID = tile.getIDs()[4];
- } else {
- ID = tile.getIDs()[6];
- }
- }
- } else {
- if (diffY) {
- if (diffZ) {
- ID = tile.getIDs()[1];
- } else {
- ID = tile.getIDs()[3];
- }
- } else {
- if (diffZ) {
- ID = tile.getIDs()[5];
- } else {
- ID = tile.getIDs()[7];
- }
- }
- }
- block = Block.blocksList[ID];
- if (block != null)
- stepSound = block.stepSound;
- }
- public MovingObjectPosition getMovingObjectPositionFromPlayer(World world,
- EntityPlayer player, boolean flag) {
- float var4 = 1.0F;
- float pitch = player.prevRotationPitch
- + (player.rotationPitch - player.prevRotationPitch) * var4;
- float yaw = player.prevRotationYaw
- + (player.rotationYaw - player.prevRotationYaw) * var4;
- double posX = player.prevPosX + (player.posX - player.prevPosX) * var4;
- double posY = player.prevPosY + (player.posY - player.prevPosY) * var4
- + 1.62D - player.yOffset;
- double posZ = player.prevPosZ + (player.posZ - player.prevPosZ) * var4;
- Vec3 posVec = world.getWorldVec3Pool().getVecFromPool(posX, posY, posZ);
- float var14 = MathHelper.cos(-yaw * 0.017453292F - (float) Math.PI);
- float var15 = MathHelper.sin(-yaw * 0.017453292F - (float) Math.PI);
- float var16 = -MathHelper.cos(-pitch * 0.017453292F);
- float var17 = MathHelper.sin(-pitch * 0.017453292F);
- float var18 = var15 * var16;
- float var20 = var14 * var16;
- double var21 = 5.0D;
- // if (player instanceof EntityPlayerMP) {
- // var21 = ((EntityPlayerMP) player).theItemInWorldManager
- // .getBlockReachDistance();
- // }
- Vec3 var23 = posVec.addVector(var18 * var21, var17 * var21, var20
- * var21);
- return world.rayTraceBlocks_do_do(posVec, var23, flag, !flag);
- }
- public void removeRedstone(World world, EntityPlayer player, int x, int y,
- int z, TileEntityTinyblock tile, MovingObjectPosition tray,
- double ii, double jj, double kk) {
- ItemStack redStack = new ItemStack(mod_tinyblock.instance().tinyblock,
- 1, HelperItem.merge(Block.redstoneWire.blockID, 0));
- if (tray.subHit < 4) {
- int n = tray.subHit + 4;
- if (tile.getIDs()[n] == Block.redstoneWire.blockID) {
- tile.removeBlock(n);
- if (!player.capabilities.isCreativeMode) {
- EntityItem entityitem = new EntityItem(world, x + ii, y
- + jj, z + kk, redStack);
- entityitem.delayBeforeCanPickup = 10;
- world.spawnEntityInWorld(entityitem);
- }
- }
- } else {
- TileEntityTinyblock tileUp = HelperWorld
- .getTile(world, x, y + 1, z);
- if (tileUp != null) {
- int n = tray.subHit - 4;
- if (tileUp.getIDs()[n] == Block.redstoneWire.blockID) {
- tileUp.removeBlock(n);
- if (!player.capabilities.isCreativeMode) {
- EntityItem entityitem = new EntityItem(world, x + ii, y
- + jj, z + kk, redStack);
- entityitem.delayBeforeCanPickup = 10;
- world.spawnEntityInWorld(entityitem);
- }
- }
- }
- }
- }
- @Override
- public boolean renderAsNormalBlock() {
- return false;
- }
- @Override
- public void setBlockBoundsBasedOnState(IBlockAccess access, int x, int y,
- int z) {
- if (access.getBlockMetadata(x, y, z) == 1)
- setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
- }
- @Override
- public int tickRate() {
- return 5;
- }
- @Override
- public void randomDisplayTick(World world, int x, int y, int z,
- Random random) {
- waterhandler.tick(world, x, y, z, random);
- TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
- for (int n = 0; n < tile.getIDs().length; n++)
- if (tile.getIDs()[n] == Block.redstoneWire.blockID) {
- int meta = tile.getMDs()[n];
- if (meta > 0) {
- double ii = x + 0.5D / 2 + (random.nextFloat() - 0.5D)
- * 0.2D;
- double jj = (y + 0.0625F / 2);
- double kk = z + 0.5D / 2 + (random.nextFloat() - 0.5D)
- * 0.2D;
- switch (n) {
- case 0:
- break;
- case 1:
- ii += 0.5;
- break;
- case 2:
- kk += 0.5;
- break;
- case 3:
- ii += 0.5;
- kk += 0.5;
- break;
- case 4:
- jj += 0.5;
- break;
- case 5:
- ii += 0.5;
- jj += 0.5;
- break;
- case 6:
- kk += 0.5;
- jj += 0.5;
- break;
- case 7:
- ii += 0.5;
- kk += 0.5;
- jj += 0.5;
- break;
- }
- float partialMeta = meta / 15.0F;
- float multipliedMeta = partialMeta * 0.6F + 0.4F;
- if (meta == 0)
- multipliedMeta = 0.0F;
- float var15 = partialMeta * partialMeta * 0.7F - 0.5F;
- float var16 = partialMeta * partialMeta * 0.6F - 0.7F;
- if (var15 < 0.0F)
- var15 = 0.0F;
- if (var16 < 0.0F)
- var16 = 0.0F;
- world.spawnParticle("reddust", ii, jj, kk, multipliedMeta,
- var15, var16);
- }
- }
- }
- @Override
- public void updateTick(World world, int x, int y, int z, Random random) {
- TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
- if (tile != null) {
- // EntityPlayer player = ModLoader.getMinecraftInstance().thePlayer;
- boolean flag = false;
- for (int n = 0; n < 4; n++) {
- if (tile.getIDs()[n] == Block.redstoneWire.blockID)
- if (world.getBlockId(x, y - 1, z) == 0) {
- tile.removeBlock(n);
- // if(!player.capabilities.isCreativeMode){
- float f = 0.7F;
- double xx = (world.rand.nextFloat() * f) + (1.0F - f)
- * 0.5D;
- double yy = (world.rand.nextFloat() * f) + (1.0F - f)
- * 0.5D;
- double zz = (world.rand.nextFloat() * f) + (1.0F - f)
- * 0.5D;
- ItemStack redStack = new ItemStack(
- mod_tinyblock.instance().tinyblock, 1,
- HelperItem.merge(Block.redstoneWire.blockID, 0));
- EntityItem entityitem = new EntityItem(world, x + xx, y
- + yy, z + zz, redStack);
- entityitem.delayBeforeCanPickup = 10;
- world.spawnEntityInWorld(entityitem);
- flag = true;
- // }
- }
- }
- if (flag)
- world.notifyBlockChange(x, y, z, Block.redstoneWire.blockID);
- }
- // Turns whole block to whole
- /*
- * TileEntityTinyblock tile =
- * (TileEntityTinyblock)world.getBlockTileEntity(x, y, z); int ID =
- * tile.IDs[0]; int MD = tile.MDs[0]; boolean flag = true; for(int n =
- * 1; n < tile.IDs.length; n++){ if(tile.IDs[n] == ID && tile.MDs[n] ==
- * MD){ continue; }else{ flag = false; break; } } if(flag)
- * world.setBlockAndMetadataWithNotify(x, y, z, ID, MD);
- */
- }
- @Override
- public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z,
- int dir) {
- // TODO: Make it connect redstone correctly
- TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
- if (tile != null)
- for (int n = 0; n < tile.getIDs().length; n++)
- if (tile.getIDs()[n] == Block.redstoneWire.blockID) {
- // @off
- switch (dir) {
- case 0:
- switch (n) {
- case 0:
- case 1:
- case 4:
- case 5:
- return true;
- }
- break;
- case 1:
- switch (n) {
- case 1:
- case 3:
- case 5:
- case 7:
- return true;
- }
- break;
- case 2:
- switch (n) {
- case 3:
- case 2:
- case 7:
- case 6:
- return true;
- }
- break;
- case 3:
- switch (n) {
- case 2:
- case 0:
- case 6:
- case 4:
- return true;
- }
- break;
- }
- // @on
- }
- return false;
- }
- @Override
- public void onNeighborBlockChange(World world, int x, int y, int z, int ID) {
- if (!world.isRemote) {
- updateAndPropagateCurrentStrength(world, x, y, z);
- super.onNeighborBlockChange(world, x, y, z, ID);
- }
- }
- private void updateAndPropagateCurrentStrength(World world, int x, int y,
- int z) {
- TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
- for (int n = 0; n < tile.getIDs().length; n++)
- if (tile.getIDs()[n] == Block.redstoneWire.blockID)
- calculateCurrentChanges(world, x, y, z, x, y, z, tile, n);
- List<ChunkPosition> blocksForUpdate = new ArrayList<ChunkPosition>(
- blocksNeedingUpdate);
- blocksNeedingUpdate.clear();
- for (int n = 0; n < blocksForUpdate.size(); ++n) {
- ChunkPosition chunk = blocksForUpdate.get(n);
- world.notifyBlocksOfNeighborChange(chunk.x, chunk.y, chunk.z,
- blockID);
- }
- }
- // TODO: Multiply metadata same way as water and make it work with
- // tinyblocks
- private void calculateCurrentChanges(World world, int x, int y, int z,
- int i2, int j2, int k2, TileEntityTinyblock tile, int n) {
- int metadata = tile.getMDs()[n];
- int strength = 0;
- wiresProvidePower = false;
- boolean indirectPower = world.isBlockIndirectlyGettingPowered(x, y, z);
- wiresProvidePower = true;
- int m;
- int xx;
- int zz;
- if (indirectPower) {
- strength = 15;
- } else {
- for (m = 0; m < 4; ++m) {
- xx = x;
- zz = z;
- // @off
- switch (m) {
- case 0:
- xx--;
- break;
- case 1:
- xx++;
- break;
- case 2:
- zz--;
- break;
- case 3:
- zz++;
- break;
- }
- // @on
- if (xx != i2 || y != j2 || zz != k2)
- strength = getMaxCurrentStrength(world, xx, y, zz, strength);
- if (world.isBlockNormalCube(xx, y, zz)
- && !world.isBlockNormalCube(x, y + 1, z)) {
- if (xx != i2 || y + 1 != j2 || zz != k2)
- strength = getMaxCurrentStrength(world, xx, y + 1, zz,
- strength);
- } else if (!world.isBlockNormalCube(xx, y, zz)
- && (xx != i2 || y - 1 != j2 || zz != k2)) {
- strength = getMaxCurrentStrength(world, xx, y - 1, zz,
- strength);
- }
- }
- if (strength > 0) {
- strength--;
- } else {
- strength = 0;
- }
- }
- if (metadata != strength) {
- world.editingBlocks = true;
- tile.getMDs()[n] = strength;// world.setBlockMetadataWithNotify(i,
- // j, k,
- // strength);
- // world.markBlocksDirty(i, j, k, i, j, k);
- world.editingBlocks = false;
- for (m = 0; m < 4; ++m) {
- xx = x;
- zz = z;
- int yy = y - 1;
- // @off
- switch (m) {
- case 0:
- xx--;
- break;
- case 1:
- xx++;
- break;
- case 2:
- zz--;
- break;
- case 3:
- zz++;
- break;
- }
- // @on
- if (world.isBlockNormalCube(xx, y, zz))
- yy += 2;
- boolean var15 = false;
- int comparedStrength = getMaxCurrentStrength(world, xx, y, zz,
- -1);
- strength = tile.getMDs()[n];// world.getBlockMetadata(i, j, k);
- if (strength > 0)
- --strength;
- if (comparedStrength >= 0 && comparedStrength != strength)
- calculateCurrentChanges(world, xx, y, zz, x, y, z, tile, n);
- comparedStrength = getMaxCurrentStrength(world, xx, yy, zz, -1);
- strength = tile.getMDs()[n];// world.getBlockMetadata(i, j, k);
- if (strength > 0)
- --strength;
- if (comparedStrength >= 0 && comparedStrength != strength)
- calculateCurrentChanges(world, xx, yy, zz, x, y, z, tile, n);
- }
- if (metadata < strength || strength == 0) {
- blocksNeedingUpdate.add(new ChunkPosition(x , y , z));
- blocksNeedingUpdate.add(new ChunkPosition(x - 1, y , z));
- blocksNeedingUpdate.add(new ChunkPosition(x + 1, y , z));
- blocksNeedingUpdate.add(new ChunkPosition(x , y - y, z));
- blocksNeedingUpdate.add(new ChunkPosition(x , y + y, z));
- blocksNeedingUpdate.add(new ChunkPosition(x , y , z - 1));
- blocksNeedingUpdate.add(new ChunkPosition(x , y , z + 1));
- }
- }
- }
- private int getMaxCurrentStrength(World world, int x, int y, int z, int old) {
- if (world.getBlockId(x, y, z) != Block.redstoneWire.blockID) {
- return old;
- } else {
- int meta = world.getBlockMetadata(x, y, z);
- return meta > old ? meta : old;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement