Fluid ingredients + some other work around this area
This commit is contained in:
parent
0118d5a999
commit
0da3168bbf
5 changed files with 71 additions and 74 deletions
|
@ -30,8 +30,10 @@ import net.minecraft.util.registry.Registry;
|
||||||
import net.minecraft.world.ExtendedBlockView;
|
import net.minecraft.world.ExtendedBlockView;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import reborncore.common.fluid.container.GenericFluidContainer;
|
import reborncore.common.fluid.container.GenericFluidContainer;
|
||||||
|
import reborncore.common.fluid.container.ItemFluidInfo;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.awt.*;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
@ -52,13 +54,11 @@ public class DynamicCellBakedModel implements BakedModel, FabricBakedModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context) {
|
public void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context) {
|
||||||
GenericFluidContainer<ItemStack> fluidContainer = GenericFluidContainer.fromStack(stack);
|
|
||||||
Fluid fluid = Fluids.EMPTY;
|
Fluid fluid = Fluids.EMPTY;
|
||||||
if(fluidContainer != null){
|
if(stack.getItem() instanceof ItemFluidInfo){
|
||||||
FluidInstance fluidInstance = fluidContainer.getFluidInstance(stack);
|
ItemFluidInfo fluidInfo = (ItemFluidInfo) stack.getItem();
|
||||||
if(!fluidInstance.isEmpty()){
|
fluid = fluidInfo.getFluid(stack);
|
||||||
fluid = fluidContainer.getFluidInstance(stack).getFluid();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
context.meshConsumer().accept(getMesh(fluid));
|
context.meshConsumer().accept(getMesh(fluid));
|
||||||
}
|
}
|
||||||
|
@ -85,10 +85,14 @@ public class DynamicCellBakedModel implements BakedModel, FabricBakedModel {
|
||||||
if(fluid != Fluids.EMPTY){
|
if(fluid != Fluids.EMPTY){
|
||||||
FluidRenderHandler fluidRenderHandler = FluidRenderHandlerRegistry.INSTANCE.get(fluid);
|
FluidRenderHandler fluidRenderHandler = FluidRenderHandlerRegistry.INSTANCE.get(fluid);
|
||||||
if(fluidRenderHandler != null){
|
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];
|
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)
|
emitter.square(Direction.SOUTH, 0.4F, 0.25F, 0.6F, 0.75F, -0.0001F)
|
||||||
.material(mat)
|
.material(mat)
|
||||||
.spriteColor(0, -1, -1, -1, -1)
|
.spriteColor(0, color, color, color, color)
|
||||||
.spriteBake(0, fluidSprite, MutableQuadView.BAKE_LOCK_UV).emit();
|
.spriteBake(0, fluidSprite, MutableQuadView.BAKE_LOCK_UV).emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,17 +24,17 @@
|
||||||
|
|
||||||
package techreborn.items;
|
package techreborn.items;
|
||||||
|
|
||||||
import io.github.prospector.silk.fluid.FluidInstance;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.fluid.Fluid;
|
import net.minecraft.fluid.Fluid;
|
||||||
|
import net.minecraft.fluid.Fluids;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemGroup;
|
import net.minecraft.item.ItemGroup;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.util.DefaultedList;
|
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 org.apache.commons.lang3.Validate;
|
||||||
import reborncore.common.fluid.container.GenericFluidContainer;
|
import reborncore.common.fluid.container.ItemFluidInfo;
|
||||||
import reborncore.common.util.ItemNBTHelper;
|
import reborncore.common.util.ItemNBTHelper;
|
||||||
import techreborn.TechReborn;
|
import techreborn.TechReborn;
|
||||||
import techreborn.init.TRContent;
|
import techreborn.init.TRContent;
|
||||||
|
@ -43,29 +43,12 @@ import techreborn.utils.FluidUtils;
|
||||||
/**
|
/**
|
||||||
* Created by modmuss50 on 17/05/2016.
|
* Created by modmuss50 on 17/05/2016.
|
||||||
*/
|
*/
|
||||||
public class ItemDynamicCell extends Item implements GenericFluidContainer<ItemStack> {
|
public class ItemDynamicCell extends Item implements ItemFluidInfo {
|
||||||
|
|
||||||
public static final int CAPACITY = 1000;
|
|
||||||
|
|
||||||
public ItemDynamicCell() {
|
public ItemDynamicCell() {
|
||||||
super(new Item.Settings().maxCount(1).group(TechReborn.ITEMGROUP));
|
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
|
@Override
|
||||||
public void appendStacks(ItemGroup tab, DefaultedList<ItemStack> subItems) {
|
public void appendStacks(ItemGroup tab, DefaultedList<ItemStack> subItems) {
|
||||||
if (!isIn(tab)) {
|
if (!isIn(tab)) {
|
||||||
|
@ -73,24 +56,21 @@ public class ItemDynamicCell extends Item implements GenericFluidContainer<ItemS
|
||||||
}
|
}
|
||||||
subItems.add(getEmptyCell(1));
|
subItems.add(getEmptyCell(1));
|
||||||
for (Fluid fluid : FluidUtils.getAllFluids()) {
|
for (Fluid fluid : FluidUtils.getAllFluids()) {
|
||||||
subItems.add(getCellWithFluid(fluid));
|
if(fluid.isStill(fluid.getDefaultState())){
|
||||||
|
subItems.add(getCellWithFluid(fluid));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
@Override
|
||||||
// public String getTranslationKey(ItemStack stack) {
|
public String getTranslationKey(ItemStack itemStack_1) {
|
||||||
// FluidStack fluidStack = getFluidHandler(stack).getFluidInstance();
|
return super.getTranslationKey(itemStack_1);
|
||||||
// if (fluidStack == null)
|
}
|
||||||
// return super.getTranslationKey(stack);
|
|
||||||
// return StringUtils.t("item.techreborn.cell.fluid.name").replaceAll("\\$fluid\\$", fluidStack.getLocalizedName());
|
|
||||||
// }
|
|
||||||
|
|
||||||
public static ItemStack getCellWithFluid(Fluid fluid, int stackSize) {
|
public static ItemStack getCellWithFluid(Fluid fluid, int stackSize) {
|
||||||
Validate.notNull(fluid);
|
Validate.notNull(fluid);
|
||||||
ItemStack stack = new ItemStack(TRContent.CELL);
|
ItemStack stack = new ItemStack(TRContent.CELL);
|
||||||
GenericFluidContainer<ItemStack> fluidContainer = GenericFluidContainer.fromStack(stack);
|
ItemNBTHelper.getNBT(stack).putString("fluid", Registry.FLUID.getId(fluid).toString());
|
||||||
Validate.notNull(fluidContainer);
|
|
||||||
fluidContainer.setFluid(stack, new FluidInstance(fluid, fluidContainer.getCapacity(stack)));
|
|
||||||
stack.setCount(stackSize);
|
stack.setCount(stackSize);
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
@ -103,28 +83,22 @@ public class ItemDynamicCell extends Item implements GenericFluidContainer<ItemS
|
||||||
return getCellWithFluid(fluid, 1);
|
return getCellWithFluid(fluid, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setFluid(ItemStack type, FluidInstance instance) {
|
public ItemStack getEmpty() {
|
||||||
Validate.notNull(type, "ItemStack cannot be null!");
|
return new ItemStack(this);
|
||||||
CompoundTag compoundTag = new CompoundTag();
|
|
||||||
instance.toTag(compoundTag);
|
|
||||||
ItemNBTHelper.getNBT(type).put("fluid", compoundTag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FluidInstance getFluidInstance(ItemStack type) {
|
public ItemStack getFull(Fluid fluid) {
|
||||||
Validate.notNull(type, "ItemStack cannot be null!");
|
return getCellWithFluid(fluid);
|
||||||
if(ItemNBTHelper.getNBT(type).containsKey("fluid")){
|
}
|
||||||
CompoundTag compoundTag = ItemNBTHelper.getNBT(type).getCompound("fluid");
|
|
||||||
return new FluidInstance(compoundTag);
|
@Override
|
||||||
|
public Fluid getFluid(ItemStack itemStack) {
|
||||||
|
CompoundTag tag = itemStack.getTag();
|
||||||
|
if(tag != null && tag.containsKey("fluid")){
|
||||||
|
return Registry.FLUID.get(new Identifier(tag.getString("fluid")));
|
||||||
}
|
}
|
||||||
return new FluidInstance();
|
return Fluids.EMPTY;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getCapacity(ItemStack type) {
|
|
||||||
Validate.notNull(type, "ItemStack cannot be null!");
|
|
||||||
return CAPACITY;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
modLoader="javafml"
|
|
||||||
loaderVersion="[13,)"
|
|
||||||
version="1"
|
|
||||||
|
|
||||||
[[mods]]
|
|
||||||
modId="techreborn"
|
|
||||||
version="${version}"
|
|
||||||
displayName="Tech Reborn"
|
|
||||||
description="Tech Reborn"
|
|
||||||
|
|
||||||
[[dependencies.techreborn]]
|
|
||||||
modId="reborncore"
|
|
||||||
mandatory=true
|
|
||||||
ordering="AFTER"
|
|
||||||
side="BOTH"
|
|
||||||
versionRange="[4.0.0,)"
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
"type": "techreborn:grinder",
|
||||||
|
"power": 10,
|
||||||
|
"time": 123,
|
||||||
|
"ingredients" : [
|
||||||
|
{
|
||||||
|
"item": "minecraft:diamond_sword",
|
||||||
|
"tag": {
|
||||||
|
"Damage": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"results" : [
|
||||||
|
{
|
||||||
|
"item": "minecraft:diamond",
|
||||||
|
"count": 4
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"type": "techreborn:grinder",
|
||||||
|
"power": 10,
|
||||||
|
"time": 123,
|
||||||
|
"ingredients" : [
|
||||||
|
{
|
||||||
|
"fluid": "minecraft:water"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"results" : [
|
||||||
|
{
|
||||||
|
"item": "minecraft:diamond",
|
||||||
|
"count": 4
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue