This commit is contained in:
Aleksey 2020-10-02 17:29:47 +03:00
commit c40c6ff014
15 changed files with 183 additions and 8 deletions

View file

@ -0,0 +1,50 @@
package ru.betterend.blocks;
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.block.Blocks;
import net.minecraft.block.ShapeContext;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootContext;
import net.minecraft.loot.context.LootContextParameters;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import ru.betterend.blocks.basis.BlockBaseNotFull;
public class BlockPath extends BlockBaseNotFull {
private static final VoxelShape SHAPE = Block.createCuboidShape(0, 0, 0, 16, 15, 16);
public BlockPath(Block source) {
super(FabricBlockSettings.copyOf(source).allowsSpawning((state, world, pos, type) -> { return false; }));
if (source instanceof BlockTerrain) {
BlockTerrain terrain = (BlockTerrain) source;
terrain.setPathBlock(this);
}
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.get(LootContextParameters.TOOL);
if (tool != null && EnchantmentHelper.getLevel(Enchantments.SILK_TOUCH, tool) > 0) {
return Collections.singletonList(new ItemStack(this));
}
return Collections.singletonList(new ItemStack(Blocks.END_STONE));
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) {
return SHAPE;
}
@Override
public VoxelShape getCollisionShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) {
return SHAPE;
}
}

View file

@ -0,0 +1,13 @@
package ru.betterend.blocks;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.sound.SoundEvents;
public class BlockSounds {
public static final BlockSoundGroup TERRAIN_SOUND = new BlockSoundGroup(1.0F, 1.0F,
SoundEvents.BLOCK_STONE_BREAK,
SoundEvents.BLOCK_WART_BLOCK_STEP,
SoundEvents.BLOCK_STONE_PLACE,
SoundEvents.BLOCK_STONE_HIT,
SoundEvents.BLOCK_STONE_FALL);
}

View file

@ -1,21 +1,62 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import java.util.Collections;
import java.util.List;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.block.MaterialColor; import net.minecraft.block.MaterialColor;
import net.minecraft.sound.BlockSoundGroup; import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootContext;
import net.minecraft.loot.context.LootContextParameters;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents; import net.minecraft.sound.SoundEvents;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import ru.betterend.blocks.basis.BlockBase; import ru.betterend.blocks.basis.BlockBase;
public class BlockTerrain extends BlockBase { public class BlockTerrain extends BlockBase {
public static final BlockSoundGroup TERRAIN_SOUND = new BlockSoundGroup(1.0F, 1.0F, private Block pathBlock;
SoundEvents.BLOCK_STONE_BREAK,
SoundEvents.BLOCK_WART_BLOCK_STEP,
SoundEvents.BLOCK_STONE_PLACE,
SoundEvents.BLOCK_STONE_HIT,
SoundEvents.BLOCK_STONE_FALL);
public BlockTerrain(MaterialColor color) { public BlockTerrain(MaterialColor color) {
super(FabricBlockSettings.copyOf(Blocks.END_STONE).materialColor(color).sounds(TERRAIN_SOUND)); super(FabricBlockSettings.copyOf(Blocks.END_STONE).materialColor(color).sounds(BlockSounds.TERRAIN_SOUND));
}
public void setPathBlock(Block roadBlock) {
this.pathBlock = roadBlock;
}
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (pathBlock != null && player.getMainHandStack().getItem().isIn(FabricToolTags.SHOVELS)) {
world.playSound(player, pos, SoundEvents.ITEM_SHOVEL_FLATTEN, SoundCategory.BLOCKS, 1.0F, 1.0F);
if (!world.isClient) {
world.setBlockState(pos, pathBlock.getDefaultState());
if (player != null && !player.isCreative()) {
player.getMainHandStack().damage(1, world.random, (ServerPlayerEntity) player);
}
}
return ActionResult.SUCCESS;
}
return ActionResult.FAIL;
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.get(LootContextParameters.TOOL);
if (tool != null && EnchantmentHelper.getLevel(Enchantments.SILK_TOUCH, tool) > 0) {
return Collections.singletonList(new ItemStack(this));
}
return Collections.singletonList(new ItemStack(Blocks.END_STONE));
} }
} }

View file

