aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-vineflower/net/minecraft/world/level/block/WeightedPressurePlateBlock.java.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patch-remap/mache-vineflower/net/minecraft/world/level/block/WeightedPressurePlateBlock.java.patch')
-rw-r--r--patch-remap/mache-vineflower/net/minecraft/world/level/block/WeightedPressurePlateBlock.java.patch118
1 files changed, 118 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower/net/minecraft/world/level/block/WeightedPressurePlateBlock.java.patch b/patch-remap/mache-vineflower/net/minecraft/world/level/block/WeightedPressurePlateBlock.java.patch
new file mode 100644
index 0000000000..b4a90e668e
--- /dev/null
+++ b/patch-remap/mache-vineflower/net/minecraft/world/level/block/WeightedPressurePlateBlock.java.patch
@@ -0,0 +1,118 @@
+--- a/net/minecraft/world/level/block/WeightedPressurePlateBlock.java
++++ b/net/minecraft/world/level/block/WeightedPressurePlateBlock.java
+@@ -3,46 +3,70 @@
+ import com.mojang.serialization.Codec;
+ import com.mojang.serialization.MapCodec;
+ import com.mojang.serialization.codecs.RecordCodecBuilder;
+-import com.mojang.serialization.codecs.RecordCodecBuilder.Instance;
+ import net.minecraft.core.BlockPos;
+ import net.minecraft.util.Mth;
+ import net.minecraft.world.entity.Entity;
++import net.minecraft.world.entity.player.Player;
+ import net.minecraft.world.level.Level;
+ import net.minecraft.world.level.block.state.BlockBehaviour;
+-import net.minecraft.world.level.block.state.BlockState;
++import net.minecraft.world.level.block.state.IBlockData;
+ import net.minecraft.world.level.block.state.StateDefinition;
+ import net.minecraft.world.level.block.state.properties.BlockSetType;
+ import net.minecraft.world.level.block.state.properties.BlockStateProperties;
+ import net.minecraft.world.level.block.state.properties.IntegerProperty;
++import org.bukkit.event.entity.EntityInteractEvent;
++// CraftBukkit end
+
+ public class WeightedPressurePlateBlock extends BasePressurePlateBlock {
+- public static final MapCodec<WeightedPressurePlateBlock> CODEC = RecordCodecBuilder.mapCodec(
+- instance -> instance.group(
+- Codec.intRange(1, 1024).fieldOf("max_weight").forGetter(weightedPressurePlateBlock -> weightedPressurePlateBlock.maxWeight),
+- BlockSetType.CODEC.fieldOf("block_set_type").forGetter(weightedPressurePlateBlock -> weightedPressurePlateBlock.type),
+- propertiesCodec()
+- )
+- .apply(instance, WeightedPressurePlateBlock::new)
+- );
++
++ public static final MapCodec<WeightedPressurePlateBlock> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
++ return instance.group(Codec.intRange(1, 1024).fieldOf("max_weight").forGetter((blockpressureplateweighted) -> {
++ return blockpressureplateweighted.maxWeight;
++ }), BlockSetType.CODEC.fieldOf("block_set_type").forGetter((blockpressureplateweighted) -> {
++ return blockpressureplateweighted.type;
++ }), propertiesCodec()).apply(instance, WeightedPressurePlateBlock::new);
++ });
+ public static final IntegerProperty POWER = BlockStateProperties.POWER;
+ private final int maxWeight;
+
+ @Override
+ public MapCodec<WeightedPressurePlateBlock> codec() {
+- return CODEC;
++ return WeightedPressurePlateBlock.CODEC;
+ }
+
+- protected WeightedPressurePlateBlock(int i, BlockSetType type, BlockBehaviour.Properties properties) {
+- super(properties, type);
+- this.registerDefaultState(this.stateDefinition.any().setValue(POWER, Integer.valueOf(0)));
++ protected WeightedPressurePlateBlock(int i, BlockSetType blocksettype, BlockBehaviour.Properties blockbase_info) {
++ super(blockbase_info, blocksettype);
++ this.registerDefaultState((IBlockData) ((IBlockData) this.stateDefinition.any()).setValue(WeightedPressurePlateBlock.POWER, 0));
+ this.maxWeight = i;
+ }
+
+ @Override
+ protected int getSignalStrength(Level level, BlockPos pos) {
+- int min = Math.min(getEntityCount(level, TOUCH_AABB.move(pos), Entity.class), this.maxWeight);
+- if (min > 0) {
+- float f = (float)Math.min(this.maxWeight, min) / (float)this.maxWeight;
++ // CraftBukkit start
++ // int i = Math.min(getEntityCount(world, BlockPressurePlateWeighted.TOUCH_AABB.move(blockposition), Entity.class), this.maxWeight);
++ int i = 0;
++ for (Entity entity : getEntities(level, WeightedPressurePlateBlock.TOUCH_AABB.move(pos), Entity.class)) {
++ org.bukkit.event.Cancellable cancellable;
++
++ if (entity instanceof Player) {
++ cancellable = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent((Player) entity, org.bukkit.event.block.Action.PHYSICAL, pos, null, null, null);
++ } else {
++ cancellable = new EntityInteractEvent(entity.getBukkitEntity(), level.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()));
++ level.getCraftServer().getPluginManager().callEvent((EntityInteractEvent) cancellable);
++ }
++
++ // We only want to block turning the plate on if all events are cancelled
++ if (!cancellable.isCancelled()) {
++ i++;
++ }
++ }
++
++ i = Math.min(i, this.maxWeight);
++ // CraftBukkit end
++
++ if (i > 0) {
++ float f = (float) Math.min(this.maxWeight, i) / (float) this.maxWeight;
++
+ return Mth.ceil(f * 15.0F);
+ } else {
+ return 0;
+@@ -50,13 +74,13 @@
+ }
+
+ @Override
+- protected int getSignalForState(BlockState state) {
+- return state.getValue(POWER);
++ protected int getSignalForState(IBlockData state) {
++ return (Integer) state.getValue(WeightedPressurePlateBlock.POWER);
+ }
+
+ @Override
+- protected BlockState setSignalForState(BlockState state, int strength) {
+- return state.setValue(POWER, Integer.valueOf(strength));
++ protected IBlockData setSignalForState(IBlockData state, int strength) {
++ return (IBlockData) state.setValue(WeightedPressurePlateBlock.POWER, strength);
+ }
+
+ @Override
+@@ -65,7 +89,7 @@
+ }
+
+ @Override
+- protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
+- builder.add(POWER);
++ protected void createBlockStateDefinition(StateDefinition.Builder<Block, IBlockData> builder) {
++ builder.add(WeightedPressurePlateBlock.POWER);
+ }
+ }