mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-20 04:09:40 +00:00
Partial fix for platform + smartmodels
This commit is contained in:
1 parent
972d0e5bf6
commit
c7d28c57de
3 files changed
+105
-4
No files matched your search
@@ -16,7 +16,9 @@ import net.minecraft.block.properties.PropertyBool;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.EnumDyeColor;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import vazkii.botania.api.item.IFloatingFlower;
|
||||
import vazkii.botania.api.state.enums.*;
|
||||
|
||||
@@ -36,6 +38,12 @@ public class BotaniaStateProps {
|
||||
// The property for platform held blockstate id
|
||||
public static final PropertyObject<IBlockState> HELD_STATE = new PropertyObject<>("held_state", IBlockState.class);
|
||||
|
||||
// The property for platform world object
|
||||
public static final PropertyObject<IBlockAccess> HELD_WORLD = new PropertyObject<>("held_world", IBlockAccess.class);
|
||||
|
||||
// The proeprty for platform world pos
|
||||
public static final PropertyObject<BlockPos> HELD_POS = new PropertyObject<>("held_pos", BlockPos.class);
|
||||
|
||||
/** Common properties to all blocks to use **/
|
||||
|
||||
// The 16 Minecraft colors
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -53,12 +53,15 @@ public class BlockPlatform extends BlockCamo implements ILexiconable, IWandable
|
||||
setUnlocalizedName(LibBlockNames.PLATFORM);
|
||||
setDefaultState(((IExtendedBlockState) blockState.getBaseState())
|
||||
.withProperty(BotaniaStateProps.HELD_STATE, null)
|
||||
.withProperty(BotaniaStateProps.HELD_WORLD, null)
|
||||
.withProperty(BotaniaStateProps.HELD_POS, null)
|
||||
.withProperty(BotaniaStateProps.PLATFORM_VARIANT, PlatformVariant.ABSTRUSE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState createBlockState() {
|
||||
return new ExtendedBlockState(this, new IProperty[] { BotaniaStateProps.PLATFORM_VARIANT, }, new IUnlistedProperty[] { BotaniaStateProps.HELD_STATE });
|
||||
return new ExtendedBlockState(this, new IProperty[] { BotaniaStateProps.PLATFORM_VARIANT, },
|
||||
new IUnlistedProperty[] { BotaniaStateProps.HELD_STATE, BotaniaStateProps.HELD_WORLD, BotaniaStateProps.HELD_POS });
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,11 +79,14 @@ public class BlockPlatform extends BlockCamo implements ILexiconable, IWandable
|
||||
|
||||
@Override
|
||||
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
|
||||
state = ((IExtendedBlockState) state).withProperty(BotaniaStateProps.HELD_WORLD, world)
|
||||
.withProperty(BotaniaStateProps.HELD_POS, 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);
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user