use of org.spongepowered.common.bridge.CreatorTrackedBridge in project SpongeCommon by SpongePowered.
the class HopperBlockEntityMixin method impl$trackNotifierWhenTransferring.
@Inject(method = "addItem(Lnet/minecraft/world/Container;Lnet/minecraft/world/entity/item/ItemEntity;)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/item/ItemEntity;getItem()Lnet/minecraft/world/item/ItemStack;"))
private static void impl$trackNotifierWhenTransferring(final Container inventory, final ItemEntity entityItem, final CallbackInfoReturnable<Boolean> callbackInfo) {
if (entityItem instanceof CreatorTrackedBridge) {
((CreatorTrackedBridge) entityItem).tracker$getCreatorUUID().ifPresent(creator -> {
if (inventory instanceof ActiveChunkReferantBridge && inventory instanceof BlockEntity) {
final BlockEntity te = (BlockEntity) inventory;
final LevelChunkBridge spongeChunk = ((ActiveChunkReferantBridge) inventory).bridge$getActiveChunk();
spongeChunk.bridge$addTrackedBlockPosition(te.getBlockState().getBlock(), te.getBlockPos(), creator, PlayerTracker.Type.NOTIFIER);
}
});
}
}
use of org.spongepowered.common.bridge.CreatorTrackedBridge in project SpongeCommon by SpongePowered.
the class InteractEntityPacketState method unwind.
@Override
public void unwind(BasicPacketContext phaseContext) {
final ServerPlayer player = phaseContext.getPacketPlayer();
final ServerboundInteractPacket useEntityPacket = phaseContext.getPacket();
final net.minecraft.world.entity.Entity entity = useEntityPacket.getTarget(player.level);
if (entity == null) {
// Something happened?
return;
}
if (entity instanceof CreatorTrackedBridge) {
((CreatorTrackedBridge) entity).tracker$setTrackedUUID(PlayerTracker.Type.CREATOR, player.getUUID());
} else {
((Entity) entity).offer(Keys.NOTIFIER, player.getUUID());
}
TrackingUtil.processBlockCaptures(phaseContext);
}
use of org.spongepowered.common.bridge.CreatorTrackedBridge in project SpongeCommon by SpongePowered.
the class InteractAtEntityPacketState method unwind.
@Override
public void unwind(BasicPacketContext context) {
final ServerPlayer player = context.getPacketPlayer();
final ServerboundInteractPacket useEntityPacket = context.getPacket();
final net.minecraft.world.entity.Entity entity = useEntityPacket.getTarget(player.level);
if (entity == null) {
// Something happened?
return;
}
final World spongeWorld = (World) player.level;
if (entity instanceof CreatorTrackedBridge) {
((CreatorTrackedBridge) entity).tracker$setTrackedUUID(PlayerTracker.Type.CREATOR, player.getUUID());
} else {
((Entity) entity).offer(Keys.NOTIFIER, player.getUUID());
}
// TODO - Determine if we need to pass the supplier or perform some parameterized
// process if not empty method on the capture object.
TrackingUtil.processBlockCaptures(context);
}
use of org.spongepowered.common.bridge.CreatorTrackedBridge in project SpongeCommon by SpongePowered.
the class SpongePacketHandler method init.
public static void init(final SpongeChannelManager registry) {
SpongePacketHandler.channel = registry.createChannel(ResourceKey.sponge("default"), PacketChannel.class);
SpongePacketHandler.channel.registerTransactional(RequestBlockTrackerDataPacket.class, TrackerDataResponsePacket.class, 0).setRequestHandler(EngineConnectionTypes.SERVER_PLAYER, (requestPacket, connection, response) -> {
final ServerPlayer player = connection.player();
if (!player.hasPermission("sponge.debug.block-tracking")) {
return;
}
final net.minecraft.server.level.ServerPlayer sender = (net.minecraft.server.level.ServerPlayer) player;
final BlockPos pos = new BlockPos(requestPacket.x, requestPacket.y, requestPacket.z);
if (!sender.level.hasChunkAt(pos)) {
return;
}
final LevelChunkBridge levelChunkBridge = (LevelChunkBridge) sender.level.getChunkAt(pos);
final Optional<UUID> owner = levelChunkBridge.bridge$getBlockCreatorUUID(pos);
final Optional<UUID> notifier = levelChunkBridge.bridge$getBlockNotifierUUID(pos);
response.success(SpongePacketHandler.createTrackerDataResponse(owner, notifier));
});
SpongePacketHandler.channel.registerTransactional(RequestEntityTrackerDataPacket.class, TrackerDataResponsePacket.class, 1).setRequestHandler(EngineConnectionTypes.SERVER_PLAYER, (requestPacket, connection, response) -> {
final ServerPlayer player = connection.player();
if (!player.hasPermission("sponge.debug.entity-tracking")) {
return;
}
final net.minecraft.server.level.ServerPlayer sender = (net.minecraft.server.level.ServerPlayer) player;
final Entity entity = sender.level.getEntity(requestPacket.entityId);
if (!(entity instanceof CreatorTrackedBridge)) {
return;
}
final CreatorTrackedBridge creatorTrackedBridge = (CreatorTrackedBridge) entity;
final Optional<UUID> owner = creatorTrackedBridge.tracker$getCreatorUUID();
final Optional<UUID> notifier = creatorTrackedBridge.tracker$getNotifierUUID();
response.success(SpongePacketHandler.createTrackerDataResponse(owner, notifier));
});
SpongePacketHandler.channel.register(ChangeViewerEnvironmentPacket.class, 3).addHandler(ClientSideConnection.class, (packet, connection) -> {
final ClientLevel world = Minecraft.getInstance().level;
if (world == null) {
return;
}
final DimensionType dimensionType = SpongeCommon.server().registryAccess().dimensionTypes().get(packet.dimensionLogic);
((LevelBridge) world).bridge$adjustDimensionLogic(dimensionType);
});
}
use of org.spongepowered.common.bridge.CreatorTrackedBridge in project SpongeCommon by SpongePowered.
the class DamageEventUtil method generateCauseFor.
/**
* This applies various contexts based on the type of {@link DamageSource}, whether
* it's provided by sponge or vanilla. This is not stack neutral, which is why it requires
* a {@link CauseStackManager.StackFrame} reference to push onto the stack.
*/
public static void generateCauseFor(final DamageSource damageSource, final CauseStackManager.StackFrame frame) {
if (damageSource instanceof EntityDamageSource) {
final net.minecraft.world.entity.Entity source = damageSource.getEntity();
if (!(source instanceof Player) && source instanceof CreatorTrackedBridge) {
final CreatorTrackedBridge creatorBridge = (CreatorTrackedBridge) source;
creatorBridge.tracker$getCreatorUUID().ifPresent(creator -> frame.addContext(EventContextKeys.CREATOR, creator));
creatorBridge.tracker$getNotifierUUID().ifPresent(notifier -> frame.addContext(EventContextKeys.NOTIFIER, notifier));
}
} else if (damageSource instanceof BlockDamageSource) {
final ServerLocation location = ((BlockDamageSource) damageSource).location();
final BlockPos blockPos = VecHelper.toBlockPos(location);
final LevelChunkBridge chunkBridge = (LevelChunkBridge) ((net.minecraft.world.level.Level) location.world()).getChunkAt(blockPos);
chunkBridge.bridge$getBlockCreatorUUID(blockPos).ifPresent(creator -> frame.addContext(EventContextKeys.CREATOR, creator));
chunkBridge.bridge$getBlockNotifierUUID(blockPos).ifPresent(notifier -> frame.addContext(EventContextKeys.NOTIFIER, notifier));
}
frame.pushCause(damageSource);
}
Aggregations