use of org.spongepowered.common.bridge.CreatorTrackedBridge in project SpongeCommon by SpongePowered.
the class LevelChunkMixin method bridge$addTrackedBlockPosition.
@Override
public void bridge$addTrackedBlockPosition(final Block block, final BlockPos pos, final UUID uuid, final PlayerTracker.Type trackerType) {
if (((LevelBridge) this.level).bridge$isFake()) {
return;
}
if (!PhaseTracker.getInstance().getPhaseContext().tracksCreatorsAndNotifiers()) {
// Don't track chunk gen
return;
}
// Update TE tracking cache
// We must always check for a TE as a mod block may not implement ITileEntityProvider if a TE exists
// Note: We do not check SpongeImplHooks.hasBlockTileEntity(block, state) as neighbor notifications do not include blockstate.
final BlockEntity blockEntity = this.blockEntities.get(pos);
if (blockEntity != null) {
if (blockEntity instanceof CreatorTrackedBridge) {
final CreatorTrackedBridge trackedBlockEntity = (CreatorTrackedBridge) blockEntity;
if (trackerType == PlayerTracker.Type.NOTIFIER) {
if (Objects.equals(trackedBlockEntity.tracker$getNotifierUUID().orElse(null), uuid)) {
return;
}
trackedBlockEntity.tracker$setTrackedUUID(PlayerTracker.Type.NOTIFIER, uuid);
} else {
if (Objects.equals(trackedBlockEntity.tracker$getCreatorUUID().orElse(null), uuid)) {
return;
}
trackedBlockEntity.tracker$setTrackedUUID(PlayerTracker.Type.CREATOR, uuid);
}
}
}
if (trackerType == PlayerTracker.Type.CREATOR) {
this.impl$setTrackedUUID(pos, uuid, trackerType, (pt, idx) -> {
pt.creatorindex = idx;
pt.notifierIndex = idx;
});
} else {
this.impl$setTrackedUUID(pos, uuid, trackerType, (pt, idx) -> pt.notifierIndex = idx);
}
}
use of org.spongepowered.common.bridge.CreatorTrackedBridge in project SpongeCommon by SpongePowered.
the class EntityUtil method processEntitySpawn.
public static boolean processEntitySpawn(final org.spongepowered.api.entity.Entity entity, final Supplier<Optional<UUID>> supplier, final Consumer<Entity> spawner) {
final Entity minecraftEntity = (Entity) entity;
if (minecraftEntity instanceof ItemEntity) {
final ItemStack item = ((ItemEntity) minecraftEntity).getItem();
if (!item.isEmpty()) {
final Optional<Entity> customEntityItem = Optional.ofNullable(PlatformHooks.INSTANCE.getWorldHooks().getCustomEntityIfItem(minecraftEntity));
if (customEntityItem.isPresent()) {
// Bypass spawning the entity item, since it is established that the custom entity is spawned.
final Entity entityToSpawn = customEntityItem.get();
supplier.get().ifPresent(spawned -> {
if (entityToSpawn instanceof CreatorTrackedBridge) {
((CreatorTrackedBridge) entityToSpawn).tracker$setTrackedUUID(PlayerTracker.Type.CREATOR, spawned);
}
});
if (entityToSpawn.removed) {
entityToSpawn.removed = false;
}
// Since forge already has a new event thrown for the entity, we don't need to throw
// the event anymore as sponge plugins getting the event after forge mods will
// have the modified entity list for entities, so no need to re-capture the entities.
entityToSpawn.level.addFreshEntity(entityToSpawn);
return true;
}
}
}
// Allowed to call force spawn directly since we've applied creator and custom item logic already
spawner.accept((Entity) entity);
return true;
}
use of org.spongepowered.common.bridge.CreatorTrackedBridge in project SpongeCommon by SpongePowered.
the class TrackingUtil method tickEntity.
public static void tickEntity(final Consumer<net.minecraft.world.entity.Entity> consumer, final net.minecraft.world.entity.Entity entity) {
checkArgument(entity instanceof Entity, "Entity %s is not an instance of SpongeAPI's Entity!", entity);
checkNotNull(entity, "Cannot capture on a null ticking entity!");
if (!((TrackableBridge) entity).bridge$shouldTick()) {
return;
}
final EntityTickContext tickContext = TickPhase.Tick.ENTITY.createPhaseContext(PhaseTracker.SERVER).source(entity);
try (final EntityTickContext context = tickContext;
final Timing entityTiming = ((TimingBridge) entity.getType()).bridge$timings()) {
if (entity instanceof CreatorTrackedBridge) {
((CreatorTrackedBridge) entity).tracker$getNotifierUUID().ifPresent(context::notifier);
((CreatorTrackedBridge) entity).tracker$getCreatorUUID().ifPresent(context::creator);
}
context.buildAndSwitch();
entityTiming.startTiming();
consumer.accept(entity);
if (ShouldFire.MOVE_ENTITY_EVENT) {
SpongeCommonEventFactory.callNaturalMoveEntityEvent(entity);
}
if (ShouldFire.ROTATE_ENTITY_EVENT) {
SpongeCommonEventFactory.callNaturalRotateEntityEvent(entity);
}
} catch (final Exception e) {
PhasePrinter.printExceptionFromPhase(PhaseTracker.getInstance().stack, e, tickContext);
}
}
use of org.spongepowered.common.bridge.CreatorTrackedBridge in project SpongeCommon by SpongePowered.
the class TrackingUtil method tickRidingEntity.
public static void tickRidingEntity(final net.minecraft.world.entity.Entity entity) {
checkArgument(entity instanceof Entity, "Entity %s is not an instance of SpongeAPI's Entity!", entity);
checkNotNull(entity, "Cannot capture on a null ticking entity!");
if (!((TrackableBridge) entity).bridge$shouldTick()) {
return;
}
final EntityTickContext tickContext = TickPhase.Tick.ENTITY.createPhaseContext(PhaseTracker.SERVER).source(entity);
try (final EntityTickContext context = tickContext;
final Timing entityTiming = ((TimingBridge) entity.getType()).bridge$timings()) {
entityTiming.startTiming();
if (entity instanceof CreatorTrackedBridge) {
((CreatorTrackedBridge) entity).tracker$getNotifierUUID().ifPresent(context::notifier);
((CreatorTrackedBridge) entity).tracker$getCreatorUUID().ifPresent(context::creator);
}
context.buildAndSwitch();
entity.rideTick();
if (ShouldFire.MOVE_ENTITY_EVENT) {
SpongeCommonEventFactory.callNaturalMoveEntityEvent(entity);
}
if (ShouldFire.ROTATE_ENTITY_EVENT) {
SpongeCommonEventFactory.callNaturalRotateEntityEvent(entity);
}
} catch (final Exception e) {
PhasePrinter.printExceptionFromPhase(PhaseTracker.getInstance().stack, e, tickContext);
}
}
Aggregations