Skip to content

Commit

Permalink
Add Machine Sounds (#183)
Browse files Browse the repository at this point in the history
* Implement machine sounds via API added in GTNE 1.18.4
  • Loading branch information
Exaxxion authored Dec 24, 2024
1 parent 1ab1322 commit 83a7e0e
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 10 deletions.
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies {

compileOnlyApi rfg.deobf("CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.1.20.689")
compileOnlyApi rfg.deobf("curse.maven:forestry-59751:2918418") // Forestry 5.8.2.422
implementation rfg.deobf("curse.maven:gregtech-nomifactory-edition-1019238:5403053") // GT Nomi 1.18.2
implementation rfg.deobf("curse.maven:gregtech-nomifactory-edition-1019238:6020404") // GT Nomi 1.18.5
implementation rfg.deobf("curse.maven:codechicken-lib-1-8-242818:2779848")
compileOnlyApi rfg.deobf("curse.maven:mantle-74924:2713386")
compileOnlyApi rfg.deobf("curse.maven:TConstruct-74072:2902483")
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gregicadditions/GregicAdditions.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.registries.IForgeRegistry;

@Mod(modid = Tags.MODID, name = Tags.MODNAME, version = Tags.VERSION, dependencies = "required-after:gregtech@[1.18.2,);after:forestry;after:tconstruct;")
@Mod(modid = Tags.MODID, name = Tags.MODNAME, version = Tags.VERSION, dependencies = "required-after:gregtech@[1.18.5,);after:forestry;after:tconstruct;")
public class GregicAdditions {

@SidedProxy(modId = Tags.MODID, clientSide = "gregicadditions.bees.ClientProxy", serverSide = "gregicadditions.bees.CommonProxy")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import gregtech.common.blocks.BlockMetalCasing.*;
import gregtech.common.blocks.*;
import gregtech.common.metatileentities.electric.*;
import gregtech.common.sound.GTSoundEvents;
import it.unimi.dsi.fastutil.*;
import it.unimi.dsi.fastutil.objects.*;
import net.minecraft.block.state.*;
Expand Down Expand Up @@ -68,6 +69,24 @@ public TileEntityProcessingArray(ResourceLocation metaTileEntityId) {
this.recipeMapWorkable = new ProcessingArrayWorkable(this);
}

/** Payload for recipe map packet when the map is null */
private static final String NONE = "NONE";

/** Max length of Recipe Map name payload in custom data packet */
private static final int MAP_NAME_LENGTH = 512;

@Override
@Nullable
public SoundEvent getSound() {
return ((ProcessingArrayWorkable)this.recipeMapWorkable).getSound();
}

@Override
protected void updateFormedValid() {
super.updateFormedValid();
((ProcessingArrayWorkable) recipeMapWorkable).findMachineStack();
}

@Override
protected BlockPattern createStructurePattern() {

Expand Down Expand Up @@ -229,12 +248,19 @@ public void readFromNBT(NBTTagCompound data) {
public void writeInitialSyncData(PacketBuffer buf) {
super.writeInitialSyncData(buf);
buf.writeBoolean(isDistinctInputBusMode);

if(recipeMapWorkable instanceof ProcessingArrayWorkable paw && paw.recipeMap != null)
buf.writeString(paw.recipeMap.unlocalizedName);
else
buf.writeString(NONE);
}

@Override
public void receiveInitialSyncData(PacketBuffer buf) {
super.receiveInitialSyncData(buf);
this.isDistinctInputBusMode = buf.readBoolean();
if(this.recipeMapWorkable instanceof ProcessingArrayWorkable paw)
paw.recipeMap = RecipeMap.getByName(buf.readString(MAP_NAME_LENGTH));
}

@Override
Expand Down Expand Up @@ -279,6 +305,9 @@ protected class ProcessingArrayWorkable extends MultiblockRecipeLogic {
ItemStack machineItemStack = ItemStack.EMPTY;
RecipeMap<?> recipeMap = null;

/** dataID for recipe map update packets, to sync with client */
private static final int RECIPEMAP_CHANGED = -999;

// Stuff for Distinct Mode
/** Index of the last bus used for distinct mode */
int lastRecipeIndex = 0;
Expand All @@ -289,6 +318,16 @@ public ProcessingArrayWorkable(RecipeMapMultiblockController tileEntity) {
super(tileEntity);
}

@Override
@Nullable
public SoundEvent getSound() {
if (isActive && (isJammed || hasNotEnoughEnergy))
return GTSoundEvents.INTERRUPTED;
if (this.recipeMap != null)
return this.recipeMap.getSound();
return null;
}

@Override
public void invalidate() {
super.invalidate();
Expand Down Expand Up @@ -596,6 +635,13 @@ protected static boolean findMachineInBlacklist(String unlocalizedName) {
return Arrays.asList(blacklist).contains(unlocalizedName);
}

@Override
public void receiveCustomData(int dataId, PacketBuffer buf) {
super.receiveCustomData(dataId, buf);
if(dataId == RECIPEMAP_CHANGED)
recipeMap = RecipeMap.getByName(buf.readString(MAP_NAME_LENGTH));
}

public void findMachineStack() {
RecipeMapMultiblockController controller = (RecipeMapMultiblockController) this.metaTileEntity;

Expand Down Expand Up @@ -623,6 +669,9 @@ public void findMachineStack() {
//we make a copy here to account for changes in the amount of machines in the hatch
this.machineItemStack = currentMachine.copy();
this.recipeMap = rmap;

// Send packet to client, so it knows what recipe map is loaded
writeCustomData(RECIPEMAP_CHANGED, buf -> buf.writeString(rmap.unlocalizedName));
}
}

Expand Down
54 changes: 46 additions & 8 deletions src/main/java/gregicadditions/recipes/GARecipeMaps.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import gregtech.api.recipes.RecipeMap;
import gregtech.api.recipes.builders.*;
import gregtech.api.recipes.machines.FuelRecipeMap;
import gregtech.common.sound.GTSoundEvents;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenProperty;

Expand All @@ -29,14 +30,51 @@ public class GARecipeMaps {
public static final RecipeMap<IntCircuitRecipeBuilder> BUNDLER_RECIPES;

static {
CLUSTER_MILL_RECIPES = new RecipeMap<>("cluster_mill", 1, 1, 1, 1, 0, 0, 0, 0, new SimpleRecipeBuilder()).setSlotOverlay(false, false, GuiTextures.BENDER_OVERLAY).setProgressBar(GuiTextures.PROGRESS_BAR_BENDING, ProgressWidget.MoveType.HORIZONTAL);
ASSEMBLY_LINE_RECIPES = new RecipeMapAssemblyLine<>("assembly_line", 4, 16, 1, 1, 0, 4, 0, 0, new SimpleRecipeBuilder()).setProgressBar(GuiTextures.PROGRESS_BAR_ARROW, ProgressWidget.MoveType.HORIZONTAL);
ASSEMBLY_LINE_RECIPES.setSlotOverlay(false, false, GuiTextures.MOLD_OVERLAY);
NAQUADAH_REACTOR_FUELS = new FuelRecipeMap("naquadah_reactor");
MASS_FAB_RECIPES = new RecipeMap<>("mass_fab", 0, 1, 0, 0, 0, 1, 1, 2, new SimpleRecipeBuilder()).setProgressBar(GuiTextures.PROGRESS_BAR_BENDING, ProgressWidget.MoveType.HORIZONTAL);
REPLICATOR_RECIPES = new RecipeMap<>("replicator", 0, 1, 0, 1, 1, 2, 0, 1, new SimpleRecipeBuilder()).setProgressBar(GuiTextures.PROGRESS_BAR_BENDING, ProgressWidget.MoveType.HORIZONTAL);
PROCESSING_ARRAY_RECIPES = new RecipeMap<>("processing_array", 0, 9, 0, 6, 0, 3, 0, 2, new SimpleRecipeBuilder()).setProgressBar(GuiTextures.PROGRESS_BAR_BENDING, ProgressWidget.MoveType.HORIZONTAL);
BUNDLER_RECIPES = new RecipeMap<>("bundler", 2, 2, 1, 1, 0, 0, 0, 0, new IntCircuitRecipeBuilder().EUt(12).duration(250))
CLUSTER_MILL_RECIPES = new RecipeMap<>("cluster_mill",
1, 1, 1, 1,
0, 0, 0, 0,
new SimpleRecipeBuilder())
.setSlotOverlay(false, false, GuiTextures.BENDER_OVERLAY)
.setProgressBar(GuiTextures.PROGRESS_BAR_BENDING, ProgressWidget.MoveType.HORIZONTAL)
.setSound(GTSoundEvents.MOTOR);

ASSEMBLY_LINE_RECIPES = new RecipeMapAssemblyLine<>("assembly_line",
4, 16, 1, 1,
0, 4, 0, 0,
new SimpleRecipeBuilder())
.setProgressBar(GuiTextures.PROGRESS_BAR_ARROW, ProgressWidget.MoveType.HORIZONTAL);

ASSEMBLY_LINE_RECIPES.setSlotOverlay(false, false, GuiTextures.MOLD_OVERLAY)
.setSound(GTSoundEvents.ASSEMBLER);

NAQUADAH_REACTOR_FUELS = new FuelRecipeMap("naquadah_reactor").setSound(GTSoundEvents.COMBUSTION);

// No sound
MASS_FAB_RECIPES = new RecipeMap<>("mass_fab",
0, 1, 0, 0,
0, 1, 1, 2,
new SimpleRecipeBuilder())
.setProgressBar(GuiTextures.PROGRESS_BAR_BENDING, ProgressWidget.MoveType.HORIZONTAL);

// No sound
REPLICATOR_RECIPES = new RecipeMap<>("replicator",
0, 1, 0, 1,
1, 2, 0, 1,
new SimpleRecipeBuilder())
.setProgressBar(GuiTextures.PROGRESS_BAR_BENDING, ProgressWidget.MoveType.HORIZONTAL);

// Manages sounds internally with custom logic
PROCESSING_ARRAY_RECIPES = new RecipeMap<>("processing_array",
0, 9, 0, 6,
0, 3, 0, 2,
new SimpleRecipeBuilder())
.setProgressBar(GuiTextures.PROGRESS_BAR_BENDING, ProgressWidget.MoveType.HORIZONTAL);

BUNDLER_RECIPES = new RecipeMap<>("bundler",
2, 2, 1, 1,
0, 0, 0, 0,
new IntCircuitRecipeBuilder().EUt(12).duration(250))
.setProgressBar(GuiTextures.PROGRESS_BAR_ARROW, ProgressWidget.MoveType.HORIZONTAL)
.setSound(GTSoundEvents.ASSEMBLER);
}
}

0 comments on commit 83a7e0e

Please sign in to comment.