Skip to content

Commit

Permalink
improved interaction with sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
MEGATREX4 committed Jul 9, 2024
1 parent 536c25f commit 0d7a2e1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class BrewingKegBlock extends BlockWithEntity implements BlockEntityProvi
public static final int INVENTORY_SIZE = OUTPUT_SLOT + 1;


private static final VoxelShape SHAPE = Block.createCuboidShape(0, 0, 0, 16, 12, 16);
private static final VoxelShape SHAPE = Block.createCuboidShape(0, 0, 0, 16, 13, 16);
public static final DirectionProperty FACING;

public BrewingKegBlock(Settings settings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.megatrex4.ukrainian_dlight.screen.BrewingKegScreenHandler;
import com.megatrex4.ukrainian_dlight.util.FluidStack;
import com.nhoryzon.mc.farmersdelight.FarmersDelightMod;
import com.nhoryzon.mc.farmersdelight.entity.block.CookingPotBlockEntity;
import com.nhoryzon.mc.farmersdelight.registry.ParticleTypesRegistry;
import com.nhoryzon.mc.farmersdelight.util.CompoundTagUtils;
import io.netty.buffer.Unpooled;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
Expand Down Expand Up @@ -39,17 +41,21 @@
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.recipe.Ingredient;
import net.minecraft.recipe.Recipe;
import net.minecraft.screen.PropertyDelegate;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.ItemScatterer;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.*;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -368,6 +374,7 @@ public void tick(World world, BlockPos pos, BlockState state) {
handleWaterBucket();
processItemTransfer(world, pos, state);
processCrafting();
spawnParticles(world, pos, state);
}

private void processItemTransfer(World world, BlockPos pos, BlockState state) {
Expand Down Expand Up @@ -439,6 +446,8 @@ private void processCrafting() {
int craftedAmount = 1;
if (this.craftItem(recipe, craftedAmount)) { // Provide craftedAmount here
this.resetProgress();
// Play brewing sound effect
playBrewingSound();
}
} else {
this.resetProgress();
Expand All @@ -448,6 +457,26 @@ private void processCrafting() {
}
}

private void playBrewingSound() {
if (world != null && !world.isClient) {
world.playSound(null, pos, SoundEvents.BLOCK_BREWING_STAND_BREW, SoundCategory.BLOCKS, 1.0f, 1.0f);
}
}

public static void spawnParticles(World world, BlockPos pos, BlockState state) {
if (world != null && !world.isClient) {
Random random = world.random;
if (random.nextFloat() < .05f) {
double baseX = pos.getX() + .5d + (random.nextDouble() * .4d - .2d);
double baseY = pos.getY() + .5d;
double baseZ = pos.getZ() + .5d + (random.nextDouble() * .4d - .2d);
double motionY = random.nextBoolean() ? .015d : .005d;
world.addParticle(ParticleTypesRegistry.STEAM.get(), baseX, baseY, baseZ, .0d, motionY, .0d);
}
}
}



private boolean hasValidIngredients(BrewingRecipe recipe) {
List<ItemStack> ingredients = new ArrayList<>();
Expand Down Expand Up @@ -509,6 +538,11 @@ private void handleWaterBucket() {
transaction.commit();
markDirty();
sendFluidPacket();

// Play water pouring sound effect
if (!this.world.isClient) {
this.world.playSound(null, this.pos, SoundEvents.ITEM_BUCKET_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
}
}
}
Expand Down Expand Up @@ -592,7 +626,7 @@ private boolean craftItem(BrewingRecipe recipe, int craftedAmount) {
if (this.progress < this.maxProgress) {
return false;
} else {
this.progress = 0;; // Ensure a copy is made to avoid side effects
this.progress = 0; // Ensure a copy is made to avoid side effects
ItemStack recipeOutput = recipe.craft(this, this.world.getRegistryManager());
ItemStack currentOutput = this.getStack(DRINKS_DISPLAY_SLOT);
drinkContainer = recipe.getContainer().copy();
Expand Down Expand Up @@ -621,6 +655,8 @@ private boolean craftItem(BrewingRecipe recipe, int craftedAmount) {
float totalExperience = recipeExperience * craftedAmount;
this.trackRecipeExperience(totalExperience);

this.world.playSound(null, this.pos, SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, SoundCategory.BLOCKS, 1.0F, 1.0F);

markDirty();
return true;
}
Expand Down

0 comments on commit 0d7a2e1

Please sign in to comment.