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

Diesel tool sounds - First Draft / Feedback desired #5955

Open
wants to merge 21 commits into
base: 1.21.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5ab2f23
Initial commit
Jun 17, 2024
60ec43b
first presentable draft
Jun 17, 2024
8e4c57a
pulled out tool sounds from DieselToolItem into INoisyTool interface
Jun 19, 2024
18f42f3
made get<*>Sound calls take ItemStack as argument
Jun 20, 2024
bec5a6c
added a temporary static for volume adjustment in INoisyTool
Jun 20, 2024
f49008e
added a fading sound to the tools to make digging quickly mined block…
Jun 20, 2024
2577012
fixed single-stutter bug when beginning to harvest
Jun 21, 2024
8356a3d
added important remarks to the INoisyTool
Jun 21, 2024
b596051
fixed follow-up stutter bug from fixing the first stutter bug 🤡
Jun 21, 2024
7e2ce26
correct checkItemMatch to compare stacks not items, since sounds are …
Jun 22, 2024
7788264
fix edge case NPE
Jun 22, 2024
60cff43
replace placeholder saw blade sound
Jun 22, 2024
310af64
rebalance buzzsaw grinding sound volume to be more in line with the o…
Jun 22, 2024
d0bae35
fixed checkItemMatch failing because updating any values on a tool it…
Jun 22, 2024
12506d9
made the same-stack check item based instead of static
Jun 22, 2024
ddeff4c
clear sound groups on leaving level (change level or back to menu)
Jun 22, 2024
a54230d
post rebase cleanup/bugfix and update to 1.21
Dec 8, 2024
eed9dd3
added missing generated resource lang file(?)
Dec 9, 2024
3fa7ce7
fixed wrong symbol(?) I don't even wanna know how that came into being
Dec 9, 2024
e20730b
added missing datagen-ed .cache file
Dec 9, 2024
3c35256
Rerun datagen
malte0811 Dec 12, 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
Prev Previous commit
Next Next commit
made the same-stack check item based instead of static
fix: if the ItemStacks are not identical when checked in checkItemValid, but still considered the same, the ItemStack of the sound group updates
  • Loading branch information
MalkContent committed Dec 5, 2024
commit 12506d9e50c2acb37aae5aec23327f1ab488f069
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,23 @@ static boolean isAbleNoisyTool(ItemStack stack)
/**
* When an ItemStack gets modified server side (i.e. takes damage, changes tags (i.e. uses fuel), etc.), it creates a new ItemStack on the client side.
* There is no unreasonably involved way to check if the new ItemStack is actually just the old ItemStack, but modified.
* So this for these cases, this checks the next best thing: Item equality and sound equality.
* So this for these cases, this default implementation checks the next best thing: Item equality and sound equality.
*
* It is encouraged to override this with a simpler check.
*
* This check also assumes, that it has already been checked and confirmed, that the stacks are not identical
*
* @param mainStack
* @param otherStack
* @return true if stacks are identical or if stacks produce the same sounds.
* @return true if stacks are considered the same stack. By default: if stacks produce the same sounds.
*/
static boolean acceptableSameStack(ItemStack mainStack, ItemStack otherStack)
default boolean noisySameStack(ItemStack mainStack, ItemStack otherStack)
{
// not making this a single line return..
if(mainStack==otherStack)
return true;

if(mainStack.getItem() instanceof INoisyTool noisyTool&&noisyTool.equals(otherStack.getItem()))
{
return noisyTool.getIdleSound(mainStack).equals(noisyTool.getIdleSound(otherStack))
&&noisyTool.getBusySound(mainStack).equals(noisyTool.getBusySound(otherStack))
&&noisyTool.getFadingSound(mainStack).equals(noisyTool.getFadingSound(otherStack))
&&noisyTool.getAttackSound(mainStack).equals(noisyTool.getAttackSound(otherStack))
&&noisyTool.getHarvestSound(mainStack).equals(noisyTool.getHarvestSound(otherStack));
}
return false;
return mainStack.getItem() instanceof INoisyTool noisyTool&&noisyTool.equals(otherStack.getItem())
&&noisyTool.getIdleSound(mainStack).equals(noisyTool.getIdleSound(otherStack))
&&noisyTool.getBusySound(mainStack).equals(noisyTool.getBusySound(otherStack))
&&noisyTool.getFadingSound(mainStack).equals(noisyTool.getFadingSound(otherStack))
&&noisyTool.getAttackSound(mainStack).equals(noisyTool.getAttackSound(otherStack))
&&noisyTool.getHarvestSound(mainStack).equals(noisyTool.getHarvestSound(otherStack));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public Holder<SoundEvent> getAttackSound(ItemStack stack)
public Holder<SoundEvent> getHarvestSound(ItemStack stack)
{
Item headitem = getHead(stack).getItem();
if (headitem instanceof GrindingDiskItem || headitem instanceof RockcutterItem)
if(headitem instanceof GrindingDiskItem||headitem instanceof RockcutterItem)
return IESounds.buzzsaw_harvest_grind;
return IESounds.buzzsaw_harvest_saw;
}
Expand All @@ -328,6 +328,12 @@ public boolean ableToMakeNoise(ItemStack stack)
return canToolBeUsed(stack);
}

