Search in sources :

Example 56 with MovecraftLocation

use of net.countercraft.movecraft.MovecraftLocation in project Movecraft by APDevTeam.

the class BlockListener method onHopperEvent.

// prevent hoppers on cruising crafts
@EventHandler(priority = EventPriority.HIGHEST)
public void onHopperEvent(InventoryMoveItemEvent event) {
    if (!(event.getSource().getHolder() instanceof Hopper)) {
        return;
    }
    Hopper block = (Hopper) event.getSource().getHolder();
    CraftManager.getInstance().getCraftsInWorld(block.getWorld());
    for (Craft tcraft : CraftManager.getInstance().getCraftsInWorld(block.getWorld())) {
        MovecraftLocation mloc = new MovecraftLocation(block.getX(), block.getY(), block.getZ());
        if (MathUtils.locIsNearCraftFast(tcraft, mloc) && tcraft.getCruising() && !tcraft.isNotProcessing()) {
            event.setCancelled(true);
            return;
        }
    }
}
Also used : Craft(net.countercraft.movecraft.craft.Craft) Hopper(org.bukkit.block.Hopper) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) EventHandler(org.bukkit.event.EventHandler)

Example 57 with MovecraftLocation

use of net.countercraft.movecraft.MovecraftLocation in project Movecraft by APDevTeam.

the class BlockListener method onPistonEvent.

// prevent pistons on cruising crafts
@EventHandler(priority = EventPriority.HIGHEST)
public void onPistonEvent(BlockPistonExtendEvent event) {
    Block block = event.getBlock();
    CraftManager.getInstance().getCraftsInWorld(block.getWorld());
    for (Craft tcraft : CraftManager.getInstance().getCraftsInWorld(block.getWorld())) {
        MovecraftLocation mloc = new MovecraftLocation(block.getX(), block.getY(), block.getZ());
        if (MathUtils.locIsNearCraftFast(tcraft, mloc) && tcraft.getCruising() && !tcraft.isNotProcessing()) {
            event.setCancelled(true);
            return;
        }
    }
}
Also used : Craft(net.countercraft.movecraft.craft.Craft) Block(org.bukkit.block.Block) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) EventHandler(org.bukkit.event.EventHandler)

Example 58 with MovecraftLocation

use of net.countercraft.movecraft.MovecraftLocation in project Movecraft by APDevTeam.

the class IWorldHandler method rotateCraft.

