generated from EpimorphicPioneers/ArchLoom-TemplateMod
-
Notifications
You must be signed in to change notification settings - Fork 5
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
1 parent
27c610c
commit 9146982
Showing
7 changed files
with
90 additions
and
4 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
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
66 changes: 66 additions & 0 deletions
66
src/main/java/com/epimorphismmc/gregiceng/common/item/GEDataStickBehavior.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,66 @@ | ||
package com.epimorphismmc.gregiceng.common.item; | ||
|
||
import com.epimorphismmc.gregiceng.common.machine.multiblock.part.appeng.CraftingIOBufferPartMachine; | ||
import com.epimorphismmc.gregiceng.common.machine.multiblock.part.appeng.CraftingIOSlavePartMachine; | ||
import com.gregtechceu.gtceu.api.item.component.IAddInformation; | ||
import com.gregtechceu.gtceu.api.item.component.IInteractionItem; | ||
import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; | ||
import com.gregtechceu.gtceu.api.machine.MetaMachine; | ||
import net.minecraft.ChatFormatting; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.nbt.Tag; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.world.InteractionResult; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.TooltipFlag; | ||
import net.minecraft.world.item.context.UseOnContext; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
|
||
public class GEDataStickBehavior implements IInteractionItem, IAddInformation { | ||
@Override | ||
public InteractionResult useOn(UseOnContext context) { | ||
Level level = context.getLevel(); | ||
BlockPos pos = context.getClickedPos(); | ||
BlockEntity blockEntity = level.getBlockEntity(pos); | ||
ItemStack stack = context.getItemInHand(); | ||
if (level.isClientSide()) { | ||
return InteractionResult.PASS; | ||
} | ||
if (blockEntity instanceof IMachineBlockEntity machineBlockEntity) { | ||
MetaMachine machine = machineBlockEntity.getMetaMachine(); | ||
if (machine instanceof CraftingIOBufferPartMachine) { | ||
stack.getOrCreateTag().putIntArray("pos", new int[]{pos.getX(), pos.getY(), pos.getZ()}); | ||
return InteractionResult.SUCCESS; | ||
} else if (machine instanceof CraftingIOSlavePartMachine slave) { | ||
if (stack.hasTag()) { | ||
if (stack.getOrCreateTag().contains("pos", Tag.TAG_INT_ARRAY)) { | ||
int[] posArray = stack.getOrCreateTag().getIntArray("pos"); | ||
BlockPos bufferPos = new BlockPos(posArray[0], posArray[1], posArray[2]); | ||
slave.setIOBuffer(bufferPos); | ||
return InteractionResult.SUCCESS; | ||
} | ||
} | ||
} | ||
} | ||
return IInteractionItem.super.useOn(context); | ||
} | ||
|
||
@Override | ||
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> tooltipComponents, TooltipFlag isAdvanced) { | ||
if (stack.hasTag()) { | ||
if (stack.getOrCreateTag().contains("pos", Tag.TAG_INT_ARRAY)) { | ||
int[] posArray = stack.getOrCreateTag().getIntArray("pos"); | ||
tooltipComponents.add(Component.translatable( | ||
"gregiceng.tooltip.buffer_bind", | ||
Component.literal("" + posArray[0]).withStyle(ChatFormatting.LIGHT_PURPLE), | ||
Component.literal("" + posArray[1]).withStyle(ChatFormatting.LIGHT_PURPLE), | ||
Component.literal("" + posArray[2]).withStyle(ChatFormatting.LIGHT_PURPLE) | ||
)); | ||
} | ||
} | ||
} | ||
} |
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