Skip to content

Commit 6c96fc7

Browse files
committed
Remove NativeAdapter impls from API surface
1 parent cf065ee commit 6c96fc7

16 files changed

Lines changed: 227 additions & 110 deletions

File tree

worldedit-bukkit/adapters/adapter-1.21.3/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_3/PaperweightAdapter.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public NativeBlockState toNative(BlockState state) {
217217

218218
@Override
219219
public BlockState fromNative(NativeBlockState state) {
220-
return adapt(((PaperweightNativeBlockState) state).delegate());
220+
return adapt(((PaperweightNativeBlockState) state).delegate);
221221
}
222222

223223
@Override public NativePosition newBlockPos(BlockVector3 pos) {
@@ -282,10 +282,6 @@ public PaperweightAdapter() throws NoSuchFieldException, NoSuchMethodException {
282282
}
283283
}
284284

285-
public NativeAdapter asNativeAdapter() {
286-
return nativeAdapter;
287-
}
288-
289285
@Override
290286
public DataFixer getDataFixer() {
291287
return this.dataFixer;
@@ -445,7 +441,7 @@ public void setBiome(Location location, BiomeType biome) {
445441

446442
@Override
447443
public NativeWorld createNativeInterface(World world) {
448-
return new PaperweightNativeWorld(this, ((CraftWorld) world).getHandle());
444+
return new PaperweightNativeWorld(this, nativeAdapter, ((CraftWorld) world).getHandle());
449445
}
450446

451447
private static net.minecraft.core.Direction adapt(Direction face) {

worldedit-bukkit/adapters/adapter-1.21.3/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_3/wna/PaperweightNativeBlockState.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@
2626
import net.minecraft.world.level.block.Block;
2727
import net.minecraft.world.level.block.state.BlockState;
2828

29-
public record PaperweightNativeBlockState(BlockState delegate) implements NativeBlockState {
29+
public final class PaperweightNativeBlockState implements NativeBlockState {
30+
public final BlockState delegate;
31+
32+
public PaperweightNativeBlockState(BlockState delegate) {
33+
this.delegate = delegate;
34+
}
35+
3036
@Override
3137
public boolean isSame(NativeBlockState other) {
3238
return this.delegate == ((PaperweightNativeBlockState) other).delegate;
@@ -45,7 +51,7 @@ public boolean hasBlockEntity() {
4551
@Override
4652
public NativeBlockState updateFromNeighbourShapes(NativeWorld world, NativePosition position) {
4753
return new PaperweightNativeBlockState(Block.updateFromNeighbourShapes(
48-
delegate, ((PaperweightNativeWorld) world).delegate(), PaperweightAdapter.adaptPos(position)
54+
delegate, ((PaperweightNativeWorld) world).delegate, PaperweightAdapter.adaptPos(position)
4955
));
5056
}
5157
}

worldedit-bukkit/adapters/adapter-1.21.3/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_3/wna/PaperweightNativeChunk.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
import java.util.Set;
5555
import javax.annotation.Nullable;
5656

57-
public record PaperweightNativeChunk(NativeWorld owner, LevelChunk delegate) implements NativeChunk {
57+
public final class PaperweightNativeChunk implements NativeChunk {
5858
private static final MethodHandle GET_VISIBLE_CHUNK_IF_PRESENT;
5959
private static final MethodHandle GET_CHANGED_BLOCKS_PER_SECTION;
6060
private static final MethodHandle SET_HAS_CHANGED_SECTIONS;
@@ -93,6 +93,14 @@ public record PaperweightNativeChunk(NativeWorld owner, LevelChunk delegate) imp
9393
Heightmap.Types.MOTION_BLOCKING_NO_LEAVES
9494
);
9595

96+
private final NativeWorld owner;
97+
private final LevelChunk delegate;
98+
99+
public PaperweightNativeChunk(NativeWorld owner, LevelChunk delegate) {
100+
this.owner = owner;
101+
this.delegate = delegate;
102+
}
103+
96104
@Override
97105
public NativeWorld getWorld() {
98106
return owner;
@@ -116,12 +124,16 @@ public NativeBlockState getBlockState(NativePosition blockPos) {
116124

117125
@Override
118126
public @Nullable NativeBlockState setBlockState(NativePosition blockPos, NativeBlockState newState, boolean update) {
119-
return new PaperweightNativeBlockState(delegate.setBlockState(
127+
BlockState blockState = delegate.setBlockState(
120128
PaperweightAdapter.adaptPos(blockPos),
121-
((PaperweightNativeBlockState) newState).delegate(),
129+
((PaperweightNativeBlockState) newState).delegate,
122130
false,
123131
update
124-
));
132+
);
133+
if (blockState == null) {
134+
return null;
135+
}
136+
return new PaperweightNativeBlockState(blockState);
125137
}
126138

127139
@Override
@@ -184,7 +196,7 @@ public void removeSectionBlockEntity(int chunkX, int chunkY, int chunkZ) {
184196
public void initializeBlockEntity(int chunkX, int chunkY, int chunkZ, NativeBlockState newState) {
185197
BlockPos pos = delegate.getPos().getBlockAt(chunkX, chunkY, chunkZ);
186198
BlockEntity blockEntity = delegate.getBlockEntity(pos, LevelChunk.EntityCreationType.CHECK);
187-
BlockState nativeState = ((PaperweightNativeBlockState) newState).delegate();
199+
BlockState nativeState = ((PaperweightNativeBlockState) newState).delegate;
188200
if (blockEntity == null) {
189201
blockEntity = ((EntityBlock) nativeState.getBlock()).newBlockEntity(pos, nativeState);
190202
if (blockEntity != null) {
@@ -211,7 +223,7 @@ public NativeChunkSection setChunkSection(int index, NativeChunkSection section,
211223
Preconditions.checkPositionIndex(index, delegate.getSectionsCount());
212224
LevelChunkSection[] chunkSections = delegate.getSections();
213225
var oldSection = new PaperweightNativeChunkSection(chunkSections[index]);
214-
chunkSections[index] = ((PaperweightNativeChunkSection) section).delegate();
226+
chunkSections[index] = ((PaperweightNativeChunkSection) section).delegate;
215227
WNASharedImpl.postChunkSectionReplacement(this, index, oldSection, section, modifiedBlocks);
216228
delegate.markUnsaved();
217229
return oldSection;

worldedit-bukkit/adapters/adapter-1.21.3/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_3/wna/PaperweightNativeChunkSection.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,21 @@
2424
import net.minecraft.world.level.block.state.BlockState;
2525
import net.minecraft.world.level.chunk.LevelChunkSection;
2626

27-
public record PaperweightNativeChunkSection(LevelChunkSection delegate) implements NativeChunkSection {
27+
public final class PaperweightNativeChunkSection implements NativeChunkSection {
28+
final LevelChunkSection delegate;
29+
30+
public PaperweightNativeChunkSection(LevelChunkSection delegate) {
31+
this.delegate = delegate;
32+
}
33+
2834
@Override
2935
public boolean isOnlyAir() {
3036
return delegate.hasOnlyAir();
3137
}
3238

3339
@Override
3440
public NativeBlockState getThenSetBlock(int i, int j, int k, NativeBlockState blockState) {
35-
BlockState nativeState = ((PaperweightNativeBlockState) blockState).delegate();
41+
BlockState nativeState = ((PaperweightNativeBlockState) blockState).delegate;
3642
if (isOnlyAir() && nativeState.isAir()) {
3743
return blockState;
3844
}

worldedit-bukkit/adapters/adapter-1.21.3/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_3/wna/PaperweightNativeWorld.java

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,21 @@
3939
import org.bukkit.event.block.BlockPhysicsEvent;
4040
import org.enginehub.linbus.tree.LinCompoundTag;
4141

42-
public record PaperweightNativeWorld(PaperweightAdapter adapter, ServerLevel delegate) implements NativeWorld {
42+
public final class PaperweightNativeWorld implements NativeWorld {
43+
44+
private final PaperweightAdapter adapter;
45+
private final NativeAdapter nativeAdapter;
46+
final ServerLevel delegate;
47+
48+
public PaperweightNativeWorld(PaperweightAdapter adapter, NativeAdapter nativeAdapter, ServerLevel delegate) {
49+
this.adapter = adapter;
50+
this.nativeAdapter = nativeAdapter;
51+
this.delegate = delegate;
52+
}
53+
4354
@Override
4455
public NativeAdapter getAdapter() {
45-
return adapter.asNativeAdapter();
56+
return nativeAdapter;
4657
}
4758

4859
@Override
@@ -64,8 +75,8 @@ public NativeChunk getChunk(int chunkX, int chunkZ) {
6475
public void notifyBlockUpdate(NativePosition pos, NativeBlockState oldState, NativeBlockState newState) {
6576
delegate.sendBlockUpdated(
6677
PaperweightAdapter.adaptPos(pos),
67-
((PaperweightNativeBlockState) oldState).delegate(),
68-
((PaperweightNativeBlockState) newState).delegate(),
78+
((PaperweightNativeBlockState) oldState).delegate,
79+
((PaperweightNativeBlockState) newState).delegate,
6980
Block.UPDATE_NEIGHBORS | Block.UPDATE_CLIENTS
7081
);
7182
}
@@ -104,18 +115,18 @@ public void notifyNeighbors(
104115
) {
105116
BlockPos nativePos = PaperweightAdapter.adaptPos(pos);
106117
if (events) {
107-
delegate.updateNeighborsAt(nativePos, ((PaperweightNativeBlockState) oldState).delegate().getBlock());
118+
delegate.updateNeighborsAt(nativePos, ((PaperweightNativeBlockState) oldState).delegate.getBlock());
108119
} else {
109120
// When we don't want events, manually run the physics without them.
110-
Block block = ((PaperweightNativeBlockState) oldState).delegate().getBlock();
121+
Block block = ((PaperweightNativeBlockState) oldState).delegate.getBlock();
111122
fireNeighborChanged(nativePos, delegate, block, nativePos.west());
112123
fireNeighborChanged(nativePos, delegate, block, nativePos.east());
113124
fireNeighborChanged(nativePos, delegate, block, nativePos.below());
114125
fireNeighborChanged(nativePos, delegate, block, nativePos.above());
115126
fireNeighborChanged(nativePos, delegate, block, nativePos.north());
116127
fireNeighborChanged(nativePos, delegate, block, nativePos.south());
117128
}
118-
BlockState nativeNewState = ((PaperweightNativeBlockState) newState).delegate();
129+
BlockState nativeNewState = ((PaperweightNativeBlockState) newState).delegate;
119130
if (nativeNewState.hasAnalogOutputSignal()) {
120131
delegate.updateNeighbourForOutputSignal(nativePos, nativeNewState.getBlock());
121132
}
@@ -128,8 +139,8 @@ private void fireNeighborChanged(BlockPos pos, ServerLevel world, Block block, B
128139
@Override
129140
public void updateBlock(NativePosition pos, NativeBlockState oldState, NativeBlockState newState) {
130141
BlockPos nativePos = PaperweightAdapter.adaptPos(pos);
131-
BlockState nativeOldState = ((PaperweightNativeBlockState) oldState).delegate();
132-
BlockState nativeNewState = ((PaperweightNativeBlockState) newState).delegate();
142+
BlockState nativeOldState = ((PaperweightNativeBlockState) oldState).delegate;
143+
BlockState nativeNewState = ((PaperweightNativeBlockState) newState).delegate;
133144
nativeOldState.onRemove(delegate, nativePos, nativeNewState, false);
134145
nativeNewState.onPlace(delegate, nativePos, nativeOldState, false);
135146
}
@@ -139,8 +150,8 @@ public void updateNeighbors(
139150
NativePosition pos, NativeBlockState oldState, NativeBlockState newState, int recursionLimit, boolean events
140151
) {
141152
BlockPos nativePos = PaperweightAdapter.adaptPos(pos);
142-
BlockState nativeOldState = ((PaperweightNativeBlockState) oldState).delegate();
143-
BlockState nativeNewState = ((PaperweightNativeBlockState) newState).delegate();
153+
BlockState nativeOldState = ((PaperweightNativeBlockState) oldState).delegate;
154+
BlockState nativeNewState = ((PaperweightNativeBlockState) newState).delegate;
144155
nativeOldState.updateIndirectNeighbourShapes(delegate, nativePos, Block.UPDATE_CLIENTS, recursionLimit);
145156
if (events) {
146157
BlockPhysicsEvent event = new BlockPhysicsEvent(
@@ -160,8 +171,8 @@ public void updateNeighbors(
160171
public void onBlockStateChange(NativePosition pos, NativeBlockState oldState, NativeBlockState newState) {
161172
delegate.onBlockStateChange(
162173
PaperweightAdapter.adaptPos(pos),
163-
((PaperweightNativeBlockState) oldState).delegate(),
164-
((PaperweightNativeBlockState) newState).delegate()
174+
((PaperweightNativeBlockState) oldState).delegate,
175+
((PaperweightNativeBlockState) newState).delegate
165176
);
166177
}
167178
}

worldedit-bukkit/adapters/adapter-1.21.4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_4/PaperweightAdapter.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public NativeBlockState toNative(BlockState state) {
217217

218218
@Override
219219
public BlockState fromNative(NativeBlockState state) {
220-
return adapt(((PaperweightNativeBlockState) state).delegate());
220+
return adapt(((PaperweightNativeBlockState) state).delegate);
221221
}
222222

223223
@Override public NativePosition newBlockPos(BlockVector3 pos) {
@@ -282,10 +282,6 @@ public PaperweightAdapter() throws NoSuchFieldException, NoSuchMethodException {
282282
}
283283
}
284284

285-
public NativeAdapter asNativeAdapter() {
286-
return nativeAdapter;
287-
}
288-
289285
@Override
290286
public DataFixer getDataFixer() {
291287
return this.dataFixer;
@@ -445,7 +441,7 @@ public void setBiome(Location location, BiomeType biome) {
445441

446442
@Override
447443
public NativeWorld createNativeInterface(World world) {
448-
return new PaperweightNativeWorld(this, ((CraftWorld) world).getHandle());
444+
return new PaperweightNativeWorld(this, nativeAdapter, ((CraftWorld) world).getHandle());
449445
}
450446

451447
private static net.minecraft.core.Direction adapt(Direction face) {

worldedit-bukkit/adapters/adapter-1.21.4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_4/wna/PaperweightNativeBlockState.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@
2626
import net.minecraft.world.level.block.Block;
2727
import net.minecraft.world.level.block.state.BlockState;
2828

29-
public record PaperweightNativeBlockState(BlockState delegate) implements NativeBlockState {
29+
public final class PaperweightNativeBlockState implements NativeBlockState {
30+
public final BlockState delegate;
31+
32+
public PaperweightNativeBlockState(BlockState delegate) {
33+
this.delegate = delegate;
34+
}
35+
3036
@Override
3137
public boolean isSame(NativeBlockState other) {
3238
return this.delegate == ((PaperweightNativeBlockState) other).delegate;
@@ -45,7 +51,7 @@ public boolean hasBlockEntity() {
4551
@Override
4652
public NativeBlockState updateFromNeighbourShapes(NativeWorld world, NativePosition position) {
4753
return new PaperweightNativeBlockState(Block.updateFromNeighbourShapes(
48-
delegate, ((PaperweightNativeWorld) world).delegate(), PaperweightAdapter.adaptPos(position)
54+
delegate, ((PaperweightNativeWorld) world).delegate, PaperweightAdapter.adaptPos(position)
4955
));
5056
}
5157
}

worldedit-bukkit/adapters/adapter-1.21.4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_4/wna/PaperweightNativeChunk.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
import java.util.Set;
5555
import javax.annotation.Nullable;
5656

57-
public record PaperweightNativeChunk(NativeWorld owner, LevelChunk delegate) implements NativeChunk {
57+
public final class PaperweightNativeChunk implements NativeChunk {
5858
private static final MethodHandle GET_VISIBLE_CHUNK_IF_PRESENT;
5959
private static final MethodHandle GET_CHANGED_BLOCKS_PER_SECTION;
6060
private static final MethodHandle SET_HAS_CHANGED_SECTIONS;
@@ -93,6 +93,14 @@ public record PaperweightNativeChunk(NativeWorld owner, LevelChunk delegate) imp
9393
Heightmap.Types.MOTION_BLOCKING_NO_LEAVES
9494
);
9595

96+
private final NativeWorld owner;
97+
private final LevelChunk delegate;
98+
99+
public PaperweightNativeChunk(NativeWorld owner, LevelChunk delegate) {
100+
this.owner = owner;
101+
this.delegate = delegate;
102+
}
103+
96104
@Override
97105
public NativeWorld getWorld() {
98106
return owner;
@@ -116,12 +124,16 @@ public NativeBlockState getBlockState(NativePosition blockPos) {
116124

117125
@Override
118126
public @Nullable NativeBlockState setBlockState(NativePosition blockPos, NativeBlockState newState, boolean update) {
119-
return new PaperweightNativeBlockState(delegate.setBlockState(
127+
BlockState blockState = delegate.setBlockState(
120128
PaperweightAdapter.adaptPos(blockPos),
121-
((PaperweightNativeBlockState) newState).delegate(),
129+
((PaperweightNativeBlockState) newState).delegate,
122130
false,
123131
update
124-
));
132+
);
133+
if (blockState == null) {
134+
return null;
135+
}
136+
return new PaperweightNativeBlockState(blockState);
125137
}
126138

127139
@Override
@@ -184,7 +196,7 @@ public void removeSectionBlockEntity(int chunkX, int chunkY, int chunkZ) {
184196
public void initializeBlockEntity(int chunkX, int chunkY, int chunkZ, NativeBlockState newState) {
185197
BlockPos pos = delegate.getPos().getBlockAt(chunkX, chunkY, chunkZ);
186198
BlockEntity blockEntity = delegate.getBlockEntity(pos, LevelChunk.EntityCreationType.CHECK);
187-
BlockState nativeState = ((PaperweightNativeBlockState) newState).delegate();
199+
BlockState nativeState = ((PaperweightNativeBlockState) newState).delegate;
188200
if (blockEntity == null) {
189201
blockEntity = ((EntityBlock) nativeState.getBlock()).newBlockEntity(pos, nativeState);
190202
if (blockEntity != null) {
@@ -211,7 +223,7 @@ public NativeChunkSection setChunkSection(int index, NativeChunkSection section,
211223
Preconditions.checkPositionIndex(index, delegate.getSectionsCount());
212224
LevelChunkSection[] chunkSections = delegate.getSections();
213225
var oldSection = new PaperweightNativeChunkSection(chunkSections[index]);
214-
chunkSections[index] = ((PaperweightNativeChunkSection) section).delegate();
226+
chunkSections[index] = ((PaperweightNativeChunkSection) section).delegate;
215227
WNASharedImpl.postChunkSectionReplacement(this, index, oldSection, section, modifiedBlocks);
216228
delegate.markUnsaved();
217229
return oldSection;

worldedit-bukkit/adapters/adapter-1.21.4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_21_4/wna/PaperweightNativeChunkSection.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,21 @@
2424
import net.minecraft.world.level.block.state.BlockState;
2525
import net.minecraft.world.level.chunk.LevelChunkSection;
2626

27-
public record PaperweightNativeChunkSection(LevelChunkSection delegate) implements NativeChunkSection {
27+
public final class PaperweightNativeChunkSection implements NativeChunkSection {
28+
final LevelChunkSection delegate;
29+
30+
public PaperweightNativeChunkSection(LevelChunkSection delegate) {
31+
this.delegate = delegate;
32+
}
33+
2834
@Override
2935
public boolean isOnlyAir() {
3036
return delegate.hasOnlyAir();
3137
}
3238

3339
@Override
3440
public NativeBlockState getThenSetBlock(int i, int j, int k, NativeBlockState blockState) {
35-
BlockState nativeState = ((PaperweightNativeBlockState) blockState).delegate();
41+
BlockState nativeState = ((PaperweightNativeBlockState) blockState).delegate;
3642
if (isOnlyAir() && nativeState.isAir()) {
3743
return blockState;
3844
}

0 commit comments

Comments
 (0)