Skip to content

Commit 2901a2b

Browse files
committed
chore: merge api-11 fixes and updates
Signed-off-by: Gabriel Harris-Rouquette <gabizou@me.com>
2 parents f25cc69 + a091b4f commit 2901a2b

13 files changed

Lines changed: 253 additions & 25 deletions

File tree

SpongeAPI

gradle/verification-metadata.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,14 @@
15031503
<sha256 value="ecd2df597d488e91f40a345a716f3d4ac1caa30b1d21ae33d1bc24e9f656744d" origin="Generated by Gradle"/>
15041504
</artifact>
15051505
</component>
1506+
<component group="io.github.juuxel" name="union-relauncher" version="1.1.1">
1507+
<artifact name="union-relauncher-1.1.1.jar">
1508+
<sha256 value="e00285ead453f947c9242b317af43c4249029f66e60f5596c5bdb59302763947" origin="Generated by Gradle"/>
1509+
</artifact>
1510+
<artifact name="union-relauncher-1.1.1.pom">
1511+
<sha256 value="d1eb0e9bca96dd7a15b724f30d34a775cd423b0faf7ac2c15b4705e81c35ff8d" origin="Generated by Gradle"/>
1512+
</artifact>
1513+
</component>
15061514
<component group="io.github.juuxel" name="unprotect" version="1.2.0">
15071515
<artifact name="unprotect-1.2.0.jar">
15081516
<sha256 value="d6b8259d9fcee6d21377e4e1ae0e7fecc2e0d8d2d40d83c020e2ca3dde57ec42" origin="Generated by Gradle"/>
@@ -1851,6 +1859,14 @@
18511859
<sha256 value="b1854f5544c3f40be358f4f674fbb7247b1b853e79a1d5b1aa2fcb94898bbeb2" origin="Generated by Gradle"/>
18521860
</artifact>
18531861
</component>
1862+
<component group="net.fabricmc" name="tiny-remapper" version="0.10.3">
1863+
<artifact name="tiny-remapper-0.10.3.jar">
1864+
<sha256 value="8b0abcbdc373f85b04dce6adf9db31922827957718b31f39791e7c254df736b2" origin="Generated by Gradle"/>
1865+
</artifact>
1866+
<artifact name="tiny-remapper-0.10.3.module">
1867+
<sha256 value="71987b3ab7d4ffd7d18002ed1111e8a2bb42c26cd7395d99db5145eeb0b60685" origin="Generated by Gradle"/>
1868+
</artifact>
1869+
</component>
18541870
<component group="net.java" name="jvnet-parent" version="3">
18551871
<artifact name="jvnet-parent-3.pom">
18561872
<sha256 value="30f5789efa39ddbf96095aada3fc1260c4561faf2f714686717cb2dc5049475a" origin="Generated by Gradle"/>

src/main/java/org/spongepowered/common/SpongeLifecycle.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@ public void establishEarlyGlobalRegistries() {
116116
holder.setRootMinecraftRegistry((Registry<Registry<?>>) BuiltInRegistries.REGISTRY);
117117

118118
SpongeRegistries.registerEarlyGlobalRegistries(holder);
119-
120-
// Plugin registries
121-
this.game.eventManager().post(new AbstractRegisterRegistryEvent.GameScopedImpl(Cause.of(EventContext.empty(), this.game), this.game));
122119
}
123120

