mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-17 10:24:23 +01:00
Added apple pie
This commit is contained in:
parent
67e9d5fb3a
commit
3a922f8aa5
24 changed files with 313 additions and 9 deletions
120
src/main/java/com/minelittlepony/unicopia/block/PieBlock.java
Normal file
120
src/main/java/com/minelittlepony/unicopia/block/PieBlock.java
Normal 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;
|
||||
}
|
||||
}
|
|
@ -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));
|
||||
|
|
|
@ -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)));
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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" }
|
||||
}
|
||||
}
|
|
@ -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",
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
|
@ -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"
|
||||
}
|
||||
}
|
|
@ -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"
|
||||
}
|
||||
}
|
|
@ -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"
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
{
|
||||
"parent": "minecraft:block/cube_column",
|
||||
"textures": {
|
||||
"end": "minecraft:block/melon_top",
|
||||
"side": "minecraft:block/melon_side"
|
||||
}
|
||||
}
|
|
@ -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" }
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -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" }
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -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" }
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -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" }
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -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 |
BIN
src/main/resources/assets/unicopia/textures/item/apple_pie.png
Normal file
BIN
src/main/resources/assets/unicopia/textures/item/apple_pie.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
|
@ -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"
|
||||
]
|
||||
]
|
||||
}
|
|
@ -10,7 +10,7 @@
|
|||
"trigger": "minecraft:inventory_changed",
|
||||
"conditions": {
|
||||
"items": [
|
||||
{ "tag": "unicopia:oats" }
|
||||
{ "item": "unicopia:oats" }
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
19
src/main/resources/data/unicopia/recipes/apple_pie.json
Normal file
19
src/main/resources/data/unicopia/recipes/apple_pie.json
Normal file
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"type": "minecraft:crafting_shaped",
|
||||
"pattern": [
|
||||
"***",
|
||||
"###",
|
||||
"***"
|
||||
],
|
||||
"key": {
|
||||
"#": {
|
||||
"tag": "unicopia:fresh_apples"
|
||||
},
|
||||
"*": {
|
||||
"item": "minecraft:wheat"
|
||||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "unicopia:apple_pie"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue