mirror of
https://github.com/songoda/SongodaCore.git
synced 2025-02-02 12:41:32 +01:00
Replace #setBlockFast implementation and move into NMS modules
We need to check if FabledSkyBlock actually needs this and if it can be removed from the Core. I added a TODO-Comment for that.
This commit is contained in:
parent
3d20f439e1
commit
43148032a2
@ -1,17 +1,11 @@
|
||||
package com.songoda.core.utils;
|
||||
|
||||
import com.songoda.core.compatibility.ClassMapping;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.MethodMapping;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.EnumSet;
|
||||
@ -328,66 +322,6 @@ public class BlockUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* Only to be used by #setBlockFast */
|
||||
private static Class<?> clazzIBlockData, clazzBlocks, clazzCraftWorld, clazzBlockPosition;
|
||||
/* Only to be used by #setBlockFast */
|
||||
private static Method getHandle, getByCombinedId, setType, getChunkAt, getBlockData;
|
||||
|
||||
/**
|
||||
* Set a block to a certain type by updating the block directly in the
|
||||
* NMS chunk.
|
||||
* <p>
|
||||
* The chunk must be loaded and players must relog if they have the
|
||||
* chunk loaded in order to use this method.
|
||||
*/
|
||||
public static void setBlockFast(World world, int x, int y, int z, Material material, byte data) {
|
||||
try {
|
||||
// Cache reflection
|
||||
if (clazzIBlockData == null) {
|
||||
clazzIBlockData = ClassMapping.I_BLOCK_DATA.getClazz();
|
||||
clazzBlockPosition = ClassMapping.BLOCK_POSITION.getClazz();
|
||||
clazzCraftWorld = ClassMapping.CRAFT_WORLD.getClazz();
|
||||
clazzBlocks = ClassMapping.BLOCKS.getClazz();
|
||||
Class<?> clazzBlock = ClassMapping.BLOCK.getClazz();
|
||||
Class<?> clazzWorld = ClassMapping.WORLD.getClazz();
|
||||
Class<?> clazzChunk = ClassMapping.CHUNK.getClazz();
|
||||
|
||||
getHandle = clazzCraftWorld.getMethod("getHandle");
|
||||
getChunkAt = MethodMapping.WORLD__GET_CHUNK_AT.getMethod(clazzWorld);
|
||||
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
|
||||
getBlockData = MethodMapping.BLOCK__GET_BLOCK_DATA.getMethod(ClassMapping.BLOCK.getClazz());
|
||||
setType = MethodMapping.CHUNK__SET_BLOCK_STATE.getMethod(ClassMapping.CHUNK.getClazz());
|
||||
} else {
|
||||
getByCombinedId = clazzBlock.getMethod("getByCombinedId", int.class);
|
||||
setType = clazzChunk.getMethod("a", clazzBlockPosition, clazzIBlockData);
|
||||
}
|
||||
}
|
||||
|
||||
// invoke and cast objects.
|
||||
Object craftWorld = clazzCraftWorld.cast(world);
|
||||
Object nmsWorld = getHandle.invoke(craftWorld);
|
||||
Object chunk = getChunkAt.invoke(nmsWorld, x >> 4, z >> 4);
|
||||
Object blockPosition = clazzBlockPosition.getConstructor(int.class, int.class, int.class).newInstance(x & 0xF, y, z & 0xF);
|
||||
|
||||
// Invoke final method.
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
|
||||
Object block = clazzBlocks.getField(material.name()).get(null);
|
||||
Object IBlockData = getBlockData.invoke(block);
|
||||
setType.invoke(chunk, blockPosition, IBlockData, true);
|
||||
} else {
|
||||
Object IBlockData = getByCombinedId.invoke(null, material.getId() + (data << 12));
|
||||
setType.invoke(chunk, blockPosition, IBlockData);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setBlockFast(World world, int x, int y, int z, CompatibleMaterial material, byte data) {
|
||||
setBlockFast(world, x, y, z, material.getBlockMaterial(), data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a crop is at its max growth stage
|
||||
*
|
||||
@ -409,8 +343,7 @@ public class BlockUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
return block.getData() >= (mat == CompatibleMaterial.BEETROOTS
|
||||
|| mat == CompatibleMaterial.NETHER_WART ? 3 : 7);
|
||||
return block.getData() >= (mat == CompatibleMaterial.BEETROOTS || mat == CompatibleMaterial.NETHER_WART ? 3 : 7);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -459,8 +392,7 @@ public class BlockUtils {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return (mat == CompatibleMaterial.BEETROOTS
|
||||
|| mat == CompatibleMaterial.NETHER_WART ? 3 : 7);
|
||||
return (mat == CompatibleMaterial.BEETROOTS || mat == CompatibleMaterial.NETHER_WART ? 3 : 7);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,9 +1,20 @@
|
||||
package com.songoda.core.nms.world;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SWorld {
|
||||
List<LivingEntity> getLivingEntities();
|
||||
|
||||
/**
|
||||
* Set a block to a certain type by updating the block directly in the NMS chunk.
|
||||
* <br>
|
||||
* The chunk must be loaded and players must relog if they have the chunk loaded in order to use this method.
|
||||
* (F3+A is not enough)
|
||||
*/
|
||||
// TODO: Check if FabledSkyBlock *really* needs this method and if it can be removed.
|
||||
// Would make thinks less complicated and I kinda cannot imagine it being *that* much faster to be worth it?
|
||||
void setBlockFast(int x, int y, int z, Material material);
|
||||
}
|
||||
|
@ -1,17 +1,35 @@
|
||||
package com.songoda.core.nms.v1_10_R1.world;
|
||||
|
||||
import com.songoda.core.nms.world.SWorld;
|
||||
import net.minecraft.server.v1_10_R1.Block;
|
||||
import net.minecraft.server.v1_10_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_10_R1.Chunk;
|
||||
import net.minecraft.server.v1_10_R1.WorldServer;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_10_R1.CraftWorld;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SWorldImpl implements SWorld {
|
||||
public SWorldImpl() {
|
||||
private final World world;
|
||||
|
||||
public SWorldImpl(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LivingEntity> getLivingEntities() {
|
||||
return new ArrayList<>();
|
||||
return new ArrayList<>(); // FIXME
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockFast(int x, int y, int z, Material material) {
|
||||
WorldServer serverLevel = ((CraftWorld) this.world).getHandle();
|
||||
Chunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4);
|
||||
|
||||
levelChunk.a(new BlockPosition(x & 0xF, y, z & 0xF), Block.getByCombinedId(0));
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SWorld getWorld(World world) {
|
||||
return new SWorldImpl();
|
||||
return new SWorldImpl(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,17 +1,35 @@
|
||||
package com.songoda.core.nms.v1_11_R1.world;
|
||||
|
||||
import com.songoda.core.nms.world.SWorld;
|
||||
import net.minecraft.server.v1_11_R1.Block;
|
||||
import net.minecraft.server.v1_11_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_11_R1.Chunk;
|
||||
import net.minecraft.server.v1_11_R1.WorldServer;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.CraftWorld;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SWorldImpl implements SWorld {
|
||||
public SWorldImpl() {
|
||||
private final World world;
|
||||
|
||||
public SWorldImpl(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LivingEntity> getLivingEntities() {
|
||||
return new ArrayList<>();
|
||||
return new ArrayList<>(); // FIXME
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockFast(int x, int y, int z, Material material) {
|
||||
WorldServer serverLevel = ((CraftWorld) this.world).getHandle();
|
||||
Chunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4);
|
||||
|
||||
levelChunk.a(new BlockPosition(x & 0xF, y, z & 0xF), Block.getByCombinedId(0));
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SWorld getWorld(World world) {
|
||||
return new SWorldImpl();
|
||||
return new SWorldImpl(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,17 +1,35 @@
|
||||
package com.songoda.core.nms.v1_12_R1.world;
|
||||
|
||||
import com.songoda.core.nms.world.SWorld;
|
||||
import net.minecraft.server.v1_12_R1.Block;
|
||||
import net.minecraft.server.v1_12_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_12_R1.Chunk;
|
||||
import net.minecraft.server.v1_12_R1.WorldServer;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SWorldImpl implements SWorld {
|
||||
public SWorldImpl() {
|
||||
private final World world;
|
||||
|
||||
public SWorldImpl(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LivingEntity> getLivingEntities() {
|
||||
return new ArrayList<>();
|
||||
return new ArrayList<>(); // FIXME
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockFast(int x, int y, int z, Material material) {
|
||||
WorldServer serverLevel = ((CraftWorld) this.world).getHandle();
|
||||
Chunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4);
|
||||
|
||||
levelChunk.a(new BlockPosition(x & 0xF, y, z & 0xF), Block.getByCombinedId(0));
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SWorld getWorld(World world) {
|
||||
return new SWorldImpl();
|
||||
return new SWorldImpl(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,17 +1,37 @@
|
||||
package com.songoda.core.nms.v1_13_R1.world;
|
||||
|
||||
import com.songoda.core.nms.world.SWorld;
|
||||
import net.minecraft.server.v1_13_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_13_R1.Chunk;
|
||||
import net.minecraft.server.v1_13_R1.IBlockData;
|
||||
import net.minecraft.server.v1_13_R1.WorldServer;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_13_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_13_R1.block.data.CraftBlockData;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SWorldImpl implements SWorld {
|
||||
public SWorldImpl() {
|
||||
private final World world;
|
||||
|
||||
public SWorldImpl(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LivingEntity> getLivingEntities() {
|
||||
return new ArrayList<>();
|
||||
return new ArrayList<>(); // FIXME
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockFast(int x, int y, int z, Material material) {
|
||||
WorldServer serverLevel = ((CraftWorld) this.world).getHandle();
|
||||
Chunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4);
|
||||
IBlockData blockState = ((CraftBlockData) material.createBlockData()).getState();
|
||||
|
||||
levelChunk.a(new BlockPosition(x & 0xF, y, z & 0xF), blockState, true);
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SWorld getWorld(World world) {
|
||||
return new SWorldImpl();
|
||||
return new SWorldImpl(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,17 +1,37 @@
|
||||
package com.songoda.core.nms.v1_13_R2.world;
|
||||
|
||||
import com.songoda.core.nms.world.SWorld;
|
||||
import net.minecraft.server.v1_13_R2.BlockPosition;
|
||||
import net.minecraft.server.v1_13_R2.Chunk;
|
||||
import net.minecraft.server.v1_13_R2.IBlockData;
|
||||
import net.minecraft.server.v1_13_R2.WorldServer;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_13_R2.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_13_R2.block.data.CraftBlockData;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SWorldImpl implements SWorld {
|
||||
public SWorldImpl() {
|
||||
private final World world;
|
||||
|
||||
public SWorldImpl(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LivingEntity> getLivingEntities() {
|
||||
return new ArrayList<>();
|
||||
return new ArrayList<>(); // FIXME
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockFast(int x, int y, int z, Material material) {
|
||||
WorldServer serverLevel = ((CraftWorld) this.world).getHandle();
|
||||
Chunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4);
|
||||
IBlockData blockState = ((CraftBlockData) material.createBlockData()).getState();
|
||||
|
||||
levelChunk.setType(new BlockPosition(x & 0xF, y, z & 0xF), blockState, true);
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SWorld getWorld(World world) {
|
||||
return new SWorldImpl();
|
||||
return new SWorldImpl(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,17 +1,37 @@
|
||||
package com.songoda.core.nms.v1_14_R1.world;
|
||||
|
||||
import com.songoda.core.nms.world.SWorld;
|
||||
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_14_R1.Chunk;
|
||||
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||
import net.minecraft.server.v1_14_R1.WorldServer;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.block.data.CraftBlockData;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SWorldImpl implements SWorld {
|
||||
public SWorldImpl() {
|
||||
private final World world;
|
||||
|
||||
public SWorldImpl(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LivingEntity> getLivingEntities() {
|
||||
return new ArrayList<>();
|
||||
return new ArrayList<>(); // FIXME
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockFast(int x, int y, int z, Material material) {
|
||||
WorldServer serverLevel = ((CraftWorld) this.world).getHandle();
|
||||
Chunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4);
|
||||
IBlockData blockState = ((CraftBlockData) material.createBlockData()).getState();
|
||||
|
||||
levelChunk.setType(new BlockPosition(x & 0xF, y, z & 0xF), blockState, true);
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SWorld getWorld(World world) {
|
||||
return new SWorldImpl();
|
||||
return new SWorldImpl(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,17 +1,37 @@
|
||||
package com.songoda.core.nms.v1_15_R1.world;
|
||||
|
||||
import com.songoda.core.nms.world.SWorld;
|
||||
import net.minecraft.server.v1_15_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_15_R1.Chunk;
|
||||
import net.minecraft.server.v1_15_R1.IBlockData;
|
||||
import net.minecraft.server.v1_15_R1.WorldServer;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SWorldImpl implements SWorld {
|
||||
public SWorldImpl() {
|
||||
private final World world;
|
||||
|
||||
public SWorldImpl(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LivingEntity> getLivingEntities() {
|
||||
return new ArrayList<>();
|
||||
return new ArrayList<>(); // FIXME
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockFast(int x, int y, int z, Material material) {
|
||||
WorldServer serverLevel = ((CraftWorld) this.world).getHandle();
|
||||
Chunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4);
|
||||
IBlockData blockState = ((CraftBlockData) material.createBlockData()).getState();
|
||||
|
||||
levelChunk.setType(new BlockPosition(x & 0xF, y, z & 0xF), blockState, true);
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SWorld getWorld(World world) {
|
||||
return new SWorldImpl();
|
||||
return new SWorldImpl(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,17 +1,37 @@
|
||||
package com.songoda.core.nms.v1_16_R1.world;
|
||||
|
||||
import com.songoda.core.nms.world.SWorld;
|
||||
import net.minecraft.server.v1_16_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_16_R1.Chunk;
|
||||
import net.minecraft.server.v1_16_R1.IBlockData;
|
||||
import net.minecraft.server.v1_16_R1.WorldServer;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.block.data.CraftBlockData;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SWorldImpl implements SWorld {
|
||||
public SWorldImpl() {
|
||||
private final World world;
|
||||
|
||||
public SWorldImpl(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LivingEntity> getLivingEntities() {
|
||||
return new ArrayList<>();
|
||||
return new ArrayList<>(); // FIXME
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockFast(int x, int y, int z, Material material) {
|
||||
WorldServer serverLevel = ((CraftWorld) this.world).getHandle();
|
||||
Chunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4);
|
||||
IBlockData blockState = ((CraftBlockData) material.createBlockData()).getState();
|
||||
|
||||
levelChunk.setType(new BlockPosition(x & 0xF, y, z & 0xF), blockState, true);
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SWorld getWorld(World world) {
|
||||
return new SWorldImpl();
|
||||
return new SWorldImpl(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,17 +1,37 @@
|
||||
package com.songoda.core.nms.v1_16_R2.world;
|
||||
|
||||
import com.songoda.core.nms.world.SWorld;
|
||||
import net.minecraft.server.v1_16_R2.BlockPosition;
|
||||
import net.minecraft.server.v1_16_R2.Chunk;
|
||||
import net.minecraft.server.v1_16_R2.IBlockData;
|
||||
import net.minecraft.server.v1_16_R2.WorldServer;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.block.data.CraftBlockData;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SWorldImpl implements SWorld {
|
||||
public SWorldImpl() {
|
||||
private final World world;
|
||||
|
||||
public SWorldImpl(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LivingEntity> getLivingEntities() {
|
||||
return new ArrayList<>();
|
||||
return new ArrayList<>(); // FIXME
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockFast(int x, int y, int z, Material material) {
|
||||
WorldServer serverLevel = ((CraftWorld) this.world).getHandle();
|
||||
Chunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4);
|
||||
IBlockData blockState = ((CraftBlockData) material.createBlockData()).getState();
|
||||
|
||||
levelChunk.setType(new BlockPosition(x & 0xF, y, z & 0xF), blockState, true);
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SWorld getWorld(World world) {
|
||||
return new SWorldImpl();
|
||||
return new SWorldImpl(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,17 +1,37 @@
|
||||
package com.songoda.core.nms.v1_16_R3.world;
|
||||
|
||||
import com.songoda.core.nms.world.SWorld;
|
||||
import net.minecraft.server.v1_16_R3.BlockPosition;
|
||||
import net.minecraft.server.v1_16_R3.Chunk;
|
||||
import net.minecraft.server.v1_16_R3.IBlockData;
|
||||
import net.minecraft.server.v1_16_R3.WorldServer;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.block.data.CraftBlockData;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SWorldImpl implements SWorld {
|
||||
public SWorldImpl() {
|
||||
private final World world;
|
||||
|
||||
public SWorldImpl(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LivingEntity> getLivingEntities() {
|
||||
return new ArrayList<>();
|
||||
return new ArrayList<>(); // FIXME
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockFast(int x, int y, int z, Material material) {
|
||||
WorldServer serverLevel = ((CraftWorld) this.world).getHandle();
|
||||
Chunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4);
|
||||
IBlockData blockState = ((CraftBlockData) material.createBlockData()).getState();
|
||||
|
||||
levelChunk.setType(new BlockPosition(x & 0xF, y, z & 0xF), blockState, true);
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SWorld getWorld(World world) {
|
||||
return new SWorldImpl();
|
||||
return new SWorldImpl(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,12 +1,17 @@
|
||||
package com.songoda.core.nms.v1_17_R1.world;
|
||||
|
||||
import com.songoda.core.nms.world.SWorld;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.server.level.WorldServer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.block.state.IBlockData;
|
||||
import net.minecraft.world.level.chunk.Chunk;
|
||||
import net.minecraft.world.level.entity.LevelEntityGetter;
|
||||
import net.minecraft.world.level.entity.PersistentEntitySectionManager;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@ -37,9 +42,8 @@ public class SWorldImpl implements SWorld {
|
||||
List<LivingEntity> list = new ArrayList<>();
|
||||
try {
|
||||
|
||||
WorldServer worldServer = ((CraftWorld) world).getHandle();
|
||||
LevelEntityGetter<net.minecraft.world.entity.Entity> entities =
|
||||
((PersistentEntitySectionManager<Entity>) fieldG.get(worldServer)).d();
|
||||
WorldServer worldServer = ((CraftWorld) this.world).getHandle();
|
||||
LevelEntityGetter<net.minecraft.world.entity.Entity> entities = ((PersistentEntitySectionManager<Entity>) fieldG.get(worldServer)).d();
|
||||
|
||||
entities.a().forEach((mcEnt) -> {
|
||||
org.bukkit.entity.Entity bukkitEntity = mcEnt.getBukkitEntity();
|
||||
@ -53,4 +57,13 @@ public class SWorldImpl implements SWorld {
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockFast(int x, int y, int z, Material material) {
|
||||
WorldServer serverLevel = ((CraftWorld) this.world).getHandle();
|
||||
Chunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4);
|
||||
IBlockData blockState = ((CraftBlockData) material.createBlockData()).getState();
|
||||
|
||||
levelChunk.setType(new BlockPosition(x & 0xF, y, z & 0xF), blockState, true);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,15 @@
|
||||
package com.songoda.core.nms.v1_18_R1.world;
|
||||
|
||||
import com.songoda.core.nms.world.SWorld;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.server.level.WorldServer;
|
||||
import net.minecraft.world.level.block.state.IBlockData;
|
||||
import net.minecraft.world.level.chunk.Chunk;
|
||||
import net.minecraft.world.level.entity.LevelEntityGetter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.block.data.CraftBlockData;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -21,7 +26,7 @@ public class SWorldImpl implements SWorld {
|
||||
public List<LivingEntity> getLivingEntities() {
|
||||
List<LivingEntity> result = new ArrayList<>();
|
||||
|
||||
WorldServer worldServer = ((CraftWorld) world).getHandle();
|
||||
WorldServer worldServer = ((CraftWorld) this.world).getHandle();
|
||||
LevelEntityGetter<net.minecraft.world.entity.Entity> entities = worldServer.P.d();
|
||||
|
||||
entities.a().forEach((mcEnt) -> {
|
||||
@ -34,4 +39,13 @@ public class SWorldImpl implements SWorld {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockFast(int x, int y, int z, Material material) {
|
||||
WorldServer serverLevel = ((CraftWorld) this.world).getHandle();
|
||||
Chunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4);
|
||||
IBlockData blockState = ((CraftBlockData) material.createBlockData()).getState();
|
||||
|
||||
levelChunk.a(new BlockPosition(x & 0xF, y, z & 0xF), blockState, true);
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,16 @@
|
||||
package com.songoda.core.nms.v1_18_R2.world;
|
||||
|
||||
import com.songoda.core.nms.world.SWorld;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraft.world.level.entity.LevelEntityGetter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -22,8 +27,8 @@ public class SWorldImpl implements SWorld {
|
||||
public List<LivingEntity> getLivingEntities() {
|
||||
List<LivingEntity> result = new ArrayList<>();
|
||||
|
||||
ServerLevel worldServer = ((CraftWorld) world).getHandle();
|
||||
LevelEntityGetter<Entity> entities = worldServer.entityManager.getEntityGetter();
|
||||
ServerLevel serverLevel = ((CraftWorld) this.world).getHandle();
|
||||
LevelEntityGetter<Entity> entities = serverLevel.entityManager.getEntityGetter();
|
||||
|
||||
entities.getAll().forEach((mcEnt) -> {
|
||||
org.bukkit.entity.Entity bukkitEntity = mcEnt.getBukkitEntity();
|
||||
@ -35,4 +40,13 @@ public class SWorldImpl implements SWorld {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockFast(int x, int y, int z, Material material) {
|
||||
ServerLevel serverLevel = ((CraftWorld) this.world).getHandle();
|
||||
LevelChunk levelChunk = serverLevel.getChunk(x >> 4, z >> 4);
|
||||
BlockState blockState = ((CraftBlockData) material.createBlockData()).getState();
|
||||
|
||||
levelChunk.setBlockState(new BlockPos(x & 0xF, y, z & 0xF), blockState, true);
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,16 @@
|
||||
package com.songoda.core.nms.v1_19_R1.world;
|
||||
|
||||
import com.songoda.core.nms.world.SWorld;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraft.world.level.entity.LevelEntityGetter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.block.data.CraftBlockData;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -22,7 +27,7 @@ public class SWorldImpl implements SWorld {
|
||||
public List<LivingEntity> getLivingEntities() {
|
||||
List<LivingEntity> result = new ArrayList<>();
|
||||
|
||||
ServerLevel worldServer = ((CraftWorld) world).getHandle();
|
||||
ServerLevel worldServer = ((CraftWorld) this.world).getHandle();
|
||||
LevelEntityGetter<Entity> entities = worldServer.entityManager.getEntityGetter();
|
||||
|
||||
entities.getAll().forEach((mcEnt) -> {
|
||||
@ -35,4 +40,13 @@ public class SWorldImpl implements SWorld {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockFast(int x, int y, int z, Material material) {
|
||||
ServerLevel serverLevel = ((CraftWorld) this.world).getHandle();
|
||||
LevelChunk levelChunk = serverLevel.getChunk(x >> 4, z >> 4);
|
||||
BlockState blockState = ((CraftBlockData) material.createBlockData()).getState();
|
||||
|
||||
levelChunk.setBlockState(new BlockPos(x & 0xF, y, z & 0xF), blockState, true);
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,35 @@
|
||||
package com.songoda.core.nms.v1_8_R1.world;
|
||||
|
||||
import com.songoda.core.nms.world.SWorld;
|
||||
import net.minecraft.server.v1_8_R1.Block;
|
||||
import net.minecraft.server.v1_8_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_8_R1.Chunk;
|
||||
import net.minecraft.server.v1_8_R1.WorldServer;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.CraftWorld;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SWorldImpl implements SWorld {
|
||||
public SWorldImpl() {
|
||||
private final World world;
|
||||
|
||||
public SWorldImpl(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LivingEntity> getLivingEntities() {
|
||||
return new ArrayList<>();
|
||||
return new ArrayList<>(); // FIXME
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockFast(int x, int y, int z, Material material) {
|
||||
WorldServer serverLevel = ((CraftWorld) this.world).getHandle();
|
||||
Chunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4);
|
||||
|
||||
levelChunk.a(new BlockPosition(x & 0xF, y, z & 0xF), Block.getByCombinedId(0));
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SWorld getWorld(World world) {
|
||||
return new SWorldImpl();
|
||||
return new SWorldImpl(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,17 +1,35 @@
|
||||
package com.songoda.core.nms.v1_8_R2.world;
|
||||
|
||||
import com.songoda.core.nms.world.SWorld;
|
||||
import net.minecraft.server.v1_8_R2.Block;
|
||||
import net.minecraft.server.v1_8_R2.BlockPosition;
|
||||
import net.minecraft.server.v1_8_R2.Chunk;
|
||||
import net.minecraft.server.v1_8_R2.WorldServer;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_8_R2.CraftWorld;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SWorldImpl implements SWorld {
|
||||
public SWorldImpl() {
|
||||
private final World world;
|
||||
|
||||
public SWorldImpl(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LivingEntity> getLivingEntities() {
|
||||
return new ArrayList<>();
|
||||
return new ArrayList<>(); // FIXME
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockFast(int x, int y, int z, Material material) {
|
||||
WorldServer serverLevel = ((CraftWorld) this.world).getHandle();
|
||||
Chunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4);
|
||||
|
||||
levelChunk.a(new BlockPosition(x & 0xF, y, z & 0xF), Block.getByCombinedId(0));
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SWorld getWorld(World world) {
|
||||
return new SWorldImpl();
|
||||
return new SWorldImpl(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,17 +1,35 @@
|
||||
package com.songoda.core.nms.v1_8_R3.world;
|
||||
|
||||
import com.songoda.core.nms.world.SWorld;
|
||||
import net.minecraft.server.v1_8_R3.Block;
|
||||
import net.minecraft.server.v1_8_R3.BlockPosition;
|
||||
import net.minecraft.server.v1_8_R3.Chunk;
|
||||
import net.minecraft.server.v1_8_R3.WorldServer;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SWorldImpl implements SWorld {
|
||||
public SWorldImpl() {
|
||||
private final World world;
|
||||
|
||||
public SWorldImpl(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LivingEntity> getLivingEntities() {
|
||||
return new ArrayList<>();
|
||||
return new ArrayList<>(); // FIXME
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockFast(int x, int y, int z, Material material) {
|
||||
WorldServer serverLevel = ((CraftWorld) this.world).getHandle();
|
||||
Chunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4);
|
||||
|
||||
levelChunk.a(new BlockPosition(x & 0xF, y, z & 0xF), Block.getByCombinedId(0));
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SWorld getWorld(World world) {
|
||||
return new SWorldImpl();
|
||||
return new SWorldImpl(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,17 +1,35 @@
|
||||
package com.songoda.core.nms.v1_9_R1.world;
|
||||
|
||||
import com.songoda.core.nms.world.SWorld;
|
||||
import net.minecraft.server.v1_9_R1.Block;
|
||||
import net.minecraft.server.v1_9_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_9_R1.Chunk;
|
||||
import net.minecraft.server.v1_9_R1.WorldServer;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.CraftWorld;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SWorldImpl implements SWorld {
|
||||
public SWorldImpl() {
|
||||
private final World world;
|
||||
|
||||
public SWorldImpl(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LivingEntity> getLivingEntities() {
|
||||
return new ArrayList<>();
|
||||
return new ArrayList<>(); // FIXME
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockFast(int x, int y, int z, Material material) {
|
||||
WorldServer serverLevel = ((CraftWorld) this.world).getHandle();
|
||||
Chunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4);
|
||||
|
||||
levelChunk.a(new BlockPosition(x & 0xF, y, z & 0xF), Block.getByCombinedId(0));
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SWorld getWorld(World world) {
|
||||
return new SWorldImpl();
|
||||
return new SWorldImpl(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,17 +1,35 @@
|
||||
package com.songoda.core.nms.v1_9_R2.world;
|
||||
|
||||
import com.songoda.core.nms.world.SWorld;
|
||||
import net.minecraft.server.v1_9_R2.Block;
|
||||
import net.minecraft.server.v1_9_R2.BlockPosition;
|
||||
import net.minecraft.server.v1_9_R2.Chunk;
|
||||
import net.minecraft.server.v1_9_R2.WorldServer;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_9_R2.CraftWorld;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SWorldImpl implements SWorld {
|
||||
public SWorldImpl() {
|
||||
private final World world;
|
||||
|
||||
public SWorldImpl(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LivingEntity> getLivingEntities() {
|
||||
return new ArrayList<>();
|
||||
return new ArrayList<>(); // FIXME
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockFast(int x, int y, int z, Material material) {
|
||||
WorldServer serverLevel = ((CraftWorld) this.world).getHandle();
|
||||
Chunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4);
|
||||
|
||||
levelChunk.a(new BlockPosition(x & 0xF, y, z & 0xF), Block.getByCombinedId(0));
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ public class WorldCoreImpl implements WorldCore {
|
||||
|
||||
@Override
|
||||
public SWorld getWorld(World world) {
|
||||
return new SWorldImpl();
|
||||
return new SWorldImpl(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user