Skip to content

Commit

Permalink
[ALPHA] Port to 24w38a
Browse files Browse the repository at this point in the history
* update dependencies
  - yarn mappings 24w38a+build.4
  - fabric api 0.104.2+1.21.2
  - fabric loader 0.16.5

* new module `:versioned:es1.21.2`

* into versioned module `logics.mixin.hotbar.MouseMixin`

* new versioned methods
  - `logics.VersionedMain#playSound`
  - `logics.VersionedMain#shouldIgnoreItemSound`

* new class `logics.impl.state.ActionResultState`

* refactored classes
  - `logics.impl.InventoryTabType` -> `.state.InventoryTabType`
  - `logics.impl.InventoryClickStatus` -> `.state.InventoryClickState`
  - `logics.entry.SoundPackLoader`
  - `logics.entry.BaseVanillaGenerator`

* update API specification
  • Loading branch information
lonefelidae16 committed Sep 19, 2024
1 parent f5b3d9f commit ed897ca
Show file tree
Hide file tree
Showing 95 changed files with 2,093 additions and 374 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ dependencies {
compileOnly include(project(path: 'logics'))
// 1.21 family
compileOnly include(project(path: 'versioned:es1.21'))
compileOnly include(project(path: 'versioned:es1.21.2'))
// 1.20 family
compileOnly include(project(path: 'versioned:es1.20.5'))
compileOnly include(project(path: 'versioned:es1.20.2'))
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ org.gradle.jvmargs=-Xmx3G
org.gradle.parallel=true
# Fabric Properties
# check these on https://fabricmc.net/develop/
minecraft_version=1.21.1
yarn_mappings=+build.1
loader_version=0.15.11
minecraft_version=24w38a
yarn_mappings=+build.4
loader_version=0.16.5
#Fabric api
fabric_api_version=0.102.0+1.21.1
fabric_api_version=0.104.2+1.21.2
# Java
java_lang_version=17
# Mod Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public final class ExtraSounds {
);

public static final Map<String, Method> CACHED_METHOD_MAP = new HashMap<>();
private static final VersionedMain MAIN = Objects.requireNonNull(VersionedMain.newInstance());

public static final VersionedMain MAIN = Objects.requireNonNull(VersionedMain.newInstance());
public static final String MODID = "extrasounds";
public static final SoundManager MANAGER = new SoundManager();
public static final String BASE_PACKAGE = "dev.stashy.extrasounds";
Expand Down Expand Up @@ -73,8 +72,8 @@ public static Identifier generateIdentifier(String namespace, String path) {
return MAIN.generateIdentifier(namespace, path);
}

public static Identifier fromItemRegistry(Item item) {
return MAIN.fromItemRegistry(item);
public static Identifier getItemId(Item item) {
return MAIN.getItemId(item);
}

public static IndexedIterable<Item> getItemRegistry() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.google.common.collect.Sets;
import dev.stashy.extrasounds.logics.debug.DebugUtils;
import dev.stashy.extrasounds.logics.entry.SoundPackLoader;
import dev.stashy.extrasounds.logics.impl.InventoryClickStatus;
import dev.stashy.extrasounds.logics.impl.state.InventoryClickState;
import dev.stashy.extrasounds.logics.runtime.VersionedPositionedSoundInstanceWrapper;
import dev.stashy.extrasounds.logics.throwable.SoundNotFoundException;
import dev.stashy.extrasounds.sounds.SoundType;
Expand Down Expand Up @@ -47,10 +47,10 @@ public final class SoundManager {

/**
* Map of an item which should not play sounds.<br>
* Predicate in this value will be passed an instance of an {@link InventoryClickStatus}.<br>
* Predicate in this value will be passed an instance of an {@link InventoryClickState}.<br>
* Item -&gt; Predicate&lt;InventoryClickStatus&gt;
*/
private static final Map<Item, Predicate<InventoryClickStatus>> IGNORE_SOUND_PREDICATE_MAP = Util.make(Maps.newHashMap(), map -> {
public static final Map<Item, Predicate<InventoryClickState>> IGNORE_SOUND_PREDICATE_MAP = Util.make(Maps.newHashMap(), map -> {
map.put(Items.BUNDLE, status -> {
return status.isRMB && !(status.slot instanceof CreativeInventoryScreen.LockableSlot);
});
Expand All @@ -70,34 +70,34 @@ public SoundManager() {
* Handles Click and KeyPress on inventory
*
* @param player player instance
* @param status click status
* @param state click state
*/
public void handleInventorySlot(PlayerEntity player, InventoryClickStatus status) {
final SlotActionType actionType = status.actionType;
public void handleInventorySlot(PlayerEntity player, InventoryClickState state) {
final SlotActionType actionType = state.actionType;

if (status.isQuickCrafting()) {
if (state.isQuickCrafting()) {
// while dragging.
return;
}
if (status.slotIndex == -1) {
if (state.slotIndex == -1) {
// screen border clicked.
return;
}
if (status.isSlotBlocked()) {
// cannot insert.
return;
}

// Determine Slot item.
final ItemStack slotStack = status.getSlotStack();
final ItemStack slotStack = state.getSlotStack();
if (actionType == SlotActionType.QUICK_MOVE) {
// cursor holding an item, then Shift + mouse (double) click.
this.handleQuickMoveSound(slotStack.getItem());
return;
}
if (state.isSlotBlocked()) {
// cannot insert.
return;
}

// Determine Cursor item.
final ItemStack cursorStack = status.getCursorStack(player);
final ItemStack cursorStack = state.getCursorStack(player);

final boolean hasCursor = !cursorStack.isEmpty();
final boolean hasSlot = !slotStack.isEmpty();
Expand All @@ -106,9 +106,9 @@ public void handleInventorySlot(PlayerEntity player, InventoryClickStatus status
return;
}

if (status.isEmptySpaceClicked()) {
if (state.isEmptySpaceClicked()) {
// Out of screen area.
if (status.isRMB) {
if (state.isRMB) {
cursorStack.setCount(1);
}
this.playThrow(cursorStack);
Expand All @@ -117,12 +117,7 @@ public void handleInventorySlot(PlayerEntity player, InventoryClickStatus status

// Test if the item should not play sound.
{
var predicateForCursor = IGNORE_SOUND_PREDICATE_MAP.getOrDefault(cursorStack.getItem(), null);
if (predicateForCursor != null && predicateForCursor.test(status)) {
return;
}
var predicateForSlot = IGNORE_SOUND_PREDICATE_MAP.getOrDefault(slotStack.getItem(), null);
if (predicateForSlot != null && predicateForSlot.test(status)) {
if (ExtraSounds.MAIN.shouldIgnoreItemSound(cursorStack.getItem(), slotStack.getItem(), state)) {
return;
}
}
Expand All @@ -135,7 +130,7 @@ public void handleInventorySlot(PlayerEntity player, InventoryClickStatus status
}
case THROW -> {
if (!hasCursor) {
if (status.button == 0) {
if (state.button == 0) {
// one item drop from stack (default: Q key)
slotStack.setCount(1);
}
Expand Down Expand Up @@ -240,7 +235,7 @@ public void playSound(SoundEvent snd, float pitch, SoundCategory category, Sound

public void playSound(SoundEvent snd, SoundType type, float volume, float pitch, BlockPos position) {
volume *= this.getSoundVolume(Mixers.MASTER);
if (volume == 0 || this.isMuted(type)) {
if (volume == 0 || this.isMuted(type.category)) {
// skip reflection when volume is zero.
if (DebugUtils.DEBUG) {
this.logZeroVolume(snd);
Expand Down Expand Up @@ -269,8 +264,7 @@ private void playSound(SoundInstance instance) {
try {
long now = System.currentTimeMillis();
if (now - this.lastPlayed > 5) {
final MinecraftClient client = MinecraftClient.getInstance();
client.send(() -> client.getSoundManager().play(instance));
ExtraSounds.MAIN.playSound(instance);
this.lastPlayed = now;
if (DebugUtils.DEBUG) {
LOGGER.info("Playing sound: {}", instance.getId());
Expand Down Expand Up @@ -306,7 +300,7 @@ public void playThrow(ItemStack itemStack, SoundCategory category) {
}
final float maxPitch = 2f;
final float pitch = (!itemStack.isStackable()) ? maxPitch :
MathHelper.lerp((float) itemStack.getCount() / itemStack.getItem().getMaxCount(), maxPitch, 1.5f);
MathHelper.lerp((itemStack.getCount() - 1f) / (itemStack.getItem().getMaxCount() - 1f), maxPitch, 1.5f);
this.playSound(Sounds.ITEM_DROP, pitch, category, Mixers.ITEM_DROP);
}

Expand All @@ -319,7 +313,7 @@ private float getSoundVolume(SoundCategory category) {
}

public SoundEvent getSoundByItem(Item item, SoundType type) {
var itemId = ExtraSounds.fromItemRegistry(item);
var itemId = ExtraSounds.getItemId(item);
Identifier id = ExtraSounds.getClickId(itemId, type);
SoundEvent sound = SoundPackLoader.CUSTOM_SOUND_EVENT.getOrDefault(id, null);
if (sound == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dev.stashy.extrasounds.logics;

import dev.stashy.extrasounds.logics.impl.state.InventoryClickState;
import me.lonefelidae16.groominglib.api.McVersionInterchange;
import net.minecraft.client.sound.SoundInstance;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.sound.SoundEvent;
Expand All @@ -20,11 +22,15 @@ public static VersionedMain newInstance() {

public abstract Identifier generateIdentifier(String namespace, String path);

public abstract Identifier fromItemRegistry(Item item);
public abstract Identifier getItemId(Item item);

public abstract SoundEvent generateSoundEvent(Identifier id);

public abstract IndexedIterable<Item> getItemRegistry();

public abstract boolean canItemsCombine(ItemStack stack1, ItemStack stack2);

public abstract void playSound(SoundInstance instance);

public abstract boolean shouldIgnoreItemSound(Item cursorItem, Item slotItem, InventoryClickState state);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import static dev.stashy.extrasounds.sounds.Sounds.event;

public abstract class BaseVanillaGenerator {
protected static final SoundDefinition DEFAULT_SOUND = SoundDefinition.of(aliased(SoundManager.FALLBACK_SOUND_EVENT));
private static final SoundDefinition DEFAULT_SOUND = SoundDefinition.of(aliased(SoundManager.FALLBACK_SOUND_EVENT));
public static final SoundGenerator GENERATOR;

static {
Expand All @@ -34,53 +34,39 @@ public abstract class BaseVanillaGenerator {
protected abstract SoundGenerator generate();

protected String getItemIdPath(Item item) {
return ExtraSounds.fromItemRegistry(item).getPath();
return ExtraSounds.getItemId(item).getPath();
}

protected boolean isBrickItem(Item item) {
private boolean isBrickItem(Item item) {
final String idPath = getItemIdPath(item);
return item == Items.BRICK || idPath.endsWith("pottery_sherd") || idPath.startsWith("pottery_shard");
}

protected boolean isPaperItem(Item item) {
return item instanceof BannerPatternItem || item instanceof BookItem || item instanceof WritableBookItem ||
item instanceof WrittenBookItem || item instanceof EnchantedBookItem || item instanceof EmptyMapItem ||
item instanceof FilledMapItem || item instanceof NameTagItem || item instanceof KnowledgeBookItem;
}

protected boolean isGearGoldenItem(Item item) {
private boolean isGearGoldenItem(Item item) {
return item instanceof CompassItem ||
item instanceof SpyglassItem || item instanceof ShearsItem;
}

protected boolean isGearLeatherItem(Item item) {
return item instanceof LeadItem || item instanceof ElytraItem || item instanceof SaddleItem;
private boolean isGearLeatherItem(Item item) {
return item instanceof LeadItem || getItemIdPath(item).equals("elytra") ||
item instanceof SaddleItem || item instanceof BundleItem;
}

protected boolean isGearGenericItem(Item item) {
private boolean isGearGenericItem(Item item) {
return item instanceof BowItem || item instanceof CrossbowItem || item instanceof FishingRodItem ||
item instanceof OnAStickItem;
}

protected SoundDefinition generateFromToolMaterial(ToolMaterial mat) {
if (mat == null) {
return SoundDefinition.of(aliased(Gear.GENERIC));
} else if (mat == ToolMaterials.WOOD) {
return SoundDefinition.of(aliased(Gear.WOOD));
} else if (mat == ToolMaterials.STONE) {
return SoundDefinition.of(aliased(Gear.STONE));
} else if (mat == ToolMaterials.IRON) {
return SoundDefinition.of(aliased(Gear.IRON));
} else if (mat == ToolMaterials.GOLD) {
return SoundDefinition.of(aliased(Gear.GOLDEN));
} else if (mat == ToolMaterials.DIAMOND) {
return SoundDefinition.of(aliased(Gear.DIAMOND));
} else if (mat == ToolMaterials.NETHERITE) {
return SoundDefinition.of(aliased(Gear.NETHERITE));
} else {
return SoundDefinition.of(aliased(Gear.GENERIC));
//⬆ even though not required, this is in case any mods add to the enum of materials
}
private boolean isPaperItem(Item item) {
return item instanceof BannerPatternItem || item instanceof WritableBookItem ||
item instanceof WrittenBookItem || item instanceof EmptyMapItem ||
item instanceof FilledMapItem || item instanceof NameTagItem || item instanceof KnowledgeBookItem ||
item == Items.BOOK || item == Items.ENCHANTED_BOOK;
}

private boolean isStewItem(Item item) {
return item == Items.SUSPICIOUS_STEW || item == Items.RABBIT_STEW ||
item == Items.BEETROOT_SOUP || item == Items.MUSHROOM_STEW;
}

protected SoundDefinition generateFromBlock(Block block) {
Expand Down Expand Up @@ -122,6 +108,20 @@ protected SoundDefinition generalSounds(Item item) {
return SoundDefinition.of(aliased(DUST));
} else if (item instanceof SpawnEggItem) {
return SoundDefinition.of(aliased(WET_SLIPPERY));
} else if (this.getItemIdPath(item).startsWith("music_disc_")) {
return SoundDefinition.of(aliased(MUSIC_DISC));
} else if (this.isBrickItem(item)) {
return SoundDefinition.of(aliased(BRICK));
} else if (this.isGearGoldenItem(item)) {
return SoundDefinition.of(aliased(Gear.GOLDEN));
} else if (this.isGearLeatherItem(item)) {
return SoundDefinition.of(aliased(Gear.LEATHER));
} else if (this.isGearGenericItem(item)) {
return SoundDefinition.of(aliased(Gear.GENERIC));
} else if (this.isPaperItem(item)) {
return SoundDefinition.of(aliased(PAPER));
} else if (this.isStewItem(item)) {
return SoundDefinition.of(aliased(BOWL));
}

return DEFAULT_SOUND;
Expand Down
Loading

0 comments on commit ed897ca

Please sign in to comment.