Skip to content
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

Revamp tools #688

Merged
merged 56 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
5ba1055
aa why u crash
screret Nov 23, 2023
ab1927e
aa why u crash
screret Nov 23, 2023
0d4d043
holy shit this is worse than I thought...
screret Nov 23, 2023
96bc900
god this is annoying to do
screret Dec 12, 2023
c371ea8
update muh codes
screret Dec 22, 2023
9267db5
it runs.
screret Dec 31, 2023
08bf55e
feat: megacommit moment
screret Dec 31, 2023
9335f6d
fix: use better, not as hardcoded AOE behaviour
screret Jan 1, 2024
a35e55e
fix: behaviours now use UseOnContext instead of a lot of parameters
screret Jan 1, 2024
681db3e
fix: ShapedEnergyTransferRecipe crashes REI because .matches() is nev…
screret Jan 1, 2024
3042b2c
fix: fill creative tabs & recipes with correctly-NBT'd items
screret Jan 1, 2024
da4e95d
fix: some more AOE fixes
screret Jan 1, 2024
dedaa8c
fix: better valid drop tier handling
screret Jan 1, 2024
f3d521d
fix: misc fixes
screret Jan 1, 2024
c750476
feat: tooltips
screret Jan 1, 2024
fd76c7d
fix: move tintColor to IGTTool
screret Jan 1, 2024
b0c385f
fix: make tool types use correct constructors
screret Jan 1, 2024
42dc652
feat: allow autofilling recipes with items that have different NBT
screret Jan 1, 2024
42ece16
fix: spades now exist.
screret Jan 1, 2024
0899e76
fix: mining tool tags.
screret Jan 1, 2024
f3d6705
chore: datagen & some minor touchups
screret Jan 1, 2024
7202b75
feat: remake how tool types are passed to IToolable etc. and how IToo…
screret Jan 2, 2024
816a680
fix: better tool break handling when entity == null
screret Jan 2, 2024
077d5ba
fix: plunger now voids fluids.
screret Jan 2, 2024
439408c
fix: hoe behaviour works.
screret Jan 3, 2024
920edfb
"fix": disable torch place behavior for initial release as I can't fi…
screret Jan 3, 2024
7fb1a1c
fix: log strip behaviour quirks
screret Jan 3, 2024
08dd470
feat: custom wrench block rotating actions
screret Jan 3, 2024
ff6d0c9
fix: rail rotating with crowbar only works with normal rails
screret Jan 3, 2024
6a89832
feat: forge overrides for all tool actions that have them, onBlockSta…
screret Jan 3, 2024
e6fea1f
fix: tree felling might've worked with any tool
screret Jan 3, 2024
a62cd97
fix: bad nullability everywhere
screret Jan 3, 2024
7496357
fix: scythe had the wrong tool class, GTHoeItem extends ShovelItem in…
screret Jan 3, 2024
ebbb6f3
fix: plunger only voids 1/81 on fabric
screret Jan 3, 2024
2eb32e2
fix: make constructors protected for tool classes
screret Jan 4, 2024
ea3f549
feat: make GTItems.TOOL_ITEMS be a table of <Material, Type, IGTTool>…
screret Jan 4, 2024
831bc51
fix: fix up tint colors in preparation for 2-color tool textures
screret Jan 4, 2024
768c0c0
feat: fallback to vanilla logic in case someone calls IGTToolImpl.def…
screret Jan 4, 2024
742d229
fix: plunger recipes set the max durability of the tool when crafting
screret Jan 4, 2024
d66ac90
fix: update jade plugin to use new tool item map
screret Jan 4, 2024
640ff81
fix: oops.
screret Jan 4, 2024
7140db5
fix: for some reason NBTToJsonConverter always converts numbers to do…
screret Jan 4, 2024
123d6b0
feat: colored tool handles
screret Jan 4, 2024
fa2cbdf
fix: reorder tint indexes on tool models
screret Jan 4, 2024
1bb018d
Revert "fix: reorder tint indexes on tool models"
screret Jan 4, 2024
0f32cba
fix: this is a better way to do the same thing.
screret Jan 4, 2024
904490a
feat: implement getDefaultInstance on all tool type classes
screret Jan 4, 2024
c1c1687
remove now useless mixin, add nbt output to fabric because it seemed …
screret Jan 4, 2024
e47443c
Revert "fix: for some reason NBTToJsonConverter always converts numbe…
screret Jan 4, 2024
bceef62
fix: heading comma in tool class tooltip
screret Jan 4, 2024
a017060
fix: fabric now has the ability to have electric tools
screret Jan 4, 2024
7abebb1
chore: changelog & version
screret Jan 4, 2024
eb012f4
chore: datagen
screret Jan 4, 2024
fce43fa
emphasize tool breakage
screret Jan 4, 2024
c33d363
fix weird import
screret Jan 4, 2024
ac49b73
Update common/src/main/java/com/gregtechceu/gtceu/api/item/tool/aoe/A…
screret Jan 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# ChangeLog

