-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow GT Screwdrivers to Configure AA Lasers
- Loading branch information
1 parent
f939840
commit d2110b2
Showing
5 changed files
with
129 additions
and
1 deletion.
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
50 changes: 50 additions & 0 deletions
50
src/main/java/com/nomiceu/nomilabs/mixin/actuallyadditions/BlockLaserRelayClientMixin.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,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; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/com/nomiceu/nomilabs/mixin/actuallyadditions/BlockLaserRelayMixin.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,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); | ||
} | ||
} |
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