diff --git a/SpongeAPI b/SpongeAPI index faefbd50d00..66847c88d79 160000 --- a/SpongeAPI +++ b/SpongeAPI @@ -1 +1 @@ -Subproject commit faefbd50d003cdbce5f61650fd49b61f96e6d79f +Subproject commit 66847c88d795ee484c4934e76cf447bd40a6afa6 diff --git a/src/main/java/org/spongepowered/common/block/SpongeScheduleUpdateTicket.java b/src/main/java/org/spongepowered/common/block/SpongeScheduleUpdateTicket.java new file mode 100644 index 00000000000..dc2cd2bffed --- /dev/null +++ b/src/main/java/org/spongepowered/common/block/SpongeScheduleUpdateTicket.java @@ -0,0 +1,77 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.common.block; + +import org.spongepowered.api.block.transaction.ScheduleUpdateTicket; +import org.spongepowered.api.scheduler.TaskPriority; +import org.spongepowered.api.world.LocatableBlock; + +import java.time.Duration; + +public final class SpongeScheduleUpdateTicket implements ScheduleUpdateTicket { + + private final LocatableBlock block; + private final T target; + private final Duration delay; + private final TaskPriority priority; + private boolean valid = true; + + public SpongeScheduleUpdateTicket(final LocatableBlock block, final T target, final Duration delay, final TaskPriority priority) { + this.block = block; + this.target = target; + this.delay = delay; + this.priority = priority; + } + + @Override + public LocatableBlock block() { + return this.block; + } + + @Override + public T target() { + return this.target; + } + + @Override + public Duration delay() { + return this.delay; + } + + @Override + public TaskPriority priority() { + return this.priority; + } + + @Override + public boolean valid() { + return this.valid; + } + + @Override + public void setValid(final boolean valid) { + this.valid = valid; + } +} diff --git a/src/main/java/org/spongepowered/common/event/tracking/IPhaseState.java b/src/main/java/org/spongepowered/common/event/tracking/IPhaseState.java index 54ea2b458ae..53e6aba097a 100644 --- a/src/main/java/org/spongepowered/common/event/tracking/IPhaseState.java +++ b/src/main/java/org/spongepowered/common/event/tracking/IPhaseState.java @@ -401,7 +401,7 @@ default void foldContextForThread(final C context, final TickTaskBridge returnVa default void associateScheduledTickUpdate(final C asContext, final ServerLevel level, final ScheduledTick entry ) { - + asContext.getTransactor().logScheduledUpdate(level, entry); } default boolean isApplyingStreams() { diff --git a/src/main/java/org/spongepowered/common/event/tracking/context/transaction/GameTransaction.java b/src/main/java/org/spongepowered/common/event/tracking/context/transaction/GameTransaction.java index d546d535e8e..cb50e5af272 100644 --- a/src/main/java/org/spongepowered/common/event/tracking/context/transaction/GameTransaction.java +++ b/src/main/java/org/spongepowered/common/event/tracking/context/transaction/GameTransaction.java @@ -50,7 +50,7 @@ @DefaultQualifier(NonNull.class) public abstract class GameTransaction implements TransactionFlow, StatefulTransaction { - private final TransactionType transactionType; + private final TransactionType transactionType; protected boolean cancelled = false; // Children Definitions @@ -61,7 +61,7 @@ public abstract class GameTransaction implements @Nullable GameTransaction<@NonNull ?> next; private boolean recorded = false; - protected GameTransaction(final TransactionType transactionType) { + protected GameTransaction(final TransactionType transactionType) { this.transactionType = transactionType; } @@ -71,7 +71,7 @@ public String toString() { .toString(); } - public final TransactionType getTransactionType() { + public final TransactionType getTransactionType() { return this.transactionType; } diff --git a/src/main/java/org/spongepowered/common/event/tracking/context/transaction/TransactionSink.java b/src/main/java/org/spongepowered/common/event/tracking/context/transaction/TransactionSink.java index da8863ac6b2..a8460eeae50 100644 --- a/src/main/java/org/spongepowered/common/event/tracking/context/transaction/TransactionSink.java +++ b/src/main/java/org/spongepowered/common/event/tracking/context/transaction/TransactionSink.java @@ -51,6 +51,7 @@ import org.spongepowered.api.item.inventory.Slot; import org.spongepowered.api.item.inventory.crafting.CraftingInventory; import org.spongepowered.api.item.inventory.transaction.SlotTransaction; +import org.spongepowered.api.scheduler.ScheduledUpdate; import org.spongepowered.api.world.BlockChangeFlag; import org.spongepowered.api.world.BlockChangeFlags; import org.spongepowered.common.SpongeCommon; @@ -178,23 +179,14 @@ default EffectTransactor logBlockDrops( return this.pushEffect(new ResultingTransactionBySideEffect(PrepareBlockDrops.getInstance())); } - @SuppressWarnings("ConstantConditions") - default void logScheduledUpdate(final ServerLevel serverWorld, final ScheduledTick data) { + @SuppressWarnings({"ConstantConditions", "unchecked"}) + default void logScheduledUpdate(final ServerLevel serverWorld, final ScheduledTick data) { final WeakReference worldRef = new WeakReference<>(serverWorld); + final WeakReference> dataRef = new WeakReference<>(data); final Supplier worldSupplier = () -> Objects.requireNonNull(worldRef.get(), "ServerWorld dereferenced"); - final @Nullable BlockEntity tileEntity = serverWorld.getBlockEntity(data.pos()); - final BlockState existing = serverWorld.getBlockState(data.pos()); - final SpongeBlockSnapshot original = TrackingUtil.createPooledSnapshot( - existing, - data.pos(), - BlockChangeFlags.NONE, - Constants.World.DEFAULT_BLOCK_CHANGE_LIMIT, - tileEntity, - worldSupplier, - Optional::empty, Optional::empty - ); - original.blockChange = BlockChange.MODIFY; - final ScheduleUpdateTransaction transaction = new ScheduleUpdateTransaction(original, data); + final Supplier> dataSupplier = () -> Objects.requireNonNull(dataRef.get(), "Data dereferenced"); + final ScheduledUpdate spongeData = (ScheduledUpdate) (Object) data; + final ScheduleUpdateTransaction transaction = new ScheduleUpdateTransaction<>(worldSupplier, dataSupplier, data.pos(), data.type(), spongeData.delay(), spongeData.priority()); this.logTransaction(transaction); } diff --git a/src/main/java/org/spongepowered/common/event/tracking/context/transaction/block/ScheduleUpdateTransaction.java b/src/main/java/org/spongepowered/common/event/tracking/context/transaction/block/ScheduleUpdateTransaction.java index 5efeeeadf15..d01fd8195bf 100644 --- a/src/main/java/org/spongepowered/common/event/tracking/context/transaction/block/ScheduleUpdateTransaction.java +++ b/src/main/java/org/spongepowered/common/event/tracking/context/transaction/block/ScheduleUpdateTransaction.java @@ -24,78 +24,145 @@ */ package org.spongepowered.common.event.tracking.context.transaction.block; +import com.google.common.base.Suppliers; +import com.google.common.collect.ImmutableList; +import io.leangen.geantyref.TypeToken; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.ticks.ScheduledTick; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; +import org.spongepowered.api.block.transaction.ScheduleUpdateTicket; +import org.spongepowered.api.event.Cause; import org.spongepowered.api.event.CauseStackManager; -import org.spongepowered.api.event.block.ChangeBlockEvent; -import org.spongepowered.common.block.SpongeBlockSnapshot; +import org.spongepowered.api.event.SpongeEventFactory; +import org.spongepowered.api.event.block.ScheduleBlockUpdateEvent; +import org.spongepowered.api.scheduler.TaskPriority; +import org.spongepowered.api.world.LocatableBlock; +import org.spongepowered.common.block.SpongeScheduleUpdateTicket; import org.spongepowered.common.bridge.world.ticks.TickNextTickDataBridge; import org.spongepowered.common.event.tracking.PhaseContext; import org.spongepowered.common.event.tracking.context.transaction.GameTransaction; +import org.spongepowered.common.event.tracking.context.transaction.type.TransactionTypes; +import org.spongepowered.common.event.tracking.context.transaction.world.WorldBasedTransaction; import org.spongepowered.common.util.PrettyPrinter; +import org.spongepowered.common.world.server.SpongeLocatableBlockBuilder; +import org.spongepowered.math.vector.Vector3i; +import java.time.Duration; import java.util.Optional; import java.util.StringJoiner; import java.util.function.BiConsumer; +import java.util.function.Supplier; -public class ScheduleUpdateTransaction extends BlockEventBasedTransaction { +public class ScheduleUpdateTransaction extends WorldBasedTransaction> { - private final ScheduledTick data; - private final SpongeBlockSnapshot original; + private final BlockPos affectedPosition; + private final BlockState originalState; + private final TypeToken typeToken; + private Supplier> dataSupplier; + private Supplier> ticketSupplier; - public ScheduleUpdateTransaction(final SpongeBlockSnapshot original, final ScheduledTick data) { - super(original.getBlockPos(), (BlockState) original.state(), original.world()); - this.data = data; - this.original = original; + @SuppressWarnings("unchecked") + public ScheduleUpdateTransaction( + final Supplier serverWorldSupplier, final Supplier> dataSupplier, + final BlockPos affectedPosition, final T target, final Duration delay, final TaskPriority priority + ) { + super(TransactionTypes.SCHEDULE_BLOCK_UPDATE.get(), ((org.spongepowered.api.world.server.ServerWorld) serverWorldSupplier.get()).key()); + this.affectedPosition = affectedPosition; + this.originalState = serverWorldSupplier.get().getBlockState(affectedPosition); + this.typeToken = TypeToken.get((Class) target.getClass()); + + this.dataSupplier = dataSupplier; + this.ticketSupplier = Suppliers.memoize(() -> { + final LocatableBlock locatableBlock = new SpongeLocatableBlockBuilder() + .world(serverWorldSupplier) + .position(this.affectedPosition.getX(), this.affectedPosition.getY(), this.affectedPosition.getZ()) + .state((org.spongepowered.api.block.BlockState) this.originalState) + .build(); + return new SpongeScheduleUpdateTicket<>(locatableBlock, target, delay, priority); + }); } @Override - protected boolean actualBlockTransaction() { - return false; + public Optional, CauseStackManager.StackFrame>> getFrameMutator(final @Nullable GameTransaction<@NonNull ?> parent) { + return Optional.empty(); } @Override - protected SpongeBlockSnapshot getResultingSnapshot() { - throw new UnsupportedOperationException(); + public Optional> generateEvent( + final PhaseContext<@NonNull ?> context, + final @Nullable GameTransaction<@NonNull ?> parent, + final ImmutableList>> gameTransactions, + final Cause currentCause + ) { + final ImmutableList> tickets = gameTransactions.stream() + .map(transaction -> ((ScheduleUpdateTransaction) transaction).ticketSupplier.get()) + .collect(ImmutableList.toImmutableList()); + + return Optional.of(SpongeEventFactory.createScheduleBlockUpdateEvent(currentCause, this.typeToken, tickets)); } @Override - protected SpongeBlockSnapshot getOriginalSnapshot() { - return this.original; + public void restore(final PhaseContext context, final ScheduleBlockUpdateEvent event) { + ((TickNextTickDataBridge) (Object) this.dataSupplier.get()).bridge$cancelForcibly(); } @Override - public Optional, CauseStackManager.StackFrame>> getFrameMutator( - final @Nullable GameTransaction<@NonNull ?> parent + public boolean markCancelledTransactions( + final ScheduleBlockUpdateEvent event, + final ImmutableList>> gameTransactions ) { - return Optional.empty(); + boolean cancelledAny = false; + for (final ScheduleUpdateTicket transaction : event.tickets()) { + if (!transaction.valid()) { + cancelledAny = true; + for (final GameTransaction> gameTransaction : gameTransactions) { + final ScheduleUpdateTransaction scheduleUpdateTransaction = (ScheduleUpdateTransaction) gameTransaction; + final Vector3i position = transaction.block().blockPosition(); + final BlockPos affectedPosition = scheduleUpdateTransaction.affectedPosition; + if (position.x() == affectedPosition.getX() + && position.y() == affectedPosition.getY() + && position.z() == affectedPosition.getZ() + ) { + gameTransaction.markCancelled(); + } + } + } + } + + return cancelledAny; } @Override - public void addToPrinter(final PrettyPrinter printer) { - printer.add("AddBlockEvent") - .add(" %s : %s", "Original Block", this.original) - .add(" %s : %s", "Original State", this.originalState) - .add(" %s : %s", "EventData", this.data); + public void markEventAsCancelledIfNecessary(final ScheduleBlockUpdateEvent event) { + super.markEventAsCancelledIfNecessary(event); + event.tickets().forEach(ScheduleUpdateTicket::invalidate); } @Override - public void restore(PhaseContext context, ChangeBlockEvent.All event) { - ((TickNextTickDataBridge) (Object) this.data).bridge$cancelForcibly(); + public void addToPrinter(final PrettyPrinter printer) { + printer.add("ScheduleUpdate") + .add(" %s : %s", "Affected Position", this.affectedPosition) + .add(" %s : %s", "Original State", this.originalState); } @Override public String toString() { return new StringJoiner(", ", ScheduleUpdateTransaction.class.getSimpleName() + "[", "]") - .add("scheduledUpdate=" + this.data) - .add("original=" + this.original) .add("affectedPosition=" + this.affectedPosition) - .add("originalState=" + this.originalState) .add("worldKey=" + this.worldKey) + .add("originalState=" + this.originalState) .add("cancelled=" + this.cancelled) .toString(); } + + @Override + protected boolean shouldBuildEventAndRestartBatch( + final GameTransaction<@NonNull ?> pointer, final PhaseContext<@NonNull ?> context + ) { + return super.shouldBuildEventAndRestartBatch(pointer, context) || !this.typeToken.equals(((ScheduleUpdateTransaction) pointer).typeToken); + } } diff --git a/src/main/java/org/spongepowered/common/event/tracking/context/transaction/inventory/MenuBasedTransaction.java b/src/main/java/org/spongepowered/common/event/tracking/context/transaction/inventory/MenuBasedTransaction.java index 57469d5811b..fe0f3321faf 100644 --- a/src/main/java/org/spongepowered/common/event/tracking/context/transaction/inventory/MenuBasedTransaction.java +++ b/src/main/java/org/spongepowered/common/event/tracking/context/transaction/inventory/MenuBasedTransaction.java @@ -35,7 +35,7 @@ abstract class MenuBasedTransaction extends GameT protected final AbstractContainerMenu menu; protected MenuBasedTransaction( - final TransactionType transactionType, + final TransactionType transactionType, final AbstractContainerMenu menu ) { super(transactionType); diff --git a/src/main/java/org/spongepowered/common/event/tracking/context/transaction/type/TransactionTypes.java b/src/main/java/org/spongepowered/common/event/tracking/context/transaction/type/TransactionTypes.java index 7e628429740..2301cc5bfb0 100644 --- a/src/main/java/org/spongepowered/common/event/tracking/context/transaction/type/TransactionTypes.java +++ b/src/main/java/org/spongepowered/common/event/tracking/context/transaction/type/TransactionTypes.java @@ -30,6 +30,7 @@ import org.spongepowered.api.event.Event; import org.spongepowered.api.event.block.ChangeBlockEvent; import org.spongepowered.api.event.block.NotifyNeighborBlockEvent; +import org.spongepowered.api.event.block.ScheduleBlockUpdateEvent; import org.spongepowered.api.event.entity.HarvestEntityEvent; import org.spongepowered.api.event.entity.SpawnEntityEvent; import org.spongepowered.api.event.item.inventory.AffectSlotEvent; @@ -52,19 +53,22 @@ public final class TransactionTypes { public static final DefaultedRegistryReference> BLOCK = TransactionTypes.key(ResourceKey.sponge("block")); - public static final DefaultedRegistryReference> ENTITY_DEATH_DROPS = TransactionTypes.key(ResourceKey.sponge("entity_death_drops")); + public static final DefaultedRegistryReference> CHANGE_INVENTORY_EVENT = TransactionTypes.key(ResourceKey.sponge("change_inventory")); - public static final DefaultedRegistryReference> NEIGHBOR_NOTIFICATION = TransactionTypes.key(ResourceKey.sponge("neighbor_notification")); + public static final DefaultedRegistryReference> CLICK_CONTAINER_EVENT = TransactionTypes.key(ResourceKey.sponge("click_container")); - public static final DefaultedRegistryReference> SPAWN_ENTITY = TransactionTypes.key(ResourceKey.sponge("spawn_entity")); + public static final DefaultedRegistryReference> ENTITY_DEATH_DROPS = TransactionTypes.key(ResourceKey.sponge("entity_death_drops")); public static final DefaultedRegistryReference> INTERACT_CONTAINER_EVENT = TransactionTypes.key(ResourceKey.sponge("interact_container")); - public static final DefaultedRegistryReference> CLICK_CONTAINER_EVENT = TransactionTypes.key(ResourceKey.sponge("click_container")); + public static final DefaultedRegistryReference> NEIGHBOR_NOTIFICATION = TransactionTypes.key(ResourceKey.sponge("neighbor_notification")); + + public static final DefaultedRegistryReference>> SCHEDULE_BLOCK_UPDATE = TransactionTypes.key(ResourceKey.sponge("schedule_block_update")); - public static final DefaultedRegistryReference> CHANGE_INVENTORY_EVENT = TransactionTypes.key(ResourceKey.sponge("change_inventory")); public static final DefaultedRegistryReference> SLOT_CHANGE = TransactionTypes.key(ResourceKey.sponge("slot_change")); + public static final DefaultedRegistryReference> SPAWN_ENTITY = TransactionTypes.key(ResourceKey.sponge("spawn_entity")); + // SORTFIELDS:OFF // @formatter:on diff --git a/src/main/java/org/spongepowered/common/event/tracking/context/transaction/world/WorldBasedTransaction.java b/src/main/java/org/spongepowered/common/event/tracking/context/transaction/world/WorldBasedTransaction.java index 76452f37be1..1a02f8dfefd 100644 --- a/src/main/java/org/spongepowered/common/event/tracking/context/transaction/world/WorldBasedTransaction.java +++ b/src/main/java/org/spongepowered/common/event/tracking/context/transaction/world/WorldBasedTransaction.java @@ -39,7 +39,7 @@ public abstract class WorldBasedTransaction exten protected final ResourceKey worldKey; protected WorldBasedTransaction( - final TransactionType transactionType, + final TransactionType transactionType, final ResourceKey worldKey ) { super(transactionType); diff --git a/src/main/java/org/spongepowered/common/event/tracking/phase/generation/DeferredScheduledUpdatePhaseState.java b/src/main/java/org/spongepowered/common/event/tracking/phase/generation/DeferredScheduledUpdatePhaseState.java index 268ad836ae4..888eda678d9 100644 --- a/src/main/java/org/spongepowered/common/event/tracking/phase/generation/DeferredScheduledUpdatePhaseState.java +++ b/src/main/java/org/spongepowered/common/event/tracking/phase/generation/DeferredScheduledUpdatePhaseState.java @@ -25,8 +25,6 @@ package org.spongepowered.common.event.tracking.phase.generation; import net.minecraft.core.BlockPos; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.ticks.ScheduledTick; import org.spongepowered.api.event.CauseStackManager; import org.spongepowered.common.event.tracking.PhaseTracker; @@ -54,12 +52,6 @@ public BiConsumer getFrameModifier() { return this.CHUNK_LOAD_MODIFIER; } - @Override - public void associateScheduledTickUpdate( - final Context asContext, ServerLevel level, final ScheduledTick entry - ) { - } - public static final class Context extends GenerationContext { private BlockPos location; diff --git a/src/main/java/org/spongepowered/common/event/tracking/phase/packet/PacketState.java b/src/main/java/org/spongepowered/common/event/tracking/phase/packet/PacketState.java index b2ecc710455..bca22bedb47 100644 --- a/src/main/java/org/spongepowered/common/event/tracking/phase/packet/PacketState.java +++ b/src/main/java/org/spongepowered/common/event/tracking/phase/packet/PacketState.java @@ -30,7 +30,6 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.chunk.LevelChunk; -import net.minecraft.world.ticks.ScheduledTick; import org.spongepowered.api.ResourceKey; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.CauseStackManager; @@ -89,13 +88,6 @@ public Supplier getSpawnTypeForTransaction( return SpawnTypes.PLACEMENT; } - @Override - public void associateScheduledTickUpdate( - final P asContext, final ServerLevel level, final ScheduledTick entry - ) { - asContext.getTransactor().logScheduledUpdate(level, entry); - } - @Override public Supplier attemptWorldKey(final P context) { final ResourceLocation worldKey = context.packetPlayer.level().dimension().location(); diff --git a/src/main/java/org/spongepowered/common/event/tracking/phase/tick/TickPhaseState.java b/src/main/java/org/spongepowered/common/event/tracking/phase/tick/TickPhaseState.java index 44af0caaa51..09b3bc8cff5 100644 --- a/src/main/java/org/spongepowered/common/event/tracking/phase/tick/TickPhaseState.java +++ b/src/main/java/org/spongepowered/common/event/tracking/phase/tick/TickPhaseState.java @@ -27,7 +27,6 @@ import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.block.Block; -import net.minecraft.world.ticks.ScheduledTick; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.spongepowered.common.entity.PlayerTracker; @@ -52,13 +51,6 @@ public void appendNotifierPreBlockTick(final ServerLevel world, final BlockPos p } - @Override - public void associateScheduledTickUpdate( - final C asContext, final ServerLevel level, final ScheduledTick entry - ) { - asContext.getTransactor().logScheduledUpdate(level, entry); - } - @Override public void appendContextPreExplosion(final ExplosionContext explosionContext, final C context) { diff --git a/src/main/java/org/spongepowered/common/registry/loader/SpongeCommonRegistryLoader.java b/src/main/java/org/spongepowered/common/registry/loader/SpongeCommonRegistryLoader.java index 879cadfed56..eb6b5a2ff83 100644 --- a/src/main/java/org/spongepowered/common/registry/loader/SpongeCommonRegistryLoader.java +++ b/src/main/java/org/spongepowered/common/registry/loader/SpongeCommonRegistryLoader.java @@ -41,13 +41,14 @@ public class SpongeCommonRegistryLoader { public static RegistryLoader> blockTransactionTypes() { return RegistryLoader.of(l -> { l.add(TransactionTypes.BLOCK, k -> new BlockTransactionType()); - l.add(TransactionTypes.ENTITY_DEATH_DROPS, k -> new NoOpTransactionType<>(false, k.value().toUpperCase(Locale.ROOT))); + l.add(TransactionTypes.CHANGE_INVENTORY_EVENT, k -> new NoOpTransactionType<>(false, k.value().toUpperCase(Locale.ROOT))); l.add(TransactionTypes.CLICK_CONTAINER_EVENT, k -> new NoOpTransactionType<>(false, k.value().toUpperCase(Locale.ROOT))); + l.add(TransactionTypes.ENTITY_DEATH_DROPS, k -> new NoOpTransactionType<>(false, k.value().toUpperCase(Locale.ROOT))); + l.add(TransactionTypes.INTERACT_CONTAINER_EVENT, k -> new NoOpTransactionType<>(false, k.value().toUpperCase(Locale.ROOT))); l.add(TransactionTypes.NEIGHBOR_NOTIFICATION, k -> new NoOpTransactionType<>(false, k.value().toUpperCase(Locale.ROOT))); - l.add(TransactionTypes.SPAWN_ENTITY, k -> new NoOpTransactionType<>(false, k.value().toUpperCase(Locale.ROOT))); - l.add(TransactionTypes.CHANGE_INVENTORY_EVENT, k -> new NoOpTransactionType<>(false, k.value().toUpperCase(Locale.ROOT))); + l.add(TransactionTypes.SCHEDULE_BLOCK_UPDATE, k -> new NoOpTransactionType<>(false, k.value().toUpperCase(Locale.ROOT))); l.add(TransactionTypes.SLOT_CHANGE, k -> new NoOpTransactionType<>(false, k.value().toUpperCase(Locale.ROOT))); - l.add(TransactionTypes.INTERACT_CONTAINER_EVENT, k -> new NoOpTransactionType<>(false, k.value().toUpperCase(Locale.ROOT))); + l.add(TransactionTypes.SPAWN_ENTITY, k -> new NoOpTransactionType<>(false, k.value().toUpperCase(Locale.ROOT))); }); } diff --git a/src/mixins/java/org/spongepowered/common/mixin/tracker/server/level/ServerLevelMixin_Tracker.java b/src/mixins/java/org/spongepowered/common/mixin/tracker/server/level/ServerLevelMixin_Tracker.java index 970ac0fd2b3..61f1534e828 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/tracker/server/level/ServerLevelMixin_Tracker.java +++ b/src/mixins/java/org/spongepowered/common/mixin/tracker/server/level/ServerLevelMixin_Tracker.java @@ -39,11 +39,8 @@ import net.minecraft.world.level.block.piston.PistonBaseBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.LevelChunk; -import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.FluidState; import net.minecraft.world.phys.Vec3; -import net.minecraft.world.ticks.ScheduledTick; -import net.minecraft.world.ticks.TickPriority; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.spongepowered.api.Sponge; @@ -167,44 +164,6 @@ public abstract class ServerLevelMixin_Tracker extends LevelMixin_Tracker implem TrackingUtil.updateTickFluid(this, fluidState, pos); } - private ScheduledTick tracker$createTick(final BlockPos pos, final T type, final int triggerTick, final TickPriority priority) { - return new ScheduledTick<>(type, pos, this.getLevelData().getGameTime() + (long)triggerTick, priority, this.nextSubTickCount()); - } - - private ScheduledTick tracker$createTick(final BlockPos pos, final T type, final int triggerTick) { - return new ScheduledTick<>(type, pos, this.getLevelData().getGameTime() + (long)triggerTick, this.nextSubTickCount()); - } - - @Override - public void scheduleTick(final BlockPos pos, final Block block, final int triggerTick, final TickPriority priority) { - final var scheduledTick = this.tracker$createTick(pos, block, triggerTick, priority); - PhaseTracker.getInstance().getPhaseContext().associateScheduledTickUpdate((ServerLevel) (Object) this, scheduledTick); - this.getBlockTicks().schedule(scheduledTick); - } - - @Override - public void scheduleTick(final BlockPos pos, final Block block, final int triggerTick) { - final var scheduledTick = this.tracker$createTick(pos, block, triggerTick); - PhaseTracker.getInstance().getPhaseContext().associateScheduledTickUpdate((ServerLevel) (Object) this, scheduledTick); - this.getBlockTicks().schedule(scheduledTick); - } - - @Override - public void scheduleTick( - final BlockPos pos, final Fluid fluid, final int triggerTick, final TickPriority priority - ) { - final var scheduledTick = this.tracker$createTick(pos, fluid, triggerTick, priority); - PhaseTracker.getInstance().getPhaseContext().associateScheduledTickUpdate((ServerLevel) (Object) this, scheduledTick); - this.getFluidTicks().schedule(scheduledTick); - } - - @Override - public void scheduleTick(final BlockPos pos, final Fluid fluid, final int triggerTick) { - final var scheduledTick = this.tracker$createTick(pos, fluid, triggerTick); - PhaseTracker.getInstance().getPhaseContext().associateScheduledTickUpdate((ServerLevel) (Object) this, scheduledTick); - this.getFluidTicks().schedule(scheduledTick); - } - /** * For PhaseTracking, we need to wrap around the * {@link BlockState#tick(ServerLevel, BlockPos, RandomSource)} method, and the ScheduledTickList uses a lambda method diff --git a/src/mixins/java/org/spongepowered/common/mixin/tracker/world/ticks/LevelTicksMixin_Tracker.java b/src/mixins/java/org/spongepowered/common/mixin/tracker/world/ticks/LevelTicksMixin_Tracker.java index df75c79cab0..8b878f94796 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/tracker/world/ticks/LevelTicksMixin_Tracker.java +++ b/src/mixins/java/org/spongepowered/common/mixin/tracker/world/ticks/LevelTicksMixin_Tracker.java @@ -33,6 +33,7 @@ import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.common.bridge.world.ticks.LevelTicksBridge; import org.spongepowered.common.bridge.world.ticks.ScheduledTickBridge; import org.spongepowered.common.event.tracking.PhaseTracker; import org.spongepowered.common.event.tracking.phase.generation.GenerationPhase; @@ -53,7 +54,8 @@ public abstract class LevelTicksMixin_Tracker { value = "INVOKE", target = "Lnet/minecraft/world/ticks/LevelChunkTicks;schedule(Lnet/minecraft/world/ticks/ScheduledTick;)V") ) - private void tracker$associatePhaseContextWithTickEntry(LevelChunkTicks instance, ScheduledTick scheduledTick) { + private void tracker$associatePhaseContextWithTickEntry(final LevelChunkTicks instance, final ScheduledTick scheduledTick) { + PhaseTracker.getInstance().getPhaseContext().associateScheduledTickUpdate(((LevelTicksBridge) this).bridge$level(), scheduledTick); instance.schedule(scheduledTick); }