-
Notifications
You must be signed in to change notification settings - Fork 18
/
BlockCarpetedPressurePlate.java
79 lines (69 loc) · 2.83 KB
/
BlockCarpetedPressurePlate.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
package knightminer.inspirations.utility.block;
import knightminer.inspirations.Inspirations;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.PressurePlateBlock;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.DyeColor;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.world.IBlockReader;
import net.minecraftforge.registries.ForgeRegistries;
import javax.annotation.Nonnull;
public class BlockCarpetedPressurePlate extends PressurePlateBlock {
protected static final VoxelShape PRESSED_AABB = VoxelShapes.or(
Block.makeCuboidShape(0, 0, 0, 16, 1, 16),
Block.makeCuboidShape(1, 1, 1, 15, 1.25, 15)
);
protected static final VoxelShape UNPRESSED_AABB = VoxelShapes.or(
Block.makeCuboidShape(0, 0, 0, 16, 1, 16),
Block.makeCuboidShape(1, 1, 1, 15, 1.5, 15)
);
private final DyeColor color;
private final String transKey;
public BlockCarpetedPressurePlate(DyeColor color) {
super(Sensitivity.MOBS, Block.Properties.create(Material.CARPET, color)
.hardnessAndResistance(0.5F)
.sound(SoundType.CLOTH)
);
this.color = color;
this.transKey = String.format("block.minecraft.%s_carpet", color.getTranslationKey());
}
@Nonnull
@Override
public VoxelShape getShape(@Nonnull BlockState state, @Nonnull IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
boolean flag = this.getRedstoneStrength(state) > 0;
return flag ? PRESSED_AABB : UNPRESSED_AABB;
}
// Use the name of the carpet on top for the translation key.
// This should never be seen normally, but other mods might display it
// so ensure it's a valid value.
@Nonnull
@Override
public String getTranslationKey() {
return transKey;
}
// Since fitted carpets may replace the original carpet, we need to lookup the item to make sure we get the right
// object. So defer until the first time we actually are pick-blocked.
private Item pickItem = Items.AIR;
@Override
public ItemStack getPickBlock(BlockState state, RayTraceResult target, IBlockReader world, BlockPos pos, PlayerEntity player) {
if(pickItem == Items.AIR) {
pickItem = ForgeRegistries.ITEMS.getValue(new ResourceLocation(color.getTranslationKey() + "_carpet"));
if(pickItem == Items.AIR) {
Inspirations.log.warn("No carpet item registered under minecraft:{}_carpet!", color.getTranslationKey());
return ItemStack.EMPTY;
}
}
return new ItemStack(pickItem);
}
}