minecraft-source/src/net/minecraft/world/level/block/InfestedBlock.java

53 lines
1.9 KiB
Java

package net.minecraft.world.level.block;
import com.google.common.collect.Maps;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.monster.Silverfish;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.item.ItemStack;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import java.util.Map;
public class InfestedBlock extends Block {
private final Block hostBlock;
private static final Map<Block, Block> BLOCK_BY_HOST_BLOCK;
public InfestedBlock(final Block bpe, final Properties c) {
super(c);
this.hostBlock = bpe;
InfestedBlock.BLOCK_BY_HOST_BLOCK.put(bpe, this);
}
public Block getHostBlock() {
return this.hostBlock;
}
public static boolean isCompatibleHostBlock(final BlockState byg) {
return InfestedBlock.BLOCK_BY_HOST_BLOCK.containsKey(byg.getBlock());
}
@Override
public void spawnAfterBreak(final BlockState byg, final Level bjt, final BlockPos fk, final ItemStack bek) {
super.spawnAfterBreak(byg, bjt, fk, bek);
if (!bjt.isClientSide && bjt.getGameRules().getBoolean(GameRules.RULE_DOBLOCKDROPS) && EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, bek) == 0) {
final Silverfish axc6 = EntityType.SILVERFISH.create(bjt);
axc6.moveTo(fk.getX() + 0.5, fk.getY(), fk.getZ() + 0.5, 0.0f, 0.0f);
bjt.addFreshEntity(axc6);
axc6.spawnAnim();
}
}
public static BlockState stateByHostBlock(final Block bpe) {
return InfestedBlock.BLOCK_BY_HOST_BLOCK.get(bpe).defaultBlockState();
}
static {
BLOCK_BY_HOST_BLOCK = Maps.newIdentityHashMap();
}
}