Skip to content

Commit

Permalink
Actually add isPresent method to lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
CodexAdrian committed May 4, 2024
1 parent f96a495 commit 9742af2
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 21 deletions.
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Port to 1.20.6 (anything more detailed would give me an anuerism, i rewrote the mod)
Added `isPresent` method to lookups
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.msrandom.multiplatform.annotations.Expect;
import org.jetbrains.annotations.Nullable;

@SuppressWarnings("NoMatchingActual")
@Expect
public class ItemApi {
public static final BlockLookup<CommonStorage<ItemResource>, @Nullable Direction> BLOCK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.util.function.Supplier;

@SuppressWarnings("ALL")
@Expect
public final class DataManagerRegistry {
public static DataManagerRegistry create(String modid);
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ org.gradle.parallel=true

enabledPlatforms=fabric,neoforge

version=3.0.0
version=4.0.0
group=earth.terrarium.botarium

minecraftVersion=1.20.6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ default T find(Level level, BlockPos pos, @Nullable C direction) {
return find(level, pos, null, null, direction);
}

default boolean isPresent(Level level, BlockPos pos, @Nullable BlockState state, @Nullable BlockEntity entity, @Nullable C direction) {
return find(level, pos, state, entity, direction) != null;
}

default boolean isPresent(BlockEntity block, @Nullable C direction) {
return find(block, direction) != null;
}

default void registerSelf(BlockGetter<T, C> getter, Block ... blocks) {
onRegister(registrar -> registrar.registerBlocks(getter, blocks));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ static <T> EntityLookup<T, Direction> createAutomation(ResourceLocation name, Cl
@Nullable
T find(Entity entity, C context);

default boolean isPresent(Entity entity, C context) {
return find(entity, context) != null;
}

default void registerFallback(EntityGetter<T, C> getter) {
onRegister(registrar -> {
for (EntityType<?> entityType : BuiltInRegistries.ENTITY_TYPE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ static <T> ItemLookup<T, Void> create(ResourceLocation name, Class<T> typeClass)
@Nullable
T find(ItemStack stack, C context);

default boolean isPresent(ItemStack stack, C context) {
return find(stack, context) != null;
}

default void registerSelf(ItemGetter<T, C> getter, Item ... items) {
onRegister(registrar -> registrar.register(getter, items));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@

@SuppressWarnings("ALL")
public final class FluidAmounts {
private FluidAmounts() {
}

@Expect
public static long toPlatformAmount(long millibuckets);

@Expect
public static long toMillibuckets(long platformAmount);

@Expect
public static final long BUCKET;

Expand All @@ -27,4 +18,13 @@ private FluidAmounts() {

@Expect
public static final long NUGGET;

private FluidAmounts() {
}

@Expect
public static long toPlatformAmount(long millibuckets);

@Expect
public static long toMillibuckets(long platformAmount);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@
import net.msrandom.multiplatform.annotations.Actual;

public class FluidAmountsActual {
@Actual
public static long toPlatformAmount(long millibuckets) {
return FluidConstants.fromBucketFraction(millibuckets, 1000);
}

@Actual
public static long toMillibuckets(long platformAmount) {
return (platformAmount * 1000) / FluidConstants.BUCKET;
}

@Actual
public static final long BUCKET = FluidConstants.BUCKET;

Expand All @@ -28,4 +18,14 @@ public static long toMillibuckets(long platformAmount) {

@Actual
public static final long NUGGET = FluidConstants.NUGGET;

@Actual
public static long toPlatformAmount(long millibuckets) {
return FluidConstants.fromBucketFraction(millibuckets, 1000);
}

@Actual
public static long toMillibuckets(long platformAmount) {
return (platformAmount * 1000) / FluidConstants.BUCKET;
}
}

0 comments on commit 9742af2

Please sign in to comment.