Merge branch 'master' into flattening_test

This commit is contained in:
Vincent Lee committed 2018-03-29 19:09:19 -05:00
commit 58fa185ef4
17 files changed
+110 -128

No files matched your search

+1
View File
@@ -95,3 +95,4 @@ lukidwen=9
quirkyrose=10
cynicalroses=6
adenmck=5
thenewdreamer=6
@@ -47,7 +47,7 @@ public final class DebugHandler {
@SubscribeEvent
public static void onDrawDebugText(RenderGameOverlayEvent.Text event) {
World world = Minecraft.getMinecraft().world;
if(Minecraft.getMinecraft().gameSettings.showDebugInfo) {
if(ConfigHandler.debugInfo && Minecraft.getMinecraft().gameSettings.showDebugInfo) {
event.getLeft().add("");
String version = LibMisc.VERSION;
if(version.contains("GRADLE"))
@@ -160,6 +160,13 @@ public class FXSparkle extends Particle {
setExpired();
}
@Override
protected void setSize(float width, float height) {
super.setSize(width, height);
// fix MC-12269: the bb is expanded only in +X +Z directions by super, call setPosition again to recalculate a correct BB
setPosition(posX, posY, posZ);
}
public void setGravity(float value) {
particleGravity = value;
}
@@ -158,6 +158,13 @@ public class FXWisp extends Particle {
this.motionZ *= 0.9800000190734863D;
}
@Override
protected void setSize(float width, float height) {
super.setSize(width, height);
// fix MC-12269: the bb is expanded only in +X +Z directions by super, call setPosition again to recalculate a correct BB
setPosition(posX, posY, posZ);
}
public void setGravity(float value) {
particleGravity = value;
}
@@ -8,14 +8,9 @@
*/
package vazkii.botania.client.model;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.BakedQuad;
@@ -45,29 +40,25 @@ import net.minecraftforge.common.property.IExtendedBlockState;
import org.apache.commons.lang3.tuple.Pair;
import vazkii.botania.api.BotaniaAPIClient;
import vazkii.botania.api.state.BotaniaStateProps;
import vazkii.botania.common.Botania;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.item.block.ItemBlockSpecialFlower;
import javax.annotation.Nonnull;
import javax.vecmath.Matrix4f;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
public class SpecialFlowerModel implements IModel {
private static final ModelResourceLocation MISSING = new ModelResourceLocation("builtin/missing", "missing");
private final ModelResourceLocation baseModel;
private final ImmutableMap<String, ModelResourceLocation> blockModels;
private final ImmutableMap<String, ModelResourceLocation> itemModels;
// SpecialFlowerModel for when there are no blockModels registered for a subtile
public static final SpecialFlowerModel INSTANCE = new SpecialFlowerModel(ImmutableMap.of(), ImmutableMap.of());
private final ImmutableMap<Optional<String>, ModelResourceLocation> blockModels;
private final ImmutableMap<Optional<String>, ModelResourceLocation> itemModels;
public SpecialFlowerModel(ImmutableMap<Optional<String>, ModelResourceLocation> blockModels,
ImmutableMap<Optional<String>, ModelResourceLocation> itemModels) {
private SpecialFlowerModel(ModelResourceLocation baseModel,
ImmutableMap<String, ModelResourceLocation> blockModels,
ImmutableMap<String, ModelResourceLocation> itemModels) {
this.baseModel = baseModel;
this.blockModels = blockModels;
this.itemModels = itemModels;
}
@@ -75,6 +66,8 @@ public class SpecialFlowerModel implements IModel {
@Override
public Collection<ResourceLocation> getDependencies() {
ImmutableSet.Builder<ResourceLocation> builder = ImmutableSet.builder();
if(!MISSING.equals(baseModel))
builder.add(baseModel);
builder.addAll(blockModels.values());
builder.addAll(itemModels.values());
@@ -91,8 +84,27 @@ public class SpecialFlowerModel implements IModel {
@Override
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
// "Bake" the SpecialFlowerModel (in reality, just create another wrapper for all the delegate blockModels)
return new SpecialFlowerBakedModel(blockModels, itemModels, PerspectiveMapWrapper.getTransforms(state));
ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms = PerspectiveMapWrapper.getTransforms(state);
IModelState transformState = new SimpleModelState(transforms);
IBakedModel baseModelBaked = ModelLoaderRegistry.getModelOrMissing(baseModel)
.bake(transformState, DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter());
ImmutableMap.Builder<String, IBakedModel> bakedBlockBuilder = ImmutableMap.builder();
for(Map.Entry<String, ModelResourceLocation> e : blockModels.entrySet()) {
IModel model = ModelLoaderRegistry.getModelOrMissing(e.getValue());
if(model != ModelLoaderRegistry.getMissingModel())
bakedBlockBuilder.put(e.getKey(), model.bake(transformState, DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter()));
}
ImmutableMap.Builder<String, IBakedModel> bakedItemBuilder = ImmutableMap.builder();
for(Map.Entry<String, ModelResourceLocation> e : itemModels.entrySet()) {
IModel model = ModelLoaderRegistry.getModelOrMissing(e.getValue());
if(model != ModelLoaderRegistry.getMissingModel())
bakedItemBuilder.put(e.getKey(), model.bake(transformState, DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter()));
}
return new SpecialFlowerBakedModel(baseModelBaked, bakedBlockBuilder.build(), bakedItemBuilder.build(), transforms);
}
@Override
@@ -103,35 +115,15 @@ public class SpecialFlowerModel implements IModel {
@Override
public IModel process(ImmutableMap<String, String> customData) {
// Load the base variant from blockstate json, and also add all the model paths we received from external API
ImmutableMap.Builder<Optional<String>, ModelResourceLocation> blockBuilder = ImmutableMap.builder();
ImmutableMap.Builder<Optional<String>, ModelResourceLocation> itemBuilder = ImmutableMap.builder();
for(String key : customData.keySet()) {
if("base".equals(key)) {
blockBuilder.put(Optional.empty(), getLocation(customData.get(key)));
}
}
ModelResourceLocation base = baseModel;
if(customData.containsKey("base"))
// Forge blockstate gives custom data in json form, have to drop the quotes
base = new ModelResourceLocation(customData.get("base").substring(1, customData.get("base").length() - 1));
for(Map.Entry<String, ModelResourceLocation> e : BotaniaAPIClient.getRegisteredSubtileBlockModels().entrySet()) {
blockBuilder.put(Optional.of(e.getKey()), e.getValue());
}
for(Map.Entry<String, ModelResourceLocation> e : BotaniaAPIClient.getRegisteredSubtileItemModels().entrySet()) {
itemBuilder.put(Optional.of(e.getKey()), e.getValue());
}
ImmutableMap<Optional<String>, ModelResourceLocation> blockModels = blockBuilder.build();
ImmutableMap<Optional<String>, ModelResourceLocation> itemModels = itemBuilder.build();
if(blockModels.isEmpty() && itemModels.isEmpty()) return INSTANCE;
return new SpecialFlowerModel(blockModels, itemModels);
}
private ModelResourceLocation getLocation(String json) {
JsonElement e = new JsonParser().parse(json);
if(e.isJsonPrimitive() && e.getAsJsonPrimitive().isString()) {
return new ModelResourceLocation(e.getAsString());
}
Botania.LOGGER.error("Expect ModelResourceLocation, got: ", json);
return new ModelResourceLocation("builtin/missing", "missing");
ImmutableMap<String, ModelResourceLocation> blockModels = ImmutableMap.copyOf(BotaniaAPIClient.getRegisteredSubtileBlockModels());
ImmutableMap<String, ModelResourceLocation> itemModels = ImmutableMap.copyOf(BotaniaAPIClient.getRegisteredSubtileItemModels());
return new SpecialFlowerModel(base, blockModels, itemModels);
}
public enum Loader implements ICustomModelLoader {
@@ -149,79 +141,40 @@ public class SpecialFlowerModel implements IModel {
}
@Override
public IModel loadModel(ResourceLocation modelLocation) throws IOException {
public IModel loadModel(ResourceLocation modelLocation) {
// Load a dummy model for now, all actual blockModels added in process().
return SpecialFlowerModel.INSTANCE;
return new SpecialFlowerModel(new ModelResourceLocation("builtin/missing", "missing"), ImmutableMap.of(), ImmutableMap.of());
}
}
}
private static class SpecialFlowerBakedModel implements IBakedModel {
private final ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms;
private final ImmutableMap<Optional<String>, ModelResourceLocation> blockModels;
private final ImmutableMap<Optional<String>, ModelResourceLocation> itemModels;
private final IBakedModel baseModel;
private final LoadingCache<String, Optional<IBakedModel>> bakedBlockModels;
private final LoadingCache<String, Optional<IBakedModel>> bakedItemModels;
private final ImmutableMap<String, IBakedModel> bakedBlockModels;
private final ImmutableMap<String, IBakedModel> bakedItemModels;
private final ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms;
SpecialFlowerBakedModel(ImmutableMap<Optional<String>, ModelResourceLocation> blockModels,
ImmutableMap<Optional<String>, ModelResourceLocation> itemModels, ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> cameraTransforms) {
this.blockModels = blockModels;
this.itemModels = itemModels;
transforms = cameraTransforms;
ModelResourceLocation baseModelPath = blockModels.getOrDefault(Optional.empty(),
new ModelResourceLocation("builtin/missing", "missing"));
baseModel = ModelLoaderRegistry.getModelOrMissing(baseModelPath)
.bake(new SimpleModelState(transforms), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter());
bakedBlockModels = CacheBuilder.newBuilder().build(new Loader(true));
bakedItemModels = CacheBuilder.newBuilder().build(new Loader(false));
}
private class Loader extends CacheLoader<String, Optional<IBakedModel>> {
private final boolean loadBlocks;
Loader(boolean blocks) {
loadBlocks = blocks;
}
@Override
public Optional<IBakedModel> load(@Nonnull String key) {
Map<Optional<String>, ModelResourceLocation> loadFrom = loadBlocks ? blockModels : itemModels;
ModelResourceLocation loc = loadFrom.get(Optional.of(key));
if(loc == null)
return Optional.empty();
IModel model = ModelLoaderRegistry.getModelOrMissing(loc);
if(model == ModelLoaderRegistry.getMissingModel())
return Optional.empty();
return Optional.of(model.bake(new SimpleModelState(transforms), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter()));
}
SpecialFlowerBakedModel(IBakedModel baseModel,
ImmutableMap<String, IBakedModel> bakedBlockModels,
ImmutableMap<String, IBakedModel> bakedItemModels,
ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> cameraTransforms) {
this.baseModel = baseModel;
this.bakedBlockModels = bakedBlockModels;
this.bakedItemModels = bakedItemModels;
this.transforms = cameraTransforms;
}
@Nonnull
@Override
public List<BakedQuad> getQuads(IBlockState state, EnumFacing face, long rand) {
if(state.getBlock() != ModBlocks.specialFlower) {
Botania.LOGGER.fatal("FOREIGN BLOCK: " + state);
return Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelManager().getMissingModel().getQuads(state, face, rand);
}
IExtendedBlockState extendedState = (IExtendedBlockState) state;
String subtileId = extendedState.getValue(BotaniaStateProps.SUBTILE_ID);
IBakedModel ret = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelManager().getMissingModel();
Optional<IBakedModel> specialModel = bakedBlockModels.getUnchecked(subtileId == null ? "" : subtileId);
if(specialModel.isPresent())
ret = specialModel.get();
IBakedModel model = bakedBlockModels.get(subtileId == null ? "" : subtileId);
if(model == null)
model = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelManager().getMissingModel();
return ret.getQuads(state, face, rand);
return model.getQuads(state, face, rand);
}
@Nonnull
@@ -236,14 +189,14 @@ public class SpecialFlowerModel implements IModel {
@Nonnull
@Override
public IBakedModel handleItemState(@Nonnull IBakedModel original, ItemStack stack, World world, EntityLivingBase living) {
Optional<IBakedModel> item = bakedItemModels.getUnchecked(ItemBlockSpecialFlower.getType(stack));
IBakedModel model = bakedItemModels.get(ItemBlockSpecialFlower.getType(stack));
if(!item.isPresent())
item = bakedBlockModels.getUnchecked(ItemBlockSpecialFlower.getType(stack));
if(model == null)
model = bakedBlockModels.get(ItemBlockSpecialFlower.getType(stack));
if(model == null)
model = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel(roseFallback);
return item.isPresent()
? item.get()
: Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel(roseFallback);
return model;
}
};
@@ -137,9 +137,7 @@ public class Botania {
PacketHandler.init();
ModEntities.init();
ModBrews.init();
ModMultiblocks.init();
ModBanners.init();
fixer = FMLCommonHandler.instance().getDataFixer().init(LibMisc.MOD_ID, LibMisc.DATA_VERSION);
fixer.registerFix(FixTypes.ITEM_INSTANCE, new FlattenItems());
fixer.registerFix(FixTypes.ITEM_INSTANCE, new FlattenNBT());
@@ -160,6 +158,7 @@ public class Botania {
@EventHandler
public void init(FMLInitializationEvent event) {
ModBanners.init();
ModPetalRecipes.init();
ModPureDaisyRecipes.init();
ModRuneRecipes.init();
@@ -335,6 +335,6 @@ public class BlockSpecialFlower extends BlockFlower implements ISpecialFlower, I
public void registerModels() {
// Let custom loader work
ModelLoader.setCustomStateMapper(this, new StateMap.Builder().ignore(BotaniaStateProps.COLOR).ignore(getTypeProperty()).build());
ModelHandler.registerInventoryVariant(this);
ModelHandler.registerBlockToState(this, 0, getDefaultState());
}
}
@@ -196,6 +196,7 @@ public class BlockPool extends BlockMod implements IWandHUD, IWandable, ILexicon
return TilePool.calculateComparatorLevel(pool.getCurrentMana(), pool.manaCap);
}
@SideOnly(Side.CLIENT)
@Override
public void renderHUD(Minecraft mc, ScaledResolution res, World world, BlockPos pos) {
((TilePool) world.getTileEntity(pos)).renderHUD(mc, res);
@@ -195,6 +195,7 @@ public class BlockSpreader extends BlockMod implements IWandable, IWandHUD, ILex
return new TileSpreader();
}
@SideOnly(Side.CLIENT)
@Override
public void renderHUD(Minecraft mc, ScaledResolution res, World world, BlockPos pos) {
((TileSpreader) world.getTileEntity(pos)).renderHUD(mc, res);
@@ -52,7 +52,6 @@ public class SubTileHydroangeas extends SubTileGenerating {
cooldown--;
for(int i = 0; i < 3; i++)
Botania.proxy.wispFX(supertile.getPos().getX() + 0.5 + Math.random() * 0.2 - 0.1, supertile.getPos().getY() + 0.5 + Math.random() * 0.2 - 0.1, supertile.getPos().getZ() + 0.5 + Math.random() * 0.2 - 0.1, 0.1F, 0.1F, 0.1F, (float) Math.random() / 6, (float) -Math.random() / 30);
return;
}
if(burnTime == 0) {
@@ -476,7 +476,12 @@ public class TilePool extends TileMod implements IManaPool, IKeyLocked, ISparkAt
@Override
public int getAvailableSpaceForMana() {
return Math.max(0, manaCap - getCurrentMana());
int space = Math.max(0, manaCap - getCurrentMana());
if(space > 0)
return space;
else if(world.getBlockState(pos.down()).getBlock() == ModBlocks.manaVoid)
return manaCap;
else return 0;
}
@Override
@@ -29,7 +29,8 @@ public class PotionFeatherfeet extends PotionMod {
@Override
public void performEffect(@Nonnull EntityLivingBase living, int amplified) {
living.fallDistance = 2.5F;
if(living.fallDistance > 2.5F)
living.fallDistance = 2.5F;
}
}
@@ -66,6 +66,7 @@ public final class ConfigHandler {
public static boolean altFlowerTextures = false;
public static boolean staticFloaters = false;
public static boolean debugInfo = true;
public static boolean matrixMode = false;
public static boolean referencesEnabled = true;
@@ -182,6 +183,9 @@ public final class ConfigHandler {
desc = "Set this to true if you use lots of floating flowers and are experiencing rendering lag. Will disable the floating flowers' animations and render them statically for a major performance boost. Hit F3+A in-world after toggling this.";
staticFloaters = loadPropBool("staticFloaters.enabled", desc, staticFloaters);
desc = "Set to false to disable Botania's messages in the F3 debug screen";
debugInfo = loadPropBool("debugInfo.enabled", desc, debugInfo);
desc = "Set this to true if you are the chosen one. For lovers of glitch art and just general mad people.";
matrixMode = loadPropBool("matrixMode.enabled", desc, matrixMode);
@@ -687,7 +687,8 @@ public class EntityDoppleganger extends EntityLiving implements IBotaniaBoss {
if (world.isRemote) {
particles();
EntityPlayer player = Botania.proxy.getClientPlayer();
player.capabilities.isFlying = player.capabilities.isFlying && player.capabilities.isCreativeMode;
if(getPlayersAround().contains(player))
player.capabilities.isFlying = player.capabilities.isFlying && player.capabilities.isCreativeMode;
return;
}
@@ -813,8 +814,6 @@ public class EntityDoppleganger extends EntityLiving implements IBotaniaBoss {
if(spawnMissiles)
spawnMissile();
} else {
float range = 3F;
players = world.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(posX - range, posY - range, posZ - range, posX + range, posY + range, posZ + range));
if(!players.isEmpty())
damageEntity(DamageSource.causePlayerDamage(players.get(0)), 0);
}
@@ -10,7 +10,9 @@
*/
package vazkii.botania.common.item;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
@@ -20,6 +22,9 @@ import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.IFluidBlock;
import vazkii.botania.common.lib.LibItemNames;
import javax.annotation.Nonnull;
@@ -49,10 +54,13 @@ public class ItemOpenBucket extends ItemMod {
if(!player.canPlayerEdit(pos, rtr.sideHit, stack))
return ActionResult.newResult(EnumActionResult.PASS, stack);
Material material = world.getBlockState(pos).getMaterial();
int l = world.getBlockState(pos).getBlock().getMetaFromState(world.getBlockState(pos)); // hack to get meta so we don't have to know the level prop
IBlockState state = world.getBlockState(pos);
Fluid fluid = FluidRegistry.lookupFluidForBlock(state.getBlock());
boolean isFull = state.getBlock() instanceof BlockLiquid && state.getValue(BlockLiquid.LEVEL) == 0
|| state.getBlock() instanceof IFluidBlock && Math.abs(((IFluidBlock) state.getBlock()).getFilledPercentage(world, pos)) >= 1;
if((material == Material.LAVA || material == Material.WATER) && l == 0) {
if(fluid != null && isFull) {
player.playSound(fluid.getFillSound(world, pos), 1.0f, 1.0f);
world.setBlockToAir(pos);
for(int x = 0; x < 5; x++)
@@ -2,15 +2,11 @@
"forge_marker": 1,
"defaults": {
"model": "botania_special:specialFlower",
"transform": "forge:default-item"
"transform": "forge:default-item",
"custom": { "base": "botania:specialflower#basemodel" }
},
"variants": {
"normal": [{
"custom": { "base": "botania:specialflower#basemodel" }
}],
"inventory": [{
"custom": { "base": "botania:specialflower#basemodel" }
}],
"normal": [{}],
"basemodel": [{
"model": "minecraft:cross",
"textures": {
@@ -351,6 +351,7 @@ shaders.enabled=Enable Shader Usage
baubleRender.enabled=Enable Bauble Rendering
spreader.posShift=Spreader Pos Shift
staticFloaters.enabled=Enable Static Floating Flowers
debugInfo.enabled=Enable Botania's F3 debug information
versionChecking.enabled=Enable Version Checking
wandBeam.static=Enable Static Wand Beam
worldgen.flower.density=Worldgen Flower Density