Revert fluid change to use Material, fixes server crash

This commit is contained in:
tterrag 2019-12-16 23:22:13 -05:00
parent 1933d05e36
commit dec91dec68
7 changed files with 61 additions and 44 deletions

View file

@ -86,7 +86,7 @@
}
+ private void func_228797_a_(IVertexBuilder p_228797_1_, double p_228797_2_, double p_228797_4_, double p_228797_6_, float p_228797_8_, float p_228797_9_, float p_228797_10_, float alpha, float p_228797_11_, float p_228797_12_, int p_228797_13_) {
+ p_228797_1_.func_225582_a_(p_228797_2_, p_228797_4_, p_228797_6_).func_227885_a_(p_228797_8_, p_228797_9_, p_228797_10_, alpha).func_225583_a_(p_228797_11_, p_228797_12_).func_227886_a_(p_228797_13_).func_225584_a_(0.0F, 1.0F, 0.0F).func_181675_d();
+ p_228797_1_.func_225582_a_(p_228797_2_, p_228797_4_, p_228797_6_).func_227885_a_(p_228797_8_, p_228797_9_, p_228797_10_, alpha).func_225583_a_(p_228797_11_, p_228797_12_).func_227886_a_(p_228797_13_).func_225584_a_(0.0F, 1.0F, 0.0F).func_181675_d();
+ }
+
private int func_228795_a_(ILightReader p_228795_1_, BlockPos p_228795_2_) {

View file

@ -47,6 +47,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.Random;
import java.util.Set;
import java.util.stream.Stream;
import javax.annotation.Nonnull;
import javax.vecmath.Matrix3f;
@ -79,6 +80,7 @@ import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.screen.MainMenuScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.renderer.ActiveRenderInfo;
import net.minecraft.client.renderer.Atlases;
import net.minecraft.client.renderer.FogRenderer.FogType;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.ItemRenderer;
@ -108,6 +110,7 @@ import net.minecraft.client.resources.I18n;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.IFluidState;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ItemStack;
@ -596,22 +599,35 @@ public class ForgeHooksClient
}
}*/
@SuppressWarnings("deprecation")
public static TextureAtlasSprite[] getFluidSprites(ILightReader world, BlockPos pos, IFluidState fluidStateIn)
{
return new TextureAtlasSprite[] {
fluidStateIn.getFluid().getAttributes().getStillMaterial(world, pos).func_229314_c_(),
fluidStateIn.getFluid().getAttributes().getFlowingMaterial(world, pos).func_229314_c_(),
Minecraft.getInstance().func_228015_a_(AtlasTexture.LOCATION_BLOCKS_TEXTURE).apply(fluidStateIn.getFluid().getAttributes().getStillTexture(world, pos)),
Minecraft.getInstance().func_228015_a_(AtlasTexture.LOCATION_BLOCKS_TEXTURE).apply(fluidStateIn.getFluid().getAttributes().getFlowingTexture(world, pos)),
};
}
public static void gatherFluidTextures(Set<Material> textures)
{
ForgeRegistries.FLUIDS.getValues().stream()
.flatMap(f -> f.getAttributes().getTextures())
.filter(Objects::nonNull)
.flatMap(ForgeHooksClient::getFluidMaterials)
.forEach(textures::add);
}
public static Stream<Material> getFluidMaterials(Fluid fluid)
{
return fluid.getAttributes().getTextures()
.filter(Objects::nonNull)
.map(ForgeHooksClient::getBlockMaterial);
}
@SuppressWarnings("deprecation")
public static Material getBlockMaterial(ResourceLocation loc)
{
return new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, loc);
}
private static class LightGatheringTransformer extends QuadGatheringTransformer {
private static final VertexFormat FORMAT = new VertexFormat(ImmutableList.of(DefaultVertexFormats.TEX_2F, DefaultVertexFormats.TEX_2S));

View file

@ -46,6 +46,7 @@ import net.minecraft.resources.IResourceManager;
import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.client.ForgeHooksClient;
import net.minecraftforge.client.model.geometry.IModelGeometry;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.resource.IResourceType;
@ -188,8 +189,7 @@ public final class ModelDynBucket implements IModelGeometry<ModelDynBucket>
TransformationMatrix transform = state.func_225615_b_();
Material fluidLocation = fluid != Fluids.EMPTY ? fluid.getAttributes().getStillMaterial() : null;
TextureAtlasSprite fluidSprite = fluidLocation != null ? spriteGetter.apply(fluidLocation) : null;
TextureAtlasSprite fluidSprite = fluid != Fluids.EMPTY ? spriteGetter.apply(ForgeHooksClient.getBlockMaterial(fluid.getAttributes().getStillTexture())) : null;
if (particleSprite == null) particleSprite = fluidSprite;

View file

@ -20,6 +20,7 @@
package net.minecraftforge.client.model;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.Collection;
import java.util.EnumMap;
import java.util.List;
@ -43,6 +44,7 @@ import net.minecraft.fluid.Fluids;
import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.client.ForgeHooksClient;
import net.minecraftforge.client.model.data.IModelData;
import net.minecraftforge.client.model.geometry.IModelGeometry;
import net.minecraftforge.client.model.pipeline.IVertexConsumer;
@ -74,10 +76,7 @@ public final class ModelFluid implements IModelGeometry<ModelFluid>
@Override
public Collection<Material> getTextures(IModelConfiguration owner, Function<ResourceLocation, IUnbakedModel> modelGetter, Set<com.mojang.datafixers.util.Pair<String, String>> missingTextureErrors)
{
FluidAttributes attrs = fluid.getAttributes();
return attrs.getOverlayMaterial() != null
? ImmutableSet.of(attrs.getStillMaterial(), attrs.getFlowingMaterial(), attrs.getOverlayMaterial())
: ImmutableSet.of(attrs.getStillMaterial(), attrs.getFlowingMaterial());
return ForgeHooksClient.getFluidMaterials(fluid).collect(Collectors.toList());
}
@Override
@ -89,9 +88,9 @@ public final class ModelFluid implements IModelGeometry<ModelFluid>
PerspectiveMapWrapper.getTransforms(sprite),
modelLocation,
attrs.getColor(),
spriteGetter.apply(attrs.getStillMaterial()),
spriteGetter.apply(attrs.getFlowingMaterial()),
Optional.ofNullable(attrs.getOverlayMaterial()).map(spriteGetter),
spriteGetter.apply(ForgeHooksClient.getBlockMaterial(attrs.getStillTexture())),
spriteGetter.apply(ForgeHooksClient.getBlockMaterial(attrs.getFlowingTexture())),
Optional.ofNullable(attrs.getOverlayTexture()).map(ForgeHooksClient::getBlockMaterial).map(spriteGetter),
attrs.isLighterThanAir(),
null
);

