Skip to content

Commit

Permalink
Add golden cake BlockItem
Browse files Browse the repository at this point in the history
Resolves #4
  • Loading branch information
matshou committed Apr 20, 2020
2 parents 71950d9 + 549a515 commit 32285fa
Show file tree
Hide file tree
Showing 13 changed files with 174 additions and 2 deletions.
60 changes: 60 additions & 0 deletions src/main/java/io/yooksi/cococakes/block/GoldenCake.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package io.yooksi.cococakes.block;

import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.MaterialColor;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.Stats;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;

public class GoldenCake extends ModCake {

// TODO: Perhaps move these values to mod config

private final int FOOD_VALUE = 4;
private final float FOOD_SATURATION = 0.2f;

protected GoldenCake(float hardness, SoundType sound) {
super(hardness, sound, MaterialColor.GOLD);
}

@Override
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult p_225533_6_) {

if (worldIn.isRemote) {
ItemStack itemstack = player.getHeldItem(handIn);
if (eatCake(worldIn, pos, state, player) == ActionResultType.SUCCESS) {
return ActionResultType.SUCCESS;
}
else if (itemstack.isEmpty()) {
return ActionResultType.CONSUME;
}
}
return eatCake(worldIn, pos, state, player);
}

private ActionResultType eatCake(IWorld world, BlockPos blockPos, BlockState state, PlayerEntity player) {

if (!player.canEat(false)) {
return ActionResultType.PASS;
}
else {
player.addStat(Stats.EAT_CAKE_SLICE);
player.getFoodStats().addStats(FOOD_VALUE, FOOD_SATURATION);
int i = state.get(BITES);
if (i < 6) {
world.setBlockState(blockPos, state.with(BITES, i + 1), 3);
}
else {
world.removeBlock(blockPos, false);
}
return ActionResultType.SUCCESS;
}
}
}
3 changes: 2 additions & 1 deletion src/main/java/io/yooksi/cococakes/block/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import io.yooksi.cococakes.CocoCakes;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.MaterialColor;
import net.minecraft.util.ResourceLocation;

public enum ModBlocks {

CHOCOLATE_CAKE(new ModCake(0.5f, SoundType.CLOTH), "choco_cake"),
GOLDEN_CAKE(new GoldenCake(0.5f, SoundType.CLOTH), "golden_cake");

private final Block block;

ModBlocks(Block block, String name) {
Expand Down
11 changes: 11 additions & 0 deletions src/main/resources/assets/cococakes/blockstates/golden_cake.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"variants": {
"bites=0": { "model": "cococakes:block/golden_cake" },
"bites=1": { "model": "cococakes:block/golden_cake_slice1" },
"bites=2": { "model": "cococakes:block/golden_cake_slice2" },
"bites=3": { "model": "cococakes:block/golden_cake_slice3" },
"bites=4": { "model": "cococakes:block/golden_cake_slice4" },
"bites=5": { "model": "cococakes:block/golden_cake_slice5" },
"bites=6": { "model": "cococakes:block/golden_cake_slice6" }
}
}
3 changes: 2 additions & 1 deletion src/main/resources/assets/cococakes/lang/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"itemGroup.cococakes": "CocoCakes",
"item.cococakes.cocoa_powder": "Cocoa Powder",
"item.cococakes.choco_milk_bucket": "Chocolate Milk Bucket",
"block.cococakes.choco_cake": "Chocolate Cake"
"block.cococakes.choco_cake": "Chocolate Cake",
"block.cococakes.golden_cake": "Golden Cake"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"parent": "block/cake",
"textures": {
"particle": "cococakes:golden_cake_side",
"bottom": "cococakes:golden_cake_bottom",
"top": "cococakes:golden_cake_top",
"side": "cococakes:golden_cake_side"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"parent": "block/cake_slice1",
"textures": {
"particle": "cococakes:golden_cake_side",
"bottom": "cococakes:golden_cake_bottom",
"top": "cococakes:golden_cake_top",
"side": "cococakes:golden_cake_side",
"inside": "cococakes:golden_cake_inner"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"parent": "block/cake_slice2",
"textures": {
"particle": "cococakes:golden_cake_side",
"bottom": "cococakes:golden_cake_bottom",
"top": "cococakes:golden_cake_top",
"side": "cococakes:golden_cake_side",
"inside": "cococakes:golden_cake_inner"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"parent": "block/cake_slice3",
"textures": {
"particle": "cococakes:golden_cake_side",
"bottom": "cococakes:golden_cake_bottom",
"top": "cococakes:golden_cake_top",
"side": "cococakes:golden_cake_side",
"inside": "cococakes:golden_cake_inner"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"parent": "block/cake_slice4",
"textures": {
"particle": "cococakes:golden_cake_side",
"bottom": "cococakes:golden_cake_bottom",
"top": "cococakes:golden_cake_top",
"side": "cococakes:golden_cake_side",
"inside": "cococakes:golden_cake_inner"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"parent": "block/cake_slice5",
"textures": {
"particle": "cococakes:golden_cake_side",
"bottom": "cococakes:golden_cake_bottom",
"top": "cococakes:golden_cake_top",
"side": "cococakes:golden_cake_side",
"inside": "cococakes:golden_cake_inner"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"parent": "block/cake_slice6",
"textures": {
"particle": "cococakes:golden_cake_side",
"bottom": "cococakes:golden_cake_bottom",
"top": "cococakes:golden_cake_top",
"side": "cococakes:golden_cake_side",
"inside": "cococakes:golden_cake_inner"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "cococakes:golden_cake"
}
}
24 changes: 24 additions & 0 deletions src/main/resources/data/cococakes/recipes/golden_cake.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
" # ",
"#X#",
" # "
],
"key": {
"#": {
"item": "minecraft:gold_ingot"
},
"X": [
{
"item": "minecraft:cake"
},
{
"item": "cococakes:choco_cake"
}
]
},
"result": {
"item": "cococakes:golden_cake"
}
}

0 comments on commit 32285fa

Please sign in to comment.