use of net.minecraft.client.network.ClientPlayNetworkHandler in project ImmersivePortalsMod by qouteall.
the class ClientTeleportationManager method changePlayerDimension.
/**
* {@link ClientPlayNetworkHandler#onPlayerRespawn(PlayerRespawnS2CPacket)}
*/
private void changePlayerDimension(ClientPlayerEntity player, ClientWorld fromWorld, ClientWorld toWorld, Vec3d destination) {
DimensionType toDimension = toWorld.dimension.getType();
DimensionType fromDimension = fromWorld.dimension.getType();
ClientPlayNetworkHandler workingNetHandler = ((IEClientWorld) fromWorld).getNetHandler();
ClientPlayNetworkHandler fakedNetHandler = ((IEClientWorld) toWorld).getNetHandler();
((IEClientPlayNetworkHandler) workingNetHandler).setWorld(toWorld);
((IEClientPlayNetworkHandler) fakedNetHandler).setWorld(fromWorld);
((IEClientWorld) fromWorld).setNetHandler(fakedNetHandler);
((IEClientWorld) toWorld).setNetHandler(workingNetHandler);
fromWorld.removeEntity(player.getEntityId());
player.removed = false;
player.world = toWorld;
player.dimension = toDimension;
player.x = destination.x;
player.y = destination.y;
player.z = destination.z;
toWorld.addPlayer(player.getEntityId(), player);
mc.world = toWorld;
mc.worldRenderer = CGlobal.clientWorldLoader.getWorldRenderer(toDimension);
toWorld.setScoreboard(fromWorld.getScoreboard());
if (mc.particleManager != null)
mc.particleManager.setWorld(toWorld);
BlockEntityRenderDispatcher.INSTANCE.setWorld(toWorld);
CGlobal.clientWorldLoader.getDimensionRenderHelper(toDimension).switchToMe();
Helper.log(String.format("Client Changed Dimension from %s to %s time: %s", fromDimension, toDimension, tickTimeForTeleportation));
Helper.log("Portal Number Near Player Now" + McHelper.getEntitiesNearby(mc.player, Portal.class, 10).count());
// because the teleportation may happen before rendering
// but after pre render info being updated
MyRenderHelper.updatePreRenderInfo(MyRenderHelper.partialTicks);
OFInterface.onPlayerTraveled.accept(fromDimension, toDimension);
}
use of net.minecraft.client.network.ClientPlayNetworkHandler in project tweakermore by Fallen-Breath.
the class InventoryRefresher method refresh.
/**
* Inspired by viaversion 1.14 -> 1.13 villager selection inventory forced resync
* https://github.com/ViaVersion/ViaVersion/blob/4074352a531cfb0de6fa81e043ee761737748a7a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java#L238
*/
public static boolean refresh(KeyAction keyAction, IKeybind iKeybind) {
MinecraftClient mc = MinecraftClient.getInstance();
ClientPlayNetworkHandler networkHandler = mc.getNetworkHandler();
if (networkHandler != null && mc.player != null) {
ItemStack uniqueItem = new ItemStack(Items.STONE);
// Tags with NaN are not equal
uniqueItem.getOrCreateTag().putDouble("force_resync", Double.NaN);
networkHandler.sendPacket(new ClickWindowC2SPacket(mc.player.container.syncId, -999, 2, SlotActionType.QUICK_CRAFT, uniqueItem, mc.player.container.getNextActionId(mc.player.inventory)));
}
return true;
}
use of net.minecraft.client.network.ClientPlayNetworkHandler in project bewitchment by MoriyaShiine.
the class SyncContractsPacket method handle.
public static void handle(MinecraftClient client, ClientPlayNetworkHandler network, PacketByteBuf buf, PacketSender sender) {
NbtCompound contractsCompound = buf.readNbt();
client.execute(new Runnable() {
@Override
public void run() {
if (client.player != null) {
BWComponents.CONTRACTS_COMPONENT.maybeGet(client.player).ifPresent(contractsComponent -> {
contractsComponent.getContracts().clear();
NbtList contractsList = contractsCompound.getList("Contracts", NbtType.COMPOUND);
for (int i = 0; i < contractsList.size(); i++) {
NbtCompound contractCompound = contractsList.getCompound(i);
contractsComponent.addContract(new Contract.Instance(BWRegistries.CONTRACTS.get(new Identifier(contractCompound.getString("Contract"))), contractCompound.getInt("Duration"), contractCompound.getInt("Cost")));
}
});
}
}
});
}
use of net.minecraft.client.network.ClientPlayNetworkHandler in project EdenClient by HahaOO7.
the class Nuker method onTick.
private void onTick(ClientPlayerEntity player) {
if (!enabled)
return;
ClientPlayNetworkHandler nh = MinecraftClient.getInstance().getNetworkHandler();
BlockState air = Blocks.AIR.getDefaultState();
ClientPlayerInteractionManager im = MinecraftClient.getInstance().interactionManager;
if (im == null)
return;
if (nh == null)
return;
if (limit > 1) {
List<BlockPos> minableBlocks = getInstantMinableBlocksInRange(player);
if (!minableBlocks.isEmpty()) {
target = null;
minableBlocks.forEach(p -> {
nh.sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, p, getHitDirectionForBlock(player, p)));
nh.sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, p, getHitDirectionForBlock(player, p)));
player.clientWorld.setBlockState(p, air);
});
nh.sendPacket(new HandSwingC2SPacket(Hand.MAIN_HAND));
return;
}
}
if (target == null || Vec3d.ofCenter(target).distanceTo(player.getEyePos()) > distance)
findTarget(player);
if (target == null)
return;
Direction dir = getHitDirectionForBlock(player, target);
if (im.updateBlockBreakingProgress(target, dir))
nh.sendPacket(new HandSwingC2SPacket(Hand.MAIN_HAND));
else
target = null;
}
use of net.minecraft.client.network.ClientPlayNetworkHandler in project EdenClient by HahaOO7.
the class HeadHunt method clickPos.
private void clickPos(Vec3i target) {
BlockPos bp = new BlockPos(target);
Direction dir = Direction.UP;
PlayerInteractBlockC2SPacket packet = new PlayerInteractBlockC2SPacket(Hand.MAIN_HAND, new BlockHitResult(Vec3d.of(bp.offset(dir)), dir, bp, false));
ClientPlayNetworkHandler nh = MinecraftClient.getInstance().getNetworkHandler();
if (nh == null)
return;
nh.sendPacket(packet);
foundHeads.add(target);
System.out.println("Head clicked: " + target);
}
Aggregations