Skip to content

Commit

Permalink
chore: merge upstream for changes and fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Harris-Rouquette <[email protected]>
  • Loading branch information
gabizou committed Oct 21, 2024
2 parents 22c156c + c4b70ac commit e33ecc7
Show file tree
Hide file tree
Showing 28 changed files with 338 additions and 215 deletions.
2 changes: 1 addition & 1 deletion SpongeAPI
1 change: 0 additions & 1 deletion forge/src/mixins/resources/mixins.spongeforge.core.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"server.commands.SpreadPlayersCommandMixin_Forge",
"server.level.ServerPlayerMixin_Forge",
"server.network.ServerGamePacketListenerImplMixin_Forge",
"server.network.ServerLoginPacketListenerImplMixin_Forge",
"world.entity.LivingEntityMixin_Forge",
"world.entity.LivingEntityMixin_Forge_Attack_Impl",
"world.entity.item.ItemEntityMixin_Forge",
Expand Down
1 change: 0 additions & 1 deletion neoforge/src/mixins/resources/mixins.spongeneo.core.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"server.level.ServerEntityMixin_Neo",
"server.level.ServerPlayerMixin_Neo",
"server.network.ServerGamePacketListenerImplMixin_Neo",
"server.network.ServerLoginPacketListenerImplMixin_Neo",
"world.entity.LivingEntityMixin_Neo",
"world.entity.LivingEntityMixin_Neo_Attack_Impl",
"world.entity.item.ItemEntityMixin_Neo",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@

import net.minecraft.network.Connection;

import java.util.concurrent.ExecutorService;

