Skip to content

Commit

Permalink
Merge pull request #1353 from YocyCraft/dev/anvil_conversion_hotfix
Browse files Browse the repository at this point in the history
Fix conversion chance of spectral anvil 修复幻灵铁砧的转换概率
  • Loading branch information
Gu-ZT authored Dec 18, 2024
2 parents 5868bca + cad810f commit 6f67fda
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
18 changes: 3 additions & 15 deletions src/main/java/dev/dubhe/anvilcraft/mixin/EndPortalBlockMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import dev.dubhe.anvilcraft.init.ModBlockTags;
import dev.dubhe.anvilcraft.init.ModBlocks;

import dev.dubhe.anvilcraft.util.SpectralAnvilConversionUtil;
import net.minecraft.core.BlockPos;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.item.FallingBlockEntity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.EndPortalBlock;
import net.minecraft.world.level.block.Portal;
import net.minecraft.world.level.block.state.BlockState;
Expand All @@ -18,6 +18,7 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;


@Mixin(EndPortalBlock.class)
abstract class EndPortalBlockMixin {
@Inject(
Expand All @@ -36,24 +37,11 @@ private void fallBlockEntityInside(
&& !fallingBlockEntity.blockState.is(ModBlockTags.END_PORTAL_UNABLE_CHANGE)
) {
BlockState newState = ModBlocks.END_DUST.getDefaultState();
anvil:
if (fallingBlockEntity.blockState.is(BlockTags.ANVIL)) {
double rand = pLevel.random.nextDouble();
if (fallingBlockEntity.blockState.is(Blocks.DAMAGED_ANVIL) && rand >= 0.01) {
break anvil;
} else if (fallingBlockEntity.blockState.is(Blocks.CHIPPED_ANVIL) && rand >= 0.02) {
break anvil;
} else if (fallingBlockEntity.blockState.is(Blocks.ANVIL) && rand >= 0.03) {
break anvil;
} else if (fallingBlockEntity.blockState.is(ModBlocks.ROYAL_ANVIL) && rand >= 0.5) {
break anvil;
} else if (fallingBlockEntity.blockState.is(ModBlocks.EMBER_ANVIL)) {
if (rand < SpectralAnvilConversionUtil.chance(fallingBlockEntity.blockState.getBlock())) {
newState = ModBlocks.SPECTRAL_ANVIL.getDefaultState();
break anvil;
} else if (rand >= 0.03) {
break anvil;
}
newState = ModBlocks.SPECTRAL_ANVIL.getDefaultState();
}
fallingBlockEntity.blockState = newState;
fallingBlockEntity.setAsInsidePortal((Portal) this, pPos);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package dev.dubhe.anvilcraft.util;

import dev.dubhe.anvilcraft.init.ModBlocks;
import it.unimi.dsi.fastutil.objects.Object2DoubleMap;
import it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;

public class SpectralAnvilConversionUtil {
private static final Object2DoubleMap<Block> SPECTRAL_ANVIL_CONVERSION_CHANCE = new Object2DoubleOpenHashMap<>();

static {
SPECTRAL_ANVIL_CONVERSION_CHANCE.put(Blocks.DAMAGED_ANVIL, 0.01);
SPECTRAL_ANVIL_CONVERSION_CHANCE.put(Blocks.CHIPPED_ANVIL, 0.02);
SPECTRAL_ANVIL_CONVERSION_CHANCE.put(Blocks.ANVIL, 0.03);
SPECTRAL_ANVIL_CONVERSION_CHANCE.put(ModBlocks.ROYAL_ANVIL.get(), 0.5);
SPECTRAL_ANVIL_CONVERSION_CHANCE.put(ModBlocks.EMBER_ANVIL.get(), 1.0);
}

public static double chance(Block block) {
return SPECTRAL_ANVIL_CONVERSION_CHANCE.getOrDefault(block, 0.03);
}
}

0 comments on commit 6f67fda

Please sign in to comment.