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

164 lines
5.7 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
2016-05-16 22:52:27 +02:00
* This file ("BlockColoredLamp.java") is part of the Actually Additions mod for Minecraft.
2015-08-29 14:33:25 +02:00
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
2015-08-29 14:33:25 +02:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2016-05-16 22:54:42 +02:00
* © 2015-2016 Ellpeck
2015-08-29 14:33:25 +02:00
*/
2016-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod.blocks;
2015-06-28 21:28:58 +02:00
2016-01-08 13:31:58 +01:00
2016-01-08 20:51:03 +01:00
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockBase;
import de.ellpeck.actuallyadditions.mod.blocks.base.ItemBlockBase;
import de.ellpeck.actuallyadditions.mod.blocks.metalists.TheColoredLampColors;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
2016-01-08 13:31:58 +01:00
import de.ellpeck.actuallyadditions.mod.util.PosUtil;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
2015-06-28 21:28:58 +02:00
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.IBlockState;
2015-06-28 21:28:58 +02:00
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.EnumFacing;
2016-03-18 23:47:22 +01:00
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
2015-06-28 21:28:58 +02:00
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
2016-01-07 18:20:59 +01:00
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2015-06-28 21:28:58 +02:00
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
2016-06-17 23:50:38 +02:00
public static final TheColoredLampColors[] ALL_LAMP_TYPES = TheColoredLampColors.values();
private static final PropertyInteger META = PropertyInteger.create("meta", 0, ALL_LAMP_TYPES.length-1);
2016-05-19 20:05:12 +02:00
public final boolean isOn;
2015-06-28 21:28:58 +02:00
public BlockColoredLamp(boolean isOn, String name){
2016-04-20 21:39:03 +02:00
super(Material.REDSTONE_LIGHT, 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;
}
2015-10-03 10:19:40 +02:00
@Override
public Item getItemDropped(IBlockState state, Random rand, int par3){
2015-10-03 10:19:40 +02:00
return Item.getItemFromBlock(InitBlocks.blockColoredLamp);
}
@Override
public int damageDropped(IBlockState state){
return this.getMetaFromState(state);
2015-06-28 21:28:58 +02:00
}
@Override
2016-03-18 23:47:22 +01:00
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack stack, EnumFacing side, float hitX, float hitY, float hitZ){
2015-06-28 21:28:58 +02:00
//Turning On
if(player.isSneaking()){
if(!world.isRemote){
2016-03-18 15:42:06 +01:00
PosUtil.setBlock(pos, world, this.isOn ? InitBlocks.blockColoredLamp : InitBlocks.blockColoredLampOn, PosUtil.getMetadata(state), 2);
2015-06-28 21:28:58 +02:00
}
return true;
}
if(stack != null){
//Changing Colors
int[] oreIDs = OreDictionary.getOreIDs(stack);
if(oreIDs.length > 0){
for(int oreID : oreIDs){
String name = OreDictionary.getOreName(oreID);
TheColoredLampColors color = TheColoredLampColors.getColorFromDyeName(name);
if(color != null){
2016-03-18 15:42:06 +01:00
if(PosUtil.getMetadata(state) != color.ordinal()){
if(!world.isRemote){
PosUtil.setMetadata(pos, world, color.ordinal(), 2);
if(!player.capabilities.isCreativeMode){
player.inventory.decrStackSize(player.inventory.currentItem, 1);
}
2015-10-02 16:48:01 +02:00
}
return true;
2015-06-28 21:28:58 +02:00
}
}
}
}
}
return false;
}
@Override
public ItemStack createStackedBlock(IBlockState state){
return new ItemStack(InitBlocks.blockColoredLamp, 1, this.getMetaFromState(state));
2015-06-28 21:28:58 +02:00
}
@Override
2015-06-28 21:28:58 +02:00
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item item, CreativeTabs tab, List list){
2016-06-17 23:50:38 +02:00
for(int j = 0; j < ALL_LAMP_TYPES.length; j++){
2015-06-28 21:28:58 +02:00
list.add(new ItemStack(item, 1, j));
}
}
@Override
public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos){
2015-10-03 10:19:40 +02:00
return this.isOn ? 15 : 0;
}
@Override
2016-04-20 21:39:03 +02:00
protected ItemBlockBase getItemBlock(){
return new TheItemBlock(this);
}
2016-02-01 17:49:55 +01:00
@Override
protected void registerRendering(){
2016-06-17 23:50:38 +02:00
for(int i = 0; i < ALL_LAMP_TYPES.length; i++){
ActuallyAdditions.proxy.addRenderRegister(new ItemStack(this, 1, i), this.getRegistryName(), META.getName()+"="+i);
2016-02-01 17:49:55 +01:00
}
}
2015-12-19 10:30:39 +01:00
@Override
public EnumRarity getRarity(ItemStack stack){
return EnumRarity.RARE;
2015-12-19 10:30:39 +01:00
}
2016-01-08 20:51:03 +01:00
@Override
2016-02-01 17:49:55 +01:00
protected PropertyInteger getMetaProperty(){
return META;
2016-01-08 20:51:03 +01:00
}
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);
}
2015-06-28 21:28:58 +02:00
@Override
public String getItemStackDisplayName(ItemStack stack){
2016-06-17 23:50:38 +02:00
if(stack.getItemDamage() >= ALL_LAMP_TYPES.length){
2016-05-19 20:05:12 +02:00
return StringUtil.BUGGED_ITEM_NAME;
2015-10-03 10:16:18 +02:00
}
2016-04-20 21:39:03 +02:00
return StringUtil.localize(this.getUnlocalizedName(stack)+".name")+(((BlockColoredLamp)this.block).isOn ? " ("+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".onSuffix.desc")+")" : "");
2015-06-28 21:28:58 +02:00
}
2015-10-03 10:19:40 +02:00
2015-10-03 10:19:40 +02:00
@Override
2015-10-28 14:46:04 +01:00
public String getUnlocalizedName(ItemStack stack){
2016-06-17 23:50:38 +02:00
return InitBlocks.blockColoredLamp.getUnlocalizedName()+ALL_LAMP_TYPES[stack.getItemDamage()].name;
2015-10-03 10:19:40 +02:00
}
2015-06-28 21:28:58 +02:00
}
}