use of net.minecraft.core.BlockPos in project Denizen-For-Bukkit by DenizenScript.
the class BlockHelperImpl method setNbtData.
@Override
public void setNbtData(Block block, CompoundTag ctag) {
CompoundTagBuilder builder = ctag.createBuilder();
builder.putInt("x", block.getX());
builder.putInt("y", block.getY());
builder.putInt("z", block.getZ());
ctag = builder.build();
BlockPos blockPos = new BlockPos(block.getX(), block.getY(), block.getZ());
BlockEntity te = ((CraftWorld) block.getWorld()).getHandle().getBlockEntity(blockPos, true);
te.load(((CompoundTagImpl) ctag).toNMSTag());
}
use of net.minecraft.core.BlockPos in project Denizen-For-Bukkit by DenizenScript.
the class DenizenNetworkManagerImpl method processShowFakeForPacket.
public boolean processShowFakeForPacket(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
if (FakeBlock.blocks.isEmpty()) {
return false;
}
try {
if (packet instanceof ClientboundLevelChunkPacket) {
FakeBlock.FakeBlockMap map = FakeBlock.blocks.get(player.getUUID());
if (map == null) {
return false;
}
int chunkX = ((ClientboundLevelChunkPacket) packet).getX();
int chunkZ = ((ClientboundLevelChunkPacket) packet).getZ();
ChunkCoordinate chunkCoord = new ChunkCoordinate(chunkX, chunkZ, player.getLevel().getWorld().getName());
List<FakeBlock> blocks = FakeBlock.getFakeBlocksFor(player.getUUID(), chunkCoord);
if (blocks == null || blocks.isEmpty()) {
return false;
}
ClientboundLevelChunkPacket newPacket = FakeBlockHelper.handleMapChunkPacket((ClientboundLevelChunkPacket) packet, blocks);
oldManager.send(newPacket, genericfuturelistener);
return true;
} else if (packet instanceof ClientboundSectionBlocksUpdatePacket) {
FakeBlock.FakeBlockMap map = FakeBlock.blocks.get(player.getUUID());
if (map == null) {
return false;
}
SectionPos coord = (SectionPos) SECTIONPOS_MULTIBLOCKCHANGE.get(packet);
ChunkCoordinate coordinateDenizen = new ChunkCoordinate(coord.getX(), coord.getZ(), player.getLevel().getWorld().getName());
if (!map.byChunk.containsKey(coordinateDenizen)) {
return false;
}
ClientboundSectionBlocksUpdatePacket newPacket = new ClientboundSectionBlocksUpdatePacket(copyPacket(packet));
LocationTag location = new LocationTag(player.getLevel().getWorld(), 0, 0, 0);
short[] originalOffsetArray = (short[]) OFFSETARRAY_MULTIBLOCKCHANGE.get(newPacket);
BlockState[] originalDataArray = (BlockState[]) BLOCKARRAY_MULTIBLOCKCHANGE.get(newPacket);
short[] offsetArray = Arrays.copyOf(originalOffsetArray, originalOffsetArray.length);
BlockState[] dataArray = Arrays.copyOf(originalDataArray, originalDataArray.length);
OFFSETARRAY_MULTIBLOCKCHANGE.set(newPacket, offsetArray);
BLOCKARRAY_MULTIBLOCKCHANGE.set(newPacket, dataArray);
for (int i = 0; i < offsetArray.length; i++) {
short offset = offsetArray[i];
BlockPos pos = coord.relativeToBlockPos(offset);
location.setX(pos.getX());
location.setY(pos.getY());
location.setZ(pos.getZ());
FakeBlock block = map.byLocation.get(location);
if (block != null) {
dataArray[i] = FakeBlockHelper.getNMSState(block);
}
}
oldManager.send(newPacket, genericfuturelistener);
return true;
} else if (packet instanceof ClientboundBlockUpdatePacket) {
BlockPos pos = ((ClientboundBlockUpdatePacket) packet).getPos();
LocationTag loc = new LocationTag(player.getLevel().getWorld(), pos.getX(), pos.getY(), pos.getZ());
FakeBlock block = FakeBlock.getFakeBlockFor(player.getUUID(), loc);
if (block != null) {
ClientboundBlockUpdatePacket newPacket = new ClientboundBlockUpdatePacket(((ClientboundBlockUpdatePacket) packet).getPos(), FakeBlockHelper.getNMSState(block));
oldManager.send(newPacket, genericfuturelistener);
return true;
}
} else if (packet instanceof ClientboundBlockBreakAckPacket) {
BlockPos pos = ((ClientboundBlockBreakAckPacket) packet).getPos();
LocationTag loc = new LocationTag(player.getLevel().getWorld(), pos.getX(), pos.getY(), pos.getZ());
FakeBlock block = FakeBlock.getFakeBlockFor(player.getUUID(), loc);
if (block != null) {
ClientboundBlockBreakAckPacket newPacket = new ClientboundBlockBreakAckPacket(copyPacket(packet));
BLOCKDATA_BLOCKBREAK.set(newPacket, FakeBlockHelper.getNMSState(block));
oldManager.send(newPacket, genericfuturelistener);
return true;
}
}
} catch (Exception ex) {
Debug.echoError(ex);
}
return false;
}
use of net.minecraft.core.BlockPos in project Denizen-For-Bukkit by DenizenScript.
the class WorldHelperImpl method getLocalDifficulty.
@Override
public float getLocalDifficulty(Location location) {
BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
DifficultyInstance scaler = ((CraftWorld) location.getWorld()).getHandle().getCurrentDifficultyAt(pos);
return scaler.getEffectiveDifficulty();
}
use of net.minecraft.core.BlockPos in project Denizen-For-Bukkit by DenizenScript.
the class BlockLightImpl method checkIfLightsBrokenByPacket.
public static void checkIfLightsBrokenByPacket(ClientboundBlockUpdatePacket packet, Level world) {
try {
BlockPos pos = packet.getPos();
int chunkX = pos.getX() >> 4;
int chunkZ = pos.getZ() >> 4;
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> {
LevelChunk chunk = world.getChunkAt(chunkX, chunkZ);
boolean any = false;
for (Vector vec : RELATIVE_CHUNKS) {
ChunkAccess other = world.getChunk(chunkX + vec.getBlockX(), chunkZ + vec.getBlockZ(), ChunkStatus.FULL, false);
if (other instanceof LevelChunk) {
List<BlockLight> lights = lightsByChunk.get(new ChunkCoordinate(((LevelChunk) other).bukkitChunk));
if (lights != null) {
any = true;
for (BlockLight light : lights) {
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> light.update(light.intendedLevel, false), 1);
}
}
}
}
if (any) {
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> sendNearbyChunkUpdates(chunk), 3);
}
}, 1);
} catch (Exception ex) {
Debug.echoError(ex);
}
}
use of net.minecraft.core.BlockPos in project Denizen-For-Bukkit by DenizenScript.
the class EntityHelperImpl method forceInteraction.
@Override
public void forceInteraction(Player player, Location location) {
CraftPlayer craftPlayer = (CraftPlayer) player;
BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
((CraftBlock) location.getBlock()).getNMS().use(((CraftWorld) location.getWorld()).getHandle(), craftPlayer != null ? craftPlayer.getHandle() : null, InteractionHand.MAIN_HAND, new BlockHitResult(new Vec3(0, 0, 0), null, pos, false));
}
Aggregations