Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package stevesExample.block;
- import java.util.List;
- import net.minecraft.block.Block;
- import net.minecraft.block.material.Material;
- import net.minecraft.client.renderer.texture.IconRegister;
- import net.minecraft.creativetab.CreativeTabs;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.util.Icon;
- import net.minecraft.world.World;
- import stevesExample.item.ItemInfo;
- import cpw.mods.fml.relauncher.Side;
- import cpw.mods.fml.relauncher.SideOnly;
- public class BlockMachine extends Block
- {
- public BlockMachine(int id)
- {
- super(id , Material.rock);
- setCreativeTab(CreativeTabs.tabRedstone);
- setHardness(2F);
- setStepSound(Block.soundStoneFootstep);
- setUnlocalizedName(BlockInfo.MACHINE_UNLOC_NAME);
- }
- @SideOnly(Side.CLIENT)
- private Icon topIcon;
- @SideOnly(Side.CLIENT)
- private Icon bottomIcon;
- @SideOnly(Side.CLIENT)
- private Icon[] sideIcons;
- @SideOnly(Side.CLIENT)
- private Icon disableIcon;
- @SideOnly(Side.CLIENT)
- @Override
- public void registerIcons(IconRegister register)
- {
- topIcon = register.registerIcon(BlockInfo.TEXTURE_LOC + ":"
- + BlockInfo.MACHINE_TOP);
- bottomIcon = register.registerIcon(BlockInfo.TEXTURE_LOC + ":"
- + BlockInfo.MACHINE_BOTTOM);
- sideIcons = new Icon[BlockInfo.MACHINE_SIDES.length];
- for (int i = 0; i < sideIcons.length; i++)
- {
- sideIcons[i] = register.registerIcon(BlockInfo.TEXTURE_LOC + ":"
- + BlockInfo.MACHINE_SIDES[i]);
- }
- disableIcon = register.registerIcon(BlockInfo.TEXTURE_LOC + ":"
- + BlockInfo.MACHINE_DISABLED);
- }
- @SideOnly(Side.CLIENT)
- @Override
- public Icon getIcon(int side, int meta)
- {
- if (side == 0)
- return bottomIcon;
- else if (side == 1)
- return isDisabled(meta) ? disableIcon : topIcon;
- else
- {
- int type = meta / 2;
- if (type == 4)
- type = 0;
- return sideIcons[type];
- }
- }
- private boolean isDisabled(int meta)
- {
- return meta % 2 == 1;
- }
- @Override
- public void onEntityWalking(World world, int x, int y, int z, Entity entity)
- {
- if (!world.isRemote && !isDisabled(world.getBlockMetadata(x , y , z)))
- {
- spawnAnvil(world , x , y + 20 , z);
- }
- }
- @Override
- public void onNeighborBlockChange(World world, int x, int y, int z, int id)
- {
- int meta = world.getBlockMetadata(x , y , z);
- if (world.isBlockIndirectlyGettingPowered(x , y , z) && !world.isRemote
- && !isDisabled(meta))
- {
- switch (meta / 2)
- {
- case 1:
- for (int i = 0; i < 5; i++)
- spawnAnvil(world , x , y + 20 + i , z);
- break;
- case 2:
- for (int i = -1; i <= 1; i++)
- {
- spawnAnvil(world , x + i , y + 20 + i , z - 2);
- spawnAnvil(world , x + i , y + 20 + i , z + 2);
- spawnAnvil(world , x - 2 , y + 20 + i , z + i);
- spawnAnvil(world , x + 2 , y + 20 + i , z + i);
- }
- break;
- case 3:
- for (int i = 1; i <= 3; i++)
- {
- spawnAnvil(world , x + i , y + 20 + i , z);
- spawnAnvil(world , x - i , y + 20 + i , z);
- spawnAnvil(world , x , y + 20 + i , z + i);
- spawnAnvil(world , x , y + 20 + i , z - i);
- }
- break;
- default:
- // spawnAnvil(world, x, y + 20, z);
- for (int i = 0; i < 5; i++)
- for (int j = 0; j < 5; j++)
- spawnAnvil(world , x - 2 + i , y + 20 , z - 2 + j);
- }
- world.setBlockMetadataWithNotify(x , y , z , 1 , 3);
- }
- }
- private void spawnAnvil(World world, int x, int y, int z)
- {
- if (world.isAirBlock(x , y , z))
- world.setBlock(x , y , z , Block.anvil.blockID);
- }
- @Override
- 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);
- int type = meta / 2;
- int disabled = meta % 2 == 0 ? 1 : 0;
- int newMeta = type * 2 + disabled;
- ItemStack itemStack = player.getItemInUse();
- if (meta == 0)
- {
- world.setBlockMetadataWithNotify(x , y , z , meta + 1 , 3);
- player.dropItem(ItemInfo.CARD_ID + 256 , 1).getEntityItem()
- .setItemDamage(3);
- }
- else if (meta != 1)
- {
- setMetaAndDropItem(world , x , y , z , player , disabled , meta);
- }
- }
- return true;
- }
- public static void setMetaAndDropItem(World world, int x, int y, int z, EntityPlayer player, int disabled, int meta)
- {
- ItemStack stack = player.getItemInUse();
- if (meta % 2 == 0 && stack == null)
- {
- player.dropItem(ItemInfo.CARD_ID + 256, 1).getEntityItem().setItemDamage(3);
- world.setBlockMetadataWithNotify(x , y , z , meta + 1 , 3);
- }
- else if (meta % 2 == 1 && stack == null && meta != 1)
- {
- player.dropItem(ItemInfo.CARD_ID + 256 , 1).getEntityItem().setItemDamage(meta / 2 - 1);
- world.setBlockMetadataWithNotify(x , y , z , 1 , 3);
- }
- }
- @Override
- public int damageDropped(int meta)
- {
- return meta;
- }
- @Override
- @SideOnly(Side.CLIENT)
- public void getSubBlocks(int id, CreativeTabs tab, List list)
- {
- for (int i = 0; i < BlockInfo.MACHINE_SIDES.length; i++)
- {
- list.add(new ItemStack(id , 1 , i * 2));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment