Skip to content

Commit

Permalink
Allow GT Screwdrivers to Configure AA Lasers
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit committed Jan 2, 2025
1 parent f939840 commit d2110b2
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/main/java/com/nomiceu/nomilabs/config/LabsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,16 @@ public static class ModIntegration {
@Config.LangKey("config.nomilabs.mod_integration.bqu_fluid_task_fixes")
public boolean enableBQuFluidTaskFixes = true;

@Config.Comment({
"Whether to make the Actually Additions Laser Relays take all GT Screwdrivers as the configuration tool.",
"Note that compasses will still work if this config is true! Change the Actually Additions config to change that behaviour!",
"Changing it to gregtech:screwdriver instead of minecraft:compass is recommended.",
"You wil also have to add a lang key for the tooltip.",
"[default: false]"
})
@Config.LangKey("config.nomilabs.mod_integration.screwdrive_aa_relays")
public boolean gtScrewdriveAARelays = false;

@Config.Comment("AE2 Terminal Options")
@Config.LangKey("config.nomilabs.mod_integration.ae2_terminal")
@Config.Name("ae2 terminal options")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.nomiceu.nomilabs.mixin.actuallyadditions;

import java.util.Set;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;

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.Redirect;

import com.google.common.collect.ImmutableSet;
import com.nomiceu.nomilabs.config.LabsConfig;

import de.ellpeck.actuallyadditions.mod.blocks.BlockLaserRelay;
import de.ellpeck.actuallyadditions.mod.config.ConfigValues;

@Mixin(value = BlockLaserRelay.class, remap = false)
public class BlockLaserRelayClientMixin {

// Yes, we are comparing the item with the two screwdrivers' registry names.
// For now, this will do. It works, and is simple.
@Unique
private static final Set<ResourceLocation> labs$screwdriverRls = ImmutableSet
.of(new ResourceLocation("gregtech", "screwdriver"), new ResourceLocation("gregtech", "screwdriver_lv"));

/**
* At the first stack.getItem, return the expected 'configurator item' if it is a screwdriver.
* Also probably not the best way to do this.
*/
@Redirect(method = "displayHud",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/item/ItemStack;getItem()Lnet/minecraft/item/Item;",
ordinal = 0,
remap = true),
require = 1,
remap = false)
private Item checkForScrewdriver(ItemStack instance) {
Item origitem = instance.getItem();

if (!LabsConfig.modIntegration.gtScrewdriveAARelays) return origitem;

if (labs$screwdriverRls.contains(origitem.getRegistryName()))
return ConfigValues.itemCompassConfigurator;

return origitem;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.nomiceu.nomilabs.mixin.actuallyadditions;

import java.util.Set;

import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

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.CallbackInfoReturnable;

import com.google.common.collect.ImmutableSet;
import com.nomiceu.nomilabs.config.LabsConfig;

import de.ellpeck.actuallyadditions.api.laser.Network;
import de.ellpeck.actuallyadditions.mod.blocks.BlockLaserRelay;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelay;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;

@Mixin(value = BlockLaserRelay.class, remap = false)
public class BlockLaserRelayMixin {

// Yes, we are comparing the item with the two screwdrivers' registry names.
// For now, this will do. It works, and is simple.
@Unique
private static final Set<ResourceLocation> labs$screwdriverRls = ImmutableSet
.of(new ResourceLocation("gregtech", "screwdriver"), new ResourceLocation("gregtech", "screwdriver_lv"));

@Inject(method = "onBlockActivated", at = @At("HEAD"), remap = true, cancellable = true)
private void detectGtScrewdrivers(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand,
EnumFacing par6, float par7, float par8, float par9,
CallbackInfoReturnable<Boolean> cir) {
if (!LabsConfig.modIntegration.gtScrewdriveAARelays) return;

ItemStack stack = player.getHeldItem(hand);
TileEntity tile = world.getTileEntity(pos);

if (!(tile instanceof TileEntityLaserRelay laser) || !StackUtil.isValid(stack)) return;

if (!labs$screwdriverRls.contains(stack.getItem().getRegistryName())) return;

if (!world.isRemote) {
laser.onCompassAction(player);
Network network = laser.getNetwork();
if (network != null) {
++network.changeAmount;
}

laser.markDirty();
laser.sendUpdate();
}

cir.setReturnValue(true);
}
}
1 change: 1 addition & 0 deletions src/main/resources/assets/nomilabs/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ config.nomilabs.mod_integration.ftb_utils=Enable FTB Utilities Integration
config.nomilabs.mod_integration.top_addons=Enable TOP Addons Integration
config.nomilabs.mod_integration.jei_ing_empty_line=Add JEI Ingredient Tooltip Empty Line
config.nomilabs.mod_integration.bqu_fluid_task_fixes=Enable BQu Fluid Task Fixes
config.nomilabs.mod_integration.screwdrive_aa_relays=Allow GT Screwdrivers for AA Laser Relays

config.nomilabs.mod_integration.effortlessbuilding=Effortless Building Integration Settings
config.nomilabs.mod_integration.effortlessbuilding.enable=Enable Effortless Building Integration
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/mixins.nomilabs.actuallyadditions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
"minVersion": "0.8",
"compatibilityLevel": "JAVA_8",
"mixins": [
"BlockLaserRelayMixin",
"TileEntityXPSolidifierMixin"
],
"client": [],
"client": [
"BlockLaserRelayClientMixin"
],
"server": []
}

0 comments on commit d2110b2

Please sign in to comment.