Full platform models. Fix bore lens crash and add copyleft headers to some things

This commit is contained in:
Vincent Lee committed 2016-01-08 18:47:31 -06:00
1 parent 84d0c75605
commit b4df8ce418
13 files changed
+196 -50

No files matched your search

@@ -25,10 +25,14 @@ import vazkii.botania.api.state.enums.*;
*/
public class BotaniaStateProps {
/** The property for specialFlower **/
/** Unlisted properties **/
// The property for specialFlower subtile id
public static final PropertyString SUBTILE_ID = new PropertyString("subtile_id");
// The property for platform held blockstate id
public static final PropertyState HELD_STATE = new PropertyState("held_state");
/** Common properties to all blocks to use **/
// The 16 Minecraft colors
@@ -0,0 +1,43 @@
/**
* This class was created by <williewillus>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*/
package vazkii.botania.api.state;
import net.minecraft.block.state.IBlockState;
import net.minecraftforge.common.property.IUnlistedProperty;
// An unlisted property that holds an IBlockState. Used for platform rendering
public class PropertyState implements IUnlistedProperty<IBlockState> {
private final String name;
public PropertyState(String name) {
this.name = name;
}
@Override
public String getName() {
return name;
}
@Override
public boolean isValid(IBlockState value) {
return true;
}
@Override
public Class<IBlockState> getType() {
return IBlockState.class;
}
@Override
public String valueToString(IBlockState value) {
return value.toString();
}
}
@@ -10,6 +10,7 @@ package vazkii.botania.api.state;
import net.minecraftforge.common.property.IUnlistedProperty;
// An unlisted property that holds a String, used for subtile rendering
public class PropertyString implements IUnlistedProperty<String> {
private final String name;
@@ -38,6 +38,7 @@ import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.client.model.obj.OBJLoader;
import net.minecraftforge.fml.common.registry.GameData;
import vazkii.botania.api.BotaniaAPIClient;
import vazkii.botania.api.state.enums.PlatformVariant;
import vazkii.botania.client.render.SpecialFlowerModel;
import vazkii.botania.api.state.BotaniaStateProps;
import vazkii.botania.api.state.enums.AltGrassVariant;
@@ -446,6 +447,7 @@ public final class ModelHandler {
registerVariantsDefaulted(ModBlocks.openCrate, CrateVariant.class, "variant");
registerVariantsDefaulted(ModBlocks.customBrick, CustomBrickVariant.class, "variant");
registerVariantsDefaulted(ModBlocks.prismarine, PrismarineVariant.class, "variant");
registerVariantsDefaulted(ModBlocks.platform, PlatformVariant.class, "variant");
}
private static void registerStandardItems() {
@@ -697,7 +699,7 @@ public final class ModelHandler {
}
private static void registerStateMappers() {
// Override for floating flowers
// Override to let smartmodels work, see RenderEventHandler
ModelLoader.setCustomStateMapper(ModBlocks.floatingSpecialFlower, new StateMapperBase() {
@Override
protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
@@ -712,23 +714,28 @@ public final class ModelHandler {
}
});
ModelLoader.setCustomStateMapper(ModBlocks.platform, new StateMapperBase() {
@Override
protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
return new ModelResourceLocation("botania:platform", "normal");
}
});
// Ignore vanilla facing, variant in double flower
ModelLoader.setCustomStateMapper(ModBlocks.doubleFlower1, (new StateMap.Builder()).ignore(BlockDoublePlant.VARIANT, BlockDoublePlant.field_181084_N).build());
ModelLoader.setCustomStateMapper(ModBlocks.doubleFlower2, (new StateMap.Builder()).ignore(BlockDoublePlant.VARIANT, BlockDoublePlant.field_181084_N).build());
// Ignore color in unstable cube, mana beacon, and petals (handled by color multiplier)
// Ignore color in unstable cube, mana beacon, special flower, and petals (handled by color multiplier)
ModelLoader.setCustomStateMapper(ModBlocks.unstableBlock, (new StateMap.Builder()).ignore(BotaniaStateProps.COLOR).build());
ModelLoader.setCustomStateMapper(ModBlocks.manaBeacon, (new StateMap.Builder()).ignore(BotaniaStateProps.COLOR).build());
ModelLoader.setCustomStateMapper(ModBlocks.petalBlock, (new StateMap.Builder()).ignore(BotaniaStateProps.COLOR).build());
ModelLoader.setCustomStateMapper(ModBlocks.specialFlower, (new StateMap.Builder()).ignore(BotaniaStateProps.COLOR, ((BlockFlower) ModBlocks.specialFlower).getTypeProperty()).build());
// Ignore vanilla variant in flowers
ModelLoader.setCustomStateMapper(ModBlocks.flower, (new StateMap.Builder()).ignore(((BlockFlower) ModBlocks.flower).getTypeProperty()).build());
ModelLoader.setCustomStateMapper(ModBlocks.shinyFlower, (new StateMap.Builder()).ignore(((BlockFlower) ModBlocks.shinyFlower).getTypeProperty()).build());
ModelLoader.setCustomStateMapper(ModBlocks.buriedPetals, (new StateMap.Builder()).ignore(((BlockFlower) ModBlocks.buriedPetals).getTypeProperty()).build());
// Ignore in special flower to suppress errors (handled in custom statemapper in BlockSpecialFlower
ModelLoader.setCustomStateMapper(ModBlocks.specialFlower, (new StateMap.Builder()).ignore(BotaniaStateProps.COLOR, ((BlockFlower) ModBlocks.specialFlower).getTypeProperty()).build());
// Ignore vanilla variant in walls
ModelLoader.setCustomStateMapper(ModFluffBlocks.biomeStoneWall, (new StateMap.Builder()).ignore(BlockWall.VARIANT).build());
ModelLoader.setCustomStateMapper(ModFluffBlocks.dreamwoodWall, (new StateMap.Builder()).ignore(BlockWall.VARIANT).build());
@@ -9,8 +9,10 @@ import net.minecraftforge.client.event.ModelBakeEvent;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.apache.commons.lang3.text.WordUtils;
import vazkii.botania.api.state.enums.PlatformVariant;
import vazkii.botania.client.core.helper.IconHelper;
import vazkii.botania.client.model.FloatingFlowerModel;
import vazkii.botania.client.model.PlatformModel;
import vazkii.botania.client.model.PylonItemModel;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.integration.buildcraft.TriggerManaLevel;
@@ -43,7 +45,7 @@ public class RenderEventHandler {
public TextureAtlasSprite[] kingKeyWeaponIcons;
public Map<TriggerManaLevel.State, TextureAtlasSprite> manaLevelTriggerIcons = Maps.newEnumMap(TriggerManaLevel.State.class);
// begin dank_memes todo 1.8 if I can figure out how to render arbitrary baked models then these will no longer be needed
// begin dank_memes
public TextureAtlasSprite tailIcon = null;
public TextureAtlasSprite phiFlowerIcon = null;
public TextureAtlasSprite goldfishIcon = null;
@@ -69,6 +71,9 @@ public class RenderEventHandler {
// Pylon item model
evt.modelRegistry.putObject(new ModelResourceLocation("botania:pylon", "inventory"), new PylonItemModel());
// Platforms
evt.modelRegistry.putObject(new ModelResourceLocation("botania:platform", "normal"), new PlatformModel());
}
@SubscribeEvent
@@ -0,0 +1,58 @@
/**
* This class was created by <williewillus>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*/
package vazkii.botania.client.model;
import com.google.common.collect.ImmutableList;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.IBakedModel;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumWorldBlockLayer;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.client.model.ISmartBlockModel;
import net.minecraftforge.common.property.IExtendedBlockState;
import vazkii.botania.api.state.BotaniaStateProps;
import java.util.List;
public class PlatformModel implements ISmartBlockModel {
@Override
public IBakedModel handleBlockState(IBlockState state) {
EnumWorldBlockLayer layer = MinecraftForgeClient.getRenderLayer();
IBlockState heldState = ((IExtendedBlockState) state).getValue(BotaniaStateProps.HELD_STATE);
Minecraft mc = Minecraft.getMinecraft();
if (heldState == null && layer == EnumWorldBlockLayer.SOLID) {
// No camo
ModelResourceLocation path = new ModelResourceLocation("botania:platform", "variant=" + state.getValue(BotaniaStateProps.PLATFORM_VARIANT).getName());
return mc.getBlockRendererDispatcher().getBlockModelShapes().getModelManager().getModel(path);
} else if (heldState != null){
if (heldState.getBlock().canRenderInLayer(layer)) {
// Steal camo's model
return mc.getBlockRendererDispatcher().getBlockModelShapes().getModelForState(heldState);
}
}
return this; // This smart model has no quads as seen below, so nothing actually renders
}
@Override public List<BakedQuad> getFaceQuads(EnumFacing p_177551_1_) { return ImmutableList.of(); }
@Override public List<BakedQuad> getGeneralQuads() { return ImmutableList.of(); }
@Override public boolean isAmbientOcclusion() { return true; }
@Override public boolean isGui3d() { return true;}
@Override public boolean isBuiltInRenderer() { return false; }
@Override public TextureAtlasSprite getParticleTexture() { return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite("botania:blocks/livingwood0"); }
@Override public ItemCameraTransforms getItemCameraTransforms() { return ItemCameraTransforms.DEFAULT; }
}
@@ -1,3 +1,11 @@
/**
* This class was created by <williewillus>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*/
package vazkii.botania.client.model;
import com.google.common.base.Function;
@@ -31,18 +31,12 @@ import net.minecraftforge.fml.relauncher.SideOnly;
public abstract class BlockCamo extends BlockModContainer<TileCamo> {
static List<Integer> validRenderTypes = Arrays.asList(0, 31, 39);
protected BlockCamo(Material par2Material) {
super(par2Material);
}
public static boolean isValidBlock(Block block) {
return block.isOpaqueCube() || isValidRenderType(block.getRenderType());
}
public static boolean isValidRenderType(int type) {
return validRenderTypes.contains(type);
return block.isOpaqueCube() || block.getRenderType() == 3;
}
@Override
@@ -72,28 +66,13 @@ public abstract class BlockCamo extends BlockModContainer<TileCamo> {
}
if(doChange && currentStack.getItem() != null) {
int metadata = currentStack.getItemDamage();
IBlockState changeState = Block.getBlockFromItem(currentStack.getItem()).getStateFromMeta(currentStack.getItemDamage());
if(block instanceof BlockDirectional) {
switch (par6) {
case DOWN:
case UP:
break;
case NORTH:
metadata = metadata & 12 | 2;
break;
case SOUTH:
metadata = metadata & 12;
break;
case WEST:
metadata = metadata & 12 | 1;
break;
case EAST:
metadata = metadata & 12 | 3;
break;
if (BlockDirectional.FACING.getAllowedValues().contains(par6.getOpposite())) {
changeState = changeState.withProperty(BlockDirectional.FACING, par6.getOpposite());
}
}
camo.camo = Block.getBlockFromItem(currentStack.getItem());
camo.camoMeta = metadata;
camo.camoState = changeState;
par1World.markBlockForUpdate(pos);
return true;
@@ -119,9 +98,9 @@ public abstract class BlockCamo extends BlockModContainer<TileCamo> {
TileEntity tile = par1World.getTileEntity(pos);
if(tile instanceof TileCamo) {
TileCamo camo = (TileCamo) tile;
Block block = camo.camo;
if(block != null)
return block instanceof BlockCamo ? 0xFFFFFF : block.getRenderColor(block.getDefaultState()); // todo
IBlockState state = camo.camoState;
if(state != null)
return state.getBlock() instanceof BlockCamo ? 0xFFFFFF : state.getBlock().getRenderColor(state);
}
return 0xFFFFFF;
}
@@ -14,6 +14,7 @@ import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
@@ -24,7 +25,12 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumWorldBlockLayer;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.property.ExtendedBlockState;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.common.property.IUnlistedProperty;
import vazkii.botania.api.lexicon.ILexiconable;
import vazkii.botania.api.lexicon.LexiconEntry;
import vazkii.botania.api.state.BotaniaStateProps;
@@ -47,12 +53,14 @@ public class BlockPlatform extends BlockCamo implements ILexiconable, IWandable
setResistance(5.0F);
setStepSound(Block.soundTypeWood);
setUnlocalizedName(LibBlockNames.PLATFORM);
setDefaultState(blockState.getBaseState().withProperty(BotaniaStateProps.PLATFORM_VARIANT, PlatformVariant.ABSTRUSE));
setDefaultState(((IExtendedBlockState) blockState.getBaseState())
.withProperty(BotaniaStateProps.HELD_STATE, null)
.withProperty(BotaniaStateProps.PLATFORM_VARIANT, PlatformVariant.ABSTRUSE));
}
@Override
public BlockState createBlockState() {
return new BlockState(this, BotaniaStateProps.PLATFORM_VARIANT);
return new ExtendedBlockState(this, new IProperty[] { BotaniaStateProps.PLATFORM_VARIANT, }, new IUnlistedProperty[] { BotaniaStateProps.HELD_STATE });
}
@Override
@@ -68,6 +76,21 @@ public class BlockPlatform extends BlockCamo implements ILexiconable, IWandable
return getDefaultState().withProperty(BotaniaStateProps.PLATFORM_VARIANT, PlatformVariant.values()[meta]);
}
@Override
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
if (world.getTileEntity(pos) instanceof TileCamo) {
TileCamo tile = ((TileCamo) world.getTileEntity(pos));
return ((IExtendedBlockState) state).withProperty(BotaniaStateProps.HELD_STATE, tile.camoState);
} else {
return ((IExtendedBlockState) state);
}
}
@Override
public boolean canRenderInLayer(EnumWorldBlockLayer layer) {
return true;
}
@Override
protected boolean shouldRegisterInNameSet() {
return false;
@@ -93,7 +116,7 @@ public class BlockPlatform extends BlockCamo implements ILexiconable, IWandable
@Override
public void addCollisionBoxesToList(World par1World, BlockPos pos, IBlockState state, AxisAlignedBB par5AxisAlignedBB, List par6List, Entity par7Entity) {
PlatformVariant variant = state.getValue(BotaniaStateProps.PLATFORM_VARIANT);
if(variant == PlatformVariant.INFRANGIBLE || variant == PlatformVariant.ABSTRUSE && par7Entity != null && par7Entity.posY > pos.getY() + (par7Entity instanceof EntityPlayer ? 2 : 0) && (!(par7Entity instanceof EntityPlayer) || !par7Entity.isSneaking()))
if(variant == PlatformVariant.INFRANGIBLE || variant == PlatformVariant.ABSTRUSE && par7Entity != null && par7Entity.posY > pos.getY() + 0.9 && (!(par7Entity instanceof EntityPlayer) || !par7Entity.isSneaking()))
super.addCollisionBoxesToList(par1World, pos, state, par5AxisAlignedBB, par6List, par7Entity);
}
@@ -12,6 +12,7 @@ package vazkii.botania.common.block.tile;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
@@ -21,21 +22,22 @@ public class TileCamo extends TileMod {
private static final String TAG_CAMO = "camo";
private static final String TAG_CAMO_META = "camoMeta";
public Block camo;
public int camoMeta;
public IBlockState camoState;
@Override
public void writeCustomNBT(NBTTagCompound cmp) {
if(camo != null) {
cmp.setString(TAG_CAMO, Block.blockRegistry.getNameForObject(camo).toString());
cmp.setInteger(TAG_CAMO_META, camoMeta);
if(camoState != null) {
cmp.setString(TAG_CAMO, Block.blockRegistry.getNameForObject(camoState.getBlock()).toString());
cmp.setInteger(TAG_CAMO_META, camoState.getBlock().getMetaFromState(camoState));
}
}
@Override
public void readCustomNBT(NBTTagCompound cmp) {
camo = Block.getBlockFromName(cmp.getString(TAG_CAMO));
camoMeta = cmp.getInteger(TAG_CAMO_META);
Block b = Block.getBlockFromName(cmp.getString(TAG_CAMO));
if (b != null) {
camoState = b.getStateFromMeta(cmp.getInteger(TAG_CAMO_META));
}
}
@Override
@@ -25,7 +25,7 @@ public class TilePlatform extends TileCamo implements IManaCollisionGhost {
public boolean onWanded(EntityPlayer player) {
if(player != null) {
if(camo == null || player.isSneaking())
if(camoState == null || player.isSneaking())
swapSelfAndPass(this, true);
else swapSurroudings(this, false);
return true;
@@ -45,15 +45,14 @@ public class TilePlatform extends TileCamo implements IManaCollisionGhost {
TileEntity tileAt = worldObj.getTileEntity(pos);
if(tileAt != null && tileAt instanceof TilePlatform) {
TilePlatform platform = (TilePlatform) tileAt;
if(empty ? platform.camo != null : platform.camo == null)
if(empty ? platform.camoState != null : platform.camoState == null)
swapSelfAndPass(platform, empty);
}
}
}
void swap(TilePlatform tile, boolean empty) {
tile.camo = empty ? null : camo;
tile.camoMeta = empty ? 0 : camoMeta;
tile.camoState = empty ? null : camoState;
worldObj.markBlockForUpdate(tile.getPos());
}
@@ -36,6 +36,9 @@ public class LensMine extends Lens {
World world = entity.worldObj;
BlockPos pos_ = pos.getBlockPos();
if (pos_ == null)
return false;
Block block = world.getBlockState(pos_).getBlock();
ItemStack composite = ((ItemLens) ModItems.lens).getCompositeLens(stack);