mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-28 03:19:14 +00:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package net.momirealms.craftengine.bukkit.api;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
||||
import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer;
|
||||
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
|
||||
@@ -108,9 +109,9 @@ public final class CraftEngineBlocks {
|
||||
boolean success;
|
||||
try {
|
||||
Object worldServer = Reflections.field$CraftWorld$ServerLevel.get(location.getWorld());
|
||||
Object blockPos = Reflections.constructor$BlockPos.newInstance(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
Object blockPos = FastNMS.INSTANCE.constructor$BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
Object blockState = block.customBlockState().handle();
|
||||
Object oldBlockState = Reflections.method$BlockGetter$getBlockState.invoke(worldServer, blockPos);
|
||||
Object oldBlockState = FastNMS.INSTANCE.method$BlockGetter$getBlockState(worldServer, blockPos);
|
||||
success = (boolean) Reflections.method$LevelWriter$setBlock.invoke(worldServer, blockPos, blockState, option.flags());
|
||||
if (success) {
|
||||
Reflections.method$BlockStateBase$onPlace.invoke(blockState, worldServer, blockPos, oldBlockState, true);
|
||||
|
||||
@@ -318,7 +318,7 @@ public class BlockEventListener implements Listener {
|
||||
if (direction == BlockFace.UP || direction == BlockFace.DOWN) {
|
||||
Object serverLevel = Reflections.field$CraftWorld$ServerLevel.get(world);
|
||||
Object chunkSource = Reflections.field$ServerLevel$chunkSource.get(serverLevel);
|
||||
Object blockPos = Reflections.constructor$BlockPos.newInstance(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
Object blockPos = LocationUtils.toBlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
Reflections.method$ServerChunkCache$blockChanged.invoke(chunkSource, blockPos);
|
||||
if (direction == BlockFace.UP) {
|
||||
NoteBlockChainUpdateUtils.noteBlockChainUpdate(serverLevel, chunkSource, Reflections.instance$Direction$UP, blockPos, 0);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.momirealms.craftengine.bukkit.block.behavior;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.BlockTags;
|
||||
import net.momirealms.craftengine.bukkit.util.LocationUtils;
|
||||
@@ -64,7 +65,7 @@ public class BushBlockBehavior extends AbstractBlockBehavior {
|
||||
ContextHolder.Builder builder = ContextHolder.builder();
|
||||
BlockPos pos = LocationUtils.fromBlockPos(blockPos);
|
||||
Vec3d vec3d = Vec3d.atCenterOf(pos);
|
||||
net.momirealms.craftengine.core.world.World world = new BukkitWorld((World) Reflections.method$Level$getCraftWorld.invoke(level));
|
||||
net.momirealms.craftengine.core.world.World world = new BukkitWorld(FastNMS.INSTANCE.method$Level$getCraftWorld(level));
|
||||
builder.withParameter(LootParameters.LOCATION, vec3d);
|
||||
builder.withParameter(LootParameters.WORLD, world);
|
||||
for (Item<Object> item : previousState.getDrops(builder, world)) {
|
||||
@@ -120,11 +121,11 @@ public class BushBlockBehavior extends AbstractBlockBehavior {
|
||||
}
|
||||
|
||||
protected boolean canSurvive(Object thisBlock, Object state, Object world, Object blockPos) throws ReflectiveOperationException {
|
||||
int y = Reflections.field$Vec3i$y.getInt(blockPos);
|
||||
int x = Reflections.field$Vec3i$x.getInt(blockPos);
|
||||
int z = Reflections.field$Vec3i$z.getInt(blockPos);
|
||||
Object belowPos = Reflections.constructor$BlockPos.newInstance(x, y - 1, z);
|
||||
Object belowState = Reflections.method$BlockGetter$getBlockState.invoke(world, belowPos);
|
||||
int y = FastNMS.INSTANCE.field$Vec3i$y(blockPos);
|
||||
int x = FastNMS.INSTANCE.field$Vec3i$x(blockPos);
|
||||
int z = FastNMS.INSTANCE.field$Vec3i$z(blockPos);
|
||||
Object belowPos = FastNMS.INSTANCE.constructor$BlockPos(x, y - 1, z);
|
||||
Object belowState = FastNMS.INSTANCE.method$BlockGetter$getBlockState(world, belowPos);
|
||||
return mayPlaceOn(belowState, world, belowPos);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.momirealms.craftengine.bukkit.block.behavior;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.EventUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.LocationUtils;
|
||||
@@ -65,7 +66,7 @@ public class ConcretePowderBlockBehavior extends FallingBlockBehavior {
|
||||
Object level = context.getLevel().serverWorld();
|
||||
Object blockPos = LocationUtils.toBlockPos(context.getClickedPos());
|
||||
try {
|
||||
Object previousState = Reflections.method$BlockGetter$getBlockState.invoke(level, blockPos);
|
||||
Object previousState = FastNMS.INSTANCE.method$BlockGetter$getBlockState(level, blockPos);
|
||||
if (!shouldSolidify(level, blockPos, previousState)) {
|
||||
return super.updateStateForPlacement(context, state);
|
||||
} else {
|
||||
@@ -137,10 +138,10 @@ public class ConcretePowderBlockBehavior extends FallingBlockBehavior {
|
||||
int j = Direction.values().length;
|
||||
for (int k = 0; k < j; k++) {
|
||||
Object direction = Reflections.instance$Directions[k];
|
||||
Object blockState = Reflections.method$BlockGetter$getBlockState.invoke(level, mutablePos);
|
||||
Object blockState = FastNMS.INSTANCE.method$BlockGetter$getBlockState(level, mutablePos);
|
||||
if (direction != Reflections.instance$Direction$DOWN || canSolidify(blockState)) {
|
||||
Reflections.method$MutableBlockPos$setWithOffset.invoke(mutablePos, pos, direction);
|
||||
blockState = Reflections.method$BlockGetter$getBlockState.invoke(level, mutablePos);
|
||||
blockState = FastNMS.INSTANCE.method$BlockGetter$getBlockState(level, mutablePos);
|
||||
if (canSolidify(blockState) && !(boolean) Reflections.method$BlockStateBase$isFaceSturdy.invoke(blockState, level, pos, Reflections.getOppositeDirection(direction), Reflections.instance$SupportType$FULL)) {
|
||||
flag = true;
|
||||
break;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.momirealms.craftengine.bukkit.block.behavior;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.LocationUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.Reflections;
|
||||
@@ -56,17 +57,17 @@ public class FallingBlockBehavior extends AbstractBlockBehavior {
|
||||
@Override
|
||||
public void tick(Object thisBlock, Object[] args, Callable<Object> superMethod) throws Exception {
|
||||
Object blockPos = args[2];
|
||||
int y = Reflections.field$Vec3i$y.getInt(blockPos);
|
||||
int y = FastNMS.INSTANCE.field$Vec3i$y(blockPos);
|
||||
Object world = args[1];
|
||||
Object dimension = Reflections.method$$LevelReader$dimensionType.invoke(world);
|
||||
int minY = Reflections.field$DimensionType$minY.getInt(dimension);
|
||||
if (y < minY) {
|
||||
return;
|
||||
}
|
||||
int x = Reflections.field$Vec3i$x.getInt(blockPos);
|
||||
int z = Reflections.field$Vec3i$z.getInt(blockPos);
|
||||
Object belowPos = Reflections.constructor$BlockPos.newInstance(x, y - 1, z);
|
||||
Object belowState = Reflections.method$BlockGetter$getBlockState.invoke(world, belowPos);
|
||||
int x = FastNMS.INSTANCE.field$Vec3i$x(blockPos);
|
||||
int z = FastNMS.INSTANCE.field$Vec3i$z(blockPos);
|
||||
Object belowPos = LocationUtils.toBlockPos(x, y - 1, z);
|
||||
Object belowState = FastNMS.INSTANCE.method$BlockGetter$getBlockState(world, belowPos);
|
||||
boolean isFree = (boolean) Reflections.method$FallingBlock$isFree.invoke(null, belowState);
|
||||
if (!isFree) {
|
||||
return;
|
||||
@@ -96,7 +97,7 @@ public class FallingBlockBehavior extends AbstractBlockBehavior {
|
||||
double y = Reflections.field$Entity$yo.getDouble(fallingBlockEntity);
|
||||
double z = Reflections.field$Entity$zo.getDouble(fallingBlockEntity);
|
||||
Vec3d vec3d = new Vec3d(x, y, z);
|
||||
net.momirealms.craftengine.core.world.World world = new BukkitWorld((World) Reflections.method$Level$getCraftWorld.invoke(level));
|
||||
net.momirealms.craftengine.core.world.World world = new BukkitWorld(FastNMS.INSTANCE.method$Level$getCraftWorld(level));
|
||||
builder.withParameter(LootParameters.LOCATION, vec3d);
|
||||
builder.withParameter(LootParameters.WORLD, world);
|
||||
for (Item<Object> item : immutableBlockState.getDrops(builder, world)) {
|
||||
@@ -121,7 +122,7 @@ public class FallingBlockBehavior extends AbstractBlockBehavior {
|
||||
if (immutableBlockState == null || immutableBlockState.isEmpty()) return;
|
||||
Object level = args[0];
|
||||
Object pos = args[1];
|
||||
net.momirealms.craftengine.core.world.World world = new BukkitWorld((World) Reflections.method$Level$getCraftWorld.invoke(level));
|
||||
net.momirealms.craftengine.core.world.World world = new BukkitWorld(FastNMS.INSTANCE.method$Level$getCraftWorld(level));
|
||||
world.playBlockSound(Vec3d.atCenterOf(LocationUtils.fromBlockPos(pos)), immutableBlockState.sounds().landSound());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.momirealms.craftengine.bukkit.block.behavior;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.util.Reflections;
|
||||
import net.momirealms.craftengine.core.block.CustomBlock;
|
||||
import net.momirealms.craftengine.core.block.behavior.BlockBehaviorFactory;
|
||||
@@ -19,11 +20,11 @@ public class HangingBlockBehavior extends BushBlockBehavior {
|
||||
|
||||
@Override
|
||||
protected boolean canSurvive(Object thisBlock, Object state, Object world, Object blockPos) throws ReflectiveOperationException {
|
||||
int y = Reflections.field$Vec3i$y.getInt(blockPos);
|
||||
int x = Reflections.field$Vec3i$x.getInt(blockPos);
|
||||
int z = Reflections.field$Vec3i$z.getInt(blockPos);
|
||||
Object belowPos = Reflections.constructor$BlockPos.newInstance(x, y + 1, z);
|
||||
Object belowState = Reflections.method$BlockGetter$getBlockState.invoke(world, belowPos);
|
||||
int y = FastNMS.INSTANCE.field$Vec3i$y(blockPos);
|
||||
int x = FastNMS.INSTANCE.field$Vec3i$x(blockPos);
|
||||
int z = FastNMS.INSTANCE.field$Vec3i$z(blockPos);
|
||||
Object belowPos = FastNMS.INSTANCE.constructor$BlockPos(x, y + 1, z);
|
||||
Object belowState = FastNMS.INSTANCE.method$BlockGetter$getBlockState(world, belowPos);
|
||||
return mayPlaceOn(belowState, world, belowPos);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.momirealms.craftengine.bukkit.block.behavior;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.BlockTags;
|
||||
import net.momirealms.craftengine.bukkit.util.LocationUtils;
|
||||
@@ -108,7 +109,7 @@ public class LeavesBlockBehavior extends WaterLoggedBlockBehavior {
|
||||
Object blockPos = args[2];
|
||||
ImmutableBlockState immutableBlockState = BukkitBlockManager.instance().getImmutableBlockState(BlockStateUtils.blockStateToId(args[0]));
|
||||
if (immutableBlockState != null && immutableBlockState.behavior() instanceof LeavesBlockBehavior behavior && behavior.isDecaying(immutableBlockState)) {
|
||||
World bukkitWorld = (World) Reflections.method$Level$getCraftWorld.invoke(level);
|
||||
World bukkitWorld = FastNMS.INSTANCE.method$Level$getCraftWorld(level);
|
||||
BlockPos pos = LocationUtils.fromBlockPos(blockPos);
|
||||
// call bukkit event
|
||||
LeavesDecayEvent event = new LeavesDecayEvent(bukkitWorld.getBlockAt(pos.x(), pos.y(), pos.z()));
|
||||
@@ -142,7 +143,7 @@ public class LeavesBlockBehavior extends WaterLoggedBlockBehavior {
|
||||
for (int k = 0; k < j; ++k) {
|
||||
Object direction = Reflections.instance$Directions[k];
|
||||
Reflections.method$MutableBlockPos$setWithOffset.invoke(mutablePos, blockPos, direction);
|
||||
Object blockState = Reflections.method$BlockGetter$getBlockState.invoke(world, mutablePos);
|
||||
Object blockState = FastNMS.INSTANCE.method$BlockGetter$getBlockState(world, mutablePos);
|
||||
i = Math.min(i, getDistanceAt(blockState) + 1);
|
||||
if (i == 1) {
|
||||
break;
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.momirealms.craftengine.bukkit.block.behavior;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.api.CraftEngineBlocks;
|
||||
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.FeatureUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.LocationUtils;
|
||||
@@ -48,10 +49,7 @@ public class SaplingBlockBehavior extends BushBlockBehavior {
|
||||
Object world = args[1];
|
||||
Object blockPos = args[2];
|
||||
Object blockState = args[0];
|
||||
int x = (int) Reflections.field$Vec3i$x.get(blockPos);
|
||||
int y = (int) Reflections.field$Vec3i$y.get(blockPos);
|
||||
int z = (int) Reflections.field$Vec3i$z.get(blockPos);
|
||||
Object aboveBlockPos = LocationUtils.toBlockPos(x, y + 1, z);
|
||||
Object aboveBlockPos = LocationUtils.above(blockPos);
|
||||
if ((int) Reflections.method$LevelReader$getMaxLocalRawBrightness.invoke(world, aboveBlockPos) >= 9 && (float) Reflections.method$RandomSource$nextFloat.invoke(args[3]) < (1.0f / 7.0f)) {
|
||||
increaseStage(world, blockPos, blockState, args[3]);
|
||||
}
|
||||
@@ -63,10 +61,10 @@ public class SaplingBlockBehavior extends BushBlockBehavior {
|
||||
int currentStage = immutableBlockState.get(this.stageProperty);
|
||||
if (currentStage != this.stageProperty.possibleValues().get(this.stageProperty.possibleValues().size() - 1)) {
|
||||
ImmutableBlockState nextStage = immutableBlockState.cycle(this.stageProperty);
|
||||
World bukkitWorld = (World) Reflections.method$Level$getCraftWorld.invoke(world);
|
||||
int x = (int) Reflections.field$Vec3i$x.get(blockPos);
|
||||
int y = (int) Reflections.field$Vec3i$y.get(blockPos);
|
||||
int z = (int) Reflections.field$Vec3i$z.get(blockPos);
|
||||
World bukkitWorld = FastNMS.INSTANCE.method$Level$getCraftWorld(world);
|
||||
int x = FastNMS.INSTANCE.field$Vec3i$x(blockPos);
|
||||
int y = FastNMS.INSTANCE.field$Vec3i$y(blockPos);
|
||||
int z = FastNMS.INSTANCE.field$Vec3i$z(blockPos);
|
||||
CraftEngineBlocks.place(new Location(bukkitWorld, x, y, z), nextStage, UpdateOption.UPDATE_NONE, false);
|
||||
} else {
|
||||
generateTree(world, blockPos, blockState, randomSource);
|
||||
@@ -88,7 +86,7 @@ public class SaplingBlockBehavior extends BushBlockBehavior {
|
||||
Object legacyState = Reflections.method$FluidState$createLegacyBlock.invoke(fluidState);
|
||||
Reflections.method$Level$setBlock.invoke(world, blockPos, legacyState, UpdateOption.UPDATE_NONE.flags());
|
||||
if ((boolean) Reflections.method$ConfiguredFeature$place.invoke(configuredFeature, world, chunkGenerator, randomSource, blockPos)) {
|
||||
if (Reflections.method$BlockGetter$getBlockState.invoke(world, blockPos) == legacyState) {
|
||||
if (FastNMS.INSTANCE.method$BlockGetter$getBlockState(world, blockPos) == legacyState) {
|
||||
Reflections.method$ServerLevel$sendBlockUpdated.invoke(world, blockPos, blockState, legacyState, 2);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -1,11 +1,54 @@
|
||||
package net.momirealms.craftengine.bukkit.block.behavior;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.LocationUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.Reflections;
|
||||
import net.momirealms.craftengine.bukkit.world.BukkitWorld;
|
||||
import net.momirealms.craftengine.core.block.ImmutableBlockState;
|
||||
import net.momirealms.craftengine.core.block.UpdateOption;
|
||||
import net.momirealms.craftengine.core.block.properties.IntegerProperty;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.loot.parameter.LootParameters;
|
||||
import net.momirealms.craftengine.core.util.context.ContextHolder;
|
||||
import net.momirealms.craftengine.core.world.Vec3d;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class SugarCaneBlockBehavior extends BushBlockBehavior {
|
||||
private final int maxHeight;
|
||||
private final boolean nearWater;
|
||||
private final boolean nearLava;
|
||||
private final IntegerProperty age;
|
||||
|
||||
public SugarCaneBlockBehavior(List<Object> tagsCanSurviveOn, Set<Object> blocksCansSurviveOn, Set<String> customBlocksCansSurviveOn) {
|
||||
public SugarCaneBlockBehavior(List<Object> tagsCanSurviveOn, Set<Object> blocksCansSurviveOn, Set<String> customBlocksCansSurviveOn, IntegerProperty age, int maxHeight, boolean nearWater, boolean nearLava) {
|
||||
super(tagsCanSurviveOn, blocksCansSurviveOn, customBlocksCansSurviveOn);
|
||||
this.nearWater = nearWater;
|
||||
this.nearLava = nearLava;
|
||||
this.maxHeight = maxHeight;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(Object thisBlock, Object[] args, Callable<Object> superMethod) throws Exception {
|
||||
Object blockState = args[0];
|
||||
Object level = args[1];
|
||||
Object blockPos = args[2];
|
||||
ImmutableBlockState currentState = BukkitBlockManager.instance().getImmutableBlockState(BlockStateUtils.blockStateToId(blockState));
|
||||
if (currentState != null && !currentState.isEmpty()) {
|
||||
Reflections.method$Level$removeBlock.invoke(level, blockPos, false);
|
||||
Vec3d vec3d = Vec3d.atCenterOf(LocationUtils.fromBlockPos(blockPos));
|
||||
net.momirealms.craftengine.core.world.World world = new BukkitWorld(FastNMS.INSTANCE.method$Level$getCraftWorld(level));
|
||||
ContextHolder.Builder builder = ContextHolder.builder()
|
||||
.withParameter(LootParameters.LOCATION, vec3d)
|
||||
.withParameter(LootParameters.WORLD, world);
|
||||
for (Item<Object> item : currentState.getDrops(builder, world)) {
|
||||
world.dropItemNaturally(vec3d, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,12 +147,7 @@ public class BlockItemBehavior extends ItemBehavior {
|
||||
|
||||
protected boolean canPlace(BlockPlaceContext context, ImmutableBlockState state) {
|
||||
try {
|
||||
Object player;
|
||||
try {
|
||||
player = Reflections.method$CraftPlayer$getHandle.invoke(context.getPlayer().platformPlayer());
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new RuntimeException("Failed to get server player", e);
|
||||
}
|
||||
Object player = context.getPlayer().serverPlayer();
|
||||
Object blockState = state.customBlockState().handle();
|
||||
Object blockPos = LocationUtils.toBlockPos(context.getClickedPos());
|
||||
Object voxelShape = Reflections.method$CollisionContext$of.invoke(null, player);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.momirealms.craftengine.bukkit.item.behavior;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.util.LocationUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.Reflections;
|
||||
import net.momirealms.craftengine.core.entity.player.InteractionHand;
|
||||
@@ -41,7 +42,7 @@ public class LiquidCollisionBlockItemBehavior extends BlockItemBehavior {
|
||||
try {
|
||||
Object blockHitResult = Reflections.method$Item$getPlayerPOVHitResult.invoke(null, world.serverWorld(), player.serverPlayer(), Reflections.instance$ClipContext$Fluid$SOURCE_ONLY);
|
||||
Object blockPos = Reflections.field$BlockHitResul$blockPos.get(blockHitResult);
|
||||
BlockPos above = new BlockPos(Reflections.field$Vec3i$x.getInt(blockPos), Reflections.field$Vec3i$y.getInt(blockPos) + offsetY, Reflections.field$Vec3i$z.getInt(blockPos));
|
||||
BlockPos above = new BlockPos(FastNMS.INSTANCE.field$Vec3i$x(blockPos), FastNMS.INSTANCE.field$Vec3i$y(blockPos) + offsetY, FastNMS.INSTANCE.field$Vec3i$z(blockPos));
|
||||
Direction direction = Direction.values()[(int) Reflections.method$Direction$ordinal.invoke(Reflections.field$BlockHitResul$direction.get(blockHitResult))];
|
||||
boolean miss = Reflections.field$BlockHitResul$miss.getBoolean(blockHitResult);
|
||||
Vec3d hitPos = LocationUtils.fromVec(Reflections.field$HitResult$location.get(blockHitResult));
|
||||
|
||||
@@ -6,6 +6,7 @@ import io.netty.handler.codec.MessageToMessageDecoder;
|
||||
import io.netty.handler.codec.MessageToMessageEncoder;
|
||||
import io.netty.util.internal.logging.InternalLogger;
|
||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
||||
import net.momirealms.craftengine.bukkit.plugin.network.impl.*;
|
||||
import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer;
|
||||
@@ -253,7 +254,7 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
|
||||
return (Channel) Reflections.field$Channel.get(
|
||||
Reflections.field$NetworkManager.get(
|
||||
Reflections.field$ServerPlayer$connection.get(
|
||||
Reflections.method$CraftPlayer$getHandle.invoke(player)
|
||||
FastNMS.INSTANCE.method$CraftPlayer$getHandle(player)
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -264,7 +265,7 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
|
||||
|
||||
public void sendPacket(@NotNull Player player, @NotNull Object packet) {
|
||||
try {
|
||||
Object serverPlayer = Reflections.method$CraftPlayer$getHandle.invoke(player);
|
||||
Object serverPlayer = FastNMS.INSTANCE.method$CraftPlayer$getHandle(player);
|
||||
this.immediatePacketConsumer.accept(serverPlayer, packet);
|
||||
} catch (Exception e) {
|
||||
this.plugin.logger().warn("Failed to send packet", e);
|
||||
|
||||
@@ -11,6 +11,7 @@ import net.momirealms.craftengine.bukkit.api.event.FurnitureInteractEvent;
|
||||
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
|
||||
import net.momirealms.craftengine.bukkit.entity.furniture.BukkitFurnitureManager;
|
||||
import net.momirealms.craftengine.bukkit.entity.furniture.LoadedFurniture;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
||||
import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer;
|
||||
import net.momirealms.craftengine.bukkit.util.*;
|
||||
@@ -268,11 +269,7 @@ public class PacketConsumers {
|
||||
Player platformPlayer = player.platformPlayer();
|
||||
World world = platformPlayer.getWorld();
|
||||
Object blockPos = Reflections.field$ServerboundPlayerActionPacket$pos.get(packet);
|
||||
BlockPos pos = new BlockPos(
|
||||
(int) Reflections.field$Vec3i$x.get(blockPos),
|
||||
(int) Reflections.field$Vec3i$y.get(blockPos),
|
||||
(int) Reflections.field$Vec3i$z.get(blockPos)
|
||||
);
|
||||
BlockPos pos = LocationUtils.fromBlockPos(blockPos);
|
||||
if (VersionHelper.isFolia()) {
|
||||
BukkitCraftEngine.instance().scheduler().sync().run(() -> {
|
||||
try {
|
||||
@@ -293,7 +290,7 @@ public class PacketConsumers {
|
||||
Object action = Reflections.field$ServerboundPlayerActionPacket$action.get(packet);
|
||||
if (action == Reflections.instance$ServerboundPlayerActionPacket$Action$START_DESTROY_BLOCK) {
|
||||
Object serverLevel = Reflections.field$CraftWorld$ServerLevel.get(world);
|
||||
Object blockState = Reflections.method$BlockGetter$getBlockState.invoke(serverLevel, LocationUtils.toBlockPos(pos));
|
||||
Object blockState = FastNMS.INSTANCE.method$BlockGetter$getBlockState(serverLevel, LocationUtils.toBlockPos(pos));
|
||||
int stateId = BlockStateUtils.blockStateToId(blockState);
|
||||
// not a custom block
|
||||
if (BlockStateUtils.isVanillaBlock(stateId)) {
|
||||
@@ -311,7 +308,7 @@ public class PacketConsumers {
|
||||
}
|
||||
if (player.isAdventureMode()) {
|
||||
Object itemStack = Reflections.method$CraftItemStack$asNMSCopy.invoke(null, player.platformPlayer().getInventory().getItemInMainHand());
|
||||
Object blockPos = Reflections.constructor$BlockPos.newInstance(pos.x(), pos.y(), pos.z());
|
||||
Object blockPos = LocationUtils.toBlockPos(pos);
|
||||
Object blockInWorld = Reflections.constructor$BlockInWorld.newInstance(serverLevel, blockPos, false);
|
||||
if (VersionHelper.isVersionNewerThan1_20_5()) {
|
||||
if (Reflections.method$ItemStack$canBreakBlockInAdventureMode != null
|
||||
@@ -523,8 +520,8 @@ public class PacketConsumers {
|
||||
if (player == null) return;
|
||||
Object pos = Reflections.field$ServerboundPickItemFromBlockPacket$pos.get(packet);
|
||||
if (VersionHelper.isFolia()) {
|
||||
int x = (int) Reflections.field$Vec3i$x.get(pos);
|
||||
int z = (int) Reflections.field$Vec3i$z.get(pos);
|
||||
int x = FastNMS.INSTANCE.field$Vec3i$x(pos);
|
||||
int z = FastNMS.INSTANCE.field$Vec3i$z(pos);
|
||||
BukkitCraftEngine.instance().scheduler().sync().run(() -> {
|
||||
try {
|
||||
handlePickItemFromBlockPacketOnMainThread(player, pos);
|
||||
@@ -548,7 +545,7 @@ public class PacketConsumers {
|
||||
|
||||
private static void handlePickItemFromBlockPacketOnMainThread(Player player, Object pos) throws Exception {
|
||||
Object serverLevel = Reflections.field$CraftWorld$ServerLevel.get(player.getWorld());
|
||||
Object blockState = Reflections.method$BlockGetter$getBlockState.invoke(serverLevel, pos);
|
||||
Object blockState = FastNMS.INSTANCE.method$BlockGetter$getBlockState(serverLevel, pos);
|
||||
ImmutableBlockState state = BukkitBlockManager.instance().getImmutableBlockState(BlockStateUtils.blockStateToId(blockState));
|
||||
if (state == null) return;
|
||||
Key itemId = state.settings().itemId();
|
||||
@@ -603,7 +600,7 @@ public class PacketConsumers {
|
||||
}
|
||||
assert Reflections.method$ServerGamePacketListenerImpl$tryPickItem != null;
|
||||
Reflections.method$ServerGamePacketListenerImpl$tryPickItem.invoke(
|
||||
Reflections.field$ServerPlayer$connection.get(Reflections.method$CraftPlayer$getHandle.invoke(player)), Reflections.method$CraftItemStack$asNMSCopy.invoke(null, itemStack));
|
||||
Reflections.field$ServerPlayer$connection.get(FastNMS.INSTANCE.method$CraftPlayer$getHandle(player)), Reflections.method$CraftItemStack$asNMSCopy.invoke(null, itemStack));
|
||||
}
|
||||
|
||||
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> ADD_ENTITY = (user, event, packet) -> {
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.common.collect.Lists;
|
||||
import io.netty.channel.Channel;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.bukkit.item.BukkitItemManager;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
||||
import net.momirealms.craftengine.bukkit.util.*;
|
||||
import net.momirealms.craftengine.bukkit.world.BukkitWorld;
|
||||
@@ -75,11 +76,7 @@ public class BukkitServerPlayer extends Player {
|
||||
|
||||
public void setPlayer(org.bukkit.entity.Player player) {
|
||||
playerRef = new WeakReference<>(player);
|
||||
try {
|
||||
serverPlayerRef = new WeakReference<>(Reflections.method$CraftPlayer$getHandle.invoke(player));
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
serverPlayerRef = new WeakReference<>(FastNMS.INSTANCE.method$CraftPlayer$getHandle(player));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -298,7 +295,7 @@ public class BukkitServerPlayer extends Player {
|
||||
public float getDestroyProgress(Object blockState, BlockPos pos) {
|
||||
try {
|
||||
Object serverPlayer = serverPlayer();
|
||||
Object blockPos = Reflections.constructor$BlockPos.newInstance(pos.x(), pos.y(), pos.z());
|
||||
Object blockPos = LocationUtils.toBlockPos(pos.x(), pos.y(), pos.z());
|
||||
return (float) Reflections.method$BlockStateBase$getDestroyProgress.invoke(blockState, serverPlayer, Reflections.method$Entity$level.invoke(serverPlayer), blockPos);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
this.plugin.logger().warn("Failed to get destroy progress for player " + platformPlayer().getName());
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.momirealms.craftengine.bukkit.util;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.core.world.BlockPos;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@@ -14,13 +15,9 @@ public class EntityUtils {
|
||||
|
||||
public static BlockPos getOnPos(Player player) {
|
||||
try {
|
||||
Object serverPlayer = Reflections.method$CraftPlayer$getHandle.invoke(player);
|
||||
Object serverPlayer = FastNMS.INSTANCE.method$CraftPlayer$getHandle(player);
|
||||
Object blockPos = Reflections.method$Entity$getOnPos.invoke(serverPlayer, 1.0E-5F);
|
||||
return new BlockPos(
|
||||
(int) Reflections.field$Vec3i$x.get(blockPos),
|
||||
(int) Reflections.field$Vec3i$y.get(blockPos),
|
||||
(int) Reflections.field$Vec3i$z.get(blockPos)
|
||||
);
|
||||
return LocationUtils.fromBlockPos(blockPos);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.momirealms.craftengine.bukkit.util;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.core.world.BlockPos;
|
||||
import net.momirealms.craftengine.core.world.Vec3d;
|
||||
import org.bukkit.Location;
|
||||
@@ -13,48 +14,39 @@ public class LocationUtils {
|
||||
return new Vec3d(loc.getX(), loc.getY(), loc.getZ());
|
||||
}
|
||||
|
||||
public static Vec3d fromVec(Object vec) throws ReflectiveOperationException {
|
||||
public static Vec3d fromVec(Object vec) {
|
||||
return new Vec3d(
|
||||
Reflections.field$Vec3$x.getDouble(vec),
|
||||
Reflections.field$Vec3$y.getDouble(vec),
|
||||
Reflections.field$Vec3$z.getDouble(vec)
|
||||
FastNMS.INSTANCE.field$Vec3$x(vec),
|
||||
FastNMS.INSTANCE.field$Vec3$y(vec),
|
||||
FastNMS.INSTANCE.field$Vec3$y(vec)
|
||||
);
|
||||
}
|
||||
|
||||
public static Object toBlockPos(BlockPos pos) {
|
||||
try {
|
||||
return Reflections.constructor$BlockPos.newInstance(pos.x(), pos.y(), pos.z());
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException("Failed to create BlockPos", e);
|
||||
}
|
||||
return toBlockPos(pos.x(), pos.y(), pos.z());
|
||||
}
|
||||
|
||||
public static Object above(Object blockPos) throws ReflectiveOperationException {
|
||||
return toBlockPos(
|
||||
Reflections.field$Vec3i$x.getInt(blockPos),
|
||||
Reflections.field$Vec3i$y.getInt(blockPos) + 1,
|
||||
Reflections.field$Vec3i$z.getInt(blockPos)
|
||||
FastNMS.INSTANCE.field$Vec3i$x(blockPos),
|
||||
FastNMS.INSTANCE.field$Vec3i$y(blockPos) + 1,
|
||||
FastNMS.INSTANCE.field$Vec3i$z(blockPos)
|
||||
);
|
||||
}
|
||||
|
||||
public static Object toBlockPos(int x, int y, int z) {
|
||||
try {
|
||||
return Reflections.constructor$BlockPos.newInstance(x, y, z);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException("Failed to create BlockPos", e);
|
||||
}
|
||||
return FastNMS.INSTANCE.constructor$BlockPos(x, y, z);
|
||||
}
|
||||
|
||||
|
||||
public static BlockPos toBlockPos(Location pos) {
|
||||
return new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
|
||||
}
|
||||
|
||||
public static BlockPos fromBlockPos(Object pos) throws ReflectiveOperationException {
|
||||
return new BlockPos(
|
||||
Reflections.field$Vec3i$x.getInt(pos),
|
||||
Reflections.field$Vec3i$y.getInt(pos),
|
||||
Reflections.field$Vec3i$z.getInt(pos)
|
||||
FastNMS.INSTANCE.field$Vec3i$x(pos),
|
||||
FastNMS.INSTANCE.field$Vec3i$y(pos),
|
||||
FastNMS.INSTANCE.field$Vec3i$z(pos)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.momirealms.craftengine.bukkit.util;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigManager;
|
||||
|
||||
public class NoteBlockChainUpdateUtils {
|
||||
@@ -9,7 +10,7 @@ public class NoteBlockChainUpdateUtils {
|
||||
public static void noteBlockChainUpdate(Object level, Object chunkSource, Object direction, Object blockPos, int times) throws ReflectiveOperationException {
|
||||
if (times >= ConfigManager.maxChainUpdate()) return;
|
||||
Object relativePos = Reflections.method$BlockPos$relative.invoke(blockPos, direction);
|
||||
Object state = Reflections.method$BlockGetter$getBlockState.invoke(level, relativePos);
|
||||
Object state = FastNMS.INSTANCE.method$BlockGetter$getBlockState(level, relativePos);
|
||||
if (BlockStateUtils.isClientSideNoteBlock(state)) {
|
||||
Reflections.method$ServerChunkCache$blockChanged.invoke(chunkSource, relativePos);
|
||||
noteBlockChainUpdate(level, chunkSource, direction, relativePos, times+1);
|
||||
|
||||
@@ -471,9 +471,9 @@ public class Reflections {
|
||||
BukkitReflectionUtils.assembleCBClass("entity.CraftPlayer")
|
||||
));
|
||||
|
||||
public static final Method method$CraftPlayer$getHandle = requireNonNull(
|
||||
ReflectionUtils.getMethod(clazz$CraftPlayer, new String[] { "getHandle" })
|
||||
);
|
||||
// public static final Method method$CraftPlayer$getHandle = requireNonNull(
|
||||
// ReflectionUtils.getMethod(clazz$CraftPlayer, new String[] { "getHandle" })
|
||||
// );
|
||||
|
||||
public static final Field field$ServerPlayer$connection = requireNonNull(
|
||||
ReflectionUtils.getInstanceDeclaredField(clazz$ServerPlayer, clazz$ServerGamePacketListenerImpl, 0)
|
||||
@@ -1364,17 +1364,17 @@ public class Reflections {
|
||||
)
|
||||
);
|
||||
|
||||
public static final Field field$Vec3i$x = requireNonNull(
|
||||
ReflectionUtils.getDeclaredField(clazz$Vec3i, int.class, 0)
|
||||
);
|
||||
|
||||
public static final Field field$Vec3i$y = requireNonNull(
|
||||
ReflectionUtils.getDeclaredField(clazz$Vec3i, int.class, 1)
|
||||
);
|
||||
|
||||
public static final Field field$Vec3i$z = requireNonNull(
|
||||
ReflectionUtils.getDeclaredField(clazz$Vec3i, int.class, 2)
|
||||
);
|
||||
// public static final Field field$Vec3i$x = requireNonNull(
|
||||
// ReflectionUtils.getDeclaredField(clazz$Vec3i, int.class, 0)
|
||||
// );
|
||||
//
|
||||
// public static final Field field$Vec3i$y = requireNonNull(
|
||||
// ReflectionUtils.getDeclaredField(clazz$Vec3i, int.class, 1)
|
||||
// );
|
||||
//
|
||||
// public static final Field field$Vec3i$z = requireNonNull(
|
||||
// ReflectionUtils.getDeclaredField(clazz$Vec3i, int.class, 2)
|
||||
// );
|
||||
|
||||
public static final Class<?> clazz$BlockState = requireNonNull(
|
||||
ReflectionUtils.getClazz(
|
||||
@@ -1597,11 +1597,11 @@ public class Reflections {
|
||||
)
|
||||
);
|
||||
|
||||
public static final Constructor<?> constructor$BlockPos = requireNonNull(
|
||||
ReflectionUtils.getConstructor(
|
||||
clazz$BlockPos, int.class, int.class, int.class
|
||||
)
|
||||
);
|
||||
// public static final Constructor<?> constructor$BlockPos = requireNonNull(
|
||||
// ReflectionUtils.getConstructor(
|
||||
// clazz$BlockPos, int.class, int.class, int.class
|
||||
// )
|
||||
// );
|
||||
|
||||
public static final Method method$Vec3i$relative = requireNonNull(
|
||||
ReflectionUtils.getMethod(
|
||||
@@ -2471,11 +2471,11 @@ public class Reflections {
|
||||
)
|
||||
);
|
||||
|
||||
public static final Method method$BlockGetter$getBlockState = requireNonNull(
|
||||
ReflectionUtils.getMethod(
|
||||
clazz$BlockGetter, clazz$BlockState, clazz$BlockPos
|
||||
)
|
||||
);
|
||||
// public static final Method method$BlockGetter$getBlockState = requireNonNull(
|
||||
// ReflectionUtils.getMethod(
|
||||
// clazz$BlockGetter, clazz$BlockState, clazz$BlockPos
|
||||
// )
|
||||
// );
|
||||
|
||||
public static final Method method$LevelAccessor$scheduleTick = requireNonNull(
|
||||
ReflectionUtils.getMethod(
|
||||
@@ -3435,6 +3435,7 @@ public class Reflections {
|
||||
)
|
||||
);
|
||||
|
||||
@Deprecated
|
||||
public static final Method method$Level$getCraftWorld = requireNonNull(
|
||||
ReflectionUtils.getMethod(
|
||||
clazz$Level, clazz$CraftWorld
|
||||
|
||||
@@ -49,7 +49,7 @@ mojang_brigadier_version=1.0.18
|
||||
byte_buddy_version=1.15.11
|
||||
snake_yaml_version=2.3
|
||||
anti_grief_version=0.13
|
||||
nms_helper_version=0.6
|
||||
nms_helper_version=0.10
|
||||
# Ignite Dependencies
|
||||
mixinextras_version=0.4.1
|
||||
mixin_version=0.15.2+mixin.0.8.7
|
||||
|
||||
Reference in New Issue
Block a user