Skip to content

Commit

Permalink
Corridor Teleporter (#222)
Browse files Browse the repository at this point in the history
Co-authored-by: Craig <[email protected]>
  • Loading branch information
CommandrMoose and Jeryn99 authored Apr 18, 2024
1 parent 537b442 commit d2bde10
Show file tree
Hide file tree
Showing 20 changed files with 450 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package whocraft.tardis_refined.common.block.device;

import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import whocraft.tardis_refined.common.blockentity.device.CorridorTeleporterBlockEntity;
import whocraft.tardis_refined.common.blockentity.life.EyeBlockEntity;
import whocraft.tardis_refined.common.tardis.ExteriorShell;
import whocraft.tardis_refined.common.util.ClientHelper;
import whocraft.tardis_refined.common.util.TRTeleporter;
import whocraft.tardis_refined.registry.TRBlockEntityRegistry;
import whocraft.tardis_refined.registry.TRDimensionTypes;

public class CorridorTeleporterBlock extends Block implements EntityBlock {

public CorridorTeleporterBlock(Properties properties) {
super(properties);
}

@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
return new CorridorTeleporterBlockEntity(blockPos, blockState);
}

@Override
public VoxelShape getShape(BlockState blockState, BlockGetter blockGetter, BlockPos blockPos, CollisionContext collisionContext) {
return Shapes.join(Block.box(2, 0, 2, 14, 2, 14), Block.box(4, 1, 4, 12, 3, 12), BooleanOp.OR);
}

@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(@NotNull Level level, @NotNull BlockState state, @NotNull BlockEntityType<T> type) {
return (level1, blockPos, blockState, t) -> {
if (t instanceof CorridorTeleporterBlockEntity corridorTeleporterBlockEntity) {
corridorTeleporterBlockEntity.tick(level, blockPos, blockState, corridorTeleporterBlockEntity);
}
};
}


@Override
public void entityInside(BlockState blockState, Level level, BlockPos blockPos, Entity entity) {

if (!level.isClientSide()){
ServerLevel serverLevel = (ServerLevel)level;
if (serverLevel.getBlockEntity(blockPos) instanceof CorridorTeleporterBlockEntity corridorTeleporterBlockEntity) {
corridorTeleporterBlockEntity.startTeleporterTimer();
}
} else {

for (int i = 0; i < 5; i++) {
ClientHelper.playParticle((ClientLevel) level, ParticleTypes.PORTAL, new Vec3(blockPos.getX() + 0.5f, blockPos.getY(), blockPos.getZ() + 0.5f), -0.5 + level.random.nextFloat(), 0.5f, -0.5 + level.random.nextFloat());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package whocraft.tardis_refined.common.blockentity.device;

import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import whocraft.tardis_refined.client.TRParticles;
import whocraft.tardis_refined.common.tardis.TardisArchitectureHandler;
import whocraft.tardis_refined.common.tardis.manager.TardisInteriorManager;
import whocraft.tardis_refined.common.util.TRTeleporter;
import whocraft.tardis_refined.registry.TRBlockEntityRegistry;
import whocraft.tardis_refined.registry.TRDimensionTypes;
import whocraft.tardis_refined.registry.TRSoundRegistry;

import java.util.List;

public class CorridorTeleporterBlockEntity extends BlockEntity implements BlockEntityTicker<CorridorTeleporterBlockEntity> {

private static int TICKS_FOR_COOLDOWN = 100;
private static int TICKS_TO_TRIGGER_TELEPORT = 160;

private int timeSinceTriggeredTicks = 0;
private int cooldownTicks = 0;

public CorridorTeleporterBlockEntity( BlockPos blockPos, BlockState blockState) {
super(TRBlockEntityRegistry.CORRIDOR_TELEPORTER.get(), blockPos, blockState);
}

public void startTeleporterTimer() {
if (cooldownTicks == 0 && timeSinceTriggeredTicks == 0) {
this.timeSinceTriggeredTicks += 1;
level.playSound(null, getBlockPos(), TRSoundRegistry.CORRIDOR_TELEPORTER.get(), SoundSource.BLOCKS, 1, 1);
}
}


@Override
public void tick(Level level, BlockPos blockPos, BlockState blockState, CorridorTeleporterBlockEntity blockEntity) {

// If we're meant to be ticking, let's tick.
if (this.timeSinceTriggeredTicks > 0 && cooldownTicks == 0) {
this.timeSinceTriggeredTicks += 1;
}

if (this.cooldownTicks > 0) {
this.cooldownTicks -= 1;
}

if (timeSinceTriggeredTicks == TICKS_TO_TRIGGER_TELEPORT) {
timeSinceTriggeredTicks = 0;
this.cooldownTicks = TICKS_FOR_COOLDOWN;

if (level.dimensionTypeId() != TRDimensionTypes.TARDIS) {
level.playSound(null, getBlockPos(), SoundEvents.BLAZE_DEATH, SoundSource.BLOCKS, 1, 0.5f);
return;
}


if (level instanceof ServerLevel serverLevel) {
AABB box = new AABB(blockPos).inflate(0.25f, 1, 0.25f);
List<Entity> entities = serverLevel.getEntitiesOfClass(Entity.class, box);
BlockPos corridorAirlock = TardisInteriorManager.STATIC_CORRIDOR_POSITION;
for (Entity entity : entities) {
TRTeleporter.performTeleport(entity, serverLevel, corridorAirlock.getX() + 0.5f, corridorAirlock.getY(), corridorAirlock.getZ() + 0.5f, 0,0 );
}

if (entities.stream().count() > 0) {
// Play at the source block and at the exit point.
level.playSound(null, getBlockPos(), TRSoundRegistry.CORRIDOR_TELEPORTER_SUCCESS.get(), SoundSource.BLOCKS, 1, 1);
level.playSound(null, corridorAirlock, TRSoundRegistry.CORRIDOR_TELEPORTER_SUCCESS.get(), SoundSource.BLOCKS, 1, 1);
}
}


}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,30 @@ public static void registerRecipes() {

), TRBlockRegistry.LANDING_PAD.get().asItem()));


register(new ManipulatorCraftingRecipe(Arrays.asList(
new ManipulatorCraftingRecipeItem(new BlockPos(0, 0, 0), TRBlockRegistry.ZEITON_FUSED_IRON_BLOCK.get()),
new ManipulatorCraftingRecipeItem(new BlockPos(0, 0, 1), Blocks.SMOOTH_STONE_SLAB),
new ManipulatorCraftingRecipeItem(new BlockPos(0, 0, 2), TRBlockRegistry.ZEITON_FUSED_IRON_BLOCK.get()),
new ManipulatorCraftingRecipeItem(new BlockPos(1, 0, 0), Blocks.SMOOTH_STONE_SLAB),
new ManipulatorCraftingRecipeItem(new BlockPos(1, 0, 1), TRBlockRegistry.LANDING_PAD.get()),
new ManipulatorCraftingRecipeItem(new BlockPos(1, 0, 2), Blocks.SMOOTH_STONE_SLAB),
new ManipulatorCraftingRecipeItem(new BlockPos(2, 0, 0), TRBlockRegistry.ZEITON_FUSED_IRON_BLOCK.get()),
new ManipulatorCraftingRecipeItem(new BlockPos(2, 0, 1), Blocks.SMOOTH_STONE_SLAB),
new ManipulatorCraftingRecipeItem(new BlockPos(2, 0, 2), TRBlockRegistry.ZEITON_FUSED_IRON_BLOCK.get()),

new ManipulatorCraftingRecipeItem(new BlockPos(0, 1, 0), Blocks.IRON_TRAPDOOR),
new ManipulatorCraftingRecipeItem(new BlockPos(0, 1, 1), Blocks.IRON_TRAPDOOR),
new ManipulatorCraftingRecipeItem(new BlockPos(0, 1, 2), Blocks.IRON_TRAPDOOR),
new ManipulatorCraftingRecipeItem(new BlockPos(1, 1, 0), Blocks.IRON_TRAPDOOR),
new ManipulatorCraftingRecipeItem(new BlockPos(1, 1, 1), Blocks.AIR),
new ManipulatorCraftingRecipeItem(new BlockPos(1, 1, 2), Blocks.IRON_TRAPDOOR),
new ManipulatorCraftingRecipeItem(new BlockPos(2, 1, 0), Blocks.IRON_TRAPDOOR),
new ManipulatorCraftingRecipeItem(new BlockPos(2, 1, 1), Blocks.IRON_TRAPDOOR),
new ManipulatorCraftingRecipeItem(new BlockPos(2, 1, 2), Blocks.IRON_TRAPDOOR)

), TRBlockRegistry.CORRIDOR_TELEPORTER.get().asItem()));

register(new ManipulatorCraftingRecipe(Arrays.asList(
new ManipulatorCraftingRecipeItem(new BlockPos(0, 0, 0), TRBlockRegistry.ZEITON_BLOCK.get()),
new ManipulatorCraftingRecipeItem(new BlockPos(0, 1, 0), Blocks.POLISHED_DEEPSLATE_WALL),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import whocraft.tardis_refined.common.blockentity.device.ArtronPillarBlockEntity;
import whocraft.tardis_refined.common.blockentity.device.AstralManipulatorBlockEntity;
import whocraft.tardis_refined.common.blockentity.door.RootShellDoorBlockEntity;
import whocraft.tardis_refined.common.blockentity.device.ConsoleConfigurationBlockEntity;
import whocraft.tardis_refined.common.blockentity.device.FlightDetectorBlockEntity;
import whocraft.tardis_refined.common.blockentity.door.BulkHeadDoorBlockEntity;
import whocraft.tardis_refined.common.blockentity.door.GlobalDoorBlockEntity;
import whocraft.tardis_refined.common.blockentity.life.ArsEggBlockEntity;
Expand Down Expand Up @@ -38,5 +36,8 @@ public class TRBlockEntityRegistry {
public static final RegistrySupplier<BlockEntityType<ArtronPillarBlockEntity>> ARTRON_PILLAR = BLOCK_ENTITY_TYPES.register("artron_pillar", () -> BlockEntityType.Builder.of(ArtronPillarBlockEntity::new, TRBlockRegistry.ARTRON_PILLAR.get()).build(null));
public static final RegistrySupplier<BlockEntityType<AstralManipulatorBlockEntity>> ASTRAL_MANIPULATOR = BLOCK_ENTITY_TYPES.register("astral_manipulator", () -> BlockEntityType.Builder.of(AstralManipulatorBlockEntity::new, TRBlockRegistry.ASTRAL_MANIPULATOR_BLOCK.get()).build(null));
public static final RegistrySupplier<BlockEntityType<EyeBlockEntity>> THE_EYE = BLOCK_ENTITY_TYPES.register("the_eye", () -> BlockEntityType.Builder.of(EyeBlockEntity::new, TRBlockRegistry.THE_EYE.get()).build(null));
public static final RegistrySupplier<BlockEntityType<CorridorTeleporterBlockEntity>> CORRIDOR_TELEPORTER = BLOCK_ENTITY_TYPES.register("corridor_teleporter", () -> BlockEntityType.Builder.of(CorridorTeleporterBlockEntity::new, TRBlockRegistry.CORRIDOR_TELEPORTER.get()).build(null));



}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ private static <T extends Block> RegistrySupplier<T> register(String id, Supplie
public static final RegistrySupplier<ConsoleConfigurationBlock> CONSOLE_CONFIGURATION_BLOCK = register("console_configuration", () -> new ConsoleConfigurationBlock(BlockBehaviour.Properties.of().strength(3, 3).sound(SoundType.ANVIL).noOcclusion()), true, true);
public static final RegistrySupplier<AstralManipulatorBlock> ASTRAL_MANIPULATOR_BLOCK = register("astral_manipulator", () -> new AstralManipulatorBlock(BlockBehaviour.Properties.of().strength(3, 3).sound(SoundType.ANVIL).noOcclusion()), true, true);
public static final RegistrySupplier<AntiGravityBlock> GRAVITY_WELL = register("gravity_well", () -> new AntiGravityBlock(BlockBehaviour.Properties.of().strength(3, 3).sound(SoundType.ANVIL).noOcclusion()), true, true);
public static final RegistrySupplier<CorridorTeleporterBlock> CORRIDOR_TELEPORTER = register("corridor_teleporter", () -> new CorridorTeleporterBlock(BlockBehaviour.Properties.of().strength(3, 3).sound(SoundType.ANVIL).noOcclusion()), true, true);




public static final RegistrySupplier<LandingPad> LANDING_PAD = register("landing_pad", () -> new LandingPad(BlockBehaviour.Properties.of().strength(3, 3).sound(SoundType.ANVIL).noOcclusion().lightLevel((x) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ public class TRSoundRegistry {
public static final RegistrySupplier<SoundEvent> LOW_FUEL = setUpSound("low_fuel");
public static final RegistrySupplier<SoundEvent> ARTRON_PILLAR = setUpSound("artron_pillar_active");

public static final RegistrySupplier<SoundEvent> CORRIDOR_TELEPORTER = setUpSound("corridor_teleporter");
public static final RegistrySupplier<SoundEvent> CORRIDOR_TELEPORTER_SUCCESS = setUpSound("corridor_teleporter_success");



// Hums

public static final RegistrySupplier<SoundEvent> HUM_CORAL = setUpSound("hum_coral");
public static final RegistrySupplier<SoundEvent> HUM_CAVE = setUpSound("hum_cave");
public static final RegistrySupplier<SoundEvent> HUM_TOYOTA = setUpSound("hum_toyota");
public static final RegistrySupplier<SoundEvent> HUM_CLASSIC = setUpSound("hum_classic");
public static final RegistrySupplier<SoundEvent> HUM_1996 = setUpSound("hum_1996");


// Hums
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"credit": "Made with Blockbench",
"texture_size": [64, 64],
"textures": {
"1": "tardis_refined:block/corridor_teleporter",
"particle": "tardis_refined:block/corridor_teleporter"
},
"elements": [
{
"from": [2, 0, 2],
"to": [14, 2, 14],
"faces": {
"north": {"uv": [3.25, 2.25, 6.25, 3.25], "texture": "#1"},
"east": {"uv": [0, 6.5, 3, 7.5], "texture": "#1"},
"south": {"uv": [3.25, 2.25, 6.25, 3.25], "texture": "#1"},
"west": {"uv": [0, 6.5, 3, 7.5], "texture": "#1"},
"up": {"uv": [3, 3, 0, 0], "texture": "#1"},
"down": {"uv": [3, 3.25, 0, 6.25], "texture": "#1"}
}
},
{
"from": [4, 1, 4],
"to": [12, 3, 12],
"faces": {
"north": {"uv": [5.5, 1.5, 7.5, 2], "texture": "#1"},
"east": {"uv": [5.5, 1.5, 7.5, 2], "texture": "#1"},
"south": {"uv": [5.5, 1.5, 7.5, 2], "texture": "#1"},
"west": {"uv": [5.5, 1.5, 7.5, 2], "texture": "#1"},
"up": {"uv": [5.25, 2, 3.25, 0], "texture": "#1"},
"down": {"uv": [5.25, 0, 3.25, 2], "texture": "#1"}
}
}
],
"display": {
"thirdperson_righthand": {
"rotation": [75, 45, 0],
"translation": [0, 2.5, 2.75],
"scale": [0.375, 0.375, 0.375]
},
"thirdperson_lefthand": {
"rotation": [75, 45, 0],
"translation": [0, 2.5, 2.75],
"scale": [0.375, 0.375, 0.375]
},
"firstperson_righthand": {
"rotation": [0, 45, 0],
"translation": [0, 3.75, 0],
"scale": [0.4, 0.4, 0.4]
},
"firstperson_lefthand": {
"rotation": [0, 45, 0],
"translation": [0, 3.75, 0],
"scale": [0.4, 0.4, 0.4]
},
"ground": {
"translation": [0, 3, 0],
"scale": [0.75, 0.75, 0.75]
},
"gui": {
"rotation": [30, 225, 0],
"translation": [0, 3.25, 0],
"scale": [0.75, 0.75, 0.75]
},
"head": {
"translation": [0, 14.25, 0]
},
"fixed": {
"translation": [0, 1, 1.25]
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"credit": "Made with Blockbench",
"texture_size": [64, 64],
"textures": {
"1": "tardis_refined:block/corridor_teleporter",
"particle": "console icons"
},
"elements": [
{
"from": [2, 0, 2],
"to": [14, 2, 14],
"faces": {
"north": {"uv": [3.25, 2.25, 6.25, 3.25], "texture": "#1"},
"east": {"uv": [0, 6.5, 3, 7.5], "texture": "#1"},
"south": {"uv": [3.25, 2.25, 6.25, 3.25], "texture": "#1"},
"west": {"uv": [0, 6.5, 3, 7.5], "texture": "#1"},
"up": {"uv": [3, 3, 0, 0], "texture": "#1"},
"down": {"uv": [3, 3.25, 0, 6.25], "texture": "#1"}
}
},
{
"from": [4, 1, 4],
"to": [12, 3, 12],
"faces": {
"north": {"uv": [5.5, 1.5, 7.5, 2], "texture": "#1"},
"east": {"uv": [5.5, 1.5, 7.5, 2], "texture": "#1"},
"south": {"uv": [5.5, 1.5, 7.5, 2], "texture": "#1"},
"west": {"uv": [5.5, 1.5, 7.5, 2], "texture": "#1"},
"up": {"uv": [5.25, 2, 3.25, 0], "texture": "#1"},
"down": {"uv": [5.25, 0, 3.25, 2], "texture": "#1"}
}
}
],
"display": {
"thirdperson_righthand": {
"rotation": [75, 45, 0],
"translation": [0, 2.5, 2.75],
"scale": [0.375, 0.375, 0.375]
},
"thirdperson_lefthand": {
"rotation": [75, 45, 0],
"translation": [0, 2.5, 2.75],
"scale": [0.375, 0.375, 0.375]
},
"firstperson_righthand": {
"rotation": [0, 45, 0],
"translation": [0, 3.75, 0],
"scale": [0.4, 0.4, 0.4]
},
"firstperson_lefthand": {
"rotation": [0, 45, 0],
"translation": [0, 3.75, 0],
"scale": [0.4, 0.4, 0.4]
},
"ground": {
"translation": [0, 3, 0],
"scale": [0.75, 0.75, 0.75]
},
"gui": {
"rotation": [30, 225, 0],
"translation": [0, 3.25, 0],
"scale": [0.75, 0.75, 0.75]
},
"head": {
"translation": [0, 14.25, 0]
},
"fixed": {
"translation": [0, 1, 1.25]
}
}
}
Loading

0 comments on commit d2bde10

Please sign in to comment.