Search in sources :

Example 1 with WorldServer

use of net.minecraft.server.level.WorldServer in project Crazy-Crates by Crazy-Crew.

the class StructureService method createSingleStructure.

/**
 * Creates a single structure of maximum 32x32x32 blocks. If you need a larger area, use {@link #createStructuresArray(Location[], String)}
 * @param corners - The edges of the area (order doesn't matter)
 * @param author - The listed author of the structure
 * @return DefinedStructure - The new structure instance
 */
public static DefinedStructure createSingleStructure(Location[] corners, String author) {
    if (corners.length != 2)
        throw new IllegalArgumentException("An area needs to be set up by exactly 2 opposite edges!");
    Location[] normalized = normalizeEdges(corners[0], corners[1]);
    WorldServer world = ((CraftWorld) normalized[0].getWorld()).getHandle();
    int[] dimensions = getDimensions(normalized);
    if (dimensions[0] > 32 || dimensions[1] > 32 || dimensions[2] > 32)
        throw new IllegalArgumentException("A single structure can only be 32x32x32! If you need more, use #createStructuresArea.");
    DefinedStructure structure = new DefinedStructure();
    structure.a(world, new BlockPosition(normalized[0].getBlockX(), normalized[0].getBlockY(), normalized[0].getBlockZ()), new BlockPosition(dimensions[0], dimensions[1], dimensions[2]), true, Blocks.jb);
    structure.a(author);
    return structure;
}
Also used : DefinedStructure(net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructure) BlockPosition(net.minecraft.core.BlockPosition) WorldServer(net.minecraft.server.level.WorldServer) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld) Location(org.bukkit.Location)

Example 2 with WorldServer

use of net.minecraft.server.level.WorldServer in project InteractionVisualizer by LOOHP.

the class V1_17 method getBoundingBoxes.

@SuppressWarnings("unchecked")
public List<BoundingBox> getBoundingBoxes(BlockPosition pos) {
    net.minecraft.core.BlockPosition blockpos = new net.minecraft.core.BlockPosition(pos.getX(), pos.getY(), pos.getZ());
    WorldServer world = ((CraftWorld) pos.getWorld()).getHandle();
    try {
        VoxelShape shape = (VoxelShape) blockDataGetShape.invoke(worldServerGetType.invoke(blockpos), world, blockpos);
        return ((List<AxisAlignedBB>) voxelShapeGetAABBList.invoke(shape)).stream().map(each -> new BoundingBox(each.a + pos.getX(), each.b + pos.getY(), each.c + pos.getZ(), each.d + pos.getX(), each.e + pos.getY(), each.f + pos.getZ())).collect(Collectors.toList());
    } catch (Exception e) {
        List<BoundingBox> boxes = new ArrayList<>();
        boxes.add(BoundingBox.of(pos.getBlock()));
        return boxes;
    }
}
Also used : BlockData(net.minecraft.world.level.block.state.BlockBase.BlockData) WorldServer(net.minecraft.server.level.WorldServer) BlockPosition(com.loohp.interactionvisualizer.objectholders.BlockPosition) IBlockAccess(net.minecraft.world.level.IBlockAccess) Item(org.bukkit.entity.Item) PacketPlayOutEntityDestroy(net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy) PacketPlayOutEntityEquipment(net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment) ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) Chunk(net.minecraft.world.level.chunk.Chunk) CraftItem(org.bukkit.craftbukkit.v1_17_R1.entity.CraftItem) TileEntityType(com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType) World(org.bukkit.World) Map(java.util.Map) WrappedIterable(com.loohp.interactionvisualizer.objectholders.WrappedIterable) Method(java.lang.reflect.Method) Material(org.bukkit.Material) EquipmentSlot(org.bukkit.inventory.EquipmentSlot) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) CraftChunk(org.bukkit.craftbukkit.v1_17_R1.CraftChunk) ChunkPosition(com.loohp.interactionvisualizer.objectholders.ChunkPosition) EntityItem(net.minecraft.world.entity.item.EntityItem) LevelEntityGetter(net.minecraft.world.level.entity.LevelEntityGetter) CraftMagicNumbers(org.bukkit.craftbukkit.v1_17_R1.util.CraftMagicNumbers) InteractionVisualizer(com.loohp.interactionvisualizer.InteractionVisualizer) Entity(org.bukkit.entity.Entity) ValuePairs(com.loohp.interactionvisualizer.objectholders.ValuePairs) BoundingBox(com.loohp.interactionvisualizer.objectholders.BoundingBox) TileEntity(com.loohp.interactionvisualizer.objectholders.TileEntity) AxisAlignedBB(net.minecraft.world.phys.AxisAlignedBB) PacketType(com.comphenix.protocol.PacketType) Field(java.lang.reflect.Field) Collectors(java.util.stream.Collectors) Pair(com.mojang.datafixers.util.Pair) ItemStack(org.bukkit.inventory.ItemStack) InvocationTargetException(java.lang.reflect.InvocationTargetException) NMSTileEntitySet(com.loohp.interactionvisualizer.objectholders.NMSTileEntitySet) PacketContainer(com.comphenix.protocol.events.PacketContainer) List(java.util.List) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld) VoxelShape(net.minecraft.world.phys.shapes.VoxelShape) EnumItemSlot(net.minecraft.world.entity.EnumItemSlot) CraftItemStack(org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack) BlockPosition(com.loohp.interactionvisualizer.objectholders.BlockPosition) WorldServer(net.minecraft.server.level.WorldServer) InvocationTargetException(java.lang.reflect.InvocationTargetException) VoxelShape(net.minecraft.world.phys.shapes.VoxelShape) BoundingBox(com.loohp.interactionvisualizer.objectholders.BoundingBox) ArrayList(java.util.ArrayList) List(java.util.List) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld)

Example 3 with WorldServer

use of net.minecraft.server.level.WorldServer in project InteractionVisualizer by LOOHP.

the class V1_18 method getBoundingBoxes.

@SuppressWarnings("unchecked")
public List<BoundingBox> getBoundingBoxes(BlockPosition pos) {
    net.minecraft.core.BlockPosition blockpos = new net.minecraft.core.BlockPosition(pos.getX(), pos.getY(), pos.getZ());
    WorldServer world = ((CraftWorld) pos.getWorld()).getHandle();
    VoxelShape shape = world.a_(blockpos).j(world, blockpos);
    try {
        return ((List<AxisAlignedBB>) voxelShapeGetAABBList.invoke(shape)).stream().map(each -> new BoundingBox(each.a + pos.getX(), each.b + pos.getY(), each.c + pos.getZ(), each.d + pos.getX(), each.e + pos.getY(), each.f + pos.getZ())).collect(Collectors.toList());
    } catch (Exception e) {
        List<BoundingBox> boxes = new ArrayList<>();
        boxes.add(BoundingBox.of(pos.getBlock()));
        return boxes;
    }
}
Also used : WorldServer(net.minecraft.server.level.WorldServer) BlockPosition(com.loohp.interactionvisualizer.objectholders.BlockPosition) Item(org.bukkit.entity.Item) CraftItemStack(org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack) PacketPlayOutEntityDestroy(net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy) PacketPlayOutEntityEquipment(net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment) ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) CraftMagicNumbers(org.bukkit.craftbukkit.v1_18_R1.util.CraftMagicNumbers) TileEntityType(com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType) World(org.bukkit.World) WrappedIterable(com.loohp.interactionvisualizer.objectholders.WrappedIterable) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld) Method(java.lang.reflect.Method) Material(org.bukkit.Material) EquipmentSlot(org.bukkit.inventory.EquipmentSlot) CraftChunk(org.bukkit.craftbukkit.v1_18_R1.CraftChunk) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ChunkPosition(com.loohp.interactionvisualizer.objectholders.ChunkPosition) EntityItem(net.minecraft.world.entity.item.EntityItem) InteractionVisualizer(com.loohp.interactionvisualizer.InteractionVisualizer) Entity(org.bukkit.entity.Entity) ValuePairs(com.loohp.interactionvisualizer.objectholders.ValuePairs) BoundingBox(com.loohp.interactionvisualizer.objectholders.BoundingBox) TileEntity(com.loohp.interactionvisualizer.objectholders.TileEntity) AxisAlignedBB(net.minecraft.world.phys.AxisAlignedBB) PacketType(com.comphenix.protocol.PacketType) Field(java.lang.reflect.Field) Collectors(java.util.stream.Collectors) Pair(com.mojang.datafixers.util.Pair) ItemStack(org.bukkit.inventory.ItemStack) InvocationTargetException(java.lang.reflect.InvocationTargetException) NMSTileEntitySet(com.loohp.interactionvisualizer.objectholders.NMSTileEntitySet) PacketContainer(com.comphenix.protocol.events.PacketContainer) List(java.util.List) PersistentEntitySectionManager(net.minecraft.world.level.entity.PersistentEntitySectionManager) VoxelShape(net.minecraft.world.phys.shapes.VoxelShape) Collections(java.util.Collections) EnumItemSlot(net.minecraft.world.entity.EnumItemSlot) CraftItem(org.bukkit.craftbukkit.v1_18_R1.entity.CraftItem) BlockPosition(com.loohp.interactionvisualizer.objectholders.BlockPosition) WorldServer(net.minecraft.server.level.WorldServer) InvocationTargetException(java.lang.reflect.InvocationTargetException) VoxelShape(net.minecraft.world.phys.shapes.VoxelShape) BoundingBox(com.loohp.interactionvisualizer.objectholders.BoundingBox) ArrayList(java.util.ArrayList) List(java.util.List) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld)

Example 4 with WorldServer

use of net.minecraft.server.level.WorldServer in project InteractionVisualizer by LOOHP.

the class V1_18_2 method getBoundingBoxes.

@SuppressWarnings("unchecked")
public List<BoundingBox> getBoundingBoxes(BlockPosition pos) {
    net.minecraft.core.BlockPosition blockpos = new net.minecraft.core.BlockPosition(pos.getX(), pos.getY(), pos.getZ());
    WorldServer world = ((CraftWorld) pos.getWorld()).getHandle();
    VoxelShape shape = world.a_(blockpos).j(world, blockpos);
    try {
        return ((List<AxisAlignedBB>) voxelShapeGetAABBList.invoke(shape)).stream().map(each -> new BoundingBox(each.a + pos.getX(), each.b + pos.getY(), each.c + pos.getZ(), each.d + pos.getX(), each.e + pos.getY(), each.f + pos.getZ())).collect(Collectors.toList());
    } catch (Exception e) {
        List<BoundingBox> boxes = new ArrayList<>();
        boxes.add(BoundingBox.of(pos.getBlock()));
        return boxes;
    }
}
Also used : WorldServer(net.minecraft.server.level.WorldServer) BlockPosition(com.loohp.interactionvisualizer.objectholders.BlockPosition) Item(org.bukkit.entity.Item) PacketPlayOutEntityDestroy(net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy) PacketPlayOutEntityEquipment(net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld) CraftChunk(org.bukkit.craftbukkit.v1_18_R2.CraftChunk) ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) TileEntityType(com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType) World(org.bukkit.World) WrappedIterable(com.loohp.interactionvisualizer.objectholders.WrappedIterable) Method(java.lang.reflect.Method) Material(org.bukkit.Material) EquipmentSlot(org.bukkit.inventory.EquipmentSlot) ChunkPosition(com.loohp.interactionvisualizer.objectholders.ChunkPosition) EntityItem(net.minecraft.world.entity.item.EntityItem) InteractionVisualizer(com.loohp.interactionvisualizer.InteractionVisualizer) Entity(org.bukkit.entity.Entity) ValuePairs(com.loohp.interactionvisualizer.objectholders.ValuePairs) BoundingBox(com.loohp.interactionvisualizer.objectholders.BoundingBox) CraftItem(org.bukkit.craftbukkit.v1_18_R2.entity.CraftItem) TileEntity(com.loohp.interactionvisualizer.objectholders.TileEntity) AxisAlignedBB(net.minecraft.world.phys.AxisAlignedBB) PacketType(com.comphenix.protocol.PacketType) Collectors(java.util.stream.Collectors) Pair(com.mojang.datafixers.util.Pair) ItemStack(org.bukkit.inventory.ItemStack) NMSTileEntitySet(com.loohp.interactionvisualizer.objectholders.NMSTileEntitySet) PacketContainer(com.comphenix.protocol.events.PacketContainer) CraftMagicNumbers(org.bukkit.craftbukkit.v1_18_R2.util.CraftMagicNumbers) List(java.util.List) CraftItemStack(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack) VoxelShape(net.minecraft.world.phys.shapes.VoxelShape) EnumItemSlot(net.minecraft.world.entity.EnumItemSlot) BlockPosition(com.loohp.interactionvisualizer.objectholders.BlockPosition) WorldServer(net.minecraft.server.level.WorldServer) VoxelShape(net.minecraft.world.phys.shapes.VoxelShape) BoundingBox(com.loohp.interactionvisualizer.objectholders.BoundingBox) ArrayList(java.util.ArrayList) List(java.util.List) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld)

