diff options
author | Linnea Gräf <nea@nea.moe> | 2024-11-09 18:11:18 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-11-09 18:11:18 +0100 |
commit | 94f12b5bc032aac26371bf5c086492436d92878c (patch) | |
tree | c940adb066653ed4f1386e8ded60d064375861dd /src | |
download | beacon-range-extender-94f12b5bc032aac26371bf5c086492436d92878c.tar.gz beacon-range-extender-94f12b5bc032aac26371bf5c086492436d92878c.tar.bz2 beacon-range-extender-94f12b5bc032aac26371bf5c086492436d92878c.zip |
Init
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/moe/nea/beacons/BeaconBeamSectionExtra.java | 13 | ||||
-rw-r--r-- | src/main/java/moe/nea/beacons/BeaconBlockEntityExtra.java | 17 | ||||
-rw-r--r-- | src/main/java/moe/nea/beacons/BeaconRangeExtender.java | 5 | ||||
-rw-r--r-- | src/main/java/moe/nea/beacons/BeaconRangeIncreaser.java | 16 | ||||
-rw-r--r-- | src/main/java/moe/nea/beacons/mixin/BeaconBeamSectionMixin.java | 22 | ||||
-rw-r--r-- | src/main/java/moe/nea/beacons/mixin/BeaconMixin.java | 94 | ||||
-rw-r--r-- | src/main/java/moe/nea/beacons/mixin/SkullBlockRangeExtender.java | 14 | ||||
-rw-r--r-- | src/main/resources/assets/beacon-range-increaser/icon.png | bin | 0 -> 5789 bytes | |||
-rw-r--r-- | src/main/resources/beacon-range-increaser.mixins.json | 13 | ||||
-rw-r--r-- | src/main/resources/fabric.mod.json | 30 |
10 files changed, 224 insertions, 0 deletions
diff --git a/src/main/java/moe/nea/beacons/BeaconBeamSectionExtra.java b/src/main/java/moe/nea/beacons/BeaconBeamSectionExtra.java new file mode 100644 index 0000000..2f5698a --- /dev/null +++ b/src/main/java/moe/nea/beacons/BeaconBeamSectionExtra.java @@ -0,0 +1,13 @@ +package moe.nea.beacons; + +import net.minecraft.world.level.block.entity.BeaconBlockEntity; + +public interface BeaconBeamSectionExtra { + static BeaconBeamSectionExtra cast(BeaconBlockEntity.BeaconBeamSection beaconBeamSection) { + return (BeaconBeamSectionExtra) beaconBeamSection; + } + + void setRangeExtenders_nea(int newRangeExtenders); + + int getRangeExtenders_nea(); +} diff --git a/src/main/java/moe/nea/beacons/BeaconBlockEntityExtra.java b/src/main/java/moe/nea/beacons/BeaconBlockEntityExtra.java new file mode 100644 index 0000000..46eb2eb --- /dev/null +++ b/src/main/java/moe/nea/beacons/BeaconBlockEntityExtra.java @@ -0,0 +1,17 @@ +package moe.nea.beacons; + +import net.minecraft.world.level.block.entity.BeaconBlockEntity; + +import java.util.List; + +public interface BeaconBlockEntityExtra { + static BeaconBlockEntityExtra cast(BeaconBlockEntity beaconBlockEntity) { + return (BeaconBlockEntityExtra) beaconBlockEntity; + } + + void setRangeExtender_nea(int rangeExtender); + + int getRangeExtender_nea(); + + List<BeaconBlockEntity.BeaconBeamSection> getCheckingBeamSections_nea(); +} diff --git a/src/main/java/moe/nea/beacons/BeaconRangeExtender.java b/src/main/java/moe/nea/beacons/BeaconRangeExtender.java new file mode 100644 index 0000000..f4fd12e --- /dev/null +++ b/src/main/java/moe/nea/beacons/BeaconRangeExtender.java @@ -0,0 +1,5 @@ +package moe.nea.beacons; + +public interface BeaconRangeExtender { + int extraBeaconRange_nea(); +} diff --git a/src/main/java/moe/nea/beacons/BeaconRangeIncreaser.java b/src/main/java/moe/nea/beacons/BeaconRangeIncreaser.java new file mode 100644 index 0000000..702a4fe --- /dev/null +++ b/src/main/java/moe/nea/beacons/BeaconRangeIncreaser.java @@ -0,0 +1,16 @@ +package moe.nea.beacons; + +import net.fabricmc.api.ModInitializer; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class BeaconRangeIncreaser implements ModInitializer { + public static final String MOD_ID = "beacon-range-increaser"; + + public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); + + @Override + public void onInitialize() { + } +}
\ No newline at end of file diff --git a/src/main/java/moe/nea/beacons/mixin/BeaconBeamSectionMixin.java b/src/main/java/moe/nea/beacons/mixin/BeaconBeamSectionMixin.java new file mode 100644 index 0000000..f4fe948 --- /dev/null +++ b/src/main/java/moe/nea/beacons/mixin/BeaconBeamSectionMixin.java @@ -0,0 +1,22 @@ +package moe.nea.beacons.mixin; + +import moe.nea.beacons.BeaconBeamSectionExtra; +import net.minecraft.world.level.block.entity.BeaconBlockEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; + +@Mixin(BeaconBlockEntity.BeaconBeamSection.class) +public class BeaconBeamSectionMixin implements BeaconBeamSectionExtra { + @Unique + private int rangeExtenders; + + @Override + public void setRangeExtenders_nea(int newRangeExtenders) { + rangeExtenders = newRangeExtenders; + } + + @Override + public int getRangeExtenders_nea() { + return rangeExtenders; + } +} diff --git a/src/main/java/moe/nea/beacons/mixin/BeaconMixin.java b/src/main/java/moe/nea/beacons/mixin/BeaconMixin.java new file mode 100644 index 0000000..4602208 --- /dev/null +++ b/src/main/java/moe/nea/beacons/mixin/BeaconMixin.java @@ -0,0 +1,94 @@ +package moe.nea.beacons.mixin; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Local; +import moe.nea.beacons.BeaconBeamSectionExtra; +import moe.nea.beacons.BeaconBlockEntityExtra; +import moe.nea.beacons.BeaconRangeExtender; +import moe.nea.beacons.BeaconRangeIncreaser; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BeaconBlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import org.objectweb.asm.Opcodes; +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; +import org.spongepowered.asm.mixin.injection.ModifyArg; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.List; + +@Mixin(BeaconBlockEntity.class) +public class BeaconMixin implements BeaconBlockEntityExtra { + + @Shadow + private List<BeaconBlockEntity.BeaconBeamSection> checkingBeamSections; + @Unique + private int rangeExtenders; + + @Override + public int getRangeExtender_nea() { + return rangeExtenders; + } + + @Override + public void setRangeExtender_nea(int rangeExtender) { + this.rangeExtenders = rangeExtender; + } + + @Override + public List<BeaconBlockEntity.BeaconBeamSection> getCheckingBeamSections_nea() { + return this.checkingBeamSections; + } + + @Inject(method = "tick", at = @At(value = "FIELD", target = "Lnet/minecraft/world/level/block/entity/BeaconBlockEntity;beamSections:Ljava/util/List;", opcode = Opcodes.ASTORE)) + private static void saveRangeExtender(Level level, BlockPos blockPos, BlockState blockState, BeaconBlockEntity beaconBlockEntity, CallbackInfo ci) { + var extra = BeaconBlockEntityExtra.cast(beaconBlockEntity); + var accExtraRange = 0; + for (var beaconBeamSection : extra.getCheckingBeamSections_nea()) { + var extraSection = BeaconBeamSectionExtra.cast(beaconBeamSection); + accExtraRange += extraSection.getRangeExtenders_nea(); + } + extra.setRangeExtender_nea(accExtraRange); + } + + @WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/core/BlockPos;above()Lnet/minecraft/core/BlockPos;")) + private static BlockPos checkForRangeExtender( + BlockPos oldBlockPos, Operation<BlockPos> original, @Local BeaconBlockEntity.BeaconBeamSection lastSection, + @Local(argsOnly = true) Level level) { + var newPos = original.call(oldBlockPos); + var blockState = level.getBlockState(oldBlockPos); + if (blockState.getBlock() instanceof BeaconRangeExtender extender && lastSection != null) { + var lastSectionExtra = BeaconBeamSectionExtra.cast(lastSection); + lastSectionExtra.setRangeExtenders_nea( + extender.extraBeaconRange_nea() + lastSectionExtra.getRangeExtenders_nea() + ); + } + return newPos; + } + + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/entity/BeaconBlockEntity;applyEffects(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;ILnet/minecraft/core/Holder;Lnet/minecraft/core/Holder;)V")) + private static void applyExtraEffects(Level level, BlockPos blockPos, BlockState blockState, BeaconBlockEntity beaconBlockEntity, CallbackInfo ci) { + var extra = BeaconBlockEntityExtra.cast(beaconBlockEntity); + lastRangeExtend = extra.getRangeExtender_nea(); + } + + @Unique + private static int lastRangeExtend = -1; + + @ModifyArg(method = "applyEffects", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/phys/AABB;inflate(D)Lnet/minecraft/world/phys/AABB;")) + private static double increaseRange(double d) { + if (lastRangeExtend < 0) { + BeaconRangeIncreaser.LOGGER.error("Could not get extended range from beacon range increase mod (which is awesome, btw)"); + return d; + } + d += lastRangeExtend; + lastRangeExtend = -1; + return d; + } + +} diff --git a/src/main/java/moe/nea/beacons/mixin/SkullBlockRangeExtender.java b/src/main/java/moe/nea/beacons/mixin/SkullBlockRangeExtender.java new file mode 100644 index 0000000..90a1fc0 --- /dev/null +++ b/src/main/java/moe/nea/beacons/mixin/SkullBlockRangeExtender.java @@ -0,0 +1,14 @@ +package moe.nea.beacons.mixin; + +import moe.nea.beacons.BeaconRangeExtender; +import net.minecraft.world.level.block.SkullBlock; +import net.minecraft.world.level.block.WitherSkullBlock; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(SkullBlock.class) +public class SkullBlockRangeExtender implements BeaconRangeExtender { + @Override + public int extraBeaconRange_nea() { + return ((SkullBlock) (Object) this) instanceof WitherSkullBlock ? 32 : 5; + } +} diff --git a/src/main/resources/assets/beacon-range-increaser/icon.png b/src/main/resources/assets/beacon-range-increaser/icon.png Binary files differnew file mode 100644 index 0000000..ec6beca --- /dev/null +++ b/src/main/resources/assets/beacon-range-increaser/icon.png diff --git a/src/main/resources/beacon-range-increaser.mixins.json b/src/main/resources/beacon-range-increaser.mixins.json new file mode 100644 index 0000000..c7ca9b6 --- /dev/null +++ b/src/main/resources/beacon-range-increaser.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "package": "moe.nea.beacons.mixin", + "compatibilityLevel": "JAVA_21", + "mixins": [ + "BeaconBeamSectionMixin", + "BeaconMixin", + "SkullBlockRangeExtender" + ], + "injectors": { + "defaultRequire": 1 + } +}
\ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..d3aec2d --- /dev/null +++ b/src/main/resources/fabric.mod.json @@ -0,0 +1,30 @@ +{ + "schemaVersion": 1, + "id": "beacon-range-increaser", + "version": "${version}", + "name": "Beacon Range Increaser", + "description": "Increases the range of beacons, if you place skulls in the path of the beam (32 for wither skulls, 5 blocks for other skulls).", + "authors": [ + "Linnea Gräf" + ], + "contact": { + "sources": "https://github.com/nea89o/beacon-range-extender" + }, + "license": "MIT", + "icon": "assets/beacon-range-increaser/icon.png", + "environment": "*", + "entrypoints": { + "main": [ + "moe.nea.beacons.BeaconRangeIncreaser" + ] + }, + "mixins": [ + "beacon-range-increaser.mixins.json" + ], + "depends": { + "fabricloader": ">=0.16.9", + "minecraft": "~1.21", + "java": ">=21", + "fabric-api": "*" + } +}
\ No newline at end of file |