/
ColumnBlock.java
157 lines (83 loc) · 3.33 KB
/
ColumnBlock.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package drmdgg.marijuanacraft.init.blocks.tileentities;
import javax.annotation.Nullable;
import drmdgg.marijuanacraft.init.ModTileEntityTypes;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import net.minecraftforge.fml.network.NetworkHooks;
import net.minecraftforge.items.ItemStackHandler;
public class ColumnBlock extends Block {
public static final BooleanProperty BURNING = BooleanProperty.create("burning");
public static final String ID = "column";
public ColumnBlock(final Properties properties) {
super(properties);
this.setDefaultState(this.getDefaultState().with(BURNING, false));
}
@Override
public boolean hasTileEntity(final BlockState state) {
return true;
}
public boolean isOpaqueCube(BlockState state)
{
return false;
}
public BlockRenderType getRenderLayer()
{
return BlockRenderType.MODEL;
}
@Nullable
@Override
public TileEntity createTileEntity(final BlockState state, final IBlockReader world) {
// Always use TileEntityType#create to allow registry overrides to work.
return ModTileEntityTypes.COLUMN.get().create();
}
/**
* Called on the logical server when a BlockState with a TileEntity is replaced by another BlockState
*
* @deprecated Call via {@link BlockState#onReplaced(World, BlockPos, BlockState, boolean)}
* Implementing/overriding is fine.
*/
@Override
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
if (state.getBlock() != newState.getBlock()) {
TileEntity tileEntity = worldIn.getTileEntity(pos);
if (tileEntity instanceof ColumnTileEntity) {
final ItemStackHandler inventory = ((ColumnTileEntity) tileEntity).inventory;
for (int slot = 0; slot < inventory.getSlots(); ++slot) {
InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), inventory.getStackInSlot(slot));
}
}
}
super.onReplaced(state, worldIn, pos, newState, isMoving);
}
/**
* @deprecated Call via {@link BlockState#onBlockActivated(World, PlayerEntity, Hand, BlockRayTraceResult)} whenever possible.
* Implementing/overriding is fine.
*/
@Override
public ActionResultType onBlockActivated(final BlockState state, final World worldIn, final BlockPos pos, final PlayerEntity player, final Hand handIn, final BlockRayTraceResult hit) {
if (!worldIn.isRemote) {
final TileEntity tileEntity = worldIn.getTileEntity(pos);
if (tileEntity instanceof ColumnTileEntity) {
NetworkHooks.openGui((ServerPlayerEntity) player, (ColumnTileEntity) tileEntity, pos);
}
}
return ActionResultType.PASS;
}
@Override
protected void fillStateContainer(final StateContainer.Builder<Block, BlockState> builder) {
super.fillStateContainer(builder.add(BURNING));
}
}