Skip to content

Commit

Permalink
FUCK, CHANGES EVERYWHERE. Oh and, added biomes in level 0 (experimental)
Browse files Browse the repository at this point in the history
  • Loading branch information
northernlimit committed Aug 29, 2024
1 parent 72b9db2 commit a2a5644
Show file tree
Hide file tree
Showing 32 changed files with 734 additions and 31 deletions.
14 changes: 8 additions & 6 deletions src/main/java/net/limit/cubliminal/Cubliminal.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.entity.event.v1.ServerEntityWorldChangeEvents;
import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry;
import net.limit.cubliminal.config.CubliminalConfig;
import net.limit.cubliminal.entity.custom.BacteriaEntity;
import net.limit.cubliminal.event.PlayerTickHandler;
import net.limit.cubliminal.event.ServerTickHandler;
import net.limit.cubliminal.event.command.NoClipCommand;
import net.limit.cubliminal.init.*;
import net.limit.cubliminal.util.NoClipEngine;
import net.limit.cubliminal.util.SanityData;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -30,6 +30,8 @@ public static Identifier id(String id) {

public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

public static ServerWorld LVL_0;

@Override
public void onInitialize() {
AutoConfig.register(CubliminalConfig.class, GsonConfigSerializer::new);
Expand All @@ -44,10 +46,10 @@ public void onInitialize() {
FabricDefaultAttributeRegistry.register(CubliminalEntities.BACTERIA, BacteriaEntity.createBacteriaAttributes());
CubliminalBlockEntities.init();
CubliminalPackets.registerC2SPackets();
ServerTickEvents.START_SERVER_TICK.register(new PlayerTickHandler());
ServerPlayConnectionEvents.JOIN.register(NoClipEngine::onPlayerJoin);
ServerTickEvents.START_SERVER_TICK.register(new ServerTickHandler());
ServerPlayerEvents.AFTER_RESPAWN.register(SanityData::resetAfterDeath);
ServerEntityWorldChangeEvents.AFTER_PLAYER_CHANGE_WORLD.register(PlayerTickHandler::afterWorldChange);
ServerEntityWorldChangeEvents.AFTER_PLAYER_CHANGE_WORLD.register(ServerTickHandler::afterWorldChange);
CommandRegistrationCallback.EVENT.register(NoClipCommand::register);
ServerLifecycleEvents.SERVER_STARTED.register(server -> LVL_0 = server.getWorld(CubliminalWorlds.THE_LOBBY_KEY));
}
}
3 changes: 3 additions & 0 deletions src/main/java/net/limit/cubliminal/CubliminalClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.limit.cubliminal.client.hud.SanityBarHudOverlay;
import net.limit.cubliminal.entity.client.BacteriaModel;
import net.limit.cubliminal.entity.client.BacteriaRenderer;
import net.limit.cubliminal.entity.client.SeatRenderer;
import net.limit.cubliminal.event.KeyInputHandler;
import net.limit.cubliminal.init.CubliminalBlocks;
import net.limit.cubliminal.init.CubliminalEntities;
Expand All @@ -31,6 +32,8 @@ public void onInitializeClient() {
.register(CubliminalEntities.BACTERIA, BacteriaRenderer::new);
EntityModelLayerRegistry
.registerModelLayer(CubliminalModelLayers.BACTERIA, BacteriaModel::getTexturedModelData);
EntityRendererRegistry
.register(CubliminalEntities.SEAT_ENTITY, SeatRenderer::new);

CubliminalPackets.registerS2CPackets();
HudRenderCallback.EVENT.register(new NoClippingHudOverlay());
Expand Down
99 changes: 99 additions & 0 deletions src/main/java/net/limit/cubliminal/block/custom/ChairBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package net.limit.cubliminal.block.custom;

import net.minecraft.block.*;
import net.minecraft.entity.Entity;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.BlockMirror;
import net.minecraft.util.BlockRotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import org.jetbrains.annotations.Nullable;

public class ChairBlock extends SeatBlock implements Waterloggable {
public static final DirectionProperty FACING = HorizontalFacingBlock.FACING;
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;

protected static final VoxelShape EAST_SHAPE = VoxelShapes.union(
Block.createCuboidShape(0, 11, 0, 2, 27, 16),
Block.createCuboidShape(0, 0, 14, 2, 11, 16),
Block.createCuboidShape(0, 0, 0, 2, 11, 2),
Block.createCuboidShape(14, 0, 0, 16, 9, 2),
Block.createCuboidShape(14, 0, 14, 16, 9, 16),
Block.createCuboidShape(2, 9, 0, 16, 11, 16));
protected static final VoxelShape WEST_SHAPE = VoxelShapes.union(
Block.createCuboidShape(14, 11, 0, 16, 27, 16),
Block.createCuboidShape(14, 0, 0, 16, 11, 2),
Block.createCuboidShape(14, 0, 14, 16, 11, 16),
Block.createCuboidShape(0, 0, 14, 2, 9, 16),
Block.createCuboidShape(0, 0, 0, 2, 9, 2),
Block.createCuboidShape(0, 9, 0, 14, 11, 16));
protected static final VoxelShape SOUTH_SHAPE = VoxelShapes.union(
Block.createCuboidShape(0, 11, 0, 16, 27, 2),
Block.createCuboidShape(0, 0, 0, 2, 11, 2),
Block.createCuboidShape(14, 0, 0, 16, 11, 2),
Block.createCuboidShape(14, 0, 14, 16, 9, 16),
Block.createCuboidShape(0, 0, 14, 2, 9, 16),
Block.createCuboidShape(0, 9, 2, 16, 11, 16));
protected static final VoxelShape NORTH_SHAPE = VoxelShapes.union(
Block.createCuboidShape(0, 11, 14, 16, 27, 16),
Block.createCuboidShape(14, 0, 14, 16, 11, 16),
Block.createCuboidShape(0, 0, 14, 2, 11, 16),
Block.createCuboidShape(0, 0, 0, 2, 9, 2),
Block.createCuboidShape(14, 0, 0, 16, 9, 2),
Block.createCuboidShape(0, 9, 0, 16, 11, 14));

public ChairBlock(Settings settings) {
super(settings);
this.setDefaultState(this.getDefaultState().with(FACING, Direction.NORTH).with(WATERLOGGED, false));
}

@Override
public float setPassengerYaw(BlockState state, Entity entity) {
return state.get(FACING).asRotation();
}

@Override
public float seatHeight(BlockState state) {
return 0.7f;
}

@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(FACING, WATERLOGGED);
}

@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return switch (state.get(FACING)) {
case SOUTH -> SOUTH_SHAPE;
case WEST -> WEST_SHAPE;
case EAST -> EAST_SHAPE;
default -> NORTH_SHAPE;
};
}

@Override
public BlockState rotate(BlockState state, BlockRotation rotation) {
return state.with(FACING, rotation.rotate(state.get(FACING)));
}

@Override
public BlockState mirror(BlockState state, BlockMirror mirror) {
return state.rotate(mirror.getRotation(state.get(FACING)));
}

@Nullable
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return this.getDefaultState().with(FACING, ctx.getHorizontalPlayerFacing().getOpposite())
.with(WATERLOGGED, ctx.getWorld().getFluidState(ctx.getBlockPos()).getFluid() == Fluids.WATER);
}
}
52 changes: 52 additions & 0 deletions src/main/java/net/limit/cubliminal/block/custom/SeatBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package net.limit.cubliminal.block.custom;

