Browse Source

also move over the noteblock audio system support

tags/0.4.0
Adrian Siekierka 2 years ago
parent
commit
d1cfabf05a

unmoved/audio-src/note/NoteBlockManager.java → src/main/java/pl/asie/charset/audio/note/CharsetAudioNoteblock.java View File

@@ -13,27 +13,39 @@ import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.event.world.NoteBlockEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import pl.asie.charset.api.audio.AudioPacket;
import pl.asie.charset.audio.ModCharsetAudio;
import pl.asie.charset.lib.annotation.CharsetModule;
import pl.asie.charset.lib.audio.types.AudioDataGameSound;
import pl.asie.charset.lib.capability.Capabilities;
import pl.asie.charset.lib.capability.audio.DefaultAudioSource;
import pl.asie.charset.lib.network.PacketRegistry;

import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;

public class NoteBlockManager {
@CharsetModule(
name = "audio.noteblock",
description = "Noteblock rework. WIP"
)
public class CharsetAudioNoteblock {
private static final Map<Predicate<IBlockState>, SoundEvent> INSTRUMENTS = new HashMap<>();
private static final SoundEvent DEFAULT_INSTRUMENT;
private static final ResourceLocation NOTE_SOURCE_KEY = new ResourceLocation("charsetaudio:noteSource");

@CharsetModule.PacketRegistry
public PacketRegistry packet;


static {
DEFAULT_INSTRUMENT = SoundEvents.BLOCK_NOTE_HARP;

@@ -53,6 +65,12 @@ public class NoteBlockManager {
return DEFAULT_INSTRUMENT;
}

@Mod.EventHandler
public void init(FMLInitializationEvent event) {
packet.registerPacket(0x01, PacketNoteParticle.class);
MinecraftForge.EVENT_BUS.register(this);
}

@SubscribeEvent(priority = EventPriority.LOW)
public void onNoteEvent(NoteBlockEvent.Play event) {
World worldIn = event.getWorld();
@@ -86,7 +104,7 @@ public class NoteBlockManager {
event.setCanceled(true);

worldIn.playSound(null, pos, sound, SoundCategory.BLOCKS, 3.0F, pitch);
ModCharsetAudio.instance.packet().sendToAllAround(new PacketNoteParticle(note, param), note, 32);
packet.sendToAllAround(new PacketNoteParticle(note, param), note, 32);
}
}
}

unmoved/audio-src/note/PacketNoteParticle.java → src/main/java/pl/asie/charset/audio/note/PacketNoteParticle.java View File


+ 3
- 2
unmoved/audio-src/storage/DataStorageManager.java View File

@@ -20,6 +20,7 @@ import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import org.apache.commons.codec.binary.Hex;
import pl.asie.charset.ModCharset;
import pl.asie.charset.audio.ModCharsetAudio;

import java.io.File;
@@ -42,10 +43,10 @@ public class DataStorageManager {
if (saveDirParent.exists() || saveDirParent.mkdir()) {
saveDir = new File(saveDirParent, "tape");
if (!saveDir.exists() && !saveDir.mkdir()) {
ModCharsetAudio.instance.logger().error("Could not create save directory! " + saveDirParent.getAbsolutePath());
ModCharset.logger.error("Could not create save directory! " + saveDirParent.getAbsolutePath());
}
} else {
ModCharsetAudio.instance.logger().error("Could not create save directory! " + saveDirParent.getAbsolutePath());
ModCharset.logger.error("Could not create save directory! " + saveDirParent.getAbsolutePath());
}

lastSave = time();

+ 2
- 2
unmoved/audio-src/storage/DataStorageStorage.java View File

@@ -20,8 +20,8 @@ import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import pl.asie.charset.ModCharset;
import pl.asie.charset.api.tape.IDataStorage;
import pl.asie.charset.audio.ModCharsetAudio;

import java.io.IOException;

@@ -38,7 +38,7 @@ public class DataStorageStorage implements Capability.IStorage<IDataStorage> {
try {
instance.onUnload();
} catch (IOException e) {
ModCharsetAudio.instance.logger().error("Could not save a DataStorage! (ID: " + instance.getUniqueId() + ")");
ModCharset.logger.error("Could not save a DataStorage! (ID: " + instance.getUniqueId() + ")");
e.printStackTrace();
}


Loading…
Cancel
Save