2017-02-26 13:56:36 +01:00
|
|
|
/*
|
2016-12-13 21:00:07 +01:00
|
|
|
* This file is part of Industrial Wires.
|
2017-02-26 13:56:36 +01:00
|
|
|
* Copyright (C) 2016-2017 malte0811
|
2016-12-13 21:00:07 +01:00
|
|
|
*
|
|
|
|
* Industrial Wires is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Industrial Wires is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
|
2017-02-26 13:56:36 +01:00
|
|
|
*/
|
2016-12-13 21:00:07 +01:00
|
|
|
package malte0811.industrialWires.blocks;
|
|
|
|
|
2017-02-26 13:56:36 +01:00
|
|
|
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces;
|
2016-12-13 21:00:07 +01:00
|
|
|
import net.minecraft.block.Block;
|
2017-02-26 13:56:36 +01:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2016-12-13 21:00:07 +01:00
|
|
|
import net.minecraft.item.ItemBlock;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2017-02-26 13:56:36 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.World;
|
2016-12-13 21:00:07 +01:00
|
|
|
|
2017-05-10 17:56:05 +02:00
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
|
2016-12-13 21:00:07 +01:00
|
|
|
public class ItemBlockIW extends ItemBlock {
|
2017-03-24 17:40:05 +01:00
|
|
|
private final Object[] values;
|
2016-12-13 21:00:07 +01:00
|
|
|
public ItemBlockIW(Block b) {
|
|
|
|
super(b);
|
2017-03-24 17:40:05 +01:00
|
|
|
if (b instanceof IMetaEnum) {
|
|
|
|
values = ((IMetaEnum)b).getValues();
|
|
|
|
} else {
|
|
|
|
values = null;
|
|
|
|
}
|
2016-12-13 21:00:07 +01:00
|
|
|
hasSubtypes = true;
|
|
|
|
}
|
2017-05-10 17:56:05 +02:00
|
|
|
|
|
|
|
@Nonnull
|
2016-12-13 21:00:07 +01:00
|
|
|
@Override
|
|
|
|
public String getUnlocalizedName(ItemStack stack) {
|
|
|
|
int meta = stack.getMetadata();
|
2017-03-24 17:40:05 +01:00
|
|
|
if (values!=null) {
|
|
|
|
return block.getUnlocalizedName() + "." + values[meta].toString().toLowerCase();
|
|
|
|
} else {
|
|
|
|
return block.getUnlocalizedName();
|
|
|
|
}
|
2016-12-13 21:00:07 +01:00
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public int getMetadata(int damage) {
|
|
|
|
return damage;
|
|
|
|
}
|
2017-03-03 19:04:08 +01:00
|
|
|
|
|
|
|
@Override
|
2017-05-10 17:56:05 +02:00
|
|
|
public boolean placeBlockAt(@Nonnull ItemStack stack, @Nonnull EntityPlayer player, World world, @Nonnull BlockPos pos,
|
|
|
|
EnumFacing side, float hitX, float hitY, float hitZ, @Nonnull IBlockState newState) {
|
2017-03-03 19:04:08 +01:00
|
|
|
if (block instanceof IPlacementCheck&&!((IPlacementCheck) block).canPlaceBlockAt(world, pos, stack)) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-28 18:15:41 +02:00
|
|
|
boolean ret = super.placeBlockAt(stack, player, world, pos, side, hitX, hitY, hitZ, newState);
|
|
|
|
if (ret) {
|
|
|
|
TileEntity te = world.getTileEntity(pos);
|
|
|
|
if (te instanceof IEBlockInterfaces.IDirectionalTile) {
|
|
|
|
EnumFacing dir = ((IEBlockInterfaces.IDirectionalTile) te).getFacingForPlacement(player, pos, side, hitX, hitY, hitZ);
|
|
|
|
((IEBlockInterfaces.IDirectionalTile) te).setFacing(dir);
|
|
|
|
}
|
2017-04-09 16:59:57 +02:00
|
|
|
if (te instanceof IEBlockInterfaces.ITileDrop) {
|
|
|
|
((IEBlockInterfaces.ITileDrop) te).readOnPlacement(player, stack);
|
|
|
|
}
|
2017-04-17 19:35:14 +02:00
|
|
|
if (te instanceof IHasDummyBlocksIW) {
|
|
|
|
((IHasDummyBlocksIW) te).placeDummies(world.getBlockState(pos));
|
|
|
|
}
|
2017-03-28 18:15:41 +02:00
|
|
|
}
|
|
|
|
return ret;
|
2017-03-03 19:04:08 +01:00
|
|
|
}
|
2016-12-13 21:00:07 +01:00
|
|
|
}
|