Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity;
import com.gregtechceu.gtceu.api.machine.MetaMachine;
import com.gregtechceu.gtceu.common.data.GTSoundEntries;
import com.gregtechceu.gtceu.config.ConfigHolder;
import com.gregtechceu.gtceu.data.recipe.CustomTags;
import com.gregtechceu.gtceu.utils.GradientUtil;
import com.lowdragmc.lowdraglib.Platform;
Expand Down Expand Up @@ -192,19 +193,47 @@ public InteractionResult useOn(UseOnContext context) {
var player = context.getPlayer();
var level = context.getLevel();
var facing = context.getClickedFace();
var pos = context.getClickedPos();
var pos = context.getClickedPos().mutable();
var stack = context.getItemInHand();
var block = level.getBlockState(pos).getBlock();

int maxBlocksToRecolor = Math.max(1, player != null && player.isCrouching() ? ConfigHolder.INSTANCE.tools.sprayCanChainLength : 1);

if (player != null) {
if (!tryPaintBlock(player, level, pos, facing)) {
return InteractionResult.PASS;
for (int i = 0; i < maxBlocksToRecolor; i++) {

// Stop once we hit another block to prevent accidentally recoloring stuff
if (level.getBlockState(pos).getBlock() != block) {
break;
}

if (!tryPaintBlock(player, level, pos, facing)) {
return InteractionResult.PASS;
}

if (!useItemDurability(player, context.getHand(), stack, empty.get())) {
break;
}

pos.move(getPaintDirection(player));
}
useItemDurability(player, context.getHand(), stack, empty.get());

GTSoundEntries.SPRAY_CAN_TOOL.play(level, null, player.position(), 1.0f, 1.0f);
return InteractionResult.SUCCESS;
}
return InteractionResult.PASS;
}

private Direction getPaintDirection(Player player) {
if (player.getXRot() > 45F) {
return Direction.DOWN;
} else if (player.getXRot() < -45F) {
return Direction.UP;
}

return player.getDirection();
}

private boolean tryPaintBlock(Player player, Level world, BlockPos pos, Direction side) {
var blockState = world.getBlockState(pos);
var block = blockState.getBlock();
Expand Down Expand Up @@ -328,6 +357,7 @@ private static boolean recolorBlockNoState(Map<DyeColor, Block> map, DyeColor co
state.setValue(property, old.getValue(property));
}
world.setBlock(pos, state, 3);
world.sendBlockUpdated(pos, old, state, 3);
return true;
}
return false;
Expand Down Expand Up @@ -446,7 +476,7 @@ public boolean useItemDurability(Player player, InteractionHand hand, ItemStack
//otherwise, update held item to replacement stack
player.setItemInHand(hand, replacementStack);
}
return true;
return false;
}
setUsesLeft(stack, usesLeft);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ public static class ToolConfigs {
@Configurable.Comment({ "Random chance for electric tools to take actual damage", "Default: 10%" })
@Configurable.Range(min = 0, max = 100)
public int rngDamageElectricTools = 10;
@Configurable
@Configurable.Comment({ "Amount of blocks that can be spray painted at once", "Default: 16" })
@Configurable.Range(min = 1, max = 512)
public int sprayCanChainLength = 16;
}

public static class ClientConfigs {
Expand Down