-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BaseAnvilBlock changes, BaseAnvilItem
- Loading branch information
Showing
4 changed files
with
81 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package ru.bclib.items; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.renderer.block.model.BlockModel; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.network.chat.TranslatableComponent; | ||
import net.minecraft.resources.ResourceLocation; | ||
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 org.jetbrains.annotations.Nullable; | ||
import ru.bclib.blocks.BaseAnvilBlock; | ||
import ru.bclib.client.models.ItemModelProvider; | ||
|
||
import java.util.List; | ||
|
||
public class BaseAnvilItem extends BlockItem implements ItemModelProvider { | ||
|
||
public final static String DESTRUCTION = "destruction"; | ||
|
||
public BaseAnvilItem(Block block, Properties properties) { | ||
super(block, properties); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("ConstantConditions") | ||
protected BlockState getPlacementState(BlockPlaceContext blockPlaceContext) { | ||
BlockState blockState = super.getPlacementState(blockPlaceContext); | ||
ItemStack stack = blockPlaceContext.getItemInHand(); | ||
int destruction = stack.getOrCreateTag().getInt(DESTRUCTION); | ||
blockState = blockState.setValue(BaseAnvilBlock.DESTRUCTION, destruction); | ||
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(DESTRUCTION); | ||
if (l > 0) { | ||
list.add(new TranslatableComponent("message.bclib.anvil_damage").append(": " + l)); | ||
} | ||
} | ||
|
||
@Override | ||
public BlockModel getItemModel(ResourceLocation resourceLocation) { | ||
return ((ItemModelProvider) getBlock()).getItemModel(resourceLocation); | ||
} | ||
} |