Skip to content

Commit

Permalink
NOVA-Minecraft 1.11 Wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
ExE-Boss committed Jan 22, 2017
1 parent 5e66bab commit 5f4e5b9
Show file tree
Hide file tree
Showing 9 changed files with 370 additions and 0 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}

Expand Down
17 changes: 17 additions & 0 deletions minecraft/1.11/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Ignore All
/*

# Sources
!/src

# github
!/.gitignore
!/README.md

# gradle
!/build.gradle
!/build.properties
!/settings.gradle
!/gradle.properties
!/gradlew*
!/gradle
73 changes: 73 additions & 0 deletions minecraft/1.11/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
}
10 changes: 10 additions & 0 deletions minecraft/1.11/gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<Redstone> getRedstoneNode(World world, Vector3D pos) {
Optional<Block> blockOptional = world.getBlock(pos);
return blockOptional.flatMap(block -> block.components.getOp(Redstone.class));
}
}
Original file line number Diff line number Diff line change
@@ -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<Redstone> 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) {}
}
Original file line number Diff line number Diff line change
@@ -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<Redstone> 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<Redstone> 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();
}
}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
rootProject.name = 'NOVA-Minecraft'

include "minecraft:1.11"
include "minecraft:1.8"
include "minecraft:1.7"

0 comments on commit 5f4e5b9

Please sign in to comment.