diff --git a/projectfiles/brewing_keg_gui_v2.psd b/projectfiles/brewing_keg_gui_v2.psd new file mode 100644 index 0000000..663c678 Binary files /dev/null and b/projectfiles/brewing_keg_gui_v2.psd differ diff --git a/projectfiles/generate_jarring/jarring.py b/scripts/jarring.py similarity index 100% rename from projectfiles/generate_jarring/jarring.py rename to scripts/jarring.py diff --git a/src/main/java/com/megatrex4/ukrainian_dlight/block/custom/BrewingKegBlock.java b/src/main/java/com/megatrex4/ukrainian_dlight/block/custom/BrewingKegBlock.java index 4665e7c..8fe2f7f 100644 --- a/src/main/java/com/megatrex4/ukrainian_dlight/block/custom/BrewingKegBlock.java +++ b/src/main/java/com/megatrex4/ukrainian_dlight/block/custom/BrewingKegBlock.java @@ -20,11 +20,14 @@ import net.minecraft.inventory.Inventories; import net.minecraft.item.ItemPlacementContext; import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtElement; import net.minecraft.particle.ParticleTypes; import net.minecraft.registry.Registries; import net.minecraft.screen.NamedScreenHandlerFactory; +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.EnumProperty; @@ -233,14 +236,90 @@ public static void spawnParticles(World world, BlockPos pos, BlockState state) { @Override public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { if (!world.isClient) { - NamedScreenHandlerFactory screenHandlerFactory = state.createScreenHandlerFactory(world, pos); - if (screenHandlerFactory != null) { - player.openHandledScreen(screenHandlerFactory); + BrewingKegBlockEntity blockEntity = (BrewingKegBlockEntity) world.getBlockEntity(pos); + if (blockEntity == null) { + return ActionResult.PASS; } + + if (hand == Hand.MAIN_HAND) { + ItemStack heldItem = player.getStackInHand(hand); + if (heldItem.isOf(Items.WATER_BUCKET)) { + return handleWaterBucket(world, pos, player, hand, blockEntity); + } else { + return handleContainerFill(world, pos, player, hand, blockEntity); + } + } + + openScreenForPlayer(state, world, pos, player); } return ActionResult.SUCCESS; } + private ActionResult handleWaterBucket(World world, BlockPos pos, PlayerEntity player, Hand hand, BrewingKegBlockEntity blockEntity) { + ItemStack heldItem = player.getStackInHand(hand); + long waterAmount = blockEntity.getWaterAmount(); + long waterCapacity = blockEntity.getWaterCapacity(); + + if (waterAmount + 1000 <= waterCapacity) { + blockEntity.addWater(1000); + if (!world.isClient) { + world.playSound(null, pos, SoundEvents.ITEM_BUCKET_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F); + } + if (!player.isCreative()) { + player.setStackInHand(hand, new ItemStack(Items.BUCKET)); + } + return ActionResult.SUCCESS; + } + return ActionResult.FAIL; + } + + private ActionResult handleContainerFill(World world, BlockPos pos, PlayerEntity player, Hand hand, BrewingKegBlockEntity blockEntity) { + ItemStack heldItem = player.getStackInHand(hand); + ItemStack requiredContainer = blockEntity.getStack(REQUIRE_CONTAINER); + + if (heldItem.isOf(requiredContainer.getItem())) { + ItemStack displayItem = blockEntity.getStack(DRINKS_DISPLAY_SLOT); + + if (!displayItem.isEmpty() && displayItem.getCount() > 0) { + ItemStack filledContainer = displayItem.copy(); + filledContainer.setCount(1); + + displayItem.decrement(1); + heldItem.decrement(1); + + if (!giveItemToPlayerOrDrop(world, player, filledContainer)) { + return ActionResult.FAIL; + } + + blockEntity.markDirty(); + blockEntity.sendFluidPacket(); + return ActionResult.SUCCESS; + } + } + return ActionResult.FAIL; + } + + private boolean giveItemToPlayerOrDrop(World world, PlayerEntity player, ItemStack itemStack) { + if (!player.getInventory().insertStack(itemStack)) { + ItemEntity itemEntity = new ItemEntity(world, player.getX(), player.getY(), player.getZ(), itemStack); + world.spawnEntity(itemEntity); + return false; + } + return true; + } + + private void openScreenForPlayer(BlockState state, World world, BlockPos pos, PlayerEntity player) { + NamedScreenHandlerFactory screenHandlerFactory = state.createScreenHandlerFactory(world, pos); + if (screenHandlerFactory != null) { + player.openHandledScreen(screenHandlerFactory); + } + } + + + + + + @Nullable @Override public BlockEntityTicker getTicker(World world, BlockState state, BlockEntityType type) { diff --git a/src/main/java/com/megatrex4/ukrainian_dlight/block/entity/BrewingKegBlockEntity.java b/src/main/java/com/megatrex4/ukrainian_dlight/block/entity/BrewingKegBlockEntity.java index 1fd1791..a0787b6 100644 --- a/src/main/java/com/megatrex4/ukrainian_dlight/block/entity/BrewingKegBlockEntity.java +++ b/src/main/java/com/megatrex4/ukrainian_dlight/block/entity/BrewingKegBlockEntity.java @@ -6,11 +6,9 @@ import com.megatrex4.ukrainian_dlight.recipe.BrewingRecipe; import com.megatrex4.ukrainian_dlight.recipe.ModRecipes; import com.megatrex4.ukrainian_dlight.screen.BrewingKegScreenHandler; +import com.megatrex4.ukrainian_dlight.util.CompoundTagUtils; 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; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; @@ -495,26 +493,35 @@ private void handleWaterBucket() { ItemStack waterBucketStack = this.getStack(WATER_SLOT); if (waterBucketStack.getItem() == Items.WATER_BUCKET) { - try (Transaction transaction = Transaction.openOuter()) { - long amountToAdd = FluidStack.convertDropletsToMb(FluidConstants.BUCKET); - long insertedAmount = this.fluidStorage.insert(FluidVariant.of(Fluids.WATER), amountToAdd, transaction); - - if (insertedAmount == amountToAdd) { - // Successfully added water, replace the bucket with an empty one - this.setStack(WATER_SLOT, new ItemStack(Items.BUCKET)); - 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); - } + boolean success = this.addWater(1000); // 1000 mb equals one bucket + + if (success) { + // Successfully added water, replace the bucket with an empty one + this.setStack(WATER_SLOT, new ItemStack(Items.BUCKET)); + 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); } } } } + public boolean addWater(long WaterAmountAdd) { + try (Transaction transaction = Transaction.openOuter()) { + long insertedAmount = this.fluidStorage.insert(FluidVariant.of(Fluids.WATER), WaterAmountAdd, transaction); + + if (insertedAmount == WaterAmountAdd) { + transaction.commit(); + return true; // Successfully added water + } + } + return false; // Failed to add water + } + + private static void transferFluidToFluidStorage(BrewingKegBlockEntity entity) { try(Transaction transaction = Transaction.openOuter()) { @@ -535,8 +542,17 @@ private boolean hasEnoughFluid() { return false; } + public long getWaterAmount() { + return fluidStorage.amount; + } + + public long getWaterCapacity() { + return fluidStorage.getCapacity(); + } + + - private void sendFluidPacket() { + public void sendFluidPacket() { PacketByteBuf data = PacketByteBufs.create(); fluidStorage.variant.toPacket(data); data.writeLong(fluidStorage.amount); diff --git a/src/main/java/com/megatrex4/ukrainian_dlight/item/DrinkBlockItem.java b/src/main/java/com/megatrex4/ukrainian_dlight/item/DrinkBlockItem.java index c932652..78abd36 100644 --- a/src/main/java/com/megatrex4/ukrainian_dlight/item/DrinkBlockItem.java +++ b/src/main/java/com/megatrex4/ukrainian_dlight/item/DrinkBlockItem.java @@ -113,7 +113,7 @@ public void onEndTick(MinecraftServer server) { activeHandlers.remove(this); // Optionally, you can unregister from the event here if it supports it - // ServerTickEvents.END_SERVER_TICK.unregister(this); + ServerTickEvents.END_SERVER_TICK.equals(this); } } } diff --git a/src/main/java/com/megatrex4/ukrainian_dlight/util/StatusEffectUtil.java b/src/main/java/com/megatrex4/ukrainian_dlight/util/StatusEffectUtil.java index 67dea0e..19e66df 100644 --- a/src/main/java/com/megatrex4/ukrainian_dlight/util/StatusEffectUtil.java +++ b/src/main/java/com/megatrex4/ukrainian_dlight/util/StatusEffectUtil.java @@ -22,19 +22,22 @@ public static void applySecondaryEffects(PlayerEntity player, StatusEffectInstan int amplifier = mainEffect.getAmplifier() + 1; if (player.getInventory().contains(ModTags.LIGHT_DRINK)) { - applyWeakness(player, duration / 2, (int) (amplifier * 1.3)); // Convert to int after multiplication - applyNausea(player, duration / 2, (int) (amplifier * 1.3)); // Convert to int after multiplication + applyWeakness(player, duration / 2, (int) (amplifier * 1.3)); + applyNausea(player, duration / 2, (int) (amplifier * 1.3)); + if (RANDOM.nextFloat() < 0.2) { + applyBlindness(player, (int) (duration * 0.7), (int) (amplifier * 1.3)); + } } else if (player.getInventory().contains(ModTags.MID_DRINK)) { - applyWeakness(player, (int) (duration * 0.7), (int) (amplifier * 1.7)); // Convert to int after multiplication - applyNausea(player, (int) (duration * 0.7), (int) (amplifier * 1.7)); // Convert to int after multiplication - if (RANDOM.nextFloat() < 0.5) { - applyBlindness(player, (int) (duration * 0.7), (int) (amplifier * 1.7)); // Convert to int after multiplication + applyWeakness(player, (int) (duration * 0.7), (int) (amplifier * 1.5)); + applyNausea(player, (int) (duration * 0.7), (int) (amplifier * 1.5)); + if (RANDOM.nextFloat() < 0.7) { + applyBlindness(player, (int) (duration * 0.7), (int) (amplifier * 1.5)); } } else if (player.getInventory().contains(ModTags.STRONG_DRINK)) { - applyWeakness(player, (int) (duration * 0.9), (int) (amplifier * 2.2)); // Convert to int after multiplication - applyNausea(player, (int) (duration * 0.9), (int) (amplifier * 2.2)); // Convert to int after multiplication - if (RANDOM.nextFloat() < 0.7) { - applyBlindness(player, (int) (duration * 0.9), (int) (amplifier * 2.2)); // Convert to int after multiplication + applyWeakness(player, (int) (duration * 0.9), (int) (amplifier * 1.7)); + applyNausea(player, (int) (duration * 0.9), (int) (amplifier * 1.7)); + if (RANDOM.nextFloat() < 0.8) { + applyBlindness(player, (int) (duration * 0.9), (int) (amplifier * 2.2)); } } } diff --git a/src/main/resources/assets/ukrainian_delight/textures/gui/brewing_keg_gui.png b/src/main/resources/assets/ukrainian_delight/textures/gui/brewing_keg_gui.png index 9af8311..4ccca7c 100644 Binary files a/src/main/resources/assets/ukrainian_delight/textures/gui/brewing_keg_gui.png and b/src/main/resources/assets/ukrainian_delight/textures/gui/brewing_keg_gui.png differ