From c26136bd9f3821963f5089c4c49ddb855a869b82 Mon Sep 17 00:00:00 2001 From: ExE Boss Date: Sat, 24 Dec 2016 12:25:29 +0100 Subject: [PATCH] NOVA-Energy Minecraft 1.11 Wrappers --- build.gradle | 5 + minecraft/.gitignore | 6 ++ minecraft/1.11/.gitignore | 17 +++ minecraft/1.11/build.gradle | 73 +++++++++++++ minecraft/1.11/gradle.properties | 10 ++ .../forge/v1_11/launch/NovaEnergyWrapper.java | 102 ++++++++++++++++++ .../energy/backward/BWEnergyStorage.java | 81 ++++++++++++++ .../energy/forward/FWEnergyStorage.java | 70 ++++++++++++ minecraft/build.gradle | 19 ++++ settings.gradle | 2 + 10 files changed, 385 insertions(+) create mode 100644 minecraft/.gitignore 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/energy/wrapper/mc/forge/v1_11/launch/NovaEnergyWrapper.java create mode 100644 minecraft/1.11/src/main/java/nova/energy/wrapper/mc/forge/v1_11/wrapper/energy/backward/BWEnergyStorage.java create mode 100644 minecraft/1.11/src/main/java/nova/energy/wrapper/mc/forge/v1_11/wrapper/energy/forward/FWEnergyStorage.java create mode 100644 minecraft/build.gradle diff --git a/build.gradle b/build.gradle index 26a97de..863823f 100644 --- a/build.gradle +++ b/build.gradle @@ -19,6 +19,11 @@ nova { "18" { wrapper "nova.core:NOVA-Core-Wrapper-MC1.8:$nova_version" } + } + "1_11" { + wrapper "nova.core:NOVA-Core-Wrapper-MC1.11:$nova_version" + runtime project(":minecraft:1.11") + } } } diff --git a/minecraft/.gitignore b/minecraft/.gitignore new file mode 100644 index 0000000..e2bf0e7 --- /dev/null +++ b/minecraft/.gitignore @@ -0,0 +1,6 @@ +/* + +!/build.gradle +!/.gitignore + +!/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..d5d4961 --- /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 = "Energy-MC-1.11" +archivesBaseName = "NOVA-Energy-Wrapper-MC1.11" + +publishing { + publications { + main(MavenPublication) { + from components.java + + artifactId archivesBaseName + + 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..4b8ef0a --- /dev/null +++ b/minecraft/1.11/gradle.properties @@ -0,0 +1,10 @@ +group = nova.energy + +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/energy/wrapper/mc/forge/v1_11/launch/NovaEnergyWrapper.java b/minecraft/1.11/src/main/java/nova/energy/wrapper/mc/forge/v1_11/launch/NovaEnergyWrapper.java new file mode 100644 index 0000000..b8f6385 --- /dev/null +++ b/minecraft/1.11/src/main/java/nova/energy/wrapper/mc/forge/v1_11/launch/NovaEnergyWrapper.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2015 NOVA, All rights reserved. + * This library is free software, licensed under GNU Lesser General Public License version 3 + * + * This file is part of NOVA. + * + * NOVA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NOVA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NOVA. If not, see . + */ +package nova.energy.wrapper.mc.forge.v1_11.launch; + +import net.minecraft.util.EnumFacing; +import net.minecraftforge.energy.CapabilityEnergy; +import net.minecraftforge.energy.IEnergyStorage; +import nova.core.event.bus.GlobalEvents; +import nova.core.loader.Loadable; +import nova.core.loader.Mod; +import nova.core.wrapper.mc.forge.v1_11.util.WrapperEvent; +import nova.energy.EnergyStorage; +import nova.energy.wrapper.mc.forge.v1_11.wrapper.energy.backward.BWEnergyStorage; +import nova.energy.wrapper.mc.forge.v1_11.wrapper.energy.forward.FWEnergyStorage; + +/** + * Compatibility with Forge Energy, which has been in Minecraft Forge since Minecraft 1.10.2. + * + * @author ExE Boss + */ +@Mod(id = NovaEnergyWrapper.id, name = NovaEnergyWrapper.name, version = NovaEnergyWrapper.version, novaVersion = "0.1.0") +public class NovaEnergyWrapper implements Loadable { + + public static final String version = "0.0.1"; + public static final String id = "nova-energy-wrapper"; + public static final String name = "NOVA Energy"; + + private final GlobalEvents events; + + public NovaEnergyWrapper(GlobalEvents events) { + this.events = events; + } + + @Override + public void preInit() { + events.on(WrapperEvent.BWBlockCreate.class).bind(evt -> { + if (evt.novaBlock.getTileEntity() == null) + return; + + IEnergyStorage energyCapability = null; + for (EnumFacing facing : EnumFacing.values()) { + if (!evt.novaBlock.getTileEntity().hasCapability(CapabilityEnergy.ENERGY, facing)) + continue; + + energyCapability = evt.novaBlock.getTileEntity().getCapability(CapabilityEnergy.ENERGY, facing); + if (energyCapability != null) + break; // NOVA-Energy is Unsided + } + + if (energyCapability == null && evt.novaBlock.getTileEntity().hasCapability(CapabilityEnergy.ENERGY, null)) + energyCapability = evt.novaBlock.getTileEntity().getCapability(CapabilityEnergy.ENERGY, null); + + if (energyCapability != null) + evt.novaBlock.components.add(new BWEnergyStorage(energyCapability)); + }); + + events.on(WrapperEvent.BWItemCreate.class).bind(evt -> { + if (evt.itemStack.isPresent() && evt.itemStack.get().hasCapability(CapabilityEnergy.ENERGY, null)) + evt.novaItem.components.add(new BWEnergyStorage(evt.itemStack.get().getCapability(CapabilityEnergy.ENERGY, null))); + }); + + events.on(WrapperEvent.BWEntityCreate.class).bind(evt -> { + if (evt.mcEntity.hasCapability(CapabilityEnergy.ENERGY, null)) + evt.novaEntity.components.add(new BWEnergyStorage(evt.mcEntity.getCapability(CapabilityEnergy.ENERGY, null))); + }); + + events.on(WrapperEvent.FWTileCreate.class).bind(evt -> { + if (evt.tileEntity == null) + return; + + if (evt.novaBlock.components.has(EnergyStorage.class)) // Components are unsided + evt.tileEntity.addCapability(CapabilityEnergy.ENERGY, new FWEnergyStorage(evt.novaBlock.components.get(EnergyStorage.class)), null); + }); + + events.on(WrapperEvent.FWItemInitCapabilities.class).bind(evt -> { + if (evt.novaItem.components.has(EnergyStorage.class)) // Components are unsided + evt.capabilityProvider.addCapability(CapabilityEnergy.ENERGY, new FWEnergyStorage(evt.novaItem.components.get(EnergyStorage.class)), null); + }); + + events.on(WrapperEvent.FWEntityCreate.class).bind(evt -> { + if (evt.novaEntity.components.has(EnergyStorage.class)) // Components are unsided + evt.mcEntity.addCapability(CapabilityEnergy.ENERGY, new FWEnergyStorage(evt.novaEntity.components.get(EnergyStorage.class)), null); + }); + } +} diff --git a/minecraft/1.11/src/main/java/nova/energy/wrapper/mc/forge/v1_11/wrapper/energy/backward/BWEnergyStorage.java b/minecraft/1.11/src/main/java/nova/energy/wrapper/mc/forge/v1_11/wrapper/energy/backward/BWEnergyStorage.java new file mode 100644 index 0000000..a3b7f4f --- /dev/null +++ b/minecraft/1.11/src/main/java/nova/energy/wrapper/mc/forge/v1_11/wrapper/energy/backward/BWEnergyStorage.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2015 NOVA, All rights reserved. + * This library is free software, licensed under GNU Lesser General Public License version 3 + * + * This file is part of NOVA. + * + * NOVA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NOVA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NOVA. If not, see . + */ +package nova.energy.wrapper.mc.forge.v1_11.wrapper.energy.backward; + +import net.minecraftforge.energy.IEnergyStorage; +import nova.energy.EnergyStorage; +import nova.energy.Unit; +import nova.energy.UnitConversion; + +/** + * + * @author ExE Boss + */ +public class BWEnergyStorage extends EnergyStorage { + + private static final UnitConversion RF_JOULE = UnitConversion.getConvertion(Unit.REDFLUX, Unit.JOULE).get(); + private static final UnitConversion JOULE_RF = RF_JOULE.reverse(); + + private final IEnergyStorage mcEnergyStorage; + + public BWEnergyStorage(IEnergyStorage mcEnergyStorage) { + this.mcEnergyStorage = mcEnergyStorage; + } + + @Override + public double recharge(double energy, boolean doRecharge) { + return RF_JOULE.convert(mcEnergyStorage.receiveEnergy((int) Math.round(JOULE_RF.convert(energy)), !doRecharge)); + } + + @Override + public double discharge(double energy, boolean doDischarge) { + return RF_JOULE.convert(mcEnergyStorage.extractEnergy((int) Math.round(JOULE_RF.convert(energy)), !doDischarge)); + } + + @Override + public double getEnergy() { + return RF_JOULE.convert(mcEnergyStorage.getEnergyStored()); + } + + @Override + public void setEnergy(double energy) { + int rf = (int) Math.round(JOULE_RF.convert(energy)) - mcEnergyStorage.getEnergyStored(); + if (rf > 0) { + mcEnergyStorage.receiveEnergy(rf, false); + } else if (rf < 0) { + mcEnergyStorage.extractEnergy(-rf, false); + } + } + + @Override + public double getEnergyCapacity() { + return RF_JOULE.convert(mcEnergyStorage.getMaxEnergyStored()); + } + + @Override + public boolean canDischarge() { + return mcEnergyStorage.canExtract(); + } + + @Override + public boolean canRecharge() { + return mcEnergyStorage.canReceive(); + } +} diff --git a/minecraft/1.11/src/main/java/nova/energy/wrapper/mc/forge/v1_11/wrapper/energy/forward/FWEnergyStorage.java b/minecraft/1.11/src/main/java/nova/energy/wrapper/mc/forge/v1_11/wrapper/energy/forward/FWEnergyStorage.java new file mode 100644 index 0000000..4a55d71 --- /dev/null +++ b/minecraft/1.11/src/main/java/nova/energy/wrapper/mc/forge/v1_11/wrapper/energy/forward/FWEnergyStorage.java @@ -0,0 +1,70 @@ +/* + * 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.energy.wrapper.mc.forge.v1_11.wrapper.energy.forward; + +import net.minecraftforge.energy.IEnergyStorage; +import nova.energy.EnergyStorage; +import nova.energy.Unit; +import nova.energy.UnitConversion; + +/** + * A FWEnergyStorage is a NOVA energy capability. + * + * @author ExE Boss + */ +public class FWEnergyStorage implements IEnergyStorage { + + private static final UnitConversion RF_JOULE = UnitConversion.getConvertion(Unit.REDFLUX, Unit.JOULE).get(); + private static final UnitConversion JOULE_RF = RF_JOULE.reverse(); + + private final EnergyStorage energyStorage; + + public FWEnergyStorage(EnergyStorage energyStorage) { + this.energyStorage = energyStorage; + } + + @Override + public int receiveEnergy(int maxReceive, boolean simulate) { + if (energyStorage != null) + return (int) Math.round(JOULE_RF.convert(energyStorage.recharge(RF_JOULE.convert(maxReceive), !simulate))); + return 0; + } + + @Override + public int extractEnergy(int maxExtract, boolean simulate) { + if (energyStorage != null) + return (int) Math.round(JOULE_RF.convert(energyStorage.discharge(RF_JOULE.convert(maxExtract), !simulate))); + return 0; + } + + @Override + public int getEnergyStored() { + if (energyStorage != null) + return (int) Math.round(JOULE_RF.convert(energyStorage.getEnergy())); + return 0; + } + + @Override + public int getMaxEnergyStored() { + if (energyStorage != null) + return (int) Math.round(JOULE_RF.convert(energyStorage.getEnergyCapacity())); + return 0; + } + + @Override + public boolean canExtract() { + if (energyStorage != null) + return energyStorage.canDischarge(); + return false; + } + + @Override + public boolean canReceive() { + if (energyStorage != null) + return energyStorage.canRecharge(); + return false; + } +} diff --git a/minecraft/build.gradle b/minecraft/build.gradle new file mode 100644 index 0000000..905f27d --- /dev/null +++ b/minecraft/build.gradle @@ -0,0 +1,19 @@ +subprojects { + buildscript { + repositories { + mavenCentral() + maven { + name "forge" + url "http://files.minecraftforge.net/maven" + } + maven { + name "sonatype" + url "https://oss.sonatype.org/content/repositories/snapshots/" + } + } + dependencies { + // Minecraft 1.11 requires newer ForgeGradle, while 1.7 and 1.8 require older. + classpath 'net.minecraftforge.gradle:ForgeGradle:' + property('forgeGradleVersion') + } + } +} diff --git a/settings.gradle b/settings.gradle index 0f85d03..7b75a36 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1,3 @@ rootProject.name = 'NOVA-Energy' + +include "minecraft:1.11"