View file

@ -846,15 +846,15 @@ public class ForgeHooks
.color(0).density(0).temperature(0).luminosity(0).viscosity(0).build(fluid);
if (fluid instanceof WaterFluid)
return net.minecraftforge.fluids.FluidAttributes.Water.builder(
new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation("block/water_still")),
new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation("block/water_flow")))
.overlay(new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation("block/water_overlay")))
new ResourceLocation("block/water_still"),
new ResourceLocation("block/water_flow"))
.overlay(new ResourceLocation("block/water_overlay"))
.translationKey("block.minecraft.water")
.color(0xFF3F76E4).build(fluid);
if (fluid instanceof LavaFluid)
return net.minecraftforge.fluids.FluidAttributes.builder(
new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation("block/lava_still")),
new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation("block/lava_flow")))
new ResourceLocation("block/lava_still"),
new ResourceLocation("block/lava_flow"))
.translationKey("block.minecraft.lava")
.luminosity(15).density(3000).viscosity(6000).temperature(1300).build(fluid);
throw new RuntimeException("Mod fluids must override createAttributes.");

View file

@ -22,7 +22,6 @@ package net.minecraftforge.fluids;
import javax.annotation.Nullable;
import net.minecraft.block.BlockState;
import net.minecraft.client.renderer.model.Material;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.IFluidState;
import net.minecraft.item.ItemStack;
@ -63,11 +62,11 @@ public class FluidAttributes
private String translationKey;
private final Material stillTexture;
private final Material flowingTexture;
private final ResourceLocation stillTexture;
private final ResourceLocation flowingTexture;
@Nullable
private final Material overlayTexture;
private final ResourceLocation overlayTexture;
private final SoundEvent fillSound;
private final SoundEvent emptySound;
@ -275,18 +274,18 @@ public class FluidAttributes
return color;
}
public Material getStillMaterial()
public ResourceLocation getStillTexture()
{
return stillTexture;
}
public Material getFlowingMaterial()
public ResourceLocation getFlowingTexture()
{
return flowingTexture;
}
@Nullable
public Material getOverlayMaterial()
public ResourceLocation getOverlayTexture()
{
return overlayTexture;
}
@ -309,8 +308,8 @@ public class FluidAttributes
public boolean isGaseous(FluidStack stack){ return isGaseous(); }
public Rarity getRarity(FluidStack stack){ return getRarity(); }
public int getColor(FluidStack stack){ return getColor(); }
public Material getStillMaterial(FluidStack stack) { return getStillMaterial(); }
public Material getFlowingMaterial(FluidStack stack) { return getFlowingMaterial(); }
public ResourceLocation getStillTexture(FluidStack stack) { return getStillTexture(); }
public ResourceLocation getFlowingTexture(FluidStack stack) { return getFlowingTexture(); }
public SoundEvent getFillSound(FluidStack stack) { return getFillSound(); }
public SoundEvent getEmptySound(FluidStack stack) { return getEmptySound(); }
@ -322,16 +321,16 @@ public class FluidAttributes
public boolean isGaseous(ILightReader world, BlockPos pos){ return isGaseous(); }
public Rarity getRarity(ILightReader world, BlockPos pos){ return getRarity(); }
public int getColor(ILightReader world, BlockPos pos){ return getColor(); }
public Material getStillMaterial(ILightReader world, BlockPos pos) { return getStillMaterial(); }
public Material getFlowingMaterial(ILightReader world, BlockPos pos) { return getFlowingMaterial(); }
public ResourceLocation getStillTexture(ILightReader world, BlockPos pos) { return getStillTexture(); }
public ResourceLocation getFlowingTexture(ILightReader world, BlockPos pos) { return getFlowingTexture(); }
public SoundEvent getFillSound(ILightReader world, BlockPos pos) { return getFillSound(); }
public SoundEvent getEmptySound(ILightReader world, BlockPos pos) { return getEmptySound(); }
public static Builder builder(Material stillTexture, Material flowingTexture) {
public static Builder builder(ResourceLocation stillTexture, ResourceLocation flowingTexture) {
return new Builder(stillTexture, flowingTexture, FluidAttributes::new);
}
public Stream<Material> getTextures()
public Stream<ResourceLocation> getTextures()
{
if (overlayTexture != null)
return Stream.of(stillTexture, flowingTexture, overlayTexture);
@ -340,9 +339,9 @@ public class FluidAttributes
public static class Builder
{
private final Material stillTexture;
private final Material flowingTexture;
private Material overlayTexture;
private final ResourceLocation stillTexture;
private final ResourceLocation flowingTexture;
private ResourceLocation overlayTexture;
private int color = 0xFFFFFFFF;
private String translationKey;
private SoundEvent fillSound;
@ -355,7 +354,7 @@ public class FluidAttributes
private Rarity rarity = Rarity.COMMON;
private BiFunction<Builder,Fluid,FluidAttributes> factory;
protected Builder(Material stillTexture, Material flowingTexture, BiFunction<Builder,Fluid,FluidAttributes> factory) {
protected Builder(ResourceLocation stillTexture, ResourceLocation flowingTexture, BiFunction<Builder,Fluid,FluidAttributes> factory) {
this.factory = factory;
this.stillTexture = stillTexture;
this.flowingTexture = flowingTexture;
@ -373,7 +372,7 @@ public class FluidAttributes
return this;
}
public final Builder overlay(Material texture)
public final Builder overlay(ResourceLocation texture)
{
overlayTexture = texture;
return this;
@ -447,7 +446,7 @@ public class FluidAttributes
return BiomeColors.func_228363_c_(world, pos) | 0xFF000000;
}
public static Builder builder(Material stillTexture, Material flowingTexture) {
public static Builder builder(ResourceLocation stillTexture, ResourceLocation flowingTexture) {
return new Builder(stillTexture, flowingTexture, Water::new);
}
}

View file

@ -19,16 +19,20 @@
package net.minecraftforge.debug.fluid;
import org.apache.commons.lang3.Validate;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.FlowingFluidBlock;
import net.minecraft.client.renderer.model.Material;
import net.minecraft.client.renderer.texture.AtlasTexture;
import net.minecraft.fluid.FlowingFluid;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.*;
import net.minecraft.item.BucketItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fluids.FluidAttributes;
@ -40,15 +44,14 @@ import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import org.apache.commons.lang3.Validate;
@Mod(NewFluidTest.MODID)
public class NewFluidTest
{
public static final String MODID = "new_fluid_test";
public static final Material FLUID_STILL = new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation("minecraft:block/brown_mushroom_block"));
public static final Material FLUID_FLOWING = new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation("minecraft:block/mushroom_stem"));
public static final ResourceLocation FLUID_STILL = new ResourceLocation("minecraft:block/brown_mushroom_block");
public static final ResourceLocation FLUID_FLOWING = new ResourceLocation("minecraft:block/mushroom_stem");
public static final DeferredRegister<Block> BLOCKS = new DeferredRegister<>(ForgeRegistries.BLOCKS, MODID);
public static final DeferredRegister<Item> ITEMS = new DeferredRegister<>(ForgeRegistries.ITEMS, MODID);