-
Notifications
You must be signed in to change notification settings - Fork 8
feat: Upgrade to Minecraft 1.21.11 #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,8 @@ | |||||
|
|
||||||
| import net.minecraft.component.DataComponentTypes; | ||||||
| import net.minecraft.entity.vehicle.*; | ||||||
| import net.minecraft.storage.ReadView; | ||||||
| import net.minecraft.storage.WriteView; | ||||||
| import net.minecraft.world.TeleportTarget; | ||||||
| import org.spongepowered.asm.mixin.Mixin; | ||||||
| import org.spongepowered.asm.mixin.Shadow; | ||||||
|
|
@@ -49,11 +51,11 @@ private void injectConstructor(CallbackInfo callbackInfo) { | |||||
| } | ||||||
|
|
||||||
| public void scripts_chunk_loaders$startChunkLoader() { | ||||||
| if (this.getWorld().isClient) return; | ||||||
| if (this.getEntityWorld().isClient()) return; | ||||||
|
|
||||||
| this.isChunkLoader = true; | ||||||
|
|
||||||
| ScriptsChunkLoadersMod.LOGGER.info("Starting chunk loader in {}", this.getWorld().getRegistryKey().getValue()); | ||||||
| ScriptsChunkLoadersMod.LOGGER.info("Starting chunk loader in {}", this.getEntityWorld().getRegistryKey().getValue()); | ||||||
| } | ||||||
|
|
||||||
| public void scripts_chunk_loaders$setChunkLoaderNameFromInventory() { | ||||||
|
|
@@ -86,6 +88,7 @@ private void injectConstructor(CallbackInfo callbackInfo) { | |||||
| scripts_chunk_loaders$stopChunkLoader(false); | ||||||
| this.lastChunkPos = null; | ||||||
| } | ||||||
| @Unique | ||||||
| public void scripts_chunk_loaders$stopChunkLoader(Boolean keepName) { | ||||||
|
||||||
| public void scripts_chunk_loaders$stopChunkLoader(Boolean keepName) { | |
| public void scripts_chunk_loaders$stopChunkLoader(boolean keepName) { |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,10 @@ | |
| import net.minecraft.server.world.ServerWorld; | ||
| import net.minecraft.util.math.BlockPos; | ||
| import net.minecraft.util.math.Box; | ||
| import org.slf4j.Logger; | ||
| import org.spongepowered.asm.mixin.Final; | ||
| import org.spongepowered.asm.mixin.Mixin; | ||
| import org.spongepowered.asm.mixin.Shadow; | ||
| import org.spongepowered.asm.mixin.Unique; | ||
| import org.spongepowered.asm.mixin.injection.At; | ||
| import org.spongepowered.asm.mixin.injection.Inject; | ||
|
|
@@ -23,53 +26,107 @@ | |
|
|
||
| @Mixin(DispenserBlock.class) | ||
| public class DispenserBlockMixin { | ||
| @Shadow @Final private static Logger LOGGER; | ||
|
|
||
|
Comment on lines
16
to
+30
|
||
| @Inject( | ||
| at = @At("HEAD"), | ||
| method = "dispense(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;)V", | ||
| cancellable = true | ||
| ) | ||
|
|
||
| private void dispense(ServerWorld world, BlockState state, BlockPos pos, CallbackInfo info) { | ||
| if (world.isClient) return; | ||
| if (world.isClient()) return; | ||
|
|
||
| DispenserBlockEntity dispenserBlockEntity = world.getBlockEntity(pos, BlockEntityType.DISPENSER).orElse(null); | ||
| if (dispenserBlockEntity == null) return; | ||
|
|
||
| String action = this.getAction(dispenserBlockEntity); | ||
| if (action == null) return; | ||
|
|
||
| this.applyChunkLoaderAction(world, state, pos, action); | ||
|
|
||
| info.cancel(); | ||
| } | ||
|
|
||
| @Unique | ||
| private String getAction(DispenserBlockEntity dispenserBlockEntity) { | ||
| // This can't be a property because the items aren't registered when we try to access them. The constructor is | ||
| // also too early because it's called before Minecraft is even fully loaded. I don't know if there is a good | ||
| // "on block created in world" or "after item registrations" event or similar that we can hook into. So for now | ||
| // it will have to be defined here. | ||
| Item[] pattern = { | ||
| Item toggleItem = Items.GLOWSTONE; | ||
| Item startItem = Items.SHROOMLIGHT; | ||
| Item stopItem = Items.MAGMA_BLOCK; | ||
|
|
||
| if (this.patternMatches(dispenserBlockEntity, this.getPattern(toggleItem))) { | ||
| return "toggle"; | ||
| } | ||
|
|
||
| if (this.patternMatches(dispenserBlockEntity, this.getPattern(startItem))) { | ||
| return "start"; | ||
| } | ||
|
|
||
| if (this.patternMatches(dispenserBlockEntity, this.getPattern(stopItem))) { | ||
| return "stop"; | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| @Unique | ||
| private Item[] getPattern(Item centerItem) { | ||
| return new Item[]{ | ||
| Items.AIR, Items.AMETHYST_SHARD, Items.AIR, | ||
| Items.AMETHYST_SHARD, Items.GLOWSTONE, Items.AMETHYST_SHARD, | ||
| Items.AMETHYST_SHARD, centerItem, Items.AMETHYST_SHARD, | ||
| Items.AIR, Items.AMETHYST_SHARD, Items.AIR | ||
| }; | ||
| } | ||
|
|
||
| @Unique | ||
| private boolean patternMatches(DispenserBlockEntity dispenserBlockEntity, Item[] pattern) { | ||
| for (int i = 0; i < 9; i++) { | ||
| ItemStack itemStack = dispenserBlockEntity.getStack(i); | ||
| if (!itemStack.isOf(pattern[i])) { | ||
| return ; | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| this.toggleMinecraftChunkLoader(world, state, pos); | ||
| info.cancel(); | ||
| return true; | ||
| } | ||
|
|
||
| @Unique | ||
| private void toggleMinecraftChunkLoader(ServerWorld world, BlockState state, BlockPos pos) { | ||
| private void applyChunkLoaderAction(ServerWorld world, BlockState state, BlockPos pos, String action) { | ||
| BlockPos blockPos = pos.offset(state.get(DispenserBlock.FACING)); | ||
| List<AbstractMinecartEntity> list = world.getEntitiesByClass(AbstractMinecartEntity.class, new Box(blockPos), EntityPredicates.VALID_ENTITY); | ||
|
|
||
| for (AbstractMinecartEntity entity : list) { | ||
| MinecartEntityExt cart = (MinecartEntityExt)entity; | ||
|
|
||
| if (cart.scripts_chunk_loaders$isChunkLoader()) { | ||
| cart.scripts_chunk_loaders$stopChunkLoader(); | ||
| } else { | ||
| cart.scripts_chunk_loaders$startChunkLoader(); | ||
| cart.scripts_chunk_loaders$setChunkLoaderNameFromInventory(); | ||
| switch (action) { | ||
| case "toggle" -> this.toggleCart(cart); | ||
| case "start" -> this.startCart(cart); | ||
| case "stop" -> this.stopCart(cart); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Unique | ||
| private void toggleCart(MinecartEntityExt cart) { | ||
| if (cart.scripts_chunk_loaders$isChunkLoader()) { | ||
| this.stopCart(cart); | ||
| } else { | ||
| this.startCart(cart); | ||
| } | ||
| } | ||
|
|
||
| @Unique | ||
| private void startCart(MinecartEntityExt cart) { | ||
| cart.scripts_chunk_loaders$startChunkLoader(); | ||
| cart.scripts_chunk_loaders$setChunkLoaderNameFromInventory(); | ||
| } | ||
|
|
||
| @Unique | ||
| private void stopCart(MinecartEntityExt cart) { | ||
| cart.scripts_chunk_loaders$stopChunkLoader(); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file now uses
ReadView/WriteViewfor custom data, but some imports are no longer referenced (org.spongepowered.asm.mixin.Shadowandnet.minecraft.nbt.NbtCompound). Please remove unused imports to keep the mixin clean and avoid stricter compiler/lint failures.