Skip to content

Commit

Permalink
Update to 1.8 + fixes
Browse files Browse the repository at this point in the history
Updated to forge 1.8, using simple network implementation and fixed bug
which caused clients to disconnect when another player's song was
played.
  • Loading branch information
zoonie committed Jan 10, 2015
1 parent cdfa4f7 commit aa34a4b
Show file tree
Hide file tree
Showing 41 changed files with 537 additions and 411 deletions.
44 changes: 32 additions & 12 deletions java/com/dynious/soundscool/SoundsCool.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
package com.dynious.soundscool;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import net.minecraftforge.fml.relauncher.Side;

import com.dynious.soundscool.block.ModBlocks;
import com.dynious.soundscool.command.CommandSoundsCool;
import com.dynious.soundscool.creativetab.CreativeTabSoundsCool;
import com.dynious.soundscool.handler.GuiHandler;
import com.dynious.soundscool.handler.SoundHandler;
import com.dynious.soundscool.lib.Reference;
import com.dynious.soundscool.network.packet.SoundChunkPacket;
import com.dynious.soundscool.network.packet.SoundUploadedPacket;
import com.dynious.soundscool.network.packet.client.CheckPresencePacket;
import com.dynious.soundscool.network.packet.client.GetUploadedSoundsPacket;
import com.dynious.soundscool.network.packet.client.RemoveSoundPacket;
import com.dynious.soundscool.network.packet.client.SoundPlayerPlayPacket;
import com.dynious.soundscool.network.packet.client.SoundPlayerSelectPacket;
import com.dynious.soundscool.network.packet.server.OpenGUIPacket;
import com.dynious.soundscool.network.packet.server.ServerPlaySoundPacket;
import com.dynious.soundscool.network.packet.server.SoundNotFoundPacket;
import com.dynious.soundscool.network.packet.server.SoundReceivedPacket;
import com.dynious.soundscool.network.packet.server.SoundRemovedPacket;
import com.dynious.soundscool.network.packet.server.StopSoundPacket;
import com.dynious.soundscool.network.packet.server.UploadedSoundsPacket;
import com.dynious.soundscool.proxy.CommonProxy;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import net.minecraft.creativetab.CreativeTabs;

@Mod(modid = Reference.modid, name = Reference.name, version = Reference.version)
public class SoundsCool
Expand All @@ -27,24 +44,27 @@ public class SoundsCool
public static CommonProxy proxy;

public static CreativeTabs tabSoundsCool = new CreativeTabSoundsCool(CreativeTabs.getNextID(), Reference.modid);

public static SimpleNetworkWrapper network = NetworkRegistry.INSTANCE.newSimpleChannel("soundscool");

@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
proxy.soundSetup();
proxy.registerMessages();

proxy.soundSetup();

proxy.UISetup();

SoundHandler.findSounds();

ModBlocks.init();

proxy.initNetworking();
}

@EventHandler
public void init(FMLInitializationEvent event)
{
proxy.registerBlocks();

proxy.initTileEntities();

Expand Down
88 changes: 36 additions & 52 deletions java/com/dynious/soundscool/block/BlockSoundPlayer.java
Original file line number Diff line number Diff line change
@@ -1,118 +1,102 @@
package com.dynious.soundscool.block;

import com.dynious.soundscool.SoundsCool;
import com.dynious.soundscool.lib.Names;
import com.dynious.soundscool.lib.Reference;
import com.dynious.soundscool.tileentity.TileSoundPlayer;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;

public class BlockSoundPlayer extends BlockContainer
import com.dynious.soundscool.SoundsCool;
import com.dynious.soundscool.lib.Names;
import com.dynious.soundscool.lib.Reference;
import com.dynious.soundscool.tileentity.TileSoundPlayer;

public class BlockSoundPlayer extends Block implements ITileEntityProvider
{
public BlockSoundPlayer()
{
super(Material.rock);
this.setCreativeTab(SoundsCool.tabSoundsCool);
this.setBlockName(Names.soundPlayer);
this.setHardness(2F);
this.setResistance(10F);
this.setStepSound(Block.soundTypeStone);
this.setUnlocalizedName(Reference.modid+":"+Names.soundPlayer);
}


@Override
public TileEntity createNewTileEntity(World var1, int var2)
{
return new TileSoundPlayer();
}



@Override
public boolean onBlockActivated(World world, int x, int y, int z,
EntityPlayer player, int par6, float par7, float par8, float par9)
public boolean onBlockActivated(World world, BlockPos pos,
IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ)
{
if (player.isSneaking())
{
return false;
}
else
{
TileEntity tile = world.getTileEntity(x, y, z);
TileEntity tile = world.getTileEntity(pos);
if (tile != null && tile instanceof TileSoundPlayer)
{
player.openGui(SoundsCool.instance, 1, world, x, y, z);
player.openGui(SoundsCool.instance, 1, world, pos.getX(), pos.getY(), pos.getZ());
}
}
return true;
}

@Override
public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side)
public boolean canConnectRedstone(IBlockAccess world, BlockPos p, EnumFacing side)
{
return true;
}

@Override
public void onBlockAdded(World world, int x, int y, int z)
public void onBlockAdded(World world, BlockPos pos, IBlockState state)
{
TileEntity tile = world.getTileEntity(x, y, z);
TileEntity tile = world.getTileEntity(pos);
if (tile != null && tile instanceof TileSoundPlayer)
{
((TileSoundPlayer)tile).setPowered(world.isBlockIndirectlyGettingPowered(x, y, z));
if(world.isBlockIndirectlyGettingPowered(pos) > 0)
((TileSoundPlayer)tile).setPowered(true);
else
((TileSoundPlayer)tile).setPowered(false);
}
}

@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block block)
public void onNeighborBlockChange(World world, BlockPos pos, IBlockState state, Block block)
{
TileEntity tile = world.getTileEntity(x, y, z);
TileEntity tile = world.getTileEntity(pos);
if (tile != null && tile instanceof TileSoundPlayer)
{
((TileSoundPlayer)tile).setPowered(world.isBlockIndirectlyGettingPowered(x, y, z));
if(world.isBlockIndirectlyGettingPowered(pos) > 0)
((TileSoundPlayer)tile).setPowered(true);
else
((TileSoundPlayer)tile).setPowered(false);
}
}

@Override
public void breakBlock(World world, int x, int y, int z, Block block, int meta)
public void breakBlock(World world, BlockPos pos, IBlockState state)
{
TileEntity tile = world.getTileEntity(x, y, z);
TileEntity tile = world.getTileEntity(pos);
if (tile != null && tile instanceof TileSoundPlayer)
{
((TileSoundPlayer)tile).stopCurrentSound();
}
super.breakBlock(world, x, y, z, block, meta);
}

private IIcon blockTop;
private IIcon blockSide;

@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister)
{
blockTop = iconRegister.registerIcon(Reference.modid + ":" + String.format("%s_top", getUnwrappedUnlocalizedName(this.getUnlocalizedName())));
blockSide = iconRegister.registerIcon(Reference.modid + ":" + String.format("%s_side", getUnwrappedUnlocalizedName(this.getUnlocalizedName())));
}

@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int metaData)
{
if (ForgeDirection.getOrientation(side) == ForgeDirection.UP || ForgeDirection.getOrientation(side) == ForgeDirection.DOWN)
{
return blockTop;
}
else
{
return blockSide;
}
super.breakBlock(world, pos, state);
}

protected String getUnwrappedUnlocalizedName(String unlocalizedName)
Expand Down
7 changes: 6 additions & 1 deletion java/com/dynious/soundscool/block/ModBlocks.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.dynious.soundscool.block;

import com.dynious.soundscool.lib.Names;
import cpw.mods.fml.common.registry.GameRegistry;
import com.dynious.soundscool.lib.Reference;

import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

public class ModBlocks
Expand Down
6 changes: 3 additions & 3 deletions java/com/dynious/soundscool/client/audio/SoundPlayer.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.dynious.soundscool.client.audio;

import com.dynious.soundscool.handler.SoundHandler;
import cpw.mods.fml.common.ObfuscationReflectionHelper;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.SoundManager;
import paulscode.sound.SoundSystem;
Expand Down
6 changes: 4 additions & 2 deletions java/com/dynious/soundscool/client/gui/GuiAdminPanel.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.dynious.soundscool.client.gui;

import com.dynious.soundscool.SoundsCool;
import com.dynious.soundscool.helper.NetworkHelper;
import com.dynious.soundscool.network.packet.client.GetUploadedSoundsPacket;

import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
Expand All @@ -16,15 +18,15 @@ public class GuiAdminPanel extends GuiScreen
public GuiAdminPanel(EntityPlayer player)
{
this.player = player;
SoundsCool.proxy.getChannel().writeOutbound(new GetUploadedSoundsPacket(player));
NetworkHelper.syncPlayerSounds(player);
}

