Created
March 9, 2021 08:40
-
-
Save TheOnlyTails/070fe3b00c365ffcae8b352ef255486f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.crypticcosmos.crypticcosmos.blocks; | |
import com.crypticcosmos.crypticcosmos.registries.CrypticCosmosDimensions; | |
import net.minecraft.block.Block; | |
import net.minecraft.block.BlockState; | |
import net.minecraft.block.SoundType; | |
import net.minecraft.block.material.Material; | |
import net.minecraft.entity.Entity; | |
import net.minecraft.entity.player.PlayerEntity; | |
import net.minecraft.util.RegistryKey; | |
import net.minecraft.util.math.BlockPos; | |
import net.minecraft.world.World; | |
import net.minecraft.world.gen.Heightmap; | |
import net.minecraft.world.server.ServerWorld; | |
import net.minecraftforge.common.util.ITeleporter; | |
import javax.annotation.Nonnull; | |
import java.util.concurrent.ThreadLocalRandom; | |
import java.util.function.Function; | |
public class RiftBlock extends Block { | |
public RiftBlock() { | |
super(Properties.create(Material.ROCK) | |
.hardnessAndResistance(40f, 1200f) | |
.sound(SoundType.STONE) | |
.doesNotBlockMovement() | |
.noDrops() | |
); | |
} | |
@SuppressWarnings("deprecation") | |
@Override | |
public void onEntityCollision(@Nonnull BlockState state, @Nonnull World worldIn, @Nonnull BlockPos pos, Entity entity) { | |
if (!entity.isAlive() || entity.world.isRemote) return; | |
if (entity.isPassenger() || entity.isBeingRidden() || !entity.isNonBoss()) return; | |
if (entity.getPortalCooldown() > 0) return; | |
if (!(entity instanceof PlayerEntity)) { | |
return; | |
} | |
// update the portal cooldown of the entity | |
entity.func_242279_ag(); | |
// noinspection ConstantConditions | |
ServerWorld destination = worldIn.getServer().getWorld(getDestination()); | |
//noinspection ConstantConditions | |
entity.changeDimension(destination, new ITeleporter() { | |
@Override | |
public Entity placeEntity(Entity entity, ServerWorld currentWorld, ServerWorld destWorld, float yaw, Function<Boolean, Entity> repositionEntity) { | |
Entity repositionedEntity = repositionEntity.apply(false); | |
repositionedEntity.setPositionAndUpdate(pos.getX(), | |
destWorld.getHeight(Heightmap.Type.MOTION_BLOCKING, pos).getY(), | |
pos.getZ()); | |
return repositionedEntity; | |
} | |
}); | |
} | |
private static RegistryKey<World> getDestination() { | |
return CrypticCosmosDimensions.DIMENSIONS.get(ThreadLocalRandom.current().nextInt(CrypticCosmosDimensions.DIMENSIONS.size())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment