diff --git a/.gitignore b/.gitignore index ca21b090a..219e29acc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ /build/ /bin/ +/Mixin/ +/run/ /.gradle/ /.settings/ /.classpath diff --git a/build.gradle b/build.gradle index 7dd975bfe..7c501842c 100644 --- a/build.gradle +++ b/build.gradle @@ -2,12 +2,12 @@ buildscript { repositories { mavenCentral() maven { - name = "ForgeFS" - url = "http://files.minecraftforge.net/maven" + name = 'sonatype-nexus-public' + url = 'https://oss.sonatype.org/content/repositories/public/' } maven { - name = "sonatype" - url = "https://oss.sonatype.org/content/repositories/snapshots/" + name = 'forge-repo' + url = 'http://files.minecraftforge.net/maven/' } } dependencies { @@ -15,6 +15,8 @@ buildscript { } } +evaluationDependsOn('Mixin') + apply plugin: "forge" repositories { @@ -40,19 +42,50 @@ archivesBaseName = "BiomesOPlenty" minecraft { version = config.minecraft_version + "-" + config.forge_version // grab latest forge - assetDir = "run/assets" - } // add some stuff to the version version = "${config.minecraft_version}-${config.mod_version}.${System.getenv().BUILD_NUMBER}" +dependencies { + compile project('Mixin') +} + jenkins { job = 'BiomesOPlenty' } +if (!minecraft.mappingsSet && minecraft.version.startsWith("1.8")) { + // Default mappings, normally if mappings are not specified then the plugin will set this + // default value internally, unfortunately this happens too late for the compile step below + // which needs the correct value to pass to the annotation processor. + minecraft.mappings = "snapshot_20141001" +} + +def mixinSrg = "${tasks.reobf.temporaryDir}" + File.separator + 'mixins.srg' +reobf.addExtraSrgFile mixinSrg + +// Source compiler configuration +tasks.withType(JavaCompile) { + options.compilerArgs += [ '-Xlint:all', '-Xlint:-path', '-Xlint:-processing', "-AreobfSrgFile=${tasks.reobf.srg}", "-AoutSrgFile=${mixinSrg}" ] + options.deprecation = true + options.encoding = 'utf8' +} + +jar { + from { project("Mixin").sourceSets.main.output } + + manifest { + attributes 'FMLCorePlugin': 'biomesoplenty.common.asm.BOPLoadingPlugin' + attributes 'FMLCorePluginContainsFMLMod': 'true' + attributes 'TweakClass': "org.spongepowered.asm.launch.MixinTweaker" + attributes 'TweakOrder': "10000" + } + + classifier = 'universal' +} + processResources { - // replace stuff in the files we want. from(sourceSets.main.resources.srcDirs) { include '**/*.info' include '**/*.properties' @@ -66,21 +99,12 @@ processResources { ]) } - // copy everything else, thats we didnt do before from(sourceSets.main.resources.srcDirs) { exclude '**/*.info' exclude '**/*.properties' } } -jar { - manifest { - //attributes 'FMLCorePlugin': 'biomesoplenty.asm.BOPLoadingPlugin' - //attributes 'FMLCorePluginContainsFMLMod': 'true' - } - classifier = 'universal' -} - import net.minecraftforge.gradle.tasks.dev.ChangelogTask import net.minecraftforge.gradle.common.Constants import net.minecraftforge.gradle.delayed.* diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 000000000..b2f31891b --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +include "Mixin" diff --git a/src/main/java/biomesoplenty/api/block/BOPBlock.java b/src/main/java/biomesoplenty/api/block/BOPBlock.java index c0f412e39..65dce4c9a 100644 --- a/src/main/java/biomesoplenty/api/block/BOPBlock.java +++ b/src/main/java/biomesoplenty/api/block/BOPBlock.java @@ -65,11 +65,21 @@ public abstract class BOPBlock extends Block return null; } + public IProperty[] getHiddenProperties() + { + return null; + } + public boolean hasPresetProperties() { return getPresetProperties() != null; } + public boolean hasHiddenProperties() + { + return getHiddenProperties() != null; + } + public String getStateName(IBlockState state, boolean fullName) { String unlocalizedName = state.getBlock().getUnlocalizedName(); diff --git a/src/main/java/biomesoplenty/common/asm/BOPLoadingPlugin.java b/src/main/java/biomesoplenty/common/asm/BOPLoadingPlugin.java new file mode 100644 index 000000000..53eb624ff --- /dev/null +++ b/src/main/java/biomesoplenty/common/asm/BOPLoadingPlugin.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright 2014, the Biomes O' Plenty Team + * + * This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License. + * + * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/. + ******************************************************************************/ + +package biomesoplenty.common.asm; + +import java.util.Map; + +import org.spongepowered.asm.launch.MixinBootstrap; +import org.spongepowered.asm.mixin.MixinEnvironment; + +import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin; +import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin.TransformerExclusions; + +@TransformerExclusions("biomesoplenty.common.asm") +public class BOPLoadingPlugin implements IFMLLoadingPlugin +{ + public BOPLoadingPlugin() + { + MixinBootstrap.init(); + MixinEnvironment.getCurrentEnvironment().addConfiguration("mixins.biomesoplenty.json"); + } + + @Override + public String[] getASMTransformerClass() + { + return new String[] { MixinBootstrap.TRANSFORMER_CLASS }; + } + + @Override + public String getModContainerClass() + { + return null; + } + + @Override + public String getSetupClass() + { + return null; + } + + @Override + public void injectData(Map data) {} + + @Override + public String getAccessTransformerClass() + { + return null; + } +} diff --git a/src/main/java/biomesoplenty/common/block/BlockCoral.java b/src/main/java/biomesoplenty/common/block/BlockCoral.java index ce0795de5..b200dea87 100644 --- a/src/main/java/biomesoplenty/common/block/BlockCoral.java +++ b/src/main/java/biomesoplenty/common/block/BlockCoral.java @@ -56,6 +56,12 @@ public class BlockCoral extends BOPPlant return new IProperty[] { VARIANT_PROP }; } + @Override + public IProperty[] getHiddenProperties() + { + return new IProperty[] { LEVEL }; + } + @Override public String getStateName(IBlockState state, boolean fullName) { diff --git a/src/main/java/biomesoplenty/common/handler/BlockModelRegisterEventHandler.java b/src/main/java/biomesoplenty/common/handler/BlockModelRegisterEventHandler.java index 8875bb4a3..09b17893d 100644 --- a/src/main/java/biomesoplenty/common/handler/BlockModelRegisterEventHandler.java +++ b/src/main/java/biomesoplenty/common/handler/BlockModelRegisterEventHandler.java @@ -8,6 +8,14 @@ package biomesoplenty.common.handler; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; + +import net.minecraft.block.Block; import net.minecraft.block.BlockLiquid; import net.minecraft.block.properties.IProperty; import net.minecraft.client.renderer.BlockModelShapes; @@ -18,11 +26,21 @@ import biomesoplenty.common.event.BlockModelRegisterEvent; public class BlockModelRegisterEventHandler { + private static Map> hiddenProperties = Maps.newHashMap(); + @SubscribeEvent public void onBlockModelRegister(BlockModelRegisterEvent event) { BlockModelShapes modelShapes = event.modelShapes; - modelShapes.func_178121_a(BOPBlocks.coral, (new StateMap.Builder()).func_178442_a(new IProperty[] {BlockLiquid.LEVEL}).build()); + for (Entry> entry : hiddenProperties.entrySet()) + { + modelShapes.func_178121_a(entry.getKey(), (new StateMap.Builder()).func_178442_a(entry.getValue().toArray(new IProperty[] {})).build()); + } + } + + public static void addHiddenProperties(Block block, IProperty... properties) + { + hiddenProperties.put(block, Sets.newHashSet(properties)); } } diff --git a/src/main/java/biomesoplenty/common/init/ModBlocks.java b/src/main/java/biomesoplenty/common/init/ModBlocks.java index 467a7e80b..922a42542 100644 --- a/src/main/java/biomesoplenty/common/init/ModBlocks.java +++ b/src/main/java/biomesoplenty/common/init/ModBlocks.java @@ -34,6 +34,7 @@ import biomesoplenty.common.block.BlockCoral; import biomesoplenty.common.block.BlockGem; import biomesoplenty.common.block.BlockGemOre; import biomesoplenty.common.block.BlockHive; +import biomesoplenty.common.handler.BlockModelRegisterEventHandler; import biomesoplenty.common.item.ItemBlockWithVariants; import biomesoplenty.common.util.block.BlockStateUtils; import biomesoplenty.core.BiomesOPlenty; @@ -86,6 +87,8 @@ public class ModBlocks BiomesOPlenty.proxy.registerBlockForMeshing(block, 0, name); } + if (block.hasHiddenProperties()) BlockModelRegisterEventHandler.addHiddenProperties(block, block.getHiddenProperties()); + return block; } } diff --git a/src/main/java/biomesoplenty/common/mixin/renderer/MixinBlockModelShapes.java b/src/main/java/biomesoplenty/common/mixin/renderer/MixinBlockModelShapes.java new file mode 100644 index 000000000..e6a4c2946 --- /dev/null +++ b/src/main/java/biomesoplenty/common/mixin/renderer/MixinBlockModelShapes.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright 2014, the Biomes O' Plenty Team + * + * This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License. + * + * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/. + ******************************************************************************/ + +package biomesoplenty.common.mixin.renderer; + +import net.minecraft.client.renderer.BlockModelShapes; +import net.minecraft.client.resources.model.ModelManager; +import net.minecraftforge.common.MinecraftForge; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import biomesoplenty.common.event.BlockModelRegisterEvent; + +@Mixin(BlockModelShapes.class) +public abstract class MixinBlockModelShapes +{ + @Inject(method = "", at = @At("RETURN")) + private void onConstructed(ModelManager modelManager, CallbackInfo callbackInfo) + { + Object obj = (Object)this; + + MinecraftForge.EVENT_BUS.post(new BlockModelRegisterEvent((BlockModelShapes)obj)); + } +} diff --git a/src/main/resources/mixins.biomesoplenty.json b/src/main/resources/mixins.biomesoplenty.json new file mode 100644 index 000000000..54c15f2b4 --- /dev/null +++ b/src/main/resources/mixins.biomesoplenty.json @@ -0,0 +1,6 @@ +{ + "package": "biomesoplenty.common.mixin", + "mixins": [ + "renderer.MixinBlockModelShapes" + ] +}