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.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<Random> randomSupplier, RenderContext context) {
|
||||
GenericFluidContainer<ItemStack> 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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<ItemStack> {
|
||||
|
||||
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<ItemStack> subItems) {
|
||||
if (!isIn(tab)) {
|
||||
|
@ -73,24 +56,21 @@ public class ItemDynamicCell extends Item implements GenericFluidContainer<ItemS
|
|||
}
|
||||
subItems.add(getEmptyCell(1));
|
||||
for (Fluid fluid : FluidUtils.getAllFluids()) {
|
||||
subItems.add(getCellWithFluid(fluid));
|
||||
if(fluid.isStill(fluid.getDefaultState())){
|
||||
subItems.add(getCellWithFluid(fluid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public String getTranslationKey(ItemStack stack) {
|
||||
// FluidStack fluidStack = getFluidHandler(stack).getFluidInstance();
|
||||
// if (fluidStack == null)
|
||||
// return super.getTranslationKey(stack);
|
||||
// return StringUtils.t("item.techreborn.cell.fluid.name").replaceAll("\\$fluid\\$", fluidStack.getLocalizedName());
|
||||
// }
|
||||
@Override
|
||||
public String getTranslationKey(ItemStack itemStack_1) {
|
||||
return super.getTranslationKey(itemStack_1);
|
||||
}
|
||||
|
||||
public static ItemStack getCellWithFluid(Fluid fluid, int stackSize) {
|
||||
Validate.notNull(fluid);
|
||||
ItemStack stack = new ItemStack(TRContent.CELL);
|
||||
GenericFluidContainer<ItemStack> 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<ItemS
|
|||
return getCellWithFluid(fluid, 1);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setFluid(ItemStack type, FluidInstance instance) {
|
||||
Validate.notNull(type, "ItemStack cannot be null!");
|
||||
CompoundTag compoundTag = new CompoundTag();
|
||||
instance.toTag(compoundTag);
|
||||
ItemNBTHelper.getNBT(type).put("fluid", compoundTag);
|
||||
public ItemStack getEmpty() {
|
||||
return new ItemStack(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidInstance getFluidInstance(ItemStack type) {
|
||||
Validate.notNull(type, "ItemStack cannot be null!");
|
||||
if(ItemNBTHelper.getNBT(type).containsKey("fluid")){
|
||||
CompoundTag compoundTag = ItemNBTHelper.getNBT(type).getCompound("fluid");
|
||||
return new FluidInstance(compoundTag);
|
||||
public ItemStack getFull(Fluid fluid) {
|
||||
return getCellWithFluid(fluid);
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity(ItemStack type) {
|
||||
Validate.notNull(type, "ItemStack cannot be null!");
|
||||
return CAPACITY;
|
||||
return Fluids.EMPTY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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…
Reference in a new issue