Example 5 with WorldServer

use of net.minecraft.server.level.WorldServer in project SSB-OneBlock by BG-Software-LLC.

the class NMSAdapter_v1_17_R1 method simulateToolBreak.

@Override
public void simulateToolBreak(Player bukkitPlayer, org.bukkit.block.Block bukkitBlock) {
    EntityPlayer entityPlayer = ((CraftPlayer) bukkitPlayer).getHandle();
    ItemStack itemStack = entityPlayer.getItemInMainHand();
    WorldServer worldServer = ((CraftWorld) bukkitBlock.getWorld()).getHandle();
    BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
    IBlockData blockData = worldServer.getType(blockPosition);
    itemStack.a(worldServer, blockData, blockPosition, entityPlayer);
}
Also used : IBlockData(net.minecraft.world.level.block.state.IBlockData) BlockPosition(net.minecraft.core.BlockPosition) EntityPlayer(net.minecraft.server.level.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer) WorldServer(net.minecraft.server.level.WorldServer) ItemStack(net.minecraft.world.item.ItemStack) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld)

Aggregations

WorldServer (net.minecraft.server.level.WorldServer)16 BlockPosition (net.minecraft.core.BlockPosition)8 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)6 CraftWorld (org.bukkit.craftbukkit.v1_17_R1.CraftWorld)5 World (org.bukkit.World)4 LivingEntity (org.bukkit.entity.LivingEntity)4 PacketType (com.comphenix.protocol.PacketType)3 PacketContainer (com.comphenix.protocol.events.PacketContainer)3 InteractionVisualizer (com.loohp.interactionvisualizer.InteractionVisualizer)3 BlockPosition (com.loohp.interactionvisualizer.objectholders.BlockPosition)3 BoundingBox (com.loohp.interactionvisualizer.objectholders.BoundingBox)3 ChunkPosition (com.loohp.interactionvisualizer.objectholders.ChunkPosition)3 NMSTileEntitySet (com.loohp.interactionvisualizer.objectholders.NMSTileEntitySet)3 TileEntity (com.loohp.interactionvisualizer.objectholders.TileEntity)3 TileEntityType (com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType)3 ValuePairs (com.loohp.interactionvisualizer.objectholders.ValuePairs)3 WrappedIterable (com.loohp.interactionvisualizer.objectholders.WrappedIterable)3 Pair (com.mojang.datafixers.util.Pair)3 Method (java.lang.reflect.Method)3 ArrayList (java.util.ArrayList)3