Skip to content

Commit

Permalink
Merge pull request #171 from ColinBashful/1.21
Browse files Browse the repository at this point in the history
Same as last one but with a few changes
  • Loading branch information
Globox1997 authored Jul 17, 2024
2 parents c5554f6 + 08d7773 commit bbf28cb
Show file tree
Hide file tree
Showing 22 changed files with 800 additions and 486 deletions.
8 changes: 6 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ processResources {
inputs.property "version", project.version

filesMatching("fabric.mod.json") {
expand "version": project.version, "fabric_version": project.fabric_version, "loader_version": project.loader_version, "minecraft_version": project.minecraft_version, "cloth_config_version": project.cloth_config_version
expand "version": project.version,
"fabric_version": project.fabric_version,
"loader_version": project.loader_version,
"minecraft_version": project.minecraft_version,
"cloth_config_version": project.cloth_config_version
}
}

Expand Down Expand Up @@ -82,4 +86,4 @@ publishing {

repositories {
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package net.dehydration.block;

import java.util.Map;

import net.dehydration.block.entity.CopperCauldronBehavior;
import net.dehydration.init.BlockInit;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorageUtil;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant;
import net.fabricmc.fabric.api.transfer.v1.storage.Storage;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
Expand All @@ -29,6 +31,8 @@
import net.minecraft.world.World;
import net.minecraft.world.WorldView;

import java.util.Map;

public abstract class AbstractCopperCauldronBlock extends Block {
private static final VoxelShape RAYCAST_SHAPE = createCuboidShape(2.0D, 4.0D, 2.0D, 14.0D, 16.0D, 14.0D);
protected static final VoxelShape OUTLINE_SHAPE;
Expand All @@ -49,8 +53,12 @@ protected boolean isEntityTouchingFluid(BlockState state, BlockPos pos, Entity e

@Override
protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
Storage<FluidVariant> storage = FluidStorage.SIDED.find(world, pos, hit.getSide().getOpposite());
if (storage != null && FluidStorageUtil.interactWithFluidStorage(storage, player, hand)) {
return ItemActionResult.success(world.isClient());
}
ItemStack itemStack = player.getStackInHand(hand);
CopperCauldronBehavior cauldronBehavior = (CopperCauldronBehavior) this.behaviorMap.get(itemStack.getItem());
CopperCauldronBehavior cauldronBehavior = this.behaviorMap.get(itemStack.getItem());
return cauldronBehavior.interact(state, world, pos, player, hand, itemStack);
}

Expand Down
20 changes: 12 additions & 8 deletions src/main/java/net/dehydration/block/BambooPumpBlock.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package net.dehydration.block;

import java.util.List;

import org.jetbrains.annotations.Nullable;

import com.mojang.serialization.MapCodec;

import net.dehydration.block.entity.BambooPumpEntity;
import net.dehydration.init.BlockInit;
import net.dehydration.init.ConfigInit;
import net.dehydration.init.ItemInit;
import net.dehydration.item.LeatherFlask;
import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant;
import net.fabricmc.fabric.api.transfer.v1.storage.Storage;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
Expand All @@ -31,8 +30,8 @@
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.loot.context.LootContextParameters;
import net.minecraft.loot.context.LootContextParameterSet.Builder;
import net.minecraft.loot.context.LootContextParameters;
import net.minecraft.registry.tag.FluidTags;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
Expand All @@ -54,6 +53,9 @@
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
import org.jetbrains.annotations.Nullable;

import java.util.List;

@SuppressWarnings("deprecation")
public class BambooPumpBlock extends BlockWithEntity {
Expand Down Expand Up @@ -87,7 +89,8 @@ public ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World w
ItemStack itemStack = bambooPumpEntity.getStack(0);
ItemStack itemStack2 = player.getStackInHand(hand);
if (itemStack.isEmpty()) {
if (itemStack2.isOf(Items.BUCKET) || itemStack2.isOf(Items.GLASS_BOTTLE) || (itemStack2.getItem() instanceof LeatherFlask && !LeatherFlask.isFlaskFull(itemStack2))) {
Storage<FluidVariant> storage = ContainerItemContext.withConstant(itemStack2).find(FluidStorage.ITEM);
if ((storage != null && storage.supportsInsertion()) || (itemStack2.getItem() instanceof LeatherFlask && !LeatherFlask.isFlaskFull(itemStack2))) {
if (!world.isClient()) {
if (player.isCreative()) {
bambooPumpEntity.setStack(0, itemStack2.copy());
Expand Down Expand Up @@ -118,7 +121,8 @@ public ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World w
}
return ItemActionResult.success(world.isClient());
}
if (itemStack.isOf(Items.BUCKET) || itemStack.isOf(Items.GLASS_BOTTLE) || (itemStack.getItem() instanceof LeatherFlask && !LeatherFlask.isFlaskFull(itemStack))) {
Storage<FluidVariant> storage = ContainerItemContext.withConstant(itemStack).find(FluidStorage.ITEM);
if ((storage != null && storage.supportsInsertion()) || (itemStack.getItem() instanceof LeatherFlask && !LeatherFlask.isFlaskFull(itemStack))) {
if (ConfigInit.CONFIG.pump_requires_water) {
boolean foundWater = false;
for (int i = 0; i < 50; i++) {
Expand Down
121 changes: 15 additions & 106 deletions src/main/java/net/dehydration/block/CampfireCauldronBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@

import net.dehydration.block.entity.CampfireCauldronEntity;
import net.dehydration.init.BlockInit;
import net.dehydration.init.ItemInit;
import net.dehydration.init.SoundInit;
import net.dehydration.item.LeatherFlask;
import net.dehydration.item.component.FlaskComponent;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.*;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorageUtil;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant;
import net.fabricmc.fabric.api.transfer.v1.storage.Storage;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockState;
import net.minecraft.block.CampfireBlock;
import net.minecraft.block.HorizontalFacingBlock;
import net.minecraft.block.ShapeContext;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.PotionContentsComponent;
import net.minecraft.entity.Entity;
import net.minecraft.entity.ai.pathing.NavigationType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.potion.Potions;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.IntProperty;
Expand Down Expand Up @@ -95,105 +96,13 @@ public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {

@Override
public ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
ItemStack itemStack = player.getStackInHand(hand);
CampfireCauldronEntity campfireCauldronEntity = (CampfireCauldronEntity) world.getBlockEntity(pos);
if (itemStack.isEmpty()) {
return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
} else {
int i = (Integer) state.get(LEVEL);
Item item = itemStack.getItem();
if (item == Items.WATER_BUCKET) {
if (i < 4 && !world.isClient()) {
if (!player.isCreative()) {
player.setStackInHand(hand, new ItemStack(Items.BUCKET));
}
campfireCauldronEntity.onFillingCauldron();
this.setLevel(world, pos, state, 4);
world.playSound(null, pos, SoundEvents.ITEM_BUCKET_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
return ItemActionResult.success(world.isClient());

} else if (item == Items.BUCKET) {
if (i == 4 && !world.isClient()) {
if (!player.isCreative()) {
itemStack.decrement(1);
if (itemStack.isEmpty()) {
player.setStackInHand(hand, new ItemStack(Items.WATER_BUCKET));
} else if (!player.getInventory().insertStack(new ItemStack(Items.WATER_BUCKET))) {
player.dropItem(new ItemStack(Items.WATER_BUCKET), false);
}
}
this.setLevel(world, pos, state, 0);
world.playSound(null, pos, SoundEvents.ITEM_BUCKET_FILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
if (!player.getStackInHand(hand).isEmpty()) {
Storage<FluidVariant> storage = FluidStorage.SIDED.find(world, pos, hit.getSide().getOpposite());
if (storage != null && FluidStorageUtil.interactWithFluidStorage(storage, player, hand)) {
return ItemActionResult.success(world.isClient());

} else {

ItemStack newItemStack;
if (item == Items.GLASS_BOTTLE) {
if (i > 0 && !world.isClient()) {
if (!player.isCreative()) {
itemStack.decrement(1);
if (this.isPurifiedWater(world, pos)) {
newItemStack = PotionContentsComponent.createStack(Items.POTION, ItemInit.PURIFIED_WATER);
} else {
newItemStack = PotionContentsComponent.createStack(Items.POTION, Potions.WATER);
}
if (player.getStackInHand(hand).isEmpty()) {
player.setStackInHand(hand, newItemStack);
} else if (!player.getInventory().insertStack(newItemStack)) {
player.dropItem(newItemStack, false);
}
}
world.playSound(null, pos, SoundEvents.ITEM_BOTTLE_FILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
this.setLevel(world, pos, state, i - 1);
}
return ItemActionResult.success(world.isClient());

} else if (item == Items.POTION && itemStack.get(DataComponentTypes.POTION_CONTENTS) != null && (itemStack.get(DataComponentTypes.POTION_CONTENTS).potion().get() == Potions.WATER
|| itemStack.get(DataComponentTypes.POTION_CONTENTS).potion().get() == ItemInit.PURIFIED_WATER)) {
if (i < 4 && !world.isClient()) {
if (!player.isCreative()) {
newItemStack = new ItemStack(Items.GLASS_BOTTLE);
player.setStackInHand(hand, newItemStack);
}
world.playSound(null, pos, SoundEvents.ITEM_BOTTLE_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F);
if (itemStack.get(DataComponentTypes.POTION_CONTENTS) != null && itemStack.get(DataComponentTypes.POTION_CONTENTS).potion().get() == Potions.WATER) {
campfireCauldronEntity.onFillingCauldron();
}
this.setLevel(world, pos, state, i + 1);
}
return ItemActionResult.success(world.isClient());

} else {
if (i > 0 && item instanceof LeatherFlask) {
FlaskComponent flaskComponent = itemStack.getOrDefault(ItemInit.FLASK_DATA, FlaskComponent.DEFAULT);
if (flaskComponent.fillLevel() < 2 + ((LeatherFlask) item).getExtraFillLevel()) {
int qualityLevel = 0;
if (this.isPurifiedWater(world, pos)) {
if ((flaskComponent.qualityLevel() == 0 || flaskComponent.fillLevel() == 0)) {
qualityLevel = 0;
} else {
qualityLevel = 1;
}
} else {
qualityLevel = 2;
}

itemStack.set(ItemInit.FLASK_DATA, new FlaskComponent(flaskComponent.fillLevel() + 1, qualityLevel));
this.setLevel(world, pos, state, i - 1);
world.playSound(null, pos, SoundInit.FILL_FLASK_EVENT, SoundCategory.NEUTRAL, 1.0F, 1.0F);
return ItemActionResult.success(world.isClient());
} else {
return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
}
} else {
return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
}
}
}
}
return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
}

public void setLevel(World world, BlockPos pos, BlockState state, int level) {
Expand Down
50 changes: 25 additions & 25 deletions src/main/java/net/dehydration/block/entity/BambooPumpEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@

import net.dehydration.init.BlockInit;
import net.dehydration.init.ConfigInit;
import net.dehydration.init.ItemInit;
import net.dehydration.item.LeatherFlask;
import net.dehydration.init.FluidInit;
import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidConstants;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant;
import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage;
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
import net.fabricmc.fabric.api.transfer.v1.storage.Storage;
import net.fabricmc.fabric.api.transfer.v1.storage.base.SingleSlotStorage;
import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.component.type.PotionContentsComponent;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventories;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
Expand Down Expand Up @@ -69,28 +75,22 @@ private void sendUpdate() {
}

private void updateInventory() {
if (!getStack(0).isEmpty()) {
ItemStack itemStack = getStack(0);
if (itemStack.isOf(Items.BUCKET)) {
if (pumpCount > 3) {
if (!this.world.isClient())
setStack(0, new ItemStack(ItemInit.PURIFIED_BUCKET));
pumpCount = 0;
cooldown = ConfigInit.CONFIG.pump_cooldown;
}
} else if (itemStack.isOf(Items.GLASS_BOTTLE)) {
if (!this.world.isClient()) {
setStack(0, PotionContentsComponent.createStack(Items.POTION, ItemInit.PURIFIED_WATER));
}
pumpCount = 0;
cooldown = ConfigInit.CONFIG.pump_cooldown;
} else if (itemStack.getItem() instanceof LeatherFlask) {
if (!this.world.isClient()) {
LeatherFlask.fillFlask(itemStack, 2);
setStack(0, itemStack);
ItemStack itemStack = getStack(0);
if (!itemStack.isEmpty()) {
Storage<FluidVariant> fluidStorage = null;
Storage<ItemVariant> itemStorage = ItemStorage.SIDED.find(this.world, this.pos, null);
if (itemStorage instanceof SingleSlotStorage<ItemVariant> singleSlotStorage) {
fluidStorage = ContainerItemContext.ofSingleSlot(singleSlotStorage).find(FluidStorage.ITEM);
}
if (fluidStorage != null && fluidStorage.supportsInsertion()) {
long amount = pumpCount * FluidConstants.BOTTLE * 2;
try (Transaction transaction = Transaction.openOuter()) {
if (fluidStorage.insert(FluidVariant.of(FluidInit.PURIFIED_WATER), amount, transaction) > 0) {
transaction.commit();
pumpCount = 0;
cooldown = ConfigInit.CONFIG.pump_cooldown;
}
}
pumpCount = 0;
cooldown = ConfigInit.CONFIG.pump_cooldown;
}
}
}
Expand Down
Loading

0 comments on commit bbf28cb

Please sign in to comment.