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
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public BlockState getTargetState(Level world) {
return Blocks.NETHERRACK.defaultBlockState();
} else if (BuiltinDimensionTypes.END_EFFECTS.equals(identifier)) {
return Blocks.END_STONE.defaultBlockState();
} else if (SpectrumDimensionKeys.DIMENSION_ID.equals(identifier)) {
} else if (SpectrumDimensionKeys.DEEPER_DOWN_ID.equals(identifier)) {
return SpectrumBlocks.BLACKSLAG.get().defaultBlockState();
}
return Blocks.DIRT.defaultBlockState();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/dafuqs/spectrum/blocks/decay/RuinBlock.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.dafuqs.spectrum.blocks.decay;

import com.mojang.serialization.*;
import de.dafuqs.spectrum.blocks.*;
import de.dafuqs.spectrum.blocks.portal.*;
import de.dafuqs.spectrum.config.*;
import de.dafuqs.spectrum.particle.effect.*;
import de.dafuqs.spectrum.progression.*;
Expand Down Expand Up @@ -109,7 +109,7 @@ protected void spawnAfterBreak(BlockState state, ServerLevel level, BlockPos pos
}
} else if (conversion == Conversion.SPECIAL || level.dimension() == Level.OVERWORLD && pos.getY() == level.getMinBuildHeight()) {
return SpectrumBlocks.DEEPER_DOWN_PORTAL.get().defaultBlockState().setValue(DeeperDownPortalBlock.FACING_UP, false);
} else if (level.dimension() == SpectrumDimensionKeys.DIMENSION_KEY && pos.getY() == level.getMaxBuildHeight() - 1) { // highest layer cannot be built on
} else if (level.dimension() == SpectrumDimensionKeys.DEEPER_DOWN_KEY && pos.getY() == level.getMaxBuildHeight() - 1) { // highest layer cannot be built on
return SpectrumBlocks.DEEPER_DOWN_PORTAL.get().defaultBlockState().setValue(DeeperDownPortalBlock.FACING_UP, true);
}
return null;
Expand Down
115 changes: 115 additions & 0 deletions src/main/java/de/dafuqs/spectrum/blocks/portal/BedrockPortalBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package de.dafuqs.spectrum.blocks.portal;

import com.google.common.collect.*;
import com.mojang.serialization.*;
import de.dafuqs.spectrum.*;
import de.dafuqs.spectrum.helpers.*;
import de.dafuqs.spectrum.networking.s2c_payloads.*;
import de.dafuqs.spectrum.particle.*;
import de.dafuqs.spectrum.registries.*;
import net.minecraft.core.*;
import net.minecraft.resources.*;
import net.minecraft.server.level.*;
import net.minecraft.sounds.*;
import net.minecraft.tags.*;
import net.minecraft.util.*;
import net.minecraft.world.*;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.player.*;
import net.minecraft.world.item.*;
import net.minecraft.world.level.*;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.state.*;
import net.minecraft.world.level.block.state.properties.*;
import net.minecraft.world.level.material.*;
import net.minecraft.world.level.portal.*;
import net.minecraft.world.phys.*;
import net.minecraft.world.phys.shapes.*;

public abstract class BedrockPortalBlock extends Block {

public static final BooleanProperty FACING_UP = BlockStateProperties.UP;

protected static final VoxelShape SHAPE = Block.box(0.0D, 0.0D, 0.0D, 16.0D, 4D, 16.0D);
protected static final VoxelShape SHAPE_UP = Block.box(0.0D, 4D, 0.0D, 16.0D, 16.0D, 16.0D);

public BedrockPortalBlock(Properties settings) {
super(settings);
this.registerDefaultState((this.stateDefinition.any()).setValue(FACING_UP, false));
}

@Override
public boolean useShapeForLightOcclusion(BlockState state) {
return true;
}

@Override
public ItemInteractionResult useItemOn(ItemStack handStack, BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if (handStack.is(SpectrumItems.BEDROCK_DUST)) {
if (world.isClientSide()) {
return ItemInteractionResult.SUCCESS;
} else {
BlockState placedState = Blocks.BEDROCK.defaultBlockState();
world.setBlockAndUpdate(pos, placedState);
world.playSound(null, pos, placedState.getSoundType().getPlaceSound(), SoundSource.BLOCKS, 1.0F, 1.0F);
return ItemInteractionResult.CONSUME;
}
}

return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
}

@Override
public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
return state.getValue(FACING_UP) ? SHAPE_UP : SHAPE;
}

@Override
public ItemStack getCloneItemStack(LevelReader world, BlockPos pos, BlockState state) {
return ItemStack.EMPTY;
}

@Override
public boolean canBeReplaced(BlockState state, Fluid fluid) {
return false;
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(FACING_UP);
}

public static void teleportToSafePosition(Level world, Entity entity, BlockPos targetPos, int maxRadius) {
for (BlockPos bp : BlockPos.withinManhattan(targetPos, maxRadius, maxRadius, maxRadius)) {
entity.setPos(Vec3.atBottomCenterOf(bp));
if (world.getBlockState(bp.below()).getCollisionShape(world, bp.below()) == Shapes.block()
&& world.noCollision(entity)
&& entity.getY() < (double) world.getMaxBuildHeight()
&& entity.getY() > (double) world.getMinBuildHeight()) {

entity.teleportTo(bp.getX() + 0.5, bp.getY() + 0.5, bp.getZ() + 0.5);
return;
}
}

world.removeBlock(targetPos.above(1), false);
world.removeBlock(targetPos, false);
world.setBlockAndUpdate(targetPos.below(1), Blocks.COBBLED_DEEPSLATE.defaultBlockState());
entity.teleportTo(targetPos.getX() + 0.5, targetPos.getY() + 0.5, targetPos.getZ() + 0.5);
}

@Override
public void animateTick(BlockState state, Level world, BlockPos pos, RandomSource random) {
if (!state.getValue(BedrockPortalBlock.FACING_UP) || random.nextInt(8) == 0) {
spawnVoidFogParticle(world, pos, random);
}
}

private static void spawnVoidFogParticle(Level world, BlockPos pos, RandomSource random) {
double d = (double) pos.getX() + random.nextDouble();
double e = (double) pos.getY() + 0.3D;
double f = (double) pos.getZ() + random.nextDouble();
world.addParticle(SpectrumParticleTypes.VOID_FOG, d, e, f, 0.0D, 0.1D, 0.0D);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package de.dafuqs.spectrum.blocks.portal;

import com.mojang.datafixers.util.*;
import com.mojang.serialization.*;
import de.dafuqs.spectrum.dimensions.*;
import de.dafuqs.spectrum.registries.*;
import net.minecraft.advancements.*;
import net.minecraft.core.*;
import net.minecraft.resources.*;
import net.minecraft.server.level.*;
import net.minecraft.world.entity.*;
import net.minecraft.world.level.*;
import net.minecraft.world.level.block.state.*;
import net.minecraft.world.level.portal.*;
import net.minecraft.world.phys.*;

public class ConservatoryPortalBlock extends BedrockPortalBlock {

public static final MapCodec<ConservatoryPortalBlock> CODEC = simpleCodec(ConservatoryPortalBlock::new);

public ConservatoryPortalBlock(Properties settings) {
super(settings);
}

@Override
public MapCodec<? extends ConservatoryPortalBlock> codec() {
return CODEC;
}

@Override
public void entityInside(BlockState state, Level level, BlockPos pos, Entity entity) {
if (level instanceof ServerLevel currentLevel && entity.canUsePortal(false) && !entity.isOnPortalCooldown() && entity instanceof ServerPlayer player) {

entity.setPortalCooldown();
if (level.dimension() == SpectrumDimensionKeys.CONSERVATORY_KEY) {
// => teleport back to where the player entered from
ConservatoryDataStore.teleportBackToEntrance(currentLevel, player);
} else {
// => teleport to Conservatory
ConservatoryDataStore.teleportToConservatory(pos, currentLevel, player, SpectrumStructureIDs.TEST);
}
}
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.dafuqs.spectrum.blocks;
package de.dafuqs.spectrum.blocks.portal;

import com.google.common.collect.*;
import com.mojang.serialization.*;
Expand All @@ -12,47 +12,30 @@
import net.minecraft.server.level.*;
import net.minecraft.sounds.*;
import net.minecraft.tags.*;
import net.minecraft.util.*;
import net.minecraft.world.*;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.player.*;
import net.minecraft.world.item.*;
import net.minecraft.world.level.*;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.state.*;
import net.minecraft.world.level.block.state.properties.*;
import net.minecraft.world.level.material.*;
import net.minecraft.world.level.portal.*;
import net.minecraft.world.phys.*;
import net.minecraft.world.phys.shapes.*;

public class DeeperDownPortalBlock extends Block {
public class DeeperDownPortalBlock extends BedrockPortalBlock {

public static final MapCodec<DeeperDownPortalBlock> CODEC = simpleCodec(DeeperDownPortalBlock::new);

private final static ResourceLocation CREATE_PORTAL_ADVANCEMENT_IDENTIFIER = SpectrumCommon.locate("midgame/open_deeper_down_portal");
private final static String CREATE_PORTAL_ADVANCEMENT_CRITERION = "opened_deeper_down_portal";

public static final BooleanProperty FACING_UP = BlockStateProperties.UP;

protected static final VoxelShape SHAPE = Block.box(0.0D, 0.0D, 0.0D, 16.0D, 4D, 16.0D);
protected static final VoxelShape SHAPE_UP = Block.box(0.0D, 4D, 0.0D, 16.0D, 16.0D, 16.0D);

public DeeperDownPortalBlock(Properties settings) {
super(settings);
this.registerDefaultState((this.stateDefinition.any()).setValue(FACING_UP, false));
}

@Override
public MapCodec<? extends DeeperDownPortalBlock> codec() {
return CODEC;
}

@Override
public boolean useShapeForLightOcclusion(BlockState state) {
return true;
}

@Override
public void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean notify) {
super.onPlace(state, world, pos, oldState, notify);
Expand All @@ -69,22 +52,6 @@ public void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldS
}
}

@Override
public ItemInteractionResult useItemOn(ItemStack handStack, BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if (handStack.is(SpectrumItems.BEDROCK_DUST)) {
if (world.isClientSide()) {
return ItemInteractionResult.SUCCESS;
} else {
BlockState placedState = Blocks.BEDROCK.defaultBlockState();
world.setBlockAndUpdate(pos, placedState);
world.playSound(null, pos, placedState.getSoundType().getPlaceSound(), SoundSource.BLOCKS, 1.0F, 1.0F);
return ItemInteractionResult.CONSUME;
}
}

return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
}

private boolean hasNeighboringPortals(Level world, BlockPos pos) {
for (Direction direction : Direction.Plane.HORIZONTAL) {
if (world.getBlockState(pos.relative(direction)).is(this)) {
Expand All @@ -94,26 +61,6 @@ private boolean hasNeighboringPortals(Level world, BlockPos pos) {
return false;
}

@Override
public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
return state.getValue(FACING_UP) ? SHAPE_UP : SHAPE;
}

@Override
public ItemStack getCloneItemStack(LevelReader world, BlockPos pos, BlockState state) {
return ItemStack.EMPTY;
}

@Override
public boolean canBeReplaced(BlockState state, Fluid fluid) {
return false;
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(FACING_UP);
}

@Override
public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) {
if (world instanceof ServerLevel serverWorld && entity.canUsePortal(false) && !entity.isOnPortalCooldown()) {
Expand Down Expand Up @@ -158,7 +105,7 @@ public void entityInside(BlockState state, Level world, BlockPos pos, Entity ent

if (currentWorldKey == Level.OVERWORLD) {
// => teleport to DD
ServerLevel targetWorld = serverWorld.getServer().getLevel(SpectrumDimensionKeys.DIMENSION_KEY);
ServerLevel targetWorld = serverWorld.getServer().getLevel(SpectrumDimensionKeys.DEEPER_DOWN_KEY);
if (targetWorld != null) {
BlockPos portalPos = new BlockPos(pos.getX(), targetWorld.getMaxBuildHeight() - 1, pos.getZ());
if (!targetWorld.getBlockState(portalPos).is(SpectrumBlocks.DEEPER_DOWN_PORTAL)) {
Expand Down Expand Up @@ -250,37 +197,4 @@ protected BlockPos computeNext() {
};
}

public void teleportToSafePosition(Level world, Entity entity, BlockPos targetPos, int maxRadius) {
for (BlockPos bp : BlockPos.withinManhattan(targetPos, maxRadius, maxRadius, maxRadius)) {
entity.setPos(Vec3.atBottomCenterOf(bp));
if (world.getBlockState(bp.below()).getCollisionShape(world, bp.below()) == Shapes.block()
&& world.noCollision(entity)
&& entity.getY() < (double) world.getMaxBuildHeight()
&& entity.getY() > (double) world.getMinBuildHeight()) {

entity.teleportTo(bp.getX() + 0.5, bp.getY() + 0.5, bp.getZ() + 0.5);
return;
}
}

world.removeBlock(targetPos.above(1), false);
world.removeBlock(targetPos, false);
world.setBlockAndUpdate(targetPos.below(1), Blocks.COBBLED_DEEPSLATE.defaultBlockState());
entity.teleportTo(targetPos.getX() + 0.5, targetPos.getY() + 0.5, targetPos.getZ() + 0.5);
}

@Override
public void animateTick(BlockState state, Level world, BlockPos pos, RandomSource random) {
if (!state.getValue(DeeperDownPortalBlock.FACING_UP) || random.nextInt(8) == 0) {
spawnVoidFogParticle(world, pos, random);
}
}

private static void spawnVoidFogParticle(Level world, BlockPos pos, RandomSource random) {
double d = (double) pos.getX() + random.nextDouble();
double e = (double) pos.getY() + 0.3D;
double f = (double) pos.getZ() + random.nextDouble();
world.addParticle(SpectrumParticleTypes.VOID_FOG, d, e, f, 0.0D, 0.1D, 0.0D);
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@NullMarked
@MethodsReturnNonnullByDefault
@FieldsAreNonnullByDefault
package de.dafuqs.spectrum.deeper_down.client;
package de.dafuqs.spectrum.blocks.portal;

import net.minecraft.*;
import org.jspecify.annotations.*;
Loading
Loading