Skip to content

Commit

Permalink
Updated to 1.0.1
Browse files Browse the repository at this point in the history
Fixed glaring bug and made easier to make carvable blocks
  • Loading branch information
LudoCrypt committed Oct 5, 2020
1 parent 02de609 commit 5a2a14a
Show file tree
Hide file tree
Showing 22 changed files with 277 additions and 772 deletions.
Binary file modified .gradle/6.5/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/6.5/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/6.5/fileContent/fileContent.lock
Binary file not shown.
Binary file modified .gradle/6.5/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/6.5/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/6.5/javaCompile/classAnalysis.bin
Binary file not shown.
Binary file modified .gradle/6.5/javaCompile/javaCompile.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
Binary file modified .gradle/checksums/checksums.lock
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ yarn_mappings=1.16.3+build.12
loader_version=0.9.3+build.207
fabric_version=0.21.0+build.407-1.16

mod_version = 1.0.0
mod_version = 1.0.1
maven_group = net.ludocrypt
archives_base_name = carve-my-pumpkin
42 changes: 21 additions & 21 deletions src/main/java/net/ludocrypt/carvepump/CarveMyPumpkin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.ludocrypt.carvepump.blocks.CarvableMelonBlock;
import net.ludocrypt.carvepump.blocks.CarvablePumpkinBlock;
import net.ludocrypt.carvepump.blocks.UncarvableMelonBlock;
import net.ludocrypt.carvepump.blocks.UncarvablePumpkinBlock;
import net.ludocrypt.carvepump.blocks.CarvableBlock;
import net.ludocrypt.carvepump.blocks.entity.CarvedBlockEntity;
import net.ludocrypt.carvepump.items.CarverItem;
import net.minecraft.block.AbstractBlock;
Expand All @@ -32,31 +29,32 @@ public class CarveMyPumpkin implements ModInitializer {

public static BlockEntityType<CarvedBlockEntity> CARVED_BLOCK_ENTITY;

public static final Block CARVED_PUMPKIN = new CarvablePumpkinBlock(AbstractBlock.Settings
.of(Material.GOURD, MaterialColor.ORANGE).strength(1.0F).sounds(BlockSoundGroup.WOOD));
public static final Block JACK_O_LANTERN = new UncarvablePumpkinBlock(AbstractBlock.Settings
public static final Block CARVED_PUMPKIN = new CarvableBlock(
AbstractBlock.Settings.of(Material.GOURD, MaterialColor.ORANGE).strength(1.0F).sounds(BlockSoundGroup.WOOD),
Blocks.PUMPKIN, new Identifier("carvepump", "textures/entity/pumpkin_halo_colors.png"), true);
public static final Block JACK_O_LANTERN = new CarvableBlock(AbstractBlock.Settings
.of(Material.GOURD, MaterialColor.ORANGE).strength(1.0F).sounds(BlockSoundGroup.WOOD).luminance((state) -> {
return 15;
}));

public static final Block CARVED_MELON = new CarvableMelonBlock(AbstractBlock.Settings
.of(Material.GOURD, MaterialColor.ORANGE).strength(1.0F).sounds(BlockSoundGroup.WOOD));
public static final Block JACK_O_MELON = new UncarvableMelonBlock(AbstractBlock.Settings
}), Blocks.PUMPKIN, new Identifier("carvepump", "textures/entity/jack_o_lantern_halo_colors.png"), false);
public static final Block CARVED_MELON = new CarvableBlock(
AbstractBlock.Settings.of(Material.GOURD, MaterialColor.ORANGE).strength(1.0F).sounds(BlockSoundGroup.WOOD),
Blocks.MELON, new Identifier("carvepump", "textures/entity/melon_halo_colors.png"), true);
public static final Block JACK_O_MELON = new CarvableBlock(AbstractBlock.Settings
.of(Material.GOURD, MaterialColor.ORANGE).strength(1.0F).sounds(BlockSoundGroup.WOOD).luminance((state) -> {
return 15;
}));
}), Blocks.MELON, new Identifier("carvepump", "textures/entity/jack_o_melon_halo_colors.png"), false);

