Prevent anvil damage restore
This commit is contained in:
parent
5e2335b255
commit
38a09c0aef
5 changed files with 60 additions and 4 deletions
|
@ -48,7 +48,10 @@ public class EndAnvilBlock extends AnvilBlock implements BlockPatterned {
|
|||
|
||||
@Override
|
||||
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
|
||||
return Collections.singletonList(new ItemStack(this));
|
||||
ItemStack stack = new ItemStack(this);
|
||||
int level = state.getValue(getDestructionProperty());
|
||||
stack.getOrCreateTag().putInt("level", level);
|
||||
return Collections.singletonList(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
44
src/main/java/ru/betterend/item/EndAnvilItem.java
Normal file
44
src/main/java/ru/betterend/item/EndAnvilItem.java
Normal file
|
@ -0,0 +1,44 @@
|
|||
package ru.betterend.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import ru.betterend.blocks.basis.EndAnvilBlock;
|
||||
import ru.betterend.registry.EndItems;
|
||||
|
||||
public class EndAnvilItem extends BlockItem {
|
||||
public EndAnvilItem(Block block) {
|
||||
super(block, EndItems.makeBlockItemSettings());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockState getPlacementState(BlockPlaceContext blockPlaceContext) {
|
||||
BlockState blockState = super.getPlacementState(blockPlaceContext);
|
||||
ItemStack stack = blockPlaceContext.getItemInHand();
|
||||
int level = stack.getOrCreateTag().getInt("level");
|
||||
blockState = blockState.setValue(((EndAnvilBlock) blockState.getBlock()).getDestructionProperty(), level);
|
||||
return blockState;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public void appendHoverText(ItemStack itemStack, @Nullable Level level, List<Component> list, TooltipFlag tooltipFlag) {
|
||||
super.appendHoverText(itemStack, level, list, tooltipFlag);
|
||||
int l = itemStack.getOrCreateTag().getInt("level");
|
||||
if (l > 0) {
|
||||
list.add(new TranslatableComponent("message.betterend.anvil_damage").append(": " + l));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ import net.minecraft.world.level.block.Blocks;
|
|||
import net.minecraft.world.level.material.MaterialColor;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.blocks.*;
|
||||
import ru.betterend.blocks.basis.EndAnvilBlock;
|
||||
import ru.betterend.blocks.basis.EndCropBlock;
|
||||
import ru.betterend.blocks.basis.EndFurnaceBlock;
|
||||
import ru.betterend.blocks.basis.EndLeavesBlock;
|
||||
|
@ -34,6 +35,7 @@ import ru.betterend.blocks.complex.StoneMaterial;
|
|||
import ru.betterend.blocks.complex.WoodenMaterial;
|
||||
import ru.betterend.config.Configs;
|
||||
import ru.betterend.interfaces.ISpetialItem;
|
||||
import ru.betterend.item.EndAnvilItem;
|
||||
import ru.betterend.item.material.EndArmorMaterial;
|
||||
import ru.betterend.item.material.EndToolMaterial;
|
||||
|
||||
|
@ -331,9 +333,14 @@ public class EndBlocks {
|
|||
if (placeOnWater) {
|
||||
EndItems.registerBlockItem(id, new WaterLilyBlockItem(block, item));
|
||||
}
|
||||
else {
|
||||
if (block instanceof EndAnvilBlock) {
|
||||
EndItems.registerBlockItem(id, new EndAnvilItem(block));
|
||||
}
|
||||
else {
|
||||
EndItems.registerBlockItem(id, new BlockItem(block, item));
|
||||
}
|
||||
}
|
||||
if (block.defaultBlockState().getMaterial().isFlammable() && FlammableBlockRegistry.getDefaultInstance().get(block).getBurnChance() == 0) {
|
||||
FlammableBlockRegistry.getDefaultInstance().add(block, 5, 5);
|
||||
}
|
||||
|
|
|
@ -848,5 +848,6 @@
|
|||
"block.betterend.smaragdant_crystal_slab": "Smaragdant Slab",
|
||||
"block.betterend.smaragdant_crystal_stairs": "Smaragdant Stairs",
|
||||
"block.betterend.smaragdant_crystal_tiles": "Smaragdant Tiles",
|
||||
"block.betterend.smaragdant_crystal_wall": "Smaragdant Wall"
|
||||
"block.betterend.smaragdant_crystal_wall": "Smaragdant Wall",
|
||||
"message.betterend.anvil_damage": "§cDamage"
|
||||
}
|
||||
|
|
|
@ -867,5 +867,6 @@
|
|||
"block.betterend.smaragdant_crystal_slab": "Смарагдантовая плита",
|
||||
"block.betterend.smaragdant_crystal_stairs": "Смарагдантовые ступени",
|
||||
"block.betterend.smaragdant_crystal_tiles": "Смарагдантовая плитка",
|
||||
"block.betterend.smaragdant_crystal_wall": "Смарагдантовая стена"
|
||||
"block.betterend.smaragdant_crystal_wall": "Смарагдантовая стена",
|
||||
"message.betterend.anvil_damage": "§cПовреждение"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue