Skip to content

Commit

Permalink
v0.0.6 with GUI for IP and Port addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanford Laptop Orchestra committed Aug 14, 2014
1 parent 637820c commit dc9d513
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 30 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -5,6 +5,10 @@ Minecraft modded with osc output
- implements Open Sound Control via OscP5

--- --- --- --- --- --- --- --- --- ---
v0.0.6 (tag: "v0.0.6")

- Added mod config file and Gui for Target IP Address, Target Port and Input Port

v0.0.5 (tag: "v0.0.5")

- Added initial OSC input for creating and removing blocks
Expand Down
12 changes: 6 additions & 6 deletions code/mcmod.info
@@ -1,11 +1,11 @@
[
{
"modid": "osccraft",
"name": "OSCCraft",
"description": "OSC-hooked events for Minecraft/Forge 1.7.2.",
"version": "${version}",
"mcversion": "${mcversion}",
"url": "",
"modid": "Osccraft",
"name": "Osccraft",
"description": "Osccraft implements OSC-hooked events for Minecraft within the Minecraft Forge 1.7.10 framework. Using the oscP5 library, Minecraft player and block events output OSC values while OSC input is hooked to create blocks.",
"version": "v0.0.6",
"mcversion": "1.7.10",
"url": "github.com/robertkhamilton/osccraft",
"updateUrl": "",
"authorList": ["Rob Hamilton"],
"credits": "Rob Hamilton",
Expand Down
22 changes: 15 additions & 7 deletions code/osccraft/OscBlock.java
Expand Up @@ -17,15 +17,15 @@
public class OscBlock extends Block
{
final OscP5 thisOscP5= new OscP5((Object)this, 7000);
NetAddress blockPlacedRemoteLocation = new NetAddress("127.0.0.1",6666);
NetAddress blockWalkingRemoteLocation = new NetAddress("127.0.0.1",6666);
NetAddress blockDestroyedRemoteLocation = new NetAddress("127.0.0.1",6666);
NetAddress blockPlacedRemoteLocation = new NetAddress(osccraft.Osccraft.configIpAddress,osccraft.Osccraft.configOutPort);
NetAddress blockWalkingRemoteLocation = new NetAddress(osccraft.Osccraft.configIpAddress,osccraft.Osccraft.configOutPort);
NetAddress blockDestroyedRemoteLocation = new NetAddress(osccraft.Osccraft.configIpAddress,osccraft.Osccraft.configOutPort);
OscMessage blockPlacedMessage = new OscMessage("/osccraft/block/placed");
OscMessage blockWalkingMessage = new OscMessage("/osccraft/block/walking");
OscMessage blockDestroyedMessage = new OscMessage("/osccraft/block/destroyed");

OscMessage blockHitMessage = new OscMessage("/osccraft/block/hit");
NetAddress blockHitRemoteLocation = new NetAddress("127.0.0.1",6666);
NetAddress blockHitRemoteLocation = new NetAddress(osccraft.Osccraft.configIpAddress,osccraft.Osccraft.configOutPort);

// set block to be updated on next tick
Boolean updateNow;
Expand All @@ -36,6 +36,8 @@ public OscBlock (Material material)

// set custom creative tab
this.setCreativeTab(Osccraft.tabOsccraft);

System.out.println("************** NEW BLOCK");
}

/**
Expand All @@ -54,7 +56,7 @@ public void onBlockPlacedBy(World p_149689_1_, int p_149689_2_, int p_149689_3_,
if(Minecraft.getMinecraft().thePlayer.getEntityId() == player.getEntityId()) {

this.blockPlacedMessage.setAddrPattern("/osccraft/block/placed");
this.blockPlacedRemoteLocation = new NetAddress("localhost",6666);
this.blockPlacedRemoteLocation = new NetAddress(osccraft.Osccraft.configIpAddress,osccraft.Osccraft.configOutPort);
this.blockPlacedMessage.add((float)p_149689_2_);
this.blockPlacedMessage.add((float)p_149689_4_);
this.blockPlacedMessage.add((float)p_149689_3_);
Expand Down Expand Up @@ -100,7 +102,7 @@ public void onBlockClicked(World p_149699_1_, int p_149699_2_, int p_149699_3_,

int blockType;
this.blockHitMessage.setAddrPattern("/osccraft/block/hit");
this.blockHitRemoteLocation = new NetAddress("127.0.0.1",6666);
this.blockHitRemoteLocation = new NetAddress(osccraft.Osccraft.configIpAddress,osccraft.Osccraft.configOutPort);
this.blockHitMessage.add(blockX);
this.blockHitMessage.add(blockZ);
this.blockHitMessage.add(blockY);
Expand Down Expand Up @@ -162,7 +164,7 @@ public void onEntityWalking(World p_149724_1_, int p_149724_2_, int p_149724_3_,
EntityPlayer player = (EntityPlayer)p_149724_5_;

this.blockWalkingMessage.setAddrPattern("/osccraft/block/walking");
this.blockWalkingRemoteLocation = new NetAddress("localhost",6666);
this.blockWalkingRemoteLocation = new NetAddress(osccraft.Osccraft.configIpAddress,osccraft.Osccraft.configOutPort);
this.blockWalkingMessage.add((float)p_149724_2_);
this.blockWalkingMessage.add((float)p_149724_4_);
this.blockWalkingMessage.add((float)p_149724_3_);
Expand All @@ -178,6 +180,12 @@ public void onEntityWalking(World p_149724_1_, int p_149724_2_, int p_149724_3_,
this.blockWalkingMessage.clear();
}

}

// Test for block being added by OSC
public void onBlockAdded(World p_149726_1_, int p_149726_2_, int p_149726_3_, int p_149726_4_) {
System.out.print("BLOCK WAS ADDED");

}

public int tickRate(World p_149738_1_)
Expand Down
15 changes: 15 additions & 0 deletions code/osccraft/OscConfigGUI.java
@@ -0,0 +1,15 @@
package osccraft;

import cpw.mods.fml.client.config.GuiConfig;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.common.config.ConfigElement;
import net.minecraftforge.common.config.Configuration;

public class OscConfigGUI extends GuiConfig {

public OscConfigGUI(GuiScreen parent) {
super(parent,
new ConfigElement(Osccraft.configFile.getCategory(Configuration.CATEGORY_GENERAL)).getChildElements(),
"Osccraft", false, false, GuiConfig.getAbridgedConfigPath(Osccraft.configFile.toString()));
}
}
30 changes: 30 additions & 0 deletions code/osccraft/OscGuiFactory.java
@@ -0,0 +1,30 @@
package osccraft;

import cpw.mods.fml.client.IModGuiFactory;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;

import java.util.Set;

public class OscGuiFactory implements IModGuiFactory {

@Override
public void initialize(Minecraft minecraftInstance) {

}

@Override
public Class<? extends GuiScreen> mainConfigGuiClass() {
return OscConfigGUI.class;
}

@Override
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() {
return null;
}

@Override
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) {
return null;
}
}
16 changes: 8 additions & 8 deletions code/osccraft/OscPlayerEventHandler.java
Expand Up @@ -23,11 +23,11 @@
public class OscPlayerEventHandler {

final OscP5 thisOscP5= new OscP5((Object)this, 7000);
final OscP5 thisOscP5Listener= new OscP5((Object)this, 6667);
NetAddress playerRemoteLocation = new NetAddress("localhost",6666);
NetAddress blockHitRemoteLocation = new NetAddress("127.0.0.1",6666);
NetAddress blockDestroyedRemoteLocation = new NetAddress("127.0.0.1",6666);
NetAddress clickRemoteLocation = new NetAddress("localhost",6666);
final OscP5 thisOscP5Listener= new OscP5((Object)this, osccraft.Osccraft.configInPort);
NetAddress playerRemoteLocation = new NetAddress(osccraft.Osccraft.configIpAddress,osccraft.Osccraft.configOutPort);
NetAddress blockHitRemoteLocation = new NetAddress(osccraft.Osccraft.configIpAddress,osccraft.Osccraft.configOutPort);
NetAddress blockDestroyedRemoteLocation = new NetAddress(osccraft.Osccraft.configIpAddress,osccraft.Osccraft.configOutPort);
NetAddress clickRemoteLocation = new NetAddress(osccraft.Osccraft.configIpAddress,osccraft.Osccraft.configOutPort);
OscMessage playerMessage = new OscMessage("/osccraft/player");
OscMessage blockHitMessage = new OscMessage("/osccraft/block/hit");
OscMessage blockDestroyedMessage = new OscMessage("/osccraft/block/destroyed");
Expand Down Expand Up @@ -58,7 +58,7 @@ public void sendOSCPlayerPosition(LivingUpdateEvent theEvent)
{

this.playerMessage.setAddrPattern("/osccraft/player");
this.playerRemoteLocation = new NetAddress("localhost",6666);
this.playerRemoteLocation = new NetAddress(osccraft.Osccraft.configIpAddress,osccraft.Osccraft.configOutPort);
this.playerMessage.add((float)player.posX);
this.playerMessage.add((float)player.posZ);
this.playerMessage.add((float)player.posY);
Expand Down Expand Up @@ -105,7 +105,7 @@ public void sendOSCBlockHit(PlayerInteractEvent theEvent)

int blockType;
this.blockHitMessage.setAddrPattern("/osccraft/block/hit");
this.blockHitRemoteLocation = new NetAddress("127.0.0.1",6666);
this.blockHitRemoteLocation = new NetAddress(osccraft.Osccraft.configIpAddress,osccraft.Osccraft.configOutPort);
this.blockHitMessage.add(blockX);
this.blockHitMessage.add(blockZ);
this.blockHitMessage.add(blockY);
Expand Down Expand Up @@ -164,7 +164,7 @@ public void sendOSCBlockDestroyed(BreakEvent theEvent)

int blockType;
this.blockDestroyedMessage.setAddrPattern("/osccraft/block/destroyed");
this.blockDestroyedRemoteLocation = new NetAddress("127.0.0.1",6666);
this.blockDestroyedRemoteLocation = new NetAddress(osccraft.Osccraft.configIpAddress,osccraft.Osccraft.configOutPort);
this.blockDestroyedMessage.add(blockX);
this.blockDestroyedMessage.add(blockZ);
this.blockDestroyedMessage.add(blockY);
Expand Down
106 changes: 97 additions & 9 deletions code/osccraft/Osccraft.java
Expand Up @@ -12,10 +12,12 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.server.management.ServerConfigurationManager;
import net.minecraft.world.IWorldAccess;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.client.event.ConfigChangedEvent;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

Expand All @@ -34,17 +36,28 @@
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
//import cpw.mods.fml.common.network.NetworkMod; // not used in 1.7

@Mod(modid="OsccraftModID", name="Osccraft", version="0.0.5")
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.common.config.Configuration;

@Mod(modid="Osccraft", name="Osccraft", version="0.0.6", guiFactory = "osccraft.OscGuiFactory")
//@NetworkMod(clientSideRequired=true) // not used in 1.7
public class Osccraft {

final OscP5 thisOscP5= new OscP5((Object)this, 6667);
final OscP5 thisOscP5= new OscP5((Object)this, osccraft.Osccraft.configInPort);
public World myWorld;
public IWorldAccess myIWorld;


// Configuration file variables
public static Configuration configFile;
//public static int myConfigInteger = 32;
//public static String myConfigString = "Hello!";
//public static boolean myConfigBool = false;
public static String configIpAddress = "127.0.0.1";
public static int configOutPort = 6666;
public static int configInPort = 6667;

// The instance of your mod that Forge uses.
@Instance(value = "OsccraftModID")
@Instance(value = "Osccraft")
public static Osccraft instance;

// Custom OSC block class
Expand All @@ -61,15 +74,41 @@ public void preInit(FMLPreInitializationEvent event) {

// init custom blocks for this mod
this.initBlocks();


configFile = new Configuration(event.getSuggestedConfigurationFile());

syncConfig();

}

public static void syncConfig() {
//myConfigInteger = configFile.getInt("My Config Integer", Configuration.CATEGORY_GENERAL, myConfigInteger, 0, Integer.MAX_VALUE, "An Integer!");
//myConfigString = configFile.getString("My Config String", Configuration.CATEGORY_GENERAL, myConfigString, "A String!");
//myConfigBool = configFile.getBoolean("My Config Bool", Configuration.CATEGORY_GENERAL, myConfigBool, "A Boolean!");

configIpAddress = configFile.getString("Target IP", Configuration.CATEGORY_GENERAL, configIpAddress, "Target IP");
configOutPort = configFile.getInt("Target Port (output)", Configuration.CATEGORY_GENERAL, configOutPort, 0, 65535, "Target Port (output)");
configInPort = configFile.getInt("Receive Port (input)", Configuration.CATEGORY_GENERAL, configInPort, 0, 65535, "Receive Port (input)");

if(configFile.hasChanged())
configFile.save();
}

@EventHandler // used in 1.6.2
//@Init // used in 1.5.2
public void load(FMLInitializationEvent event) {
proxy.registerRenderers();
proxy.registerRenderers();

// Configuration file: register changes
FMLCommonHandler.instance().bus().register(instance);
}

@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent eventArgs) {
if(eventArgs.modID.equals("Osccraft"))
syncConfig();
}

@EventHandler // used in 1.6.2
//@PostInit // used in 1.5.2
public void postInit(FMLPostInitializationEvent event) {
Expand All @@ -89,7 +128,7 @@ void oscEvent(OscMessage theOscMessage) {
System.out.println("### received an osc message: ");
//System.out.println(" addrpattern: "+theOscMessage.addrPattern());
//System.out.println(" typetag: "+theOscMessage.typetag());
//theOscMessage.print();
theOscMessage.print();

//if(theOscMessage.checkAddrPattern("/osccraft/block/create")==true) {
// addBlock(theOscMessage);
Expand All @@ -105,13 +144,62 @@ void oscEvent(OscMessage theOscMessage) {
case "/osccraft/block/remove":
removeBlock(theOscMessage);
break;

case "/osccraft/block/opacity": // not working
setBlockOpacity(theOscMessage);
break;
case "/osccraft/block/light": // not working
setBlockLight(theOscMessage);
break;
}

//System.out.print(myWorld.playerEntities.get(0).toString() );
}

private void setBlockOpacity(OscMessage theOscMessage){

int opacity, x, y, z;

opacity = theOscMessage.get(0).intValue();
x = theOscMessage.get(1).intValue();
y = theOscMessage.get(2).intValue();
z = theOscMessage.get(3).intValue();

Block block = myWorld.getBlock(x, y, z);

block.setLightOpacity(opacity);
Minecraft.getMinecraft().renderGlobal.markBlockForUpdate(x, y, z);
myWorld.markBlockForUpdate(x, y, z);
//myIWorld.markBlockForRenderUpdate(x,y,z);
//myWorld.markBlockRangeForRenderUpdate(x,y,z,x,y,z);
}

private void setBlockLight(OscMessage theOscMessage){

float level;
int x, y, z;

level = theOscMessage.get(0).floatValue();
x = theOscMessage.get(1).intValue();
y = theOscMessage.get(2).intValue();
z = theOscMessage.get(3).intValue();

//Block block = myWorld.getBlock(x, y, z);

//block.setLightLevel(level);


myWorld.getBlock(x, y, z).setLightLevel(level);


Minecraft.getMinecraft().renderGlobal.markBlockForUpdate(x, y, z);
myWorld.markBlockForUpdate(x, y, z);
//myIWorld.markBlockForRenderUpdate(x, y, z);
//myWorld.markBlockRangeForRenderUpdate(x,y,z,x,y,z);

//myWorld.getBlock(x, y, z).UpdateTick()
//myWorld.updateAllLightTypes(x, y, z);

}
// Add block of specified type at OSC coordinates
private void addBlock(OscMessage theOscMessage)
{
Expand Down
Binary file added mod/osccraft-1.7.10-0.0.6.jar
Binary file not shown.

0 comments on commit dc9d513

Please sign in to comment.