From 0da3168bbf505ab05d8c8ecb2b1e1e09bdaf4c55 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sun, 28 Jul 2019 17:14:38 +0100 Subject: [PATCH] Fluid ingredients + some other work around this area --- .../client/render/DynamicCellBakedModel.java | 18 +++-- .../techreborn/items/ItemDynamicCell.java | 76 ++++++------------- src/main/resources/META-INF/mods.toml | 16 ---- .../recipes/grinder/grinder_test_2.json | 19 +++++ .../recipes/grinder/grinder_test_3.json | 16 ++++ 5 files changed, 71 insertions(+), 74 deletions(-) delete mode 100644 src/main/resources/META-INF/mods.toml create mode 100644 src/main/resources/data/techreborn/recipes/grinder/grinder_test_2.json create mode 100644 src/main/resources/data/techreborn/recipes/grinder/grinder_test_3.json diff --git a/src/main/java/techreborn/client/render/DynamicCellBakedModel.java b/src/main/java/techreborn/client/render/DynamicCellBakedModel.java index 4f507a860..7276b657e 100644 --- a/src/main/java/techreborn/client/render/DynamicCellBakedModel.java +++ b/src/main/java/techreborn/client/render/DynamicCellBakedModel.java @@ -30,8 +30,10 @@ import net.minecraft.util.registry.Registry; import net.minecraft.world.ExtendedBlockView; import net.minecraft.world.World; import reborncore.common.fluid.container.GenericFluidContainer; +import reborncore.common.fluid.container.ItemFluidInfo; import javax.annotation.Nullable; +import java.awt.*; import java.util.Collections; import java.util.List; import java.util.Random; @@ -52,13 +54,11 @@ public class DynamicCellBakedModel implements BakedModel, FabricBakedModel { @Override public void emitItemQuads(ItemStack stack, Supplier randomSupplier, RenderContext context) { - GenericFluidContainer fluidContainer = GenericFluidContainer.fromStack(stack); Fluid fluid = Fluids.EMPTY; - if(fluidContainer != null){ - FluidInstance fluidInstance = fluidContainer.getFluidInstance(stack); - if(!fluidInstance.isEmpty()){ - fluid = fluidContainer.getFluidInstance(stack).getFluid(); - } + if(stack.getItem() instanceof ItemFluidInfo){ + ItemFluidInfo fluidInfo = (ItemFluidInfo) stack.getItem(); + fluid = fluidInfo.getFluid(stack); + } context.meshConsumer().accept(getMesh(fluid)); } @@ -85,10 +85,14 @@ public class DynamicCellBakedModel implements BakedModel, FabricBakedModel { if(fluid != Fluids.EMPTY){ FluidRenderHandler fluidRenderHandler = FluidRenderHandlerRegistry.INSTANCE.get(fluid); if(fluidRenderHandler != null){ + int color = fluidRenderHandler.getFluidColor(MinecraftClient.getInstance().world, BlockPos.ORIGIN, fluid.getDefaultState()); + //Does maths that works + color = new Color((float)(color >> 16 & 255) / 255.0F, (float)(color >> 8 & 255) / 255.0F,(float)(color & 255) / 255.0F).getRGB(); + Sprite fluidSprite = fluidRenderHandler.getFluidSprites(MinecraftClient.getInstance().world, BlockPos.ORIGIN, fluid.getDefaultState())[0]; emitter.square(Direction.SOUTH, 0.4F, 0.25F, 0.6F, 0.75F, -0.0001F) .material(mat) - .spriteColor(0, -1, -1, -1, -1) + .spriteColor(0, color, color, color, color) .spriteBake(0, fluidSprite, MutableQuadView.BAKE_LOCK_UV).emit(); } } diff --git a/src/main/java/techreborn/items/ItemDynamicCell.java b/src/main/java/techreborn/items/ItemDynamicCell.java index df4fa400a..2078aafdf 100644 --- a/src/main/java/techreborn/items/ItemDynamicCell.java +++ b/src/main/java/techreborn/items/ItemDynamicCell.java @@ -24,17 +24,17 @@ package techreborn.items; -import io.github.prospector.silk.fluid.FluidInstance; -import net.minecraft.entity.Entity; import net.minecraft.fluid.Fluid; +import net.minecraft.fluid.Fluids; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundTag; import net.minecraft.util.DefaultedList; -import net.minecraft.world.World; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; import org.apache.commons.lang3.Validate; -import reborncore.common.fluid.container.GenericFluidContainer; +import reborncore.common.fluid.container.ItemFluidInfo; import reborncore.common.util.ItemNBTHelper; import techreborn.TechReborn; import techreborn.init.TRContent; @@ -43,29 +43,12 @@ import techreborn.utils.FluidUtils; /** * Created by modmuss50 on 17/05/2016. */ -public class ItemDynamicCell extends Item implements GenericFluidContainer { - - public static final int CAPACITY = 1000; +public class ItemDynamicCell extends Item implements ItemFluidInfo { public ItemDynamicCell() { super(new Item.Settings().maxCount(1).group(TechReborn.ITEMGROUP)); } - @Override - public void inventoryTick(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { - //Clearing tag because ItemUtils.isItemEqual doesn't handle tags ForgeCaps and display - //And breaks ability to use in recipes - //TODO: Property ItemUtils.isItemEquals tags equality handling? - if (stack.hasTag()) { - CompoundTag tag = stack.getTag(); - if (tag.getSize() != 1 || tag.containsKey("Fluid")) { - CompoundTag clearTag = new CompoundTag(); - clearTag.put("Fluid", tag.getCompound("Fluid")); - stack.setTag(clearTag); - } - } - } - @Override public void appendStacks(ItemGroup tab, DefaultedList subItems) { if (!isIn(tab)) { @@ -73,24 +56,21 @@ public class ItemDynamicCell extends Item implements GenericFluidContainer fluidContainer = GenericFluidContainer.fromStack(stack); - Validate.notNull(fluidContainer); - fluidContainer.setFluid(stack, new FluidInstance(fluid, fluidContainer.getCapacity(stack))); + ItemNBTHelper.getNBT(stack).putString("fluid", Registry.FLUID.getId(fluid).toString()); stack.setCount(stackSize); return stack; } @@ -103,28 +83,22 @@ public class ItemDynamicCell extends Item implements GenericFluidContainer