mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-25 18:09:27 +00:00
优化变量名
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package net.momirealms.craftengine.bukkit.block.behavior;
|
||||
|
||||
import io.papermc.paper.event.entity.EntityInsideBlockEvent;
|
||||
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MBlocks;
|
||||
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.DirectionUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.EventUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.LocationUtils;
|
||||
import net.momirealms.craftengine.bukkit.world.BukkitWorldManager;
|
||||
import net.momirealms.craftengine.core.block.BlockBehavior;
|
||||
@@ -48,6 +50,7 @@ public class PressurePlateBlockBehavior extends BukkitBlockBehavior {
|
||||
this.pressurePlateSensitivity = pressurePlateSensitivity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object updateShape(Object thisBlock, Object[] args, Callable<Object> superMethod) throws Exception {
|
||||
Object state = args[0];
|
||||
Object level;
|
||||
@@ -62,9 +65,10 @@ public class PressurePlateBlockBehavior extends BukkitBlockBehavior {
|
||||
Direction direction = DirectionUtils.fromNMSDirection(VersionHelper.isOrAbove1_21_2() ? args[4] : args[1]);
|
||||
return direction == Direction.DOWN && !FastNMS.INSTANCE.method$BlockStateBase$canSurvive(state, level, blockPos)
|
||||
? MBlocks.AIR$defaultState
|
||||
: superMethod.call();
|
||||
: state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSurvive(Object thisBlock, Object[] args, Callable<Object> superMethod) throws Exception {
|
||||
Object blockPos = LocationUtils.below(args[2]);
|
||||
Object level = args[1];
|
||||
@@ -72,6 +76,7 @@ public class PressurePlateBlockBehavior extends BukkitBlockBehavior {
|
||||
|| FastNMS.INSTANCE.method$Block$canSupportCenter(level, blockPos, CoreReflections.instance$Direction$UP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(Object thisBlock, Object[] args, Callable<Object> superMethod) throws Exception {
|
||||
Object state = args[0];
|
||||
int signalForState = this.getSignalForState(state);
|
||||
@@ -80,7 +85,13 @@ public class PressurePlateBlockBehavior extends BukkitBlockBehavior {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public void entityInside(Object thisBlock, Object[] args, Callable<Object> superMethod) {
|
||||
EntityInsideBlockEvent event = new EntityInsideBlockEvent(FastNMS.INSTANCE.method$Entity$getBukkitEntity(args[3]), FastNMS.INSTANCE.method$CraftBlock$at(args[1], args[2]));
|
||||
if (EventUtils.fireAndCheckCancel(event)) {
|
||||
return;
|
||||
}
|
||||
Object state = args[0];
|
||||
int signalForState = this.getSignalForState(state);
|
||||
if (signalForState == 0) {
|
||||
@@ -105,8 +116,9 @@ public class PressurePlateBlockBehavior extends BukkitBlockBehavior {
|
||||
|
||||
private void checkPressed(@Nullable Object entity, Object level, Object pos, Object state, int currentSignal, Object thisBlock) {
|
||||
int signalStrength = this.getSignalStrength(level, pos);
|
||||
boolean flag = currentSignal > 0;
|
||||
boolean flag1 = signalStrength > 0;
|
||||
boolean wasActive = currentSignal > 0;
|
||||
boolean isActive = signalStrength > 0;
|
||||
|
||||
if (currentSignal != signalStrength) {
|
||||
Object blockState = this.setSignalForState(state, signalStrength);
|
||||
FastNMS.INSTANCE.method$LevelWriter$setBlock(level, pos, blockState, 2);
|
||||
@@ -114,27 +126,44 @@ public class PressurePlateBlockBehavior extends BukkitBlockBehavior {
|
||||
FastNMS.INSTANCE.method$Level$setBlocksDirty(level, pos, state, blockState);
|
||||
}
|
||||
|
||||
if (!flag1 && flag) {
|
||||
World world = BukkitWorldManager.instance().getWorld(FastNMS.INSTANCE.method$Level$getCraftWorld(level)).world();
|
||||
world.playBlockSound(LocationUtils.toVec3d(LocationUtils.fromBlockPos(pos)), this.offSound);
|
||||
FastNMS.INSTANCE.method$Level$getCraftWorld(level).sendGameEvent(FastNMS.INSTANCE.method$Entity$getBukkitEntity(entity),
|
||||
GameEvent.BLOCK_DEACTIVATE,
|
||||
new Vector(FastNMS.INSTANCE.field$Vec3i$x(pos), FastNMS.INSTANCE.field$Vec3i$y(pos), FastNMS.INSTANCE.field$Vec3i$z(pos))
|
||||
);
|
||||
} else if (flag1 && !flag) {
|
||||
World world = BukkitWorldManager.instance().getWorld(FastNMS.INSTANCE.method$Level$getCraftWorld(level)).world();
|
||||
world.playBlockSound(LocationUtils.toVec3d(LocationUtils.fromBlockPos(pos)), this.onSound);
|
||||
FastNMS.INSTANCE.method$Level$getCraftWorld(level).sendGameEvent(FastNMS.INSTANCE.method$Entity$getBukkitEntity(entity),
|
||||
GameEvent.BLOCK_ACTIVATE,
|
||||
new Vector(FastNMS.INSTANCE.field$Vec3i$x(pos), FastNMS.INSTANCE.field$Vec3i$y(pos), FastNMS.INSTANCE.field$Vec3i$z(pos))
|
||||
);
|
||||
org.bukkit.World craftWorld = FastNMS.INSTANCE.method$Level$getCraftWorld(level);
|
||||
int x = FastNMS.INSTANCE.field$Vec3i$x(pos);
|
||||
int y = FastNMS.INSTANCE.field$Vec3i$y(pos);
|
||||
int z = FastNMS.INSTANCE.field$Vec3i$z(pos);
|
||||
Vector positionVector = new Vector(x, y, z);
|
||||
|
||||
if (!isActive && wasActive) {
|
||||
handleDeactivation(entity, craftWorld, pos, positionVector);
|
||||
} else if (isActive && !wasActive) {
|
||||
handleActivation(entity, craftWorld, pos, positionVector);
|
||||
}
|
||||
|
||||
if (flag1) {
|
||||
if (isActive) {
|
||||
FastNMS.INSTANCE.method$LevelAccessor$scheduleBlockTick(level, pos, thisBlock, 20);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleDeactivation(Object entity, org.bukkit.World craftWorld, Object pos, Vector positionVector) {
|
||||
World world = BukkitWorldManager.instance().getWorld(craftWorld).world();
|
||||
world.playBlockSound(LocationUtils.toVec3d(LocationUtils.fromBlockPos(pos)), this.offSound);
|
||||
craftWorld.sendGameEvent(
|
||||
FastNMS.INSTANCE.method$Entity$getBukkitEntity(entity),
|
||||
GameEvent.BLOCK_DEACTIVATE,
|
||||
positionVector
|
||||
);
|
||||
}
|
||||
|
||||
private void handleActivation(Object entity, org.bukkit.World craftWorld, Object pos, Vector positionVector) {
|
||||
World world = BukkitWorldManager.instance().getWorld(craftWorld).world();
|
||||
world.playBlockSound(LocationUtils.toVec3d(LocationUtils.fromBlockPos(pos)), this.onSound);
|
||||
craftWorld.sendGameEvent(
|
||||
FastNMS.INSTANCE.method$Entity$getBukkitEntity(entity),
|
||||
GameEvent.BLOCK_ACTIVATE,
|
||||
positionVector
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void affectNeighborsAfterRemoval(Object thisBlock, Object[] args, Callable<Object> superMethod) {
|
||||
boolean movedByPiston = (boolean) args[3];
|
||||
if (!movedByPiston && this.getSignalForState(args[0]) > 0) {
|
||||
@@ -147,6 +176,7 @@ public class PressurePlateBlockBehavior extends BukkitBlockBehavior {
|
||||
FastNMS.INSTANCE.method$Level$updateNeighborsAt(level, LocationUtils.below(pos), thisBlock);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSignal(Object thisBlock, Object[] args, Callable<Object> superMethod) {
|
||||
return this.getSignalForState(args[0]);
|
||||
}
|
||||
@@ -157,11 +187,13 @@ public class PressurePlateBlockBehavior extends BukkitBlockBehavior {
|
||||
return blockState.get(this.poweredProperty) ? 15 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDirectSignal(Object thisBlock, Object[] args, Callable<Object> superMethod) {
|
||||
Direction direction = DirectionUtils.fromNMSDirection(args[3]);
|
||||
return direction == Direction.UP ? this.getSignalForState(args[0]) : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSignalSource(Object thisBlock, Object[] args, Callable<Object> superMethod) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user