Advertisement
Guest User

Class

a guest
Jul 21st, 2015
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.50 KB | None | 0 0
  1. package com.github.wolfiewaffle.hardcoretorches.blocks;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Random;
  5.  
  6. import net.minecraft.block.BlockTorch;
  7. import net.minecraft.block.ITileEntityProvider;
  8. import net.minecraft.creativetab.CreativeTabs;
  9. import net.minecraft.entity.EntityLivingBase;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. import net.minecraft.init.Blocks;
  12. import net.minecraft.item.Item;
  13. import net.minecraft.item.ItemStack;
  14. import net.minecraft.tileentity.TileEntity;
  15. import net.minecraft.world.World;
  16.  
  17. import com.github.wolfiewaffle.hardcoretorches.help.Reference;
  18. import com.github.wolfiewaffle.hardcoretorches.init.ModBlocks;
  19. import com.github.wolfiewaffle.hardcoretorches.tileentities.TileEntityTorchLit;
  20. import com.github.wolfiewaffle.hardcoretorches.tileentities.TileEntityTorchLitCoke;
  21. import com.github.wolfiewaffle.hardcoretorches.tileentities.TileEntityTorchUnlitCoke;
  22.  
  23. import cpw.mods.fml.relauncher.Side;
  24. import cpw.mods.fml.relauncher.SideOnly;
  25.  
  26. public class BlockTorchLitCoke extends BlockTorch implements ITileEntityProvider
  27. {
  28.     // The maximum fuel of a Lit Torch
  29.     public static final int MAX_FUEL_COKE = BlockTorchLit.MAX_FUEL*2;
  30.    
  31.     //Constructor
  32.     public BlockTorchLitCoke() {
  33.         super();
  34.         this.setCreativeTab(CreativeTabs.tabBlock);
  35.         this.setStepSound(soundTypeStone);
  36.         this.setBlockName("torchLitCoke");
  37.         this.setLightLevel(0.8f);
  38.         this.setBlockTextureName(Reference.MODID + ":" + getUnlocalizedName().substring(5));
  39.     }
  40.    
  41.     //Particles and burning out
  42.     @SideOnly(Side.CLIENT)
  43.     public void randomDisplayTick(World world, int x, int y, int z, Random rand) {
  44.         int meta = world.getBlockMetadata(x, y, z);
  45.         double d0 = (double)((float)x + 0.5F);
  46.         double d1 = (double)((float)y + 0.7F);
  47.         double d2 = (double)((float)z + 0.5F);
  48.         double d3 = 0.2199999988079071D;
  49.         double d4 = 0.27000001072883606D;
  50.         int oldFuel = ((TileEntityTorchLitCoke)world.getTileEntity(x, y, z)).getFuelAmount();
  51.        
  52.         //Particles
  53.         if (meta == 1)
  54.         {
  55.             world.spawnParticle("smoke", d0 - d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D);
  56.             world.spawnParticle("flame", d0 - d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D);
  57.         }
  58.         else if (meta == 2)
  59.         {
  60.             world.spawnParticle("smoke", d0 + d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D);
  61.             world.spawnParticle("flame", d0 + d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D);
  62.         }
  63.         else if (meta == 3)
  64.         {
  65.             world.spawnParticle("smoke", d0, d1 + d3, d2 - d4, 0.0D, 0.0D, 0.0D);
  66.             world.spawnParticle("flame", d0, d1 + d3, d2 - d4, 0.0D, 0.0D, 0.0D);
  67.         }
  68.         else if (meta == 4)
  69.         {
  70.             world.spawnParticle("smoke", d0, d1 + d3, d2 + d4, 0.0D, 0.0D, 0.0D);
  71.             world.spawnParticle("flame", d0, d1 + d3, d2 + d4, 0.0D, 0.0D, 0.0D);
  72.         }
  73.         else
  74.         {
  75.             world.spawnParticle("smoke", d0, d1, d2, 0.0D, 0.0D, 0.0D);
  76.             world.spawnParticle("flame", d0, d1, d2, 0.0D, 0.0D, 0.0D);
  77.         }
  78.        
  79.         //Rain extinguishing
  80.         if((world.isRaining() && world.canBlockSeeTheSky(x, y, z))) {
  81.            
  82.             //Set world block
  83.             world.setBlock(x, y, z, ModBlocks.torchUnlitCoke, meta, 3);
  84.             world.playSoundEffect(d0, d1, d2, "random.fizz", 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F);
  85.            
  86.             //Set the fuel value
  87.             TileEntity te2 = (TileEntityTorchLitCoke)world.getTileEntity(x, y, z);
  88.             ((TileEntityTorchUnlitCoke)te2).setFuel(oldFuel);
  89.            
  90.             //Not working
  91.             if (meta == 1) {
  92.                 for(int c = 1; c < 10+1; c++) {
  93.                     world.spawnParticle("smoke", d0 - d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D);  
  94.                 }
  95.             }
  96.             else if (meta == 2) {
  97.                 for(int c = 1; c < 10+1; c++) {
  98.                     world.spawnParticle("smoke", d0 + d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D);
  99.                 }
  100.             }
  101.             else if (meta == 3) {
  102.                 for(int c = 1; c < 10+1; c++) {
  103.                     world.spawnParticle("smoke", d0, d1 + d3, d2 - d4, 0.0D, 0.0D, 0.0D);
  104.                 }
  105.             }
  106.             else if (meta == 4) {
  107.                 for(int c = 1; c < 10+1; c++) {
  108.                     world.spawnParticle("smoke", d0, d1 + d3, d2 + d4, 0.0D, 0.0D, 0.0D);
  109.                 }
  110.             }
  111.             else {
  112.                 for(int c = 1; c < 10+1; c++) {
  113.                     world.spawnParticle("smoke", d0, d1, d2, 0.0D, 0.0D, 0.0D);
  114.                 }
  115.             }
  116.         }
  117.     }
  118.    
  119.     //Create the TileEntity
  120.     @Override
  121.     public TileEntity createNewTileEntity(World world, int meta) {
  122.         return new TileEntityTorchLitCoke();
  123.     }
  124.    
  125.     //Get TileEntity method
  126.     private TileEntityTorchLitCoke getTileEntity(World world, int x, int y, int z){
  127.         return (TileEntityTorchLitCoke) world.getTileEntity(x, y, z);
  128.     }
  129.    
  130.     //Get fuel amount debug
  131.     @Override
  132.     public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int meta, float hitX, float hitY, float hitZ) {
  133.         if (!world.isRemote) {
  134.             TileEntityTorchLitCoke te = getTileEntity(world, x, y, z);
  135.             System.out.printf("Right click. Fuel: %d\n", te.getFuelAmount());
  136.         }
  137.        
  138.         //Extinguish torch
  139.         if (player.inventory.getCurrentItem() != null)
  140.         {
  141.             if (player.inventory.getCurrentItem().getItem() == Item.getItemFromBlock(Blocks.wool) ||
  142.                 player.inventory.getCurrentItem().getItem() == Item.getItemFromBlock(Blocks.carpet))
  143.             {
  144.                 int l = world.getBlockMetadata(x, y, z);
  145.                 double d0 = (double)((float)x + 0.5F);
  146.                 double d1 = (double)((float)y + 0.7F);
  147.                 double d2 = (double)((float)z + 0.5F);
  148.                 int oldFuel = ((TileEntityTorchLit)world.getTileEntity(x, y, z)).getFuelAmount();
  149.                
  150.                 //Set world block
  151.                 world.setBlock(x, y, z, ModBlocks.torchUnlitCoke, l, 3);
  152.                 world.playSoundEffect(d0, d1, d2, "random.fizz", 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F);
  153.                
  154.                 //Set the fuel value
  155.                 TileEntity te2 = (TileEntityTorchLitCoke)world.getTileEntity(x, y, z);
  156.                 ((TileEntityTorchLitCoke)te2).setFuel(oldFuel);
  157.                
  158.                 //Consume item
  159.                 player.inventory.decrStackSize(player.inventory.currentItem, 1);
  160.             }
  161.            
  162.             //Light a held torch
  163.             if (player.inventory.getCurrentItem().getItem() == Item.getItemFromBlock(ModBlocks.torchUnlit))
  164.             {
  165.                 ItemStack stack = player.inventory.getStackInSlot(player.inventory.currentItem);
  166.                 int count = 0;
  167.                 int oldFuel = stack.getItemDamage();
  168.                
  169.                 //Get the amount of held items
  170.                 if(player.getCurrentEquippedItem() != null) {
  171.                     count = player.getCurrentEquippedItem().stackSize;
  172.                 }
  173.                
  174.                 //If there is only one torch, just light it
  175.                 if (count == 1) {
  176.                     player.inventory.setInventorySlotContents(player.inventory.currentItem, new ItemStack(Item.getItemFromBlock(ModBlocks.torchLit), count, oldFuel));
  177.                 } else if (count > 1) {
  178.                     //Subtract one torch from the stack and give a lit torch to the player
  179.                     player.inventory.setInventorySlotContents(player.inventory.currentItem, new ItemStack(Item.getItemFromBlock(ModBlocks.torchUnlit), count-1, oldFuel));
  180.                     if (player.inventory.addItemStackToInventory(new ItemStack(Item.getItemFromBlock(ModBlocks.torchLit), 1, oldFuel)) == true) {
  181.                         System.out.println("There was space in the inventory");
  182.                     } else {
  183.                         //world.spawnEntityInWorld(new EntityItem(world, player.posX, player.posY, player.posZ, new ItemStack(Item.getItemFromBlock(ModBlocks.torchLit))));
  184.                         player.dropPlayerItemWithRandomChoice(new ItemStack(Item.getItemFromBlock(ModBlocks.torchLit)), true);
  185.                     }
  186.                 }
  187.             }
  188.            
  189.             //Light a held coke torch
  190.             if (player.inventory.getCurrentItem().getItem() == Item.getItemFromBlock(ModBlocks.torchUnlitCoke))
  191.             {
  192.                 ItemStack stack = player.inventory.getStackInSlot(player.inventory.currentItem);
  193.                 int count = 0;
  194.                 int oldFuel = stack.getItemDamage();
  195.                
  196.                 //Get the amount of held items
  197.                 if(player.getCurrentEquippedItem() != null) {
  198.                     count = player.getCurrentEquippedItem().stackSize;
  199.                 }
  200.                
  201.                 //If there is only one torch, just light it
  202.                 if (count == 1) {
  203.                     player.inventory.setInventorySlotContents(player.inventory.currentItem, new ItemStack(Item.getItemFromBlock(ModBlocks.torchLitCoke), count, oldFuel));
  204.                 } else if (count > 1) {
  205.                     //Subtract one torch from the stack and give a lit torch to the player
  206.                     player.inventory.setInventorySlotContents(player.inventory.currentItem, new ItemStack(Item.getItemFromBlock(ModBlocks.torchUnlitCoke), count-1, oldFuel));
  207.                     if (player.inventory.addItemStackToInventory(new ItemStack(Item.getItemFromBlock(ModBlocks.torchLitCoke), 1, oldFuel)) == true) {
  208.                         System.out.println("There was space in the inventory");
  209.                     } else {
  210.                         //world.spawnEntityInWorld(new EntityItem(world, player.posX, player.posY, player.posZ, new ItemStack(Item.getItemFromBlock(ModBlocks.torchLit))));
  211.                         player.dropPlayerItemWithRandomChoice(new ItemStack(Item.getItemFromBlock(ModBlocks.torchLitCoke)), true);
  212.                     }
  213.                 }
  214.             }
  215.         }
  216.         return true;
  217.     }
  218.    
  219.     //Place block
  220.     @Override
  221.     public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase player, ItemStack itemstack) {
  222.         TileEntityTorchLitCoke te = getTileEntity(world, i, j, k);
  223.         int itemMeta = itemstack.getItemDamage();
  224.  
  225.         //Item damage goes from 0 to 1000, TE fuel value goes from 1000 to 0
  226.         //itemDamage + fuel = MAX_FUEL
  227.         te.setFuel(MAX_FUEL_COKE - itemMeta);
  228.     }
  229.    
  230.     //I forgot what this is for...
  231.     @Override
  232.     public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest) {
  233.       if(willHarvest) {
  234.         return true;
  235.       }
  236.       return super.removedByPlayer(world, player, x, y, z, willHarvest);
  237.     }
  238.    
  239.     //Harvest method, needs to be modified for some reason I forgot
  240.     @Override
  241.     public void harvestBlock(World world, EntityPlayer player, int x, int y, int z, int meta) {
  242.       super.harvestBlock(world, player, x, y, z, meta);
  243.       world.setBlockToAir(x, y, z);
  244.     }
  245.    
  246.     //Get drops
  247.     @Override
  248.     public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune)
  249.     {
  250.         TileEntityTorchLitCoke te =  getTileEntity(world, x, y, z);
  251.        
  252.         //Item damage goes from 0 to 1000, TE fuel value goes from 1000 to 0
  253.         //itemDamage + fuel = MAX_FUEL_COKE
  254.         int itemMeta = MAX_FUEL_COKE - te.getFuelAmount();
  255.        
  256.         ArrayList<ItemStack> drop = new ArrayList<ItemStack>();
  257.         drop.add(new ItemStack(getItemDropped(metadata, world.rand, fortune), quantityDropped(metadata, fortune, world.rand), itemMeta));
  258.         return drop;
  259.     }
  260. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement