From 0540dadfc5c350be71a9ebc6c9d2e5c769d55e47 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 9 Nov 2015 18:05:52 +0100 Subject: [PATCH] Crystals! --- .../blocks/BlockCrystal.java | 113 ++++++++++++++++++ .../actuallyadditions/blocks/InitBlocks.java | 4 + .../metalists/TheColoredLampColors.java | 4 +- .../actuallyadditions/items/InitItems.java | 4 + .../actuallyadditions/items/ItemCrystal.java | 79 ++++++++++++ .../items/metalists/TheCrystals.java | 31 +++++ 6 files changed, 234 insertions(+), 1 deletion(-) create mode 100644 src/main/java/ellpeck/actuallyadditions/blocks/BlockCrystal.java create mode 100644 src/main/java/ellpeck/actuallyadditions/items/ItemCrystal.java create mode 100644 src/main/java/ellpeck/actuallyadditions/items/metalists/TheCrystals.java diff --git a/src/main/java/ellpeck/actuallyadditions/blocks/BlockCrystal.java b/src/main/java/ellpeck/actuallyadditions/blocks/BlockCrystal.java new file mode 100644 index 000000000..c0fc7face --- /dev/null +++ b/src/main/java/ellpeck/actuallyadditions/blocks/BlockCrystal.java @@ -0,0 +1,113 @@ +/* + * This file ("BlockCrystal.java") is part of the Actually Additions Mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015 Ellpeck + */ + +package ellpeck.actuallyadditions.blocks; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import ellpeck.actuallyadditions.items.ItemBlockBase; +import ellpeck.actuallyadditions.items.metalists.TheCrystals; +import ellpeck.actuallyadditions.util.IActAddItemOrBlock; +import ellpeck.actuallyadditions.util.ModUtil; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; + +import java.util.List; + +public class BlockCrystal extends Block implements IActAddItemOrBlock{ + + public static final TheCrystals[] allCrystals = TheCrystals.values(); + + public BlockCrystal(){ + super(Material.rock); + this.setHardness(1.5F); + this.setResistance(10.0F); + this.setHarvestLevel("pickaxe", 1); + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(int side, int metadata){ + return this.blockIcon; + } + + @Override + @SideOnly(Side.CLIENT) + public int getRenderColor(int meta){ + return meta >= allCrystals.length ? super.getRenderColor(meta) : allCrystals[meta].color; + } + + @Override + public int damageDropped(int meta){ + return meta; + } + + @Override + @SideOnly(Side.CLIENT) + public int colorMultiplier(IBlockAccess world, int x, int y, int z){ + return this.getRenderColor(world.getBlockMetadata(x, y, z)); + } + + @SuppressWarnings("all") + @SideOnly(Side.CLIENT) + public void getSubBlocks(Item item, CreativeTabs tab, List list){ + for(int j = 0; j < allCrystals.length; j++){ + list.add(new ItemStack(item, 1, j)); + } + } + + @Override + @SideOnly(Side.CLIENT) + public void registerBlockIcons(IIconRegister iconReg){ + this.blockIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getName()); + } + + @Override + public String getName(){ + return "blockCrystal"; + } + + @Override + public EnumRarity getRarity(ItemStack stack){ + return stack.getItemDamage() >= allCrystals.length ? EnumRarity.common : allCrystals[stack.getItemDamage()].rarity; + } + + public static class TheItemBlock extends ItemBlockBase{ + + public TheItemBlock(Block block){ + super(block); + this.setHasSubtypes(true); + this.setMaxDamage(0); + } + + @Override + public String getUnlocalizedName(ItemStack stack){ + return this.getUnlocalizedName()+(stack.getItemDamage() >= allCrystals.length ? " ERROR!" : allCrystals[stack.getItemDamage()].name); + } + + @Override + public int getMetadata(int damage){ + return damage; + } + + @Override + public EnumRarity getRarity(ItemStack stack){ + EnumRarity rarity = ((IActAddItemOrBlock)this.field_150939_a).getRarity(stack); + return rarity == null ? EnumRarity.common : rarity; + } + } +} diff --git a/src/main/java/ellpeck/actuallyadditions/blocks/InitBlocks.java b/src/main/java/ellpeck/actuallyadditions/blocks/InitBlocks.java index fbfe667aa..666b963ee 100644 --- a/src/main/java/ellpeck/actuallyadditions/blocks/InitBlocks.java +++ b/src/main/java/ellpeck/actuallyadditions/blocks/InitBlocks.java @@ -101,10 +101,14 @@ public class InitBlocks{ public static Block blockLaserRelay; public static Block blockBlackLotus; + public static Block blockCrystal; public static void init(){ ModUtil.LOGGER.info("Initializing Blocks..."); + blockCrystal = new BlockCrystal(); + BlockUtil.register(blockCrystal, BlockCrystal.TheItemBlock.class); + blockBlackLotus = new BlockBlackLotus(); BlockUtil.register(blockBlackLotus); diff --git a/src/main/java/ellpeck/actuallyadditions/blocks/metalists/TheColoredLampColors.java b/src/main/java/ellpeck/actuallyadditions/blocks/metalists/TheColoredLampColors.java index b359b322d..638ce7530 100644 --- a/src/main/java/ellpeck/actuallyadditions/blocks/metalists/TheColoredLampColors.java +++ b/src/main/java/ellpeck/actuallyadditions/blocks/metalists/TheColoredLampColors.java @@ -10,6 +10,8 @@ package ellpeck.actuallyadditions.blocks.metalists; +import ellpeck.actuallyadditions.util.StringUtil; + public enum TheColoredLampColors{ WHITE("White"), @@ -39,7 +41,7 @@ public enum TheColoredLampColors{ if(color.substring(0, 3).equals("dye")){ String actualName = color.substring(3); for(int i = 0; i < values().length; i++){ - if(values()[i].name.equals(actualName)){ + if(StringUtil.equalsToLowerCase(values()[i].name, actualName)){ return values()[i]; } } diff --git a/src/main/java/ellpeck/actuallyadditions/items/InitItems.java b/src/main/java/ellpeck/actuallyadditions/items/InitItems.java index e0fc3460d..2b06cbecb 100644 --- a/src/main/java/ellpeck/actuallyadditions/items/InitItems.java +++ b/src/main/java/ellpeck/actuallyadditions/items/InitItems.java @@ -128,10 +128,14 @@ public class InitItems{ public static Item itemChestToCrateUpgrade; public static Item itemLaserWrench; + public static Item itemCrystal; public static void init(){ ModUtil.LOGGER.info("Initializing Items..."); + itemCrystal = new ItemCrystal(); + ItemUtil.register(itemCrystal); + itemLaserWrench = new ItemLaserWrench(); ItemUtil.register(itemLaserWrench); diff --git a/src/main/java/ellpeck/actuallyadditions/items/ItemCrystal.java b/src/main/java/ellpeck/actuallyadditions/items/ItemCrystal.java new file mode 100644 index 000000000..3e766dd3c --- /dev/null +++ b/src/main/java/ellpeck/actuallyadditions/items/ItemCrystal.java @@ -0,0 +1,79 @@ +/* + * This file ("ItemCrystal.java") is part of the Actually Additions Mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015 Ellpeck + */ + +package ellpeck.actuallyadditions.items; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import ellpeck.actuallyadditions.blocks.BlockCrystal; +import ellpeck.actuallyadditions.util.IActAddItemOrBlock; +import ellpeck.actuallyadditions.util.ModUtil; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; + +import java.util.List; + +public class ItemCrystal extends Item implements IActAddItemOrBlock{ + + public ItemCrystal(){ + this.setHasSubtypes(true); + this.setMaxDamage(0); + } + + @Override + public int getMetadata(int damage){ + return damage; + } + + @Override + public String getUnlocalizedName(ItemStack stack){ + return this.getUnlocalizedName()+(stack.getItemDamage() >= BlockCrystal.allCrystals.length ? " ERROR!" : BlockCrystal.allCrystals[stack.getItemDamage()].name); + } + + @Override + @SideOnly(Side.CLIENT) + public int getColorFromItemStack(ItemStack stack, int pass){ + return stack.getItemDamage() >= BlockCrystal.allCrystals.length ? super.getColorFromItemStack(stack, pass) : BlockCrystal.allCrystals[stack.getItemDamage()].color; + } + + @Override + public EnumRarity getRarity(ItemStack stack){ + return stack.getItemDamage() >= BlockCrystal.allCrystals.length ? EnumRarity.common : BlockCrystal.allCrystals[stack.getItemDamage()].rarity; + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(ItemStack stack, int pass){ + return this.itemIcon; + } + + @SuppressWarnings("all") + @SideOnly(Side.CLIENT) + public void getSubItems(Item item, CreativeTabs tab, List list){ + for(int j = 0; j < BlockCrystal.allCrystals.length; j++){ + list.add(new ItemStack(this, 1, j)); + } + } + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister iconReg){ + this.itemIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getName()); + } + + @Override + public String getName(){ + return "itemCrystal"; + } +} \ No newline at end of file diff --git a/src/main/java/ellpeck/actuallyadditions/items/metalists/TheCrystals.java b/src/main/java/ellpeck/actuallyadditions/items/metalists/TheCrystals.java new file mode 100644 index 000000000..443b55bf0 --- /dev/null +++ b/src/main/java/ellpeck/actuallyadditions/items/metalists/TheCrystals.java @@ -0,0 +1,31 @@ +/* + * This file ("TheCrystals.java") is part of the Actually Additions Mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015 Ellpeck + */ + +package ellpeck.actuallyadditions.items.metalists; + +import net.minecraft.item.EnumRarity; + +public enum TheCrystals{ + + REDSTONE("Red", EnumRarity.rare, 12595250), + LAPIS("Blue", EnumRarity.uncommon, 24983), + DIAMOND("LightBlue", EnumRarity.epic, 40140), + COAL("Black", EnumRarity.uncommon, 2500135); + + public final String name; + public final EnumRarity rarity; + public final int color; + + TheCrystals(String name, EnumRarity rarity, int color){ + this.name = name; + this.rarity = rarity; + this.color = color; + } +} \ No newline at end of file