Added apple pie

This commit is contained in:
Sollace 2022-09-29 22:01:56 +02:00
parent 67e9d5fb3a
commit 3a922f8aa5
24 changed files with 313 additions and 9 deletions

View file

@ -0,0 +1,120 @@
package com.minelittlepony.unicopia.block;
import com.minelittlepony.unicopia.util.SoundEmitter;
import net.minecraft.block.*;
import net.minecraft.entity.ai.pathing.NavigationType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.*;
import net.minecraft.sound.SoundEvents;
import net.minecraft.stat.Stats;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.IntProperty;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.*;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.*;
import net.minecraft.world.event.GameEvent;
public class PieBlock extends Block {
public static final int MAX_BITES = 3;
public static final IntProperty BITES = IntProperty.of("bites", 0, MAX_BITES);
private static final VoxelShape[] SHAPES;
static {
final int PIE_HEIGHT = 5;
final VoxelShape WEDGE = Block.createCuboidShape(1, 0, 1, 8, PIE_HEIGHT, 8);
final float OFFSET_AMOUNT = 7F/16F;
SHAPES = new VoxelShape[] {
Block.createCuboidShape(1, 0, 1, 15, PIE_HEIGHT, 15),
VoxelShapes.union(WEDGE, WEDGE.offset(OFFSET_AMOUNT, 0, 0), WEDGE.offset(OFFSET_AMOUNT, 0, OFFSET_AMOUNT)),
VoxelShapes.union(WEDGE, WEDGE.offset(OFFSET_AMOUNT, 0, 0)),
WEDGE
};
}
public PieBlock(Settings settings) {
super(settings);
setDefaultState(getDefaultState().with(BITES, 0));
}
@Deprecated
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return SHAPES[state.get(BITES)];
}
@Deprecated
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
ItemStack itemStack = player.getStackInHand(hand);
if (world.isClient) {
if (tryEat(world, pos, state, player).isAccepted()) {
return ActionResult.SUCCESS;
}
if (itemStack.isEmpty()) {
return ActionResult.CONSUME;
}
}
return tryEat(world, pos, state, player);
}
protected ActionResult tryEat(WorldAccess world, BlockPos pos, BlockState state, PlayerEntity player) {
if (!player.canConsume(false)) {
return ActionResult.PASS;
}
player.incrementStat(Stats.EAT_CAKE_SLICE);
player.getHungerManager().add(2, 0.1f);
int bites = state.get(BITES);
world.emitGameEvent(player, GameEvent.EAT, pos);
SoundEmitter.playSoundAt(player, SoundEvents.ENTITY_PLAYER_BURP, 0.5F, world.getRandom().nextFloat() * 0.1F + 0.9F);
if (bites < MAX_BITES) {
world.setBlockState(pos, state.with(BITES, bites + 1), Block.NOTIFY_ALL);
} else {
world.removeBlock(pos, false);
world.emitGameEvent(player, GameEvent.BLOCK_DESTROY, pos);
}
return ActionResult.SUCCESS;
}
@Deprecated
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (direction == Direction.DOWN && !state.canPlaceAt(world, pos)) {
return Blocks.AIR.getDefaultState();
}
return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);
}
@Deprecated
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
return world.getBlockState(pos.down()).getMaterial().isSolid();
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(BITES);
}
@Override
public int getComparatorOutput(BlockState state, World world, BlockPos pos) {
return (5 - state.get(BITES)) * 2;
}
@Override
public boolean hasComparatorOutput(BlockState state) {
return true;
}
@Override
public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) {
return false;
}
}

View file

