mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-17 10:55:17 +00:00
Prepwork to restore floating flower rendering in the static case
This commit is contained in:
1 parent
1ff8cf6fe2
commit
eadfa10e82
11 files changed
+143
-226
No files matched your search
@@ -24,26 +24,27 @@ import java.util.Map;
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public final class BotaniaAPIClient {
|
||||
|
||||
private static final Map<IFloatingFlower.IslandType, ModelResourceLocation> islandTypeModels = Maps.newHashMap();
|
||||
private static final Map<IFloatingFlower.IslandType, ResourceLocation> islandTypeModels = Maps.newHashMap();
|
||||
|
||||
private BotaniaAPIClient() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers your model for island type islandType here.
|
||||
* Call this during {@code ModelRegistryEvent}.
|
||||
* Call this during {@link net.minecraftforge.client.event.ModelRegistryEvent}.
|
||||
*
|
||||
* @param islandType The islandtype to register
|
||||
* @param model The variant within a blockstate json to use as the islandtype's model
|
||||
* @param model The model, may be {@link ResourceLocation} to point directly into the models folder or
|
||||
* {@link ModelResourceLocation} to go through the blockstate jsons.
|
||||
*/
|
||||
public static void registerIslandTypeModel(IFloatingFlower.IslandType islandType, ModelResourceLocation model) {
|
||||
public static void registerIslandTypeModel(IFloatingFlower.IslandType islandType, ResourceLocation model) {
|
||||
islandTypeModels.put(islandType, model);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return An immutable and live view of the registered island type model map
|
||||
*/
|
||||
public static Map<IFloatingFlower.IslandType, ModelResourceLocation> getRegisteredIslandTypeModels() {
|
||||
public static Map<IFloatingFlower.IslandType, ResourceLocation> getRegisteredIslandTypeModels() {
|
||||
return Collections.unmodifiableMap(islandTypeModels);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,12 +17,10 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.event.ModelBakeEvent;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import vazkii.botania.client.model.FloatingFlowerModel;
|
||||
import vazkii.botania.client.model.GunModel;
|
||||
import vazkii.botania.client.model.LexiconModel;
|
||||
import vazkii.botania.client.model.PlatformModel;
|
||||
import vazkii.botania.client.render.tile.RenderTileCorporeaCrystalCube;
|
||||
import vazkii.botania.common.Botania;
|
||||
import vazkii.botania.common.item.equipment.bauble.ItemFlightTiara;
|
||||
import vazkii.botania.common.item.relic.ItemKingKey;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
@@ -79,13 +77,6 @@ public class MiscellaneousIcons {
|
||||
|
||||
@SubscribeEvent
|
||||
public void onModelBake(ModelBakeEvent evt) {
|
||||
// Floating flowers
|
||||
FloatingFlowerModel model = new FloatingFlowerModel(evt.getModelLoader());
|
||||
evt.getModelRegistry().put(new ModelResourceLocation("botania:mini_island", "normal"), model);
|
||||
evt.getModelRegistry().put(new ModelResourceLocation("botania:mini_island", "inventory"), model);
|
||||
evt.getModelRegistry().put(new ModelResourceLocation("botania:floating_special_flower", "normal"), model);
|
||||
evt.getModelRegistry().put(new ModelResourceLocation("botania:floating_special_flower", "inventory"), model);
|
||||
|
||||
// Platforms
|
||||
ModelResourceLocation abstruseName = new ModelResourceLocation("botania:abstruse_platform", "");
|
||||
IBakedModel abstruse = evt.getModelRegistry().get(abstruseName);
|
||||
|
||||
@@ -10,12 +10,11 @@ package vazkii.botania.client.core.handler;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.entity.SpriteRenderer;
|
||||
import net.minecraft.client.renderer.entity.SpriteRenderer;
|
||||
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.event.ModelRegistryEvent;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.client.model.animation.TileEntityRendererAnimation;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
@@ -25,6 +24,7 @@ import net.minecraftforge.api.distmarker.Dist;
|
||||
import vazkii.botania.api.BotaniaAPIClient;
|
||||
import vazkii.botania.api.item.IFloatingFlower;
|
||||
import vazkii.botania.api.lexicon.multiblock.IMultiblockRenderHook;
|
||||
import vazkii.botania.client.model.FloatingFlowerModel;
|
||||
import vazkii.botania.client.render.entity.RenderBabylonWeapon;
|
||||
import vazkii.botania.client.render.entity.RenderCorporeaSpark;
|
||||
import vazkii.botania.client.render.entity.RenderDoppleganger;
|
||||
@@ -55,13 +55,15 @@ import vazkii.botania.common.entity.EntityPoolMinecart;
|
||||
import vazkii.botania.common.entity.EntitySpark;
|
||||
import vazkii.botania.common.entity.EntityThornChakram;
|
||||
import vazkii.botania.common.entity.EntityVineBall;
|
||||
import vazkii.botania.common.item.ModItems;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
|
||||
import static vazkii.botania.common.lib.ResourceLocationHelper.prefix;
|
||||
|
||||
@Mod.EventBusSubscriber(value = Dist.CLIENT, modid = LibMisc.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public final class ModelHandler {
|
||||
@SubscribeEvent
|
||||
public static void registerModels(ModelRegistryEvent evt) {
|
||||
ModelLoaderRegistry.registerLoader(FloatingFlowerModel.Loader.INSTANCE);
|
||||
ModelLoader.addSpecialModel(new ModelResourceLocation(LibMisc.MOD_ID + ":mana_gun_clip", "inventory"));
|
||||
ModelLoader.addSpecialModel(new ModelResourceLocation(LibMisc.MOD_ID + ":desu_gun", "inventory"));
|
||||
ModelLoader.addSpecialModel(new ModelResourceLocation(LibMisc.MOD_ID + ":desu_gun_clip", "inventory"));
|
||||
@@ -117,16 +119,16 @@ public final class ModelHandler {
|
||||
}
|
||||
|
||||
private static void registerSubtiles() {
|
||||
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.GRASS, new ModelResourceLocation("botania:mini_island", "variant=grass"));
|
||||
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.PODZOL, new ModelResourceLocation("botania:mini_island", "variant=podzol"));
|
||||
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.MYCEL, new ModelResourceLocation("botania:mini_island", "variant=mycel"));
|
||||
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.SNOW, new ModelResourceLocation("botania:mini_island", "variant=snow"));
|
||||
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.DRY, new ModelResourceLocation("botania:mini_island", "variant=dry"));
|
||||
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.GOLDEN, new ModelResourceLocation("botania:mini_island", "variant=golden"));
|
||||
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.VIVID, new ModelResourceLocation("botania:mini_island", "variant=vivid"));
|
||||
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.SCORCHED, new ModelResourceLocation("botania:mini_island", "variant=scorched"));
|
||||
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.INFUSED, new ModelResourceLocation("botania:mini_island", "variant=infused"));
|
||||
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.MUTATED, new ModelResourceLocation("botania:mini_island", "variant=mutated"));
|
||||
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.GRASS, prefix("block/islands/island_grass"));
|
||||
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.PODZOL, prefix("block/islands/island_podzol"));
|
||||
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.MYCEL, prefix("block/islands/island_mycel"));
|
||||
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.SNOW, prefix("block/islands/island_snow"));
|
||||
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.DRY, prefix("block/islands/island_dry"));
|
||||
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.GOLDEN, prefix("block/islands/island_golden"));
|
||||
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.VIVID, prefix("block/islands/island_vivid"));
|
||||
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.SCORCHED, prefix("block/islands/island_scorched"));
|
||||
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.INFUSED, prefix("block/islands/island_infused"));
|
||||
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.MUTATED, prefix("block/islands/island_mutated"));
|
||||
}
|
||||
|
||||
private ModelHandler() {}
|
||||
|
||||
@@ -1,219 +1,142 @@
|
||||
/**
|
||||
* 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
|
||||
* <p/>
|
||||
* 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.HashBasedTable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Table;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.model.ItemCameraTransforms;
|
||||
import net.minecraft.client.renderer.model.ItemOverrideList;
|
||||
import net.minecraft.client.renderer.model.IUnbakedModel;
|
||||
import net.minecraft.client.renderer.model.ModelBakery;
|
||||
import net.minecraft.client.renderer.model.ModelManager;
|
||||
import net.minecraft.client.renderer.texture.ISprite;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.resources.IResourceManager;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.model.BakedModelWrapper;
|
||||
import net.minecraftforge.client.model.BasicState;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.client.model.ICustomModelLoader;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.client.model.data.IDynamicBakedModel;
|
||||
import net.minecraftforge.client.model.ModelStateComposition;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
import net.minecraftforge.client.model.pipeline.IVertexConsumer;
|
||||
import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
|
||||
import net.minecraftforge.client.model.pipeline.VertexTransformer;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import vazkii.botania.api.BotaniaAPIClient;
|
||||
import vazkii.botania.api.item.IFloatingFlower;
|
||||
import vazkii.botania.api.state.BotaniaStateProps;
|
||||
import vazkii.botania.common.Botania;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
import vazkii.botania.common.block.decor.BlockFloatingFlower;
|
||||
import vazkii.botania.common.lib.LibBlockNames;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.vecmath.Matrix4f;
|
||||
import javax.vecmath.Vector3f;
|
||||
import javax.vecmath.Vector4f;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class FloatingFlowerModel implements IDynamicBakedModel {
|
||||
private final ModelBakery bakery;
|
||||
private final Table<IFloatingFlower.IslandType, ResourceLocation, CompositeBakedModel> CACHE = HashBasedTable.create();
|
||||
public class FloatingFlowerModel implements IUnbakedModel {
|
||||
private static final FloatingFlowerModel INIT = new FloatingFlowerModel(null);
|
||||
|
||||
public FloatingFlowerModel(ModelBakery bakery) {
|
||||
this.bakery = bakery;
|
||||
}
|
||||
@Nullable
|
||||
private final ResourceLocation flower;
|
||||
|
||||
protected static BakedQuad transform(BakedQuad quad, final TRSRTransformation transform) {
|
||||
UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(DefaultVertexFormats.ITEM);
|
||||
final IVertexConsumer consumer = new VertexTransformer(builder) {
|
||||
@Override
|
||||
public void put(int element, float... data) {
|
||||
VertexFormatElement formatElement = DefaultVertexFormats.ITEM.getElement(element);
|
||||
switch(formatElement.getUsage()) {
|
||||
case POSITION: {
|
||||
float[] newData = new float[4];
|
||||
Vector4f vec = new Vector4f(data);
|
||||
transform.getMatrixVec().transform(vec);
|
||||
vec.get(newData);
|
||||
parent.put(element, newData);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
parent.put(element, data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
quad.pipe(consumer);
|
||||
return builder.build();
|
||||
}
|
||||
@Nullable
|
||||
private IUnbakedModel unbakedFlower = null;
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(BlockState state, Direction face, @Nonnull Random rand, @Nonnull IModelData data) {
|
||||
if(!data.hasProperty(BotaniaStateProps.FLOATING_DATA))
|
||||
return Minecraft.getInstance().getBlockRendererDispatcher().getBlockModelShapes().getModelManager().getMissingModel().getQuads(state, face, rand, data);
|
||||
IFloatingFlower floatingData = data.getData(BotaniaStateProps.FLOATING_DATA);
|
||||
return getModel(floatingData.getIslandType(), floatingData.getDisplayStack()).getQuads(state, face, rand);
|
||||
}
|
||||
private final Map<IFloatingFlower.IslandType, IUnbakedModel> unbakedIslands = new HashMap<>();
|
||||
|
||||
// Get the model for this islandtype + flower type combination. If it's not cached already, generate it.
|
||||
private CompositeBakedModel getModel(IFloatingFlower.IslandType islandType, ItemStack flower) {
|
||||
ModelManager modelManager = Minecraft.getInstance().getItemRenderer().getItemModelMesher().getModelManager();
|
||||
private FloatingFlowerModel(@Nullable ResourceLocation flower) {
|
||||
this.flower = flower;
|
||||
if (flower != null)
|
||||
this.unbakedFlower = ModelLoaderRegistry.getModelOrMissing(flower);
|
||||
for (Map.Entry<IFloatingFlower.IslandType, ResourceLocation> e : BotaniaAPIClient.getRegisteredIslandTypeModels().entrySet()) {
|
||||
IUnbakedModel unbakedIsland = ModelLoaderRegistry.getModelOrMissing(e.getValue());
|
||||
unbakedIslands.put(e.getKey(), unbakedIsland);
|
||||
}
|
||||
}
|
||||
|
||||
if(islandType == null) // This and the next one can be null if obtained from a non-extended state
|
||||
islandType = IFloatingFlower.IslandType.GRASS;
|
||||
@Nonnull
|
||||
@Override
|
||||
public Collection<ResourceLocation> getDependencies() {
|
||||
List<ResourceLocation> ret = new ArrayList<>(BotaniaAPIClient.getRegisteredIslandTypeModels().values());
|
||||
if (flower != null)
|
||||
ret.add(flower);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if(CACHE.contains(islandType, flower.getItem().getRegistryName())) {
|
||||
return CACHE.get(islandType, flower.getItem().getRegistryName());
|
||||
} else {
|
||||
IBakedModel islandModel;
|
||||
try {
|
||||
islandModel = ModelLoaderRegistry.getModel(BotaniaAPIClient.getRegisteredIslandTypeModels().get(islandType))
|
||||
.bake(bakery, ModelLoader.defaultTextureGetter(),
|
||||
new BasicState(TRSRTransformation.identity(), false), DefaultVertexFormats.ITEM);
|
||||
} catch (Exception e) {
|
||||
islandModel = modelManager.getMissingModel();
|
||||
}
|
||||
@Nonnull
|
||||
@Override
|
||||
public Collection<ResourceLocation> getTextures(@Nonnull Function<ResourceLocation, IUnbakedModel> modelGetter, @Nonnull Set<String> missingTextureErrors) {
|
||||
Set<ResourceLocation> ret = new HashSet<>();
|
||||
for (IUnbakedModel island : unbakedIslands.values()) {
|
||||
ret.addAll(island.getTextures(modelGetter, missingTextureErrors));
|
||||
}
|
||||
ret.addAll(unbakedFlower.getTextures(modelGetter, missingTextureErrors));
|
||||
return ret;
|
||||
}
|
||||
|
||||
IBakedModel flowerModel = Minecraft.getInstance().getItemRenderer().getItemModelMesher().getItemModel(flower);
|
||||
@Nonnull
|
||||
@Override
|
||||
public IUnbakedModel process(ImmutableMap<String, String> customData) {
|
||||
// Forge is big dumb and passes this in *with the quote markers*...
|
||||
String flowerPath = customData.get("flower");
|
||||
return new FloatingFlowerModel(new ResourceLocation(flowerPath.substring(1, flowerPath.length() - 1)));
|
||||
}
|
||||
|
||||
// Enhance!
|
||||
CompositeBakedModel model = new CompositeBakedModel(flowerModel, islandModel);
|
||||
Botania.LOGGER.debug("Cached floating flower model for islandtype {} and flowertype {}", islandType, flower.getItem().getRegistryName());
|
||||
CACHE.put(islandType, flower.getItem().getRegistryName(), model);
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@Nullable
|
||||
@Override
|
||||
public IBakedModel bake(ModelBakery bakery, Function<ResourceLocation, TextureAtlasSprite> spriteGetter, ISprite sprite, VertexFormat format) {
|
||||
final TRSRTransformation transform = TRSRTransformation.blockCenterToCorner(new TRSRTransformation(new Vector3f(0F, 0.2F, 0F), null, new Vector3f(0.5F, 0.5F, 0.5F), null));
|
||||
IModelState comp = new ModelStateComposition(transform, sprite.getState());
|
||||
IBakedModel bakedFlower = unbakedFlower.bake(bakery, spriteGetter, new BasicState(comp, false), format);
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemOverrideList getOverrides() {
|
||||
return itemHandler;
|
||||
}
|
||||
Map<IFloatingFlower.IslandType, IBakedModel> bakedIslands = new HashMap<>();
|
||||
for (Map.Entry<IFloatingFlower.IslandType, IUnbakedModel> e : unbakedIslands.entrySet()) {
|
||||
IBakedModel bakedIsland = e.getValue().bake(bakery, spriteGetter, sprite, format);
|
||||
bakedIslands.put(e.getKey(), bakedIsland);
|
||||
}
|
||||
return new Baked(bakedFlower, bakedIslands);
|
||||
}
|
||||
|
||||
@Override public boolean isAmbientOcclusion() { return false; }
|
||||
@Override public boolean isGui3d() { return true; }
|
||||
@Override public boolean isBuiltInRenderer() { return false; }
|
||||
@Nonnull @Override public TextureAtlasSprite getParticleTexture() { return Minecraft.getInstance().getTextureMap().getAtlasSprite("minecraft:blocks/dirt"); }
|
||||
@Nonnull @Override public ItemCameraTransforms getItemCameraTransforms() { return ItemCameraTransforms.DEFAULT; }
|
||||
private static class Baked extends BakedModelWrapper<IBakedModel> {
|
||||
private final Map<IFloatingFlower.IslandType, IBakedModel> islands;
|
||||
|
||||
private static class CompositeBakedModel implements IBakedModel {
|
||||
Baked(IBakedModel flower, Map<IFloatingFlower.IslandType, IBakedModel> islands) {
|
||||
super(flower);
|
||||
this.islands = islands;
|
||||
}
|
||||
|
||||
private final IBakedModel flower;
|
||||
private final IBakedModel island;
|
||||
private final List<BakedQuad> genQuads;
|
||||
private final Map<Direction, List<BakedQuad>> faceQuads = new EnumMap<>(Direction.class);
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, @Nonnull IModelData extraData) {
|
||||
List<BakedQuad> quads = super.getQuads(state, side, rand, extraData);
|
||||
IFloatingFlower.IslandType type = IFloatingFlower.IslandType.GRASS;
|
||||
if (extraData.hasProperty(BotaniaStateProps.FLOATING_DATA)) {
|
||||
type = extraData.getData(BotaniaStateProps.FLOATING_DATA).getIslandType();
|
||||
}
|
||||
quads.addAll(islands.get(type).getQuads(state, side, rand, extraData));
|
||||
return quads;
|
||||
}
|
||||
}
|
||||
|
||||
public CompositeBakedModel(IBakedModel flower, IBakedModel island) {
|
||||
this.flower = flower;
|
||||
this.island = island;
|
||||
public enum Loader implements ICustomModelLoader {
|
||||
INSTANCE;
|
||||
|
||||
ImmutableList.Builder<BakedQuad> genBuilder = ImmutableList.builder();
|
||||
final TRSRTransformation transform = TRSRTransformation.blockCenterToCorner(new TRSRTransformation(new Vector3f(0F, 0.2F, 0F), null, new Vector3f(0.5F, 0.5F, 0.5F), null));
|
||||
@Override
|
||||
public void onResourceManagerReload(@Nonnull IResourceManager resourceManager) {}
|
||||
|
||||
for(Direction e : Direction.values())
|
||||
faceQuads.put(e, new ArrayList<>());
|
||||
@Override
|
||||
public boolean accepts(ResourceLocation modelLocation) {
|
||||
return modelLocation.getNamespace().equals("botania_special") && modelLocation.getPath().equals("models/floating_flower");
|
||||
}
|
||||
|
||||
// Add flower quads, scaled and translated
|
||||
flower.getQuads(null, null, new Random(0)).stream().map(q -> transform(q, transform)).forEach(genBuilder::add);
|
||||
for(Direction e : Direction.values()) {
|
||||
List<BakedQuad> faceQ = faceQuads.get(e);
|
||||
flower.getQuads(null, e, new Random(0)).stream().map(input -> transform(input, transform)).forEach(faceQ::add);
|
||||
}
|
||||
|
||||
// Add island quads
|
||||
genBuilder.addAll(island.getQuads(null, null, new Random(0)));
|
||||
for(Direction e : Direction.values()) {
|
||||
faceQuads.get(e).addAll(island.getQuads(null, e, new Random(0)));
|
||||
}
|
||||
|
||||
genQuads = genBuilder.build();
|
||||
}
|
||||
|
||||
// Forward all to flower model
|
||||
@Nonnull @Override public List<BakedQuad> getQuads(BlockState state, Direction face, @Nonnull Random rand) {
|
||||
return face == null ? genQuads : faceQuads.get(face);
|
||||
}
|
||||
@Override public boolean isAmbientOcclusion() {
|
||||
return flower.isAmbientOcclusion();
|
||||
}
|
||||
@Override public boolean isGui3d() {
|
||||
return flower.isGui3d();
|
||||
}
|
||||
@Override public boolean isBuiltInRenderer() {
|
||||
return flower.isBuiltInRenderer();
|
||||
}
|
||||
@Nonnull @Override public TextureAtlasSprite getParticleTexture() {
|
||||
return flower.getParticleTexture();
|
||||
}
|
||||
@Nonnull @Override public ItemCameraTransforms getItemCameraTransforms() {
|
||||
return flower.getItemCameraTransforms();
|
||||
}
|
||||
@Nonnull @Override public ItemOverrideList getOverrides() { return ItemOverrideList.EMPTY; }
|
||||
|
||||
@Override
|
||||
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(ItemCameraTransforms.TransformType cameraTransformType) {
|
||||
Pair<? extends IBakedModel, Matrix4f> pair = island.handlePerspective(cameraTransformType);
|
||||
if(pair != null && pair.getRight() != null)
|
||||
return Pair.of(this, pair.getRight());
|
||||
return Pair.of(this, TRSRTransformation.identity().getMatrixVec());
|
||||
}
|
||||
}
|
||||
|
||||
private final ItemOverrideList itemHandler = new ItemOverrideList() {
|
||||
@Nonnull
|
||||
@Override
|
||||
public IBakedModel getModelWithOverrides(IBakedModel model, ItemStack stack, @Nullable World worldIn, @Nullable LivingEntity entityIn) {
|
||||
// Items always have GRASS island
|
||||
return FloatingFlowerModel.this.getModel(IFloatingFlower.IslandType.GRASS, stack);
|
||||
}
|
||||
};
|
||||
@Nonnull
|
||||
@Override
|
||||
public IUnbakedModel loadModel(@Nonnull ResourceLocation modelLocation) {
|
||||
return FloatingFlowerModel.INIT;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.network.play.server.SUpdateTileEntityPacket;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraftforge.client.model.ModelDataManager;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
import net.minecraftforge.client.model.data.ModelDataMap;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
@@ -79,7 +80,8 @@ public class TileFloatingFlower extends TileMod {
|
||||
IFloatingFlower.IslandType oldType = floatingData.getIslandType();
|
||||
super.onDataPacket(net, packet);
|
||||
if(oldType != floatingData.getIslandType()) {
|
||||
// todo 1.14 world.markForRerender(pos);
|
||||
ModelDataManager.requestModelDataRefresh(this);
|
||||
world.notifyBlockUpdate(getPos(), getBlockState(), getBlockState(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user