public void animatedTeleport() { Task.Builder builder = MoseCraft.getPlugin().getGame().getScheduler().createTaskBuilder(); builder.intervalTicks(20); builder.async(); builder.name(POS1.getBlockX() + "," + POS1.getBlockY() + "," + POS1.getBlockZ()); builder.execute(new TeleportTask()).submit(MoseCraft.getPlugin().getGame()); }
public static ChangeBlockEvent.Break callBlockBreakEvent(Event event) { if (!(event instanceof ChangeBlockEvent.Break)) { throw new IllegalArgumentException("Event is not a valid ChangeBlockEventBreak"); } ChangeBlockEvent.Break spongeEvent = (ChangeBlockEvent.Break) event; if (spongeEvent.getCause().first(Player.class).isPresent()) { Player player = spongeEvent.getCause().first(Player.class).get(); Iterator<Transaction<BlockSnapshot>> iterator = spongeEvent.getTransactions().iterator(); while (iterator.hasNext()) { Transaction<BlockSnapshot> transaction = iterator.next(); Location<World> location = transaction.getOriginal().getLocation().get(); net.minecraft.world.World world = (net.minecraft.world.World) location.getExtent(); BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()); StaticMixinHelper.breakEventExtendedState = (IBlockState) transaction.getOriginal().getExtendedState(); BlockEvent.BreakEvent forgeEvent = new BlockEvent.BreakEvent( world, pos, (IBlockState) transaction.getOriginal().getState(), (EntityPlayer) player); StaticMixinHelper.breakEventExtendedState = null; ((IMixinEventBus) MinecraftForge.EVENT_BUS).post(forgeEvent, true); if (forgeEvent.isCanceled()) { transaction.setValid(false); } } } return spongeEvent; }
@SuppressWarnings("unchecked") private void animation2() { for (Location<World> loc : POS2) { World world = loc.getExtent(); Location<World> pos1 = world.getLocation(loc.getBlockX() - 3, loc.getBlockY(), loc.getBlockZ() + 3); Location<World> pos2 = world.getLocation(loc.getBlockX() + 3, loc.getBlockY(), loc.getBlockZ() + 3); Location<World> pos3 = world.getLocation(loc.getBlockX() - 3, loc.getBlockY(), loc.getBlockZ() - 3); Location<World> pos4 = world.getLocation(loc.getBlockX() + 3, loc.getBlockY(), loc.getBlockZ() + 3); Location<World>[] pos = mix(pos1, pos2, pos3, pos4); for (Location<World> pos5 : pos) { Lightning light = (Lightning) world.createEntity(EntityTypes.LIGHTNING, pos5.getBlockPosition()).get(); light.setEffect(true); world.spawnEntity(light, Causes.TELEPORT_LIGHTNING.build()); } } }
// Block events public static BlockEvent createBlockEvent(Event event) { if (!(event instanceof ChangeBlockEvent)) { throw new IllegalArgumentException("Event is not a valid ChangeBlockEvent."); } ChangeBlockEvent spongeEvent = (ChangeBlockEvent) event; Location<World> location = spongeEvent.getTransactions().get(0).getOriginal().getLocation().get(); net.minecraft.world.World world = (net.minecraft.world.World) location.getExtent(); BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()); BlockEvent forgeEvent = new BlockEvent(world, pos, world.getBlockState(pos)); return forgeEvent; }
public static PlayerSleepInBedEvent createPlayerSleepInBedEvent(Event event) { if (!(event instanceof SleepingEvent.Pre)) { throw new IllegalArgumentException( "Event " + event + " is not a valid SleepingEvent.Pre event."); } SleepingEvent.Pre spongeEvent = (SleepingEvent.Pre) event; Optional<Player> player = spongeEvent.getCause().first(Player.class); if (!player.isPresent()) { return null; } Location<World> location = spongeEvent.getBed().getLocation().get(); BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()); return new PlayerSleepInBedEvent((EntityPlayer) player.get(), pos); }
public static BlockEvent.PlaceEvent createBlockPlaceEvent(Event event) { if (!(event instanceof ChangeBlockEvent.Place)) { throw new IllegalArgumentException("Event is not a valid ChangeBlockEvent.Place event."); } ChangeBlockEvent.Place spongeEvent = (ChangeBlockEvent.Place) event; Location<World> location = spongeEvent.getTransactions().get(0).getOriginal().getLocation().get(); net.minecraft.world.World world = (net.minecraft.world.World) location.getExtent(); BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()); BlockSnapshot replacementBlock = spongeEvent.getTransactions().get(0).getFinal(); IBlockState state = (IBlockState) replacementBlock.getState(); Optional<Player> player = spongeEvent.getCause().first(Player.class); if (!player.isPresent()) { return null; } net.minecraftforge.common.util.BlockSnapshot forgeSnapshot = new net.minecraftforge.common.util.BlockSnapshot(world, pos, state); BlockEvent.PlaceEvent forgeEvent = new BlockEvent.PlaceEvent( forgeSnapshot, world.getBlockState(pos), (EntityPlayer) player.get()); return forgeEvent; }
@Override public boolean triggerMechanic(Location block, Sign sign, Human human, Boolean forceState) { if (!SignUtil.getTextRaw(sign, 1).equals("[Door]")) { Direction back = SignUtil.getTextRaw(sign, 1).equals("[Door Up]") ? Direction.UP : Direction.DOWN; Location baseBlock = block.getRelative(back); Location otherSide = getOtherEnd(block, back, maximumLength); if (otherSide == null) { if (human instanceof CommandSource) ((CommandSource) human).sendMessage(Texts.builder("Missing other end!").build()); return true; } Location otherBase = otherSide.getRelative(back.getOpposite()); if (!baseBlock.getBlock().equals(otherBase.getBlock())) { if (human instanceof CommandSource) ((CommandSource) human) .sendMessage(Texts.builder("Both ends must be the same material!").build()); return true; } int leftBlocks = 0, rightBlocks = 0; // Default to 0. Single width bridge is the default. Location left = baseBlock.getRelative(SignUtil.getLeft(block)); Location right = baseBlock.getRelative(SignUtil.getRight(block)); // Calculate left distance Location otherLeft = otherBase.getRelative(SignUtil.getLeft(block)); while (true) { if (leftBlocks >= maximumWidth) break; if (left.getBlock().equals(baseBlock.getBlock()) && otherLeft.getBlock().equals(baseBlock.getBlock())) { leftBlocks++; left = left.getRelative(SignUtil.getLeft(block)); otherLeft = otherLeft.getRelative(SignUtil.getLeft(block)); } else { break; } } // Calculate right distance Location otherRight = otherBase.getRelative(SignUtil.getRight(block)); while (true) { if (rightBlocks >= maximumWidth) break; if (right.getBlock().equals(baseBlock.getBlock()) && otherRight.getBlock().equals(baseBlock.getBlock())) { rightBlocks++; right = right.getRelative(SignUtil.getRight(block)); otherRight = otherRight.getRelative(SignUtil.getRight(block)); } else { break; } } baseBlock = baseBlock.getRelative(back); BlockState type = block.getRelative(back).getBlock(); if (baseBlock.getBlock().equals(type) && (forceState == null || !forceState)) type = BlockTypes.AIR.getDefaultState(); while (baseBlock.getBlockY() != otherSide.getBlockY() + (back == Direction.UP ? -1 : 1)) { baseBlock.setBlock(type); left = baseBlock.getRelative(SignUtil.getLeft(block)); for (int i = 0; i < leftBlocks; i++) { left.setBlock(type); left = left.getRelative(SignUtil.getLeft(block)); } right = baseBlock.getRelative(SignUtil.getRight(block)); for (int i = 0; i < rightBlocks; i++) { right.setBlock(type); right = right.getRelative(SignUtil.getRight(block)); } baseBlock = baseBlock.getRelative(back); } } else { if (human instanceof CommandSource) ((CommandSource) human) .sendMessage(Texts.builder("Door not activatable from here!").build()); return false; } return true; }
public static ChangeBlockEvent.Place callBlockPlaceEvent(Event event) { if (!(event instanceof ChangeBlockEvent.Place)) { throw new IllegalArgumentException("Event is not a valid ChangeBlockEventPlace"); } ChangeBlockEvent.Place spongeEvent = (ChangeBlockEvent.Place) event; if (spongeEvent.getCause().first(Player.class).isPresent()) { EntityPlayer player = (EntityPlayer) spongeEvent.getCause().first(Player.class).get(); net.minecraft.world.World world = (net.minecraft.world.World) spongeEvent.getTargetWorld(); if (spongeEvent.getTransactions().size() == 1) { BlockPos pos = VecHelper.toBlockPos(spongeEvent.getTransactions().get(0).getOriginal().getPosition()); IBlockState state = (IBlockState) spongeEvent.getTransactions().get(0).getOriginal().getState(); net.minecraftforge.common.util.BlockSnapshot blockSnapshot = new net.minecraftforge.common.util.BlockSnapshot(world, pos, state); IBlockState placedAgainst = Blocks.air.getDefaultState(); if (StaticMixinHelper.packetPlayer != null && StaticMixinHelper.processingPacket instanceof C08PacketPlayerBlockPlacement) { C08PacketPlayerBlockPlacement packet = (C08PacketPlayerBlockPlacement) StaticMixinHelper.processingPacket; EnumFacing facing = EnumFacing.getFront(packet.getPlacedBlockDirection()); placedAgainst = blockSnapshot.world.getBlockState(blockSnapshot.pos.offset(facing.getOpposite())); } BlockEvent.PlaceEvent forgeEvent = new BlockEvent.PlaceEvent(blockSnapshot, placedAgainst, player); ((IMixinEventBus) MinecraftForge.EVENT_BUS).post(forgeEvent, true); if (forgeEvent.isCanceled()) { spongeEvent.getTransactions().get(0).setValid(false); } } else { // multi Iterator<Transaction<BlockSnapshot>> iterator = spongeEvent.getTransactions().iterator(); List<net.minecraftforge.common.util.BlockSnapshot> blockSnapshots = new ArrayList<>(); while (iterator.hasNext()) { Transaction<BlockSnapshot> transaction = iterator.next(); Location<World> location = transaction.getOriginal().getLocation().get(); IBlockState state = (IBlockState) transaction.getOriginal().getState(); BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()); net.minecraftforge.common.util.BlockSnapshot blockSnapshot = new net.minecraftforge.common.util.BlockSnapshot(world, pos, state); blockSnapshots.add(blockSnapshot); } IBlockState placedAgainst = Blocks.air.getDefaultState(); if (StaticMixinHelper.packetPlayer != null && StaticMixinHelper.processingPacket instanceof C08PacketPlayerBlockPlacement) { C08PacketPlayerBlockPlacement packet = (C08PacketPlayerBlockPlacement) StaticMixinHelper.processingPacket; EnumFacing facing = EnumFacing.getFront(packet.getPlacedBlockDirection()); placedAgainst = blockSnapshots .get(0) .world .getBlockState(blockSnapshots.get(0).pos.offset(facing.getOpposite())); } BlockEvent.MultiPlaceEvent forgeEvent = new BlockEvent.MultiPlaceEvent(blockSnapshots, placedAgainst, player); ((IMixinEventBus) MinecraftForge.EVENT_BUS).post(forgeEvent, true); if (forgeEvent.isCanceled()) { while (iterator.hasNext()) { iterator.next().setValid(false); } } } } return spongeEvent; }