/
Drawbridge.java
74 lines (61 loc) · 2.25 KB
/
Drawbridge.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package slimeknights.tmechworks.blocks;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import net.minecraft.world.World;
import slimeknights.tmechworks.blocks.logic.DrawbridgeLogic;
import slimeknights.tmechworks.blocks.logic.DrawbridgeLogicBase;
import javax.annotation.Nonnull;
import java.util.Locale;
public class Drawbridge extends RedstoneMachine
{
public static final PropertyEnum<DrawbridgeType> TYPE = PropertyEnum.create("type", DrawbridgeType.class, DrawbridgeType.values());
public Drawbridge ()
{
super(Material.IRON);
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(TYPE, DrawbridgeType.NORMAL));
}
@Override public int getMetaFromState (IBlockState state)
{
return ((DrawbridgeType) state.getValue(TYPE)).ordinal();
}
@Override public IBlockState getStateFromMeta (int meta)
{
return getDefaultState().withProperty(TYPE, DrawbridgeType.values()[meta]);
}
@Override public TileEntity createNewTileEntity (@Nonnull World worldIn, int meta)
{
try
{
return DrawbridgeType.values()[meta].tileEntityClass.newInstance();
}
catch (InstantiationException | IllegalAccessException e)
{
e.printStackTrace();
}
return null;
}
@Nonnull @Override protected BlockStateContainer createBlockState ()
{
return new BlockStateContainer(this, FACING, TYPE);
}
public enum DrawbridgeType implements IStringSerializable
{
NORMAL(DrawbridgeLogic.class),
ADVANCED(DrawbridgeLogicBase.class),
EXTENDED(DrawbridgeLogicBase.class);
public final Class<? extends DrawbridgeLogicBase> tileEntityClass;
DrawbridgeType (Class<? extends DrawbridgeLogicBase> te)
{
tileEntityClass = te;
}
@Override public String getName ()
{
return this.toString().toLowerCase(Locale.US);
}
}
}