// @Override
// public void addPlayerLocation(Player player, double x, double y, double z, float yaw, float pitch){
// ServerPlayer ePlayer = ((CraftPlayer) player).getHandle();
// ePlayer.connection.teleport(x, y, z, yaw, pitch, EnumSet.allOf(ClientboundPlayerPositionPacket.RelativeArgument.class));
// }
@Override
public void rotateCraft(@NotNull Craft craft, @NotNull MovecraftLocation originPoint, @NotNull MovecraftRotation rotation) {
    // *******************************************
    // *      Step one: Convert to Positions     *
    // *******************************************
    HashMap<BlockPos, BlockPos> rotatedPositions = new HashMap<>();
    MovecraftRotation counterRotation = rotation == MovecraftRotation.CLOCKWISE ? MovecraftRotation.ANTICLOCKWISE : MovecraftRotation.CLOCKWISE;
    for (MovecraftLocation newLocation : craft.getHitBox()) {
        rotatedPositions.put(locationToPosition(MathUtils.rotateVec(counterRotation, newLocation.subtract(originPoint)).add(originPoint)), locationToPosition(newLocation));
    }
    // *******************************************
    // *         Step two: Get the tiles         *
    // *******************************************
    ServerLevel nativeWorld = ((CraftWorld) craft.getWorld()).getHandle();
    List<TileHolder> tiles = new ArrayList<>();
    // get the tiles
    for (BlockPos position : rotatedPositions.keySet()) {
        // BlockEntity tile = nativeWorld.removeBlockEntity(position);
        BlockEntity tile = removeBlockEntity(nativeWorld, position);
        if (tile == null)
            continue;
        // tile.a(ROTATION[rotation.ordinal()]);
        // get the nextTick to move with the tile
        tiles.add(new TileHolder(tile, tickProvider.getNextTick(nativeWorld, position), position));
    }
    // *******************************************
    // *   Step three: Translate all the blocks  *
    // *******************************************
    // blockedByWater=false means an ocean-going vessel
    // TODO: Simplify
    // TODO: go by chunks
    // TODO: Don't move unnecessary blocks
    // get the blocks and rotate them
    HashMap<BlockPos, BlockState> blockData = new HashMap<>();
    for (BlockPos position : rotatedPositions.keySet()) {
        blockData.put(position, nativeWorld.getBlockState(position).rotate(ROTATION[rotation.ordinal()]));
    }
    // create the new block
    for (Map.Entry<BlockPos, BlockState> entry : blockData.entrySet()) {
        setBlockFast(nativeWorld, rotatedPositions.get(entry.getKey()), entry.getValue());
    }
    // TODO: go by chunks
    for (TileHolder tileHolder : tiles) {
        moveBlockEntity(nativeWorld, rotatedPositions.get(tileHolder.getTilePosition()), tileHolder.getTile());
        if (tileHolder.getNextTick() == null)
            continue;
        final long currentTime = nativeWorld.E.getGameTime();
        nativeWorld.getBlockTickList().scheduleTick(rotatedPositions.get(tileHolder.getNextTick().pos), (Block) tileHolder.getNextTick().getType(), (int) (tileHolder.getNextTick().triggerTick - currentTime), tileHolder.getNextTick().priority);
    }
    // *******************************************
    // *   Step five: Destroy the leftovers      *
    // *******************************************
    // TODO: add support for pass-through
    Collection<BlockPos> deletePositions = CollectionUtils.filter(rotatedPositions.keySet(), rotatedPositions.values());
    for (BlockPos position : deletePositions) {
        setBlockFast(nativeWorld, position, Blocks.AIR.defaultBlockState());
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MovecraftRotation(net.countercraft.movecraft.MovecraftRotation) BlockState(net.minecraft.world.level.block.state.BlockState) BlockPos(net.minecraft.core.BlockPos) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld) HashMap(java.util.HashMap) Map(java.util.Map) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 59 with MovecraftLocation

use of net.countercraft.movecraft.MovecraftLocation in project Movecraft by APDevTeam.

the class IWorldHandler method rotateCraft.

@Override
public void rotateCraft(@NotNull Craft craft, @NotNull MovecraftLocation originPoint, @NotNull MovecraftRotation rotation) {
    // *******************************************
    // *      Step one: Convert to Positions     *
    // *******************************************
    HashMap<BlockPosition, BlockPosition> rotatedPositions = new HashMap<>();
    MovecraftRotation counterRotation = rotation == MovecraftRotation.CLOCKWISE ? MovecraftRotation.ANTICLOCKWISE : MovecraftRotation.CLOCKWISE;
    for (MovecraftLocation newLocation : craft.getHitBox()) {
        rotatedPositions.put(locationToPosition(MathUtils.rotateVec(counterRotation, newLocation.subtract(originPoint)).add(originPoint)), locationToPosition(newLocation));
    }
    // *******************************************
    // *         Step two: Get the tiles         *
    // *******************************************
    WorldServer nativeWorld = ((CraftWorld) craft.getWorld()).getHandle();
    List<TileHolder> tiles = new ArrayList<>();
    // get the tiles
    for (BlockPosition position : rotatedPositions.keySet()) {
        // TileEntity tile = nativeWorld.removeTileEntity(position);
        TileEntity tile = removeTileEntity(nativeWorld, position);
        if (tile == null)
            continue;
        tile.a(ROTATION[rotation.ordinal()]);
        // get the nextTick to move with the tile
        tiles.add(new TileHolder(tile, tickProvider.getNextTick(nativeWorld, position), position));
    }
    // *******************************************
    // *   Step three: Translate all the blocks  *
    // *******************************************
    // blockedByWater=false means an ocean-going vessel
    // TODO: Simplify
    // TODO: go by chunks
    // TODO: Don't move unnecessary blocks
    // get the blocks and rotate them
    HashMap<BlockPosition, IBlockData> blockData = new HashMap<>();
    for (BlockPosition position : rotatedPositions.keySet()) {
        blockData.put(position, nativeWorld.getType(position).a(ROTATION[rotation.ordinal()]));
    }
    // create the new block
    for (Map.Entry<BlockPosition, IBlockData> entry : blockData.entrySet()) {
        setBlockFast(nativeWorld, rotatedPositions.get(entry.getKey()), entry.getValue());
    }
    // TODO: go by chunks
    for (TileHolder tileHolder : tiles) {
        moveTileEntity(nativeWorld, rotatedPositions.get(tileHolder.getTilePosition()), tileHolder.getTile());
        if (tileHolder.getNextTick() == null)
            continue;
        final long currentTime = nativeWorld.worldData.getTime();
        nativeWorld.getBlockTickList().a(rotatedPositions.get(tileHolder.getNextTick().a), (Block) tileHolder.getNextTick().b(), (int) (tileHolder.getNextTick().b - currentTime), tileHolder.getNextTick().c);
    }
    // *******************************************
    // *   Step five: Destroy the leftovers      *
    // *******************************************
    // TODO: add support for pass-through
    Collection<BlockPosition> deletePositions = CollectionUtils.filter(rotatedPositions.keySet(), rotatedPositions.values());
    for (BlockPosition position : deletePositions) {
        setBlockFast(nativeWorld, position, Blocks.AIR.getBlockData());
    }
}
Also used : HashMap(java.util.HashMap) BlockPosition(net.minecraft.server.v1_14_R1.BlockPosition) ArrayList(java.util.ArrayList) WorldServer(net.minecraft.server.v1_14_R1.WorldServer) MovecraftRotation(net.countercraft.movecraft.MovecraftRotation) TileEntity(net.minecraft.server.v1_14_R1.TileEntity) IBlockData(net.minecraft.server.v1_14_R1.IBlockData) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) CraftWorld(org.bukkit.craftbukkit.v1_14_R1.CraftWorld) HashMap(java.util.HashMap) Map(java.util.Map)

