-
Notifications
You must be signed in to change notification settings - Fork 497
/
SchematicRail.java
77 lines (68 loc) · 3.26 KB
/
SchematicRail.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
75
76
77
/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com
* <p/>
* BuildCraft is distributed under the terms of the Minecraft Mod Public License 1.0, or MMPL. Please check the contents
* of the license located in http://www.mod-buildcraft.com/MMPL-1.0.txt */
package buildcraft.builders.schematics;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.properties.BuildCraftProperties;
import buildcraft.core.builders.schematics.SchematicBlockFloored;
import net.minecraft.block.BlockRail;
import net.minecraft.block.BlockRailBase;
import net.minecraft.block.BlockRailBase.EnumRailDirection;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import java.util.List;
public class SchematicRail extends SchematicBlockFloored {
private static final IBlockState defaultDirection = Blocks.rail.getDefaultState().withProperty(BlockRail.SHAPE, EnumRailDirection.NORTH_SOUTH);
@Override
public void rotateLeft(IBuilderContext context) {
EnumRailDirection direction = (EnumRailDirection) state.getValue(BlockRail.SHAPE);
state = state.withProperty(BlockRail.SHAPE, getRotatedDirection(direction));
}
@Override
public void placeInWorld(IBuilderContext context, BlockPos pos, List<ItemStack> stacks) {
// If we set it to NORTH_SOUTH here (and don't update) then when we set it to the actual state in the post
// processing it just ignores the update because they are the same
if (state == defaultDirection) context.world().setBlockState(pos, defaultDirection, BuildCraftProperties.MARK_BLOCK_FOR_UPDATE);
else context.world().setBlockState(pos, defaultDirection, BuildCraftProperties.UPDATE_NONE);
}
@Override
public boolean isAlreadyBuilt(IBuilderContext context, BlockPos pos) {
return state.getBlock() == context.world().getBlockState(pos).getBlock();
}
@Override
public void postProcessing(IBuilderContext context, BlockPos pos) {
context.world().setBlockState(pos, state);
}
public void setMetaData(BlockRailBase.EnumRailDirection newValue) {
state = state.withProperty(BlockRail.SHAPE, newValue);
}
private EnumRailDirection getRotatedDirection(EnumRailDirection old) {
switch (old) {
case ASCENDING_EAST:
return EnumRailDirection.ASCENDING_SOUTH;
case ASCENDING_NORTH:
return EnumRailDirection.ASCENDING_EAST;
case ASCENDING_SOUTH:
return EnumRailDirection.ASCENDING_WEST;
case ASCENDING_WEST:
return EnumRailDirection.ASCENDING_NORTH;
case EAST_WEST:
return EnumRailDirection.NORTH_SOUTH;
case NORTH_EAST:
return EnumRailDirection.SOUTH_EAST;
case NORTH_SOUTH:
return EnumRailDirection.EAST_WEST;
case NORTH_WEST:
return EnumRailDirection.NORTH_EAST;
case SOUTH_EAST:
return EnumRailDirection.SOUTH_WEST;
case SOUTH_WEST:
return EnumRailDirection.NORTH_WEST;
default:
return EnumRailDirection.NORTH_SOUTH;
}
}
}