added foundation for SoundEvents

added a few soundevents for custom subtitles
sounds.json can be generated by launching the main in foundation/utility/data/Generator.java (this should be done before starting the client when new sound events were added)
This commit is contained in:
Zelophed 2020-02-15 01:57:16 +01:00
parent 6537214403
commit 50ba34e779
17 changed files with 287 additions and 20 deletions

View file

@ -0,0 +1,110 @@
package com.simibubi.create;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.simibubi.create.foundation.utility.data.ICanGenerateJson;
import net.minecraft.data.DirectoryCache;
import net.minecraft.data.IDataProvider;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.SoundEvents;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.registries.IForgeRegistry;
import java.io.IOException;
import java.nio.file.Path;
public enum AllSoundEvents implements ICanGenerateJson {
CUCKOO_PIG("creeperclock"),
CUCKOO_CREEPER("pigclock"),
SCHEMATICANNON_LAUNCH_BLOCK(SoundEvents.ENTITY_GENERIC_EXPLODE),
SCHEMATICANNON_FINISH(SoundEvents.BLOCK_NOTE_BLOCK_BELL),
SLIME_ADDED(SoundEvents.BLOCK_SLIME_BLOCK_PLACE),
MECHANICAL_PRESS_ACTIVATION(SoundEvents.BLOCK_ANVIL_LAND),
MECHANICAL_PRESS_ITEM_BREAK(SoundEvents.ENTITY_ITEM_BREAK),
BLOCKZAPPER_PLACE(SoundEvents.BLOCK_NOTE_BLOCK_BASEDRUM),
BLOCKZAPPER_CONFIRM(SoundEvents.BLOCK_NOTE_BLOCK_BELL),
BLOCKZAPPER_DENY(SoundEvents.BLOCK_NOTE_BLOCK_BASS),
BLOCK_FUNNEL_EAT(SoundEvents.ENTITY_GENERIC_EAT),
;
String id;
SoundEvent event, child;
//For adding our own sounds at assets/create/sounds/name.ogg
AllSoundEvents(){
id = name().toLowerCase();
}
AllSoundEvents(String name){
id = name;
}
//For wrapping a existing sound with new subtitle
AllSoundEvents(SoundEvent child){
id = name().toLowerCase();
this.child = child;
}
//subtitles are taken from the lang file (create.subtitle.sound_event_name)
public SoundEvent get(){
return event;
}
private String getName(){
return id;
}
public static void register(RegistryEvent.Register<SoundEvent> event) {
IForgeRegistry<SoundEvent> registry = event.getRegistry();
for (AllSoundEvents entry :
values()) {
ResourceLocation rec = new ResourceLocation(Create.ID, entry.getName());
SoundEvent sound = new SoundEvent(rec).setRegistryName(rec);
registry.register(sound);
entry.event = sound;
}
}
public void generate(Path path, DirectoryCache cache){
Gson GSON = (new GsonBuilder()).setPrettyPrinting().disableHtmlEscaping().create();
path = path.resolve("assets/create");
try {
JsonObject json = new JsonObject();
for (AllSoundEvents soundEvent :
values()) {
JsonObject entry = new JsonObject();
JsonArray arr = new JsonArray();
if (soundEvent.child != null){
//wrapper
JsonObject s = new JsonObject();
s.addProperty("name", soundEvent.child.getName().toString());
s.addProperty("type", "event");
arr.add(s);
} else{
//own sound
arr.add(Create.ID + ":" + soundEvent.getName());
}
entry.add("sounds", arr);
entry.addProperty("subtitle", Create.ID + ".subtitle." + soundEvent.getName());
json.add(soundEvent.getName(), entry);
}
IDataProvider.save(GSON, cache, json, path.resolve("sounds.json"));
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -1,6 +1,7 @@
package com.simibubi.create;
import com.simibubi.create.foundation.advancement.AllCriterionTriggers;
import net.minecraft.util.SoundEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -55,6 +56,7 @@ public class Create {
modEventBus.addGenericListener(ContainerType.class, AllContainers::register);
modEventBus.addGenericListener(EntityType.class, AllEntities::register);
modEventBus.addGenericListener(ParticleType.class, AllParticles::register);
modEventBus.addGenericListener(SoundEvent.class, AllSoundEvents::register);
AllConfigs.registerAll();
modEventBus.addListener(AllConfigs::onLoad);

View file

@ -0,0 +1,35 @@
package com.simibubi.create.foundation.utility.data;
import com.simibubi.create.AllSoundEvents;
import net.minecraft.data.DirectoryCache;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Generator {
/*
* this can probably be called by some gradle task or so but im not know how, so for now i just added a main below and execute from there when we need to generate jsons
**/
public static void generateJsonFiles(){
Path base = Paths.get("src/main/resources");
DirectoryCache cache;
try {
cache = new DirectoryCache(base, "cache");
for (ICanGenerateJson gen:
new ICanGenerateJson[]{AllSoundEvents.CUCKOO_CREEPER}) {
gen.generate(base, cache);
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
generateJsonFiles();
}
}

View file

@ -0,0 +1,11 @@
package com.simibubi.create.foundation.utility.data;
import net.minecraft.data.DirectoryCache;
import java.nio.file.Path;
public interface ICanGenerateJson {
//path points to the resource1s base folder
void generate(Path path, DirectoryCache cache);
}

View file

@ -2,6 +2,7 @@ package com.simibubi.create.modules.contraptions.components.contraptions.chassis
import java.util.List;
import com.simibubi.create.AllSoundEvents;
import com.simibubi.create.foundation.block.IHaveScrollableValue;
import com.simibubi.create.foundation.block.IWithTileEntity;
import com.simibubi.create.foundation.utility.Lang;
@ -18,7 +19,6 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.Vec3d;
@ -69,7 +69,7 @@ public abstract class AbstractChassisBlock extends RotatedPillarBlock
return true;
}
worldIn.playSound(null, pos, SoundEvents.BLOCK_SLIME_BLOCK_PLACE, SoundCategory.BLOCKS, .5f, 1);
worldIn.playSound(null, pos, AllSoundEvents.SLIME_ADDED.get(), SoundCategory.BLOCKS, .5f, 1);
if (isSlimeBall && !player.isCreative())
heldItem.shrink(1);
if (!isSlimeBall && !player.isCreative())

View file

@ -1,6 +1,7 @@
package com.simibubi.create.modules.contraptions.components.contraptions.piston;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllSoundEvents;
import com.simibubi.create.config.AllConfigs;
import com.simibubi.create.foundation.utility.AllShapes;
import com.simibubi.create.foundation.utility.Lang;
@ -21,7 +22,6 @@ import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.Vec3d;
@ -68,7 +68,7 @@ public class MechanicalPistonBlock extends DirectionalAxisKineticBlock {
worldIn.addParticle(ParticleTypes.ITEM_SLIME, vec.x, vec.y, vec.z, 0, 0, 0);
return true;
}
worldIn.playSound(null, pos, SoundEvents.BLOCK_SLIME_BLOCK_PLACE, SoundCategory.BLOCKS, .5f, 1);
worldIn.playSound(null, pos, AllSoundEvents.SLIME_ADDED.get(), SoundCategory.BLOCKS, .5f, 1);
if (!player.isCreative())
player.getHeldItem(handIn).shrink(1);
worldIn.setBlockState(pos, AllBlocks.STICKY_MECHANICAL_PISTON.get().getDefaultState().with(FACING, direction)

View file

@ -78,6 +78,12 @@ public class MotorBlock extends HorizontalKineticBlock
boolean forward = delta > 0;
int step = forward ? 1 : -1;
int currentSpeed = te.newGeneratedSpeed;
if (world.getClosestPlayer(pos.getX(), pos.getY(), pos.getZ()).isSneaking()){
te.setSpeedValueLazily(currentSpeed + step);
return;
}
int magnitude = Math.abs(currentSpeed) - (forward == currentSpeed > 0 ? 0 : 1);
if (magnitude >= 4)

View file

@ -5,6 +5,7 @@ import java.util.List;
import java.util.Optional;
import com.simibubi.create.AllRecipes;
import com.simibubi.create.AllSoundEvents;
import com.simibubi.create.AllTileEntities;
import com.simibubi.create.foundation.item.ItemHelper;
import com.simibubi.create.foundation.utility.VecHelper;
@ -25,7 +26,6 @@ import net.minecraft.particles.ItemParticleData;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.util.NonNullList;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
@ -190,8 +190,8 @@ public class MechanicalPressTileEntity extends BasinOperatingTileEntity {
}
if (!world.isRemote) {
world.playSound(null, getPos(), SoundEvents.ENTITY_ITEM_BREAK, SoundCategory.BLOCKS, .5f, 1f);
world.playSound(null, getPos(), SoundEvents.BLOCK_ANVIL_LAND, SoundCategory.BLOCKS, .125f, 1f);
world.playSound(null, getPos(), AllSoundEvents.MECHANICAL_PRESS_ITEM_BREAK.get(), SoundCategory.BLOCKS, .5f, 1f);
world.playSound(null, getPos(), AllSoundEvents.MECHANICAL_PRESS_ACTIVATION.get(), SoundCategory.BLOCKS, .125f, 1f);
}
}

View file

@ -57,7 +57,7 @@ public class AnalogLeverBlock extends HorizontalFaceBlock implements IWithTileEn
te.changeState(sneak);
float f = .25f + ((te.state + 5) / 15f) * .5f;
worldIn.playSound((PlayerEntity) null, pos, SoundEvents.BLOCK_LEVER_CLICK, SoundCategory.BLOCKS, 0.2F, f);
worldIn.playSound(null, pos, SoundEvents.BLOCK_LEVER_CLICK, SoundCategory.BLOCKS, 0.2F, f);
return true;
}

View file

@ -5,6 +5,7 @@ import java.util.List;
import java.util.Random;
import java.util.function.Supplier;
import com.simibubi.create.AllSoundEvents;
import org.lwjgl.opengl.GL11;
import com.mojang.blaze3d.platform.GlStateManager;
@ -26,8 +27,6 @@ import net.minecraft.particles.ParticleTypes;
import net.minecraft.util.Hand;
import net.minecraft.util.HandSide;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
@ -149,8 +148,7 @@ public class BlockzapperHandler {
public static void playSound(Hand hand, BlockPos position) {
float pitch = hand == Hand.MAIN_HAND ? 2f : 0.9f;
SoundEvent sound = SoundEvents.BLOCK_NOTE_BLOCK_BASEDRUM;
Minecraft.getInstance().world.playSound(position, sound, SoundCategory.BLOCKS, 0.8f, pitch, false);
Minecraft.getInstance().world.playSound(position, AllSoundEvents.BLOCKZAPPER_PLACE.get(), SoundCategory.BLOCKS, 0.8f, pitch, false);
}
public static void addBeam(LaserBeam beam) {

View file

@ -10,6 +10,7 @@ import java.util.function.Predicate;
import com.google.common.base.Predicates;
import com.simibubi.create.AllItems;
import com.simibubi.create.AllPackets;
import com.simibubi.create.AllSoundEvents;
import com.simibubi.create.Create;
import com.simibubi.create.foundation.block.render.CustomRenderedItemModel;
import com.simibubi.create.foundation.gui.ScreenOpener;
@ -50,7 +51,6 @@ import net.minecraft.util.Hand;
import net.minecraft.util.HandSide;
import net.minecraft.util.NonNullList;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceContext;
@ -196,7 +196,7 @@ public class BlockzapperItem extends Item implements IHaveCustomItemModel {
if (nbt.contains("BlockUsed"))
stateToUse = NBTUtil.readBlockState(nbt.getCompound("BlockUsed"));
else {
world.playSound(player, player.getPosition(), SoundEvents.BLOCK_NOTE_BLOCK_BASS, SoundCategory.BLOCKS, 1f,
world.playSound(player, player.getPosition(), AllSoundEvents.BLOCKZAPPER_DENY.get(), SoundCategory.BLOCKS, 1f,
0.5f);
player.sendStatusMessage(
new StringTextComponent(TextFormatting.RED + Lang.translate("blockzapper.leftClickToSet")), true);
@ -333,7 +333,7 @@ public class BlockzapperItem extends Item implements IHaveCustomItemModel {
return true;
stack.getTag().put("BlockUsed", NBTUtil.writeBlockState(newState));
entity.world.playSound((PlayerEntity) entity, entity.getPosition(), SoundEvents.BLOCK_NOTE_BLOCK_BELL,
entity.world.playSound((PlayerEntity) entity, entity.getPosition(), AllSoundEvents.BLOCKZAPPER_CONFIRM.get(),
SoundCategory.BLOCKS, 0.5f, 0.8f);
return true;

View file

@ -3,6 +3,7 @@ package com.simibubi.create.modules.logistics.block.belts;
import java.util.List;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllSoundEvents;
import com.simibubi.create.AllTileEntities;
import com.simibubi.create.foundation.behaviour.base.SmartTileEntity;
import com.simibubi.create.foundation.behaviour.base.TileEntityBehaviour;
@ -24,7 +25,6 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.Direction.Axis;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.Vec3i;
@ -96,7 +96,7 @@ public class FunnelTileEntity extends SmartTileEntity {
if (remainder.isEmpty()) {
if (!world.isRemote)
world.playSound(null, pos, SoundEvents.ENTITY_GENERIC_EAT, SoundCategory.BLOCKS, .125f, 1f);
world.playSound(null, pos, AllSoundEvents.BLOCK_FUNNEL_EAT.get(), SoundCategory.BLOCKS, .125f, 1f);
justEaten = stack.copy();
}

View file

@ -6,6 +6,7 @@ import java.util.List;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllItems;
import com.simibubi.create.AllSoundEvents;
import com.simibubi.create.AllTileEntities;
import com.simibubi.create.config.AllConfigs;
import com.simibubi.create.config.CSchematics;
@ -39,7 +40,6 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
@ -556,7 +556,7 @@ public class SchematicannonTileEntity extends SmartTileEntity implements INamedC
statusMsg = "finished";
resetPrinter();
target = getPos().add(1, 0, 0);
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.BLOCK_NOTE_BLOCK_BELL,
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), AllSoundEvents.SCHEMATICANNON_FINISH.get(),
SoundCategory.BLOCKS, 1, .7f);
sendUpdate = true;
return;
@ -702,7 +702,7 @@ public class SchematicannonTileEntity extends SmartTileEntity implements INamedC
if (state.getBlock() != Blocks.AIR)
blocksPlaced++;
flyingBlocks.add(new LaunchedBlock(this, target, state));
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.ENTITY_GENERIC_EXPLODE,
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), AllSoundEvents.SCHEMATICANNON_LAUNCH_BLOCK.get(),
SoundCategory.BLOCKS, .1f, 1.1f);
}

View file

@ -608,6 +608,16 @@
"advancement.create:speed_secret": "Hella fast",
"advancement.create:speed_secret.desc": "Watch a Speedometer reach exactly 666 speed",
"create.subtitle.schematicannon_launch_block": "Schematicannon shoots",
"create.subtitle.schematicannon_finish": "Schematicannon finishes",
"create.subtitle.slime_added": "Slime squishes",
"create.subtitle.mechanical_press_activation": "Mechanical Press activates",
"create.subtitle.mechanical_press_item_break": "Metal clanks",
"create.subtitle.blockzapper_place": "Blocks zap into place",
"create.subtitle.blockzapper_confirm": "Affirmative Ding",
"create.subtitle.blockzapper_deny": "Declining Boop",
"create.subtitle.block_funnel_eat": "Funnel eats",
"_comment": "-------------------------] ITEM DESCRIPTIONS [------------------------------------------------",
"item.create.example_item.tooltip": "EXAMPLE ITEM (just a marker that this tooltip exists)",

View file

@ -0,0 +1,95 @@
{
"creeperclock": {
"sounds": [
"create:creeperclock"
],
"subtitle": "create.subtitle.creeperclock"
},
"pigclock": {
"sounds": [
"create:pigclock"
],
"subtitle": "create.subtitle.pigclock"
},
"schematicannon_launch_block": {
"sounds": [
{
"name": "minecraft:entity.generic.explode",
"type": "event"
}
],
"subtitle": "create.subtitle.schematicannon_launch_block"
},
"schematicannon_finish": {
"sounds": [
{
"name": "minecraft:block.note_block.bell",
"type": "event"
}
],
"subtitle": "create.subtitle.schematicannon_finish"
},
"slime_added": {
"sounds": [
{
"name": "minecraft:block.slime_block.place",
"type": "event"
}
],
"subtitle": "create.subtitle.slime_added"
},
"mechanical_press_activation": {
"sounds": [
{
"name": "minecraft:block.anvil.land",
"type": "event"
}
],
"subtitle": "create.subtitle.mechanical_press_activation"
},
"mechanical_press_item_break": {
"sounds": [
{
"name": "minecraft:entity.item.break",
"type": "event"
}
],
"subtitle": "create.subtitle.mechanical_press_item_break"
},
"blockzapper_place": {
"sounds": [
{
"name": "minecraft:block.note_block.basedrum",
"type": "event"
}
],
"subtitle": "create.subtitle.blockzapper_place"
},
"blockzapper_confirm": {
"sounds": [
{
"name": "minecraft:block.note_block.bell",
"type": "event"
}
],
"subtitle": "create.subtitle.blockzapper_confirm"
},
"blockzapper_deny": {
"sounds": [
{
"name": "minecraft:block.note_block.bass",
"type": "event"
}
],
"subtitle": "create.subtitle.blockzapper_deny"
},
"block_funnel_eat": {
"sounds": [
{
"name": "minecraft:entity.generic.eat",
"type": "event"
}
],
"subtitle": "create.subtitle.block_funnel_eat"
}
}

Binary file not shown.