Example 60 with MovecraftLocation

use of net.countercraft.movecraft.MovecraftLocation in project Movecraft by APDevTeam.

the class IWorldHandler method rotateCraft.

// @Override
// public void addPlayerLocation(Player player, double x, double y, double z, float yaw, float pitch){
// ServerPlayer ePlayer = ((CraftPlayer) player).getHandle();
// ePlayer.connection.teleport(x, y, z, yaw, pitch, EnumSet.allOf(ClientboundPlayerPositionPacket.RelativeArgument.class));
// }
@Override
public void rotateCraft(@NotNull Craft craft, @NotNull MovecraftLocation originPoint, @NotNull MovecraftRotation rotation) {
    // *******************************************
    // *      Step one: Convert to Positions     *
    // *******************************************
    HashMap<BlockPos, BlockPos> rotatedPositions = new HashMap<>();
    MovecraftRotation counterRotation = rotation == MovecraftRotation.CLOCKWISE ? MovecraftRotation.ANTICLOCKWISE : MovecraftRotation.CLOCKWISE;
    for (MovecraftLocation newLocation : craft.getHitBox()) {
        rotatedPositions.put(locationToPosition(MathUtils.rotateVec(counterRotation, newLocation.subtract(originPoint)).add(originPoint)), locationToPosition(newLocation));
    }
    // *******************************************
    // *         Step two: Get the tiles         *
    // *******************************************
    ServerLevel nativeWorld = ((CraftWorld) craft.getWorld()).getHandle();
    List<TileHolder> tiles = new ArrayList<>();
    // get the tiles
    for (BlockPos position : rotatedPositions.keySet()) {
        // BlockEntity tile = nativeWorld.removeBlockEntity(position);
        BlockEntity tile = removeBlockEntity(nativeWorld, position);
        if (tile == null)
            continue;
        // tile.a(ROTATION[rotation.ordinal()]);
        // get the nextTick to move with the tile
        tiles.add(new TileHolder(tile, tickProvider.getNextTick(nativeWorld, position), position));
    }
    // *******************************************
    // *   Step three: Translate all the blocks  *
    // *******************************************
    // blockedByWater=false means an ocean-going vessel
    // TODO: Simplify
    // TODO: go by chunks
    // TODO: Don't move unnecessary blocks
    // get the blocks and rotate them
    HashMap<BlockPos, BlockState> blockData = new HashMap<>();
    for (BlockPos position : rotatedPositions.keySet()) {
        blockData.put(position, nativeWorld.getBlockState(position).rotate(ROTATION[rotation.ordinal()]));
    }
    // create the new block
    for (Map.Entry<BlockPos, BlockState> entry : blockData.entrySet()) {
        setBlockFast(nativeWorld, rotatedPositions.get(entry.getKey()), entry.getValue());
    }
    // TODO: go by chunks
    for (TileHolder tileHolder : tiles) {
        moveBlockEntity(nativeWorld, rotatedPositions.get(tileHolder.getTilePosition()), tileHolder.getTile());
        if (tileHolder.getNextTick() == null)
            continue;
        final long currentTime = nativeWorld.M.getGameTime();
        nativeWorld.getBlockTicks().schedule(new ScheduledTick<>((Block) tileHolder.getNextTick().type(), rotatedPositions.get(tileHolder.getNextTick().pos()), tileHolder.getNextTick().triggerTick() - currentTime, tileHolder.getNextTick().priority(), tileHolder.getNextTick().subTickOrder()));
    }
    // *******************************************
    // *   Step five: Destroy the leftovers      *
    // *******************************************
    // TODO: add support for pass-through
    Collection<BlockPos> deletePositions = CollectionUtils.filter(rotatedPositions.keySet(), rotatedPositions.values());
    for (BlockPos position : deletePositions) {
        setBlockFast(nativeWorld, position, Blocks.AIR.defaultBlockState());
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MovecraftRotation(net.countercraft.movecraft.MovecraftRotation) BlockState(net.minecraft.world.level.block.state.BlockState) Block(net.minecraft.world.level.block.Block) BlockPos(net.minecraft.core.BlockPos) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld) HashMap(java.util.HashMap) Map(java.util.Map) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Aggregations

MovecraftLocation (net.countercraft.movecraft.MovecraftLocation)60 Craft (net.countercraft.movecraft.craft.Craft)18 EventHandler (org.bukkit.event.EventHandler)18 Material (org.bukkit.Material)17 World (org.bukkit.World)15 Sign (org.bukkit.block.Sign)14 BlockState (org.bukkit.block.BlockState)13 Block (org.bukkit.block.Block)12 ArrayList (java.util.ArrayList)11 Location (org.bukkit.Location)11 Map (java.util.Map)10 HashMap (java.util.HashMap)9 SetHitBox (net.countercraft.movecraft.util.hitboxes.SetHitBox)9 HashSet (java.util.HashSet)8 SinkingCraft (net.countercraft.movecraft.craft.SinkingCraft)8 NotNull (org.jetbrains.annotations.NotNull)8 MovecraftRotation (net.countercraft.movecraft.MovecraftRotation)6 HitBox (net.countercraft.movecraft.util.hitboxes.HitBox)6 SolidHitBox (net.countercraft.movecraft.util.hitboxes.SolidHitBox)6 LinkedList (java.util.LinkedList)5