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", "");
|
||||
}
|
||||
}
|
|
@ -1,58 +1,58 @@
|
|||
package ru.betterend.blocks;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.block.MaterialColor;
|
||||
import net.minecraft.block.OreBlock;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.enchantment.Enchantments;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.loot.context.LootContext;
|
||||
import net.minecraft.loot.context.LootContextParameters;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import ru.betterend.util.MHelper;
|
||||
|
||||
public class BlockOre extends OreBlock {
|
||||
private final Item dropItem;
|
||||
private final int minCount;
|
||||
private final int maxCount;
|
||||
|
||||
public BlockOre(Item drop, int minCount, int maxCount) {
|
||||
super(FabricBlockSettings.of(Material.STONE, MaterialColor.SAND)
|
||||
.hardness(3F)
|
||||
.resistance(9F)
|
||||
.requiresTool()
|
||||
.sounds(BlockSoundGroup.STONE));
|
||||
this.dropItem = drop;
|
||||
this.minCount = minCount;
|
||||
this.maxCount = maxCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDroppedStacks(BlockState state, LootContext.Builder builder) {
|
||||
ItemStack tool = builder.get(LootContextParameters.TOOL);
|
||||
if (tool != null && tool.isEffectiveOn(state)) {
|
||||
int count = 0;
|
||||
int fortune = EnchantmentHelper.getLevel(Enchantments.FORTUNE, tool);
|
||||
if (fortune > 0) {
|
||||
int min = MathHelper.clamp(minCount + fortune, minCount, maxCount);
|
||||
int max = maxCount + (fortune / Enchantments.FORTUNE.getMaxLevel());
|
||||
if (min == max) {
|
||||
return Lists.newArrayList(new ItemStack(dropItem, max));
|
||||
}
|
||||
count = MHelper.randRange(min, max, MHelper.RANDOM);
|
||||
} else {
|
||||
count = MHelper.randRange(minCount, maxCount, MHelper.RANDOM);
|
||||
}
|
||||
return Lists.newArrayList(new ItemStack(dropItem, count));
|
||||
}
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
}
|
||||
package ru.betterend.blocks.basis;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.block.MaterialColor;
|
||||
import net.minecraft.block.OreBlock;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.enchantment.Enchantments;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.loot.context.LootContext;
|
||||
import net.minecraft.loot.context.LootContextParameters;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import ru.betterend.util.MHelper;
|
||||
|
||||
public class BlockOre extends OreBlock {
|
||||
private final Item dropItem;
|
||||
private final int minCount;
|
||||
private final int maxCount;
|
||||
|
||||
public BlockOre(Item drop, int minCount, int maxCount) {
|
||||
super(FabricBlockSettings.of(Material.STONE, MaterialColor.SAND)
|
||||
.hardness(3F)
|
||||
.resistance(9F)
|
||||
.requiresTool()
|
||||
.sounds(BlockSoundGroup.STONE));
|
||||
this.dropItem = drop;
|
||||
this.minCount = minCount;
|
||||
this.maxCount = maxCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDroppedStacks(BlockState state, LootContext.Builder builder) {
|
||||
ItemStack tool = builder.get(LootContextParameters.TOOL);
|
||||
if (tool != null && tool.isEffectiveOn(state)) {
|
||||
int count = 0;
|
||||
int fortune = EnchantmentHelper.getLevel(Enchantments.FORTUNE, tool);
|
||||
if (fortune > 0) {
|
||||
int min = MathHelper.clamp(minCount + fortune, minCount, maxCount);
|
||||
int max = maxCount + (fortune / Enchantments.FORTUNE.getMaxLevel());
|
||||
if (min == max) {
|
||||
return Lists.newArrayList(new ItemStack(dropItem, max));
|
||||
}
|
||||
count = MHelper.randRange(min, max, MHelper.RANDOM);
|
||||
} else {
|
||||
count = MHelper.randRange(minCount, maxCount, MHelper.RANDOM);
|
||||
}
|
||||
return Lists.newArrayList(new ItemStack(dropItem, count));
|
||||
}
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
}
|
|
@ -12,6 +12,7 @@ import ru.betterend.blocks.basis.BlockBark;
|
|||
import ru.betterend.blocks.basis.BlockBarkStripable;
|
||||
import ru.betterend.blocks.basis.BlockBarrel;
|
||||
import ru.betterend.blocks.basis.BlockBase;
|
||||
import ru.betterend.blocks.basis.BlockBookshelf;
|
||||
import ru.betterend.blocks.basis.BlockChest;
|
||||
import ru.betterend.blocks.basis.BlockCraftingTable;
|
||||
import ru.betterend.blocks.basis.BlockDoor;
|
||||
|
@ -54,6 +55,7 @@ public class WoodenMaterial {
|
|||
|
||||
public final Block chest;
|
||||
public final Block barrel;
|
||||
public final Block shelf;
|
||||
|
||||
public WoodenMaterial(String name, MaterialColor woodColor, MaterialColor planksColor) {
|
||||
FabricBlockSettings materialPlanks = FabricBlockSettings.copyOf(Blocks.OAK_PLANKS).materialColor(planksColor);
|
||||
|
@ -80,6 +82,7 @@ public class WoodenMaterial {
|
|||
|
||||
chest = EndBlocks.registerBlock(name + "_chest", new BlockChest(planks));
|
||||
barrel = EndBlocks.registerBlock(name + "_barrel", new BlockBarrel(planks));
|
||||
shelf = EndBlocks.registerBlock(name + "_bookshelf", new BlockBookshelf(planks));
|
||||
|
||||
// Recipes //
|
||||
GridRecipe.make(name + "_planks", planks).setOutputCount(4).setList("#").addMaterial('#', log, bark, log_stripped, bark_stripped).setGroup("end_planks").build();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue