diff --git a/createSymLinks.bat b/createSymLinks.bat index 0f7e117..6b25ae4 100644 --- a/createSymLinks.bat +++ b/createSymLinks.bat @@ -8,3 +8,4 @@ REM with the exception that deleting a symlink does not delete the linked resou REM Run this script after you've cloned the repo and anytime this file was changed in a new commit. mklink /j "mcp\src\minecraft\wdl" "src\wdl" +mklink /j "forge\src\main\java\wdl" "src\wdl" diff --git a/createSymLinks.sh b/createSymLinks.sh index b75f50f..e360f63 100755 --- a/createSymLinks.sh +++ b/createSymLinks.sh @@ -10,3 +10,4 @@ # Run this script after you've cloned the repo and anytime this file was changed in a new commit. ln -sr "src/wdl" "mcp/src/minecraft/wdl" +ln -sr "src/wdl" "forge/src/main/java/wdl" diff --git a/forge/.gitignore b/forge/.gitignore new file mode 100644 index 0000000..0bc60f9 --- /dev/null +++ b/forge/.gitignore @@ -0,0 +1,11 @@ +/.gradle +/.settings +/bin +/build +/eclipse +/gradle +/.classpath +/.project +/gradlew +/gradlew.bat +/*.txt diff --git a/forge/README.md b/forge/README.md new file mode 100644 index 0000000..00125e1 --- /dev/null +++ b/forge/README.md @@ -0,0 +1,27 @@ +# World Downloader Forge +## First time setup +Unzip the latest **Src** bundle from [files.minecraftforge.net](http://files.minecraftforge.net/) into this folder. + +## Updating to newer Forge versions +In the file **build.gradle** change the version number in line 25 to the latest one listed on [files.minecraftforge.net](http://files.minecraftforge.net/) +For example: + + version = "1.7.10-10.13.0.1156" + +The first part is the Minecraft version and the second part is the Forge version. +There is no need to download the latest version! The commands in the next section do this automatically. + +## After first time setup and after each update +* Open a command window in this folder (Windows: Shift+Click -> "Open command window here") +* Run command: `gradlew setupDecompWorkspace` +* Run command: `gradlew eclipse` + +## Building the mod +* Open a command window in this folder (Windows: Shift+Click -> "Open command window here") +* Run command: `gradlew build` +* The jar file containing the mod can be found in the subfolder **build/libs** + +## Other gradle "tasks" +`gradlew tasks` + +[More information about Forge](http://www.minecraftforge.net/forum/index.php/topic,14048.0.html) \ No newline at end of file diff --git a/forge/build.gradle b/forge/build.gradle new file mode 100644 index 0000000..7bc6476 --- /dev/null +++ b/forge/build.gradle @@ -0,0 +1,63 @@ +buildscript { + repositories { + mavenCentral() + maven { + name = "forge" + url = "http://files.minecraftforge.net/maven" + } + maven { + name = "sonatype" + url = "https://oss.sonatype.org/content/repositories/snapshots/" + } + } + dependencies { + classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT' + } +} + +apply plugin: 'forge' + +version = "1.7.10" +group= "wdl" // http://maven.apache.org/guides/mini/guide-naming-conventions.html +archivesBaseName = "WorldDownloader" + +minecraft { + version = "1.7.10-10.13.0.1180" + assetDir = "eclipse/assets" +} + +dependencies { + // you may put jars on which you depend on in ./libs + // or you may define them like so.. + //compile "some.group:artifact:version:classifier" + //compile "some.group:artifact:version" + + // real examples + //compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env + //compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env + + // for more info... + // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html + // http://www.gradle.org/docs/current/userguide/dependency_management.html + +} + +processResources +{ + // this will ensure that this task is redone when the versions change. + inputs.property "version", project.version + inputs.property "mcversion", project.minecraft.version + + // replace stuff in mcmod.info, nothing else + from(sourceSets.main.resources.srcDirs) { + include 'mcmod.info' + + // replace version and mcversion + expand 'version':project.version, 'mcversion':project.minecraft.version + } + + // copy everything else, thats not the mcmod.info + from(sourceSets.main.resources.srcDirs) { + exclude 'mcmod.info' + } +} diff --git a/forge/src/main/java/.gitignore b/forge/src/main/java/.gitignore new file mode 100644 index 0000000..1e2a3e6 --- /dev/null +++ b/forge/src/main/java/.gitignore @@ -0,0 +1,2 @@ +/wdl +/com/example/examplemod \ No newline at end of file diff --git a/forge/src/main/java/wdl_forge/ForgeMod.java b/forge/src/main/java/wdl_forge/ForgeMod.java new file mode 100644 index 0000000..af65472 --- /dev/null +++ b/forge/src/main/java/wdl_forge/ForgeMod.java @@ -0,0 +1,152 @@ +package wdl_forge; + +import wdl.WDL; +import net.minecraft.client.gui.GuiIngameMenu; +import net.minecraftforge.client.event.ClientChatReceivedEvent; +import net.minecraftforge.client.event.GuiOpenEvent; +import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent; +import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.world.ChunkEvent; +import net.minecraftforge.event.world.NoteBlockEvent; +import net.minecraftforge.event.world.WorldEvent; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.Mod; +import cpw.mods.fml.common.Mod.EventHandler; +import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.network.FMLNetworkEvent.ClientDisconnectionFromServerEvent; + +// TODO: Use the Forge mod proxy stuff to avoid performance impact in singleplayer. + +@Mod(modid = ForgeMod.MODID, version = ForgeMod.VERSION) +public class ForgeMod +{ + public static final String MODID = "WDL"; + public static final String VERSION = "1.7.10"; + + @EventHandler + public void init(FMLInitializationEvent event) + { + FMLCommonHandler.instance().bus().register(this); + MinecraftForge.EVENT_BUS.register(this); + } + + @SubscribeEvent + public void onChunkLoad(ChunkEvent.Load event) + { + if(event.world != WDL.wc) + { + WDL.onWorldLoad(); + } + } + + @SubscribeEvent + public void onChunkUnload(ChunkEvent.Unload event) + { + if(WDL.downloading && event.world.isRemote) + { + WDL.onChunkNoLongerNeeded(event.getChunk()); + } + } + + @SubscribeEvent + public void onWorldLoad(WorldEvent.Load event) + { + if(event.world.isRemote) + { + //WDL.onWorldLoad(); //Does NOT work! The player is not yet initialized here. + event.world.addWorldAccess(new WDLWorldAccess()); + } + } + + /* + @SubscribeEvent + public void onWorldUnload(WorldEvent.Unload event) + { + if(event.world.isRemote) + { + // not used + //WDL.onWorldUnload(); + } + } + */ + + @SubscribeEvent + public void onGuiSwitch(GuiOpenEvent event) + { + + if(WDL.downloading) + { + if(WDL.tp.openContainer != WDL.windowContainer) + { + if(WDL.tp.openContainer == WDL.tp.inventoryContainer) + { + WDL.onItemGuiClosed(); + } + WDL.windowContainer = WDL.tp.openContainer; + } + } + + } + + @SubscribeEvent + public void onNoteBlock(NoteBlockEvent event) + { + if(WDL.downloading && event.world.isRemote) + { + WDL.onBlockEvent(event.x, event.y, event.z, event.block, 0, event.getVanillaNoteId()); + } + } + + @SubscribeEvent + public void onDisconnect(ClientDisconnectionFromServerEvent event) + { + WDL.stop(); + } + + /* + @SubscribeEvent + public void onConnect(ClientConnectedToServerEvent event) + { + // mc.theWorld is still null! + } + */ + + @SubscribeEvent + public void onGuiDrawn(InitGuiEvent.Post event) + { + if(event.gui instanceof GuiIngameMenu) + { + WDL.injectWDLButtons((GuiIngameMenu)event.gui, event.buttonList); + } + + if(WDL.downloading) + { + if(WDL.tp.openContainer != WDL.windowContainer) + { + if(WDL.tp.openContainer != WDL.tp.inventoryContainer) + { + WDL.onItemGuiOpened(); + } + WDL.windowContainer = WDL.tp.openContainer; + } + } + } + + @SubscribeEvent + public void onGuiButtonClicked(ActionPerformedEvent.Pre event) + { + if(event.gui instanceof GuiIngameMenu) + { + WDL.handleWDLButtonClick((GuiIngameMenu)event.gui, event.button); + } + } + + @SubscribeEvent + public void onChatMessage(ClientChatReceivedEvent event) + { + WDL.handleServerSeedMessage(event.message.getFormattedText()); + } + +} diff --git a/forge/src/main/java/wdl_forge/WDLWorldAccess.java b/forge/src/main/java/wdl_forge/WDLWorldAccess.java new file mode 100644 index 0000000..c06bdb4 --- /dev/null +++ b/forge/src/main/java/wdl_forge/WDLWorldAccess.java @@ -0,0 +1,68 @@ +package wdl_forge; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.IWorldAccess; + +public class WDLWorldAccess implements IWorldAccess +{ + + // TODO: This needs a better solution! + @Override + public void onEntityDestroy(Entity entity) + { + /* + if(WDL.shouldKeepEntity(entity)) + { + //entity.isDead = false; + WDL.chatDebug("Reviving entity " + entity); + + Entity test = WDL.wc.getEntityByID(entity.getEntityId()); + WDL.chatDebug("test=" + test); + entity.isDead = false; + //WDL.wc.addEntityToWorld(entity.getEntityId(), entity); + //WDL.wc.spawnEntityInWorld(entity); + } + */ + } + + + // Unused: + + @Override + public void onEntityCreate(Entity a) {} + + @Override + public void markBlockForUpdate(int a, int b, int c) {} + + @Override + public void markBlockForRenderUpdate(int a, int b, int c) {} + + @Override + public void markBlockRangeForRenderUpdate(int a, int b, int c, int d, int e, int f) {} + + @Override + public void playSound(String a, double b, double c, double d, float e, float f) {} + + @Override + public void playSoundToNearExcept(EntityPlayer a, String b, double c, double d, double e, float f, float g) {} + + @Override + public void spawnParticle(String a, double b, double c, double d, double e, double f, double g) {} + + @Override + public void playRecord(String a, int b, int c, int d) {} + + @Override + public void broadcastSound(int a, int b, int c, int d, int e) {} + + @Override + public void playAuxSFX(EntityPlayer a, int b, int c, int d, int e, int f) {} + + @Override + public void destroyBlockPartially(int a, int b, int c, int d, int e) {} + + @Override + public void onStaticEntitiesChanged() {} + +} diff --git a/forge/src/main/resources/mcmod.info b/forge/src/main/resources/mcmod.info new file mode 100644 index 0000000..a8696f9 --- /dev/null +++ b/forge/src/main/resources/mcmod.info @@ -0,0 +1,16 @@ +[ +{ + "modid": "WDL", + "name": "World Downloader", + "description": "Backup your creations from multiplayer servers", + "version": "${version}", + "mcversion": "${mcversion}", + "url": "http://www.minecraftforum.net/topic/1444862-", + "updateUrl": "", + "authorList": ["nairol","cubic72"], + "credits": "", + "logoFile": "", + "screenshots": [], + "dependencies": [] +} +]