Skip to content

Commit

Permalink
Add c:experience to the XP Fluid, and ensure Experience Holder can ac…
Browse files Browse the repository at this point in the history
…cept other fluids with that tag - Solves #164
  • Loading branch information
Direwolf20-MC committed Sep 18, 2024
1 parent 1bd8863 commit c59a73a
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// 1.21.1 2024-09-18T12:55:01.3643366 JustDireThings FluidTags
8ae2f887f0ec5e3342028a75a1076411a177ef9c data/c/tags/fluid/experience.json
6 changes: 6 additions & 0 deletions src/generated/resources/data/c/tags/fluid/experience.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"values": [
"justdirethings:xp_fluid_source",
"justdirethings:xp_fluid_flowing"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import com.direwolf20.justdirethings.common.capabilities.ExperienceHolderFluidTank;
import com.direwolf20.justdirethings.common.containers.handlers.PotionCanisterHandler;
import com.direwolf20.justdirethings.common.entities.DecoyEntity;
import com.direwolf20.justdirethings.common.fluids.xpfluid.XPFluid;
import com.direwolf20.justdirethings.common.items.FluidCanister;
import com.direwolf20.justdirethings.common.items.PortalGunV2;
import com.direwolf20.justdirethings.common.items.TimeWand;
import com.direwolf20.justdirethings.common.items.datacomponents.JustDireDataComponents;
import com.direwolf20.justdirethings.common.items.interfaces.PoweredItem;
import com.direwolf20.justdirethings.common.network.PacketHandler;
import com.direwolf20.justdirethings.datagen.JustDireFluidTags;
import com.direwolf20.justdirethings.setup.ClientSetup;
import com.direwolf20.justdirethings.setup.Config;
import com.direwolf20.justdirethings.setup.ModSetup;
Expand Down Expand Up @@ -303,7 +303,7 @@ public boolean canFillFluidType(FluidStack fluid) {
event.registerBlock(Capabilities.FluidHandler.BLOCK,
(level, pos, state, be, side) -> {
if (be instanceof ExperienceHolderBE experienceHolderBE) {
return new ExperienceHolderFluidTank(experienceHolderBE, fluidstack -> fluidstack.getFluid() instanceof XPFluid); //TODO Tags?
return new ExperienceHolderFluidTank(experienceHolderBE, fluidstack -> fluidstack.is(JustDireFluidTags.EXPERIENCE));
}
return null;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,11 @@ public int fill(FluidStack resource, FluidAction action) {
if (fluid.isEmpty()) {
return Math.min(capacity, resource.getAmount() - resource.getAmount() % 20);
}
if (!FluidStack.isSameFluidSameComponents(fluid, resource)) {
return 0;
}
return Math.min(capacity - getFluidAmount() - ((capacity - getFluidAmount()) % 20), resource.getAmount() - resource.getAmount() % 20);
}
if (fluid.isEmpty()) {
return resource.getAmount() - insertFluid(resource.getAmount());
}
if (!FluidStack.isSameFluidSameComponents(fluid, resource)) {
return 0;
}
int filled = resource.getAmount() - insertFluid(resource.getAmount());
if (filled > 0)
onContentsChanged();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public static void gatherData(GatherDataEvent event) {
List.of(new LootTableProvider.SubProviderEntry(JustDireLootTables::new, LootContextParamSets.BLOCK)), event.getLookupProvider()));
JustDireBlockTags blockTags = new JustDireBlockTags(packOutput, lookupProvider, event.getExistingFileHelper());
generator.addProvider(event.includeServer(), blockTags);
JustDireFluidTags fluidTags = new JustDireFluidTags(packOutput, lookupProvider, event.getExistingFileHelper());
generator.addProvider(event.includeServer(), fluidTags);
JustDireItemTags itemTags = new JustDireItemTags(packOutput, lookupProvider, blockTags, event.getExistingFileHelper());
generator.addProvider(event.includeServer(), itemTags);
JustDireDataMaps dataMaps = new JustDireDataMaps(packOutput, lookupProvider);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.direwolf20.justdirethings.datagen;

import com.direwolf20.justdirethings.JustDireThings;
import com.direwolf20.justdirethings.setup.Registration;
import net.minecraft.core.HolderLookup;
import net.minecraft.data.PackOutput;
import net.minecraft.data.tags.FluidTagsProvider;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.FluidTags;
import net.minecraft.tags.TagKey;
import net.minecraft.world.level.material.Fluid;
import net.neoforged.neoforge.common.data.ExistingFileHelper;
import org.jetbrains.annotations.Nullable;

import java.util.concurrent.CompletableFuture;

public class JustDireFluidTags extends FluidTagsProvider {

public static final TagKey<Fluid> EXPERIENCE = forgeTag("experience");

public JustDireFluidTags(PackOutput output, CompletableFuture<HolderLookup.Provider> lookupProvider, @Nullable ExistingFileHelper existingFileHelper) {
super(output, lookupProvider, JustDireThings.MODID, existingFileHelper);
}

private static TagKey<Fluid> forgeTag(String name) {
return FluidTags.create(ResourceLocation.fromNamespaceAndPath("c", name));
}

@Override
protected void addTags(HolderLookup.Provider provider) {
this.tag(EXPERIENCE)
.add(Registration.XP_FLUID_SOURCE.get())
.add(Registration.XP_FLUID_FLOWING.get());
}

@Override
public String getName() {
return "JustDireThings FluidTags";
}
}

0 comments on commit c59a73a

Please sign in to comment.