2017-02-28 17:32:40 +01:00
|
|
|
/*
|
2016-12-13 21:00:07 +01:00
|
|
|
* This file is part of Industrial Wires.
|
2017-02-28 17:32:40 +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-28 17:32:40 +01:00
|
|
|
*/
|
2016-12-13 21:00:07 +01:00
|
|
|
package malte0811.industrialWires.blocks.converter;
|
|
|
|
|
|
|
|
import blusunrize.immersiveengineering.api.IEProperties;
|
2017-07-09 18:10:06 +02:00
|
|
|
import malte0811.industrialWires.IndustrialWires;
|
2017-03-21 18:12:09 +01:00
|
|
|
import malte0811.industrialWires.blocks.BlockIWBase;
|
2016-12-13 21:00:07 +01:00
|
|
|
import malte0811.industrialWires.blocks.IMetaEnum;
|
|
|
|
import net.minecraft.block.material.Material;
|
2017-03-21 18:12:09 +01:00
|
|
|
import net.minecraft.block.properties.IProperty;
|
2016-12-13 21:00:07 +01:00
|
|
|
import net.minecraft.block.properties.PropertyEnum;
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
2017-05-10 17:56:05 +02:00
|
|
|
import net.minecraft.util.EnumHand;
|
|
|
|
import net.minecraft.util.NonNullList;
|
2016-12-13 21:00:07 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.RayTraceResult;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
2017-05-10 17:56:05 +02:00
|
|
|
import javax.annotation.Nonnull;
|
2017-03-07 16:51:47 +01:00
|
|
|
|
2017-03-21 18:12:09 +01:00
|
|
|
public class BlockMechanicalConverter extends BlockIWBase implements IMetaEnum {
|
|
|
|
private static PropertyEnum<MechanicalBlockType> type = PropertyEnum.create("type", MechanicalBlockType.class);
|
2017-05-11 16:39:20 +02:00
|
|
|
|
2016-12-13 21:00:07 +01:00
|
|
|
public BlockMechanicalConverter() {
|
2017-03-21 18:12:09 +01:00
|
|
|
super(Material.IRON, "mechanical_converter");
|
2016-12-13 21:00:07 +01:00
|
|
|
}
|
2016-12-15 21:32:28 +01:00
|
|
|
|
2016-12-13 21:00:07 +01:00
|
|
|
@Override
|
2017-07-09 18:10:06 +02:00
|
|
|
public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> list) {
|
|
|
|
if (tab== IndustrialWires.creativeTab) {
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
list.add(new ItemStack(this, 1, i));
|
|
|
|
}
|
2016-12-13 21:00:07 +01:00
|
|
|
}
|
|
|
|
}
|
2016-12-15 21:32:28 +01:00
|
|
|
|
2016-12-13 21:00:07 +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};
|
2016-12-13 21:00:07 +01:00
|
|
|
}
|
2017-03-07 16:51:47 +01:00
|
|
|
|
2017-05-10 17:56:05 +02:00
|
|
|
@Nonnull
|
2016-12-13 21:00:07 +01:00
|
|
|
@Override
|
|
|
|
public IBlockState getStateFromMeta(int meta) {
|
|
|
|
return getDefaultState().withProperty(type, MechanicalBlockType.values[meta]);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object[] getValues() {
|
|
|
|
return MechanicalBlockType.values;
|
|
|
|
}
|
|
|
|
|
|
|
|
@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 IE_MOTOR:
|
2016-12-13 21:00:07 +01:00
|
|
|
return new TileEntityIEMotor();
|
|
|
|
case IE_TO_IC2:
|
|
|
|
return new TileEntityMechIEtoIC();
|
|
|
|
case IC2_TO_IE:
|
|
|
|
return new TileEntityMechICtoIE();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2017-03-28 18:15:41 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasTileEntity(IBlockState state) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-12-13 21:00:07 +01:00
|
|
|
@Override
|
|
|
|
public int getMetaFromState(IBlockState state) {
|
|
|
|
return state.getValue(type).ordinal();
|
|
|
|
}
|
2017-05-11 16:39:20 +02:00
|
|
|
|
2016-12-13 21:00:07 +01:00
|
|
|
@Override
|
2017-05-10 17:56:05 +02:00
|
|
|
@Nonnull
|
|
|
|
public IBlockState getStateForPlacement(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing facing, float hitX, float hitY,
|
|
|
|
float hitZ, int meta, @Nonnull EntityLivingBase placer, EnumHand h) {
|
|
|
|
IBlockState base = super.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, meta, placer, h);
|
2017-03-28 18:15:41 +02:00
|
|
|
return base.withProperty(type, MechanicalBlockType.values[meta]);
|
2016-12-13 21:00:07 +01:00
|
|
|
}
|
2017-05-10 17:56:05 +02:00
|
|
|
|
2016-12-13 21:00:07 +01:00
|
|
|
@Override
|
|
|
|
public int damageDropped(IBlockState state) {
|
|
|
|
return state.getValue(type).ordinal();
|
|
|
|
}
|
2017-05-10 17:56:05 +02:00
|
|
|
|
|
|
|
@Nonnull
|
2016-12-13 21:00:07 +01:00
|
|
|
@Override
|
2017-05-10 17:56:05 +02:00
|
|
|
public ItemStack getPickBlock(@Nonnull IBlockState state, RayTraceResult target, @Nonnull World world, @Nonnull BlockPos pos,
|
|
|
|
EntityPlayer player) {
|
2016-12-13 21:00:07 +01:00
|
|
|
return new ItemStack(this, 1, damageDropped(state));
|
|
|
|
}
|
2017-05-11 16:39:20 +02:00
|
|
|
|
2016-12-19 18:16:46 +01:00
|
|
|
@Override
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
public boolean eventReceived(IBlockState state, World worldIn, BlockPos pos, int id, int param) {
|
|
|
|
boolean def = super.eventReceived(state, worldIn, pos, id, param);
|
2017-05-11 16:39:20 +02:00
|
|
|
if ((id & 255) == 255) {
|
2016-12-19 18:16:46 +01:00
|
|
|
IBlockState s = worldIn.getBlockState(pos);
|
|
|
|
worldIn.notifyBlockUpdate(pos, s, s, 3);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return def;
|
|
|
|
}
|
2016-12-13 21:00:07 +01:00
|
|
|
}
|