public interface ServerLoginPacketListenerImplBridge {

ExecutorService bridge$getExecutor();

Connection bridge$getConnection();

boolean bridge$isIntentDone();
}
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,12 @@ public DataView set(final DataQuery path, final Object value) {
// always have to copy a data view to avoid overwriting existing
// views and to set the interior path correctly.
final Collection<DataQuery> valueKeys = ((DataView) serialized).keys(true);
for (final DataQuery oldKey : valueKeys) {
this.set(path.then(oldKey), ((DataView) serialized).get(oldKey).get());
if (!valueKeys.isEmpty()) {
for (final DataQuery oldKey : valueKeys) {
this.set(path.then(oldKey), ((DataView) serialized).get(oldKey).get());
}
} else {
this.createView(path);
}
} else {
this.map.put(key, serialized);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public EffectResult processSideEffect(
// )
// ) {
if (LightEngine.hasDifferentLightProperties(oldState.state(), currentState)) {
ProfilerFiller filler = Profiler.get();
// ProfilerFiller $$12 = this.level.getProfiler();
final ProfilerFiller filler = Profiler.get();

filler.push("updateSkyLightSources");
// this.skyLightSources.update(this, $$6, $$3, $$8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.spongepowered.common.SpongeCommon;
import org.spongepowered.common.adventure.SpongeAdventure;
import org.spongepowered.common.bridge.network.ConnectionBridge;
import org.spongepowered.common.bridge.network.ServerLoginPacketListenerImplBridge;
import org.spongepowered.common.event.tracking.PhaseTracker;
import org.spongepowered.common.profile.SpongeGameProfile;

Expand Down Expand Up @@ -66,7 +67,11 @@ public boolean active() {
@Override
public Optional<EngineConnectionState> state() {
if (this.active()) {
return Optional.of((EngineConnectionState) this.connection.getPacketListener());
final EngineConnectionState state = (EngineConnectionState) this.connection.getPacketListener();
if (!(state instanceof ServerLoginPacketListenerImplBridge loginBridge) || loginBridge.bridge$isIntentDone()) {
return Optional.of(state);
}
return Optional.of(DummyIntent.of(state.transferred()));
}
return Optional.empty();
}
Expand Down Expand Up @@ -134,4 +139,21 @@ boolean shouldFireDisconnectionImmediately() {
return this == EventFireState.POST;
}
}

private record DummyIntent(boolean transferred) implements EngineConnectionState.Intent {

private static final DummyIntent TRANSFERRED_FALSE = new DummyIntent(false);
private static final DummyIntent TRANSFERRED_TRUE = new DummyIntent(true);

@Override
public boolean transferred() {
return this.transferred;
}

static DummyIntent of(final boolean transferred) {
return transferred
? DummyIntent.TRANSFERRED_TRUE
: DummyIntent.TRANSFERRED_FALSE;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@

public final class ConnectionUtil {

public static boolean isIntentPhase(final EngineConnection connection) {
final EngineConnectionState state = (EngineConnectionState) ((SpongeEngineConnection) connection).connection().getPacketListener();
return state instanceof EngineConnectionState.Intent;
}

public static boolean isLoginPhase(final EngineConnection connection) {
final EngineConnectionState state = (EngineConnectionState) ((SpongeEngineConnection) connection).connection().getPacketListener();
return state instanceof EngineConnectionState.Login;
Expand All @@ -50,6 +55,12 @@ public static TransactionStore getTransactionStore(final EngineConnection connec
return ((ConnectionBridge) networkManager).bridge$getTransactionStore();
}

public static void checkHandshakeOrIntentPhase(final EngineConnection connection) {
if (!ConnectionUtil.isIntentPhase(connection) && !ConnectionUtil.isLoginPhase(connection)) {
throw new IllegalStateException("This dispatcher may only be used for connections in the handshake phase.");
}
}

public static void checkHandshakePhase(final EngineConnection connection) {
if (!ConnectionUtil.isLoginPhase(connection)) {
throw new IllegalStateException("This dispatcher may only be used for connections in the handshake phase.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void handleTransactionResponse(final EngineConnection connection, final Object s

@Override
public CompletableFuture<ChannelBuf> sendTo(final EngineConnection connection, final Consumer<ChannelBuf> payload) {
ConnectionUtil.checkHandshakePhase(connection);
ConnectionUtil.checkHandshakeOrIntentPhase(connection);

final EngineConnectionState state = (EngineConnectionState) ((SpongeEngineConnection) connection).connection().getPacketListener();

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/spongepowered/common/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import net.minecraft.nbt.DoubleTag;
import net.minecraft.nbt.FloatTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.server.level.ChunkLevel;
import net.minecraft.server.level.FullChunkStatus;
import net.minecraft.world.inventory.ClickType;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
Expand Down Expand Up @@ -440,7 +442,7 @@ public static final class Chunk {

public static final class ChunkTicket {

public static final int MAX_FULL_CHUNK_TICKET_LEVEL = 33;
public static final int MAX_FULL_CHUNK_TICKET_LEVEL = ChunkLevel.byStatus(FullChunkStatus.ENTITY_TICKING);

// Highest ticket level that will cause loading a full chunk, plus one.
public static final int MAX_FULL_CHUNK_DISTANCE = ChunkTicket.MAX_FULL_CHUNK_TICKET_LEVEL + 1;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/spongepowered/common/util/VecHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static ChunkPos toChunkPos(final Vector3i vector) {
if (vector == null) {
return null;
}
return new ChunkPos(vector.x(), vector.x());
return new ChunkPos(vector.x(), vector.z());
}

// === MC Vector3d --> flow Vector3d ==
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import net.minecraft.world.level.LevelSettings;
import net.minecraft.world.level.WorldDataConfiguration;
import net.minecraft.world.level.biome.BiomeManager;
import net.minecraft.world.level.dimension.BuiltinDimensionTypes;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.PatrolSpawner;
Expand Down Expand Up @@ -816,8 +817,14 @@ private ServerLevel createNonDefaultLevel(
dataTag = null; // ((MinecraftServerAccessor) this.server).accessor$storageSource().getDataTag(); // Fallback to overworld level.dat
}
final PrimaryLevelData levelData = this.getOrCreateLevelData(dataTag, levelStem, directoryName);
final List<CustomSpawner> spawners;
if (levelStem.type().is(BuiltinDimensionTypes.OVERWORLD) || levelStem.type().is(BuiltinDimensionTypes.OVERWORLD_CAVES)) {
spawners = ImmutableList.of(new PhantomSpawner(), new PatrolSpawner(), new CatSpawner(), new VillageSiege(), new WanderingTraderSpawner(levelData));
} else {
spawners = ImmutableList.of();
}
((ResourceKeyBridge) levelData).bridge$setKey(worldKey);
return this.createLevel(registryKey, levelStem, worldKey, worldTypeKey, storageSource, levelData, ImmutableList.of(), chunkStatusListener);
return this.createLevel(registryKey, levelStem, worldKey, worldTypeKey, storageSource, levelData, spawners, chunkStatusListener);
}

private ServerLevel createLevel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ public static void validateStreamArgs(final Vector3i min, final Vector3i max, fi

public static void validateStreamArgs(final Vector3i min, final Vector3i max, final Vector3i existingMin, final Vector3i existingMax, final StreamOptions options) {
VolumeStreamUtils.validateStreamArgs(min, max, options);
if (existingMin.compareTo(Objects.requireNonNull(min, "Minimum coordinates cannot be null!")) > 0) {
if (existingMin.x() > min.x() || existingMin.y() > min.y() || existingMin.z() > min.z()) {
throw new IllegalArgumentException(String.format("Minimum %s cannot be lower than the current minimum coordinates: %s", min, existingMin));
}
if (existingMax.compareTo(Objects.requireNonNull(max, "Maximum coordinates cannot be null!")) < 0) {
if (existingMax.x() < max.x() || existingMax.y() < max.y() || existingMax.z() < max.z()) {
throw new IllegalArgumentException(String.format("Maximum %s cannot be greater than the current maximum coordinates: %s", max, existingMax));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public abstract class EntityMixin_API implements org.spongepowered.api.entity.En
@Shadow public abstract void shadow$lookAt(EntityAnchorArgument.Anchor param0, Vec3 param1);
@Shadow public abstract CompoundTag shadow$saveWithoutId(CompoundTag $$0);
@Shadow public abstract Level shadow$level();
@Shadow public abstract Vec3 shadow$position();
// @formatter:on

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,20 @@
package org.spongepowered.common.mixin.api.minecraft.world.entity.projectile.windcharge;

import net.minecraft.world.entity.projectile.windcharge.AbstractWindCharge;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.api.entity.explosive.Explosive;
import org.spongepowered.api.entity.projectile.windcharge.WindChargeLike;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.common.mixin.api.minecraft.world.entity.EntityMixin_API;

@Mixin(AbstractWindCharge.class)
public abstract class AbstractWindChargeMixin_API implements WindChargeLike {
public abstract class AbstractWindChargeMixin_API extends EntityMixin_API implements WindChargeLike, Explosive {

@Shadow protected abstract void shadow$explode(Vec3 var1);

@Override
public void detonate() {
this.shadow$explode(this.shadow$position());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,10 @@ public String getServerModName() {
}

@ModifyConstant(method = "tickServer",
slice = @Slice(from = @At(value = "FIELD", target = "Lnet/minecraft/server/MinecraftServer;ticksUntilAutosave:I", ordinal = 0)),
slice = @Slice(
to = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;autoSave()V", ordinal = 1),
from = @At(value = "FIELD", target = "Lnet/minecraft/server/MinecraftServer;ticksUntilAutosave:I", ordinal = 0)
),
constant = @Constant(intValue = 0, ordinal = 0, expandZeroConditions = Constant.Condition.LESS_THAN_OR_EQUAL_TO_ZERO))
private int impl$getSaveTickInterval(final int zero) {
if (!this.shadow$isDedicatedServer()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,26 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.neoforge.mixin.core.server.network;
package org.spongepowered.common.mixin.core.server.commands;

import net.minecraft.network.protocol.login.ServerLoginPacketListener;
import net.minecraft.server.network.ServerLoginPacketListenerImpl;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.commands.WeatherCommand;
import net.minecraft.server.level.ServerLevel;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.common.bridge.network.ServerLoginPacketListenerImplBridge;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(ServerLoginPacketListenerImpl.class)
public abstract class ServerLoginPacketListenerImplMixin_Neo implements ServerLoginPacketListener, ServerLoginPacketListenerImplBridge {
@Mixin(WeatherCommand.class)
public abstract class WeatherCommandMixin {

// @formatter:off
@Shadow private ServerLoginPacketListenerImpl.State state;
// @formatter:on

@Inject(method = "tick", at = @At("HEAD"))
private void impl$onTick(final CallbackInfo ci) {
// In SpongeVanilla we do channel registration during this state, not sure if we need to do anything in SpongeNeo
if (this.state == ServerLoginPacketListenerImpl.State.NEGOTIATING) {
this.state = ServerLoginPacketListenerImpl.State.VERIFYING;
}
@Redirect(method = {
"getDuration",
"setClear",
"setRain",
"setThunder"
}, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;overworld()Lnet/minecraft/server/level/ServerLevel;"))
private static ServerLevel impl$useCurrentWorld(final MinecraftServer instance, final CommandSourceStack $$0) {
return $$0.getLevel();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,29 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.forge.mixin.core.server.network;
package org.spongepowered.common.mixin.core.server.commands;

import net.minecraft.network.protocol.login.ServerLoginPacketListener;
import net.minecraft.server.network.ServerLoginPacketListenerImpl;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.commands.WorldBorderCommand;
import net.minecraft.server.level.ServerLevel;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.common.bridge.network.ServerLoginPacketListenerImplBridge;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(ServerLoginPacketListenerImpl.class)
public abstract class ServerLoginPacketListenerImplMixin_Forge implements ServerLoginPacketListener, ServerLoginPacketListenerImplBridge {
@Mixin(WorldBorderCommand.class)
public abstract class WorldBorderCommandMixin {

// @formatter:off
@Shadow private ServerLoginPacketListenerImpl.State state;
// @formatter:on

@Inject(method = "tick", at = @At("HEAD"))
private void impl$onTick(final CallbackInfo ci) {
// In SpongeVanilla we do channel registration during this state, not sure if we need to do anything in SpongeForge
if (this.state == ServerLoginPacketListenerImpl.State.NEGOTIATING) {
this.state = ServerLoginPacketListenerImpl.State.VERIFYING;
}
@Redirect(method = {
"setDamageBuffer",
"setDamageAmount",
"setWarningTime",
"setWarningDistance",
"getSize",
"setCenter",
"setSize"
}, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;overworld()Lnet/minecraft/server/level/ServerLevel;"))
private static ServerLevel impl$useCurrentWorld(final MinecraftServer instance, final CommandSourceStack $$0) {
return $$0.getLevel();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import net.kyori.adventure.text.Component;
import net.minecraft.network.Connection;
import net.minecraft.network.ProtocolInfo;
import net.minecraft.network.protocol.login.ClientboundLoginDisconnectPacket;
import net.minecraft.network.protocol.login.LoginProtocols;
import net.minecraft.server.network.MemoryServerHandshakePacketListenerImpl;
Expand All @@ -37,6 +38,7 @@
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.common.adventure.SpongeAdventure;
import org.spongepowered.common.bridge.network.ConnectionBridge;
Expand All @@ -58,16 +60,21 @@ public abstract class MemoryServerHandshakePacketListenerImplMixin implements Se
target = "Lnet/minecraft/network/Connection;setupInboundProtocol(Lnet/minecraft/network/ProtocolInfo;Lnet/minecraft/network/PacketListener;)V"),
cancellable = true)
private void impl$onLogin(final CallbackInfo ci) {
this.connection.setupOutboundProtocol(LoginProtocols.CLIENTBOUND);
final SpongeEngineConnection connection = ((ConnectionBridge) this.connection).bridge$getEngineConnection();
final Component message = Component.text("You are not allowed to log in to this server.");
final ServerSideConnectionEvent.Intent event = SpongeEventFactory.createServerSideConnectionEventIntent(
PhaseTracker.getCauseStackManager().currentCause(), message, message, (ServerSideConnection) connection, false);
if (connection.postGuardedEvent(event)) {
ci.cancel();
final net.minecraft.network.chat.Component kickReason = SpongeAdventure.asVanilla(event.message());
this.connection.setupOutboundProtocol(LoginProtocols.CLIENTBOUND);
this.connection.send(new ClientboundLoginDisconnectPacket(kickReason));
this.connection.disconnect(kickReason);
}
}

@Redirect(method = "handleIntention", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/Connection;setupOutboundProtocol(Lnet/minecraft/network/ProtocolInfo;)V"))
private void impl$onSetupOutboundProtocol(final Connection instance, final ProtocolInfo<?> $$0) {
//Moved to impl$onLogin
}
}
Loading

0 comments on commit e33ecc7

Please sign in to comment.