Skip to content

Commit

Permalink
Make cakes pull the bites from the item stack NBT if available
Browse files Browse the repository at this point in the history
  • Loading branch information
Juuxel committed Jan 15, 2022
1 parent e5e29db commit 0a0c437
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ but major versions still indicate breaking changes to worlds etc.
[Blocks to Parts](https://github.com/Juuxel/BlocksToParts).
- Updated to Minecraft 1.18.1.
- Reduced the amount of mixins dramatically thanks to LibMultiPart updates.
- Cakes placed in multipart containers now get the proper bite count from
the item's `BlockStateTag` NBT data

### Fixed
- Fix torch luminance being 15 instead of 14
16 changes: 14 additions & 2 deletions src/main/java/juuxel/vanillaparts/MultipartItemTweak.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.CakeBlock;
import net.minecraft.block.DyedCarpetBlock;
import net.minecraft.block.FenceBlock;
import net.minecraft.block.LeverBlock;
Expand All @@ -38,6 +39,8 @@
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.ActionResult;
Expand Down Expand Up @@ -102,8 +105,17 @@ public ActionResult interact(PlayerEntity player, World world, Hand hand, BlockH
} else if (block instanceof FenceBlock) {
offer = handleFences(world, hit, pos, block);
} else if (block == Blocks.CAKE) {
// TODO: Pull the bites from the block state tag
offer = handleSimple(world, pos, block, holder -> new CakePart(VpParts.CAKE, holder));
NbtCompound blockStateTag = stack.getSubNbt("BlockStateTag");
String bitesProperty = CakeBlock.BITES.getName();
int bites;

if (blockStateTag != null && blockStateTag.contains(bitesProperty, NbtElement.NUMBER_TYPE)) {
bites = blockStateTag.getInt(bitesProperty);
} else {
bites = 0;
}

offer = handleSimple(world, pos, block, holder -> new CakePart(VpParts.CAKE, holder, bites));
} else {
for (Extension extension : extensions) {
offer = extension.handle(block, player, world, hand, hit, pos);
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/juuxel/vanillaparts/part/CakePart.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ public CakePart(PartDefinition definition, MultipartHolder holder, int bites) {
this.bites = bites;
}

@Deprecated
public CakePart(PartDefinition definition, MultipartHolder holder) {
this(definition, holder, 0);
}

public static CakePart fromNbt(PartDefinition definition, MultipartHolder holder, NbtCompound nbt) {
return new CakePart(definition, holder, nbt.getInt(NbtKeys.BITES));
}
Expand Down

0 comments on commit 0a0c437

Please sign in to comment.