-
-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
465 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
.../java/io/izzel/arclight/common/bridge/core/world/level/levelgen/StructureStartBridge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.izzel.arclight.common.bridge.core.world.level.levelgen; | ||
|
||
import org.bukkit.event.world.AsyncStructureGenerateEvent; | ||
|
||
public interface StructureStartBridge { | ||
|
||
void bridge$setGenerateCause(AsyncStructureGenerateEvent.Cause cause); | ||
} |
3 changes: 3 additions & 0 deletions
3
...rc/main/java/io/izzel/arclight/common/bridge/core/world/storage/loot/LootTableBridge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
package io.izzel.arclight.common.bridge.core.world.storage.loot; | ||
|
||
import org.bukkit.craftbukkit.v.CraftLootTable; | ||
|
||
public interface LootTableBridge { | ||
|
||
void bridge$setCraftLootTable(CraftLootTable lootTable); | ||
} |
16 changes: 16 additions & 0 deletions
16
arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/PotionTypeMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.izzel.arclight.common.mixin.bukkit; | ||
|
||
import org.bukkit.NamespacedKey; | ||
import org.bukkit.potion.PotionType; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
@Mixin(PotionType.class) | ||
public class PotionTypeMixin { | ||
|
||
@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Lorg/bukkit/NamespacedKey;minecraft(Ljava/lang/String;)Lorg/bukkit/NamespacedKey;")) | ||
private NamespacedKey arclight$nsFromString(String key) { | ||
return NamespacedKey.fromString(key); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
.../src/main/java/io/izzel/arclight/common/mixin/core/server/commands/PlaceCommandMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.izzel.arclight.common.mixin.core.server.commands; | ||
|
||
import io.izzel.arclight.common.bridge.core.world.level.levelgen.StructureStartBridge; | ||
import net.minecraft.commands.CommandSourceStack; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Holder; | ||
import net.minecraft.server.commands.PlaceCommand; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.world.level.chunk.ChunkGenerator; | ||
import net.minecraft.world.level.levelgen.structure.Structure; | ||
import net.minecraft.world.level.levelgen.structure.StructureStart; | ||
import org.bukkit.event.world.AsyncStructureGenerateEvent; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; | ||
|
||
@Mixin(PlaceCommand.class) | ||
public class PlaceCommandMixin { | ||
|
||
@Inject(method = "placeStructure", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/levelgen/structure/StructureStart;getBoundingBox()Lnet/minecraft/world/level/levelgen/structure/BoundingBox;")) | ||
private static void arclight$cause(CommandSourceStack p_214588_, Holder.Reference<Structure> p_251799_, BlockPos p_214590_, CallbackInfoReturnable<Integer> cir, | ||
ServerLevel level, Structure structure, ChunkGenerator chunkGenerator, StructureStart structureStart) { | ||
((StructureStartBridge) (Object) structureStart).bridge$setGenerateCause(AsyncStructureGenerateEvent.Cause.COMMAND); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
.../izzel/arclight/common/mixin/core/world/level/levelgen/structure/StructurePieceMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package io.izzel.arclight.common.mixin.core.world.level.levelgen.structure; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.util.RandomSource; | ||
import net.minecraft.world.level.ServerLevelAccessor; | ||
import net.minecraft.world.level.WorldGenLevel; | ||
import net.minecraft.world.level.block.Blocks; | ||
import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.levelgen.structure.BoundingBox; | ||
import net.minecraft.world.level.levelgen.structure.StructurePiece; | ||
import org.bukkit.craftbukkit.v.block.CraftBlockEntityState; | ||
import org.bukkit.craftbukkit.v.block.CraftBlockState; | ||
import org.bukkit.craftbukkit.v.block.CraftBlockStates; | ||
import org.bukkit.craftbukkit.v.block.CraftCreatureSpawner; | ||
import org.bukkit.craftbukkit.v.util.TransformerGeneratorAccess; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
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.asm.mixin.injection.callback.LocalCapture; | ||
|
||
@Mixin(StructurePiece.class) | ||
public class StructurePieceMixin { | ||
|
||
@Inject(method = "placeBlock", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/WorldGenLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) | ||
private void arclight$useTransformer(WorldGenLevel level, BlockState p_73436_, int p_73437_, int p_73438_, int p_73439_, BoundingBox p_73440_, CallbackInfo ci, BlockPos pos) { | ||
if (level instanceof TransformerGeneratorAccess transformerGeneratorAccess) { | ||
transformerGeneratorAccess.setCraftBlock(pos, (CraftBlockState) CraftBlockStates.getBlockState(pos, p_73436_, null), 2); | ||
ci.cancel(); | ||
} | ||
} | ||
|
||
@Unique | ||
protected boolean placeCraftBlockEntity(ServerLevelAccessor worldAccess, BlockPos position, CraftBlockEntityState<?> craftBlockEntityState, int i) { | ||
if (worldAccess instanceof TransformerGeneratorAccess transformerAccess) { | ||
return transformerAccess.setCraftBlock(position, craftBlockEntityState, i); | ||
} | ||
boolean result = worldAccess.setBlock(position, craftBlockEntityState.getHandle(), i); | ||
var tileEntity = worldAccess.getBlockEntity(position); | ||
if (tileEntity != null) { | ||
tileEntity.load(craftBlockEntityState.getSnapshotNBT()); | ||
} | ||
return result; | ||
} | ||
|
||
@Unique | ||
protected void placeCraftSpawner(ServerLevelAccessor worldAccess, BlockPos position, org.bukkit.entity.EntityType entityType, int i) { | ||
// This method is used in structures that are generated by code and place spawners as they set the entity after the block was placed making it impossible for plugins to access that information | ||
var spawner = (CraftCreatureSpawner) CraftBlockStates.getBlockState(position, Blocks.SPAWNER.defaultBlockState(), null); | ||
spawner.setSpawnedType(entityType); | ||
placeCraftBlockEntity(worldAccess, position, spawner, i); | ||
} | ||
|
||
@Unique | ||
protected void setCraftLootTable(ServerLevelAccessor worldAccess, BlockPos position, RandomSource randomSource, ResourceLocation loottableKey) { | ||
// This method is used in structures that use data markers to a loot table to loot containers as otherwise plugins won't have access to that information. | ||
var tileEntity = worldAccess.getBlockEntity(position); | ||
if (tileEntity instanceof RandomizableContainerBlockEntity tileEntityLootable) { | ||
tileEntityLootable.setLootTable(loottableKey, randomSource.nextLong()); | ||
if (worldAccess instanceof TransformerGeneratorAccess transformerAccess) { | ||
transformerAccess.setCraftBlock(position, (CraftBlockState) CraftBlockStates.getBlockState(position, tileEntity.getBlockState(), tileEntityLootable.saveWithFullMetadata()), 3); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.