Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
updated antimatter, made drum item be an actual fluid storage item
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Oct 7, 2023
1 parent 57d6444 commit a11d078
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import earth.terrarium.botarium.common.fluid.base.FluidHolder;
import earth.terrarium.botarium.common.fluid.base.PlatformFluidHandler;
import earth.terrarium.botarium.common.fluid.utils.FluidHooks;
import earth.terrarium.botarium.common.item.ItemStackHolder;
import io.github.gregtechintergalactical.gtutility.machine.DrumMachine;
import muramasa.antimatter.Ref;
import muramasa.antimatter.capability.fluid.FluidTank;
import muramasa.antimatter.capability.fluid.FluidTanks;
import muramasa.antimatter.capability.machine.MachineFluidHandler;
import muramasa.antimatter.data.AntimatterTags;
import muramasa.antimatter.machine.event.ContentEvent;
import muramasa.antimatter.gui.SlotType;
import muramasa.antimatter.tool.AntimatterToolType;
import muramasa.antimatter.util.AntimatterPlatformUtils;
import muramasa.antimatter.util.Utils;
Expand All @@ -25,6 +26,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
Expand Down Expand Up @@ -84,8 +86,9 @@ public void onDrop(BlockState state, LootContext.Builder builder, List<ItemStack
if (!drops.isEmpty()){
ItemStack stack = drops.get(0);
if (!getDrop().isEmpty()){
CompoundTag nbt = stack.getOrCreateTag();
nbt.put("Fluid", getDrop().serialize());
ItemStackHolder holder = new ItemStackHolder(stack);
FluidHooks.safeGetItemFluidManager(stack).ifPresent(f -> f.insertFluid(holder, drop, false));
stack = holder.getStack();
}
if (isOutput()){
CompoundTag nbt = stack.getOrCreateTag();
Expand All @@ -99,7 +102,7 @@ public void onPlacedBy(Level world, BlockPos pos, BlockState state, @org.jetbrai
CompoundTag nbt = stack.getTag();
if (nbt != null && (nbt.contains("Fluid") || nbt.contains("Outputs"))){
this.fluidHandler.ifPresent(f -> {
FluidHolder fluid = nbt.contains("Fluid") ? FluidHooks.fluidFromCompound(nbt.getCompound("Fluid")) : FluidHooks.emptyFluid();
FluidHolder fluid = nbt.contains("Fluid") ? FluidHooks.fluidFromCompound(nbt.getCompound("Fluid")) : FluidHooks.safeGetItemFluidManager(stack).map(fi -> fi.getFluidInTank(0)).orElse(FluidHooks.emptyFluid());
if (!fluid.isEmpty()){
f.insertFluid(fluid, false);
}
Expand Down Expand Up @@ -133,7 +136,7 @@ public static class DrumFluidHandler extends MachineFluidHandler<BlockEntityDrum
boolean output = false;
public DrumFluidHandler(BlockEntityDrum tile) {
super(tile);
tanks.put(FluidDirection.INPUT, FluidTanks.create(tile, ContentEvent.FLUID_INPUT_CHANGED, b -> {
tanks.put(FluidDirection.INPUT, FluidTanks.create(tile, SlotType.FL_IN, b -> {
b.tank(((DrumMachine)tile.getMachineType()).maxCapacity);
return b;
}));
Expand Down Expand Up @@ -202,7 +205,10 @@ public boolean canInput(FluidHolder fluid, Direction direction) {
@Override
public long insertFluid(FluidHolder fluid, boolean simulate) {
if (tile.getMachineType() instanceof DrumMachine drumMachine && !drumMachine.isAcidProof() && fluid.getFluid().is(AntimatterTags.ACID)){
return 0;
if (!simulate) {
tile.getLevel().setBlock(tile.getBlockPos(), Blocks.AIR.defaultBlockState(), 3);
}
return Math.min(16L, fluid.getFluidAmount());
}
return super.insertFluid(fluid, simulate);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@
import muramasa.antimatter.capability.item.EmptyContainer;
import muramasa.antimatter.gui.SlotType;
import muramasa.antimatter.gui.slot.AbstractSlot;
import muramasa.antimatter.machine.event.ContentEvent;
import muramasa.antimatter.tool.IAntimatterTool;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.entity.BlockEntity;
import tesseract.TesseractCapUtils;

public class SlotTypes {
public static SlotType<AbstractSlot<?>> TOOLS = new SlotType<>("tools", (type, gui, item, i, d) -> new AbstractSlot<>(type, gui, item.getOrDefault(type, new EmptyContainer()), i, d.getX(), d.getY()), (t, i) -> i.getItem() instanceof IAntimatterTool || i.getItem().canBeDepleted(), ContentEvent.ITEM_INPUT_CHANGED);
public static SlotType<AbstractSlot<?>> TOOLS = new SlotType<>("tools", (type, gui, item, i, d) -> new AbstractSlot<>(type, gui, item.getOrDefault(type, new EmptyContainer()), i, d.getX(), d.getY()), (t, i) -> i.getItem() instanceof IAntimatterTool || i.getItem().canBeDepleted());
public static SlotType<AbstractSlot<?>> TOOL_CHARGE = new SlotType<>("tool_charge", (type, gui, item, i, d) -> new AbstractSlot<>(type,gui, item.getOrDefault(type, new EmptyContainer()), i, d.getX(), d.getY()), (t, i) -> {
if (t instanceof BlockEntity tile) {
return TesseractCapUtils.getEnergyHandler(tile, null).map(eh -> TesseractCapUtils.getEnergyHandlerItem(i).map(inner -> ((inner.getInputVoltage() | inner.getOutputVoltage()) <= (eh.getInputVoltage() | eh.getOutputVoltage()) )).orElse(false)).orElse(false) || i.getItem() instanceof IAntimatterTool || i.getItem().canBeDepleted();
}
return true;
}, ContentEvent.ITEM_INPUT_CHANGED, true, true, new ResourceLocation(GTUtility.ID, "electric_tool"));
public static SlotType<SlotCrafting> CRAFTING = new SlotType<>("crafting", (type, gui, item, i, d) -> new SlotCrafting(type, gui, item.getOrDefault(type, new EmptyContainer()), i, d.getX(), d.getY()), (t, i) -> true, ContentEvent.ITEM_INPUT_CHANGED, false, true);
public static SlotType<AbstractSlot<?>> PARK = new SlotType<>("park", (type, gui, item, i, d) -> new AbstractSlot<>(type, gui, item.getOrDefault(type, new EmptyContainer()), i, d.getX(), d.getY()), (t, i) -> true, ContentEvent.ITEM_INPUT_CHANGED, true, true, new ResourceLocation(GTUtility.ID, "park"));
}, true, true, new ResourceLocation(GTUtility.ID, "electric_tool"));
public static SlotType<SlotCrafting> CRAFTING = new SlotType<>("crafting", (type, gui, item, i, d) -> new SlotCrafting(type, gui, item.getOrDefault(type, new EmptyContainer()), i, d.getX(), d.getY()), (t, i) -> true, false, true);
public static SlotType<AbstractSlot<?>> PARK = new SlotType<>("park", (type, gui, item, i, d) -> new AbstractSlot<>(type, gui, item.getOrDefault(type, new EmptyContainer()), i, d.getX(), d.getY()), (t, i) -> true, true, true, new ResourceLocation(GTUtility.ID, "park"));

public static void init(){

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.github.gregtechintergalactical.gtutility.item;

import earth.terrarium.botarium.common.fluid.base.FluidHolder;
import io.github.gregtechintergalactical.gtutility.machine.DrumMachine;
import muramasa.antimatter.block.AntimatterItemBlock;
import muramasa.antimatter.data.AntimatterTags;
import muramasa.antimatter.item.IFluidItem;
import muramasa.antimatter.machine.BlockMachine;
import tesseract.TesseractGraphWrappers;

import java.util.function.BiPredicate;

public class ItemBlockDrum extends AntimatterItemBlock implements IFluidItem {
final DrumMachine machine;
public ItemBlockDrum(BlockMachine block) {
super(block);
if (block.getType() instanceof DrumMachine machine){
this.machine = machine;
} else {
machine = null;
}
}

@Override
public long getTankSize() {
if (machine != null) return machine.maxCapacity * TesseractGraphWrappers.dropletMultiplier;
return 0;
}

@Override
public BiPredicate<Integer, FluidHolder> getFilter() {
return (i, f) -> {
if (machine != null && !machine.isAcidProof() && f.getFluid().is(AntimatterTags.ACID)) return false;
return true;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import earth.terrarium.botarium.common.fluid.utils.FluidHooks;
import io.github.gregtechintergalactical.gtutility.GTUtility;
import io.github.gregtechintergalactical.gtutility.blockentity.BlockEntityDrum;
import io.github.gregtechintergalactical.gtutility.item.ItemBlockDrum;
import muramasa.antimatter.AntimatterAPI;
import muramasa.antimatter.machine.Tier;
import muramasa.antimatter.material.Material;
Expand All @@ -25,14 +26,15 @@ public DrumMachine(String domain, Material material, int maxCapacity) {
setTiers(Tier.NONE);
this.setTile(((materialMachine, blockPos, blockState) -> new BlockEntityDrum(this, blockPos, blockState)));
setBlock((type, tier) -> new BlockMachineMaterial(type, tier, BlockBehaviour.Properties.of(WRENCH_MATERIAL).strength(1.0f, 10.0f)));
setItemBlock(ItemBlockDrum::new);
setTooltipInfo((machine, stack, world, tooltip, flag) -> {
tooltip.add(new TranslatableComponent("machine.drum.capacity", maxCapacity));
if (acidProof){
tooltip.add(new TranslatableComponent("antimatter.tooltip.acid_proof"));
}
CompoundTag nbt = stack.getTag();
if (nbt != null && (nbt.contains("Fluid") || nbt.contains("Outputs"))){
FluidHolder fluid = nbt.contains("Fluid") ? FluidHooks.fluidFromCompound(nbt.getCompound("Fluid")) : FluidHooks.emptyFluid();
FluidHolder fluid = nbt.contains("Fluid") ? FluidHooks.fluidFromCompound(nbt.getCompound("Fluid")) : FluidHooks.safeGetItemFluidManager(stack).map(fi -> fi.getFluidInTank(0)).orElse(FluidHooks.emptyFluid());
if (!fluid.isEmpty()){
tooltip.add(new TranslatableComponent("machine.drum.fluid", fluid.getFluidAmount(), FluidPlatformUtils.getFluidDisplayName(fluid)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
import com.teamresourceful.resourcefullib.common.networking.base.PacketContext;
import com.teamresourceful.resourcefullib.common.networking.base.PacketHandler;
import io.github.gregtechintergalactical.gtutility.GTUtility;
import muramasa.antimatter.network.packets.IAntimatterPacket;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.inventory.AbstractContainerMenu;

public class MessageCraftingSync implements Packet<MessageCraftingSync> {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ forge_version=40.2.4
fabric_api_version=0.57.0+1.18.2
fabric_loader_version=0.14.6

antimatter_version=0.2-rc47-1.18.2
antimatter_version=0.2-rc55-1.18.2
tesseract_version=0.2-1.18.2
jei_version=10.1.0.223
rei_version=8.3.557
Expand All @@ -23,4 +23,4 @@ top_file=3157997

maven_group=io.github.gregtechintergalactical
archive_base_name=gtutility
mod_version=0.1-pre15
mod_version=0.1-pre16

0 comments on commit a11d078

Please sign in to comment.