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
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 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 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;
|
2016-11-16 20:31:16 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
2017-07-28 03:17:50 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.Util;
|
2015-06-28 21:28:58 +02:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.material.Material;
|
2016-11-21 16:23:48 +01:00
|
|
|
import net.minecraft.block.properties.PropertyEnum;
|
2021-02-27 13:24:45 +01:00
|
|
|
import net.minecraft.block.state.BlockStateContainer;
|
2015-06-28 21:28:58 +02:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
2021-02-26 22:15:48 +01:00
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2015-06-28 21:28:58 +02:00
|
|
|
import net.minecraft.item.EnumRarity;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2021-02-27 13:24:45 +01:00
|
|
|
import net.minecraft.util.Direction;
|
2021-02-26 22:15:48 +01:00
|
|
|
import net.minecraft.util.Hand;
|
2016-11-19 21:11:17 +01:00
|
|
|
import net.minecraft.util.NonNullList;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2015-06-28 21:28:58 +02:00
|
|
|
import net.minecraft.world.IBlockAccess;
|
|
|
|
import net.minecraft.world.World;
|
2021-02-27 13:24:45 +01:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
2021-02-26 22:15:48 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.OnlyIn;
|
2015-06-28 21:28:58 +02:00
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
import java.util.Random;
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
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();
|
2017-07-28 03:17:50 +02:00
|
|
|
public static final PropertyEnum<TheColoredLampColors> TYPE = PropertyEnum.create("type", TheColoredLampColors.class);
|
2016-05-19 20:05:12 +02:00
|
|
|
public final boolean isOn;
|
2015-06-28 21:28:58 +02:00
|
|
|
|
2021-02-27 13:24:45 +01:00
|
|
|
public BlockColoredLamp(boolean isOn) {
|
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);
|
2015-07-07 01:13:39 +02:00
|
|
|
this.setResistance(3.0F);
|
2015-06-28 21:28:58 +02:00
|
|
|
this.isOn = isOn;
|
|
|
|
}
|
|
|
|
|
2015-10-03 10:19:40 +02:00
|
|
|
@Override
|
2021-02-26 22:15:48 +01:00
|
|
|
public Item getItemDropped(BlockState state, Random rand, int par3) {
|
2021-02-28 11:35:10 +01:00
|
|
|
return Item.getItemFromBlock(ActuallyBlocks.blockColoredLamp);
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-02-26 22:15:48 +01:00
|
|
|
public int damageDropped(BlockState state) {
|
2016-01-07 23:42:42 +01:00
|
|
|
return this.getMetaFromState(state);
|
2015-06-28 21:28:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-02-27 13:24:45 +01:00
|
|
|
public boolean onBlockActivated(World world, BlockPos pos, BlockState state, PlayerEntity player, Hand hand, Direction side, float hitX, float hitY, float hitZ) {
|
2016-11-19 21:11:17 +01:00
|
|
|
ItemStack stack = player.getHeldItem(hand);
|
2015-06-28 21:28:58 +02:00
|
|
|
//Turning On
|
2021-02-26 22:15:48 +01:00
|
|
|
if (hand == Hand.MAIN_HAND && stack.isEmpty()) {
|
|
|
|
world.setBlockState(pos, (this.isOn
|
2021-02-28 11:35:10 +01:00
|
|
|
? ActuallyBlocks.blockColoredLamp
|
|
|
|
: ActuallyBlocks.blockColoredLampOn).getDefaultState().withProperty(TYPE, state.getValue(TYPE)), 2);
|
2017-07-08 11:04:57 +02:00
|
|
|
world.notifyLightSet(pos);
|
2015-06-28 21:28:58 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (StackUtil.isValid(stack)) {
|
2016-01-08 21:55:39 +01:00
|
|
|
//Changing Colors
|
|
|
|
int[] oreIDs = OreDictionary.getOreIDs(stack);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (oreIDs.length > 0) {
|
|
|
|
for (int oreID : oreIDs) {
|
2016-01-08 21:55:39 +01:00
|
|
|
String name = OreDictionary.getOreName(oreID);
|
|
|
|
TheColoredLampColors color = TheColoredLampColors.getColorFromDyeName(name);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (color != null) {
|
|
|
|
if (this.getMetaFromState(state) != color.ordinal()) {
|
|
|
|
if (!world.isRemote) {
|
2016-07-04 20:15:41 +02:00
|
|
|
world.setBlockState(pos, this.getStateFromMeta(color.ordinal()), 2);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (!player.capabilities.isCreativeMode) {
|
2016-01-08 21:55:39 +01:00
|
|
|
player.inventory.decrStackSize(player.inventory.currentItem, 1);
|
|
|
|
}
|
2015-10-02 16:48:01 +02:00
|
|
|
}
|
2016-01-08 21:55:39 +01:00
|
|
|
return true;
|
2015-06-28 21:28:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-06-10 21:52:37 +02:00
|
|
|
@Override
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> list) {
|
|
|
|
for (int j = 0; j < ALL_LAMP_TYPES.length; j++) {
|
2017-06-17 00:48:49 +02:00
|
|
|
list.add(new ItemStack(this, 1, j));
|
2015-06-28 21:28:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-02-26 22:15:48 +01:00
|
|
|
public int getLightValue(BlockState state, IBlockAccess world, BlockPos pos) {
|
|
|
|
return this.isOn
|
|
|
|
? 15
|
|
|
|
: 0;
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
|
|
|
|
2016-02-01 20:32:49 +01:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
protected ItemBlockBase getItemBlock() {
|
2016-04-20 21:39:03 +02:00
|
|
|
return new TheItemBlock(this);
|
2016-02-01 20:32:49 +01:00
|
|
|
}
|
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public void registerRendering() {
|
|
|
|
for (int i = 0; i < ALL_LAMP_TYPES.length; i++) {
|
|
|
|
ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this, 1, i), this.getRegistryName(), TYPE.getName() + "=" + ALL_LAMP_TYPES[i].regName);
|
2016-02-01 17:49:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-19 10:30:39 +01:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public EnumRarity getRarity(ItemStack stack) {
|
2016-01-07 23:42:42 +01:00
|
|
|
return EnumRarity.RARE;
|
2015-12-19 10:30:39 +01:00
|
|
|
}
|
|
|
|
|
2016-01-08 20:51:03 +01:00
|
|
|
@Override
|
2021-02-26 22:15:48 +01:00
|
|
|
public BlockState getStateFromMeta(int meta) {
|
2016-11-21 16:23:48 +01:00
|
|
|
return this.getDefaultState().withProperty(TYPE, TheColoredLampColors.values()[meta]);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-02-26 22:15:48 +01:00
|
|
|
public int getMetaFromState(BlockState state) {
|
2016-11-21 16:23:48 +01:00
|
|
|
return state.getValue(TYPE).ordinal();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
protected BlockStateContainer createBlockState() {
|
2016-11-21 16:23:48 +01:00
|
|
|
return new BlockStateContainer(this, TYPE);
|
2016-01-08 20:51:03 +01:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public static class TheItemBlock extends ItemBlockBase {
|
2015-06-28 21:28:58 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public TheItemBlock(Block block) {
|
2015-06-28 21:28:58 +02:00
|
|
|
super(block);
|
|
|
|
this.setHasSubtypes(true);
|
|
|
|
this.setMaxDamage(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public String getItemStackDisplayName(ItemStack stack) {
|
2021-02-26 22:15:48 +01:00
|
|
|
if (stack.getItemDamage() >= ALL_LAMP_TYPES.length) {
|
|
|
|
return StringUtil.BUGGED_ITEM_NAME;
|
|
|
|
}
|
|
|
|
if (Util.isClient()) {
|
|
|
|
return super.getItemStackDisplayName(stack) + (((BlockColoredLamp) this.block).isOn
|
|
|
|
? " (" + StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".onSuffix.desc") + ")"
|
|
|
|
: "");
|
|
|
|
} else {
|
|
|
|
return super.getItemStackDisplayName(stack);
|
|
|
|
}
|
2015-06-28 21:28:58 +02:00
|
|
|
}
|
2015-10-03 10:19:40 +02:00
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public String getTranslationKey(ItemStack stack) {
|
2021-02-28 11:35:10 +01:00
|
|
|
return ActuallyBlocks.blockColoredLamp.getTranslationKey() + "_" + ALL_LAMP_TYPES[stack.getItemDamage()].regName;
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
2015-06-28 21:28:58 +02:00
|
|
|
}
|
2017-07-08 11:04:57 +02:00
|
|
|
}
|