Skip to content

Commit 307e8b7

Browse files
committed
Fix mixin conflict with YungsApi (#1262)
1 parent fc9d39e commit 307e8b7

File tree

2 files changed

+203
-5
lines changed

2 files changed

+203
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,224 @@
11
package io.izzel.arclight.common.mixin.vanilla.world.level.levelgen.structure.templatesystem;
22

3+
import com.google.common.collect.Lists;
4+
import com.mojang.datafixers.util.Pair;
35
import io.izzel.arclight.common.bridge.core.world.level.levelgen.structure.templatesystem.StructureTemplateBridge;
46
import net.minecraft.core.BlockPos;
7+
import net.minecraft.core.Direction;
8+
import net.minecraft.core.Vec3i;
9+
import net.minecraft.nbt.CompoundTag;
10+
import net.minecraft.util.RandomSource;
11+
import net.minecraft.world.Clearable;
12+
import net.minecraft.world.level.LevelAccessor;
513
import net.minecraft.world.level.ServerLevelAccessor;
14+
import net.minecraft.world.level.block.Block;
15+
import net.minecraft.world.level.block.Blocks;
16+
import net.minecraft.world.level.block.LiquidBlockContainer;
617
import net.minecraft.world.level.block.Mirror;
718
import net.minecraft.world.level.block.Rotation;
19+
import net.minecraft.world.level.block.entity.BlockEntity;
20+
import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity;
21+
import net.minecraft.world.level.block.state.BlockState;
822
import net.minecraft.world.level.levelgen.structure.BoundingBox;
923
import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings;
1024
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
25+
import net.minecraft.world.level.material.FluidState;
26+
import net.minecraft.world.phys.shapes.BitSetDiscreteVoxelShape;
27+
import net.minecraft.world.phys.shapes.DiscreteVoxelShape;
28+
import org.bukkit.craftbukkit.v.block.CraftBlockEntityState;
29+
import org.bukkit.craftbukkit.v.block.CraftBlockState;
30+
import org.bukkit.craftbukkit.v.block.CraftBlockStates;
31+
import org.bukkit.craftbukkit.v.block.CraftLootable;
32+
import org.bukkit.craftbukkit.v.util.CraftStructureTransformer;
33+
import org.bukkit.craftbukkit.v.util.TransformerGeneratorAccess;
1134
import org.jetbrains.annotations.Nullable;
35+
import org.spongepowered.asm.mixin.Final;
1236
import org.spongepowered.asm.mixin.Mixin;
37+
import org.spongepowered.asm.mixin.Overwrite;
1338
import org.spongepowered.asm.mixin.Shadow;
1439

15-
@Mixin(StructureTemplate.class)
40+
import java.util.Iterator;
41+
import java.util.List;
42+
43+
@Mixin(value = StructureTemplate.class)
1644
public abstract class StructureTemplateMixin_Vanilla implements StructureTemplateBridge {
1745

1846
// @formatter:off
1947
@Shadow protected abstract void placeEntities(ServerLevelAccessor serverLevelAccessor, BlockPos blockPos, Mirror mirror, Rotation rotation, BlockPos blockPos2, @Nullable BoundingBox boundingBox, boolean bl);
48+
@Shadow @Final public List<StructureTemplate.Palette> palettes;
49+
@Shadow @Final public List<StructureTemplate.StructureEntityInfo> entityInfoList;
50+
@Shadow private Vec3i size;
51+
@Shadow public static void updateShapeAtEdge(LevelAccessor p_74511_, int p_74512_, DiscreteVoxelShape p_74513_, int p_74514_, int p_74515_, int p_74516_) { }
2052
// @formatter:on
2153

22-
@Override
23-
public void bridge$platform$placeEntities(ServerLevelAccessor serverLevelAccessor, BlockPos blockPos, Mirror mirror, Rotation rotation, BlockPos blockPos2, @Nullable BoundingBox boundingBox, boolean bl, StructurePlaceSettings placementIn) {
24-
this.placeEntities(serverLevelAccessor, blockPos, mirror, rotation, blockPos2, boundingBox, bl);
54+
/**
55+
* @author IzzelAliz
56+
* @reason
57+
*/
58+
@Overwrite
59+
public boolean placeInWorld(ServerLevelAccessor p_230329_, BlockPos pos, BlockPos p_230331_, StructurePlaceSettings placeSettings, RandomSource p_230333_, int p_230334_) {
60+
if (this.palettes.isEmpty()) {
61+
return false;
62+
} else {
63+
// CraftBukkit start
64+
// We only want the TransformerGeneratorAccess at certain locations because in here are many "block update" calls that shouldn't be transformed
65+
var wrappedAccess = p_230329_;
66+
CraftStructureTransformer structureTransformer = null;
67+
if (wrappedAccess instanceof TransformerGeneratorAccess transformerAccess) {
68+
p_230329_ = transformerAccess.getHandle();
69+
structureTransformer = transformerAccess.getStructureTransformer();
70+
// The structureTransformer is not needed if we can not transform blocks therefore we can save a little bit of performance doing this
71+
if (structureTransformer != null && !structureTransformer.canTransformBlocks()) {
72+
structureTransformer = null;
73+
}
74+
}
75+
// CraftBukkit end
76+
List<StructureTemplate.StructureBlockInfo> list = placeSettings.getRandomPalette(this.palettes, pos).blocks();
77+
if ((!list.isEmpty() || !placeSettings.isIgnoreEntities() && !this.entityInfoList.isEmpty()) && this.size.getX() >= 1 && this.size.getY() >= 1 && this.size.getZ() >= 1) {
78+
BoundingBox boundingbox = placeSettings.getBoundingBox();
79+
List<BlockPos> list1 = Lists.newArrayListWithCapacity(placeSettings.shouldKeepLiquids() ? list.size() : 0);
80+
List<BlockPos> list2 = Lists.newArrayListWithCapacity(placeSettings.shouldKeepLiquids() ? list.size() : 0);
81+
List<Pair<BlockPos, CompoundTag>> list3 = Lists.newArrayListWithCapacity(list.size());
82+
int i = Integer.MAX_VALUE;
83+
int j = Integer.MAX_VALUE;
84+
int k = Integer.MAX_VALUE;
85+
int l = Integer.MIN_VALUE;
86+
int i1 = Integer.MIN_VALUE;
87+
int j1 = Integer.MIN_VALUE;
88+
89+
for (StructureTemplate.StructureBlockInfo structuretemplate$structureblockinfo : StructureTemplate.processBlockInfos(p_230329_, pos, p_230331_, placeSettings, list)) {
90+
BlockPos blockpos = structuretemplate$structureblockinfo.pos();
91+
if (boundingbox == null || boundingbox.isInside(blockpos)) {
92+
FluidState fluidstate = placeSettings.shouldKeepLiquids() ? p_230329_.getFluidState(blockpos) : null;
93+
BlockState blockstate = structuretemplate$structureblockinfo.state().mirror(placeSettings.getMirror()).rotate(placeSettings.getRotation());
94+
if (structuretemplate$structureblockinfo.nbt() != null) {
95+
BlockEntity blockentity = p_230329_.getBlockEntity(blockpos);
96+
Clearable.tryClear(blockentity);
97+
p_230329_.setBlock(blockpos, Blocks.BARRIER.defaultBlockState(), 20);
98+
}
99+
// CraftBukkit start
100+
if (structureTransformer != null) {
101+
var craftBlockState = (CraftBlockState) CraftBlockStates.getBlockState(blockpos, blockstate, null);
102+
if (structuretemplate$structureblockinfo.nbt() != null && craftBlockState instanceof CraftBlockEntityState<?> entityState) {
103+
entityState.loadData(structuretemplate$structureblockinfo.nbt());
104+
if (craftBlockState instanceof CraftLootable<?> craftLootable) {
105+
craftLootable.setSeed(p_230333_.nextLong());
106+
}
107+
}
108+
craftBlockState = structureTransformer.transformCraftState(craftBlockState);
109+
blockstate = craftBlockState.getHandle();
110+
structuretemplate$structureblockinfo = new StructureTemplate.StructureBlockInfo(blockpos, blockstate, (craftBlockState instanceof CraftBlockEntityState<?> craftBlockEntityState ? craftBlockEntityState.getSnapshotNBT() : null));
111+
}
112+
// CraftBukkit end
113+
114+
if (p_230329_.setBlock(blockpos, blockstate, p_230334_)) {
115+
i = Math.min(i, blockpos.getX());
116+
j = Math.min(j, blockpos.getY());
117+
k = Math.min(k, blockpos.getZ());
118+
l = Math.max(l, blockpos.getX());
119+
i1 = Math.max(i1, blockpos.getY());
120+
j1 = Math.max(j1, blockpos.getZ());
121+
list3.add(Pair.of(blockpos, structuretemplate$structureblockinfo.nbt()));
122+
if (structuretemplate$structureblockinfo.nbt() != null) {
123+
BlockEntity blockentity1 = p_230329_.getBlockEntity(blockpos);
124+
if (blockentity1 != null) {
125+
if (structureTransformer == null && blockentity1 instanceof RandomizableContainerBlockEntity) {
126+
structuretemplate$structureblockinfo.nbt().putLong("LootTableSeed", p_230333_.nextLong());
127+
}
128+
129+
blockentity1.load(structuretemplate$structureblockinfo.nbt());
130+
}
131+
}
132+
133+
if (fluidstate != null) {
134+
if (blockstate.getFluidState().isSource()) {
135+
list2.add(blockpos);
136+
} else if (blockstate.getBlock() instanceof LiquidBlockContainer) {
137+
((LiquidBlockContainer) blockstate.getBlock()).placeLiquid(p_230329_, blockpos, blockstate, fluidstate);
138+
if (!fluidstate.isSource()) {
139+
list1.add(blockpos);
140+
}
141+
}
142+
}
143+
}
144+
}
145+
}
146+
147+
boolean flag = true;
148+
Direction[] adirection = new Direction[]{Direction.UP, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST};
149+
150+
while (flag && !list1.isEmpty()) {
151+
flag = false;
152+
Iterator<BlockPos> iterator = list1.iterator();
153+
154+
while (iterator.hasNext()) {
155+
BlockPos blockpos3 = iterator.next();
156+
FluidState fluidstate2 = p_230329_.getFluidState(blockpos3);
157+
158+
for (int i2 = 0; i2 < adirection.length && !fluidstate2.isSource(); ++i2) {
159+
BlockPos blockpos1 = blockpos3.relative(adirection[i2]);
160+
FluidState fluidstate1 = p_230329_.getFluidState(blockpos1);
161+
if (fluidstate1.isSource() && !list2.contains(blockpos1)) {
162+
fluidstate2 = fluidstate1;
163+
}
164+
}
165+
166+
if (fluidstate2.isSource()) {
167+
BlockState blockstate1 = p_230329_.getBlockState(blockpos3);
168+
Block block = blockstate1.getBlock();
169+
if (block instanceof LiquidBlockContainer) {
170+
((LiquidBlockContainer) block).placeLiquid(p_230329_, blockpos3, blockstate1, fluidstate2);
171+
flag = true;
172+
iterator.remove();
173+
}
174+
}
175+
}
176+
}
177+
178+
if (i <= l) {
179+
if (!placeSettings.getKnownShape()) {
180+
DiscreteVoxelShape discretevoxelshape = new BitSetDiscreteVoxelShape(l - i + 1, i1 - j + 1, j1 - k + 1);
181+
int k1 = i;
182+
int l1 = j;
183+
int j2 = k;
184+
185+
for (Pair<BlockPos, CompoundTag> pair1 : list3) {
186+
BlockPos blockpos2 = pair1.getFirst();
187+
discretevoxelshape.fill(blockpos2.getX() - k1, blockpos2.getY() - l1, blockpos2.getZ() - j2);
188+
}
189+
190+
updateShapeAtEdge(p_230329_, p_230334_, discretevoxelshape, k1, l1, j2);
191+
}
192+
193+
for (Pair<BlockPos, CompoundTag> pair : list3) {
194+
BlockPos blockpos4 = pair.getFirst();
195+
if (!placeSettings.getKnownShape()) {
196+
BlockState blockstate2 = p_230329_.getBlockState(blockpos4);
197+
BlockState blockstate3 = Block.updateFromNeighbourShapes(blockstate2, p_230329_, blockpos4);
198+
if (blockstate2 != blockstate3) {
199+
p_230329_.setBlock(blockpos4, blockstate3, p_230334_ & -2 | 16);
200+
}
201+
202+
p_230329_.blockUpdated(blockpos4, blockstate3.getBlock());
203+
}
204+
205+
if (pair.getSecond() != null) {
206+
BlockEntity blockentity2 = p_230329_.getBlockEntity(blockpos4);
207+
if (blockentity2 != null) {
208+
blockentity2.setChanged();
209+
}
210+
}
211+
}
212+
}
213+
214+
if (!placeSettings.isIgnoreEntities()) {
215+
this.placeEntities(wrappedAccess, pos, placeSettings.getMirror(), placeSettings.getRotation(), placeSettings.getRotationPivot(), placeSettings.getBoundingBox(), placeSettings.shouldFinalizeEntities());
216+
}
217+
218+
return true;
219+
} else {
220+
return false;
221+
}
222+
}
25223
}
26224
}

arclight-common/src/main/resources/mixins.arclight.vanilla.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"conformVisibility": true,
1414
"requireAnnotations": false
1515
},
16-
"mixinPriority": 500,
16+
"mixinPriority": 555,
1717
"compatibilityLevel": "JAVA_17",
1818
"mixins": [
1919
"server.Main_ServerShutdownThreadMixin_Vanilla",

0 commit comments

Comments
 (0)