public static final ToolItem WOODEN_CARVER = new CarverItem(ToolMaterials.WOOD, 3, 1,
public static final ToolItem WOODEN_CARVER = new CarverItem(ToolMaterials.WOOD, 2, 1,
new Item.Settings().group(ItemGroup.TOOLS).maxCount(1));
public static final ToolItem STONE_CARVER = new CarverItem(ToolMaterials.STONE, 4, 1,
public static final ToolItem STONE_CARVER = new CarverItem(ToolMaterials.STONE, 2, 1,
new Item.Settings().group(ItemGroup.TOOLS).maxCount(1));
public static final ToolItem GOLD_CARVER = new CarverItem(ToolMaterials.GOLD, 3, 1,
public static final ToolItem GOLD_CARVER = new CarverItem(ToolMaterials.GOLD, 2, 1,
new Item.Settings().group(ItemGroup.TOOLS).maxCount(1));
public static final ToolItem IRON_CARVER = new CarverItem(ToolMaterials.IRON, 5, 1,
public static final ToolItem IRON_CARVER = new CarverItem(ToolMaterials.IRON, 2, 1,
new Item.Settings().group(ItemGroup.TOOLS).maxCount(1));
public static final ToolItem DIAMOND_CARVER = new CarverItem(ToolMaterials.DIAMOND, 6, 1,
public static final ToolItem DIAMOND_CARVER = new CarverItem(ToolMaterials.DIAMOND, 2, 1,
new Item.Settings().group(ItemGroup.TOOLS).maxCount(1));
public static final ToolItem NETHERITE_CARVER = new CarverItem(ToolMaterials.NETHERITE, 7, 1,
public static final ToolItem NETHERITE_CARVER = new CarverItem(ToolMaterials.NETHERITE, 2, 1,
new Item.Settings().group(ItemGroup.TOOLS).maxCount(1));

// List of carvable blocks
Expand Down Expand Up @@ -86,12 +84,14 @@ public void onInitialize() {
Registry.register(Registry.ITEM, id("carved_pumpkin"),
new BlockItem(CARVED_PUMPKIN, new FabricItemSettings().equipmentSlot(stack -> EquipmentSlot.HEAD)));

Registry.register(Registry.ITEM, id("jack_o_lantern"), new BlockItem(JACK_O_LANTERN, new FabricItemSettings()));
Registry.register(Registry.ITEM, id("jack_o_lantern"),
new BlockItem(JACK_O_LANTERN, new FabricItemSettings().recipeRemainder(Blocks.PUMPKIN.asItem())));

Registry.register(Registry.ITEM, id("carved_melon"),
new BlockItem(CARVED_MELON, new FabricItemSettings().equipmentSlot(stack -> EquipmentSlot.HEAD)));

Registry.register(Registry.ITEM, id("jack_o_melon"), new BlockItem(JACK_O_MELON, new FabricItemSettings()));
Registry.register(Registry.ITEM, id("jack_o_melon"),
new BlockItem(JACK_O_MELON, new FabricItemSettings().recipeRemainder(Blocks.MELON.asItem())));

}

Expand Down
191 changes: 188 additions & 3 deletions src/main/java/net/ludocrypt/carvepump/blocks/CarvableBlock.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,62 @@
package net.ludocrypt.carvepump.blocks;

import java.util.Arrays;
import java.util.Iterator;

import net.ludocrypt.carvepump.CarveMyPumpkin;
import net.ludocrypt.carvepump.blocks.entity.CarvedBlockEntity;
import net.minecraft.advancement.criterion.Criteria;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.BlockWithEntity;
import net.minecraft.block.Blocks;
import net.minecraft.block.HorizontalFacingBlock;
import net.minecraft.block.Material;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.pattern.BlockPattern;
import net.minecraft.block.pattern.BlockPatternBuilder;
import net.minecraft.block.pattern.CachedBlockPosition;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.passive.IronGolemEntity;
import net.minecraft.entity.passive.SnowGolemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.predicate.block.BlockStatePredicate;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.util.Identifier;
import net.minecraft.util.function.MaterialPredicate;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;

public class CarvableBlock extends BlockWithEntity {

public static final DirectionProperty FACING = HorizontalFacingBlock.FACING;

public CarvableBlock(AbstractBlock.Settings settings) {
private BlockPattern snowGolemPattern;
private BlockPattern ironGolemPattern;

private Block carvedBlock;
private Identifier renderId;

public boolean carvable;

public CarvableBlock(AbstractBlock.Settings settings, Block carvedBlock, Identifier renderId, boolean iscarvable) {
super(settings);
this.setDefaultState(
(BlockState) ((BlockState) this.stateManager.getDefaultState()).with(FACING, Direction.NORTH));
this.carvedBlock = carvedBlock;
this.renderId = renderId;
carvable = iscarvable;
}

@Override
Expand All @@ -46,12 +79,164 @@ public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.INVISIBLE;
}

@Override
public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof CarvedBlockEntity) {
CarvedBlockEntity carvedPumpkinBlockEntity = (CarvedBlockEntity) blockEntity;
if (!world.isClient && !carvedPumpkinBlockEntity.isUncarved()) {
ItemStack itemStack = new ItemStack(state.getBlock());
CompoundTag compoundTag = carvedPumpkinBlockEntity.serializeCarving(new CompoundTag());
if (!compoundTag.isEmpty()) {
itemStack.putSubTag("BlockEntityTag", compoundTag);
}
ItemEntity itemEntity = new ItemEntity(world, (double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D,
(double) pos.getZ() + 0.5D, itemStack);
itemEntity.setToDefaultPickupDelay();
world.spawnEntity(itemEntity);
}
}
super.onBreak(world, pos, state, player);
}

@Override
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
super.onPlaced(world, pos, state, placer, itemStack);
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof CarvedBlockEntity) {
CarvedBlockEntity carvedPumpkinBlockEntity = (CarvedBlockEntity) blockEntity;
if (itemStack.hasTag()) {
carvedPumpkinBlockEntity.deserializeCarving(itemStack.getSubTag("BlockEntityTag"));
}
}
}

@Override
public String getTranslationKey() {
return carvedBlock.getTranslationKey();
}

@Override
public ItemStack getPickStack(BlockView world, BlockPos pos, BlockState state) {
ItemStack itemStack = new ItemStack(state.getBlock());
CompoundTag compoundTag = ((CarvedBlockEntity) world.getBlockEntity(pos)).serializeCarving(new CompoundTag());
if (!compoundTag.isEmpty()) {
itemStack.putSubTag("BlockEntityTag", compoundTag);
}
return itemStack;
}

public Block getCarvingBlock() {
return Blocks.PUMPKIN;
return carvedBlock;
}

public Identifier getRenderId() {
return new Identifier("carvepump", "textures/entity/pumpkin_halo_colors.png");
return renderId;
}

// Entity Spawning

@Override
public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean notify) {
if (!oldState.isOf(state.getBlock())) {
this.trySpawnEntity(world, pos, state);
}
}

private void trySpawnEntity(World world, BlockPos pos, BlockState state) {
BlockPattern.Result result = this.getSnowGolemPattern().searchAround(world, pos);
int k;
Iterator<ServerPlayerEntity> var6;
ServerPlayerEntity serverPlayerEntity2;
int m;
if (result != null) {
for (k = 0; k < this.getSnowGolemPattern().getHeight(); ++k) {
CachedBlockPosition cachedBlockPosition = result.translate(0, k, 0);
world.setBlockState(cachedBlockPosition.getBlockPos(), Blocks.AIR.getDefaultState(), 2);
world.syncWorldEvent(2001, cachedBlockPosition.getBlockPos(),
Block.getRawIdFromState(cachedBlockPosition.getBlockState()));
}

SnowGolemEntity snowGolemEntity = (SnowGolemEntity) EntityType.SNOW_GOLEM.create(world);
BlockPos blockPos = result.translate(0, 2, 0).getBlockPos();
snowGolemEntity.refreshPositionAndAngles((double) blockPos.getX() + 0.5D, (double) blockPos.getY() + 0.05D,
(double) blockPos.getZ() + 0.5D, 0.0F, 0.0F);
world.spawnEntity(snowGolemEntity);
var6 = world
.getNonSpectatingEntities(ServerPlayerEntity.class, snowGolemEntity.getBoundingBox().expand(5.0D))
.iterator();

while (var6.hasNext()) {
serverPlayerEntity2 = (ServerPlayerEntity) var6.next();
Criteria.SUMMONED_ENTITY.trigger(serverPlayerEntity2, snowGolemEntity);
}

for (m = 0; m < this.getSnowGolemPattern().getHeight(); ++m) {
CachedBlockPosition cachedBlockPosition2 = result.translate(0, m, 0);
world.updateNeighbors(cachedBlockPosition2.getBlockPos(), Blocks.AIR);
}
} else {
result = this.getIronGolemPattern().searchAround(world, pos);
if (result != null) {
for (k = 0; k < this.getIronGolemPattern().getWidth(); ++k) {
for (int l = 0; l < this.getIronGolemPattern().getHeight(); ++l) {
CachedBlockPosition cachedBlockPosition3 = result.translate(k, l, 0);
world.setBlockState(cachedBlockPosition3.getBlockPos(), Blocks.AIR.getDefaultState(), 2);
world.syncWorldEvent(2001, cachedBlockPosition3.getBlockPos(),
Block.getRawIdFromState(cachedBlockPosition3.getBlockState()));
}
}

BlockPos blockPos2 = result.translate(1, 2, 0).getBlockPos();
IronGolemEntity ironGolemEntity = (IronGolemEntity) EntityType.IRON_GOLEM.create(world);
ironGolemEntity.setPlayerCreated(true);
ironGolemEntity.refreshPositionAndAngles((double) blockPos2.getX() + 0.5D,
(double) blockPos2.getY() + 0.05D, (double) blockPos2.getZ() + 0.5D, 0.0F, 0.0F);
world.spawnEntity(ironGolemEntity);
var6 = world.getNonSpectatingEntities(ServerPlayerEntity.class,
ironGolemEntity.getBoundingBox().expand(5.0D)).iterator();

while (var6.hasNext()) {
serverPlayerEntity2 = (ServerPlayerEntity) var6.next();
Criteria.SUMMONED_ENTITY.trigger(serverPlayerEntity2, ironGolemEntity);
}

for (m = 0; m < this.getIronGolemPattern().getWidth(); ++m) {
for (int n = 0; n < this.getIronGolemPattern().getHeight(); ++n) {
CachedBlockPosition cachedBlockPosition4 = result.translate(m, n, 0);
world.updateNeighbors(cachedBlockPosition4.getBlockPos(), Blocks.AIR);
}
}
}
}
}

private BlockPattern getSnowGolemPattern() {
if (this.snowGolemPattern == null) {
this.snowGolemPattern = BlockPatternBuilder.start().aisle("^", "#", "#")
.where('^', CachedBlockPosition.matchesBlockState((state) -> {
return state != null && (Arrays.stream(CarveMyPumpkin.carvableBlocks)
.anyMatch(t -> t.equals(state.getBlock())));
}))
.where('#', CachedBlockPosition.matchesBlockState(BlockStatePredicate.forBlock(Blocks.SNOW_BLOCK)))
.build();
}

return this.snowGolemPattern;
}

private BlockPattern getIronGolemPattern() {
if (this.ironGolemPattern == null) {
this.ironGolemPattern = BlockPatternBuilder.start().aisle("~^~", "###", "~#~")
.where('^', CachedBlockPosition.matchesBlockState((state) -> {
return state != null && (Arrays.stream(CarveMyPumpkin.carvableBlocks)
.anyMatch(t -> t.equals(state.getBlock())));
}))
.where('#', CachedBlockPosition.matchesBlockState(BlockStatePredicate.forBlock(Blocks.IRON_BLOCK)))
.where('~', CachedBlockPosition.matchesBlockState(MaterialPredicate.create(Material.AIR))).build();
}

return this.ironGolemPattern;
}

}
Loading

0 comments on commit 5a2a14a

Please sign in to comment.