Advertisement
Guest User

GemBlocksForGreg 1.3

a guest
Feb 26th, 2015
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.64 KB | None | 0 0
  1. // GemBlocksForGregMod.java
  2.  
  3. package de.ultrapeeks.gemblocksforgreg;
  4.  
  5. import gregtech.api.enums.Materials;
  6. import net.minecraft.block.Block;
  7. import net.minecraft.creativetab.CreativeTabs;
  8. import net.minecraft.item.Item;
  9. import net.minecraft.item.ItemStack;
  10. import net.minecraftforge.common.config.Configuration;
  11. import net.minecraftforge.oredict.OreDictionary;
  12. import net.minecraftforge.oredict.ShapedOreRecipe;
  13. import cpw.mods.fml.common.Mod;
  14. import cpw.mods.fml.common.Mod.EventHandler;
  15. import cpw.mods.fml.common.Mod.Instance;
  16. import cpw.mods.fml.common.event.FMLInitializationEvent;
  17. import cpw.mods.fml.common.event.FMLPreInitializationEvent;
  18. import cpw.mods.fml.common.registry.GameRegistry;
  19. import cpw.mods.fml.relauncher.Side;
  20. import cpw.mods.fml.relauncher.SideOnly;
  21. import de.ultrapeeks.gemblocksforgreg.BasicGemBlock.GemType;
  22.  
  23. @Mod(modid = GemBlocksForGregMod.MODID, name = GemBlocksForGregMod.NAME, version = GemBlocksForGregMod.VERSION,
  24.         dependencies = "required-after:gregtech")
  25. public class GemBlocksForGregMod {
  26.     public static final String MODID = "GemBlocksForGreg";
  27.     public static final String NAME = "GemBlocksForGreg";
  28.     public static final String VERSION = "1.3";
  29.    
  30.     @Instance(value = MODID)
  31.     public static GemBlocksForGregMod instance;
  32.    
  33.     public static CreativeTabs tabCustom = new CreativeTabs(MODID) {
  34.         @Override
  35.         @SideOnly(Side.CLIENT)
  36.         public Item getTabIconItem() {
  37.             return Item.getItemFromBlock(GameRegistry.findBlock(MODID, "rubyBlock"));
  38.         }
  39.     };
  40.    
  41.     @EventHandler
  42.     public void preInit(FMLPreInitializationEvent event) {
  43.         Configuration config = new Configuration(event.getSuggestedConfigurationFile());
  44.         config.load();
  45.        
  46.         boolean change = config.get("features", "enableChangedUrnaniumByProducts", false,
  47.                 "If set to true: Replaces Plutonium 244 with Uranium 235 in the byproduct list of Uranium and Uraninite.").getBoolean(false);
  48.        
  49.         config.save();
  50.        
  51.         for (GemType type: GemType.values()) {
  52.             Block block = new BasicGemBlock(type);
  53.             GameRegistry.registerBlock(block, type.getName());
  54.             for(String oreName: type.getOreNames()) {
  55.                 OreDictionary.registerOre(oreName, block);
  56.             }
  57.             GameRegistry.addRecipe(new ShapedOreRecipe(
  58.                     new ItemStack(block), "xxx", "xxx", "xxx", Character.valueOf('x'), type.getGemOreName()));
  59.         }
  60.        
  61.         Block block = null;
  62.         for (int i = 0; i < MetalType.values().length; i++) {
  63.             MetalType type = MetalType.values()[i];
  64.             if (i % 16 == 0) {
  65.                 block = new BasicMetalBlock(i / 16);
  66.                 GameRegistry.registerBlock(block, MetalBlockItem.class, block.getUnlocalizedName(), block);
  67.             }
  68.            
  69.             ItemStack stack = new ItemStack(block, 1, i % 16);
  70.             for(String oreName: type.getOreNames()) {
  71.                 OreDictionary.registerOre(oreName, stack.copy());
  72.             }
  73.             GameRegistry.addRecipe(new ShapedOreRecipe(
  74.                     stack.copy(), "xxx", "xxx", "xxx", Character.valueOf('x'), type.getIngotOreName()));
  75.         }
  76.        
  77.         if (change) {
  78.             Materials.Uraninite.mOreByProducts.set(2, Materials.Uranium235);
  79.             Materials.Uranium.mOreByProducts.set(1, Materials.Uranium235);
  80.         }
  81.     }
  82.    
  83.     @EventHandler
  84.     public void postInit(FMLInitializationEvent event) {
  85.         for(ItemStack item: OreDictionary.getOres("ironwood")) {
  86.             OreDictionary.registerOre("ingotIronWood", item);
  87.         }
  88.     }
  89. }
  90.  
  91. // ---------------------------------------------------------------------------------------------
  92. // BasicGemBlock.java
  93.  
  94. package de.ultrapeeks.gemblocksforgreg;
  95.  
  96. import net.minecraft.block.Block;
  97. import net.minecraft.block.material.Material;
  98.  
  99. public class BasicGemBlock extends Block {
  100.    
  101.     public enum GemType {
  102.        
  103.         RUBY("rubyBlock", "gemRuby", "blockRuby", "blockGemRuby"),
  104.         SAPPHIRE("sapphireBlock", "gemSapphire", "blockSapphire", "blockGemSapphire"),
  105.         GREEN_SAPPHIRE("greenSapphireBlock", "gemGreenSapphire", "blockGreenSapphire", "blockGemGreenSapphire"),
  106.         OLIVINE("olivineBlock", "gemOlivine", "blockOlivine", "blockGemOlivine"),
  107.         TOPAZ("topazBlock", "gemTopaz", "blockTopaz", "blockGemTopaz"),
  108.         TANZANITE("tanzaniteBlock", "gemTanzanite", "blockTanzanite", "blockGemTanzanite"),
  109.         AMETHYST("amethystBlock", "gemAmethyst", "blockAmethyst", "blockGemAmethyst"),
  110.         OPAL("opalBlock", "gemOpal", "blockOpal", "blockGemOpal"),
  111.         JASPER("jasperBlock", "gemJasper", "blockJasper", "blockGemJasper"),
  112.         BLUE_TOPAZ("blueTopazBlock", "gemBlueTopaz", "blockBlueTopaz", "blockGemBlueTopaz"),
  113.         FOOLS_RUBY("foolsRubyBlock", "gemFoolsRuby", "blockFoolsRuby", "blockGemFoolsRuby"),
  114.         AMBER("amberBlock", "gemAmber", "blockAmber", "blockGemAmber"),
  115.         DILITHIUM("dilithiumBlock", "gemDilithium", "blockDilithium", "blockGemDilithium"),
  116.         FORCICIUM("forciciumBlock", "gemForcicium", "blockForcicium", "blockGemForcicium"),
  117.         FORCILLIUM("forcilliumBlock", "gemForcillium", "blockForcillium", "blockGemForcillium"),
  118.         FORCE("forceBlock", "gemForce", "blockForce", "blockGemForce"),
  119.         RED_GARNET("redGarnetBlock", "gemGarnetRed", "blockGarnetRed", "blockGemGarnetRed"),
  120.         YELLOW_GARNET("yellowGarnetBlock", "gemGarnetYellow", "blockGarnetYellow", "blockGemGarnetYellow"),
  121.         VINTEUM("vinteumBlock", "gemVinteum", "blockVinteum", "blockGemVinteum"),
  122.         ENDERPEARL("enderPearlBlock", "gemEnderPearl", "blockEnderPearl", "blockGemEnderPearl"),
  123.         ENDEREYE("enderEyeBlock", "gemEnderEye", "blockEnderEye", "blockGemEnderEye"),
  124.         AER("aerCrystalBlock", "gemInfusedAir", "blockInfusedAir", "blockGemInfusedAir"),
  125.         IGNIS("ignisCrystalBlock", "gemInfusedFire", "blockInfusedFire", "blockGemInfusedFire"),
  126.         TERRA("terraCrystalBlock", "gemInfusedEarth", "blockInfusedEarth", "blockGemInfusedEarth"),
  127.         AQUA("aquaCrystalBlock", "gemInfusedWater", "blockInfusedWater", "blockGemInfusedWater"),
  128.         PERDITIO("perditioCrystalBlock", "gemInfusedEntropy", "blockInfusedEntropy", "blockGemInfusedEntropy"),
  129.         ORDO("ordoCrystalBlock", "gemInfusedOrder", "blockInfusedOrder", "blockGemInfusedOrder");
  130.  
  131.         private String name;
  132.         private String gemOreName;
  133.         private String[] oreNames;
  134.        
  135.         private GemType(String name, String gemOreName, String... oreNames) {
  136.             this.name = name;
  137.             this.gemOreName = gemOreName;
  138.             this.oreNames = oreNames;
  139.         }
  140.        
  141.         public String getName() {
  142.             return name;
  143.         }
  144.        
  145.         public String[] getOreNames() {
  146.             return oreNames;
  147.         }
  148.        
  149.         public String getGemOreName() {
  150.             return gemOreName;
  151.         }
  152.     }
  153.    
  154.     private static final String TEXTURE_PREFIX = "gemblocksforgreg:gems/";
  155.    
  156.     private GemType type;
  157.  
  158.     protected BasicGemBlock(GemType type) {
  159.         super(Material.iron);
  160.         this.type = type;
  161.         setBlockName(type.getName());
  162.         setHardness(3.0f);
  163.         setStepSound(Block.soundTypeMetal);
  164.         setCreativeTab(GemBlocksForGregMod.tabCustom);
  165.         setHarvestLevel("pickaxe", 2);
  166.         setBlockTextureName(TEXTURE_PREFIX + type.getName());
  167.     }
  168. }
  169.  
  170. // --------------------------------------------------------------------------------------------------
  171. // BasicMetalBlock.java
  172.  
  173. package de.ultrapeeks.gemblocksforgreg;
  174.  
  175. import java.util.List;
  176.  
  177. import net.minecraft.block.Block;
  178. import net.minecraft.block.material.Material;
  179. import net.minecraft.client.renderer.texture.IIconRegister;
  180. import net.minecraft.creativetab.CreativeTabs;
  181. import net.minecraft.item.Item;
  182. import net.minecraft.item.ItemStack;
  183. import net.minecraft.util.IIcon;
  184. import cpw.mods.fml.relauncher.Side;
  185. import cpw.mods.fml.relauncher.SideOnly;
  186.  
  187. public class BasicMetalBlock extends Block{
  188.    
  189.     private static final String TEXTURE_PREFIX = "gemblocksforgreg:metals/";
  190.    
  191.     private final int offset;
  192.    
  193.     private IIcon[] iconBuffer;
  194.    
  195.     @Override
  196.     public int damageDropped(int damage) {
  197.         return damage;
  198.     }
  199.    
  200.     @Override
  201.     @SideOnly(Side.CLIENT)
  202.     public void getSubBlocks(Item item, CreativeTabs tab, List list) {
  203.         int enumLength = MetalType.values().length;
  204.         for (int i = 0; i < 16 && i + this.offset * 16 < enumLength; i++) {
  205.             list.add(new ItemStack(item, 1, i));
  206.         }
  207.     }
  208.    
  209.     @Override
  210.     @SideOnly(Side.CLIENT)
  211.     public void registerBlockIcons(IIconRegister icons) {
  212.         int enumLength = MetalType.values().length;
  213.         int offset = this.offset * 16;
  214.         this.iconBuffer = new IIcon[Math.min(enumLength - offset, 16)];
  215.         IIcon defaultIcon = icons.registerIcon(TEXTURE_PREFIX + "defaultBlock");
  216.        
  217.         for(int i = 0; i < this.iconBuffer.length; i++) {
  218.             this.iconBuffer[i] = icons.registerIcon(TEXTURE_PREFIX + MetalType.values()[i + offset].getName());
  219.         }
  220.     }
  221.    
  222.     @Override
  223.     @SideOnly(Side.CLIENT)
  224.     public IIcon getIcon(int side, int meta) {
  225.         if (meta >= this.iconBuffer.length) {
  226.             System.out.println("Warning: unknown meta data " + meta + " for block " + getUnlocalizedName() + ". Prevented Overflow.");
  227.             return this.iconBuffer[0];
  228.         }
  229.         return this.iconBuffer[meta];
  230.     }
  231.    
  232.     public int getOffset() {
  233.         return offset;
  234.     }
  235.  
  236.     protected BasicMetalBlock(int offset) {
  237.         super(Material.iron);
  238.         this.offset = offset;
  239.        
  240.         setBlockName("metalBlock" + offset);
  241.         setHardness(3.0f);
  242.         setStepSound(Block.soundTypeMetal);
  243.         setCreativeTab(GemBlocksForGregMod.tabCustom);
  244.         setHarvestLevel("pickaxe", 2);
  245.     }
  246. }
  247.  
  248. // ----------------------------------------------------------------------------------------
  249. // MetalBlockItem.java
  250.  
  251. package de.ultrapeeks.gemblocksforgreg;
  252.  
  253. import net.minecraft.block.Block;
  254. import net.minecraft.item.ItemBlock;
  255. import net.minecraft.item.ItemStack;
  256.  
  257. public class MetalBlockItem extends ItemBlock{
  258.  
  259.     private BasicMetalBlock block;
  260.    
  261.     public MetalBlockItem(Block block, BasicMetalBlock metalBlock) {
  262.         super(block);
  263.         this.block = metalBlock;
  264.         setHasSubtypes(true);
  265.     }
  266.    
  267.     @Override
  268.     public int getMetadata(int damage) {
  269.         return damage;
  270.     }
  271.    
  272.     @Override
  273.     public String getUnlocalizedName(ItemStack itemStack) {
  274.         MetalType type = MetalType.values()[block.getOffset() * 16 + itemStack.getItemDamage()];
  275.         return "tile." + type.getName();
  276.     }
  277. }
  278.  
  279. // -------------------------------------------------------------------------------------------------------------
  280. // MetalType.java
  281.  
  282. package de.ultrapeeks.gemblocksforgreg;
  283.  
  284. public enum MetalType {
  285.    
  286.     BERYLLIUM("Beryllium"),
  287.     MAGNESIUM("Magnesium"),
  288.     ALUMINIUM("Aluminium"),
  289.     SILICON("Silicon"),
  290.     SCANDIUM("Scandium"),
  291.     TITANIUM("Titanium"),
  292.     VANADIUM("Vanadium"),
  293.     CHROME("Chrome"),
  294.     MANGANESE("Manganese"),
  295.     COBALT("Cobalt"),
  296.     NICKEL("Nickel"),
  297.     COPPER("Copper"),
  298.     ZINC("Zinc"),
  299.     GALLIUM("Gallium"),
  300.     ARSENIC("Arsenic"),
  301.     RUBIDIUM("Rubidium"),
  302.     YTTRIUM("Yttrium"),
  303.     NIOBIUM("Niobium"),
  304.     MOLYBDENUM("Molybdenum"),
  305.     PALLADIUM("Palladium"),
  306.     SILVER("Silver"),
  307.     INDIUM("Indium"),
  308.     TIN("Tin"),
  309.     ANTIMONY("Antimony"),
  310.     TELLURIUM("Tellurium"),
  311.     CAESIUM("Caesium"),
  312.     LANTHANUM("Lanthanum"),
  313.     CERIUM("Cerium"),
  314.     PRASEODYMIUM("Praseodymium"),
  315.     NEODYMIUM("Neodymium"),
  316.     SAMARIUM("Samarium"),
  317.     EUROPIUM("Europium"),
  318.     GADOLINIUM("Gadolinium"),
  319.     TERBIUM("Terbium"),
  320.     DYSPROSIUM("Dysprosium"),
  321.     HOLMIUM("Holmium"),
  322.     ERBIUM("Erbium"),
  323.     THULIUM("Thulium"),
  324.     YTTERBIUM("Ytterbium"),
  325.     LUTETIUM("Lutetium"),
  326.     TANTALUM("Tantalum"),
  327.     TUNGSTEN("Tungsten"),
  328.     OSMIUM("Osmium"),
  329.     IRIDIUM("Iridium"),
  330.     PLATINUM("Platinum"),
  331.     LEAD("Lead"),
  332.     BISMUTH("Bismuth"),
  333.     THORIUM("Thorium"),
  334.     URANIUM235("Uranium235"),
  335.     URANIUM("Uranium"),
  336.     PLUTONIUM("Plutonium"),
  337.     PLUTONIUM241("Plutonium241"),
  338.     AMERICIUM("Americium"),
  339.     NEUTRONIUM("Neutronium"),
  340.     BRONZE("Bronze"),
  341.     BRASS("Brass"),
  342.     INVAR("Invar"),
  343.     ELECTRUM("Electrum"),
  344.     WROUGHT_IRON("WroughtIron"),
  345.     STEEL("Steel"),
  346.     STAINLESS_STEEL("StainlessSteel"),
  347.     PIG_IRON("PigIron"),
  348.     RED_ALLOY("RedAlloy"),
  349.     BLUE_ALLOY("BlueAlloy"),
  350.     CUPRONICKEL("Cupronickel"),
  351.     NICHROME("Nichrome"),
  352.     KANTHAL("Kanthal"),
  353.     MAGNALIUM("Magnalium"),
  354.     SOLDERING_ALLOY("SolderingAlloy"),
  355.     BATTERY_ALLOY("BatteryAlloy"),
  356.     TUNGSTEN_STEEL("TungstenSteel"),
  357.     OSMIRIDIUM("Osmiridium"),
  358.     SUNNARIUM("Sunnarium"),
  359.     ADAMANTIUM("Adamantium"),
  360.     FLUXED_ELECTRUM("ElectrumFlux"),
  361.     ENDERIUM("Enderium"),
  362.     HSLA_STEEL("HSLA"),
  363.     INFUSED_GOLD("InfusedGold"),
  364.     NAQUADAH("Naquadah"),
  365.     NAQUADAH_ALLOY("NaquadahAlloy"),
  366.     ENRICHED_NAQUADAH("NaquadahEnriched"),
  367.     NAQUADRIA("Naquadria"),
  368.     DURANIUM("Duranium"),
  369.     TRITANIUM("Tritanium"),
  370.     THAUMIUM("Thaumium"),
  371.     MITHRIL("Mithril"),
  372.     MIDASIUM("Midasium"),
  373.     ASTRAL_SILVER("AstralSilver"),
  374.     BLACK_STEEL("BlackSteel"),
  375.     DAMASCUS_STEEL("DamascusSteel"),
  376.     SHADOW_IRON("ShadowIron"),
  377.     SHADOW_STEEL("ShadowSteel"),
  378.     IRON_WOOD("IronWood"),
  379.     METEORIC_IRON("MeteoricIron"),
  380.     METEORIC_STEEL("MeteoricSteel"),
  381.     DARK_IRON("DarkIron"),
  382.     COBALT_BRASS("CobaltBrass"),
  383.     ULTIMET("Ultimet"),
  384.     ANNEALED_COPPER("AnnealedCopper"),
  385.     FIERY_STEEL("FierySteel"),
  386.     RED_STEEL("RedSteel"),
  387.     BLUE_STEEL("BlueSteel"),
  388.     STERLING_SILVER("SterlingSilver"),
  389.     ROSE_GOLD("RoseGold"),
  390.     BLACK_BRONZE("BlackBronze"),
  391.     BISMUTH_BRONZE("BismuthBronze"),
  392.     MAGNETIC_IRON("IronMagnetic"),
  393.     MAGNETIC_STEEL("SteelMagnetic"),
  394.     MAGNETIC_NEODYMIUM("NeodymiumMagnetic"),
  395.     VANADIUM_GALLIUM("VanadiumGallium"),
  396.     YTTRIUM_BARIUM_CUPRATE("YttriumBariumCuprate"),
  397.     NIOBIUM_NITRIDE("NiobiumNitride"),
  398.     NIOBIUM_TITANIUM("NiobiumTitanium"),
  399.     CHROMIUM_DIOXIDE("ChromiumDioxide"),
  400.     KNIGHTMETAL("Knightmetal"),
  401.     TIN_ALLOY("TinAlloy"),
  402.     DEEP_IRON("DeepIron"),
  403.     DESH("Desh");
  404.    
  405.     private String name;
  406.     private String ingotOreName;
  407.     private String[] oreNames;
  408.    
  409.     private MetalType(String material) {
  410.         this.name = material.substring(0, 1).toLowerCase() + material.substring(1) + "Block";
  411.         this.ingotOreName = "ingot" + material;
  412.         this.oreNames = new String[]{"block" + material, "blockMetal" + material};
  413.     }
  414.    
  415.     public String getName() {
  416.         return name;
  417.     }
  418.    
  419.     public String[] getOreNames() {
  420.         return oreNames;
  421.     }
  422.    
  423.     public String getIngotOreName() {
  424.         return ingotOreName;
  425.     }
  426. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement