Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/main/java/de/dafuqs/spectrum/blocks/present/PresentBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.serialization.*;
import de.dafuqs.spectrum.api.energy.color.*;
import de.dafuqs.spectrum.api.item.*;
import de.dafuqs.spectrum.components.*;
import de.dafuqs.spectrum.helpers.*;
import de.dafuqs.spectrum.networking.s2c_payloads.*;
import de.dafuqs.spectrum.particle.effect.*;
Expand All @@ -17,6 +18,7 @@
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.player.*;
import net.minecraft.world.item.*;
import net.minecraft.world.item.context.*;
import net.minecraft.world.level.*;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.entity.*;
Expand Down Expand Up @@ -106,9 +108,8 @@ public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
@Override
public void setPlacedBy(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack itemStack) {
BlockEntity blockEntity = world.getBlockEntity(pos);
world.setBlockAndUpdate(pos, state.setValue(PresentBlock.VARIANT, PresentBlockItem.getWrapData(itemStack).variant()));
if (blockEntity instanceof PresentBlockEntity presentBlockEntity) {
presentBlockEntity.setPresent(itemStack);
presentBlockEntity.setPresent(itemStack.copyWithCount(1));
}
}

Expand Down Expand Up @@ -220,7 +221,16 @@ private static void spawnParticlesClient(Level world, BlockPos pos, int color, i
world.addParticle(particleEffect, posX, posY, posZ, randX, randY, randZ);
}
}


@Override
public @Nullable BlockState getStateForPlacement(BlockPlaceContext context) {
WrappedPresentComponent presentComponent = PresentBlockItem.getWrapData(context.getItemInHand());
if (presentComponent != null) {
return this.defaultBlockState().setValue(VARIANT, presentComponent.variant());
}
return super.getStateForPlacement(context);
}

@Override
public @Nullable BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return new PresentBlockEntity(pos, state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ public InteractionResultHolder<ItemStack> use(Level world, Player user, Interact
return InteractionResultHolder.pass(itemStack);
}

@Override
public int getMaxStackSize(ItemStack stack) {
return stack.has(SpectrumDataComponentTypes.WRAPPED_PRESENT) || !isEmpty(stack) ? 1 : super.getMaxStackSize(stack);
}

// CraftingInventory does not recalculate the recipe after inputting / retrieving stacks from the present.
// The recipes output will still hold the original present data from when it was put into the crafting grid
// If the player then puts / receives items from the present they are able to duplicate items
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ItemStack assemble(CraftingInput input, HolderLookup.Provider registryLoo
for (int j = 0; j < input.size(); ++j) {
ItemStack stack = input.getItem(j);
if (stack.getItem() instanceof PresentBlockItem) {
presentStack = stack.copy();
presentStack = stack.copyWithCount(1);
} else if (stack.getItem() instanceof PigmentItem pigmentItem) {
InkColor color = pigmentItem.getInkColor();
if (colors.containsKey(color)) {
Expand Down Expand Up @@ -101,14 +101,14 @@ public ItemStack assemble(CraftingInput input, HolderLookup.Provider registryLoo
return PresentBlock.WrappingPaper.PURPLE;
} else if (item == Items.CAKE) {
return PresentBlock.WrappingPaper.CAKE;
} else if (stack.is(ItemTags.FLOWERS)) {
return PresentBlock.WrappingPaper.STRIPED;
} else if (item == Items.SPORE_BLOSSOM) {
return PresentBlock.WrappingPaper.PRIDE;
} else if (item == Items.FIREWORK_STAR) {
return PresentBlock.WrappingPaper.STARRY;
} else if (item == Items.SNOWBALL) {
return PresentBlock.WrappingPaper.WINTER;
} else if (item == Items.SPORE_BLOSSOM) {
return PresentBlock.WrappingPaper.PRIDE;
} else if (stack.is(ItemTags.FLOWERS)) {
return PresentBlock.WrappingPaper.STRIPED;
}
return null;
}
Expand Down
Loading