Portal block
This commit is contained in:
parent
439e96a526
commit
59a0d0df6c
18 changed files with 765 additions and 1 deletions
70
src/main/java/ru/betterend/blocks/EndPortalBlock.java
Normal file
70
src/main/java/ru/betterend/blocks/EndPortalBlock.java
Normal file
|
@ -0,0 +1,70 @@
|
|||
package ru.betterend.blocks;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.NetherPortalBlock;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import ru.betterend.client.ERenderLayer;
|
||||
import ru.betterend.client.IRenderTypeable;
|
||||
import ru.betterend.registry.ParticleRegistry;
|
||||
|
||||
public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable {
|
||||
|
||||
public EndPortalBlock() {
|
||||
super(FabricBlockSettings.copyOf(Blocks.NETHER_PORTAL));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
|
||||
if (random.nextInt(100) == 0) {
|
||||
world.playSound(pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, SoundEvents.BLOCK_PORTAL_AMBIENT, SoundCategory.BLOCKS, 0.5F, random.nextFloat() * 0.4F + 0.8F, false);
|
||||
}
|
||||
|
||||
double x = pos.getX() + random.nextDouble();
|
||||
double y = pos.getY() + random.nextDouble();
|
||||
double z = pos.getZ() + random.nextDouble();
|
||||
double vx = (random.nextDouble() - 0.5D) * 0.5D;
|
||||
double vy = (random.nextDouble() - 0.5D) * 0.5D;
|
||||
double vz = (random.nextDouble() - 0.5D) * 0.5D;
|
||||
int k = random.nextInt(2) * 2 - 1;
|
||||
if (!world.getBlockState(pos.west()).isOf(this) && !world.getBlockState(pos.east()).isOf(this)) {
|
||||
x = pos.getX() + 0.5D + 0.25D * k;
|
||||
vx = (random.nextDouble() * 2.0D * k);
|
||||
} else {
|
||||
z = pos.getZ() + 0.5D + 0.25D * k;
|
||||
vz = (random.nextDouble() * 2.0D * k);
|
||||
}
|
||||
|
||||
world.addParticle(ParticleRegistry.PORTAL_SPHERE, x, y, z, vx, vy, vz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {}
|
||||
|
||||
@Override
|
||||
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, WorldAccess world, BlockPos pos, BlockPos posFrom) {
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ERenderLayer getRenderLayer() {
|
||||
return ERenderLayer.TRANSLUCENT;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue