Search in sources :

Example 6 with CreatorTrackedBridge

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);
            }
        });
    }
}
Also used : CreatorTrackedBridge(org.spongepowered.common.bridge.CreatorTrackedBridge) LevelChunkBridge(org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge) ActiveChunkReferantBridge(org.spongepowered.common.bridge.world.level.chunk.ActiveChunkReferantBridge) HopperBlockEntity(net.minecraft.world.level.block.entity.HopperBlockEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 7 with CreatorTrackedBridge

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);
}
Also used : Entity(org.spongepowered.api.entity.Entity) CreatorTrackedBridge(org.spongepowered.common.bridge.CreatorTrackedBridge) ServerPlayer(net.minecraft.server.level.ServerPlayer) ServerboundInteractPacket(net.minecraft.network.protocol.game.ServerboundInteractPacket)

Example 8 with CreatorTrackedBridge

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);
}
Also used : Entity(org.spongepowered.api.entity.Entity) CreatorTrackedBridge(org.spongepowered.common.bridge.CreatorTrackedBridge) ServerPlayer(net.minecraft.server.level.ServerPlayer) ServerboundInteractPacket(net.minecraft.network.protocol.game.ServerboundInteractPacket) World(org.spongepowered.api.world.World)

Example 9 with CreatorTrackedBridge

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);
    });
}
Also used : Entity(net.minecraft.world.entity.Entity) DimensionType(net.minecraft.world.level.dimension.DimensionType) CreatorTrackedBridge(org.spongepowered.common.bridge.CreatorTrackedBridge) ClientLevel(net.minecraft.client.multiplayer.ClientLevel) PacketChannel(org.spongepowered.api.network.channel.packet.PacketChannel) LevelBridge(org.spongepowered.common.bridge.world.level.LevelBridge) ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer) BlockPos(net.minecraft.core.BlockPos) LevelChunkBridge(org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge) UUID(java.util.UUID)

Example 10 with CreatorTrackedBridge

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);
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) LivingEntity(net.minecraft.world.entity.LivingEntity) AABB(net.minecraft.world.phys.AABB) LivingEntityAccessor(org.spongepowered.common.accessor.world.entity.LivingEntityAccessor) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) MobType(net.minecraft.world.entity.MobType) EventContext(org.spongepowered.api.event.EventContext) Registry(net.minecraft.core.Registry) ChunkSource(net.minecraft.world.level.chunk.ChunkSource) CreatorTrackedBridge(org.spongepowered.common.bridge.CreatorTrackedBridge) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Map(java.util.Map) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Player(net.minecraft.world.entity.player.Player) List(java.util.List) BlockPos(net.minecraft.core.BlockPos) BlockDamageSource(org.spongepowered.api.event.cause.entity.damage.source.BlockDamageSource) Optional(java.util.Optional) ServerLocation(org.spongepowered.api.world.server.ServerLocation) Enchantment(net.minecraft.world.item.enchantment.Enchantment) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) LevelChunkBridge(org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge) EventContextKeys(org.spongepowered.api.event.EventContextKeys) ServerWorld(org.spongepowered.api.world.server.ServerWorld) BlockState(net.minecraft.world.level.block.state.BlockState) HashMap(java.util.HashMap) DamageModifierTypes(org.spongepowered.api.event.cause.entity.damage.DamageModifierTypes) MobEffects(net.minecraft.world.effect.MobEffects) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator) ArrayList(java.util.ArrayList) EntityDamageSource(net.minecraft.world.damagesource.EntityDamageSource) ItemStackUtil(org.spongepowered.common.item.util.ItemStackUtil) DamageSource(net.minecraft.world.damagesource.DamageSource) EnchantmentHelper(net.minecraft.world.item.enchantment.EnchantmentHelper) CombatRules(net.minecraft.world.damagesource.CombatRules) Server(org.spongepowered.api.Server) CauseStackManager(org.spongepowered.api.event.CauseStackManager) FallingBlockDamageSource(org.spongepowered.api.event.cause.entity.damage.source.FallingBlockDamageSource) Cause(org.spongepowered.api.event.Cause) Entity(net.minecraft.world.entity.Entity) DamageFunction(org.spongepowered.api.event.cause.entity.damage.DamageFunction) DamageModifier(org.spongepowered.api.event.cause.entity.damage.DamageModifier) EquipmentSlot(net.minecraft.world.entity.EquipmentSlot) Attributes(net.minecraft.world.entity.ai.attributes.Attributes) Mth(net.minecraft.util.Mth) Collections(java.util.Collections) ListTag(net.minecraft.nbt.ListTag) Player(net.minecraft.world.entity.player.Player) CreatorTrackedBridge(org.spongepowered.common.bridge.CreatorTrackedBridge) ServerLocation(org.spongepowered.api.world.server.ServerLocation) EntityDamageSource(net.minecraft.world.damagesource.EntityDamageSource) Entity(net.minecraft.world.entity.Entity) BlockDamageSource(org.spongepowered.api.event.cause.entity.damage.source.BlockDamageSource) FallingBlockDamageSource(org.spongepowered.api.event.cause.entity.damage.source.FallingBlockDamageSource) BlockPos(net.minecraft.core.BlockPos) LevelChunkBridge(org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge)

Aggregations

CreatorTrackedBridge (org.spongepowered.common.bridge.CreatorTrackedBridge)14 Entity (net.minecraft.world.entity.Entity)5 LevelChunkBridge (org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge)5 ServerPlayer (net.minecraft.server.level.ServerPlayer)4 Entity (org.spongepowered.api.entity.Entity)4 Timing (co.aikar.timings.Timing)3 BlockPos (net.minecraft.core.BlockPos)3 TickableBlockEntity (net.minecraft.world.level.block.entity.TickableBlockEntity)3 BlockEntity (org.spongepowered.api.block.entity.BlockEntity)3 Inject (org.spongepowered.asm.mixin.injection.Inject)3 ActiveChunkReferantBridge (org.spongepowered.common.bridge.world.level.chunk.ActiveChunkReferantBridge)3 UUID (java.util.UUID)2 ServerboundInteractPacket (net.minecraft.network.protocol.game.ServerboundInteractPacket)2 DamageSource (net.minecraft.world.damagesource.DamageSource)2 EntityDamageSource (net.minecraft.world.damagesource.EntityDamageSource)2 LivingEntity (net.minecraft.world.entity.LivingEntity)2 CauseStackManager (org.spongepowered.api.event.CauseStackManager)2 TimingBridge (org.spongepowered.common.bridge.TimingBridge)2 LevelBridge (org.spongepowered.common.bridge.world.level.LevelBridge)2 EntityTickContext (org.spongepowered.common.event.tracking.phase.tick.EntityTickContext)2