-
Notifications
You must be signed in to change notification settings - Fork 9
Architects Wand - select block from backhand, randomize with trowel #121
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
cd0f6fe
architects wand builds with off hand blocks
tomasz-brak 4917d1c
Merge branch 'GTNewHorizons:master' into master
tomasz-brak 8a2346c
works, but buggy
tomasz-brak 5c898ac
fix placemnt of block entities
tomasz-brak 76ea28b
spotless
tomasz-brak 8a48b06
remove dep
tomasz-brak a1eec2a
style
tomasz-brak 0db5cb4
added missing is gt loaded check
tomasz-brak dc030b8
added NEI infopages
tomasz-brak 57d2983
fix sound
tomasz-brak 5e12b48
fix - onItemUsed called twice, remove from inv order changed
tomasz-brak 7fa2bab
spotless + rem dep
tomasz-brak 1a3ea01
damage trowel config value
tomasz-brak 07733f5
remove unused variable
tomasz-brak 08fa4b5
fix, check item damage
tomasz-brak 43f2539
config comment + spotless
tomasz-brak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
136 changes: 136 additions & 0 deletions
136
src/main/java/com/fouristhenumber/utilitiesinexcess/utils/ArchitectsSelection.java
This file contains hidden or 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,136 @@ | ||
| package com.fouristhenumber.utilitiesinexcess.utils; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
| import net.minecraft.block.Block; | ||
| import net.minecraft.entity.player.EntityPlayer; | ||
| import net.minecraft.item.ItemBlock; | ||
| import net.minecraft.item.ItemStack; | ||
| import net.minecraft.util.MovingObjectPosition; | ||
| import net.minecraft.world.World; | ||
|
|
||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| import com.fouristhenumber.utilitiesinexcess.compat.Mods; | ||
| import com.gtnewhorizon.gtnhlib.blockpos.BlockPos; | ||
|
|
||
| import gregtech.api.items.MetaGeneratedTool; | ||
| import gregtech.common.tools.ToolTrowel; | ||
| import xonin.backhand.api.core.BackhandUtils; | ||
|
|
||
| public class ArchitectsSelection { | ||
|
|
||
| private final Set<ItemStack> validBlocks; | ||
| private final ItemStack backhand; | ||
| private final ItemStack lookAtBlock; | ||
|
|
||
| public ArchitectsSelection(EntityPlayer player, World world, MovingObjectPosition movingObjectPosition) { | ||
| this.validBlocks = new HashSet<>(); | ||
| backhand = Mods.Backhand.isLoaded() ? BackhandUtils.getOffhandItem(player) : null; | ||
| lookAtBlock = getBlockByLocation(world, movingObjectPosition, player); | ||
|
|
||
| // No logic is executed if we don't look at any block, no need to bother checking other cases | ||
| if (lookAtBlock == null) { | ||
| return; | ||
| } | ||
|
|
||
| this.validBlocks.add(lookAtBlock); // Clicked block is always valid | ||
|
|
||
| if (backhand == null) { | ||
| return; | ||
| } | ||
| if (isValidBlock(backhand)) { | ||
| this.validBlocks.add(backhand.copy()); | ||
| return; | ||
| } | ||
| if (isTrowel(backhand)) { | ||
| this.validBlocks.addAll(hotbarBlocks(player)); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * @param player | ||
| * @return Always a valid block list or null | ||
| */ | ||
| public List<ItemStack> blockToPlace(EntityPlayer player) { | ||
|
|
||
| if (backhand == null) { | ||
| return Collections.singletonList((lookAtBlock)); | ||
| } | ||
| if (isValidBlock(backhand)) { | ||
| return Collections.singletonList(backhand); | ||
| } else if (isTrowel(backhand)) { | ||
| return hotbarBlocks(player); | ||
| } else { | ||
| return Collections.singletonList(lookAtBlock); | ||
| } | ||
| } | ||
|
|
||
| public int maxPlaceCount(EntityPlayer player, int wandLimit) { | ||
| if (player.capabilities.isCreativeMode) return wandLimit; | ||
| int count = 0; | ||
| for (ItemStack block : blockToPlace(player)) { | ||
| count += ArchitectsWandUtils.countItemInInventory(player, block); | ||
| } | ||
| return Math.min(count, wandLimit); | ||
| } | ||
|
|
||
| public boolean matches(ItemStack other) { | ||
| if (other == null) return false; | ||
| return this.validBlocks.stream() | ||
| .anyMatch( | ||
| validBlock -> validBlock.getItem() == other.getItem() | ||
| && ItemStack.areItemStackTagsEqual(validBlock, other) | ||
| && validBlock.getItemDamage() == other.getItemDamage()); | ||
| } | ||
|
|
||
| public static boolean isTrowel(@Nullable ItemStack stack) { | ||
| if (stack == null) { | ||
| return false; | ||
| } | ||
| if (Mods.GT.isLoaded() && stack.getItem() instanceof MetaGeneratedTool metaGeneratedTool) { | ||
| return metaGeneratedTool.getToolStats(stack) instanceof ToolTrowel; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private static boolean isValidBlock(@Nullable ItemStack stack) { | ||
| return (stack != null && stack.getItem() instanceof ItemBlock); | ||
| } | ||
|
|
||
| private static List<ItemStack> hotbarBlocks(EntityPlayer player) { | ||
| List<ItemStack> candidates = new ArrayList<>(); | ||
|
|
||
| for (int i = 0; i < 9; i++) { | ||
| if (i == player.inventory.currentItem) { | ||
| continue; | ||
| } | ||
| ItemStack item = player.inventory.mainInventory[i]; | ||
| if (!isValidBlock(item)) { | ||
| continue; | ||
| } | ||
| candidates.add(item); | ||
| } | ||
| return candidates; | ||
| } | ||
|
|
||
| public static ItemStack getBlockByLocation(World world, MovingObjectPosition movingObjectPosition, | ||
| EntityPlayer player) { | ||
|
|
||
| BlockPos blockPos = new BlockPos( | ||
| movingObjectPosition.blockX, | ||
| movingObjectPosition.blockY, | ||
| movingObjectPosition.blockZ); | ||
|
|
||
| Block block = world.getBlock(blockPos.x, blockPos.y, blockPos.z); | ||
| if (block == null) { | ||
| return null; | ||
| } | ||
| return block.getPickBlock(movingObjectPosition, world, blockPos.x, blockPos.y, blockPos.z, player); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.