-
Notifications
You must be signed in to change notification settings - Fork 185
/
Copy pathBlockSurfaceRock.java
executable file
·137 lines (118 loc) · 4.87 KB
/
BlockSurfaceRock.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
package gregtech.common.blocks;
import gregtech.api.GTValues;
import gregtech.api.items.toolitem.ToolClasses;
import gregtech.api.unification.OreDictUnifier;
import gregtech.api.unification.material.Material;
import gregtech.api.unification.material.Materials;
import gregtech.api.unification.ore.OrePrefix;
import gregtech.api.util.GTUtility;
import gregtech.common.blocks.properties.PropertyMaterial;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@SuppressWarnings("deprecation")
public abstract class BlockSurfaceRock extends BlockMaterialBase {
private static final AxisAlignedBB STONE_AABB = new AxisAlignedBB(2.0 / 16.0, 0.0 / 16.0, 2.0 / 16.0, 14.0 / 16.0,
2.0 / 16.0, 14.0 / 16.0);
public static final ModelResourceLocation MODEL_LOCATION = new ModelResourceLocation(
GTUtility.gregtechId("surface_rock"), "normal");
public static BlockSurfaceRock create(Material[] materials) {
PropertyMaterial property = PropertyMaterial.create("variant", materials);
return new BlockSurfaceRock() {
@NotNull
@Override
public PropertyMaterial getVariantProperty() {
return property;
}
};
}
private BlockSurfaceRock() {
super(net.minecraft.block.material.Material.GOURD);
setTranslationKey("surface_rock");
setHardness(0.25f);
}
@Nullable
@Override
public String getHarvestTool(@NotNull IBlockState state) {
return ToolClasses.SHOVEL;
}
@Override
public boolean onBlockActivated(@NotNull World worldIn, @NotNull BlockPos pos, @NotNull IBlockState state,
EntityPlayer playerIn, @NotNull EnumHand hand, @NotNull EnumFacing facing,
float hitX, float hitY, float hitZ) {
dropBlockAsItem(worldIn, pos, state, 0);
worldIn.setBlockToAir(pos);
playerIn.swingArm(hand);
return true;
}
@NotNull
@Override
public SoundType getSoundType(@NotNull IBlockState state, @NotNull World world, @NotNull BlockPos pos,
@Nullable Entity entity) {
return SoundType.GROUND;
}
@Override
@NotNull
public AxisAlignedBB getBoundingBox(@NotNull IBlockState state, @NotNull IBlockAccess source,
@NotNull BlockPos pos) {
return STONE_AABB;
}
private ItemStack getDropStack(IBlockState state, int amount) {
return OreDictUnifier.get(OrePrefix.dust, getGtMaterial(state), amount);
}
@Override
@NotNull
public ItemStack getPickBlock(@NotNull IBlockState state, @NotNull RayTraceResult target, @NotNull World world,
@NotNull BlockPos pos, @NotNull EntityPlayer player) {
return getDropStack(state, 1);
}
@Override
public void getDrops(NonNullList<ItemStack> drops, @NotNull IBlockAccess world, @NotNull BlockPos pos,
@NotNull IBlockState state, int fortune) {
int amount = GTValues.RNG.nextInt(Math.max(1, 9 - (fortune * 2)));
if (amount == 0) {
drops.add(getDropStack(state, 1));
} else {
drops.add(OreDictUnifier.get(OrePrefix.dust, Materials.Stone, 1));
}
}
@Override
public boolean isFullCube(@NotNull IBlockState state) {
return false;
}
@Override
public boolean isOpaqueCube(@NotNull IBlockState state) {
return false;
}
@Override
public void neighborChanged(@NotNull IBlockState state, @NotNull World worldIn, @NotNull BlockPos pos,
@NotNull Block blockIn, BlockPos fromPos) {
if (fromPos.up().equals(pos)) {
if (worldIn.getBlockState(fromPos).getBlockFaceShape(worldIn, fromPos, EnumFacing.UP) !=
BlockFaceShape.SOLID) {
worldIn.destroyBlock(pos, true);
}
}
}
@Override
@NotNull
public BlockFaceShape getBlockFaceShape(@NotNull IBlockAccess worldIn, @NotNull IBlockState state,
@NotNull BlockPos pos, @NotNull EnumFacing face) {
return BlockFaceShape.UNDEFINED;
}
}