Skip to content

Commit

Permalink
Compat, Fixes, Buckets, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
crispytwig committed Dec 15, 2024
1 parent d12bcde commit 28ea2e3
Show file tree
Hide file tree
Showing 82 changed files with 1,277 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ public class SGConfig extends MidnightConfig {

@Comment(category = MAIN, centered = true) public static Comment itemsMisc;

@Entry(category = MAIN) public static boolean warningPings = true;
@Entry(category = MAIN) public static boolean calmerWarnings = false;

@Entry(category = MAIN) public static boolean eggnogEffects = true;
@Entry(category = MAIN) public static boolean negativeEggnogEffects = true;
@Entry(category = MAIN) public static boolean crazyGingerbreadMen = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
package com.starfish_studios.seasons_greetings;

import com.starfish_studios.seasons_greetings.client.SeasonsGreetingsClient;
import com.starfish_studios.seasons_greetings.event.SnowCauldronUseEvent;
import com.starfish_studios.seasons_greetings.event.CauldronUseEvent;
import com.starfish_studios.seasons_greetings.event.WreathInteractions;
import com.starfish_studios.seasons_greetings.registry.SGRegistry;
import eu.midnightdust.lib.config.MidnightConfig;
import net.fabricmc.api.ModInitializer;

import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.fabricmc.fabric.api.resource.conditions.v1.ResourceCondition;
import net.fabricmc.fabric.api.resource.conditions.v1.ResourceConditionType;
import net.fabricmc.fabric.api.resource.conditions.v1.ResourceConditions;
import net.minecraft.resources.ResourceLocation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SeasonsGreetings implements ModInitializer {
public static final String MOD_ID = "seasonsgreetings";
Expand All @@ -33,7 +27,7 @@ public void onInitialize() {

SGRegistry.registerAll();

UseBlockCallback.EVENT.register(new SnowCauldronUseEvent());
UseBlockCallback.EVENT.register(new CauldronUseEvent());
UseBlockCallback.EVENT.register(new WreathInteractions());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public static void registerScreens() {
private static void registerParticles() {
ParticleFactoryRegistry.getInstance().register(SGParticles.COCOA_BUBBLE, PoppingBubbleParticle.Provider::new);
ParticleFactoryRegistry.getInstance().register(SGParticles.MILK_BUBBLE, PoppingBubbleParticle.Provider::new);
ParticleFactoryRegistry.getInstance().register(SGParticles.EGGNOG_BUBBLE, PoppingBubbleParticle.Provider::new);
}

@SuppressWarnings("all")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,69 +55,93 @@ protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockSt
}

public void animateTick(BlockState blockState, Level level, BlockPos blockPos, RandomSource randomSource) {
if (blockState.is(SGBlocks.HOT_COCOA_CAULDRON) && level.getBlockState(blockPos.below()).is(SGTags.SGBlockTags.HEAT_SOURCES)) {

if (blockState.is(SGBlocks.EGGNOG_CAULDRON) && level.getBlockState(blockPos.below()).is(SGTags.SGBlockTags.HEAT_SOURCES)) {
if (blockState.getValue(LayeredCauldronBlock.LEVEL) == 3) {
for (int i = 0; i < 2; ++i) {
double x = (double) blockPos.getX() + 0.3 + ((level.random.nextDouble() * 0.8D) - 0.2D);
double y = (double) blockPos.getY() + 1 + (level.random.nextDouble() * 0.2D - 0.1D);
double z = (double) blockPos.getZ() + 0.3 + ((level.random.nextDouble() * 0.8D) - 0.2D);

level.addParticle(SGParticles.COCOA_BUBBLE, x, y, z, 0.0D, 0.0D, 0.0D);
level.addParticle(SGParticles.EGGNOG_BUBBLE, x, y, z, 0.0D, 0.0D, 0.0D);
}
} else if (blockState.getValue(LayeredCauldronBlock.LEVEL) == 2) {
for (int i = 0; i < 2; ++i) {
double x = (double) blockPos.getX() + 0.3 + ((level.random.nextDouble() * 0.8D) - 0.2D);
double y = (double) blockPos.getY() + 0.8 + (level.random.nextDouble() * 0.2D - 0.1D);
double z = (double) blockPos.getZ() + 0.3 + ((level.random.nextDouble() * 0.8D) - 0.2D);

level.addParticle(SGParticles.COCOA_BUBBLE, x, y, z, 0.0D, 0.0D, 0.0D);
level.addParticle(SGParticles.EGGNOG_BUBBLE, x, y, z, 0.0D, 0.0D, 0.0D);
}
} else if (blockState.getValue(LayeredCauldronBlock.LEVEL) == 1) {
for (int i = 0; i < 2; ++i) {
double x = (double) blockPos.getX() + 0.3 + ((level.random.nextDouble() * 0.8D) - 0.2D);
double y = (double) blockPos.getY() + 0.6 + (level.random.nextDouble() * 0.2D - 0.1D);
double z = (double) blockPos.getZ() + 0.3 + ((level.random.nextDouble() * 0.8D) - 0.2D);

level.addParticle(SGParticles.COCOA_BUBBLE, x, y, z, 0.0D, 0.0D, 0.0D);
level.addParticle(SGParticles.EGGNOG_BUBBLE, x, y, z, 0.0D, 0.0D, 0.0D);
}
}


if (randomSource.nextInt(10) == 0) {
level.playLocalSound((double) blockPos.getX() + 0.5, (double) blockPos.getY() + 0.5, (double) blockPos.getZ() + 0.5, SGSoundEvents.COCOA_CAULDRON_BUBBLE, SoundSource.BLOCKS,
level.playLocalSound((double) blockPos.getX() + 0.5, (double) blockPos.getY() + 0.5, (double) blockPos.getZ() + 0.5, SGSoundEvents.EGGNOG_CAULDRON_BUBBLE, SoundSource.BLOCKS,
0.3F, 1.0F + level.random.nextFloat() * 0.2F, false);
}
}

}

protected @NotNull ItemInteractionResult useItemOn(ItemStack itemStack, BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) {
if (itemStack.is(Items.BUCKET)) {
player.playSound(SoundEvents.ARROW_HIT_PLAYER, 0.5F, level.random.nextFloat() * 0.1F + 0.9F);
player.displayClientMessage(Component.translatable("block.seasons_greetings.hot_cocoa_cauldron.bucket")
.withStyle(ChatFormatting.RED).withStyle(ChatFormatting.ITALIC), true);
if (itemStack.is(Items.BUCKET) && blockState.getValue(LayeredCauldronBlock.LEVEL) == 3) {
if (!player.isCreative()) {
itemStack.shrink(1);
if (!player.getInventory().add(new ItemStack(SGItems.EGGNOG_BUCKET))) {
player.drop(new ItemStack(SGItems.EGGNOG_BUCKET), false);
}
}
level.setBlockAndUpdate(blockPos, Blocks.CAULDRON.defaultBlockState());
player.playSound(SoundEvents.BUCKET_FILL, 1.0F, 1.0F);
return ItemInteractionResult.SUCCESS;
}

else if (itemStack.is(Items.GLASS_BOTTLE)) {
if (blockState.getValue(LayeredCauldronBlock.LEVEL) == 1) {
level.setBlockAndUpdate(blockPos, Blocks.CAULDRON.defaultBlockState());
if (!player.getInventory().add(new ItemStack(SGItems.HOT_COCOA))) {
player.drop(new ItemStack(SGItems.HOT_COCOA), false);
if (!player.isCreative()) {
itemStack.shrink(1);
if (!player.getInventory().add(new ItemStack(SGItems.EGGNOG))) {
player.drop(new ItemStack(SGItems.EGGNOG), false);
}
}
player.playSound(SoundEvents.BOTTLE_FILL, 1.0F, 1.0F);
return ItemInteractionResult.SUCCESS;
} else if (blockState.getValue(LayeredCauldronBlock.LEVEL) > 1) {
level.setBlockAndUpdate(blockPos, blockState.setValue(LayeredCauldronBlock.LEVEL, blockState.getValue(LayeredCauldronBlock.LEVEL) - 1));
if (!player.getInventory().add(new ItemStack(SGItems.HOT_COCOA))) {
player.drop(new ItemStack(SGItems.HOT_COCOA), false);
if (!player.isCreative()) {
itemStack.shrink(1);
if (!player.getInventory().add(new ItemStack(SGItems.EGGNOG))) {
player.drop(new ItemStack(SGItems.EGGNOG), false);
}
}
player.playSound(SoundEvents.BOTTLE_FILL, 1.0F, 1.0F);
return ItemInteractionResult.SUCCESS;
}
}

else if (itemStack.is(SGItems.EGGNOG)) {
if (blockState.getValue(LayeredCauldronBlock.LEVEL) < 3) {
level.setBlockAndUpdate(blockPos, blockState.setValue(LayeredCauldronBlock.LEVEL, blockState.getValue(LayeredCauldronBlock.LEVEL) + 1));
if (!player.isCreative()) {
itemStack.shrink(1);
if (!player.getInventory().add(new ItemStack(Items.GLASS_BOTTLE))) {
player.drop(new ItemStack(Items.GLASS_BOTTLE), false);
}
}
player.playSound(SoundEvents.BOTTLE_EMPTY, 1.0F, 1.0F);
return ItemInteractionResult.SUCCESS;
}
}

return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.starfish_studios.seasons_greetings.common.block;

import com.mojang.serialization.MapCodec;
import com.starfish_studios.seasons_greetings.SGConfig;
import com.starfish_studios.seasons_greetings.registry.*;
import net.fabricmc.fabric.api.block.BlockPickInteractionAware;
import net.minecraft.ChatFormatting;
Expand Down Expand Up @@ -56,7 +57,6 @@ protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockSt

public void animateTick(BlockState blockState, Level level, BlockPos blockPos, RandomSource randomSource) {
if (blockState.is(SGBlocks.HOT_COCOA_CAULDRON) && level.getBlockState(blockPos.below()).is(SGTags.SGBlockTags.HEAT_SOURCES)) {

if (blockState.getValue(LayeredCauldronBlock.LEVEL) == 3) {
for (int i = 0; i < 2; ++i) {
double x = (double) blockPos.getX() + 0.3 + ((level.random.nextDouble() * 0.8D) - 0.2D);
Expand Down Expand Up @@ -92,32 +92,73 @@ public void animateTick(BlockState blockState, Level level, BlockPos blockPos, R

}

public static void giveItem(Player player, ItemStack consumedItem, ItemStack outputItem) {
if (!player.isCreative()) {
consumedItem.shrink(1);

if (!player.getInventory().add(outputItem)) {
player.drop(outputItem, false);
}
} else {
if (!player.getInventory().contains(outputItem)) {
if (!player.getInventory().add(outputItem)) {
player.drop(outputItem, false);
}
}
}
}

protected @NotNull ItemInteractionResult useItemOn(ItemStack itemStack, BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) {
if (itemStack.is(Items.BUCKET)) {
player.playSound(SoundEvents.ARROW_HIT_PLAYER, 0.5F, level.random.nextFloat() * 0.1F + 0.9F);
player.displayClientMessage(Component.translatable("block.seasons_greetings.hot_cocoa_cauldron.bucket")
.withStyle(ChatFormatting.RED).withStyle(ChatFormatting.ITALIC), true);
if (itemStack.is(Items.BUCKET) && !level.getBlockState(blockPos.below()).is(SGTags.SGBlockTags.HEAT_SOURCES)
|| itemStack.is(Items.GLASS_BOTTLE) && !level.getBlockState(blockPos.below()).is(SGTags.SGBlockTags.HEAT_SOURCES)
) {
if (SGConfig.warningPings && !SGConfig.calmerWarnings) {
player.playSound(SoundEvents.ARROW_HIT_PLAYER, 0.5F, level.random.nextFloat() * 0.1F + 0.9F);
player.displayClientMessage(Component.literal("[!] ")
.append(Component.translatable("block.seasons_greetings.hot_cocoa_cauldron.too_cold"))
.withStyle(ChatFormatting.RED).withStyle(ChatFormatting.ITALIC), true);
}
else if (SGConfig.calmerWarnings) {
player.displayClientMessage(Component.translatable("block.seasons_greetings.hot_cocoa_cauldron.too_cold"), true);
} else {
return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
}
player.swing(interactionHand);
}


if (itemStack.is(Items.BUCKET) && blockState.getValue(LayeredCauldronBlock.LEVEL) == 3 && level.getBlockState(blockPos.below()).is(SGTags.SGBlockTags.HEAT_SOURCES)) {
giveItem(player, itemStack, new ItemStack(SGItems.HOT_COCOA_BUCKET));
level.setBlockAndUpdate(blockPos, Blocks.CAULDRON.defaultBlockState());
player.playSound(SoundEvents.BUCKET_FILL, 1.0F, 1.0F);
return ItemInteractionResult.SUCCESS;
}

else if (itemStack.is(Items.GLASS_BOTTLE)) {
if (itemStack.is(Items.GLASS_BOTTLE) && level.getBlockState(blockPos.below()).is(SGTags.SGBlockTags.HEAT_SOURCES)) {
if (blockState.getValue(LayeredCauldronBlock.LEVEL) == 1) {
level.setBlockAndUpdate(blockPos, Blocks.CAULDRON.defaultBlockState());
if (!player.getInventory().add(new ItemStack(SGItems.HOT_COCOA))) {
player.drop(new ItemStack(SGItems.HOT_COCOA), false);
}
giveItem(player, itemStack, new ItemStack(SGItems.HOT_COCOA));
player.playSound(SoundEvents.BOTTLE_FILL, 1.0F, 1.0F);
return ItemInteractionResult.SUCCESS;
} else if (blockState.getValue(LayeredCauldronBlock.LEVEL) > 1) {
level.setBlockAndUpdate(blockPos, blockState.setValue(LayeredCauldronBlock.LEVEL, blockState.getValue(LayeredCauldronBlock.LEVEL) - 1));
if (!player.getInventory().add(new ItemStack(SGItems.HOT_COCOA))) {
player.drop(new ItemStack(SGItems.HOT_COCOA), false);
}
giveItem(player, itemStack, new ItemStack(SGItems.HOT_COCOA));
player.playSound(SoundEvents.BOTTLE_FILL, 1.0F, 1.0F);
return ItemInteractionResult.SUCCESS;
}
}

if (itemStack.is(SGItems.HOT_COCOA)) {
if (blockState.getValue(LayeredCauldronBlock.LEVEL) < 3) {
level.setBlockAndUpdate(blockPos, blockState.setValue(LayeredCauldronBlock.LEVEL, blockState.getValue(LayeredCauldronBlock.LEVEL) + 1));
giveItem(player, itemStack, new ItemStack(Items.GLASS_BOTTLE));
player.playSound(SoundEvents.BOTTLE_EMPTY, 1.0F, 1.0F);
return ItemInteractionResult.SUCCESS;
}
}



return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
}

Expand Down
Loading

0 comments on commit 28ea2e3

Please sign in to comment.