@Override
public void initGui()
{
super.initGui();
this.buttonList.add(new GuiButton(0, getWidth() / 2, getHeight() - 42, I18n.format("gui.done")));
maxSounds = new GuiTextField(fontRendererObj, getWidth()/2, getHeight()/2, 20, 15);
maxSounds = new GuiTextField(0, fontRendererObj, getWidth()/2, getHeight()/2, 20, 15);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.dynious.soundscool.handler.SoundHandler;
import com.dynious.soundscool.sound.Sound;
import cpw.mods.fml.client.GuiScrollingList;
import net.minecraftforge.fml.client.GuiScrollingList;
import net.minecraft.client.renderer.Tessellator;

public class GuiLocalSoundsList extends GuiScrollingList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.dynious.soundscool.handler.SoundHandler;
import com.dynious.soundscool.sound.Sound;
import cpw.mods.fml.client.GuiScrollingList;
import net.minecraftforge.fml.client.GuiScrollingList;
import net.minecraft.client.renderer.Tessellator;

public class GuiRemoteSoundsList extends GuiScrollingList
Expand Down
25 changes: 15 additions & 10 deletions java/com/dynious/soundscool/client/gui/GuiSoundPlayer.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
package com.dynious.soundscool.client.gui;

import com.dynious.soundscool.SoundsCool;
import com.dynious.soundscool.handler.SoundHandler;
import com.dynious.soundscool.network.packet.client.GetUploadedSoundsPacket;
import com.dynious.soundscool.network.packet.client.SoundPlayerPlayPacket;
import com.dynious.soundscool.sound.Sound;
import com.dynious.soundscool.tileentity.TileSoundPlayer;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import org.apache.commons.io.FileUtils;

import com.dynious.soundscool.SoundsCool;
import com.dynious.soundscool.handler.SoundHandler;
import com.dynious.soundscool.helper.NetworkHelper;
import com.dynious.soundscool.helper.SoundHelper;
import com.dynious.soundscool.network.packet.client.GetUploadedSoundsPacket;
import com.dynious.soundscool.network.packet.client.SoundPlayerPlayPacket;
import com.dynious.soundscool.sound.Sound;
import com.dynious.soundscool.tileentity.TileSoundPlayer;

@SideOnly(Side.CLIENT)
public class GuiSoundPlayer extends GuiScreen implements IListGui
{
Expand All @@ -25,7 +29,7 @@ public class GuiSoundPlayer extends GuiScreen implements IListGui
public GuiSoundPlayer(TileSoundPlayer tile)
{
this.tile = tile;
SoundsCool.proxy.getChannel().writeOutbound(new GetUploadedSoundsPacket(Minecraft.getMinecraft().thePlayer));
NetworkHelper.syncPlayerSounds(Minecraft.getMinecraft().thePlayer);
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -77,7 +81,8 @@ protected void actionPerformed(GuiButton button)
case 1:
if (tile.getSelectedSound() != null)
{
SoundsCool.proxy.getChannel().writeOutbound(new SoundPlayerPlayPacket(tile));
NetworkHelper.syncPlayerSounds(Minecraft.getMinecraft().thePlayer);
SoundsCool.network.sendToServer(new SoundPlayerPlayPacket(tile));
}
break;
}
Expand Down
7 changes: 5 additions & 2 deletions java/com/dynious/soundscool/client/gui/GuiSounds.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@
import com.dynious.soundscool.network.packet.client.GetUploadedSoundsPacket;
import com.dynious.soundscool.network.packet.client.RemoveSoundPacket;
import com.dynious.soundscool.sound.Sound;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;

import org.apache.commons.io.FileUtils;

import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;

import java.awt.*;
import java.util.UUID;

Expand Down Expand Up @@ -47,7 +50,7 @@ protected JDialog createDialog(Component parent)
}
};
fileChooser.setFileFilter(new FileNameExtensionFilter("Sound Files (.ogg, .wav, .mp3)", "ogg", "wav", "mp3"));
SoundsCool.proxy.getChannel().writeOutbound(new GetUploadedSoundsPacket(player));
NetworkHelper.syncPlayerSounds(player);
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -157,7 +160,7 @@ protected void actionPerformed(GuiButton button)
}
else
{
SoundsCool.proxy.getChannel().writeOutbound(new RemoveSoundPacket(selectedSound.getSoundName()));
SoundsCool.network.sendToServer(new RemoveSoundPacket(selectedSound.getSoundName()));
SoundHandler.removeSound(selectedSound);
selectSoundIndex(-1);
}
Expand Down
Loading

0 comments on commit aa34a4b

Please sign in to comment.