Skip to content

Commit

Permalink
change filewriter
Browse files Browse the repository at this point in the history
  • Loading branch information
yurisuika committed Oct 28, 2024
1 parent 788b32e commit 81ed583
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/main/java/dev/yurisuika/blossom/util/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.io.File;
import java.io.FileWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;

public class Config {
Expand All @@ -25,7 +26,7 @@ public static void setOptions(Options options) {

public static void saveConfig() {
try {
FileWriter fileWriter = new FileWriter(file);
FileWriter fileWriter = new FileWriter(file, StandardCharsets.UTF_8);
fileWriter.write(gson.toJson(getOptions()));
fileWriter.close();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import net.minecraft.util.ParticleUtils;
import net.minecraft.util.RandomSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.ItemInteractionResult;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
Expand Down Expand Up @@ -122,7 +122,7 @@ public void randomTick(BlockState state, ServerLevel level, BlockPos pos, Random
if (level.isRaining() && precipitation == Precipitation.RAIN) {
f = 5.0F;
}
if (random.nextInt((int)(25.0F / f) + 1) == 0) {
if (random.nextInt((int) (25.0F / f) + 1) == 0) {
level.setBlock(pos, defaultBlockState().setValue(AGE, i + 1)
.setValue(DISTANCE, state.getValue(DISTANCE))
.setValue(PERSISTENT, state.getValue(PERSISTENT))
Expand Down Expand Up @@ -248,12 +248,11 @@ public void performBonemeal(ServerLevel level, RandomSource random, BlockPos pos
applyGrowth(level, pos, state);
}

public InteractionResult useItemOn(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
ItemStack itemStack = player.getItemInHand(hand);
Item item = itemStack.getItem();
public ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
Item item = stack.getItem();
if (item instanceof ShearsItem) {
level.playSound(player, player.getX(), player.getY(), player.getZ(), SoundEvents.CROP_BREAK, SoundSource.NEUTRAL, 1.0F, 1.0F);
itemStack.hurtAndBreak(1, player, LivingEntity.getSlotForHand(hand));
stack.hurtAndBreak(1, player, LivingEntity.getSlotForHand(hand));
if (!level.isClientSide()) {
player.awardStat(Stats.ITEM_USED.get(item));
}
Expand All @@ -263,9 +262,9 @@ public InteractionResult useItemOn(BlockState state, Level level, BlockPos pos,
.setValue(PERSISTENT, state.getValue(PERSISTENT))
.setValue(WATERLOGGED, state.getValue(WATERLOGGED))
);
return InteractionResult.SUCCESS;
return ItemInteractionResult.SUCCESS;
} else {
return InteractionResult.PASS;
return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.ItemInteractionResult;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
Expand Down Expand Up @@ -124,7 +124,7 @@ public void randomTick(BlockState state, ServerLevel level, BlockPos pos, Random
if (level.isRaining() && precipitation == Precipitation.RAIN) {
f = 5.0F;
}
if (random.nextInt((int)(25.0F / f) + 1) == 0) {
if (random.nextInt((int) (25.0F / f) + 1) == 0) {
level.setBlock(pos, defaultBlockState().setValue(AGE, i + 1)
.setValue(DISTANCE, state.getValue(DISTANCE))
.setValue(PERSISTENT, state.getValue(PERSISTENT))
Expand Down Expand Up @@ -254,14 +254,13 @@ public static void dropFruit(Level level, BlockPos pos, Item item, int bonus) {
popResource(level, pos, new ItemStack(item, count));
}

public InteractionResult useItemOn(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
ItemStack itemStack = player.getItemInHand(hand);
public ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if (isMaxAge(state)) {
Item item = itemStack.getItem();
Item item = stack.getItem();
if (item instanceof ShearsItem) {
level.playSound(player, player.getX(), player.getY(), player.getZ(), SoundEvents.CROP_BREAK, SoundSource.NEUTRAL, 1.0F, 1.0F);
dropFruit(level, pos, shearedItem, (itemStack.isEnchanted() && EnchantmentHelper.getEnchantmentsForCrafting(itemStack).entrySet().contains(Enchantments.FORTUNE)) ? EnchantmentHelper.getItemEnchantmentLevel(Enchantments.FORTUNE, itemStack) : 0);
itemStack.hurtAndBreak(1, player, LivingEntity.getSlotForHand(hand));
dropFruit(level, pos, shearedItem, (stack.isEnchanted() && EnchantmentHelper.getEnchantmentsForCrafting(stack).entrySet().contains(Enchantments.FORTUNE)) ? EnchantmentHelper.getItemEnchantmentLevel(Enchantments.FORTUNE, stack) : 0);
stack.hurtAndBreak(1, player, LivingEntity.getSlotForHand(hand));
if (!level.isClientSide()) {
player.awardStat(Stats.ITEM_USED.get(item));
}
Expand All @@ -272,9 +271,9 @@ public InteractionResult useItemOn(BlockState state, Level level, BlockPos pos,
.setValue(WATERLOGGED, state.getValue(WATERLOGGED))
);
}
return InteractionResult.SUCCESS;
return ItemInteractionResult.SUCCESS;
} else {
return InteractionResult.PASS;
return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/blossom.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"minVersion": "0.8",
"package": "dev.yurisuika.blossom.mixin",
"refmap": "blossom.refmap.json",
"compatibilityLevel": "JAVA_17",
"compatibilityLevel": "JAVA_21",
"mixins": [
"world.entity.EntityAccessor",
"world.entity.MobAccessor",
Expand Down

0 comments on commit 81ed583

Please sign in to comment.