use of net.minecraft.network.play.client.CPacketUseEntity in project SpongeCommon by SpongePowered.
the class AttackEntityPacketState method isPacketIgnored.
@Override
public boolean isPacketIgnored(Packet<?> packetIn, EntityPlayerMP packetPlayer) {
final CPacketUseEntity useEntityPacket = (CPacketUseEntity) packetIn;
// There are cases where a player is interacting with an entity that
// doesn't exist on the server.
@Nullable net.minecraft.entity.Entity entity = useEntityPacket.getEntityFromWorld(packetPlayer.world);
return entity == null;
}
use of net.minecraft.network.play.client.CPacketUseEntity in project SpongeCommon by SpongePowered.
the class InteractAtEntityPacketState method populateContext.
@Override
public void populateContext(EntityPlayerMP playerMP, Packet<?> packet, BasicPacketContext context) {
final CPacketUseEntity useEntityPacket = (CPacketUseEntity) packet;
final ItemStack stack = ItemStackUtil.cloneDefensive(playerMP.getHeldItem(useEntityPacket.getHand()));
if (stack != null) {
context.itemUsed(stack);
}
}
use of net.minecraft.network.play.client.CPacketUseEntity in project SpongeCommon by SpongePowered.
the class InteractEntityPacketState method populateContext.
@Override
public void populateContext(EntityPlayerMP playerMP, Packet<?> packet, BasicPacketContext context) {
final CPacketUseEntity useEntityPacket = (CPacketUseEntity) packet;
net.minecraft.entity.Entity entity = useEntityPacket.getEntityFromWorld(playerMP.world);
if (entity != null) {
final ItemStack stack = ItemStackUtil.cloneDefensive(playerMP.getHeldItem(useEntityPacket.getHand()));
if (stack != null) {
context.itemUsed(stack);
}
}
}
use of net.minecraft.network.play.client.CPacketUseEntity in project SpongeCommon by SpongePowered.
the class InteractEntityPacketState method isPacketIgnored.
@Override
public boolean isPacketIgnored(Packet<?> packetIn, EntityPlayerMP packetPlayer) {
final CPacketUseEntity useEntityPacket = (CPacketUseEntity) packetIn;
// There are cases where a player is interacting with an entity that doesn't exist on the server.
@Nullable net.minecraft.entity.Entity entity = useEntityPacket.getEntityFromWorld(packetPlayer.world);
return entity == null;
}
use of net.minecraft.network.play.client.CPacketUseEntity in project SpongeCommon by SpongePowered.
the class InteractEntityPacketState method unwind.
@Override
public void unwind(BasicPacketContext phaseContext) {
final EntityPlayerMP player = phaseContext.getPacketPlayer();
final CPacketUseEntity useEntityPacket = phaseContext.getPacket();
final net.minecraft.entity.Entity entity = useEntityPacket.getEntityFromWorld(player.world);
if (entity == null) {
// Something happened?
return;
}
final World spongeWorld = EntityUtil.getSpongeWorld(player);
EntityUtil.toMixin(entity).setNotifier(player.getUniqueID());
phaseContext.getCapturedBlockSupplier().acceptAndClearIfNotEmpty(blocks -> {
final PrettyPrinter printer = new PrettyPrinter(80);
printer.add("Processing Interact Entity").centre().hr();
printer.add("The blocks captured are:");
for (BlockSnapshot blockSnapshot : blocks) {
printer.add(" Block: %s", blockSnapshot);
}
printer.trace(System.err);
});
phaseContext.getCapturedEntitySupplier().acceptAndClearIfNotEmpty(entities -> {
final PrettyPrinter printer = new PrettyPrinter(80);
printer.add("Processing Interact Entity").centre().hr();
printer.add("The entities captured are:");
for (Entity capturedEntity : entities) {
printer.add(" Entity: %s", capturedEntity);
}
printer.trace(System.err);
});
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
Sponge.getCauseStackManager().pushCause(player);
Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.PLACEMENT);
phaseContext.getCapturedItemsSupplier().acceptAndClearIfNotEmpty(entities -> {
final List<Entity> items = entities.stream().map(EntityUtil::fromNative).collect(Collectors.toList());
SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), items);
SpongeImpl.postEvent(event);
if (!event.isCancelled()) {
processSpawnedEntities(player, event);
}
});
}
phaseContext.getCapturedEntityDropSupplier().acceptIfNotEmpty(map -> {
final PrettyPrinter printer = new PrettyPrinter(80);
printer.add("Processing Interact Entity").centre().hr();
printer.add("The item stacks captured are: ");
for (Map.Entry<UUID, Collection<ItemDropData>> entry : map.asMap().entrySet()) {
printer.add(" - Entity with UUID: %s", entry.getKey());
for (ItemDropData stack : entry.getValue()) {
printer.add(" - %s", stack);
}
}
printer.trace(System.err);
});
phaseContext.getCapturedBlockSupplier().acceptAndClearIfNotEmpty(snapshots -> TrackingUtil.processBlockCaptures(snapshots, this, phaseContext));
}
Aggregations