Add green apple seeds and recipe

This commit is contained in:
Sollace 2022-09-25 01:55:29 +02:00
parent 9476b5634c
commit 9e0e03379e
19 changed files with 202 additions and 14 deletions

View file

@ -1,6 +1,5 @@
package com.minelittlepony.unicopia.block;
import java.util.ArrayList;
import java.util.List;
import com.minelittlepony.unicopia.ability.EarthPonyKickAbility.Buckable;
@ -19,8 +18,6 @@ public class FruitBlock extends Block implements Buckable {
public static final int DEFAULT_FRUIT_SIZE = 8;
public static final VoxelShape DEFAULT_SHAPE = createFruitShape(DEFAULT_FRUIT_SIZE);
public static final List<FruitBlock> REGISTRY = new ArrayList<>();
private final Direction attachmentFace;
private final Block stem;
private final VoxelShape shape;
@ -37,7 +34,6 @@ public class FruitBlock extends Block implements Buckable {
this.attachmentFace = attachmentFace;
this.stem = stem;
this.shape = shape;
REGISTRY.add(this);
}
@Override

View file

@ -0,0 +1,87 @@
package com.minelittlepony.unicopia.block;
import java.util.function.Supplier;
import org.jetbrains.annotations.Nullable;
import net.minecraft.block.*;
import net.minecraft.item.ItemConvertible;
import net.minecraft.item.ItemStack;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.math.*;
import net.minecraft.util.math.random.Random;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.*;
public class SproutBlock extends CropBlock implements TintedBlock {
private static final VoxelShape[] AGE_TO_SHAPE = new VoxelShape[]{
Block.createCuboidShape(7, 0, 7, 9, 2, 9),
Block.createCuboidShape(7, 0, 7, 9, 4, 9),
Block.createCuboidShape(7, 0, 7, 9, 6, 9),
Block.createCuboidShape(7, 0, 7, 9, 8, 9),
Block.createCuboidShape(7, 0, 7, 9, 10, 9),
Block.createCuboidShape(7, 0, 7, 9, 12, 9),
Block.createCuboidShape(7, 0, 7, 9, 14, 9),
Block.createCuboidShape(7, 0, 7, 9, 16, 9)
};
private final ItemConvertible seeds;
private final Supplier<BlockState> matureState;
private final int overlay;
public SproutBlock(int overlay, ItemConvertible seeds, Supplier<BlockState> matureState) {
super(Settings.of(Material.PLANT).noCollision().ticksRandomly().breakInstantly().sounds(BlockSoundGroup.STEM));
this.seeds = seeds;
this.matureState = matureState;
this.overlay = overlay;
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return AGE_TO_SHAPE[state.get(getAgeProperty())];
}
@Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
super.randomTick(state, world, pos, random);
onGrow(world, world.getBlockState(pos), pos);
}
@Override
public void applyGrowth(World world, BlockPos pos, BlockState state) {
super.applyGrowth(world, pos, state);
onGrow(world, world.getBlockState(pos), pos);
}
@Override
protected ItemConvertible getSeedsItem() {
return seeds;
}
@Override
public ItemStack getPickStack(BlockView world, BlockPos pos, BlockState state) {
return new ItemStack(seeds.asItem());
}
protected void onGrow(World world, BlockState state, BlockPos pos) {
if (isMature(state)) {
mature(world, state, pos);
}
}
protected void mature(World world, BlockState state, BlockPos pos) {
state = matureState.get();
world.setBlockState(pos, matureState.get());
BlockSoundGroup group = state.getSoundGroup();
world.playSound(null, pos, group.getPlaceSound(), SoundCategory.BLOCKS, group.getVolume(), group.getPitch());
}
@Override
public int getTint(BlockState state, @Nullable BlockRenderView world, @Nullable BlockPos pos, int foliageColor) {
return TintedBlock.blend(foliageColor, overlay);
}
}

View file

