Bookshelves
This commit is contained in:
parent
9ed5b7df19
commit
0a8e73d9d9
15 changed files with 131 additions and 59 deletions
61
src/main/java/ru/betterend/blocks/basis/BlockBookshelf.java
Normal file
61
src/main/java/ru/betterend/blocks/basis/BlockBookshelf.java
Normal file
|
@ -0,0 +1,61 @@
|
|||
package ru.betterend.blocks.basis;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.enchantment.Enchantments;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.loot.context.LootContext;
|
||||
import net.minecraft.loot.context.LootContextParameters;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.interfaces.Patterned;
|
||||
|
||||
public class BlockBookshelf extends BlockBase {
|
||||
public BlockBookshelf(Block source) {
|
||||
super(FabricBlockSettings.copyOf(source));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDroppedStacks(BlockState state, LootContext.Builder builder) {
|
||||
ItemStack tool = builder.get(LootContextParameters.TOOL);
|
||||
if (tool != null && tool.isEffectiveOn(state)) {
|
||||
int silk = EnchantmentHelper.getLevel(Enchantments.SILK_TOUCH, tool);
|
||||
if (silk > 0) {
|
||||
return Collections.singletonList(new ItemStack(this));
|
||||
}
|
||||
}
|
||||
return Collections.singletonList(new ItemStack(Items.BOOK, 3));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Identifier statePatternId() {
|
||||
return Patterned.BLOCK_STATES_PATTERN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModelPattern(String block) {
|
||||
Identifier blockId = Registry.BLOCK.getId(this);
|
||||
String name = getName(blockId);
|
||||
return Patterned.createJson(Patterned.BOOKSHELF, BetterEnd.makeID(name), blockId.getPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStatesPattern(Reader data) {
|
||||
Identifier blockId = Registry.BLOCK.getId(this);
|
||||
String name = getName(blockId);
|
||||
return Patterned.createJson(data, BetterEnd.makeID(name), blockId.getPath());
|
||||
}
|
||||
|
||||
private String getName(Identifier blockId) {
|
||||
String name = blockId.getPath();
|
||||
return name.replace("_bookshelf", "");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue