2017-03-24 17:40:05 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Industrial Wires.
|
|
|
|
* Copyright (C) 2016-2017 malte0811
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package malte0811.industrialWires.blocks.controlpanel;
|
|
|
|
|
|
|
|
import blusunrize.immersiveengineering.api.IEProperties;
|
2017-04-09 16:59:57 +02:00
|
|
|
import malte0811.industrialWires.IndustrialWires;
|
2017-03-24 17:40:05 +01:00
|
|
|
import malte0811.industrialWires.blocks.BlockIWBase;
|
2017-03-28 18:15:41 +02:00
|
|
|
import malte0811.industrialWires.blocks.IMetaEnum;
|
2017-05-19 17:45:30 +02:00
|
|
|
import malte0811.industrialWires.controlpanel.PanelComponent;
|
2017-07-03 20:38:31 +02:00
|
|
|
import malte0811.industrialWires.controlpanel.PanelUtils;
|
2017-06-25 18:34:10 +02:00
|
|
|
import malte0811.industrialWires.controlpanel.PropertyComponents;
|
2017-03-24 17:40:05 +01:00
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.block.properties.IProperty;
|
2017-03-28 18:15:41 +02:00
|
|
|
import net.minecraft.block.properties.PropertyEnum;
|
2017-03-24 17:40:05 +01:00
|
|
|
import net.minecraft.block.state.BlockStateContainer;
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
2017-03-28 18:15:41 +02:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
2017-04-09 16:59:57 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2017-03-28 18:15:41 +02:00
|
|
|
import net.minecraft.item.Item;
|
2017-06-30 21:04:02 +02:00
|
|
|
import net.minecraft.item.ItemBlock;
|
2017-03-24 17:40:05 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2017-04-01 17:33:58 +02:00
|
|
|
import net.minecraft.util.BlockRenderLayer;
|
2017-04-09 16:59:57 +02:00
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import net.minecraft.util.EnumHand;
|
2017-05-10 17:56:05 +02:00
|
|
|
import net.minecraft.util.NonNullList;
|
2017-03-24 17:40:05 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2017-04-24 17:26:42 +02:00
|
|
|
import net.minecraft.util.math.RayTraceResult;
|
2017-03-24 17:40:05 +01:00
|
|
|
import net.minecraft.world.IBlockAccess;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.property.ExtendedBlockState;
|
|
|
|
import net.minecraftforge.common.property.IExtendedBlockState;
|
|
|
|
import net.minecraftforge.common.property.IUnlistedProperty;
|
|
|
|
|
2017-05-10 17:56:05 +02:00
|
|
|
import javax.annotation.Nonnull;
|
2017-07-03 20:38:31 +02:00
|
|
|
import java.util.List;
|
2017-03-28 18:15:41 +02:00
|
|
|
|
2017-04-02 17:16:42 +02:00
|
|
|
public class BlockPanel extends BlockIWBase implements IMetaEnum {
|
2017-03-28 18:15:41 +02:00
|
|
|
public static final PropertyEnum<BlockTypes_Panel> type = PropertyEnum.create("type", BlockTypes_Panel.class);
|
2017-05-11 16:39:20 +02:00
|
|
|
|
2017-03-24 17:40:05 +01:00
|
|
|
public BlockPanel() {
|
|
|
|
super(Material.IRON, "control_panel");
|
2017-04-01 17:33:58 +02:00
|
|
|
lightOpacity = 0;
|
|
|
|
}
|
|
|
|
|
2017-06-30 21:04:02 +02:00
|
|
|
@Override
|
|
|
|
protected ItemBlock createItemBlock() {
|
|
|
|
return new ItemBlockPanel(this);
|
|
|
|
}
|
|
|
|
|
2017-04-01 17:33:58 +02:00
|
|
|
@Override
|
|
|
|
public boolean canRenderInLayer(IBlockState state, BlockRenderLayer layer) {
|
|
|
|
switch (state.getValue(type)) {
|
|
|
|
case TOP:
|
2017-05-11 16:39:20 +02:00
|
|
|
return layer == BlockRenderLayer.CUTOUT;
|
2017-04-01 17:33:58 +02:00
|
|
|
case RS_WIRE:
|
2017-05-11 16:39:20 +02:00
|
|
|
return layer == BlockRenderLayer.TRANSLUCENT || layer == BlockRenderLayer.SOLID;
|
2017-04-17 19:35:14 +02:00
|
|
|
default:
|
|
|
|
return super.canRenderInLayer(state, layer);
|
2017-04-01 17:33:58 +02:00
|
|
|
}
|
2017-03-24 17:40:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-05-10 17:56:05 +02:00
|
|
|
public TileEntity createTileEntity(@Nonnull World world, @Nonnull IBlockState state) {
|
2017-05-11 16:39:20 +02:00
|
|
|
switch (state.getValue(type)) {
|
2017-03-28 18:15:41 +02:00
|
|
|
case TOP:
|
|
|
|
return new TileEntityPanel();
|
|
|
|
case RS_WIRE:
|
|
|
|
return new TileEntityRSPanelConn();
|
2017-04-10 16:20:39 +02:00
|
|
|
case CREATOR:
|
|
|
|
return new TileEntityPanelCreator();
|
2017-06-30 21:04:02 +02:00
|
|
|
case UNFINISHED:
|
|
|
|
return new TileEntityUnfinishedPanel();
|
2017-04-17 19:35:14 +02:00
|
|
|
default:
|
|
|
|
return null;
|
2017-03-28 18:15:41 +02:00
|
|
|
}
|
2017-03-24 17:40:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasTileEntity(IBlockState state) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-04-17 19:35:14 +02:00
|
|
|
protected IProperty<?>[] getProperties() {
|
2017-04-24 17:26:42 +02:00
|
|
|
return new IProperty[]{IEProperties.FACING_ALL, type};
|
2017-03-24 17:40:05 +01:00
|
|
|
}
|
|
|
|
|
2017-05-10 17:56:05 +02:00
|
|
|
@Nonnull
|
2017-03-24 17:40:05 +01:00
|
|
|
@Override
|
|
|
|
protected BlockStateContainer createBlockState() {
|
|
|
|
BlockStateContainer base = super.createBlockState();
|
|
|
|
return new ExtendedBlockState(this, base.getProperties().toArray(new IProperty[0]), new IUnlistedProperty[]{
|
2017-03-28 18:15:41 +02:00
|
|
|
PropertyComponents.INSTANCE, IEProperties.CONNECTIONS
|
2017-03-24 17:40:05 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-10 17:56:05 +02:00
|
|
|
@Nonnull
|
2017-03-28 18:15:41 +02:00
|
|
|
@Override
|
2017-05-10 17:56:05 +02:00
|
|
|
public IBlockState getActualState(@Nonnull IBlockState state, IBlockAccess worldIn, BlockPos pos) {
|
2017-03-28 18:15:41 +02:00
|
|
|
state = super.getActualState(state, worldIn, pos);
|
|
|
|
TileEntity te = worldIn.getTileEntity(pos);
|
|
|
|
if (te instanceof TileEntityPanel) {
|
|
|
|
state.withProperty(type, BlockTypes_Panel.TOP);
|
|
|
|
}
|
|
|
|
if (te instanceof TileEntityRSPanelConn) {
|
|
|
|
state.withProperty(type, BlockTypes_Panel.RS_WIRE);
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2017-05-10 17:56:05 +02:00
|
|
|
@Nonnull
|
2017-03-24 17:40:05 +01:00
|
|
|
@Override
|
2017-05-10 17:56:05 +02:00
|
|
|
public IBlockState getExtendedState(@Nonnull IBlockState state, IBlockAccess world, BlockPos pos) {
|
2017-03-24 17:40:05 +01:00
|
|
|
state = super.getExtendedState(state, world, pos);
|
|
|
|
if (state instanceof IExtendedBlockState) {
|
|
|
|
TileEntity te = world.getTileEntity(pos);
|
|
|
|
if (te instanceof TileEntityPanel) {
|
2017-04-01 17:33:58 +02:00
|
|
|
state = ((IExtendedBlockState) state).withProperty(PropertyComponents.INSTANCE, ((TileEntityPanel) te).getComponents());
|
2017-03-24 17:40:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMetaFromState(IBlockState state) {
|
2017-03-28 18:15:41 +02:00
|
|
|
return state.getValue(type).ordinal();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IBlockState getStateFromMeta(int meta) {
|
|
|
|
return super.getStateFromMeta(meta).withProperty(type, BlockTypes_Panel.values()[meta]);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object[] getValues() {
|
|
|
|
return BlockTypes_Panel.values();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-05-10 17:56:05 +02:00
|
|
|
public void getSubBlocks(@Nonnull Item itemIn, CreativeTabs tab, NonNullList<ItemStack> list) {
|
2017-06-30 21:04:02 +02:00
|
|
|
for (int i = 0; i < BlockTypes_Panel.values().length; i++) {
|
|
|
|
list.add(new ItemStack(itemIn, 1, i));
|
|
|
|
}
|
2017-04-01 17:33:58 +02:00
|
|
|
}
|
2017-05-11 16:39:20 +02:00
|
|
|
|
2017-04-01 17:33:58 +02:00
|
|
|
@Override
|
|
|
|
public boolean isFullBlock(IBlockState state) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-05-11 16:39:20 +02:00
|
|
|
|
2017-04-01 17:33:58 +02:00
|
|
|
@Override
|
|
|
|
public boolean isFullCube(IBlockState state) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-05-11 16:39:20 +02:00
|
|
|
|
2017-04-01 17:33:58 +02:00
|
|
|
@Override
|
|
|
|
public boolean isNormalCube(IBlockState state, IBlockAccess world, BlockPos pos) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-05-11 16:39:20 +02:00
|
|
|
|
2017-04-01 17:33:58 +02:00
|
|
|
@Override
|
|
|
|
public boolean isOpaqueCube(IBlockState state) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-04-09 16:59:57 +02:00
|
|
|
|
|
|
|
@Override
|
2017-05-10 17:56:05 +02:00
|
|
|
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
|
|
|
|
if (!super.onBlockActivated(world, pos, state, player, hand, side, hitX, hitY, hitZ) && hand == EnumHand.MAIN_HAND) {
|
2017-04-09 16:59:57 +02:00
|
|
|
TileEntity te = world.getTileEntity(pos);
|
2017-05-11 16:39:20 +02:00
|
|
|
if (te instanceof TileEntityRSPanelConn) {
|
2017-04-10 16:20:39 +02:00
|
|
|
if (!world.isRemote) {
|
2017-04-09 16:59:57 +02:00
|
|
|
player.openGui(IndustrialWires.instance, 0, te.getWorld(), te.getPos().getX(), te.getPos().getY(), te.getPos().getZ());
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2017-04-10 16:20:39 +02:00
|
|
|
if (te instanceof TileEntityPanelCreator) {
|
|
|
|
if (!world.isRemote) {
|
2017-04-20 20:44:08 +02:00
|
|
|
player.openGui(IndustrialWires.instance, 0, te.getWorld(), te.getPos().getX(), te.getPos().getY(), te.getPos().getZ());
|
2017-04-10 16:20:39 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2017-04-09 16:59:57 +02:00
|
|
|
return false;
|
|
|
|
}
|
2017-05-11 16:39:20 +02:00
|
|
|
return state.getValue(type) == BlockTypes_Panel.TOP;
|
2017-04-09 16:59:57 +02:00
|
|
|
}
|
2017-04-24 17:26:42 +02:00
|
|
|
|
|
|
|
@Override
|
2017-05-10 17:56:05 +02:00
|
|
|
@Nonnull
|
|
|
|
public ItemStack getPickBlock(@Nonnull IBlockState state, RayTraceResult target, @Nonnull World world, @Nonnull BlockPos pos, EntityPlayer player) {
|
2017-06-30 21:04:02 +02:00
|
|
|
TileEntity te = world.getTileEntity(pos);
|
|
|
|
if (te instanceof TileEntityPanel) {
|
|
|
|
return ((TileEntityPanel) te).getTileDrop(player, state);
|
2017-04-24 17:26:42 +02:00
|
|
|
}
|
|
|
|
return super.getPickBlock(state, target, world, pos, player);
|
|
|
|
}
|
2017-05-19 17:45:30 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void harvestBlock(@Nonnull World worldIn, EntityPlayer player, @Nonnull BlockPos pos, @Nonnull IBlockState state, TileEntity te, ItemStack stack) {
|
|
|
|
super.harvestBlock(worldIn, player, pos, state, te, stack);
|
|
|
|
if (te instanceof TileEntityPanel) {
|
|
|
|
for (PanelComponent pc:((TileEntityPanel) te).getComponents()) {
|
|
|
|
pc.dropItems((TileEntityPanel)te);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-03 20:38:31 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void breakBlock(@Nonnull World worldIn, @Nonnull BlockPos pos, @Nonnull IBlockState state) {
|
|
|
|
super.breakBlock(worldIn, pos, state);
|
|
|
|
//break connections
|
|
|
|
List<BlockPos> panels = PanelUtils.discoverPanelParts(worldIn, pos, 11 * 11 * 11);
|
|
|
|
for (BlockPos p : panels) {
|
|
|
|
if (!p.equals(pos)) {
|
|
|
|
TileEntity panelPart = worldIn.getTileEntity(p);
|
|
|
|
if (panelPart instanceof TileEntityPanel) {
|
|
|
|
((TileEntityPanel) panelPart).removeAllRSCons();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
|
|
|
|
super.onBlockAdded(worldIn, pos, state);
|
|
|
|
List<BlockPos> panels = PanelUtils.discoverPanelParts(worldIn, pos, 11 * 11 * 11);
|
|
|
|
for (BlockPos p : panels) {
|
|
|
|
if (!p.equals(pos)) {
|
|
|
|
TileEntity panelPart = worldIn.getTileEntity(p);
|
|
|
|
if (panelPart instanceof TileEntityPanel) {
|
|
|
|
((TileEntityPanel) panelPart).firstTick = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-24 17:40:05 +01:00
|
|
|
}
|