From 5f4e5b9a6fbeb3ab700368106db3ba45c153d391 Mon Sep 17 00:00:00 2001 From: ExE Boss Date: Sun, 25 Dec 2016 22:30:31 +0100 Subject: [PATCH] NOVA-Minecraft 1.11 Wrappers --- build.gradle | 4 + minecraft/1.11/.gitignore | 17 +++ minecraft/1.11/build.gradle | 73 +++++++++++ minecraft/1.11/gradle.properties | 10 ++ .../v1_11/depmodules/ComponentModule.java | 15 +++ .../mc/forge/v1_11/launch/RedstoneAPI.java | 47 +++++++ .../wrapper/redstone/backward/BWRedstone.java | 80 ++++++++++++ .../wrapper/redstone/forward/FWRedstone.java | 123 ++++++++++++++++++ settings.gradle | 1 + 9 files changed, 370 insertions(+) create mode 100644 minecraft/1.11/.gitignore create mode 100644 minecraft/1.11/build.gradle create mode 100644 minecraft/1.11/gradle.properties create mode 100644 minecraft/1.11/src/main/java/nova/minecraft/wrapper/mc/forge/v1_11/depmodules/ComponentModule.java create mode 100644 minecraft/1.11/src/main/java/nova/minecraft/wrapper/mc/forge/v1_11/launch/RedstoneAPI.java create mode 100644 minecraft/1.11/src/main/java/nova/minecraft/wrapper/mc/forge/v1_11/wrapper/redstone/backward/BWRedstone.java create mode 100644 minecraft/1.11/src/main/java/nova/minecraft/wrapper/mc/forge/v1_11/wrapper/redstone/forward/FWRedstone.java diff --git a/build.gradle b/build.gradle index b07763b..a725a55 100644 --- a/build.gradle +++ b/build.gradle @@ -21,6 +21,10 @@ nova { wrapper "nova.core:NOVA-Core-Wrapper-MC1.8:$nova_version" runtime project(":minecraft:1.8") } + "1_11" { + wrapper "nova.core:NOVA-Core-Wrapper-MC1.11:$nova_version" + runtime project(":minecraft:1.11") + } } } diff --git a/minecraft/1.11/.gitignore b/minecraft/1.11/.gitignore new file mode 100644 index 0000000..85be317 --- /dev/null +++ b/minecraft/1.11/.gitignore @@ -0,0 +1,17 @@ +# Ignore All +/* + +# Sources +!/src + +# github +!/.gitignore +!/README.md + +# gradle +!/build.gradle +!/build.properties +!/settings.gradle +!/gradle.properties +!/gradlew* +!/gradle diff --git a/minecraft/1.11/build.gradle b/minecraft/1.11/build.gradle new file mode 100644 index 0000000..67481c6 --- /dev/null +++ b/minecraft/1.11/build.gradle @@ -0,0 +1,73 @@ +apply plugin: "maven-publish" +apply plugin: "com.jfrog.artifactory" +apply from: "https://raw.githubusercontent.com/NOVA-Team/NOVA-Gradle/master/shared-scripts/java.gradle" + +idea.module.name = "Minecraft-MC-1.11" +archivesBaseName = "NOVA-Minecraft-Wrapper-MC1.11" + +publishing { + publications { + main(MavenPublication) { + from components.java + + artifactId "NOVA-Minecraft-Wrapper-MC1.11" + + artifact sourcesJar + artifact javadocJar + + pom.withXml(writePom(project.properties)) + } + } +} + +artifactory { + publish { + defaults { + publications("main") + publishPom = true + } + } +} + +task deobfJar(type: Jar) { + from sourceSets.main.output + classifier = 'deobf' +} + +artifacts { + archives jar + archives deobfJar +} + +apply plugin: 'net.minecraftforge.gradle.forge' + +minecraft { + version = property("minecraft.version") + "-" + property("forge.version") + mappings = 'snapshot_20161220' + runDir = "run" +} + +dependencies { + compile rootProject + compile group: "nova.core", name: "NOVA-Core", version: property("nova_version"), changing: true + compile group: "nova.core", name: "NOVA-Core-Wrapper-MC1.11", version: property("nova_version"), classifier: "deobf", changing: true" +} + +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/minecraft/1.11/gradle.properties b/minecraft/1.11/gradle.properties new file mode 100644 index 0000000..39836aa --- /dev/null +++ b/minecraft/1.11/gradle.properties @@ -0,0 +1,10 @@ +group = nova.minecraft + +minecraft.version = 1.11 +forge.version = 13.19.1.2189 +forgeGradleVersion = 2.2-SNAPSHOT + +packaging = jar +info.inceptionYear = 2016 +info.description = The NOVA-Minecraft Minecraft 1.11 wrapper. +info.organization.name = NOVA diff --git a/minecraft/1.11/src/main/java/nova/minecraft/wrapper/mc/forge/v1_11/depmodules/ComponentModule.java b/minecraft/1.11/src/main/java/nova/minecraft/wrapper/mc/forge/v1_11/depmodules/ComponentModule.java new file mode 100644 index 0000000..ce013f7 --- /dev/null +++ b/minecraft/1.11/src/main/java/nova/minecraft/wrapper/mc/forge/v1_11/depmodules/ComponentModule.java @@ -0,0 +1,15 @@ +package nova.minecraft.wrapper.mc.forge.v1_11.depmodules; + +import nova.minecraft.redstone.Redstone; +import nova.minecraft.wrapper.mc.forge.v1_11.wrapper.redstone.forward.FWRedstone; +import se.jbee.inject.bind.BinderModule; + +/** + * @author Calclavia + */ +public class ComponentModule extends BinderModule { + @Override + protected void declare() { + bind(Redstone.class).to(FWRedstone.class); + } +} diff --git a/minecraft/1.11/src/main/java/nova/minecraft/wrapper/mc/forge/v1_11/launch/RedstoneAPI.java b/minecraft/1.11/src/main/java/nova/minecraft/wrapper/mc/forge/v1_11/launch/RedstoneAPI.java new file mode 100644 index 0000000..8f05aa0 --- /dev/null +++ b/minecraft/1.11/src/main/java/nova/minecraft/wrapper/mc/forge/v1_11/launch/RedstoneAPI.java @@ -0,0 +1,47 @@ +package nova.minecraft.wrapper.mc.forge.v1_11.launch; + +import nova.core.block.Block; +import nova.core.event.bus.GlobalEvents; +import nova.core.loader.Loadable; +import nova.core.loader.Mod; +import nova.core.world.World; +import nova.core.wrapper.mc.forge.v1_11.util.WrapperEvent; +import nova.minecraft.redstone.Redstone; +import nova.minecraft.wrapper.mc.forge.v1_11.depmodules.ComponentModule; +import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; + +import java.util.Optional; + +/** + * The Minecraft native loader + * @author Calclavia + */ +@Mod(id = "nova-minecraft-wrapper", name = "NOVA Minecraft", version = "0.0.1", novaVersion = "0.0.1", priority = 1, modules = { ComponentModule.class }) +public class RedstoneAPI implements Loadable { + + private final GlobalEvents events; + + public RedstoneAPI(GlobalEvents events) { + this.events = events; + } + + @Override + public void preInit() { + events.on(WrapperEvent.RedstoneConnect.class) + .bind(evt -> evt.canConnect = getRedstoneNode(evt.world, evt.position) + .map(n -> n.canConnect.apply(null)).orElseGet(() -> false)); + + events.on(WrapperEvent.StrongRedstone.class) + .bind(evt -> evt.power = getRedstoneNode(evt.world, evt.position) + .map(Redstone::getOutputStrongPower).orElseGet(() -> 0)); + + events.on(WrapperEvent.WeakRedstone.class) + .bind(evt -> evt.power = getRedstoneNode(evt.world, evt.position) + .map(Redstone::getOutputWeakPower).orElseGet(() -> 0)); + } + + public Optional getRedstoneNode(World world, Vector3D pos) { + Optional blockOptional = world.getBlock(pos); + return blockOptional.flatMap(block -> block.components.getOp(Redstone.class)); + } +} \ No newline at end of file diff --git a/minecraft/1.11/src/main/java/nova/minecraft/wrapper/mc/forge/v1_11/wrapper/redstone/backward/BWRedstone.java b/minecraft/1.11/src/main/java/nova/minecraft/wrapper/mc/forge/v1_11/wrapper/redstone/backward/BWRedstone.java new file mode 100644 index 0000000..99c13cf --- /dev/null +++ b/minecraft/1.11/src/main/java/nova/minecraft/wrapper/mc/forge/v1_11/wrapper/redstone/backward/BWRedstone.java @@ -0,0 +1,80 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package nova.minecraft.wrapper.mc.forge.v1_11.wrapper.redstone.backward; + +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; +import nova.core.block.Block; +import nova.core.util.Direction; +import nova.core.wrapper.mc.forge.v1_11.wrapper.block.backward.BWBlock; +import nova.core.wrapper.mc.forge.v1_11.wrapper.block.world.BWWorld; +import nova.internal.core.Game; +import nova.minecraft.redstone.Redstone; +import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; + +import java.util.function.Consumer; +import java.util.stream.IntStream; + +/** + * + * @author ExE Boss + */ +public class BWRedstone extends Redstone { + + private BWBlock block() { + return (BWBlock) getProvider(); + } + + private net.minecraft.world.World mcWorld() { + return ((BWWorld) block().world()).world(); + } + + public BWRedstone() { + this.canConnect = (Redstone otherRedstone) -> { + Block otherBlock = ((Block)otherRedstone.getProvider()); + Vector3D otherPos = otherBlock.position(); + Vector3D thisPos = block().position(); + BlockPos pos = new BlockPos(block().x(), block().y(), block().z()); + return block().mcBlock.canConnectRedstone(mcWorld().getBlockState(pos), mcWorld(), pos, Game.natives().toNative(Direction.fromVector(thisPos.crossProduct(otherPos)))); + }; + } + + @Override + public void onInputPowerChange(Consumer action) {} + + @Override + public int getOutputStrongPower() { + BlockPos pos = new BlockPos(block().x(), block().y(), block().z()); + return IntStream.range(0, 6).map(side -> mcWorld().getBlockState(pos).getStrongPower(mcWorld(), pos, EnumFacing.values()[side])).max().orElse(0); + } + + @Override + public void setOutputStrongPower(int power) {} + + @Override + public int getWeakPower(int side) { + return mcWorld().getRedstonePower(new BlockPos(block().x(), block().y(), block().z()), EnumFacing.values()[side]); + } + + @Override + public int getInputWeakPower() { + return mcWorld().isBlockIndirectlyGettingPowered(new BlockPos(block().x(), block().y(), block().z())); + } + + @Override + public int getInputStrongPower() { + return mcWorld().getStrongPower(new BlockPos(block().x(), block().y(), block().z())); + } + + @Override + public int getOutputWeakPower() { + BlockPos pos = new BlockPos(block().x(), block().y(), block().z()); + return IntStream.range(0, 6).map(side -> mcWorld().getBlockState(pos).getWeakPower(mcWorld(), pos, EnumFacing.values()[side])).max().orElse(0); + } + + @Override + public void setOutputWeakPower(int power) {} +} diff --git a/minecraft/1.11/src/main/java/nova/minecraft/wrapper/mc/forge/v1_11/wrapper/redstone/forward/FWRedstone.java b/minecraft/1.11/src/main/java/nova/minecraft/wrapper/mc/forge/v1_11/wrapper/redstone/forward/FWRedstone.java new file mode 100644 index 0000000..08466ac --- /dev/null +++ b/minecraft/1.11/src/main/java/nova/minecraft/wrapper/mc/forge/v1_11/wrapper/redstone/forward/FWRedstone.java @@ -0,0 +1,123 @@ +package nova.minecraft.wrapper.mc.forge.v1_11.wrapper.redstone.forward; + +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; +import nova.core.block.Block; +import nova.core.wrapper.mc.forge.v1_11.wrapper.block.world.BWWorld; +import nova.minecraft.redstone.Redstone; + +import java.util.function.Consumer; +import java.util.stream.IntStream; + +/** + * A Minecraft implementation that wraps Redstone to a Node + * @author Calclavia + */ +//TODO: Create NodeVirtualRedstone (for MC blocks that are redstone, but don't implement NOVA) +public class FWRedstone extends Redstone { + private boolean init = false; + private int inputStrongPower = 0; + private int inputWeakPower = 0; + private int[] inputSidedWeakPower = { 0, 0, 0, 0, 0, 0 }; + private int outputStrongPower = 0; + private int outputWeakPower = 0; + private Consumer onPowerChange = redstone -> { + }; + + private Block block() { + return (Block) getProvider(); + } + + @Override + public void onProviderChange() { + //Hook into the block's events. + getProvider().events.on(Block.NeighborChangeEvent.class).bind(evt -> recache()); + } + + @Override + public int getInputWeakPower() { + return inputWeakPower; + } + + @Override + public int getInputStrongPower() { + return inputStrongPower; + } + + @Override + public void onInputPowerChange(Consumer action) { + onPowerChange = action; + } + + @Override + public int getOutputStrongPower() { + if (!init) { + recache(); + } + return outputStrongPower; + } + + @Override + public void setOutputStrongPower(int power) { + outputStrongPower = power; + block().world().markChange(block().position()); + } + + @Override + public int getWeakPower(int side) { + if (!init) { + recache(); + } + return inputSidedWeakPower[side]; + } + + @Override + public int getOutputWeakPower() { + if (!init) { + recache(); + } + return outputWeakPower; + } + + @Override + public void setOutputWeakPower(int power) { + outputWeakPower = power; + block().world().markChange(block().position()); + } + + /** + * Recaches the Redstone state. + */ + public void recache() { + init = true; + boolean hasChanged = false; + + int newInputStrongPower = mcWorld().getStrongPower(new BlockPos(block().x(), block().y(), block().z())); + + if (inputStrongPower != newInputStrongPower) { + inputStrongPower = newInputStrongPower; + hasChanged = true; + } + + int newInputWeakPower = mcWorld().isBlockIndirectlyGettingPowered(new BlockPos(block().x(), block().y(), block().z())); + if (inputWeakPower != newInputWeakPower) { + inputWeakPower = newInputWeakPower; + hasChanged = true; + } + + int[] newInputSidedWeakPower = IntStream.range(0, 6).map(i -> mcWorld().getRedstonePower(new BlockPos(block().x(), block().y(), block().z()), EnumFacing.values()[i])).toArray(); + + if (inputSidedWeakPower != newInputSidedWeakPower) { + inputSidedWeakPower = newInputSidedWeakPower; + hasChanged = true; + } + + if (hasChanged) { + onPowerChange.accept(this); + } + } + + private net.minecraft.world.World mcWorld() { + return ((BWWorld) block().world()).world(); + } +} diff --git a/settings.gradle b/settings.gradle index 5c32951..b719b67 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,5 @@ rootProject.name = 'NOVA-Minecraft' +include "minecraft:1.11" include "minecraft:1.8" include "minecraft:1.7"