more misc fluid work, gonna leave most of this untill we have an offical or new api
This commit is contained in:
parent
0742abb840
commit
6a93c3fd46
28 changed files with 147 additions and 404 deletions
src/main/java/techreborn/items
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.items;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import techreborn.utils.FluidUtils;
|
||||
|
||||
public class ItemCells {
|
||||
public static ItemStack getCellByName(String name, int count) {
|
||||
if (name.equalsIgnoreCase("empty") || name.equalsIgnoreCase("cell")) {
|
||||
return ItemDynamicCell.getEmptyCell(count).copy();
|
||||
}
|
||||
Fluid fluid = FluidUtils.getFluid("fluid" + name.toLowerCase());
|
||||
if (fluid == null) {
|
||||
fluid = FluidUtils.getFluid(name.toLowerCase());
|
||||
if (fluid == null) {
|
||||
fluid = FluidUtils.getFluid(name.toLowerCase());
|
||||
}
|
||||
}
|
||||
Validate.notNull(fluid, "The fluid " + name + " could not be found");
|
||||
return ItemDynamicCell.getCellWithFluid(fluid, count);
|
||||
}
|
||||
|
||||
public static ItemStack getCellByName(String name) {
|
||||
return getCellByName(name, 1);
|
||||
}
|
||||
|
||||
public static boolean isCellEqual(ItemStack stack1, ItemStack stack2){
|
||||
if(stack1 == null || stack2 == null){
|
||||
return false;
|
||||
}
|
||||
if(stack1.isEmpty() || stack2.isEmpty()){
|
||||
return false;
|
||||
}
|
||||
if(stack1.getTag() == null || stack2.getTag() == null){
|
||||
return false;
|
||||
}
|
||||
return stack1.getTag().equals(stack2.getTag());
|
||||
}
|
||||
|
||||
}
|
|
@ -24,17 +24,17 @@
|
|||
|
||||
package techreborn.items;
|
||||
|
||||
import io.github.prospector.silk.fluid.FluidInstance;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
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.util.registry.Registry;
|
||||
import net.minecraft.world.World;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import reborncore.common.fluid.container.GenericFluidContainer;
|
||||
import reborncore.common.util.ItemNBTHelper;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.TRContent;
|
||||
|
@ -43,12 +43,12 @@ import techreborn.utils.FluidUtils;
|
|||
/**
|
||||
* Created by modmuss50 on 17/05/2016.
|
||||
*/
|
||||
public class ItemDynamicCell extends Item {
|
||||
public class ItemDynamicCell extends Item implements GenericFluidContainer<ItemStack> {
|
||||
|
||||
public static final int CAPACITY = 1000;
|
||||
|
||||
public ItemDynamicCell() {
|
||||
super(new Item.Settings().group(TechReborn.ITEMGROUP));
|
||||
super(new Item.Settings().maxCount(1).group(TechReborn.ITEMGROUP));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -66,8 +66,6 @@ public class ItemDynamicCell extends Item {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void appendStacks(ItemGroup tab, DefaultedList<ItemStack> subItems) {
|
||||
if (!isIn(tab)) {
|
||||
|
@ -81,22 +79,18 @@ public class ItemDynamicCell extends Item {
|
|||
|
||||
// @Override
|
||||
// public String getTranslationKey(ItemStack stack) {
|
||||
// FluidStack fluidStack = getFluidHandler(stack).getFluid();
|
||||
// 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 ICapabilityProvider initCapabilities(ItemStack stack, CompoundTag nbt) {
|
||||
// return getFluidHandler(stack);
|
||||
// }
|
||||
//
|
||||
|
||||
public static ItemStack getCellWithFluid(Fluid fluid, int stackSize) {
|
||||
Validate.notNull(fluid);
|
||||
ItemStack stack = new ItemStack(TRContent.CELL);
|
||||
ItemNBTHelper.getNBT(stack).putString("fluid", Registry.FLUID.getId(fluid).toString());
|
||||
GenericFluidContainer<ItemStack> fluidContainer = GenericFluidContainer.fromStack(stack);
|
||||
Validate.notNull(fluidContainer);
|
||||
fluidContainer.setFluid(stack, new FluidInstance(fluid, fluidContainer.getCapacity(stack)));
|
||||
stack.setCount(stackSize);
|
||||
return stack;
|
||||
}
|
||||
|
@ -110,4 +104,27 @@ public class ItemDynamicCell extends Item {
|
|||
}
|
||||
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
return new FluidInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity(ItemStack type) {
|
||||
Validate.notNull(type, "ItemStack cannot be null!");
|
||||
return CAPACITY;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue