Skip to content

Commit

Permalink
Port the fusion shrine advancement fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Electro593 authored and Azzyypaaras committed Dec 5, 2023
1 parent 8ac3aee commit 0358f59
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.jetbrains.annotations.*;
import vazkii.patchouli.api.*;

@SuppressWarnings("UnstableApiUsage")
public class FusionShrineBlock extends InWorldInteractionBlock {

public static final Identifier UNLOCK_IDENTIFIER = SpectrumCommon.locate("collect_all_basic_pigments_besides_brown");
Expand All @@ -58,7 +59,7 @@ public static boolean verifyStructureWithSkyAccess(World world, BlockPos blockPo
world.playSound(null, blockPos, SpectrumSoundEvents.USE_FAIL, SoundCategory.NEUTRAL, 1.0F, 1.0F);
return false;
}
if (!world.isSkyVisible(blockPos)) {
if (!world.isSkyVisible(blockPos) && client.player != null) {
if (world.isClient) {
world.addParticle(SpectrumParticleTypes.RED_SPARKLE_RISING, blockPos.getX() + 0.5, blockPos.getY() + 1, blockPos.getZ() + 0.5, 0, 0.5, 0);
client.player.playSound(SpectrumSoundEvents.USE_FAIL, SoundCategory.NEUTRAL, 1.0F, 1.0F);
Expand Down Expand Up @@ -189,30 +190,22 @@ public void onLandedUpon(World world, BlockState state, BlockPos pos, Entity ent
}

@Override
@SuppressWarnings("deprecation")
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (world.isClient) {
verifyStructureWithSkyAccess(world, pos, null);
return ActionResult.SUCCESS;
} else {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof FusionShrineBlockEntity fusionShrineBlockEntity) {
// if the structure is valid the player can put / retrieve items and fluids into the shrine
if (blockEntity instanceof FusionShrineBlockEntity fusionShrineBlockEntity && verifyStructure(world, pos, (ServerPlayerEntity) player)) {
fusionShrineBlockEntity.setOwner(player);

ItemStack handStack = player.getStackInHand(hand);
if (FluidStorageUtil.interactWithFluidStorage(fusionShrineBlockEntity.fluidStorage, player, hand)) {
if (FluidStorageUtil.interactWithFluidStorage(fusionShrineBlockEntity.fluidStorage, player, hand)
|| (player.isSneaking() || handStack.isEmpty()) && retrieveLastStack(world, pos, player, hand, handStack, fusionShrineBlockEntity)
|| !handStack.isEmpty() && inputHandStack(world, player, hand, handStack, fusionShrineBlockEntity)) {
fusionShrineBlockEntity.updateInClientWorld();
} else {
// if the structure is valid the player can put / retrieve blocks into the shrine
if (player.isSneaking() || handStack.isEmpty()) {
// sneaking or empty hand: remove items
if (retrieveLastStack(world, pos, player, hand, handStack, fusionShrineBlockEntity)) {
fusionShrineBlockEntity.updateInClientWorld();
}
} else if (verifyStructure(world, pos, (ServerPlayerEntity) player) && !handStack.isEmpty()) {
if (inputHandStack(world, player, hand, handStack, fusionShrineBlockEntity)) {
fusionShrineBlockEntity.updateInClientWorld();
}
}
}
}

Expand All @@ -221,6 +214,7 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
}

@Override
@SuppressWarnings("deprecation")
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return SHAPE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import java.util.*;

@SuppressWarnings("UnstableApiUsage")
public class FusionShrineBlockEntity extends InWorldInteractionBlockEntity implements PlayerOwned, Upgradeable {

protected static final int INVENTORY_SIZE = 7;
Expand Down Expand Up @@ -90,7 +91,7 @@ public static void clientTick(@NotNull World world, BlockPos blockPos, BlockStat
public void spawnCraftingParticles() {
BlockPos blockPos = getPos();
FusionShrineRecipe recipe = this.currentRecipe;
if (recipe != null) {
if (recipe != null && world != null) {
Fluid fluid = this.getFluidVariant().getFluid();
Optional<DyeColor> optionalFluidColor = ColorRegistry.FLUID_COLORS.getMapping(fluid);
if (optionalFluidColor.isPresent()) {
Expand Down Expand Up @@ -261,8 +262,10 @@ public void writeNbt(NbtCompound nbt) {
}

public void playSound(SoundEvent soundEvent, float volume) {
Random random = world.random;
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), soundEvent, SoundCategory.BLOCKS, volume, 0.9F + random.nextFloat() * 0.15F);
if (world != null) {
Random random = world.random;
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), soundEvent, SoundCategory.BLOCKS, volume, 0.9F + random.nextFloat() * 0.15F);
}
}

public void grantPlayerFusionCraftingAdvancement(FusionShrineRecipe recipe, int experience) {
Expand Down

0 comments on commit 0358f59

Please sign in to comment.