@Override
public boolean noisySameStack(ItemStack mainStack, ItemStack otherStack)
{
return mainStack.getItem() instanceof BuzzsawItem buzzsawItem&&buzzsawItem.equals(otherStack.getItem())&&getHead(mainStack).getItem().equals(getHead(otherStack).getItem());
}

@Override
public boolean mineBlock(ItemStack stack, Level world, BlockState state, BlockPos pos, LivingEntity living)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ public boolean ableToMakeNoise(ItemStack stack)
return canToolBeUsed(stack);
}

@Override
public boolean noisySameStack(ItemStack mainStack, ItemStack otherStack)
{
return mainStack.getItem() instanceof DrillItem drillItem&&drillItem.equals(otherStack.getItem());
}

@Override
public Tier getHarvestLevel(ItemStack stack, @Nullable Player player)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class NoisyToolSoundGroup
private static final int ATTACK_DURATION = 7-1;
private static final int FADE_DURATION = 20-1;
private final INoisyTool noisyToolItem;
private final ItemStack noisyToolStack;
private ItemStack noisyToolStack;
private final int hotbarSlot;
private final LivingEntity holder;
private final int harvestTimeoutGrace;
Expand Down Expand Up @@ -59,16 +59,30 @@ public INoisyTool getItem()
return noisyToolItem;
}

public boolean checkItemMatch(ItemStack handItemStack, int hotbarSlot)
public boolean checkItemValid(ItemStack handItemStack, int hotbarSlot)
{
if(this.hotbarSlot!=hotbarSlot||!INoisyTool.acceptableSameStack(noisyToolStack, handItemStack)||!noisyToolItem.ableToMakeNoise(handItemStack))
if(this.hotbarSlot!=hotbarSlot||!checkItemMatch(handItemStack)||!noisyToolItem.ableToMakeNoise(handItemStack))
{
switchMotorOnOff(false);
return false;
}
return true;
}

private boolean checkItemMatch(ItemStack handItemStack)
{
if (noisyToolStack == handItemStack)
{
return true;
}
else if (noisyToolItem.noisySameStack(noisyToolStack, handItemStack))
{
noisyToolStack = handItemStack;
return true;
}
return false;
}

public enum ToolMotorState
{
OFF,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static NoisyToolSoundGroup getSafeNTSG(LivingEntity entity, EquipmentSlot

if(soundGroup!=null)
{
if(!soundGroup.checkItemMatch(handItem, hotbarSlot))
if(!soundGroup.checkItemValid(handItem, hotbarSlot))
{
ntsgs.remove(slot);
soundGroup = null;
Expand Down