Version: 1.0.19.b
Version: 1.0.20

- fix output hatches not being recognized
- revamps tools, bringing parity with 1.12 (except electric tools)
- adds spades, an AOE shovel
- adds functionality to most tools that were missing it previously
- colored crowbars
- fixes some tools' block break times etc.
- brings parity with forge & fabric on some tool-related functionality
- fixes some issues with crafting tools
- AOE tools now work in creative mode
- wrenches now rotate blocks other than GT machines
- crowbars now rotate rail blocks
- plungers made from different rubbers now have different durabilities

***WARNING: THIS BREAKS MOST EXISTING TOOLS!***

Notes for addon devs:
- GTItems.TOOL_ITEMS is now a table<Material, Type, Tool item> instead of the old <Tier, Type, Item>
- torch placing with pickaxes is currently disabled as none of us can find a fix for it deleting the tool.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.gregtechceu.gtceu.api.data.RotationState;
import com.gregtechceu.gtceu.api.item.MetaMachineItem;
import com.gregtechceu.gtceu.api.item.tool.GTToolType;
import com.gregtechceu.gtceu.api.item.tool.ToolHelper;
import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity;
import com.gregtechceu.gtceu.api.machine.MachineDefinition;
import com.gregtechceu.gtceu.api.machine.MetaMachine;
Expand All @@ -14,6 +16,7 @@
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.RandomSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
Expand All @@ -23,6 +26,7 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
Expand All @@ -42,6 +46,7 @@

import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
import java.util.Set;