@ -66,6 +66,8 @@ public interface UBlocks {
Block SOUR_APPLE = register("sour_apple", new FruitBlock(FabricBlockSettings.of(Material.GOURD, MapColor.GREEN).sounds(BlockSoundGroup.WOOD), Direction.DOWN, SOUR_APPLE_LEAVES, FruitBlock.DEFAULT_SHAPE));
Block SOUR_APPLE_SPROUT = register("sour_apple_sprout", new SproutBlock(0xE5FFCC88, () -> UItems.SOUR_APPLE_SEEDS, () -> UTreeGen.SOUR_APPLE_TREE.sapling().map(Block::getDefaultState).get()));
Block APPLE_PIE = register("apple_pie", new PieBlock(FabricBlockSettings.of(Material.CAKE, MapColor.ORANGE).strength(0.5F).sounds(BlockSoundGroup.WOOL)));
SegmentedCropBlock OATS = register("oats", SegmentedCropBlock.create(11, 5, AbstractBlock.Settings.copy(Blocks.WHEAT), () -> UItems.OAT_SEEDS, null, () -> UBlocks.OATS_STEM));
SegmentedCropBlock OATS_STEM = register("oats_stem", OATS.createNext(5));
SegmentedCropBlock OATS_CROWN = register("oats_crown", OATS_STEM.createNext(5));

View file

@ -83,6 +83,7 @@ public interface UItems {
Item CIDER = register("cider", new DrinkableItem(new Item.Settings().group(ItemGroup.FOOD).food(UFoodComponents.CIDER).maxCount(1).recipeRemainder(MUG)));
Item JUICE = register("juice", new DrinkableItem(new Item.Settings().group(ItemGroup.FOOD).recipeRemainder(Items.GLASS_BOTTLE).maxCount(1).food(UFoodComponents.JUICE)));
Item BURNED_JUICE = register("burned_juice", new DrinkableItem(new Item.Settings().group(ItemGroup.FOOD).recipeRemainder(Items.GLASS_BOTTLE).maxCount(1).food(UFoodComponents.BURNED_JUICE)));
Item APPLE_PIE = register("apple_pie", new BlockItem(UBlocks.APPLE_PIE, new Item.Settings().group(ItemGroup.FOOD).maxCount(1)));
Item GOLDEN_FEATHER = register("golden_feather", new Item(new Item.Settings().rarity(Rarity.UNCOMMON).group(ItemGroup.MATERIALS)));
Item GOLDEN_WING = register("golden_wing", new Item(new Item.Settings().rarity(Rarity.UNCOMMON).group(ItemGroup.MATERIALS)));

View file

@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.util;
import net.minecraft.entity.Entity;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.World;
public interface SoundEmitter {
@ -21,7 +22,7 @@ public interface SoundEmitter {
}
default float getRandomPitch() {
return (float)getReferenceWorld().getRandom().nextTriangular(0.5F, 0.2F);
return getRandomPitch(getReferenceWorld().getRandom());
}
static void playSoundAt(Entity entity, SoundEvent sound, float pitch, float volume) {
@ -31,4 +32,8 @@ public interface SoundEmitter {
static void playSoundAt(Entity entity, SoundEvent sound, SoundCategory category, float pitch, float volume) {
entity.world.playSound(null, entity.getX(), entity.getY(), entity.getZ(), sound, category, volume, pitch);
}
static float getRandomPitch(Random rng) {
return (float)rng.nextTriangular(0.5F, 0.2F);
}
}

View file

@ -0,0 +1,8 @@
{
"variants": {
"bites=0": { "model": "unicopia:block/apple_pie" },
"bites=1": { "model": "unicopia:block/apple_pie_elbow" },
"bites=2": { "model": "unicopia:block/apple_pie_straight" },
"bites=3": { "model": "unicopia:block/apple_pie_corner" }
}
}

View file

@ -106,6 +106,7 @@
"block.unicopia.zap_leaves": "Zap Apple Leaves",
"block.unicopia.zap_apple": "Zap Apple",
"block.unicopia.zap_bulb": "Unripened Zap Apple",
"block.unicopia.apple_pie": "Apple Pie",
"block.unicopia.green_apple_leaves": "Granny Smith Leaves",
"block.unicopia.green_apple_sapling": "Granny Smith Sapling",

View file

@ -0,0 +1,9 @@
{
"parent": "unicopia:block/pie_full",
"textures": {
"top": "unicopia:block/apple_pie_top",
"bottom": "unicopia:block/apple_pie_bottom",
"sides": "unicopia:block/apple_pie_side",
"inner": "unicopia:block/apple_pie_inner"
}
}

View file

@ -0,0 +1,9 @@
{
"parent": "unicopia:block/pie_corner",
"textures": {
"top": "unicopia:block/apple_pie_top",
"bottom": "unicopia:block/apple_pie_bottom",
"sides": "unicopia:block/apple_pie_side",
"inner": "unicopia:block/apple_pie_inner"
}
}

View file

@ -0,0 +1,9 @@
{
"parent": "unicopia:block/pie_elbow",
"textures": {
"top": "unicopia:block/apple_pie_top",
"bottom": "unicopia:block/apple_pie_bottom",
"sides": "unicopia:block/apple_pie_side",
"inner": "unicopia:block/apple_pie_inner"
}
}

View file

@ -0,0 +1,9 @@
{
"parent": "unicopia:block/pie_straight",
"textures": {
"top": "unicopia:block/apple_pie_top",
"bottom": "unicopia:block/apple_pie_bottom",
"sides": "unicopia:block/apple_pie_side",
"inner": "unicopia:block/apple_pie_inner"
}
}

View file

@ -1,7 +0,0 @@
{
"parent": "minecraft:block/cube_column",
"textures": {
"end": "minecraft:block/melon_top",
"side": "minecraft:block/melon_side"
}
}

View file

@ -0,0 +1,18 @@
{
"textures": {
"particle": "#top"
},
"elements": [
{ "from": [ 1, 0, 1 ],
"to": [ 8, 5, 8 ],
"faces": {
"up": { "uv": [ 1, 1, 8, 8 ], "texture": "#top" },
"down": { "uv": [ 1, 8, 8, 15 ], "texture": "#bottom" },
"north": { "uv": [ 8, 11, 15, 16 ], "texture": "#sides" },
"south": { "uv": [ 1, 11, 8, 16 ], "texture": "#inner" },
"west": { "uv": [ 1, 11, 8, 16 ], "texture": "#sides" },
"east": { "uv": [ 8, 11, 15, 16 ], "texture": "#inner" }
}
}
]
}

View file

@ -0,0 +1,29 @@
{
"textures": {
"particle": "#top"
},
"elements": [
{ "from": [ 1, 0, 1 ],
"to": [ 15, 5, 8 ],
"faces": {
"up": { "uv": [ 1, 1, 15, 8 ], "texture": "#top" },
"down": { "uv": [ 1, 8, 15, 15 ], "texture": "#bottom" },
"north": { "uv": [ 1, 11, 15, 16 ], "texture": "#sides" },
"south": { "uv": [ 1, 11, 15, 16 ], "texture": "#inner" },
"west": { "uv": [ 1, 11, 8, 16 ], "texture": "#sides" },
"east": { "uv": [ 8, 11, 15, 16 ], "texture": "#sides" }
}
},
{ "from": [ 8, 0, 8 ],
"to": [ 15, 5, 15 ],
"faces": {
"up": { "uv": [ 8, 8, 15, 15 ], "texture": "#top" },
"down": { "uv": [ 8, 1, 15, 8 ], "texture": "#bottom" },
"north": { "uv": [ 1, 11, 8, 16 ], "texture": "#sides" },
"south": { "uv": [ 8, 11, 15, 16 ], "texture": "#sides" },
"west": { "uv": [ 8, 11, 15, 16 ], "texture": "#inner" },
"east": { "uv": [ 1, 11, 8, 16 ], "texture": "#sides" }
}
}
]
}

View file

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

View file

@ -0,0 +1,18 @@
{
"textures": {
"particle": "#top"
},
"elements": [
{ "from": [ 1, 0, 1 ],
"to": [ 15, 5, 8 ],
"faces": {
"up": { "uv": [ 1, 1, 15, 8 ], "texture": "#top" },
"down": { "uv": [ 1, 8, 15, 15 ], "texture": "#bottom" },
"north": { "uv": [ 1, 11, 15, 16 ], "texture": "#sides" },
"south": { "uv": [ 1, 11, 15, 16 ], "texture": "#inner" },
"west": { "uv": [ 1, 11, 8, 16 ], "texture": "#sides" },
"east": { "uv": [ 8, 11, 15, 16 ], "texture": "#sides" }
}
}
]
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:item/apple_pie"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View file

@ -0,0 +1,30 @@
{
"parent": "minecraft:recipes/root",
"rewards": {
"recipes": [
"unicopia:apple_pie"
]
},
"criteria": {
"has_ingredients": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{ "tag": [ "unicopia:fresh_apples" ] }
]
}
},
"has_the_recipe": {
"trigger": "minecraft:recipe_unlocked",
"conditions": {
"recipe": "unicopia:apple_pie"
}
}
},
"requirements": [
[
"has_ingredients",
"has_the_recipe"
]
]
}

View file

@ -10,7 +10,7 @@
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{ "tag": "unicopia:oats" }
{ "item": "unicopia:oats" }
]
}
},

View file

@ -0,0 +1,19 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"***",
"###",
"***"
],
"key": {
"#": {
"tag": "unicopia:fresh_apples"
},
"*": {
"item": "minecraft:wheat"
}
},
"result": {
"item": "unicopia:apple_pie"
}
}