diff --git a/src/main/java/com/minelittlepony/unicopia/block/FruitBlock.java b/src/main/java/com/minelittlepony/unicopia/block/FruitBlock.java index f5a75aeb..cdcc47f8 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/FruitBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/FruitBlock.java @@ -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 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 diff --git a/src/main/java/com/minelittlepony/unicopia/block/SproutBlock.java b/src/main/java/com/minelittlepony/unicopia/block/SproutBlock.java new file mode 100644 index 00000000..ca934c01 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/block/SproutBlock.java @@ -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 matureState; + + private final int overlay; + + public SproutBlock(int overlay, ItemConvertible seeds, Supplier 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); + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/block/UBlocks.java b/src/main/java/com/minelittlepony/unicopia/block/UBlocks.java index 6e75221c..b2cb7f61 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/UBlocks.java +++ b/src/main/java/com/minelittlepony/unicopia/block/UBlocks.java @@ -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 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 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); } diff --git a/src/main/java/com/minelittlepony/unicopia/client/URenderers.java b/src/main/java/com/minelittlepony/unicopia/client/URenderers.java index 2c0b4784..a6b509d5 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/URenderers.java +++ b/src/main/java/com/minelittlepony/unicopia/client/URenderers.java @@ -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 PendingParticleFactory createFactory(ParticleSupplier supplier) { diff --git a/src/main/java/com/minelittlepony/unicopia/item/UItems.java b/src/main/java/com/minelittlepony/unicopia/item/UItems.java index 81ca8677..096dcb25 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/UItems.java +++ b/src/main/java/com/minelittlepony/unicopia/item/UItems.java @@ -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))); diff --git a/src/main/resources/assets/unicopia/blockstates/green_apple_sprout.json b/src/main/resources/assets/unicopia/blockstates/green_apple_sprout.json new file mode 100644 index 00000000..7f3b2549 --- /dev/null +++ b/src/main/resources/assets/unicopia/blockstates/green_apple_sprout.json @@ -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" + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/lang/en_us.json b/src/main/resources/assets/unicopia/lang/en_us.json index 67df2c27..d78689e3 100644 --- a/src/main/resources/assets/unicopia/lang/en_us.json +++ b/src/main/resources/assets/unicopia/lang/en_us.json @@ -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", diff --git a/src/main/resources/assets/unicopia/models/block/green_apple_sprout_stage0.json b/src/main/resources/assets/unicopia/models/block/green_apple_sprout_stage0.json new file mode 100644 index 00000000..7f8918c5 --- /dev/null +++ b/src/main/resources/assets/unicopia/models/block/green_apple_sprout_stage0.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:block/stem_growth0", + "textures": { + "stem": "minecraft:block/melon_stem" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/models/block/green_apple_sprout_stage1.json b/src/main/resources/assets/unicopia/models/block/green_apple_sprout_stage1.json new file mode 100644 index 00000000..0d573b71 --- /dev/null +++ b/src/main/resources/assets/unicopia/models/block/green_apple_sprout_stage1.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:block/stem_growth1", + "textures": { + "stem": "minecraft:block/melon_stem" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/models/block/green_apple_sprout_stage2.json b/src/main/resources/assets/unicopia/models/block/green_apple_sprout_stage2.json new file mode 100644 index 00000000..c1934202 --- /dev/null +++ b/src/main/resources/assets/unicopia/models/block/green_apple_sprout_stage2.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:block/stem_growth2", + "textures": { + "stem": "minecraft:block/melon_stem" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/models/block/green_apple_sprout_stage3.json b/src/main/resources/assets/unicopia/models/block/green_apple_sprout_stage3.json new file mode 100644 index 00000000..8b4ef33f --- /dev/null +++ b/src/main/resources/assets/unicopia/models/block/green_apple_sprout_stage3.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:block/stem_growth3", + "textures": { + "stem": "minecraft:block/melon_stem" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/models/block/green_apple_sprout_stage4.json b/src/main/resources/assets/unicopia/models/block/green_apple_sprout_stage4.json new file mode 100644 index 00000000..cba7914b --- /dev/null +++ b/src/main/resources/assets/unicopia/models/block/green_apple_sprout_stage4.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:block/stem_growth4", + "textures": { + "stem": "minecraft:block/melon_stem" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/models/block/green_apple_sprout_stage5.json b/src/main/resources/assets/unicopia/models/block/green_apple_sprout_stage5.json new file mode 100644 index 00000000..bd48d3f1 --- /dev/null +++ b/src/main/resources/assets/unicopia/models/block/green_apple_sprout_stage5.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:block/stem_growth5", + "textures": { + "stem": "minecraft:block/melon_stem" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/models/block/green_apple_sprout_stage6.json b/src/main/resources/assets/unicopia/models/block/green_apple_sprout_stage6.json new file mode 100644 index 00000000..c8f07f26 --- /dev/null +++ b/src/main/resources/assets/unicopia/models/block/green_apple_sprout_stage6.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:block/stem_growth6", + "textures": { + "stem": "minecraft:block/melon_stem" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/models/block/green_apple_sprout_stage7.json b/src/main/resources/assets/unicopia/models/block/green_apple_sprout_stage7.json new file mode 100644 index 00000000..2b479f70 --- /dev/null +++ b/src/main/resources/assets/unicopia/models/block/green_apple_sprout_stage7.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:block/stem_growth7", + "textures": { + "stem": "minecraft:block/melon_stem" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/models/block/melon.json b/src/main/resources/assets/unicopia/models/block/melon.json new file mode 100644 index 00000000..ef3816b9 --- /dev/null +++ b/src/main/resources/assets/unicopia/models/block/melon.json @@ -0,0 +1,7 @@ +{ + "parent": "minecraft:block/cube_column", + "textures": { + "end": "minecraft:block/melon_top", + "side": "minecraft:block/melon_side" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/models/item/green_apple_seeds.json b/src/main/resources/assets/unicopia/models/item/green_apple_seeds.json new file mode 100644 index 00000000..8c88f5e8 --- /dev/null +++ b/src/main/resources/assets/unicopia/models/item/green_apple_seeds.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "unicopia:item/green_apple_seeds" + } +} diff --git a/src/main/resources/assets/unicopia/textures/item/green_apple_seeds.png b/src/main/resources/assets/unicopia/textures/item/green_apple_seeds.png new file mode 100644 index 00000000..78a8d100 Binary files /dev/null and b/src/main/resources/assets/unicopia/textures/item/green_apple_seeds.png differ diff --git a/src/main/resources/data/unicopia/recipes/green_apple_to_seeds.json b/src/main/resources/data/unicopia/recipes/green_apple_to_seeds.json new file mode 100644 index 00000000..7794b7ea --- /dev/null +++ b/src/main/resources/data/unicopia/recipes/green_apple_to_seeds.json @@ -0,0 +1,7 @@ +{ + "type": "minecraft:crafting_shapeless", + "ingredients": [ + { "item": "unicopia:green_apple" } + ], + "result": { "item": "unicopia:green_apple_seeds", "count": 3 } +}