From 6caacbd2017eecf904bc8da8dc52f2cc8b028945 Mon Sep 17 00:00:00 2001 From: maxbick Date: Sun, 3 Dec 2023 14:04:51 -0500 Subject: [PATCH 1/7] Added BeanstalkBlock, as well as its model and tag files --- .../hugman/mubble/block/BeanstalkBlock.java | 53 +++++++++++++++++++ .../fr/hugman/mubble/registry/SuperMario.java | 8 ++- .../fr/hugman/mubble/tag/MubbleBlockTags.java | 10 ++++ .../assets/mubble/blockstates/beanstalk.json | 7 +++ .../assets/mubble/models/block/beanstalk.json | 29 ++++++++++ .../tags/blocks/beanstalk_plantable_on.json | 13 +++++ 6 files changed, 115 insertions(+), 5 deletions(-) create mode 100644 src/main/java/fr/hugman/mubble/block/BeanstalkBlock.java create mode 100644 src/main/java/fr/hugman/mubble/tag/MubbleBlockTags.java create mode 100644 src/main/resources/assets/mubble/blockstates/beanstalk.json create mode 100644 src/main/resources/assets/mubble/models/block/beanstalk.json create mode 100644 src/main/resources/data/mubble/tags/blocks/beanstalk_plantable_on.json diff --git a/src/main/java/fr/hugman/mubble/block/BeanstalkBlock.java b/src/main/java/fr/hugman/mubble/block/BeanstalkBlock.java new file mode 100644 index 00000000..3b51a8ae --- /dev/null +++ b/src/main/java/fr/hugman/mubble/block/BeanstalkBlock.java @@ -0,0 +1,53 @@ +package fr.hugman.mubble.block; + +import fr.hugman.mubble.tag.MubbleBlockTags; +import net.minecraft.block.*; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.random.Random; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.util.shape.VoxelShapes; +import net.minecraft.world.BlockView; +import net.minecraft.world.World; +import net.minecraft.world.WorldView; + +/** + * Most of the functions of this code were + * essentially copied from the BambooBlock class. + * + * @author MaxBrick + * @since v4.0.0 + */ + +public class BeanstalkBlock extends Block implements Fertilizable { + public BeanstalkBlock(AbstractBlock.Settings settings) { + super(settings); + } + + public boolean isTransparent(BlockState state, BlockView world, BlockPos pos) { + return true; + } + public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + return VoxelShapes.fullCube(); + } + + public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + return VoxelShapes.empty(); + } + + public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + return world.getBlockState(pos.down()).isIn(MubbleBlockTags.BEANSTALK_PLANTABLE_ON); + } + + public boolean isFertilizable(WorldView world, BlockPos pos, BlockState state, boolean isClient) { + return world.getBlockState(pos.up(pos.getY() - world.getHeight())) == state; + } + + public boolean canGrow(World world, Random random, BlockPos pos, BlockState state) { + return true; + } + + public void grow(ServerWorld world, Random random, BlockPos pos, BlockState state) { + world.setBlockState(pos.up(1), state); + } +} diff --git a/src/main/java/fr/hugman/mubble/registry/SuperMario.java b/src/main/java/fr/hugman/mubble/registry/SuperMario.java index e98f709e..43d2df40 100644 --- a/src/main/java/fr/hugman/mubble/registry/SuperMario.java +++ b/src/main/java/fr/hugman/mubble/registry/SuperMario.java @@ -5,11 +5,7 @@ import fr.hugman.dawn.block.DawnBlockSettings; import fr.hugman.dawn.item.DawnItemSettings; import fr.hugman.mubble.Mubble; -import fr.hugman.mubble.block.BeepBlock; -import fr.hugman.mubble.block.EmptyBlock; -import fr.hugman.mubble.block.DecoratedBumpableBlock; -import fr.hugman.mubble.block.NoteBlock; -import fr.hugman.mubble.block.SnakeBlock; +import fr.hugman.mubble.block.*; import fr.hugman.mubble.block.entity.BumpableBlockEntity; import fr.hugman.mubble.item.CapeFeatherItem; import fr.hugman.mubble.screen.BumpableBlockScreenHandler; @@ -48,6 +44,7 @@ public class SuperMario { public static final SnakeBlock SLOW_SNAKE_BLOCK = new SnakeBlock(DawnBlockSettings.copy(Blocks.IRON_BLOCK).mapColor(MapColor.RED).item()); public static final BeepBlock RED_BEEP_BLOCK = new BeepBlock(MapColor.RED, false); public static final BeepBlock BLUE_BEEP_BLOCK = new BeepBlock(MapColor.BLUE, true); + public static final BeanstalkBlock BEANSTALK = new BeanstalkBlock(DawnBlockSettings.copy(Blocks.SUGAR_CANE).mapColor(MapColor.GREEN).item()); public static final ScreenHandlerType BUMPABLE_BLOCK_SCREEN_HANDLER = new ScreenHandlerType<>(BumpableBlockScreenHandler::new, FeatureFlags.VANILLA_FEATURES); public static final BlockEntityType BUMPABLE_BLOCK_ENTITY_TYPE = @@ -74,6 +71,7 @@ public static void init(Registrar r) { r.add("slow_snake_block", SLOW_SNAKE_BLOCK); r.add("red_beep_block", RED_BEEP_BLOCK); r.add("blue_beep_block", BLUE_BEEP_BLOCK); + r.add("beanstalk", BEANSTALK); Registry.register(Registries.SCREEN_HANDLER, r.id("bumpable_block"), BUMPABLE_BLOCK_SCREEN_HANDLER); //TODO: create a registrar method for screen handlers in Dawn API r.add("bumpable_block", BUMPABLE_BLOCK_ENTITY_TYPE); diff --git a/src/main/java/fr/hugman/mubble/tag/MubbleBlockTags.java b/src/main/java/fr/hugman/mubble/tag/MubbleBlockTags.java new file mode 100644 index 00000000..653ffe35 --- /dev/null +++ b/src/main/java/fr/hugman/mubble/tag/MubbleBlockTags.java @@ -0,0 +1,10 @@ +package fr.hugman.mubble.tag; + +import net.minecraft.block.Block; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.tag.TagKey; +import net.minecraft.util.Identifier; + +public class MubbleBlockTags { + public static final TagKey BEANSTALK_PLANTABLE_ON = TagKey.of(RegistryKeys.BLOCK, new Identifier("mubble", "beanstalk_plantable_on")); +} diff --git a/src/main/resources/assets/mubble/blockstates/beanstalk.json b/src/main/resources/assets/mubble/blockstates/beanstalk.json new file mode 100644 index 00000000..2f0a8fba --- /dev/null +++ b/src/main/resources/assets/mubble/blockstates/beanstalk.json @@ -0,0 +1,7 @@ +{ + "variants": { + "": { + "model": "mubble:block/beanstalk" + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/mubble/models/block/beanstalk.json b/src/main/resources/assets/mubble/models/block/beanstalk.json new file mode 100644 index 00000000..895284e2 --- /dev/null +++ b/src/main/resources/assets/mubble/models/block/beanstalk.json @@ -0,0 +1,29 @@ +{ + "ambientocclusion": false, + "textures": { + "all": "mubble:block/beanstalk", + "particle": "mubble:block/beanstalk" + }, + "elements": [ + { + "from": [ 0.8, 0, 8 ], + "to": [ 15.2, 16, 8 ], + "rotation": { "origin": [ 8, 8, 8 ], "axis": "y", "angle": 45, "rescale": true }, + "shade": false, + "faces": { + "north": { "uv": [ 0, 0, 16, 16 ], "texture": "#all" }, + "south": { "uv": [ 0, 0, 16, 16 ], "texture": "#all" } + } + }, + { + "from": [ 8, 0, 0.8 ], + "to": [ 8, 16, 15.2 ], + "rotation": { "origin": [ 8, 8, 8 ], "axis": "y", "angle": 45, "rescale": true }, + "shade": false, + "faces": { + "west": { "uv": [ 0, 0, 16, 16 ], "texture": "#all" }, + "east": { "uv": [ 0, 0, 16, 16 ], "texture": "#all" } + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/mubble/tags/blocks/beanstalk_plantable_on.json b/src/main/resources/data/mubble/tags/blocks/beanstalk_plantable_on.json new file mode 100644 index 00000000..59325d05 --- /dev/null +++ b/src/main/resources/data/mubble/tags/blocks/beanstalk_plantable_on.json @@ -0,0 +1,13 @@ +{ + "replace": false, + "values": [ + "mubble:empty_block", + "mubble:beanstalk", + "#minecraft:dirt", + "#minecraft:base_stone_overworld", + "#minecraft:sand", + "#minecraft:snow", + "minecraft:gravel", + "minecraft:suspicious_gravel" + ] +} \ No newline at end of file From 34a001ec768d40aac998877e1fd1c74b96921ba9 Mon Sep 17 00:00:00 2001 From: maxbick Date: Sat, 13 Jan 2024 21:38:18 -0500 Subject: [PATCH 2/7] SOMEHOW I SUCCESSFULLY ADDED THE ENTITY CLASS????? --- gradle/wrapper/gradle-wrapper.properties | 2 +- .../java/fr/hugman/mubble/MubbleClient.java | 17 +++++ .../hugman/mubble/block/BeanstalkBlock.java | 61 +++++++++++++++++- .../hugman/mubble/entity/BeanstalkEntity.java | 11 ++++ .../mubble/entity/BeanstalkEntityModel.java | 46 +++++++++++++ .../entity/BeanstalkEntityRenderer.java | 18 ++++++ .../fr/hugman/mubble/registry/SuperMario.java | 19 +++++- .../mubble/textures/block/beanstalk.png | Bin 0 -> 345 bytes .../data/minecraft/tags/blocks/climbable.json | 6 ++ 9 files changed, 175 insertions(+), 5 deletions(-) create mode 100644 src/main/java/fr/hugman/mubble/entity/BeanstalkEntity.java create mode 100644 src/main/java/fr/hugman/mubble/entity/BeanstalkEntityModel.java create mode 100644 src/main/java/fr/hugman/mubble/entity/BeanstalkEntityRenderer.java create mode 100644 src/main/resources/assets/mubble/textures/block/beanstalk.png create mode 100644 src/main/resources/data/minecraft/tags/blocks/climbable.json diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index fae08049..a5952066 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/fr/hugman/mubble/MubbleClient.java b/src/main/java/fr/hugman/mubble/MubbleClient.java index d679720e..1110e1ea 100644 --- a/src/main/java/fr/hugman/mubble/MubbleClient.java +++ b/src/main/java/fr/hugman/mubble/MubbleClient.java @@ -2,23 +2,40 @@ import fr.hugman.mubble.client.gui.screen.BumpableBlockScreen; import fr.hugman.mubble.client.render.BumpableBlockEntityRenderer; +import fr.hugman.mubble.entity.BeanstalkEntityModel; +import fr.hugman.mubble.entity.BeanstalkEntityRenderer; import fr.hugman.mubble.registry.SuperMario; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; +import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry; +import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry; import net.minecraft.client.gui.screen.ingame.HandledScreens; import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.block.entity.BlockEntityRendererFactories; +import net.minecraft.client.render.entity.model.EntityModelLayer; +import net.minecraft.util.Identifier; @Environment(EnvType.CLIENT) public class MubbleClient implements ClientModInitializer { + public static final EntityModelLayer MODEL_CUBE_LAYER = new EntityModelLayer( + new Identifier("mubble", "beanstalk"), "main" + ); + @Override public void onInitializeClient() { BlockRenderLayerMap.INSTANCE.putBlock(SuperMario.RED_BEEP_BLOCK, RenderLayer.getCutout()); BlockRenderLayerMap.INSTANCE.putBlock(SuperMario.BLUE_BEEP_BLOCK, RenderLayer.getCutout()); + BlockRenderLayerMap.INSTANCE.putBlock(SuperMario.BEANSTALK, RenderLayer.getCutout()); HandledScreens.register(SuperMario.BUMPABLE_BLOCK_SCREEN_HANDLER, BumpableBlockScreen::new); BlockEntityRendererFactories.register(SuperMario.BUMPABLE_BLOCK_ENTITY_TYPE, BumpableBlockEntityRenderer::new); + + EntityRendererRegistry.register(SuperMario.BEANSTALK_ENTITY, BeanstalkEntityRenderer::new); + // In 1.17, use EntityRendererRegistry.register (seen below) instead of EntityRendererRegistry.INSTANCE.register (seen above) + EntityRendererRegistry.register(SuperMario.BEANSTALK_ENTITY, BeanstalkEntityRenderer::new); + + EntityModelLayerRegistry.registerModelLayer(MODEL_CUBE_LAYER, BeanstalkEntityModel::getTexturedModelData); } } diff --git a/src/main/java/fr/hugman/mubble/block/BeanstalkBlock.java b/src/main/java/fr/hugman/mubble/block/BeanstalkBlock.java index 3b51a8ae..6371f15c 100644 --- a/src/main/java/fr/hugman/mubble/block/BeanstalkBlock.java +++ b/src/main/java/fr/hugman/mubble/block/BeanstalkBlock.java @@ -1,19 +1,22 @@ package fr.hugman.mubble.block; +import fr.hugman.mubble.registry.SuperMario; import fr.hugman.mubble.tag.MubbleBlockTags; import net.minecraft.block.*; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; import net.minecraft.util.math.random.Random; import net.minecraft.util.shape.VoxelShape; import net.minecraft.util.shape.VoxelShapes; import net.minecraft.world.BlockView; import net.minecraft.world.World; +import net.minecraft.world.WorldAccess; import net.minecraft.world.WorldView; /** * Most of the functions of this code were - * essentially copied from the BambooBlock class. + * essentially copied from BambooBlock. * * @author MaxBrick * @since v4.0.0 @@ -27,6 +30,7 @@ public BeanstalkBlock(AbstractBlock.Settings settings) { public boolean isTransparent(BlockState state, BlockView world, BlockPos pos) { return true; } + public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { return VoxelShapes.fullCube(); } @@ -35,19 +39,70 @@ public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos return VoxelShapes.empty(); } + + + public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { + if (!state.canPlaceAt(world, pos)) { + world.breakBlock(pos, true); + } + } + public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { return world.getBlockState(pos.down()).isIn(MubbleBlockTags.BEANSTALK_PLANTABLE_ON); } + + protected int countBeanstalksAbove(BlockView world, BlockPos pos) { + int i; + for(i = 0; i < 16 && world.getBlockState(pos.up(i + 1)).isOf(SuperMario.BEANSTALK); ++i) { + } + + return i; + } + protected int countBeanstalksBelow(BlockView world, BlockPos pos) { + int i; + for(i = 0; i < 16 && world.getBlockState(pos.down(i + 1)).isOf(SuperMario.BEANSTALK); ++i) { + } + + return i; + } + + public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) { + if (!state.canPlaceAt(world, pos)) { + world.scheduleBlockTick(pos, this, 1); + } + return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos); + } + + //This function as well as the count functions are ripped from BambooBlock.java public boolean isFertilizable(WorldView world, BlockPos pos, BlockState state, boolean isClient) { - return world.getBlockState(pos.up(pos.getY() - world.getHeight())) == state; + int i = this.countBeanstalksAbove(world, pos); + int j = this.countBeanstalksBelow(world, pos); + return i + j + 1 < 16; } public boolean canGrow(World world, Random random, BlockPos pos, BlockState state) { return true; } + //Here I took the logic I needed from BambooBlock.java public void grow(ServerWorld world, Random random, BlockPos pos, BlockState state) { - world.setBlockState(pos.up(1), state); + int i = this.countBeanstalksAbove(world, pos); + int j = this.countBeanstalksBelow(world, pos); + int k = i + j + 1; + int l = 1 + random.nextInt(2); + + + for(int m = 0; m < l; ++m) { + BlockPos blockPos = pos.up(i); + if (k >= 16 || !world.isAir(blockPos.up())) { + return; + } + + world.setBlockState(blockPos.up(1), state); + ++i; + ++k; + } + } } diff --git a/src/main/java/fr/hugman/mubble/entity/BeanstalkEntity.java b/src/main/java/fr/hugman/mubble/entity/BeanstalkEntity.java new file mode 100644 index 00000000..058a2100 --- /dev/null +++ b/src/main/java/fr/hugman/mubble/entity/BeanstalkEntity.java @@ -0,0 +1,11 @@ +package fr.hugman.mubble.entity; + +import net.minecraft.entity.EntityType; +import net.minecraft.entity.mob.MobEntity; +import net.minecraft.world.World; + +public class BeanstalkEntity extends MobEntity { + public BeanstalkEntity(EntityType entityType, World world) { + super(entityType, world); + } +} \ No newline at end of file diff --git a/src/main/java/fr/hugman/mubble/entity/BeanstalkEntityModel.java b/src/main/java/fr/hugman/mubble/entity/BeanstalkEntityModel.java new file mode 100644 index 00000000..809a587d --- /dev/null +++ b/src/main/java/fr/hugman/mubble/entity/BeanstalkEntityModel.java @@ -0,0 +1,46 @@ +package fr.hugman.mubble.entity; + +import com.google.common.collect.ImmutableList; +import net.minecraft.client.model.*; +import net.minecraft.client.render.VertexConsumer; +import net.minecraft.client.render.entity.model.EntityModel; +import net.minecraft.client.render.entity.model.EntityModelPartNames; +import net.minecraft.client.util.math.MatrixStack; + +/** + * @author MaxBrick + * @since v4.0.0 + */ + +//I have no idea what I'm doing! +public class BeanstalkEntityModel extends EntityModel{ + private final ModelPart base; + + public BeanstalkEntityModel(ModelPart modelPart) { + this.base = modelPart.getChild(EntityModelPartNames.CUBE); + } + + public static TexturedModelData getTexturedModelData() { + ModelData modelData = new ModelData(); + ModelPartData modelPartData = modelData.getRoot(); + modelPartData.addChild( + EntityModelPartNames.CUBE, ModelPartBuilder.create().uv( + 0, 0 + ).cuboid( + -8F, -8F, -8F, 16F, 16F, 16F + ), ModelTransform.pivot(0F, 0F, 0F) + ); + return TexturedModelData.of(modelData, 16, 16); + } + + @Override + public void setAngles(BeanstalkEntity entity, float limbAngle, float limbDistance, float animationProgress, float headYaw, float headPitch) { + } + + @Override + public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) { + ImmutableList.of(this.base).forEach((modelRenderer) -> { + modelRenderer.render(matrices, vertices, light, overlay, red, green, blue, alpha); + }); + } +} diff --git a/src/main/java/fr/hugman/mubble/entity/BeanstalkEntityRenderer.java b/src/main/java/fr/hugman/mubble/entity/BeanstalkEntityRenderer.java new file mode 100644 index 00000000..22305d0c --- /dev/null +++ b/src/main/java/fr/hugman/mubble/entity/BeanstalkEntityRenderer.java @@ -0,0 +1,18 @@ +package fr.hugman.mubble.entity; + +import fr.hugman.mubble.MubbleClient; +import net.minecraft.client.render.entity.EntityRendererFactory; +import net.minecraft.client.render.entity.MobEntityRenderer; +import net.minecraft.util.Identifier; + +public class BeanstalkEntityRenderer extends MobEntityRenderer { + + public BeanstalkEntityRenderer(EntityRendererFactory.Context context) { + super(context, new BeanstalkEntityModel(context.getPart(MubbleClient.MODEL_CUBE_LAYER)), 0.5f); + } + + @Override + public Identifier getTexture(BeanstalkEntity entity) { + return new Identifier("mubble", "textures/block/beanstalk.png"); + } +} diff --git a/src/main/java/fr/hugman/mubble/registry/SuperMario.java b/src/main/java/fr/hugman/mubble/registry/SuperMario.java index 43d2df40..ded95a36 100644 --- a/src/main/java/fr/hugman/mubble/registry/SuperMario.java +++ b/src/main/java/fr/hugman/mubble/registry/SuperMario.java @@ -7,13 +7,19 @@ import fr.hugman.mubble.Mubble; import fr.hugman.mubble.block.*; import fr.hugman.mubble.block.entity.BumpableBlockEntity; +import fr.hugman.mubble.entity.BeanstalkEntity; import fr.hugman.mubble.item.CapeFeatherItem; import fr.hugman.mubble.screen.BumpableBlockScreenHandler; import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup; import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder; +import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry; +import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder; import net.minecraft.block.Blocks; import net.minecraft.block.MapColor; import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.entity.EntityDimensions; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.SpawnGroup; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; @@ -26,6 +32,7 @@ import net.minecraft.resource.featuretoggle.FeatureFlags; import net.minecraft.screen.ScreenHandlerType; import net.minecraft.text.Text; +import net.minecraft.util.Identifier; import net.minecraft.util.Rarity; public class SuperMario { @@ -44,7 +51,7 @@ public class SuperMario { public static final SnakeBlock SLOW_SNAKE_BLOCK = new SnakeBlock(DawnBlockSettings.copy(Blocks.IRON_BLOCK).mapColor(MapColor.RED).item()); public static final BeepBlock RED_BEEP_BLOCK = new BeepBlock(MapColor.RED, false); public static final BeepBlock BLUE_BEEP_BLOCK = new BeepBlock(MapColor.BLUE, true); - public static final BeanstalkBlock BEANSTALK = new BeanstalkBlock(DawnBlockSettings.copy(Blocks.SUGAR_CANE).mapColor(MapColor.GREEN).item()); + public static final BeanstalkBlock BEANSTALK = new BeanstalkBlock(DawnBlockSettings.copy(Blocks.SUGAR_CANE).mapColor(MapColor.GREEN).item().nonOpaque()); public static final ScreenHandlerType BUMPABLE_BLOCK_SCREEN_HANDLER = new ScreenHandlerType<>(BumpableBlockScreenHandler::new, FeatureFlags.VANILLA_FEATURES); public static final BlockEntityType BUMPABLE_BLOCK_ENTITY_TYPE = @@ -53,6 +60,14 @@ public class SuperMario { public static final CapeFeatherItem CAPE_FEATHER = new CapeFeatherItem(new Item.Settings(), false); public static final CapeFeatherItem SUPER_CAPE_FEATHER = new CapeFeatherItem(new Item.Settings().rarity(Rarity.EPIC), true); + // ENTITY + public static final EntityType BEANSTALK_ENTITY = Registry.register( + Registries.ENTITY_TYPE, + new Identifier("mubble", "beanstalk"), + FabricEntityTypeBuilder.create( + SpawnGroup.MISC, BeanstalkEntity::new).dimensions(EntityDimensions.fixed(1.0f, 1.0f) + ).build() + ); // ITEM GROUP public static final RegistryKey ITEM_GROUP = RegistryKey.of(RegistryKeys.ITEM_GROUP, Mubble.id("super_mario")); @@ -79,6 +94,8 @@ public static void init(Registrar r) { r.add("cape_feather", CAPE_FEATHER); r.add("super_cape_feather", SUPER_CAPE_FEATHER); + FabricDefaultAttributeRegistry.register(BEANSTALK_ENTITY, BeanstalkEntity.createMobAttributes()); + appendItemGroups(); } diff --git a/src/main/resources/assets/mubble/textures/block/beanstalk.png b/src/main/resources/assets/mubble/textures/block/beanstalk.png new file mode 100644 index 0000000000000000000000000000000000000000..77d81bb32f03ffff8b33ced9977357eb9ee816c4 GIT binary patch literal 345 zcmV-f0jBi3G8AJ`n-Zt0Q^6a78Bs#h8fwYYS8z?W;lq7zz;R1DYSipbg9hN48mb zej}+XB)Mq|svGfUf>>A~sY+XbVDZ#btV}(s8>J7ZeG&)XBw8pR=s!u(j_@EKU_>0F r5AXmRtJO^=3he{vf{rHL%f}|(DXZB{)+hq>00000NkvXXu0mjf+$xiG literal 0 HcmV?d00001 diff --git a/src/main/resources/data/minecraft/tags/blocks/climbable.json b/src/main/resources/data/minecraft/tags/blocks/climbable.json new file mode 100644 index 00000000..af55cba4 --- /dev/null +++ b/src/main/resources/data/minecraft/tags/blocks/climbable.json @@ -0,0 +1,6 @@ +{ + "replace": false, + "values": [ + "mubble:beanstalk" + ] +} \ No newline at end of file From 2f1119db93d03997a91d9216a56623cb0fc7d774 Mon Sep 17 00:00:00 2001 From: maxbick Date: Sun, 14 Jan 2024 22:51:46 -0500 Subject: [PATCH 3/7] Added growth functionality (and some other changes) --- .../java/fr/hugman/mubble/MubbleClient.java | 2 +- .../hugman/mubble/block/BeanstalkBlock.java | 4 +- .../fr/hugman/mubble/block/BumpableBlock.java | 10 +++ .../hugman/mubble/entity/BeanstalkEntity.java | 72 ++++++++++++++++++- .../mubble/entity/BeanstalkEntityModel.java | 2 +- .../entity/BeanstalkEntityRenderer.java | 7 +- .../fr/hugman/mubble/registry/SuperMario.java | 5 +- 7 files changed, 89 insertions(+), 13 deletions(-) diff --git a/src/main/java/fr/hugman/mubble/MubbleClient.java b/src/main/java/fr/hugman/mubble/MubbleClient.java index 1110e1ea..79adbab9 100644 --- a/src/main/java/fr/hugman/mubble/MubbleClient.java +++ b/src/main/java/fr/hugman/mubble/MubbleClient.java @@ -33,7 +33,7 @@ public void onInitializeClient() { BlockEntityRendererFactories.register(SuperMario.BUMPABLE_BLOCK_ENTITY_TYPE, BumpableBlockEntityRenderer::new); EntityRendererRegistry.register(SuperMario.BEANSTALK_ENTITY, BeanstalkEntityRenderer::new); - // In 1.17, use EntityRendererRegistry.register (seen below) instead of EntityRendererRegistry.INSTANCE.register (seen above) + EntityRendererRegistry.register(SuperMario.BEANSTALK_ENTITY, BeanstalkEntityRenderer::new); EntityModelLayerRegistry.registerModelLayer(MODEL_CUBE_LAYER, BeanstalkEntityModel::getTexturedModelData); diff --git a/src/main/java/fr/hugman/mubble/block/BeanstalkBlock.java b/src/main/java/fr/hugman/mubble/block/BeanstalkBlock.java index 6371f15c..d154bdc8 100644 --- a/src/main/java/fr/hugman/mubble/block/BeanstalkBlock.java +++ b/src/main/java/fr/hugman/mubble/block/BeanstalkBlock.java @@ -74,7 +74,7 @@ public BlockState getStateForNeighborUpdate(BlockState state, Direction directio return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos); } - //This function as well as the count functions are ripped from BambooBlock.java + //This function as well as the count functions are ripped from BambooBlock.class public boolean isFertilizable(WorldView world, BlockPos pos, BlockState state, boolean isClient) { int i = this.countBeanstalksAbove(world, pos); int j = this.countBeanstalksBelow(world, pos); @@ -85,7 +85,7 @@ public boolean canGrow(World world, Random random, BlockPos pos, BlockState stat return true; } - //Here I took the logic I needed from BambooBlock.java + //Here I took the logic I needed from BambooBlock.class public void grow(ServerWorld world, Random random, BlockPos pos, BlockState state) { int i = this.countBeanstalksAbove(world, pos); int j = this.countBeanstalksBelow(world, pos); diff --git a/src/main/java/fr/hugman/mubble/block/BumpableBlock.java b/src/main/java/fr/hugman/mubble/block/BumpableBlock.java index 54dcd750..34a8468f 100644 --- a/src/main/java/fr/hugman/mubble/block/BumpableBlock.java +++ b/src/main/java/fr/hugman/mubble/block/BumpableBlock.java @@ -1,6 +1,7 @@ package fr.hugman.mubble.block; import fr.hugman.mubble.block.entity.BumpableBlockEntity; +import fr.hugman.mubble.entity.BeanstalkEntity; import fr.hugman.mubble.registry.MubbleSounds; import fr.hugman.mubble.registry.SuperMario; import net.fabricmc.api.EnvType; @@ -16,6 +17,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.SpawnReason; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.inventory.Inventory; import net.minecraft.item.ItemStack; @@ -33,11 +35,13 @@ import net.minecraft.world.event.GameEvent; import org.jetbrains.annotations.Nullable; +import java.util.Objects; import java.util.Optional; /** * @author haykam * @author Hugman + * @author MaxBrick * @since v4.0.0 */ public class BumpableBlock extends BlockWithEntity implements HittableBlock { @@ -230,6 +234,12 @@ public void loot(World world, BlockPos pos, BlockState state, BumpableBlockEntit } var actualState = world.getBlockState(pos); var center = pos.toCenterPos(); + + if(blockEntity.getStack(0) == SuperMario.BEANSTALK.asItem().getDefaultStack() && !world.isClient()) { + SuperMario.BEANSTALK_ENTITY.spawn(world.getServer().getWorld(world.getRegistryKey()), pos, SpawnReason.TRIGGERED).growth = blockEntity.count(SuperMario.BEANSTALK.asItem()); + return; + } + if(actualState.isAir()) { ItemScatterer.spawn(world, pos, blockEntity); } diff --git a/src/main/java/fr/hugman/mubble/entity/BeanstalkEntity.java b/src/main/java/fr/hugman/mubble/entity/BeanstalkEntity.java index 058a2100..4e86d4f5 100644 --- a/src/main/java/fr/hugman/mubble/entity/BeanstalkEntity.java +++ b/src/main/java/fr/hugman/mubble/entity/BeanstalkEntity.java @@ -1,11 +1,77 @@ package fr.hugman.mubble.entity; +import fr.hugman.mubble.registry.SuperMario; +import net.minecraft.block.Blocks; +import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; -import net.minecraft.entity.mob.MobEntity; +import net.minecraft.entity.MovementType; +import net.minecraft.fluid.Fluids; +import net.minecraft.nbt.NbtCompound; import net.minecraft.world.World; -public class BeanstalkEntity extends MobEntity { - public BeanstalkEntity(EntityType entityType, World world) { +/** + * This class is made by copying and modifying + * methods from FallingBlockEntity + * Real creative, I know :) + * + * @author MaxBrick + * @since v4.0.0 + */ + +public class BeanstalkEntity extends Entity { + + //This will determine how high the entity will grow. It should be set upon spawning + public int growth = 0; + + public int spawnHeight = (int) this.getY(); + + private int travelDistance = 0; + + public BeanstalkEntity(EntityType entityType, World world) { super(entityType, world); } + + @Override + protected void initDataTracker() { + + } + + protected Entity.MoveEffect getMoveEffect() { + return MoveEffect.NONE; + } + + public void tick() { + //I don't know why, but I have to use the move function to actually make it move + this.setVelocity(0.0, 0.3, 0.0); + this.move(MovementType.SELF, this.getVelocity()); + + if(!this.getWorld().getBlockState(this.getBlockPos().up()).isAir() || growth < 1) { + this.discard(); + } + + if(this.getY() > spawnHeight + travelDistance + 1 && this.getWorld().getBlockState(this.getBlockPos()).isAir()) { + travelDistance++; + + this.getWorld().setBlockState(this.getBlockPos(), SuperMario.BEANSTALK.getDefaultState()); + + growth--; + + } + } + + @Override + protected void writeCustomDataToNbt(NbtCompound nbt) { + nbt.putInt("Growth", this.growth); + nbt.putInt("SpawnHeight", this.spawnHeight); + } + + @Override + protected void readCustomDataFromNbt(NbtCompound nbt) { + this.growth = nbt.getInt("Growth"); + this.spawnHeight = nbt.getInt("SpawnHeight"); + } + + public boolean isAttackable() { + return false; + } } \ No newline at end of file diff --git a/src/main/java/fr/hugman/mubble/entity/BeanstalkEntityModel.java b/src/main/java/fr/hugman/mubble/entity/BeanstalkEntityModel.java index 809a587d..66338e39 100644 --- a/src/main/java/fr/hugman/mubble/entity/BeanstalkEntityModel.java +++ b/src/main/java/fr/hugman/mubble/entity/BeanstalkEntityModel.java @@ -27,7 +27,7 @@ public static TexturedModelData getTexturedModelData() { EntityModelPartNames.CUBE, ModelPartBuilder.create().uv( 0, 0 ).cuboid( - -8F, -8F, -8F, 16F, 16F, 16F + -8F, 8F, -8F, 16F, 16F, 16F ), ModelTransform.pivot(0F, 0F, 0F) ); return TexturedModelData.of(modelData, 16, 16); diff --git a/src/main/java/fr/hugman/mubble/entity/BeanstalkEntityRenderer.java b/src/main/java/fr/hugman/mubble/entity/BeanstalkEntityRenderer.java index 22305d0c..600d5dbf 100644 --- a/src/main/java/fr/hugman/mubble/entity/BeanstalkEntityRenderer.java +++ b/src/main/java/fr/hugman/mubble/entity/BeanstalkEntityRenderer.java @@ -1,14 +1,13 @@ package fr.hugman.mubble.entity; -import fr.hugman.mubble.MubbleClient; +import net.minecraft.client.render.entity.EntityRenderer; import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.MobEntityRenderer; import net.minecraft.util.Identifier; -public class BeanstalkEntityRenderer extends MobEntityRenderer { +public class BeanstalkEntityRenderer extends EntityRenderer { public BeanstalkEntityRenderer(EntityRendererFactory.Context context) { - super(context, new BeanstalkEntityModel(context.getPart(MubbleClient.MODEL_CUBE_LAYER)), 0.5f); + super(context); } @Override diff --git a/src/main/java/fr/hugman/mubble/registry/SuperMario.java b/src/main/java/fr/hugman/mubble/registry/SuperMario.java index ded95a36..4b23080f 100644 --- a/src/main/java/fr/hugman/mubble/registry/SuperMario.java +++ b/src/main/java/fr/hugman/mubble/registry/SuperMario.java @@ -61,6 +61,8 @@ public class SuperMario { public static final CapeFeatherItem CAPE_FEATHER = new CapeFeatherItem(new Item.Settings(), false); public static final CapeFeatherItem SUPER_CAPE_FEATHER = new CapeFeatherItem(new Item.Settings().rarity(Rarity.EPIC), true); // ENTITY + + //This probably should be changed to be more consistent with the rest of the registries public static final EntityType BEANSTALK_ENTITY = Registry.register( Registries.ENTITY_TYPE, new Identifier("mubble", "beanstalk"), @@ -94,8 +96,6 @@ public static void init(Registrar r) { r.add("cape_feather", CAPE_FEATHER); r.add("super_cape_feather", SUPER_CAPE_FEATHER); - FabricDefaultAttributeRegistry.register(BEANSTALK_ENTITY, BeanstalkEntity.createMobAttributes()); - appendItemGroups(); } @@ -116,6 +116,7 @@ public static void appendItemGroups() { entries.add(SuperMario.SLOW_SNAKE_BLOCK); entries.add(SuperMario.RED_BEEP_BLOCK); entries.add(SuperMario.BLUE_BEEP_BLOCK); + entries.add(SuperMario.BEANSTALK); entries.add(SuperMario.CAPE_FEATHER); entries.add(SuperMario.SUPER_CAPE_FEATHER); }) From 501c09318f4571c4d7f6f79152e1195238af64f4 Mon Sep 17 00:00:00 2001 From: maxbick Date: Sun, 14 Jan 2024 23:38:59 -0500 Subject: [PATCH 4/7] Attempted to implement growth functionality to BumpableBlock.java --- .../fr/hugman/mubble/block/BumpableBlock.java | 15 +++++++++++---- .../fr/hugman/mubble/entity/BeanstalkEntity.java | 7 +++---- .../mubble/entity/BeanstalkEntityModel.java | 1 + 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/java/fr/hugman/mubble/block/BumpableBlock.java b/src/main/java/fr/hugman/mubble/block/BumpableBlock.java index 34a8468f..3b9a4976 100644 --- a/src/main/java/fr/hugman/mubble/block/BumpableBlock.java +++ b/src/main/java/fr/hugman/mubble/block/BumpableBlock.java @@ -235,20 +235,27 @@ public void loot(World world, BlockPos pos, BlockState state, BumpableBlockEntit var actualState = world.getBlockState(pos); var center = pos.toCenterPos(); - if(blockEntity.getStack(0) == SuperMario.BEANSTALK.asItem().getDefaultStack() && !world.isClient()) { - SuperMario.BEANSTALK_ENTITY.spawn(world.getServer().getWorld(world.getRegistryKey()), pos, SpawnReason.TRIGGERED).growth = blockEntity.count(SuperMario.BEANSTALK.asItem()); - return; - } + if(actualState.isAir()) { ItemScatterer.spawn(world, pos, blockEntity); } else { + //TODO: make this actually work + //This should check if the container has a beanstalk. + //Then it should spawn the beanstalk entity, + //set its growth value to the quantity of beanstalks in the container, + if(blockEntity.getStack(0).isOf(SuperMario.BEANSTALK.asItem())) { + Objects.requireNonNull(SuperMario.BEANSTALK_ENTITY.spawn(world.getServer().getWorld(world.getRegistryKey()), pos, SpawnReason.TRIGGERED)).growth = blockEntity.count(SuperMario.BEANSTALK.asItem()); + return; + } var direction = blockEntity.getBumpDirection(); var x = center.getX() + direction.getOffsetX() * 0.75D; var y = center.getY() + direction.getOffsetY() * 0.75D; var z = center.getZ() + direction.getOffsetZ() * 0.75D; for(int i = 0; i < blockEntity.size(); ++i) { + Objects.requireNonNull(SuperMario.BEANSTALK_ENTITY.spawn(world.getServer().getWorld(world.getRegistryKey()), pos, SpawnReason.TRIGGERED)).growth = blockEntity.count(SuperMario.BEANSTALK.asItem()); + ItemScatterer.spawn(world, x, y, z, blockEntity.getStack(i)); } } diff --git a/src/main/java/fr/hugman/mubble/entity/BeanstalkEntity.java b/src/main/java/fr/hugman/mubble/entity/BeanstalkEntity.java index 4e86d4f5..f043bf49 100644 --- a/src/main/java/fr/hugman/mubble/entity/BeanstalkEntity.java +++ b/src/main/java/fr/hugman/mubble/entity/BeanstalkEntity.java @@ -23,7 +23,8 @@ public class BeanstalkEntity extends Entity { //This will determine how high the entity will grow. It should be set upon spawning public int growth = 0; - public int spawnHeight = (int) this.getY(); + //This should always be set to its y position when spawned + private final int spawnHeight = (int) this.getY(); private int travelDistance = 0; @@ -49,26 +50,24 @@ public void tick() { this.discard(); } + //Checks if its current position is one block higher than where it previously was before placing block if(this.getY() > spawnHeight + travelDistance + 1 && this.getWorld().getBlockState(this.getBlockPos()).isAir()) { travelDistance++; this.getWorld().setBlockState(this.getBlockPos(), SuperMario.BEANSTALK.getDefaultState()); growth--; - } } @Override protected void writeCustomDataToNbt(NbtCompound nbt) { nbt.putInt("Growth", this.growth); - nbt.putInt("SpawnHeight", this.spawnHeight); } @Override protected void readCustomDataFromNbt(NbtCompound nbt) { this.growth = nbt.getInt("Growth"); - this.spawnHeight = nbt.getInt("SpawnHeight"); } public boolean isAttackable() { diff --git a/src/main/java/fr/hugman/mubble/entity/BeanstalkEntityModel.java b/src/main/java/fr/hugman/mubble/entity/BeanstalkEntityModel.java index 66338e39..7389bcb7 100644 --- a/src/main/java/fr/hugman/mubble/entity/BeanstalkEntityModel.java +++ b/src/main/java/fr/hugman/mubble/entity/BeanstalkEntityModel.java @@ -13,6 +13,7 @@ */ //I have no idea what I'm doing! +//TODO: fix the model so it's identical to BeanstalkBlock's model public class BeanstalkEntityModel extends EntityModel{ private final ModelPart base; From f20711192ea4181e945109cfb17d99a7139d62c9 Mon Sep 17 00:00:00 2001 From: maxbick Date: Wed, 17 Jan 2024 20:46:53 -0500 Subject: [PATCH 5/7] Partially fixed beanstalk spawning --- .../fr/hugman/mubble/block/BumpableBlock.java | 22 +++++++++++-------- .../tags/blocks/beanstalk_plantable_on.json | 2 ++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/java/fr/hugman/mubble/block/BumpableBlock.java b/src/main/java/fr/hugman/mubble/block/BumpableBlock.java index 3b9a4976..46695520 100644 --- a/src/main/java/fr/hugman/mubble/block/BumpableBlock.java +++ b/src/main/java/fr/hugman/mubble/block/BumpableBlock.java @@ -241,20 +241,24 @@ public void loot(World world, BlockPos pos, BlockState state, BumpableBlockEntit ItemScatterer.spawn(world, pos, blockEntity); } else { - //TODO: make this actually work - //This should check if the container has a beanstalk. - //Then it should spawn the beanstalk entity, - //set its growth value to the quantity of beanstalks in the container, - if(blockEntity.getStack(0).isOf(SuperMario.BEANSTALK.asItem())) { - Objects.requireNonNull(SuperMario.BEANSTALK_ENTITY.spawn(world.getServer().getWorld(world.getRegistryKey()), pos, SpawnReason.TRIGGERED)).growth = blockEntity.count(SuperMario.BEANSTALK.asItem()); - return; - } + var direction = blockEntity.getBumpDirection(); var x = center.getX() + direction.getOffsetX() * 0.75D; var y = center.getY() + direction.getOffsetY() * 0.75D; var z = center.getZ() + direction.getOffsetZ() * 0.75D; for(int i = 0; i < blockEntity.size(); ++i) { - Objects.requireNonNull(SuperMario.BEANSTALK_ENTITY.spawn(world.getServer().getWorld(world.getRegistryKey()), pos, SpawnReason.TRIGGERED)).growth = blockEntity.count(SuperMario.BEANSTALK.asItem()); + //TODO: make this work for ? blocks + //This should check if the container has a beanstalk. + //Then it should spawn the beanstalk entity, + //set its growth value to the quantity of beanstalks in the container, + //and empty its contents. + if(blockEntity.getStack(i).isOf(SuperMario.BEANSTALK.asItem())) { + Objects.requireNonNull(SuperMario.BEANSTALK_ENTITY.spawn(world.getServer().getWorld(world.getRegistryKey()), pos, SpawnReason.TRIGGERED)).growth = blockEntity.count(SuperMario.BEANSTALK.asItem()); + //TODO: make custom sound for beanstalk + world.playSound(null, center.getX(), center.getY(), center.getZ(), MubbleSounds.BUMPABLE_BLOCK_LOOT, SoundCategory.BLOCKS, 1.0F, 1.0F); + blockEntity.clear(); + return; + } ItemScatterer.spawn(world, x, y, z, blockEntity.getStack(i)); } diff --git a/src/main/resources/data/mubble/tags/blocks/beanstalk_plantable_on.json b/src/main/resources/data/mubble/tags/blocks/beanstalk_plantable_on.json index 59325d05..0cf325e8 100644 --- a/src/main/resources/data/mubble/tags/blocks/beanstalk_plantable_on.json +++ b/src/main/resources/data/mubble/tags/blocks/beanstalk_plantable_on.json @@ -3,6 +3,8 @@ "values": [ "mubble:empty_block", "mubble:beanstalk", + "mubble:exclamation_block", + "mubble:note_block", "#minecraft:dirt", "#minecraft:base_stone_overworld", "#minecraft:sand", From 62a5e192ae2e5d32e81c7466a05a04fe4874defb Mon Sep 17 00:00:00 2001 From: maxbick Date: Sat, 20 Jan 2024 12:32:59 -0500 Subject: [PATCH 6/7] Fixed beanstalk spawning --- .../hugman/mubble/block/BeanstalkBlock.java | 10 ++----- .../fr/hugman/mubble/block/BumpableBlock.java | 26 ++++++++++++------- .../hugman/mubble/entity/BeanstalkEntity.java | 2 +- .../mubble/entity/BeanstalkEntityModel.java | 9 ++++++- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/main/java/fr/hugman/mubble/block/BeanstalkBlock.java b/src/main/java/fr/hugman/mubble/block/BeanstalkBlock.java index d154bdc8..87a7b555 100644 --- a/src/main/java/fr/hugman/mubble/block/BeanstalkBlock.java +++ b/src/main/java/fr/hugman/mubble/block/BeanstalkBlock.java @@ -9,10 +9,7 @@ import net.minecraft.util.math.random.Random; import net.minecraft.util.shape.VoxelShape; import net.minecraft.util.shape.VoxelShapes; -import net.minecraft.world.BlockView; -import net.minecraft.world.World; -import net.minecraft.world.WorldAccess; -import net.minecraft.world.WorldView; +import net.minecraft.world.*; /** * Most of the functions of this code were @@ -39,8 +36,6 @@ public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos return VoxelShapes.empty(); } - - public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { if (!state.canPlaceAt(world, pos)) { world.breakBlock(pos, true); @@ -103,6 +98,5 @@ public void grow(ServerWorld world, Random random, BlockPos pos, BlockState stat ++i; ++k; } - } -} +} \ No newline at end of file diff --git a/src/main/java/fr/hugman/mubble/block/BumpableBlock.java b/src/main/java/fr/hugman/mubble/block/BumpableBlock.java index 46695520..457044f1 100644 --- a/src/main/java/fr/hugman/mubble/block/BumpableBlock.java +++ b/src/main/java/fr/hugman/mubble/block/BumpableBlock.java @@ -203,13 +203,15 @@ public void onBumpEnd(World world, BlockPos pos, BlockState state, BumpableBlock return; } var newState = blockEntity.getBumpedState(); - if(newState != null) { - world.setBlockState(pos, newState); + + this.loot(world, pos, state, blockEntity); + + if(newState != null) { + world.setBlockState(pos, newState); } else { - world.setBlockState(pos, state.with(BUMPING, false)); + world.setBlockState(pos, state.with(BUMPING, false)); } - this.loot(world, pos, state, blockEntity); } } @@ -247,12 +249,16 @@ public void loot(World world, BlockPos pos, BlockState state, BumpableBlockEntit var y = center.getY() + direction.getOffsetY() * 0.75D; var z = center.getZ() + direction.getOffsetZ() * 0.75D; for(int i = 0; i < blockEntity.size(); ++i) { - //TODO: make this work for ? blocks - //This should check if the container has a beanstalk. - //Then it should spawn the beanstalk entity, - //set its growth value to the quantity of beanstalks in the container, - //and empty its contents. - if(blockEntity.getStack(i).isOf(SuperMario.BEANSTALK.asItem())) { + /* + This should check if the container holds beanstalks. + If it does, and blockEntity.getBumpedState() is not air, + it will spawn a beanstalk, setting its growth value + to the amount of beanstalks in the container, + and finally empties the blockEntity. + */ + if( + blockEntity.getStack(i).isOf(SuperMario.BEANSTALK.asItem()) && (blockEntity.getBumpedState() == null || !blockEntity.getBumpedState().isAir()) + ) { Objects.requireNonNull(SuperMario.BEANSTALK_ENTITY.spawn(world.getServer().getWorld(world.getRegistryKey()), pos, SpawnReason.TRIGGERED)).growth = blockEntity.count(SuperMario.BEANSTALK.asItem()); //TODO: make custom sound for beanstalk world.playSound(null, center.getX(), center.getY(), center.getZ(), MubbleSounds.BUMPABLE_BLOCK_LOOT, SoundCategory.BLOCKS, 1.0F, 1.0F); diff --git a/src/main/java/fr/hugman/mubble/entity/BeanstalkEntity.java b/src/main/java/fr/hugman/mubble/entity/BeanstalkEntity.java index f043bf49..cec2cdc0 100644 --- a/src/main/java/fr/hugman/mubble/entity/BeanstalkEntity.java +++ b/src/main/java/fr/hugman/mubble/entity/BeanstalkEntity.java @@ -43,7 +43,7 @@ protected Entity.MoveEffect getMoveEffect() { public void tick() { //I don't know why, but I have to use the move function to actually make it move - this.setVelocity(0.0, 0.3, 0.0); + this.setVelocity(0.0D, 0.3D, 0.0D); this.move(MovementType.SELF, this.getVelocity()); if(!this.getWorld().getBlockState(this.getBlockPos().up()).isAir() || growth < 1) { diff --git a/src/main/java/fr/hugman/mubble/entity/BeanstalkEntityModel.java b/src/main/java/fr/hugman/mubble/entity/BeanstalkEntityModel.java index 7389bcb7..6eb0da0a 100644 --- a/src/main/java/fr/hugman/mubble/entity/BeanstalkEntityModel.java +++ b/src/main/java/fr/hugman/mubble/entity/BeanstalkEntityModel.java @@ -29,7 +29,14 @@ public static TexturedModelData getTexturedModelData() { 0, 0 ).cuboid( -8F, 8F, -8F, 16F, 16F, 16F - ), ModelTransform.pivot(0F, 0F, 0F) + ), ModelTransform.pivot(8F, 0F, 8F) + ); + modelPartData.addChild( + EntityModelPartNames.CUBE, ModelPartBuilder.create().uv( + 0, 0 + ).cuboid( + -8F, 8F, -8F, 16F, 16F, 16F + ), ModelTransform.pivot(-8F, 0F, -8F) ); return TexturedModelData.of(modelData, 16, 16); } From 0ffde77d7e1e1a27e5074d63156f9c8464d036e8 Mon Sep 17 00:00:00 2001 From: maxbick Date: Sat, 20 Jan 2024 12:44:44 -0500 Subject: [PATCH 7/7] Added item model file and lang for beanstalks --- src/main/resources/assets/mubble/lang/en_us.json | 1 + src/main/resources/assets/mubble/models/item/beanstalk.json | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 src/main/resources/assets/mubble/models/item/beanstalk.json diff --git a/src/main/resources/assets/mubble/lang/en_us.json b/src/main/resources/assets/mubble/lang/en_us.json index 55bb9ca4..8d8d0342 100644 --- a/src/main/resources/assets/mubble/lang/en_us.json +++ b/src/main/resources/assets/mubble/lang/en_us.json @@ -16,6 +16,7 @@ "block.mubble.slow_snake_block": "Slow Snake Block", "block.mubble.red_beep_block": "Red Beep Block", "block.mubble.blue_beep_block": "Blue Beep Block", + "block.mubble.beanstalk": "Beanstalk", "item.mubble.cape_feather": "Cape Feather", "item.mubble.super_cape_feather": "Super Cape Feather", diff --git a/src/main/resources/assets/mubble/models/item/beanstalk.json b/src/main/resources/assets/mubble/models/item/beanstalk.json new file mode 100644 index 00000000..74ee3de8 --- /dev/null +++ b/src/main/resources/assets/mubble/models/item/beanstalk.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "mubble:block/beanstalk" + } +} \ No newline at end of file