Partial fix for platform + smartmodels

This commit is contained in:
Vincent Lee committed 2016-02-08 13:03:38 -06:00
1 parent 972d0e5bf6
commit c7d28c57de
3 files changed
+105 -4

No files matched your search

@@ -16,13 +16,20 @@ 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.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumWorldBlockLayer;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.WorldType;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.client.model.ISmartBlockModel;
import net.minecraftforge.common.property.IExtendedBlockState;
import vazkii.botania.api.state.BotaniaStateProps;
import vazkii.botania.common.block.BlockCamo;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.block.tile.TileCamo;
import java.util.List;
@@ -35,6 +42,12 @@ public class PlatformModel implements ISmartBlockModel {
EnumWorldBlockLayer layer = MinecraftForgeClient.getRenderLayer();
IBlockState heldState = ((IExtendedBlockState) state).getValue(BotaniaStateProps.HELD_STATE);
IBlockAccess heldWorld = ((IExtendedBlockState) state).getValue(BotaniaStateProps.HELD_WORLD);
BlockPos heldPos = ((IExtendedBlockState) state).getValue(BotaniaStateProps.HELD_POS);
if (heldWorld == null || heldPos == null) {
return this;
}
Minecraft mc = Minecraft.getMinecraft();
if(heldState == null && layer == EnumWorldBlockLayer.SOLID) {
@@ -43,12 +56,15 @@ public class PlatformModel implements ISmartBlockModel {
return mc.getBlockRendererDispatcher().getBlockModelShapes().getModelManager().getModel(path);
} else if(heldState != null) {
if(heldState.getBlock().canRenderInLayer(layer)) {
IBlockState actual = heldState.getBlock().getActualState(heldState, new FakeBlockAccess(heldWorld), heldPos);
// Steal camo's model
IBakedModel model = mc.getBlockRendererDispatcher().getBlockModelShapes().getModelForState(heldState);
IBakedModel model = mc.getBlockRendererDispatcher().getBlockModelShapes().getModelForState(actual);
if(model instanceof ISmartBlockModel) {
// Their model can be smart too
model = ((ISmartBlockModel) model).handleBlockState(heldState);
IBlockState extended = heldState.getBlock().getExtendedState(actual, new FakeBlockAccess(heldWorld), heldPos);
model = ((ISmartBlockModel) model).handleBlockState(extended);
}
return model;
@@ -93,4 +109,75 @@ public class PlatformModel implements ISmartBlockModel {
return ItemCameraTransforms.DEFAULT;
}
private static class FakeBlockAccess implements IBlockAccess {
private final IBlockAccess compose;
private FakeBlockAccess(IBlockAccess compose) {
this.compose = compose;
}
@Override
public TileEntity getTileEntity(BlockPos pos) {
/* todo is this actually needed? if so this can't be an iblockaccess anymore
IBlockState state = getBlockState(pos);
if(state == null || !state.getBlock().hasTileEntity(state))
return null;
TileEntity tile = state.getBlock().createTileEntity(this, state);
if(tile == null)
return null;
tile.setWorldObj(this);
tile.setPos(pos);
return tile;*/
return compose.getTileEntity(pos);
}
@Override
public int getCombinedLight(BlockPos pos, int lightValue) {
return 15 << 20 | 15 << 4;
}
@Override
public IBlockState getBlockState(BlockPos pos) {
IBlockState state = compose.getBlockState(pos);
if(state.getBlock() instanceof BlockCamo) {
state = ((TileCamo) compose.getTileEntity(pos)).camoState;
}
return state;
}
@Override
public boolean isAirBlock(BlockPos pos) {
return compose.isAirBlock(pos);
}
@Override
public BiomeGenBase getBiomeGenForCoords(BlockPos pos) {
return compose.getBiomeGenForCoords(pos);
}
@Override
public boolean extendedLevelsInChunkCache() {
return compose.extendedLevelsInChunkCache();
}
@Override
public int getStrongPower(BlockPos pos, EnumFacing direction) {
return compose.getStrongPower(pos, direction);
}
@Override
public WorldType getWorldType() {
return compose.getWorldType();
}
@Override
public boolean isSideSolid(BlockPos pos, EnumFacing side, boolean _default) {
return compose.isSideSolid(pos, side, _default);
}
}
}