2017-03-21 18:12:09 +01:00
|
|
|
/*
|
2016-09-29 16:19:16 +02:00
|
|
|
* This file is part of Industrial Wires.
|
2017-03-21 18:12:09 +01:00
|
|
|
* Copyright (C) 2016-2017 malte0811
|
2016-09-29 16:19:16 +02: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-03-21 18:12:09 +01:00
|
|
|
*/
|
2016-12-08 17:52:34 +01:00
|
|
|
package malte0811.industrialWires.blocks.wire;
|
2016-09-15 20:43:18 +02:00
|
|
|
|
|
|
|
import blusunrize.immersiveengineering.api.IEProperties;
|
|
|
|
import malte0811.industrialWires.IndustrialWires;
|
2017-03-21 18:12:09 +01:00
|
|
|
import malte0811.industrialWires.blocks.BlockIWBase;
|
2016-12-08 17:52:34 +01:00
|
|
|
import malte0811.industrialWires.blocks.IMetaEnum;
|
2017-05-11 16:39:20 +02:00
|
|
|
import malte0811.industrialWires.wires.IC2Wiretype;
|
2016-09-15 20:43:18 +02:00
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.block.properties.IProperty;
|
|
|
|
import net.minecraft.block.properties.PropertyEnum;
|
|
|
|
import net.minecraft.block.state.BlockStateContainer;
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
2017-05-11 16:39:20 +02:00
|
|
|
import net.minecraft.client.resources.I18n;
|
2017-07-09 18:10:06 +02:00
|
|
|
import net.minecraft.client.util.ITooltipFlag;
|
2017-03-21 18:12:09 +01:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2016-09-15 20:43:18 +02:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.BlockRenderLayer;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
2017-05-10 17:56:05 +02:00
|
|
|
import net.minecraft.util.NonNullList;
|
2016-09-15 20:43:18 +02:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.IBlockAccess;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.property.ExtendedBlockState;
|
|
|
|
import net.minecraftforge.common.property.IUnlistedProperty;
|
|
|
|
|
2017-05-10 17:56:05 +02:00
|
|
|
import javax.annotation.Nonnull;
|
2017-07-09 18:10:06 +02:00
|
|
|
import javax.annotation.Nullable;
|
2017-04-04 17:07:45 +02:00
|
|
|
import java.util.Arrays;
|
2017-05-11 16:39:20 +02:00
|
|
|
import java.util.List;
|
2017-04-04 17:07:45 +02:00
|
|
|
|
2017-03-21 18:12:09 +01:00
|
|
|
public class BlockIC2Connector extends BlockIWBase implements IMetaEnum {
|
2017-08-23 22:30:24 +02:00
|
|
|
private static final PropertyEnum<BlockTypes_IC2_Connector> type = PropertyEnum.create("type", BlockTypes_IC2_Connector.class);
|
|
|
|
public static final String NAME = "ic2_connector";
|
2017-05-11 16:39:20 +02:00
|
|
|
|
2016-09-15 20:43:18 +02:00
|
|
|
public BlockIC2Connector() {
|
2017-08-23 22:30:24 +02:00
|
|
|
super(Material.IRON, NAME);
|
2016-09-15 20:43:18 +02:00
|
|
|
setHardness(3.0F);
|
|
|
|
setResistance(15.0F);
|
|
|
|
lightOpacity = 0;
|
|
|
|
}
|
2017-05-10 17:56:05 +02:00
|
|
|
|
2016-09-15 20:43:18 +02:00
|
|
|
@Override
|
2017-05-10 17:56:05 +02:00
|
|
|
public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos posNeighbor) {
|
2016-09-15 20:43:18 +02:00
|
|
|
TileEntity te = world.getTileEntity(pos);
|
2017-05-11 16:39:20 +02:00
|
|
|
if (te instanceof TileEntityIC2ConnectorTin) {
|
2016-09-15 20:43:18 +02:00
|
|
|
TileEntityIC2ConnectorTin connector = (TileEntityIC2ConnectorTin) te;
|
2017-08-22 18:33:05 +02:00
|
|
|
if (world.isAirBlock(pos.offset(connector.facing))) {
|
2016-09-15 20:43:18 +02:00
|
|
|
this.dropBlockAsItem(connector.getWorld(), pos, world.getBlockState(pos), 0);
|
|
|
|
connector.getWorld().setBlockToAir(pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-21 18:12:09 +01:00
|
|
|
|
|
|
|
@Override
|
2017-07-09 18:10:06 +02:00
|
|
|
public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> list) {
|
2017-07-10 20:30:18 +02:00
|
|
|
for (int i = 0; i < type.getAllowedValues().size(); i++) {
|
|
|
|
list.add(new ItemStack(this, 1, i));
|
2017-03-21 18:12:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-10 17:56:05 +02:00
|
|
|
@Nonnull
|
2016-09-15 20:43:18 +02:00
|
|
|
@Override
|
|
|
|
protected BlockStateContainer createBlockState() {
|
|
|
|
BlockStateContainer base = super.createBlockState();
|
|
|
|
IUnlistedProperty<?>[] unlisted = (base instanceof ExtendedBlockState) ? ((ExtendedBlockState) base).getUnlistedProperties().toArray(new IUnlistedProperty[0]) : new IUnlistedProperty[0];
|
2017-05-11 16:39:20 +02:00
|
|
|
unlisted = Arrays.copyOf(unlisted, unlisted.length + 1);
|
|
|
|
unlisted[unlisted.length - 1] = IEProperties.CONNECTIONS;
|
2016-09-15 20:43:18 +02:00
|
|
|
return new ExtendedBlockState(this, base.getProperties().toArray(new IProperty[0]), unlisted);
|
|
|
|
}
|
2017-03-21 18:12:09 +01:00
|
|
|
|
|
|
|
@Override
|
2017-04-17 19:35:14 +02:00
|
|
|
protected IProperty<?>[] getProperties() {
|
2017-03-21 18:12:09 +01:00
|
|
|
return new IProperty[]{type, IEProperties.FACING_ALL};
|
|
|
|
}
|
|
|
|
|
2017-05-10 17:56:05 +02:00
|
|
|
@Nonnull
|
2017-03-21 18:12:09 +01:00
|
|
|
@Override
|
2017-05-10 17:56:05 +02:00
|
|
|
public IBlockState getActualState(@Nonnull IBlockState state, IBlockAccess worldIn, BlockPos pos) {
|
2017-03-21 18:12:09 +01:00
|
|
|
state = super.getActualState(state, worldIn, pos);
|
|
|
|
TileEntity te = worldIn.getTileEntity(pos);
|
|
|
|
if (te instanceof TileEntityIC2ConnectorTin) {
|
|
|
|
state.withProperty(IEProperties.FACING_ALL, ((TileEntityIC2ConnectorTin) te).getFacing());
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2017-05-10 17:56:05 +02:00
|
|
|
@Nonnull
|
2017-03-21 18:12:09 +01:00
|
|
|
@Override
|
|
|
|
public IBlockState getStateFromMeta(int meta) {
|
|
|
|
return super.getStateFromMeta(meta).withProperty(type, BlockTypes_IC2_Connector.values()[meta]);
|
|
|
|
}
|
|
|
|
|
2016-09-15 20:43:18 +02:00
|
|
|
@Override
|
2017-05-10 17:56:05 +02:00
|
|
|
public boolean isSideSolid(IBlockState state, @Nonnull IBlockAccess world, @Nonnull BlockPos pos, EnumFacing side) {
|
2016-09-15 20:43:18 +02:00
|
|
|
return false;
|
|
|
|
}
|
2017-03-21 18:12:09 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasTileEntity(IBlockState state) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-15 20:43:18 +02:00
|
|
|
@Override
|
2017-05-10 17:56:05 +02:00
|
|
|
public TileEntity createTileEntity(@Nonnull World world, @Nonnull IBlockState state) {
|
2017-03-21 18:12:09 +01:00
|
|
|
switch (state.getValue(type)) {
|
|
|
|
case TIN_CONN:
|
2016-09-15 20:43:18 +02:00
|
|
|
return new TileEntityIC2ConnectorTin(false);
|
2017-03-21 18:12:09 +01:00
|
|
|
case TIN_RELAY:
|
2016-09-15 20:43:18 +02:00
|
|
|
return new TileEntityIC2ConnectorTin(true);
|
2017-03-21 18:12:09 +01:00
|
|
|
case COPPER_CONN:
|
2016-09-15 20:43:18 +02:00
|
|
|
return new TileEntityIC2ConnectorCopper(false);
|
2017-03-21 18:12:09 +01:00
|
|
|
case COPPER_RELAY:
|
2016-09-15 20:43:18 +02:00
|
|
|
return new TileEntityIC2ConnectorCopper(true);
|
2017-03-21 18:12:09 +01:00
|
|
|
case GOLD_CONN:
|
2016-09-15 20:43:18 +02:00
|
|
|
return new TileEntityIC2ConnectorGold(false);
|
2017-03-21 18:12:09 +01:00
|
|
|
case GOLD_RELAY:
|
2016-09-15 20:43:18 +02:00
|
|
|
return new TileEntityIC2ConnectorGold(true);
|
2017-03-21 18:12:09 +01:00
|
|
|
case HV_CONN:
|
2016-09-15 20:43:18 +02:00
|
|
|
return new TileEntityIC2ConnectorHV(false);
|
2017-03-21 18:12:09 +01:00
|
|
|
case HV_RELAY:
|
2016-09-15 20:43:18 +02:00
|
|
|
return new TileEntityIC2ConnectorHV(true);
|
2017-03-21 18:12:09 +01:00
|
|
|
case GLASS_CONN:
|
2016-09-22 19:52:01 +02:00
|
|
|
return new TileEntityIC2ConnectorGlass(false);
|
2017-03-21 18:12:09 +01:00
|
|
|
case GLASS_RELAY:
|
2016-09-22 19:52:01 +02:00
|
|
|
return new TileEntityIC2ConnectorGlass(true);
|
2017-03-21 18:12:09 +01:00
|
|
|
}
|
2016-09-15 20:43:18 +02:00
|
|
|
return null;
|
|
|
|
}
|
2017-05-11 16:39:20 +02:00
|
|
|
|
|
|
|
@Override
|
2017-07-09 18:10:06 +02:00
|
|
|
public void addInformation(ItemStack stack, @Nullable World world, List<String> tooltip, ITooltipFlag advanced) {
|
|
|
|
super.addInformation(stack, world, tooltip, advanced);
|
2017-05-11 16:39:20 +02:00
|
|
|
if (!stack.isEmpty() && stack.getMetadata() % 2 == 0) {
|
|
|
|
int type = stack.getMetadata() / 2;
|
|
|
|
tooltip.add(I18n.format(IndustrialWires.MODID + ".tooltip.power_tier", type + 1));
|
|
|
|
tooltip.add(I18n.format(IndustrialWires.MODID + ".tooltip.eu_per_tick", IC2Wiretype.IC2_TYPES[type].getTransferRate() / 8));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-15 20:43:18 +02:00
|
|
|
@Override
|
2017-05-10 17:56:05 +02:00
|
|
|
public boolean canRenderInLayer(IBlockState state, BlockRenderLayer layer) {
|
2017-05-11 16:39:20 +02:00
|
|
|
return layer == BlockRenderLayer.TRANSLUCENT || layer == BlockRenderLayer.SOLID;
|
2016-10-28 08:26:20 +02:00
|
|
|
}
|
2017-05-11 16:39:20 +02:00
|
|
|
|
2016-10-28 08:26:20 +02:00
|
|
|
@Override
|
|
|
|
public boolean isFullBlock(IBlockState state) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-05-11 16:39:20 +02:00
|
|
|
|
2016-10-28 08:26:20 +02:00
|
|
|
@Override
|
|
|
|
public boolean isFullCube(IBlockState state) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-05-11 16:39:20 +02:00
|
|
|
|
2016-10-28 08:26:20 +02:00
|
|
|
@Override
|
|
|
|
public boolean isNormalCube(IBlockState state, IBlockAccess world, BlockPos pos) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-05-11 16:39:20 +02:00
|
|
|
|
2016-10-28 08:26:20 +02:00
|
|
|
@Override
|
|
|
|
public boolean isOpaqueCube(IBlockState state) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-05-10 17:56:05 +02:00
|
|
|
|
|
|
|
/*@Override
|
2016-10-28 08:26:20 +02:00
|
|
|
public boolean isVisuallyOpaque() {
|
|
|
|
return false;
|
2017-05-10 17:56:05 +02:00
|
|
|
}*/
|
2016-12-08 17:52:34 +01:00
|
|
|
@Override
|
|
|
|
public Object[] getValues() {
|
2017-03-21 18:12:09 +01:00
|
|
|
return BlockTypes_IC2_Connector.values();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMetaFromState(IBlockState state) {
|
|
|
|
return state.getValue(type).ordinal();
|
2016-12-08 17:52:34 +01:00
|
|
|
}
|
2016-09-15 20:43:18 +02:00
|
|
|
}
|