import com.google.common.base.Predicates;
import net.limit.cubliminal.entity.custom.SeatEntity;
import net.limit.cubliminal.init.CubliminalEntities;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.SpawnReason;
import net.minecraft.entity.ai.pathing.NavigationType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;

import java.util.List;

public class SeatBlock extends Block {
public SeatBlock(Settings settings) {
super(settings);
}

public float setPassengerYaw(BlockState state, Entity entity) {
return entity.getYaw();
}

public float seatHeight(BlockState state) {
return 1;
}

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
List<SeatEntity> list = world.getEntitiesByClass(SeatEntity.class, new Box(pos), Predicates.alwaysTrue());
if (world.isClient()) {
return ActionResult.CONSUME;
} else if (list.isEmpty()) {
SeatEntity seatEntity = CubliminalEntities.SEAT_ENTITY.spawn((ServerWorld) world, pos, SpawnReason.TRIGGERED);
player.startRiding(seatEntity, true);
}
return ActionResult.SUCCESS;
}

@Override
public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ protected void appendProperties(StateManager.Builder<Block, BlockState> builder)
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return switch (state.get(FACING)) {
default -> NORTH_SHAPE;
case SOUTH -> SOUTH_SHAPE;
case WEST -> WEST_SHAPE;
case EAST -> EAST_SHAPE;
default -> NORTH_SHAPE;
};
}
@Override
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/net/limit/cubliminal/entity/client/SeatRenderer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package net.limit.cubliminal.entity.client;

import net.limit.cubliminal.entity.custom.SeatEntity;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.util.Identifier;

public class SeatRenderer extends EntityRenderer<SeatEntity> {
public SeatRenderer(EntityRendererFactory.Context ctx) {
super(ctx);
}

@Override
public Identifier getTexture(SeatEntity entity) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class BacteriaEntity extends HostileEntity {
private int idleAnimationTimeout = 0;
public final AnimationState attackAnimationState = new AnimationState();
public int attackAnimationTimeout = 0;
public BacteriaEntity(EntityType<? extends HostileEntity> entityType, World world) {
public BacteriaEntity(EntityType<? extends BacteriaEntity> entityType, World world) {
super(entityType, world);
this.setStepHeight(3f);
((MobNavigation)this.getNavigation()).setCanPathThroughDoors(true);
Expand Down
89 changes: 89 additions & 0 deletions src/main/java/net/limit/cubliminal/entity/custom/SeatEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package net.limit.cubliminal.entity.custom;

import com.google.common.base.Predicates;
import com.google.common.collect.Lists;
import net.limit.cubliminal.block.custom.SeatBlock;
import net.minecraft.block.BlockState;
import net.minecraft.entity.*;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;

import java.util.List;
import java.util.function.Predicate;

public class SeatEntity extends Entity {

public SeatEntity(EntityType<? extends SeatEntity> type, World world) {
super(type, world);
}

@Override
public void tick() {
if (this.getWorld().isClient()) return;
if (!(this.getBlockStateAtPos().getBlock() instanceof SeatBlock)
|| !this.getWorld().getEntitiesByClass(SeatEntity.class, new Box(this.getBlockPos())
, Predicate.not(Predicates.alwaysTrue())).isEmpty()
|| this.getPassengerList().isEmpty()) this.discard();
if (this.isSubmergedInWater()) this.removeAllPassengers();
}

@Override
public Vec3d updatePassengerForDismount(LivingEntity passenger) {
Vec3d vec3d = this.getBlockPos().toCenterPos();
double offset = 0;
for (EntityPose entityPose : passenger.getPoses()) {
passenger.setPose(entityPose);
BlockState state = this.getBlockStateAtPos();
if (state.getBlock() instanceof SeatBlock seatBlock) offset = seatBlock.seatHeight(state);
}

return vec3d.add(0, offset - 0.5, 0);
}

@Override
public Vec3d getPassengerRidingPos(Entity passenger) {
BlockPos pos = this.getBlockPos();
BlockState state = this.getBlockStateAtPos();
double seatHeight = 0;
if (state.getBlock() instanceof SeatBlock seatBlock) seatHeight = seatBlock.seatHeight(state);
return pos.toCenterPos().add(0, seatHeight - 0.5, 0);
}

@Override
public boolean canAddPassenger(Entity passenger) {
return this.getPassengerList().isEmpty();
}

@Override
public boolean isInvulnerable() {
return true;
}

@Override
protected void addPassenger(Entity passenger) {
BlockState state = this.getBlockStateAtPos();
if (state.getBlock() instanceof SeatBlock seatBlock) passenger.setYaw(seatBlock.setPassengerYaw(state, passenger));
super.addPassenger(passenger);
}

@Override
protected boolean canStartRiding(Entity entity) {
return true;
}

@Override
protected void initDataTracker() {
}

@Override
protected void readCustomDataFromNbt(NbtCompound nbt) {
}

@Override
protected void writeCustomDataToNbt(NbtCompound nbt) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import net.minecraft.world.World;


public class PlayerTickHandler implements ServerTickEvents.StartTick {
public class ServerTickHandler implements ServerTickEvents.StartTick {
public static boolean isVulnerable(ServerPlayerEntity player) {
return !player.isCreative() && !player.isSpectator();
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/net/limit/cubliminal/init/CubliminalBiomes.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,36 @@

import com.mojang.serialization.Codec;
import net.limit.cubliminal.Cubliminal;
import net.limit.cubliminal.world.biome.level_0.LevelZeroBiomeSource;
import net.limit.cubliminal.world.chunk.LevelZeroChunkGenerator;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.source.BiomeSource;
import net.minecraft.world.gen.chunk.ChunkGenerator;

public class CubliminalBiomes {
public static final RegistryKey<Biome> THE_LOBBY_BIOME = RegistryKey
.of(RegistryKeys.BIOME, Cubliminal.id(CubliminalWorlds.THE_LOBBY));

public static final RegistryKey<Biome> PILLAR_BIOME = RegistryKey
.of(RegistryKeys.BIOME, Cubliminal.id("pillar_biome"));

public static final RegistryKey<Biome> REDROOMS_BIOME = RegistryKey
.of(RegistryKeys.BIOME, Cubliminal.id("redrooms"));

public static void init() {
getChunkGenerator("the_lobby_chunk_generator", LevelZeroChunkGenerator.CODEC);
getBiomeSource("the_lobby_biome_source", LevelZeroBiomeSource.CODEC);
}

public static <C extends ChunkGenerator, D extends Codec<C>> D getChunkGenerator(String id, D chunkGeneratorCodec) {
return Registry.register(Registries.CHUNK_GENERATOR, Cubliminal.id(id), chunkGeneratorCodec);
}
public static <C extends BiomeSource, D extends Codec<C>> D getBiomeSource(String id, D biomeSourceCodec) {
return Registry.register(Registries.BIOME_SOURCE, Cubliminal.id(id), biomeSourceCodec);
}

}
Loading

0 comments on commit a2a5644

Please sign in to comment.