@ -1,5 +1,8 @@
package com.minelittlepony.unicopia.block;
import java.util.ArrayList;
import java.util.List;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.item.UItems;
@ -18,6 +21,8 @@ import net.minecraft.util.registry.Registry;
import net.minecraft.world.BlockView;
public interface UBlocks {
List<Block> TRANSLUCENT_BLOCKS = new ArrayList<>();
Block ROCKS = register("rocks", new RockCropBlock(FabricBlockSettings.of(
new FabricMaterialBuilder(MapColor.STONE_GRAY).allowsMovement().lightPassesThrough().notSolid().destroyedByPiston().build()
)
@ -29,10 +34,10 @@ public interface UBlocks {
Block FROSTED_OBSIDIAN = register("frosted_obsidian", new FrostedObsidianBlock(FabricBlockSettings.copy(Blocks.OBSIDIAN).ticksRandomly()));
Block ZAP_LOG = register("zap_log", new ZapAppleLogBlock(Blocks.OAK_LOG, MapColor.GRAY, MapColor.DEEPSLATE_GRAY), ItemGroup.MATERIALS);
Block ZAP_WOOD = register("zap_wood", new ZapBlock(AbstractBlock.Settings.of(Material.WOOD, MapColor.DEEPSLATE_GRAY).sounds(BlockSoundGroup.WOOD), Blocks.OAK_WOOD), ItemGroup.MATERIALS);
Block ZAP_WOOD = register("zap_wood", new ZapAppleLogBlock(Blocks.OAK_WOOD, MapColor.DEEPSLATE_GRAY, MapColor.DEEPSLATE_GRAY), ItemGroup.MATERIALS);
Block STRIPPED_ZAP_LOG = register("stripped_zap_log", new ZapAppleLogBlock(Blocks.STRIPPED_OAK_LOG, MapColor.LIGHT_GRAY, MapColor.GRAY), ItemGroup.MATERIALS);
Block STRIPPED_ZAP_WOOD = register("stripped_zap_wood", new ZapBlock(AbstractBlock.Settings.of(Material.WOOD, MapColor.DEEPSLATE_GRAY).sounds(BlockSoundGroup.WOOD), Blocks.STRIPPED_OAK_WOOD), ItemGroup.MATERIALS);
Block STRIPPED_ZAP_WOOD = register("stripped_zap_wood", new ZapAppleLogBlock(Blocks.STRIPPED_OAK_WOOD, MapColor.GRAY, MapColor.GRAY), ItemGroup.MATERIALS);
Block ZAP_LEAVES = register("zap_leaves", new ZapAppleLeavesBlock(), ItemGroup.DECORATIONS);
Block ZAP_BULB = register("zap_bulb", new FruitBlock(FabricBlockSettings.of(Material.GOURD, MapColor.GRAY).strength(500, 1200).sounds(BlockSoundGroup.AZALEA_LEAVES), Direction.DOWN, ZAP_LEAVES, FruitBlock.DEFAULT_SHAPE));
@ -44,6 +49,7 @@ public interface UBlocks {
() -> UItems.GREEN_APPLE.getDefaultStack()
), ItemGroup.DECORATIONS);
Block GREEN_APPLE = register("green_apple", new FruitBlock(FabricBlockSettings.of(Material.GOURD, MapColor.GREEN).sounds(BlockSoundGroup.WOOD), Direction.DOWN, GREEN_APPLE_LEAVES, FruitBlock.DEFAULT_SHAPE));
Block GREEN_APPLE_SPROUT = register("green_apple_sprout", new SproutBlock(0xE5FFFF88, () -> UItems.GREEN_APPLE_SEEDS, () -> UTreeGen.GREEN_APPLE_TREE.sapling().map(Block::getDefaultState).get()));
static <T extends Block> T register(String name, T item) {
return register(Unicopia.id(name), item);
@ -62,6 +68,9 @@ public interface UBlocks {
if (block instanceof TintedBlock) {
TintedBlock.REGISTRY.add(block);
}
if (block instanceof SaplingBlock || block instanceof SproutBlock || block instanceof FruitBlock) {
TRANSLUCENT_BLOCKS.add(block);
}
return Registry.register(Registry.BLOCK, id, block);
}

View file

@ -35,9 +35,7 @@ import net.minecraft.client.color.world.FoliageColors;
import net.minecraft.client.item.ModelPredicateProviderRegistry;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.particle.SpriteProvider;
import net.minecraft.client.render.DiffuseLighting;
import net.minecraft.client.render.OverlayTexture;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.*;
import net.minecraft.client.render.entity.FlyingItemEntityRenderer;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.render.model.json.ModelTransformation;
@ -135,14 +133,12 @@ public interface URenderers {
ColorProviderRegistry.BLOCK.register(tintedProvider, TintedBlock.REGISTRY.stream().toArray(Block[]::new));
ColorProviderRegistry.ITEM.register((stack, i) -> {
Block block = Block.getBlockFromItem(stack.getItem());
return block instanceof TintedBlock ? tintedProvider.getColor(block.getDefaultState(), null, null, i) : FoliageColors.getDefaultColor();
return tintedProvider.getColor(Block.getBlockFromItem(stack.getItem()).getDefaultState(), null, null, i);
}, TintedBlock.REGISTRY.stream().map(Block::asItem).filter(i -> i != Items.AIR).toArray(Item[]::new));
BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayers.getTranslucent(), FruitBlock.REGISTRY.stream().toArray(FruitBlock[]::new));
BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayers.getTranslucent(), Tree.REGISTRY.stream().flatMap(tree -> tree.sapling().stream()).toArray(Block[]::new));
BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getCutout(), UBlocks.TRANSLUCENT_BLOCKS.stream().toArray(Block[]::new));
// for lava boats
BlockRenderLayerMap.INSTANCE.putFluids(RenderLayers.getTranslucent(), Fluids.LAVA, Fluids.FLOWING_LAVA);
BlockRenderLayerMap.INSTANCE.putFluids(RenderLayer.getTranslucent(), Fluids.LAVA, Fluids.FLOWING_LAVA);
}
static <T extends ParticleEffect> PendingParticleFactory<T> createFactory(ParticleSupplier<T> supplier) {

View file

@ -79,6 +79,8 @@ public interface UItems {
Item WEIRD_ROCK = register("weird_rock", new Item(new Item.Settings().group(ItemGroup.MATERIALS)));
Item ROCK_STEW = register("rock_stew", new Item(new Item.Settings().group(ItemGroup.FOOD).food(FoodComponents.MUSHROOM_STEW)));
Item GREEN_APPLE_SEEDS = register("green_apple_seeds", new AliasedBlockItem(UBlocks.GREEN_APPLE_SPROUT, new Item.Settings().group(ItemGroup.MATERIALS)));
Item MUG = register("mug", new Item(new Settings().group(ItemGroup.MATERIALS).maxCount(16)));
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)));

