Skip to content

Commit

Permalink
add hopper fluid pickup, update item textures and other jazz
Browse files Browse the repository at this point in the history
  • Loading branch information
enjarai committed Apr 20, 2022
1 parent 58c870c commit 3ba7355
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 18 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
- Edit Fluid Hopper recipe to make sense
- The Fluid Hopper and Omni-Hopper can now pick up liquids from the world or waterlogged blocks
- Edit Fluid Hopper recipe to make sense
- Added an exception for insertion and extraction amounts from cauldrons, this way lava can be transported between cauldrons without issues
- Update item textures for Fluid Hoppers to not look like clay
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ repositories {
includeGroup "curse.maven"
}
}

// for ARRP
maven {
url "https://storage.googleapis.com/devan-maven/"
}
}

dependencies {
Expand All @@ -37,6 +42,9 @@ dependencies {

// Include Cooldown Coordinator 0.3.0 via cursemaven
include(modImplementation("curse.maven:cooldown-coordinator-594072:3757479"))

// Include ARRP
include(modImplementation("net.devtech:arrp:${project.arrp_version}"))
}

processResources {
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.13.3

# Mod Properties
mod_version = 1.1.0
mod_version = 1.1.1
maven_group = nl.enjarai
archives_base_name = omnihopper

# Dependencies
fabric_version=0.47.8+1.18.2
cooldowncoordinator_version=0.2.1
arrp_version=0.5.7
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class FluidOmniHopperBlock extends OmniHopperBlock {
public FluidOmniHopperBlock(Settings settings) {
super(settings);
}
// TODO add oxidization and use datagen for models

@Nullable
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant;
import net.fabricmc.fabric.api.transfer.v1.storage.Storage;
import net.fabricmc.fabric.api.transfer.v1.storage.base.SingleVariantStorage;
import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.CauldronBlock;
import net.minecraft.block.FluidDrainable;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.fluid.Fluids;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -71,14 +76,33 @@ public void readNbt(NbtCompound tag) {
}

@Override
protected long getAmountPerActivation() {
return FluidConstants.BUCKET / 2;
protected long getAmountPerActivation(BlockState targetState) {
return FluidConstants.BUCKET / (targetState.isOf(Blocks.CAULDRON) ? 1 : 4);
}

@Override
protected boolean pickupInWorldObjects(World world, BlockPos pos, Direction suckyDirection) {
// TODO pickup source blocks from world
return super.pickupInWorldObjects(world, pos, suckyDirection);
var fluidPos = pos.offset(suckyDirection);
var fluid = world.getFluidState(fluidPos);
var state = world.getBlockState(fluidPos);

if (fluid.isStill() && state.getBlock() instanceof FluidDrainable drainable) {
try (var transaction = Transaction.openOuter()) {
long inserted = getStorage().insert(
FluidVariant.of(fluid.getFluid()),
FluidConstants.BUCKET,
transaction
);

if (inserted == FluidConstants.BUCKET && !drainable.tryDrainFluid(world, fluidPos, state).isEmpty()) {
transaction.commit();

return true;
}
}
}

return false;
}

@Override
Expand Down
26 changes: 15 additions & 11 deletions src/main/java/nl/enjarai/omnihopper/blocks/HopperBlockEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
import net.minecraft.nbt.NbtCompound;
import net.minecraft.screen.NamedScreenHandlerFactory;
import net.minecraft.text.Text;
import net.minecraft.util.Nameable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;

import static nl.enjarai.omnihopper.blocks.OmniHopperBlock.POINTY_BIT;
import static nl.enjarai.omnihopper.blocks.OmniHopperBlock.SUCKY_BIT;
import org.jetbrains.annotations.Nullable;

@SuppressWarnings("UnstableApiUsage")
public abstract class HopperBlockEntity<T> extends BlockEntity implements CoordinatedCooldown, NamedScreenHandlerFactory {
public abstract class HopperBlockEntity<T> extends BlockEntity implements CoordinatedCooldown, NamedScreenHandlerFactory, Nameable {
protected int transferCooldown;
protected long lastTickTime;
private Text customName;
Expand Down Expand Up @@ -88,13 +87,13 @@ protected boolean insert(World world, BlockPos pos, BlockState state) {
Storage<T> target = getBlockApiLookup().find(world, targetPos, direction.getOpposite());

if (target != null) {
BlockEntity blockEntityTarget = world.getBlockEntity(pos.offset(direction));
BlockEntity blockEntityTarget = world.getBlockEntity(targetPos);
boolean targetEmpty = StorageUtil.findStoredResource(target, null) == null;
if (StorageUtil.move(
getStorage(),
target,
iv -> true,
getAmountPerActivation(),
getAmountPerActivation(world.getBlockState(targetPos)),
null
) == 1) {
if (targetEmpty) {
Expand All @@ -108,14 +107,15 @@ protected boolean insert(World world, BlockPos pos, BlockState state) {

protected boolean extract(World world, BlockPos pos, BlockState state) {
Direction suckyDirection = getSuckyDirection(state);
Storage<T> source = getBlockApiLookup().find(world, pos.add(suckyDirection.getVector()), suckyDirection.getOpposite());
BlockPos targetPos = pos.offset(suckyDirection);
Storage<T> source = getBlockApiLookup().find(world, targetPos, suckyDirection.getOpposite());

if (source != null) {
long moved = StorageUtil.move(
source,
getStorage(),
iv -> true,
getAmountPerActivation(),
getAmountPerActivation(world.getBlockState(targetPos)),
null
);
return moved >= 1;
Expand Down Expand Up @@ -143,13 +143,17 @@ public void notifyCooldown() {
this.markDirty();
}

protected abstract long getAmountPerActivation();
protected abstract long getAmountPerActivation(BlockState targetState);

public abstract Text getName();
@Nullable
@Override
public Text getCustomName() {
return customName;
}

@Override
public Text getDisplayName() {
return this.customName != null ? this.customName : this.getName();
return getCustomName() != null ? getCustomName() : getName();
}

protected void setTransferCooldown(int transferCooldown) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Storage<ItemVariant> getStorage() {
}

@Override
protected long getAmountPerActivation() {
protected long getAmountPerActivation(BlockState targetState) {
return 1;
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3ba7355

Please sign in to comment.