Guest User

BlockElementalLight.java

a guest
Jun 29th, 2019
32
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package me.onVoid.adjunct.block;
  2.  
  3. import java.util.Locale;
  4. import java.util.Random;
  5. import javax.annotation.Nullable;
  6. import me.onVoid.adjunct.init.ItemsAdjunct;
  7. import me.onVoid.adjunct.proxy.CommonProxy;
  8. import me.onVoid.adjunct.tab.CreativeTabsAdjunct;
  9. import me.onVoid.adjunct.util.IHasModel;
  10. import me.onVoid.adjunct.util.Methods;
  11. import me.onVoid.adjunct.util.References;
  12. import net.minecraft.block.Block;
  13. import net.minecraft.block.BlockDirt;
  14. import net.minecraft.block.SoundType;
  15. import net.minecraft.block.material.MapColor;
  16. import net.minecraft.block.material.Material;
  17. import net.minecraft.block.properties.IProperty;
  18. import net.minecraft.block.properties.PropertyEnum;
  19. import net.minecraft.block.state.BlockStateContainer;
  20. import net.minecraft.block.state.IBlockState;
  21. import net.minecraft.client.gui.GuiScreen;
  22. import net.minecraft.client.renderer.block.model.ModelBakery;
  23. import net.minecraft.client.renderer.block.model.ModelResourceLocation;
  24. import net.minecraft.client.util.ITooltipFlag;
  25. import net.minecraft.creativetab.CreativeTabs;
  26. import net.minecraft.init.Blocks;
  27. import net.minecraft.init.Items;
  28. import net.minecraft.item.EnumRarity;
  29. import net.minecraft.item.Item;
  30. import net.minecraft.item.ItemStack;
  31. import net.minecraft.util.IStringSerializable;
  32. import net.minecraft.util.NonNullList;
  33. import net.minecraft.util.math.BlockPos;
  34. import net.minecraft.util.math.MathHelper;
  35. import net.minecraft.util.text.TextFormatting;
  36. import net.minecraft.world.IBlockAccess;
  37. import net.minecraft.world.World;
  38. import net.minecraftforge.client.model.ModelLoader;
  39. import net.minecraftforge.fml.relauncher.Side;
  40. import net.minecraftforge.fml.relauncher.SideOnly;
  41.  
  42. public class BlockElementalLight extends Block implements IHasModel
  43. {
  44.  
  45.     public BlockElementalLight() {
  46.         super(Material.GLASS);
  47.         setUnlocalizedName("light_elemental");
  48.         setRegistryName("light_elemental");
  49.         setHardness(0.3F);
  50.         setResistance(1.5F);
  51.         setLightLevel(1.0F);
  52.         setSoundType(SoundType.GLASS);
  53.         setCreativeTab(CreativeTabsAdjunct.tabAdjunct);
  54.         this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, BlockElementalLight.ElementalLightType.DEFAULT));
  55.     }
  56.    
  57.     public static final PropertyEnum<BlockElementalLight.ElementalLightType> VARIANT = PropertyEnum.<BlockElementalLight.ElementalLightType>create("variant", BlockElementalLight.ElementalLightType.class);
  58.  
  59.     @Override
  60.     public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos)
  61.     {
  62.         return ((BlockElementalLight.ElementalLightType)state.getValue(VARIANT)).getColor();
  63.     }
  64.    
  65.     @Override
  66.     public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> items){
  67.         items.add(new ItemStack(this, 1, BlockElementalLight.ElementalLightType.DEFAULT.getMetadata()));
  68.         items.add(new ItemStack(this, 1, BlockElementalLight.ElementalLightType.GLASSLESS.getMetadata()));
  69.         items.add(new ItemStack(this, 1, BlockElementalLight.ElementalLightType.INTRICATE.getMetadata()));
  70.     }
  71.    
  72.     @Override
  73.     public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
  74.     {
  75.         return new ItemStack(this, 1, ((BlockElementalLight.ElementalLightType)state.getValue(VARIANT)).getMetadata());
  76.     }
  77.    
  78.     @Override
  79.     public IBlockState getStateFromMeta(int meta)
  80.     {
  81.         return this.getDefaultState().withProperty(VARIANT, BlockElementalLight.ElementalLightType.byMetadata(meta));
  82.     }
  83.    
  84.     @Override
  85.     public int getMetaFromState(IBlockState state)
  86.     {
  87.         return ((BlockElementalLight.ElementalLightType)state.getValue(VARIANT)).getMetadata();
  88.     }
  89.  
  90.     @Override
  91.     protected BlockStateContainer createBlockState()
  92.     {
  93.         return new BlockStateContainer(this, new IProperty[] {VARIANT});
  94.     }
  95.    
  96.     @Override
  97.     public int quantityDroppedWithBonus(int fortune, Random random)
  98.     {
  99.         //return MathHelper.clamp(this.quantityDropped(random) + random.nextInt(fortune + 1), 1, 4);
  100.         return quantityDropped(random);
  101.     }
  102.  
  103.     @Override
  104.     public int quantityDropped(Random random)
  105.     {
  106.         if (random.nextInt(9) == 0){
  107.             return 1;
  108.         }
  109.         return 0;
  110.     }
  111.  
  112.     @Override
  113.     public Item getItemDropped(IBlockState state, Random rand, int fortune)
  114.     {
  115.         return ItemsAdjunct.dustElementalMixture;
  116.     }
  117.    
  118.     @SideOnly(Side.CLIENT)
  119.     @Override
  120.     public void addInformation(ItemStack stack, @Nullable World worldIn, java.util.List<String> info, ITooltipFlag flagIn)
  121.     {
  122.         info.set(0, EnumRarity.COMMON.rarityColor + info.get(0));
  123.        
  124.         if(GuiScreen.isShiftKeyDown()){
  125.             info.addAll(Methods.breakString("A light of the elements`" + TextFormatting.WHITE + "TBD.", "`"));
  126.         } else {
  127.             info.add(References.shiftText);
  128.         }
  129.     }
  130.    
  131.     public static enum ElementalLightType implements IStringSerializable
  132.     {
  133.         DEFAULT(0, "default", MapColor.ORANGE_STAINED_HARDENED_CLAY),
  134.         GLASSLESS(1, "glassless", MapColor.ORANGE_STAINED_HARDENED_CLAY),
  135.         INTRICATE(2, "intricate", MapColor.ORANGE_STAINED_HARDENED_CLAY);
  136.  
  137.         private static final BlockElementalLight.ElementalLightType[] METADATA_LOOKUP = new BlockElementalLight.ElementalLightType[values().length];
  138.         private final int metadata;
  139.         private final String name;
  140.         private final String unlocalizedName;
  141.         private final MapColor color;
  142.  
  143.         private ElementalLightType(int metadataIn, String nameIn, MapColor color)
  144.         {
  145.             this(metadataIn, nameIn, nameIn, color);
  146.         }
  147.  
  148.         private ElementalLightType(int metadataIn, String nameIn, String unlocalizedNameIn, MapColor color)
  149.         {
  150.             this.metadata = metadataIn;
  151.             this.name = nameIn;
  152.             this.unlocalizedName = unlocalizedNameIn;
  153.             this.color = color;
  154.         }
  155.  
  156.         public int getMetadata()
  157.         {
  158.             return this.metadata;
  159.         }
  160.  
  161.         public String getUnlocalizedName()
  162.         {
  163.             return this.unlocalizedName;
  164.         }
  165.  
  166.         public MapColor getColor()
  167.         {
  168.             return this.color;
  169.         }
  170.  
  171.         public String toString()
  172.         {
  173.             return this.name;
  174.         }
  175.  
  176.         public static BlockElementalLight.ElementalLightType byMetadata(int metadata)
  177.         {
  178.             if (metadata < 0 || metadata >= METADATA_LOOKUP.length)
  179.             {
  180.                 metadata = 0;
  181.             }
  182.  
  183.             return METADATA_LOOKUP[metadata];
  184.         }
  185.  
  186.         public String getName()
  187.         {
  188.             return this.name;
  189.         }
  190.  
  191.         static
  192.         {
  193.             for (BlockElementalLight.ElementalLightType blockelementallight$elementallighttype : values())
  194.             {
  195.                 METADATA_LOOKUP[blockelementallight$elementallighttype.getMetadata()] = blockelementallight$elementallighttype;
  196.             }
  197.         }
  198.     }
  199.    
  200.     /*@SideOnly(Side.CLIENT)
  201.     public void initModel() {
  202.         for (int i = 0; i < ElementalLightType.values().length; i++){
  203.             ModelResourceLocation model = new ModelResourceLocation(getRegistryName() + "_" + i, "inventory");
  204.             ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), i, new ModelResourceLocation(getRegistryName(), "inventory"));
  205.             ModelBakery.registerItemVariants(Item.getItemFromBlock(this), model);
  206.         }
  207.     }*/
  208.    
  209.     @Override @SideOnly(Side.CLIENT)
  210.     public void initModel() {
  211.         ModelResourceLocation DefaultModel = new ModelResourceLocation(getRegistryName() + "", "inventory");
  212.         ModelResourceLocation GlasslessModel = new ModelResourceLocation(getRegistryName() + "_glassless", "inventory");
  213.         ModelResourceLocation IntricateModel = new ModelResourceLocation(getRegistryName() + "_intricate", "inventory");
  214.  
  215.         ModelBakery.registerItemVariants(Item.getItemFromBlock(this), DefaultModel, GlasslessModel, IntricateModel);
  216.  
  217.         ModelLoader.setCustomModelResourceLocation(CommonProxy.itemBlockLightElemental, ElementalLightType.DEFAULT.getMetadata(), DefaultModel);
  218.         ModelLoader.setCustomModelResourceLocation(CommonProxy.itemBlockLightElemental, ElementalLightType.GLASSLESS.getMetadata(), GlasslessModel);
  219.         ModelLoader.setCustomModelResourceLocation(CommonProxy.itemBlockLightElemental, ElementalLightType.INTRICATE.getMetadata(), IntricateModel);
  220.     }
  221.  
  222. }
RAW Paste Data