Skip to content

Commit

Permalink
add charcoal
Browse files Browse the repository at this point in the history
  • Loading branch information
Badtz committed Oct 15, 2023
1 parent 36eadb2 commit 9866a9d
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 9 deletions.
9 changes: 9 additions & 0 deletions src/main/java/me/woach/bone/Bone.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
Expand All @@ -32,6 +34,7 @@
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

Expand All @@ -52,6 +55,8 @@ public static Identifier getId(String path) {
public static final BoneForgeBlock BONE_FORGE_BLOCK = new BoneForgeBlock();

public static final BoneFireBlock BONE_FIRE_BLOCK = new BoneFireBlock();
public static final Block CHARCOAL_BLOCK = new Block(FabricBlockSettings.create().requiresTool()
.strength(3.0f).sounds(BlockSoundGroup.STONE).burnable());

public static final BlockEntityType<BoneForgeBlockEntity> BONE_FORGE_BLOCK_ENTITY = Registry.register(
Registries.BLOCK_ENTITY_TYPE,
Expand All @@ -72,6 +77,7 @@ public void onInitialize() {
Registry.register(Registries.ITEM_GROUP, getId("bone"), ITEM_GROUP.entries((context, entries) -> {
entries.add(BONE_ITEM);
entries.add(BONE_FORGE_BLOCK);
entries.add(CHARCOAL_BLOCK);
for (AbstractItemRegistry ItemRegistry : ITEM_REGISTRIES) {
for (Item item : ItemRegistry.getItems()) {
entries.add(item);
Expand All @@ -83,6 +89,9 @@ public void onInitialize() {
Registry.register(Registries.ITEM, getId("bone_forge"),
new BlockItem(BONE_FORGE_BLOCK, new FabricItemSettings()));
Registry.register(Registries.BLOCK, getId("bone_fire"), BONE_FIRE_BLOCK);
Registry.register(Registries.BLOCK, getId("charcoal_block"), CHARCOAL_BLOCK);
Registry.register(Registries.ITEM, getId("charcoal_block"),
new BlockItem(CHARCOAL_BLOCK, new FabricItemSettings()));
Registry.register(Registries.ITEM, getId("bone_fire"),
new BlockItem(BONE_FIRE_BLOCK, new FabricItemSettings()));
Registry.register(Registries.ITEM, getId("bone"), BONE_ITEM);
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/me/woach/bone/blocks/BoneForgeBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,37 @@ public BoneForgeBlock() {
super(FabricBlockSettings.create().pistonBehavior(PistonBehavior.BLOCK).strength(4.0f).requiresTool()
.luminance(8).sounds(BlockSoundGroup.STONE));
}

@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext context) {
return VoxelShapes.union(
VoxelShapes.cuboid(0.00f, 0.375f, 0.00f, 1.00f, 0.75f, 1.00f));
}

// public static boolean isAlit(WorldAccess world, BlockPos pos) {
// BlockPos below = pos.down();
// }
// public static boolean isAlit(WorldAccess world, BlockPos pos) {
// BlockPos below = pos.down();
// }

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (world.isClient) return ActionResult.SUCCESS;
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand,
BlockHitResult hit) {
if (world.isClient)
return ActionResult.SUCCESS;
BoneForgeBlockEntity blockEntity = (BoneForgeBlockEntity) world.getBlockEntity(pos);
assert blockEntity != null;

ItemStack playersItem = player.getStackInHand(hand);
if (!playersItem.isEmpty()) {
// Try to put tool into forge
if(blockEntity.isBoneforgable(playersItem) && blockEntity.getStack(BoneForgeBlockEntity.TOOL_SLOT).isEmpty()) {
if (blockEntity.isBoneforgable(playersItem)
&& blockEntity.getStack(BoneForgeBlockEntity.TOOL_SLOT).isEmpty()) {
blockEntity.setStack(BoneForgeBlockEntity.TOOL_SLOT, playersItem.copy());
playersItem.setCount(0);
return ActionResult.SUCCESS;
}

// Try to put bone into forge
if(blockEntity.isBone(playersItem) && blockEntity.getStack(BoneForgeBlockEntity.BONE_SLOT).isEmpty()) {
if (blockEntity.isBone(playersItem) && blockEntity.getStack(BoneForgeBlockEntity.BONE_SLOT).isEmpty()) {
blockEntity.setStack(BoneForgeBlockEntity.BONE_SLOT, playersItem.copyWithCount(1));
if (!player.getAbilities().creativeMode) {
playersItem.decrement(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "bone:block/charcoal_block"
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/assets/bone/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"block.bone.bone_forge": "Bone Forge",
"block.bone.charcoal_block": "Block of Charcoal",
"block.bone.bone_fire": "Bone Fire",
"block.bone.bone_fire.type=jord": "Jord Fire",
"block.bone.bone_fire.type=aegir": "Aegir Fire",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "block/cube_all",
"textures": {
"all": "bone:block/charcoal_block"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "bone:block/charcoal_block"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"type": "minecraft:block",
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "minecraft:item",
"name": "bone:charcoal_block"
}
],
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
]
}
]
}
12 changes: 12 additions & 0 deletions src/main/resources/data/bone/recipes/charcoal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "minecraft:crafting_shapeless",
"ingredients": [
{
"item": "bone:charcoal_block"
}
],
"result": {
"item": "minecraft:charcoal",
"count": 9
}
}
16 changes: 16 additions & 0 deletions src/main/resources/data/bone/recipes/charcoal_block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"###",
"###",
"###"
],
"key": {
"#": {
"item": "minecraft:charcoal"
}
},
"result": {
"item": "bone:charcoal_block"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"bone:charcoal_block"
]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"replace": false,
"values": [
"bone:bone_forge"
"bone:bone_forge",
"bone:charcoal_block"
]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"replace": false,
"values": [
"bone:bone_forge"
"bone:bone_forge",
"bone:charcoal_block"
]
}

0 comments on commit 9866a9d

Please sign in to comment.