Skip to content

Commit

Permalink
Quacker! (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zorbatron authored Oct 8, 2024
1 parent a1d7bfe commit 30b1cac
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 20 deletions.
4 changes: 3 additions & 1 deletion src/main/java/com/zorbatron/zbgt/api/util/ZBGTUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import org.jetbrains.annotations.NotNull;

import com.zorbatron.zbgt.ZBGTCore;

import gregtech.api.capability.INotifiableHandler;
import gregtech.api.capability.impl.GhostCircuitItemStackHandler;
import gregtech.api.capability.impl.ItemHandlerList;
Expand All @@ -16,7 +18,7 @@
public class ZBGTUtility {

public static @NotNull ResourceLocation zbgtId(@NotNull String path) {
return new ResourceLocation("zbgt", path);
return new ResourceLocation(ZBGTCore.MODID, path);
}

public static final int[] intV = { 8, 32, 128, 512, 2048, 8192, 32768, 131072, 524288, 2097152, 8388608, 33554432,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import com.zorbatron.zbgt.common.metatileentities.multi.MetaTileEntityYOTTank;
import com.zorbatron.zbgt.common.metatileentities.multi.electric.*;
import com.zorbatron.zbgt.common.metatileentities.multi.electric.megamultis.*;
import com.zorbatron.zbgt.common.metatileentities.multi.electric.quads.MetaTileEntityQuadEBF;
import com.zorbatron.zbgt.common.metatileentities.multi.electric.quads.MetaTileEntityQueezer;
import com.zorbatron.zbgt.common.metatileentities.multi.electric.quads.*;
import com.zorbatron.zbgt.common.metatileentities.multi.multiblockpart.*;
import com.zorbatron.zbgt.common.metatileentities.storage.MetaTileEntityCreativeComputationProvider;

Expand Down Expand Up @@ -39,6 +38,7 @@ public class ZBGTMetaTileEntities {

public static MetaTileEntityQuadEBF QUAD_EBF;
public static MetaTileEntityQueezer QUEEZER;
public static MetaTileEntityQuacker QUACKER;

public static MetaTileEntityYOTTank YOTTANK;

Expand Down Expand Up @@ -125,5 +125,8 @@ public static void init() {
new MetaTileEntityMegaFusionReactor(zbgtId("mega_fusion_2"), GTValues.ZPM));
MEGA_FUSION[2] = registerMetaTileEntity(18062,
new MetaTileEntityMegaFusionReactor(zbgtId("mega_fusion_3"), GTValues.UV));

QUACKER = registerMetaTileEntity(18063,
new MetaTileEntityQuacker(zbgtId("quacker")));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.zorbatron.zbgt.common.metatileentities.multi.electric.quads;

import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.ISound;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import org.jetbrains.annotations.NotNull;

import com.zorbatron.zbgt.core.sound.ZBGTSoundEvents;

import gregtech.api.GTValues;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
import gregtech.api.pattern.BlockPattern;
import gregtech.api.pattern.FactoryBlockPattern;
import gregtech.common.metatileentities.multi.electric.MetaTileEntityCrackingUnit;

public class MetaTileEntityQuacker extends MetaTileEntityCrackingUnit {

private int quackTimer;

public MetaTileEntityQuacker(ResourceLocation metaTileEntityId) {
super(metaTileEntityId);
this.recipeMapWorkable.setParallelLimit(4);
this.quackTimer = calculateQuackInterval();
}

@Override
public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) {
return new MetaTileEntityQuacker(metaTileEntityId);
}

@Override
protected void updateFormedValid() {
super.updateFormedValid();

if (isActive() && quackTimer == 0) {
playQuack();
// Only quack every 1 to 5 minutes.
quackTimer = calculateQuackInterval();
} else if (quackTimer > 0) {
quackTimer--;
}
}

private int calculateQuackInterval() {
return 20 * 60 + GTValues.RNG.nextInt(20 * 60 * 4);
}

@SideOnly(Side.CLIENT)
private void playQuack() {
int randomInt = GTValues.RNG.nextInt(5);
ResourceLocation soundLocation = ZBGTSoundEvents.QUACKS.get(randomInt).getSoundName();
BlockPos pos = getPos();

// I'm not using GregTechAPI.soundManager.startTileSound because it checks if a sound is playing at the
// position, which there will be because of the cracker's normal active sound effect.
ISound sound = new PositionedSoundRecord(soundLocation, SoundCategory.BLOCKS, getVolume(), 1.0F,
false, 0, ISound.AttenuationType.LINEAR, pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F);
Minecraft.getMinecraft().getSoundHandler().playSound(sound);
}

@Override
protected @NotNull BlockPattern createStructurePattern() {
return FactoryBlockPattern.start()
.aisle("XCXCX", "XCXCX", "XCXCX", "XCXCX", "XCXCX")
.aisle("XCXCX", "X###X", "XCTCX", "X###X", "XCXCX")
.aisle("XCXCX", "XCTCX", "XCTCX", "XCTCX", "XCXCX")
.aisle("XCXCX", "X###X", "XCTCX", "X###X", "XCXCX")
.aisle("XCXCX", "XCXCX", "XCSCX", "XCXCX", "XCXCX")
.where('S', selfPredicate())
.where('C', heatingCoils())
.where('X', states(getCasingState()).setMinGlobalLimited(25)
.or(autoAbilities()))
.where('T', states(getCasingState()))
.where('#', air())
.build();
}
}
26 changes: 25 additions & 1 deletion src/main/java/com/zorbatron/zbgt/core/sound/ZBGTSoundEvents.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.zorbatron.zbgt.core.sound;

import static com.zorbatron.zbgt.api.util.ZBGTUtility.zbgtId;

import java.util.Arrays;
import java.util.List;

import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;

import gregtech.api.GregTechAPI;
Expand All @@ -8,7 +14,25 @@ public class ZBGTSoundEvents {

public static SoundEvent FX_LOW_FREQ;

public static List<SoundEvent> QUACKS;
public static SoundEvent QUACK_1;
public static SoundEvent QUACK_2;
public static SoundEvent QUACK_3;
public static SoundEvent QUACK_4;
public static SoundEvent QUACK_5;

public static void register() {
FX_LOW_FREQ = GregTechAPI.soundManager.registerSound("fx_lo_freq");
FX_LOW_FREQ = registerSoundHelper(zbgtId("yottank_pulse"));

QUACK_1 = registerSoundHelper(zbgtId("quack_1"));
QUACK_2 = registerSoundHelper(zbgtId("quack_2"));
QUACK_3 = registerSoundHelper(zbgtId("quack_3"));
QUACK_4 = registerSoundHelper(zbgtId("quack_4"));
QUACK_5 = registerSoundHelper(zbgtId("quack_5"));
QUACKS = Arrays.asList(QUACK_1, QUACK_2, QUACK_3, QUACK_4, QUACK_5);
}

private static SoundEvent registerSoundHelper(ResourceLocation resourceLocation) {
return GregTechAPI.soundManager.registerSound(resourceLocation.getNamespace(), resourceLocation.getPath());
}
}
12 changes: 0 additions & 12 deletions src/main/resources/assets/gregtech/sounds.json

This file was deleted.

12 changes: 8 additions & 4 deletions src/main/resources/assets/zbgt/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ recipemap.precise_assembler_recipes.name=Precise Assembler
zbgt.machine.quad_ebf.name=Quad EBF
zbgt.machine.quad_ebf.tooltip=The same shape as a quad EBF, and thus has 4 innate parallels!

zbgt.machine.queezer.name=Queezer
zbgt.machine.queezer.tooltip=A quad freezer that has 4 innate parallels

zbgt.machine.quacker.name=Quacker
zbgt.machine.quacker.tooltip=A slightly larger oil cracker, although it may sometimes act like a duck...

zbgt.machine.coal.name=Component Assembly Line
zbgt.machine.coal.description.1=Creates large batches of §fComponents§7 for §e75%%§7 of the Cost.
zbgt.machine.coal.description.2=Recipes are limited by §bCasing Tier§7.
Expand All @@ -196,9 +202,6 @@ zbgt.machine.coal.computation_tier.hover=Maximum amount of computation available
zbgt.recipe.coal_casing_tier=Casing Tier:
recipemap.coal_recipes.name=Component Assembly Line

zbgt.machine.queezer.name=Queezer
zbgt.machine.queezer.tooltip=A quad freezer that has 4 innate parallels

zbgt.machine.yottank.name=YOTTank
zbgt.machine.yottank.max_capacity=Capacity: %s
zbgt.machine.yottank.current_capacity=Stored: %s
Expand Down Expand Up @@ -294,7 +297,8 @@ zbgt.substation_enabled= and Substation Hatches


# Sound subtitles
zbgt.subtitle.fx_lo_freq=Low Frequency Buzzing
zbgt.subtitle.yottank_pulse=YOTTank Pulsed
zbgt.subtitle.quack=Quacker Quacked


# Materials
Expand Down
62 changes: 62 additions & 0 deletions src/main/resources/assets/zbgt/sounds.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"yottank_pulse": {
"category": "block",
"subtitle": "zbgt.subtitle.yottank_pulse",
"sounds": [
{
"name": "zbgt:fx_lo_freq",
"stream": false
}
]
},
"quack_1": {
"category": "block",
"subtitle": "zbgt.subtitle.quack",
"sounds": [
{
"name": "zbgt:quack_1",
"stream": false
}
]
},
"quack_2": {
"category": "block",
"subtitle": "zbgt.subtitle.quack",
"sounds": [
{
"name": "zbgt:quack_2",
"stream": false
}
]
},
"quack_3": {
"category": "block",
"subtitle": "zbgt.subtitle.quack",
"sounds": [
{
"name": "zbgt:quack_3",
"stream": false
}
]
},
"quack_4": {
"category": "block",
"subtitle": "zbgt.subtitle.quack",
"sounds": [
{
"name": "zbgt:quack_4",
"stream": false
}
]
},
"quack_5": {
"category": "block",
"subtitle": "zbgt.subtitle.quack",
"sounds": [
{
"name": "zbgt:quack_5",
"stream": false
}
]
}
}
Binary file added src/main/resources/assets/zbgt/sounds/quack_1.ogg
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added src/main/resources/assets/zbgt/sounds/quack_4.ogg
Binary file not shown.
Binary file added src/main/resources/assets/zbgt/sounds/quack_5.ogg
Binary file not shown.

0 comments on commit 30b1cac

Please sign in to comment.