/**
* @author KilaBash
Expand Down Expand Up @@ -232,10 +237,24 @@ public void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState
}
}


@Override
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
var machine = getMachine(world, pos);
ItemStack itemStack = player.getItemInHand(hand);

Set<GTToolType> types = ToolHelper.getToolTypes(itemStack);
if (machine != null && !types.isEmpty() && ToolHelper.canUse(itemStack)) {
var result = machine.onToolClick(types, itemStack, new UseOnContext(player, hand, hit));
if (result.getSecond() == InteractionResult.CONSUME && player instanceof ServerPlayer serverPlayer) {
ToolHelper.playToolSound(result.getFirst(), serverPlayer);

if (!serverPlayer.isCreative()) {
ToolHelper.damageItem(itemStack, serverPlayer, 1);
}
}
if (result.getSecond() != InteractionResult.PASS) return result.getSecond();
}

if (machine instanceof IInteractedMachine interactedMachine) {
var result = interactedMachine.onUse(state, world, pos, player, hand, hit);
if (result != InteractionResult.PASS) return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import com.gregtechceu.gtceu.api.blockentity.PipeBlockEntity;
import com.gregtechceu.gtceu.api.capability.ICoverable;
import com.gregtechceu.gtceu.api.capability.IToolable;
import com.gregtechceu.gtceu.api.item.PipeBlockItem;
import com.gregtechceu.gtceu.api.item.tool.GTToolType;
import com.gregtechceu.gtceu.api.item.tool.ToolHelper;
import com.gregtechceu.gtceu.api.pipenet.IAttachData;
import com.gregtechceu.gtceu.api.pipenet.IPipeNode;
import com.gregtechceu.gtceu.api.pipenet.IPipeType;
Expand All @@ -18,10 +20,14 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
Expand All @@ -35,6 +41,7 @@
import net.minecraft.world.level.storage.loot.LootParams;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.EntityCollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
Expand All @@ -43,6 +50,7 @@

import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
import java.util.Set;

/**
* @author KilaBash
Expand Down Expand Up @@ -180,6 +188,26 @@ public void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState
}
}

@Override
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
ItemStack itemStack = player.getItemInHand(hand);
BlockEntity entity = level.getBlockEntity(pos);

Set<GTToolType> types = ToolHelper.getToolTypes(itemStack);
if (entity instanceof IToolable toolable && !types.isEmpty() && ToolHelper.canUse(itemStack)) {
var result = toolable.onToolClick(types, itemStack, new UseOnContext(player, hand, hit));
if (result.getSecond() == InteractionResult.CONSUME && player instanceof ServerPlayer serverPlayer) {
ToolHelper.playToolSound(result.getFirst(), serverPlayer);

if (!serverPlayer.isCreative()) {
ToolHelper.damageItem(itemStack, serverPlayer, 1);
}
}
return result.getSecond();
}
return InteractionResult.PASS;
}

@Override
public boolean isCollisionShapeFullBlock(BlockState state, BlockGetter level, BlockPos pos) {
return false;
Expand All @@ -197,7 +225,7 @@ public VoxelShape getShape(BlockState pState, BlockGetter pLevel, BlockPos pPos,
if (context instanceof EntityCollisionContext entityCtx && entityCtx.getEntity() instanceof Player player) {
var coverable = pipeNode.getCoverContainer();
var held = player.getMainHandItem();
if (held.is(GTToolType.WIRE_CUTTER.itemTag) || held.is(GTToolType.WRENCH.itemTag) ||
if (GTToolType.WIRE_CUTTER.itemTags.stream().anyMatch(held::is) || GTToolType.WRENCH.itemTags.stream().anyMatch(held::is) ||
CoverPlaceBehavior.isCoverBehaviorItem(held, coverable::hasAnyCover, coverDef -> ICoverable.canPlaceCover(coverDef, coverable)) ||
(held.getItem() instanceof BlockItem blockItem && blockItem.getBlock() instanceof PipeBlock<?,?,?> pipeBlock && pipeBlock.pipeType.type().equals(pipeType.type()))) {
return Shapes.or(Shapes.block(), shape);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;

import java.util.Set;

/**
* @author KilaBash
* @date 2023/2/17
Expand Down Expand Up @@ -77,12 +79,12 @@ public void clearRemoved() {
}

@Override
public boolean shouldRenderGrid(Player player, ItemStack held, GTToolType toolType) {
return metaMachine.shouldRenderGrid(player, held, toolType);
public boolean shouldRenderGrid(Player player, ItemStack held, Set<GTToolType> toolTypes) {
return metaMachine.shouldRenderGrid(player, held, toolTypes);
}

@Override
public ResourceTexture sideTips(Player player, GTToolType toolType, Direction side) {
return metaMachine.sideTips(player, toolType, side);
public ResourceTexture sideTips(Player player, Set<GTToolType> toolTypes, Direction side) {
return metaMachine.sideTips(player, toolTypes, side);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.lowdragmc.lowdraglib.syncdata.blockentity.IAsyncAutoSyncBlockEntity;
import com.lowdragmc.lowdraglib.syncdata.blockentity.IAutoPersistBlockEntity;
import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder;
import com.mojang.datafixers.util.Pair;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.MethodsReturnNonnullByDefault;
Expand All @@ -42,12 +43,12 @@
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
* @author KilaBash
Expand Down Expand Up @@ -228,10 +229,10 @@ public int getVisualConnections() {
//******* Interaction *******//
//////////////////////////////////////
@Override
public boolean shouldRenderGrid(Player player, ItemStack held, GTToolType toolType) {
if (canToolTunePipe(toolType) || toolType == GTToolType.SCREWDRIVER) return true;
public boolean shouldRenderGrid(Player player, ItemStack held, Set<GTToolType> toolTypes) {
if (toolTypes.contains(getPipeTuneTool()) || toolTypes.contains(GTToolType.SCREWDRIVER)) return true;
for (CoverBehavior cover : coverContainer.getCovers()) {
if (cover.shouldRenderGrid(player, held, toolType)) return true;
if (cover.shouldRenderGrid(player, held, toolTypes)) return true;
}
return false;
}
Expand All @@ -241,22 +242,22 @@ public ResourceTexture getPipeTexture(boolean isBlock) {
}

@Override
public ResourceTexture sideTips(Player player, GTToolType toolType, Direction side) {
if (canToolTunePipe(toolType)) {
public ResourceTexture sideTips(Player player, Set<GTToolType> toolTypes, Direction side) {
if (toolTypes.contains(getPipeTuneTool())) {
return getPipeTexture(isBlocked(side));
}
var cover = coverContainer.getCoverAtSide(side);
if (cover != null) {
return cover.sideTips(player, toolType, side);
return cover.sideTips(player, toolTypes, side);
}
return null;
}

@Override
public InteractionResult onToolClick(@NotNull GTToolType toolType, ItemStack itemStack, UseOnContext context) {
public Pair<GTToolType, InteractionResult> onToolClick(Set<GTToolType> toolTypes, ItemStack itemStack, UseOnContext context) {
// the side hit from the machine grid
var playerIn = context.getPlayer();
if (playerIn == null) return InteractionResult.PASS;
if (playerIn == null) return Pair.of(null, InteractionResult.PASS);

var hand = context.getHand();
var hitResult = new BlockHitResult(context.getClickLocation(), context.getClickedFace(), context.getClickedPos(), false);
Expand All @@ -265,15 +266,15 @@ public InteractionResult onToolClick(@NotNull GTToolType toolType, ItemStack ite
if (gridSide == null) gridSide = hitResult.getDirection();

// Prioritize covers where they apply (Screwdriver, Soft Mallet)
if (toolType == GTToolType.SCREWDRIVER) {
if (toolTypes.contains(GTToolType.SCREWDRIVER)) {
if (coverBehavior != null) {
return coverBehavior.onScrewdriverClick(playerIn, hand, hitResult);
return Pair.of(GTToolType.SCREWDRIVER, coverBehavior.onScrewdriverClick(playerIn, hand, hitResult));
}
} else if (toolType == GTToolType.SOFT_MALLET) {
} else if (toolTypes.contains(GTToolType.SOFT_MALLET)) {
if (coverBehavior != null) {
return coverBehavior.onSoftMalletClick(playerIn, hand, hitResult);
return Pair.of(GTToolType.SOFT_MALLET, coverBehavior.onSoftMalletClick(playerIn, hand, hitResult));
}
} else if (canToolTunePipe(toolType)) {
} else if (toolTypes.contains(getPipeTuneTool())) {
setBlocked(gridSide, !isBlocked(gridSide));
// try to connect to the next node.
if (!isBlocked(gridSide)) {
Expand All @@ -282,21 +283,21 @@ public InteractionResult onToolClick(@NotNull GTToolType toolType, ItemStack ite
node.setBlocked(gridSide.getOpposite(), false);
}
}
return InteractionResult.CONSUME;
} else if (toolType == GTToolType.CROWBAR) {
return Pair.of(getPipeTuneTool(), InteractionResult.CONSUME);
} else if (toolTypes.contains(GTToolType.CROWBAR)) {
if (coverBehavior != null) {
if (!isRemote()) {
getCoverContainer().removeCover(gridSide, playerIn);
}
return InteractionResult.CONSUME;
return Pair.of(GTToolType.CROWBAR, InteractionResult.CONSUME);
}
}

return InteractionResult.PASS;
return Pair.of(null, InteractionResult.PASS);
}

protected boolean canToolTunePipe(GTToolType toolType) {
return toolType == GTToolType.WRENCH;
protected GTToolType getPipeTuneTool() {
return GTToolType.WRENCH;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.gregtechceu.gtceu.api.gui.GuiTextures;
import com.gregtechceu.gtceu.api.gui.fancy.IFancyConfigurator;
import com.gregtechceu.gtceu.api.gui.widget.CoverContainerConfigurator;
import com.gregtechceu.gtceu.api.item.tool.ToolHelper;
import com.gregtechceu.gtceu.utils.GTUtil;
import com.lowdragmc.lowdraglib.LDLib;
import com.lowdragmc.lowdraglib.gui.texture.IGuiTexture;
Expand Down Expand Up @@ -94,7 +95,7 @@ default boolean placeCoverOnSide(Direction side, ItemStack itemStack, CoverDefin
markDirty();
scheduleNeighborShapeUpdate();
// TODO achievement
// AdvancementTriggers.FIRST_COVER_PLACE.trigger((EntityPlayerMP) player);
// AdvancementTriggers.FIRST_COVER_PLACE.trigger((PlayerMP) player);
return true;
}

Expand Down Expand Up @@ -197,7 +198,7 @@ static boolean doesCoverCollide(Direction side, List<VoxelShape> collisionBox, d

@Nullable
static Direction rayTraceCoverableSide(ICoverable coverable, Player player) {
var rayTrace = RayTraceHelper.rayTraceRange(coverable.getLevel(), player, 5);
var rayTrace = RayTraceHelper.rayTraceRange(coverable.getLevel(), player, ToolHelper.getPlayerBlockReach(player));
if (rayTrace.getType() == HitResult.Type.MISS) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.gregtechceu.gtceu.api.capability;

import com.gregtechceu.gtceu.api.item.tool.GTToolType;
import com.mojang.datafixers.util.Pair;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import org.jetbrains.annotations.Nullable;

import javax.annotation.Nonnull;
import java.util.Set;

/**
* @author KilaBash
Expand All @@ -19,6 +22,6 @@ public interface IToolable {
*
* @return SUCCESS / CONSUME (will damage tool) / FAIL if something happened, so tools will get damaged and animations will be played
*/
InteractionResult onToolClick(@Nonnull GTToolType toolType, ItemStack itemStack, UseOnContext context);
Pair<@Nullable GTToolType, InteractionResult> onToolClick(@Nonnull Set<GTToolType> toolTypes, ItemStack itemStack, UseOnContext context);

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
* Represents cover instance attached on the specific side of meta tile entity
Expand Down Expand Up @@ -178,16 +179,16 @@ public ICoverRenderer getCoverRenderer() {
}

@Override
public boolean shouldRenderGrid(Player player, ItemStack held, GTToolType toolType) {
return toolType == GTToolType.CROWBAR || (toolType == GTToolType.SCREWDRIVER && this instanceof IUICover);
public boolean shouldRenderGrid(Player player, ItemStack held, Set<GTToolType> toolTypes) {
return toolTypes.contains(GTToolType.CROWBAR) || (toolTypes.contains(GTToolType.SCREWDRIVER ) && this instanceof IUICover);
}

@Override
public ResourceTexture sideTips(Player player, GTToolType toolType, Direction side) {
if (toolType == GTToolType.CROWBAR) {
public ResourceTexture sideTips(Player player, Set<GTToolType> toolTypes, Direction side) {
if (toolTypes.contains(GTToolType.CROWBAR)) {
return GuiTextures.TOOL_REMOVE_COVER;
}
if (toolType == GTToolType.SCREWDRIVER && this instanceof IUICover) {
if (toolTypes.contains(GTToolType.SCREWDRIVER) && this instanceof IUICover) {
return GuiTextures.TOOL_COVER_SETTINGS;
}
return null;
Expand Down
Loading