124121
@Override
@@ -140,6 +137,9 @@ public void establishGlobalRegistries(final RegistryAccess.Frozen registryAccess
140137
case DIMENSIONS -> {
141138
SpongeRegistries.registerGlobalRegistriesDimensionLayer((SpongeRegistryHolder) this.game, registryAccess, this.featureFlags);
142139

140+
// Plugin registries
141+
this.game.eventManager().post(new AbstractRegisterRegistryEvent.GameScopedImpl(Cause.of(EventContext.empty(), this.game), this.game));
142+
143143
// Freeze Sponge Root - Registries are now available
144144
holder.registryHolder().freezeSpongeRootRegistry();
145145
}

src/main/java/org/spongepowered/common/SpongeServer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
*/
2525
package org.spongepowered.common;
2626

27+
import net.minecraft.core.BlockPos;
28+
import org.checkerframework.checker.nullness.qual.Nullable;
2729
import org.spongepowered.api.Server;
2830
import org.spongepowered.common.command.manager.SpongeCommandManager;
2931
import org.spongepowered.common.profile.SpongeGameProfileManager;
@@ -47,6 +49,10 @@ public interface SpongeServer extends SpongeEngine, Server {
4749

4850
UsernameCache getUsernameCache();
4951

52+
@Nullable Integer getBlockDestructionId(BlockPos pos);
53+
54+
int getOrCreateBlockDestructionId(BlockPos pos);
55+
5056
SpongeUserManager userManager();
5157

5258
@Override

src/mixins/java/org/spongepowered/common/mixin/api/minecraft/server/MinecraftServerMixin_API.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import net.kyori.adventure.text.Component;
3535
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
3636
import net.minecraft.commands.Commands;
37+
import net.minecraft.core.BlockPos;
3738
import net.minecraft.core.RegistryAccess;
3839
import net.minecraft.core.registries.Registries;
3940
import net.minecraft.server.MinecraftServer;
@@ -51,6 +52,7 @@
5152
import net.minecraft.world.level.storage.LevelStorageSource;
5253
import net.minecraft.world.level.storage.WorldData;
5354
import org.checkerframework.checker.nullness.qual.NonNull;
55+
import org.checkerframework.checker.nullness.qual.Nullable;
5456
import org.spongepowered.api.Game;
5557
import org.spongepowered.api.Server;
5658
import org.spongepowered.api.Sponge;
@@ -479,6 +481,16 @@ public UsernameCache getUsernameCache() {
479481
return this.api$usernameCache;
480482
}
481483

484+
@Override
485+
public @Nullable Integer getBlockDestructionId(BlockPos pos) {
486+
return this.api$blockDestructionIdCache.get(pos).orElse(null);
487+
}
488+
489+
@Override
490+
public int getOrCreateBlockDestructionId(BlockPos pos) {
491+
return this.api$blockDestructionIdCache.getOrCreate(pos);
492+
}
493+
482494
@Override
483495
public BlockDestructionIdCache getBlockDestructionIdCache() {
484496
return this.api$blockDestructionIdCache;

src/mixins/java/org/spongepowered/common/mixin/api/minecraft/server/level/ServerPlayerMixin_API.java

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@
3434
import net.kyori.adventure.text.Component;
3535
import net.minecraft.advancements.Advancement;
3636
import net.minecraft.advancements.AdvancementHolder;
37+
import net.minecraft.core.BlockPos;
3738
import net.minecraft.network.Connection;
3839
import net.minecraft.network.chat.ChatType;
3940
import net.minecraft.network.chat.MessageSignature;
4041
import net.minecraft.network.chat.PlayerChatMessage;
42+
import net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket;
4143
import net.minecraft.network.protocol.game.ClientboundDeleteChatPacket;
4244
import net.minecraft.network.protocol.game.ClientboundInitializeBorderPacket;
4345
import net.minecraft.resources.ResourceLocation;
@@ -115,7 +117,9 @@ public abstract class ServerPlayerMixin_API extends PlayerMixin_API implements S
115117
// @formatter:on
116118

117119

118-
@Shadow @Nullable private Vec3 enteredLavaOnVehiclePosition;
120+
@Shadow
121+
@Nullable
122+
private Vec3 enteredLavaOnVehiclePosition;
119123
private volatile Pointers api$pointers;
120124

121125
private final TabList api$tabList = new SpongeTabList((net.minecraft.server.level.ServerPlayer) (Object) this);
@@ -152,7 +156,7 @@ public ServerSideConnection connection() {
152156
/**
153157
* @author Minecrell - August 22nd, 2016
154158
* @reason Use InetSocketAddress#getHostString() where possible (instead of
155-
* inspecting SocketAddress#toString()) to support IPv6 addresses
159+
* inspecting SocketAddress#toString()) to support IPv6 addresses
156160
*/
157161
@Overwrite
158162
public String getIpAddress() {
@@ -207,6 +211,27 @@ public boolean hasPlayedBefore() {
207211
return timeSinceFirstJoined.getSeconds() > 0;
208212
}
209213

214+
@Override
215+
public void sendBlockProgress(final int x, final int y, final int z, final double progress) {
216+
if (progress < 0 || progress > 1) {
217+
throw new IllegalArgumentException("Progress must be between 0 and 1");
218+
}
219+
220+
final BlockPos pos = new BlockPos(x, y, z);
221+
final int id = ((SpongeServer) this.server).getOrCreateBlockDestructionId(pos);
222+
final int progressStage = progress == 1 ? 9 : (int) (progress * 10);
223+
this.connection.send(new ClientboundBlockDestructionPacket(id, pos, progressStage));
224+
}
225+
226+
@Override
227+
public void resetBlockProgress(final int x, final int y, final int z) {
228+
final BlockPos pos = new BlockPos(x, y, z);
229+
final Integer id = ((SpongeServer) this.server).getBlockDestructionId(pos);
230+
if (id != null) {
231+
this.connection.send(new ClientboundBlockDestructionPacket(id, pos, -1));
232+
}
233+
}
234+
210235
@Override
211236
public boolean respawn() {
212237
if (this.impl$isFake) {
@@ -275,21 +300,21 @@ public Optional<WorldBorder> setWorldBorder(final @Nullable WorldBorder border)
275300
return currentBorder; // do not fire an event since nothing would have changed
276301
}
277302
final ChangeWorldBorderEvent.Player event =
278-
SpongeEventFactory.createChangeWorldBorderEventPlayer(PhaseTracker.getCauseStackManager().currentCause(),
279-
Optional.ofNullable(border), Optional.ofNullable(border), this, Optional.ofNullable(border));
303+
SpongeEventFactory.createChangeWorldBorderEventPlayer(PhaseTracker.getCauseStackManager().currentCause(),
304+
Optional.ofNullable(border), Optional.ofNullable(border), this, Optional.ofNullable(border));
280305
if (SpongeCommon.post(event)) {
281306
return currentBorder;
282307
}
283308

284309
final net.minecraft.world.level.border.@Nullable WorldBorder oldWorldBorder = ((ServerPlayerBridge) this).bridge$getWorldBorder();
285310
if (oldWorldBorder != null) { // is the world border about to be unset?
286311
((WorldBorderAccessor) oldWorldBorder).accessor$listeners().remove(
287-
((ServerPlayerBridge) this).bridge$getWorldBorderListener()); // remove the listener, if so
312+
((ServerPlayerBridge) this).bridge$getWorldBorderListener()); // remove the listener, if so
288313
}
289314
final Optional<WorldBorder> toSet = event.newBorder();
290315
if (toSet.isPresent()) {
291316
final net.minecraft.world.level.border.WorldBorder mutableWorldBorder =
292-
new net.minecraft.world.level.border.WorldBorder();
317+
new net.minecraft.world.level.border.WorldBorder();
293318
((WorldBorderBridge) mutableWorldBorder).bridge$applyFrom(toSet.get());
294319
((ServerPlayerBridge) this).bridge$replaceWorldBorder(mutableWorldBorder);
295320
mutableWorldBorder.addListener(((ServerPlayerBridge) this).bridge$getWorldBorderListener());
@@ -439,7 +464,7 @@ public void sendResourcePacks(final @NonNull ResourcePackRequest request) {
439464
}
440465

441466
@Override
442-
public void removeResourcePacks(final @NonNull UUID id, final @NonNull UUID @NonNull... others) {
467+
public void removeResourcePacks(final @NonNull UUID id, final @NonNull UUID @NonNull ... others) {
443468
((ServerCommonPacketListenerImplBridge) this.connection).bridge$removeResourcePacks(id, others);
444469
}
445470

src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/level/LevelMixin_API.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,18 @@
2727
import net.kyori.adventure.sound.Sound;
2828
import net.minecraft.core.BlockPos;
2929
import net.minecraft.nbt.CompoundTag;
30+
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;
3031
import net.minecraft.resources.ResourceKey;
3132
import net.minecraft.server.MinecraftServer;
3233
import net.minecraft.server.level.ServerChunkCache;
34+
import net.minecraft.server.level.ServerPlayer;
3335
import net.minecraft.util.Tuple;
3436
import net.minecraft.world.level.BlockAndTintGetter;
3537
import net.minecraft.world.level.Level;
3638
import net.minecraft.world.level.LevelAccessor;
3739
import net.minecraft.world.level.LevelReader;
3840
import net.minecraft.world.level.LightLayer;
41+
import net.minecraft.world.level.block.state.BlockState;
3942
import net.minecraft.world.level.chunk.ChunkAccess;
4043
import net.minecraft.world.level.chunk.ChunkSource;
4144
import net.minecraft.world.level.chunk.ImposterProtoChunk;
@@ -261,6 +264,19 @@ public void resetBlockProgress(final int x, final int y, final int z) {
261264
ViewerPacketUtil.resetBlockProgress(x, y, z, this.engine()).ifPresent(((ViewerBridge) this)::bridge$sendToViewer);
262265
}
263266

267+
@Override
268+
public void sendBlockChange(final int x, final int y, final int z, final org.spongepowered.api.block.BlockState state) {
269+
Objects.requireNonNull(state, "state");
270+
271+
final ClientboundBlockUpdatePacket packet = new ClientboundBlockUpdatePacket(new BlockPos(x, y, z), (BlockState) state);
272+
273+
((net.minecraft.world.level.Level) (Object) this).players()
274+
.stream()
275+
.filter(ServerPlayer.class::isInstance)
276+
.map(ServerPlayer.class::cast)
277+
.forEach(p -> p.connection.send(packet));
278+
}
279+
264280
// Audience
265281

266282
@Override
@@ -289,7 +305,7 @@ public void addBlockEntity(final int x, final int y, final int z, final BlockEnt
289305

290306
// Retrieve a "blank" block entity from the one we just created (or already existed) through sponge.
291307
final net.minecraft.world.level.block.entity.BlockEntity mcNewBlockEntity = (net.minecraft.world.level.block.entity.BlockEntity) this.blockEntity(x, y, z)
292-
.orElseThrow(() -> new IllegalStateException("Failed to create Block Entity at " + this.location(Vector3i.from(x, y, z))));
308+
.orElseThrow(() -> new IllegalStateException("Failed to create Block Entity at " + this.location(Vector3i.from(x, y, z))));
293309

294310
// Load the data into it.
295311
mcNewBlockEntity.loadWithComponents(tag, mcOriginalBlockEntity.getLevel().registryAccess());
@@ -381,7 +397,7 @@ public VolumeStream<W, Entity> entityStream(final Vector3i min, final Vector3i m
381397
Objects.requireNonNull(options, "options"));
382398

383399
final boolean shouldCarbonCopy = options.carbonCopy();
384-
final Vector3i size = max.sub(min).add(1, 1 ,1);
400+
final Vector3i size = max.sub(min).add(1, 1, 1);
385401
final @MonotonicNonNull ObjectArrayMutableEntityBuffer backingVolume;
386402
if (shouldCarbonCopy) {
387403
backingVolume = new ObjectArrayMutableEntityBuffer(min, size);

src/mixins/java/org/spongepowered/common/mixin/core/world/entity/EntitySelectorMixin.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import net.minecraft.world.entity.Entity;
2828
import net.minecraft.world.entity.EntitySelector;
29+
import net.minecraft.world.entity.player.Player;
2930
import org.spongepowered.asm.mixin.Final;
3031
import org.spongepowered.asm.mixin.Mixin;
3132
import org.spongepowered.asm.mixin.Mutable;
@@ -38,11 +39,20 @@
3839
public abstract class EntitySelectorMixin {
3940

4041
@Shadow @Final @Mutable public static Predicate<Entity> NO_SPECTATORS = entity -> {
41-
if (entity instanceof VanishableBridge && ((VanishableBridge) entity).bridge$vanishState().invisible()) {
42+
if (entity instanceof VanishableBridge vb && vb.bridge$vanishState().invisible()) {
4243
// Sponge: Count vanished entities as spectating
4344
return false;
4445
}
4546
return !entity.isSpectator();
4647
};
4748

49+
@Shadow @Final @Mutable public static Predicate<Entity> NO_CREATIVE_OR_SPECTATOR = $$0 -> {
50+
if ($$0 instanceof VanishableBridge vb && vb.bridge$vanishState().invisible()) {
51+
// Sponge: Count vanished entities as spectating
52+
return false;
53+
}
54+
return !($$0 instanceof Player) || !$$0.isSpectator() && !((Player)$$0).isCreative();
55+
};
56+
57+
4858
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* This file is part of Sponge, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) SpongePowered <https://www.spongepowered.org>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package org.spongepowered.common.mixin.core.world.entity.ai.sensing;
26+
27+
import net.minecraft.server.level.ServerLevel;
28+
import net.minecraft.world.entity.Entity;
29+
import net.minecraft.world.entity.LivingEntity;
30+
import net.minecraft.world.entity.ai.sensing.NearestLivingEntitySensor;
31+
import net.minecraft.world.phys.AABB;
32+
import org.spongepowered.asm.mixin.Mixin;
33+
import org.spongepowered.asm.mixin.injection.At;
34+
import org.spongepowered.asm.mixin.injection.Redirect;
35+
import org.spongepowered.common.bridge.data.VanishableBridge;
36+
37+
import java.util.List;
38+
import java.util.function.Predicate;
39+
40+
@Mixin(NearestLivingEntitySensor.class)
41+
public class NearestLivingEntitySensorMixin<T extends LivingEntity> extends SensorMixin<T> {
42+
43+
@Redirect(method = "doTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;getEntitiesOfClass(Ljava/lang/Class;Lnet/minecraft/world/phys/AABB;Ljava/util/function/Predicate;)Ljava/util/List;"))
44+
private <T extends Entity> List<T> impl$ignoreVanishedEntities(
45+
final ServerLevel instance, final Class<T> aClass, final AABB aabb,
46+
final Predicate<? super T> predicate
47+
) {
48+
return instance.getEntitiesOfClass(aClass, aabb, entity -> {
49+
if (entity instanceof VanishableBridge v) {
50+
final var state = v.bridge$vanishState();
51+
if (state.invisible() || state.untargetable()) {
52+
return false;
53+
}
54+
}
55+
return predicate.test(entity);
56+
});
57+
}
58+
}

0 commit comments

Comments
 (0)