Added our own system for hiding block properties

This commit is contained in:
Adubbz 2015-01-11 19:33:37 +11:00
parent 549ce43f8b
commit 2756365320
10 changed files with 173 additions and 17 deletions

2
.gitignore vendored
View File

@ -1,5 +1,7 @@
/build/
/bin/
/Mixin/
/run/
/.gradle/
/.settings/
/.classpath

View File

@ -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.*

1
settings.gradle Normal file
View File

@ -0,0 +1 @@
include "Mixin"

View File

@ -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();

View File

@ -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<String, Object> data) {}
@Override
public String getAccessTransformerClass()
{
return null;
}
}

View File

@ -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)
{

View File

@ -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<Block, Set<IProperty>> 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<Block, Set<IProperty>> 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));
}
}

View File

@ -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;
}
}

View File

@ -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 = "<init>", at = @At("RETURN"))
private void onConstructed(ModelManager modelManager, CallbackInfo callbackInfo)
{
Object obj = (Object)this;
MinecraftForge.EVENT_BUS.post(new BlockModelRegisterEvent((BlockModelShapes)obj));
}
}

View File

@ -0,0 +1,6 @@
{
"package": "biomesoplenty.common.mixin",
"mixins": [
"renderer.MixinBlockModelShapes"
]
}