Skip to content

Commit

Permalink
diaaaaaazeeeeeeeeeepam
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoghurt4C committed Nov 28, 2020
1 parent 0d7896d commit 4cd50cc
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 14 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx1G
yarn_mappings=1.16.4+build.6
loader_version=0.10.6+build.214

mod_version = 0.6.0
mod_version = 0.6.1
maven_group = mod.codewarrior
archives_base_name = sips

Expand Down
1 change: 1 addition & 0 deletions src/main/java/mod/codewarrior/sips/items/SipsItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand han
}

private boolean attemptFill(World world, PlayerEntity user, ItemStack stack) {
if (FluidUtil.getAmount(stack) >= maxCapacity) return false;
BlockHitResult rtr = raycast(world, user, RaycastContext.FluidHandling.SOURCE_ONLY);
if (rtr.getType() == HitResult.Type.BLOCK) {
BlockPos blockPos = rtr.getBlockPos();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import mod.codewarrior.sips.SipsMod;
import mod.codewarrior.sips.config.SipsConfig;
import mod.codewarrior.sips.utils.Sippable;
import mod.codewarrior.sips.utils.SippableRegistryCallback;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.SimpleResourceReloadListener;
import net.minecraft.entity.player.PlayerEntity;
Expand Down Expand Up @@ -84,15 +85,7 @@ public CompletableFuture<Void> apply(Collection<Identifier> collection, Resource
}
});

//manual
if (SipsConfig.liquidXpHasEffect()) {
Sippable.fromPredicate("liquid_xp", new Sippable() {
@Override
public void onSipped(FluidKey drank, World world, PlayerEntity player) {
player.addExperience(7 + world.random.nextInt(5));
}
});
}
SippableRegistryCallback.EVENT.invoker().registerSippable();
}, executor);
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/mod/codewarrior/sips/registry/SipsEvents.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package mod.codewarrior.sips.registry;

import alexiil.mc.lib.attributes.fluid.volume.FluidKey;
import mod.codewarrior.sips.config.SipsConfig;
import mod.codewarrior.sips.utils.Sippable;
import mod.codewarrior.sips.utils.SippableRegistryCallback;
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.minecraft.block.Block;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -13,6 +17,17 @@

public class SipsEvents {
public static void init() {
SippableRegistryCallback.EVENT.register(() -> {
if (SipsConfig.liquidXpHasEffect()) {
Sippable.fromPredicate("liquid_xp", new Sippable() {
@Override
public void onSipped(FluidKey drank, World world, PlayerEntity player) {
player.addExperience(7 + world.random.nextInt(5));
}
});
}
});

UseBlockCallback.EVENT.register(((player, world, hand, rtr) -> {
ItemStack stack = player.getStackInHand(hand);
BlockPos pos = rtr.getBlockPos().offset(rtr.getSide());
Expand Down
24 changes: 20 additions & 4 deletions src/main/java/mod/codewarrior/sips/utils/Sippable.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ public class Sippable {

public List<Effect> effects = new ArrayList<>();

public Sippable() { /*override onSipped()*/ }
/**
* You can use either of these 3 constructors, depending on which values you want to change;
* The empty one is mainly for overriding {@link Sippable#onSipped(FluidKey, World, PlayerEntity)}
*/
public Sippable() {}

public Sippable(int shanks, float saturation, float damage) {
this.shanks = shanks;
Expand Down Expand Up @@ -116,6 +120,11 @@ public static void fromConfig(Map.Entry<String, JsonElement> entry) {
}
}

/**
* Queries the TagRegistry for a specified tag, then registers the given Sippable for all of its values.
* @param id the target Tag Identifier
* @param sippable Sippable object shared between the Tag's values
*/
public static void fromTag(Identifier id, Sippable sippable) {
Tag<Fluid> tag = ServerTagManagerHolder.getTagManager().getFluids().getTag(id);
if (tag != null && !tag.values().isEmpty()) {
Expand All @@ -128,6 +137,11 @@ public static void fromTag(Identifier id, Sippable sippable) {
}
}

/**
* Loops the registry using the given predicate, and registers the given Sippable for any match.
* @param predicate "id" of the target fluid(s)
* @param sippable Sippable object shared between them
*/
public static void fromPredicate(String predicate, Sippable sippable) {
Registry.FLUID.forEach(fluid -> {
if (Registry.FLUID.getId(fluid).getPath().equals(predicate)) {
Expand Down Expand Up @@ -218,9 +232,11 @@ public static Effect parseEffect(Map.Entry<String, JsonElement> effect) {
return new Effect(name, duration, level, showParticles, showIcon);
}

public void onSipped(FluidKey drank, World world, PlayerEntity player) {

}
/**
* Override this method to add custom effects to your Sippable without using StatusEffects
* Keep in mind that, for the time being, this only gets called serverside in SMP.
*/
public void onSipped(FluidKey drank, World world, PlayerEntity player) {}

public static class Effect {
Identifier name;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package mod.codewarrior.sips.utils;

import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;

public interface SippableRegistryCallback {

Event<SippableRegistryCallback> EVENT = EventFactory.createArrayBacked(SippableRegistryCallback.class, (listeners) -> () -> {
for (SippableRegistryCallback listener : listeners) {
listener.registerSippable();
}
});

void registerSippable();
}

0 comments on commit 4cd50cc

Please sign in to comment.