View file

@ -0,0 +1,28 @@
{
"variants": {
"age=0": {
"model": "unicopia:block/green_apple_sprout_stage0"
},
"age=1": {
"model": "unicopia:block/green_apple_sprout_stage1"
},
"age=2": {
"model": "unicopia:block/green_apple_sprout_stage2"
},
"age=3": {
"model": "unicopia:block/green_apple_sprout_stage3"
},
"age=4": {
"model": "unicopia:block/green_apple_sprout_stage4"
},
"age=5": {
"model": "unicopia:block/green_apple_sprout_stage5"
},
"age=6": {
"model": "unicopia:block/green_apple_sprout_stage6"
},
"age=7": {
"model": "unicopia:block/green_apple_sprout_stage7"
}
}
}

View file

@ -57,6 +57,7 @@
"item.unicopia.rock": "Rock",
"item.unicopia.weird_rock": "Weird Rock",
"item.unicopia.rock_stew": "Rock Stew",
"item.unicopia.green_apple_seeds": "Granny Smith Apple Seeds",
"item.unicopia.daffodil_daisy_sandwich": "Daffodil Daisy Sandwich",
"item.unicopia.hay_burger": "Hay Burger",
@ -98,6 +99,7 @@
"block.unicopia.zap_bulb": "Unripened Zap Apple",
"block.unicopia.green_apple_leaves": "Granny Smith Leaves",
"block.unicopia.green_apple_sapling": "Granny Smith Sapling",
"block.unicopia.green_apple_sprout": "Granny Smith Sprout",
"entity.unicopia.butterfly": "Butterfly",
"entity.unicopia.twittermite": "Twittermite",

View file

@ -0,0 +1,6 @@
{
"parent": "minecraft:block/stem_growth0",
"textures": {
"stem": "minecraft:block/melon_stem"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "minecraft:block/stem_growth1",
"textures": {
"stem": "minecraft:block/melon_stem"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "minecraft:block/stem_growth2",
"textures": {
"stem": "minecraft:block/melon_stem"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "minecraft:block/stem_growth3",
"textures": {
"stem": "minecraft:block/melon_stem"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "minecraft:block/stem_growth4",
"textures": {
"stem": "minecraft:block/melon_stem"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "minecraft:block/stem_growth5",
"textures": {
"stem": "minecraft:block/melon_stem"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "minecraft:block/stem_growth6",
"textures": {
"stem": "minecraft:block/melon_stem"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "minecraft:block/stem_growth7",
"textures": {
"stem": "minecraft:block/melon_stem"
}
}

View file

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

View file

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

@ -0,0 +1,7 @@
{
"type": "minecraft:crafting_shapeless",
"ingredients": [
{ "item": "unicopia:green_apple" }
],
"result": { "item": "unicopia:green_apple_seeds", "count": 3 }
}