@ -14,6 +14,7 @@ import ru.betterend.blocks.BlockMossyGlowshroomFur;
import ru.betterend.blocks.BlockMossyGlowshroomHymenophore; import ru.betterend.blocks.BlockMossyGlowshroomHymenophore;
import ru.betterend.blocks.BlockMossyGlowshroomSapling; import ru.betterend.blocks.BlockMossyGlowshroomSapling;
import ru.betterend.blocks.BlockOre; import ru.betterend.blocks.BlockOre;
import ru.betterend.blocks.BlockPath;
import ru.betterend.blocks.BlockTerrain; import ru.betterend.blocks.BlockTerrain;
import ru.betterend.blocks.BlockUmbrellaMoss; import ru.betterend.blocks.BlockUmbrellaMoss;
import ru.betterend.blocks.BlockUmbrellaMossTall; import ru.betterend.blocks.BlockUmbrellaMossTall;
@ -29,6 +30,10 @@ public class BlockRegistry {
public static final Block END_MYCELIUM = registerBlock("end_mycelium", new BlockTerrain(MaterialColor.LIGHT_BLUE)); public static final Block END_MYCELIUM = registerBlock("end_mycelium", new BlockTerrain(MaterialColor.LIGHT_BLUE));
public static final Block END_MOSS = registerBlock("end_moss", new BlockTerrain(MaterialColor.CYAN)); public static final Block END_MOSS = registerBlock("end_moss", new BlockTerrain(MaterialColor.CYAN));
// Roads //
public static final Block END_MYCELIUM_PATH = registerBlock("end_mycelium_path", new BlockPath(END_MYCELIUM));
public static final Block END_MOSS_PATH = registerBlock("end_moss_path", new BlockPath(END_MOSS));
// Wooden Materials // // Wooden Materials //
public static final Block MOSSY_GLOWSHROOM_SAPLING = registerBlock("mossy_glowshroom_sapling", new BlockMossyGlowshroomSapling()); public static final Block MOSSY_GLOWSHROOM_SAPLING = registerBlock("mossy_glowshroom_sapling", new BlockMossyGlowshroomSapling());
public static final Block MOSSY_GLOWSHROOM_CAP = registerBlock("mossy_glowshroom_cap", new BlockMossyGlowshroomCap()); public static final Block MOSSY_GLOWSHROOM_CAP = registerBlock("mossy_glowshroom_cap", new BlockMossyGlowshroomCap());

View file

@ -0,0 +1,10 @@
{
"variants": {
"": [
{ "model": "betterend:block/end_moss_path" },
{ "model": "betterend:block/end_moss_path", "y": 90 },
{ "model": "betterend:block/end_moss_path", "y": 180 },
{ "model": "betterend:block/end_moss_path", "y": 270 }
]
}
}

View file

@ -0,0 +1,10 @@
{
"variants": {
"": [
{ "model": "betterend:block/end_mycelium_path" },
{ "model": "betterend:block/end_mycelium_path", "y": 90 },
{ "model": "betterend:block/end_mycelium_path", "y": 180 },
{ "model": "betterend:block/end_mycelium_path", "y": 270 }
]
}
}

View file

@ -4,6 +4,10 @@
"block.betterend.end_mycelium": "End Mycelium", "block.betterend.end_mycelium": "End Mycelium",
"block.betterend.end_moss": "End Moss", "block.betterend.end_moss": "End Moss",
"block.betterend.endstone_dust": "End Stone Dust", "block.betterend.endstone_dust": "End Stone Dust",
"block.betterend.end_mycelium_path": "End Mycelium Path",
"block.betterend.end_moss_path": "End Moss Path",
"block.betterend.ender_ore": "Ender Ore", "block.betterend.ender_ore": "Ender Ore",
"block.betterend.terminite_block": "Terminite Block", "block.betterend.terminite_block": "Terminite Block",
"block.betterend.aeternium_block": "Aeternium Block", "block.betterend.aeternium_block": "Aeternium Block",

View file

@ -4,6 +4,10 @@
"block.betterend.end_mycelium": "Мицелий края", "block.betterend.end_mycelium": "Мицелий края",
"block.betterend.end_moss": "Мох края", "block.betterend.end_moss": "Мох края",
"block.betterend.endstone_dust": "Эндерняковая пыль", "block.betterend.endstone_dust": "Эндерняковая пыль",
"block.betterend.end_mycelium_path": "Дорога из мицелия края",
"block.betterend.end_moss_path": "Дорога из мха края",
"block.betterend.ender_ore": "Руда Края", "block.betterend.ender_ore": "Руда Края",
"block.betterend.terminite_block": "Блок Терминита", "block.betterend.terminite_block": "Блок Терминита",
"block.betterend.aeternium_block": "Блок Этерия", "block.betterend.aeternium_block": "Блок Этерия",

View file

@ -0,0 +1,7 @@
{ "parent": "betterend:block/path",
"textures": {
"top": "betterend:block/end_moss_path_top",
"side": "betterend:block/end_moss_side",
"bottom": "block/end_stone"
}
}

View file

@ -0,0 +1,7 @@
{ "parent": "betterend:block/path",
"textures": {
"top": "betterend:block/end_mycelium_path_top",
"side": "betterend:block/end_mycelium_side",
"bottom": "block/end_stone"
}
}

View file

@ -0,0 +1,18 @@
{ "parent": "block/block",
"textures": {
"particle": "#side"
},
"elements": [
{ "from": [ 0, 0, 0 ],
"to": [ 16, 15, 16 ],
"faces": {
"down": { "uv": [ 0, 0, 16, 16 ], "texture": "#bottom", "cullface": "down" },
"up": { "uv": [ 0, 0, 16, 16 ], "texture": "#top" },
"north": { "uv": [ 0, 1, 16, 16 ], "texture": "#side", "cullface": "north" },
"south": { "uv": [ 0, 1, 16, 16 ], "texture": "#side", "cullface": "south" },
"west": { "uv": [ 0, 1, 16, 16 ], "texture": "#side", "cullface": "west" },
"east": { "uv": [ 0, 1, 16, 16 ], "texture": "#side", "cullface": "east" }
}
}
]
}

View file

@ -0,0 +1,3 @@
{
"parent": "betterend:block/end_moss_path"
}

View file

@ -0,0 +1,3 @@
{
"parent": "betterend:block/end_mycelium_path"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB