ActuallyAdditions/src/main/java/ellpeck/actuallyadditions/blocks/BlockColoredLamp.java

164 lines
5.5 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
* This file ("BlockColoredLamp.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-11-02 20:55:19 +01:00
* © 2015 Ellpeck
2015-08-29 14:33:25 +02:00
*/
2015-06-28 21:28:58 +02:00
package ellpeck.actuallyadditions.blocks;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ellpeck.actuallyadditions.blocks.base.BlockBase;
import ellpeck.actuallyadditions.blocks.base.ItemBlockBase;
2015-06-28 21:28:58 +02:00
import ellpeck.actuallyadditions.blocks.metalists.TheColoredLampColors;
import ellpeck.actuallyadditions.util.ModUtil;
import ellpeck.actuallyadditions.util.StringUtil;
2015-06-28 21:28:58 +02:00
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.entity.player.EntityPlayer;
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 net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
import java.util.List;
import java.util.Random;
public class BlockColoredLamp extends BlockBase{
2015-06-28 21:28:58 +02:00
public static TheColoredLampColors[] allLampTypes = TheColoredLampColors.values();
public boolean isOn;
2015-10-28 14:46:04 +01:00
@SideOnly(Side.CLIENT)
private IIcon[] textures;
2015-06-28 21:28:58 +02:00
public BlockColoredLamp(boolean isOn, String name){
super(Material.redstoneLight, name);
2015-06-28 21:28:58 +02:00
this.setHarvestLevel("pickaxe", 0);
this.setHardness(0.5F);
this.setResistance(3.0F);
2015-06-28 21:28:58 +02:00
this.isOn = isOn;
}
@Override
public EnumRarity getRarity(ItemStack stack){
return EnumRarity.rare;
}
2015-10-03 10:19:40 +02:00
@Override
2015-10-28 14:46:04 +01:00
@SideOnly(Side.CLIENT)
2015-10-03 10:19:40 +02:00
public IIcon getIcon(int side, int meta){
return meta >= allLampTypes.length ? null : textures[meta];
}
@Override
public Item getItemDropped(int par1, Random rand, int par3){
return Item.getItemFromBlock(InitBlocks.blockColoredLamp);
}
@Override
public int damageDropped(int meta){
return meta;
2015-06-28 21:28:58 +02:00
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ){
//Turning On
if(player.isSneaking()){
if(!world.isRemote){
world.setBlock(x, y, z, this.isOn ? InitBlocks.blockColoredLamp : InitBlocks.blockColoredLampOn, world.getBlockMetadata(x, y, z), 2);
}
return true;
}
//Changing Colors
int[] oreIDs = OreDictionary.getOreIDs(player.getCurrentEquippedItem());
if(oreIDs.length > 0){
for(int oreID : oreIDs){
String name = OreDictionary.getOreName(oreID);
TheColoredLampColors color = TheColoredLampColors.getColorFromDyeName(name);
if(color != null){
if(world.getBlockMetadata(x, y, z) != color.ordinal()){
if(!world.isRemote){
world.setBlockMetadataWithNotify(x, y, z, color.ordinal(), 2);
2015-10-02 16:48:01 +02:00
if(!player.capabilities.isCreativeMode){
player.inventory.decrStackSize(player.inventory.currentItem, 1);
}
2015-06-28 21:28:58 +02:00
}
return true;
}
}
}
}
return false;
}
@Override
2015-10-03 10:19:40 +02:00
public ItemStack createStackedBlock(int meta){
return new ItemStack(InitBlocks.blockColoredLamp, 1, meta);
2015-06-28 21:28:58 +02:00
}
@Override
2015-10-03 10:19:40 +02:00
@SideOnly(Side.CLIENT)
public Item getItem(World world, int x, int y, int z){
return Item.getItemFromBlock(InitBlocks.blockColoredLamp);
2015-06-28 21:28:58 +02:00
}
@SuppressWarnings("all")
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item item, CreativeTabs tab, List list){
2015-10-02 16:48:01 +02:00
for(int j = 0; j < allLampTypes.length; j++){
2015-06-28 21:28:58 +02:00
list.add(new ItemStack(item, 1, j));
}
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconReg){
2015-10-28 14:46:04 +01:00
this.textures = new IIcon[allLampTypes.length];
2015-06-28 21:28:58 +02:00
for(int i = 0; i < allLampTypes.length; i++){
2015-12-03 22:53:05 +01:00
this.textures[i] = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getBaseName()+allLampTypes[i].name);
2015-06-28 21:28:58 +02:00
}
}
2015-10-03 10:19:40 +02:00
@Override
public int getLightValue(IBlockAccess world, int x, int y, int z){
return this.isOn ? 15 : 0;
}
@Override
public Class<? extends ItemBlockBase> getItemBlock(){
return TheItemBlock.class;
}
public static class TheItemBlock extends ItemBlockBase{
2015-06-28 21:28:58 +02:00
public TheItemBlock(Block block){
super(block);
this.setHasSubtypes(true);
this.setMaxDamage(0);
}
@Override
public String getItemStackDisplayName(ItemStack stack){
2015-10-03 10:16:18 +02:00
if(stack.getItemDamage() >= allLampTypes.length){
return null;
}
2015-10-08 17:37:09 +02:00
return StringUtil.localize(this.getUnlocalizedName(stack)+".name")+(((BlockColoredLamp)this.field_150939_a).isOn ? " ("+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".onSuffix.desc")+")" : "");
2015-06-28 21:28:58 +02:00
}
2015-10-03 10:19:40 +02:00
@Override
2015-10-28 14:46:04 +01:00
public String getUnlocalizedName(ItemStack stack){
return InitBlocks.blockColoredLamp.getUnlocalizedName()+allLampTypes[stack.getItemDamage()].name;
2015-10-03 10:19:40 +02:00
}
2015-06-28 21:28:58 +02:00
}
}