Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.mcreator.simplejumpmod.procedures;
- import net.minecraft.world.phys.Vec3;
- import net.minecraft.world.level.LevelAccessor;
- import net.minecraft.world.level.GameType;
- import net.minecraft.world.entity.player.Player;
- import net.minecraft.world.entity.Entity;
- import net.minecraft.server.level.ServerPlayer;
- import net.minecraft.client.Minecraft;
- import net.minecraft.core.BlockPos;
- import net.minecraft.world.level.block.state.BlockState;
- import net.minecraft.world.phys.AABB;
- import net.minecraft.core.Direction;
- import net.minecraft.world.level.block.state.properties.DirectionProperty;
- import net.minecraft.world.level.block.state.properties.Property;
- import net.mcreator.simplejumpmod.init.SimplejumpmodModBlocks;
- public class GoopyBlockUpdateTickProcedure {
- public static void execute(LevelAccessor world, double x, double y, double z, Entity entity) {
- if (entity == null)
- return;
- if (entity instanceof Player && new Object() {
- public boolean checkGamemode(Entity _ent) {
- if (_ent instanceof ServerPlayer _serverPlayer) {
- return _serverPlayer.gameMode.getGameModeForPlayer() == GameType.SURVIVAL;
- } else if (_ent.level().isClientSide() && _ent instanceof Player _player) {
- return Minecraft.getInstance().getConnection().getPlayerInfo(_player.getGameProfile().getId()) != null && Minecraft.getInstance().getConnection().getPlayerInfo(_player.getGameProfile().getId()).getGameMode() == GameType.SURVIVAL;
- }
- return false;
- }
- }.checkGamemode(entity) && !entity.isShiftKeyDown()) {
- BlockPos blockPos = new BlockPos((int) x, (int) y, (int) z);
- BlockState blockState = world.getBlockState(blockPos);
- if (blockState.getBlock() == SimplejumpmodModBlocks.GOOPY_BLOCK.get()) {
- Direction hitSide = null;
- // Calculate the player's collision box
- AABB playerAABB = entity.getBoundingBox();
- // Calculate the block's collision box
- AABB blockAABB = blockState.getCollisionShape(world, blockPos).bounds();
- // Check for collision with each side
- if (playerAABB.intersects(new AABB(blockPos, blockPos.offset(1, 0, 0)))) {
- hitSide = Direction.WEST;
- } else if (playerAABB.intersects(new AABB(blockPos, blockPos.offset(0, 0, 1)))) {
- hitSide = Direction.NORTH;
- } else if (playerAABB.intersects(new AABB(blockPos.offset(-1, 0, 0), blockPos))) {
- hitSide = Direction.EAST;
- } else if (playerAABB.intersects(new AABB(blockPos.offset(0, 0, -1), blockPos))) {
- hitSide = Direction.SOUTH;
- } else if (playerAABB.intersects(new AABB(blockPos.offset(0, 1, 0), blockPos.offset(1, 1, 1)))) {
- hitSide = Direction.DOWN;
- } else if (playerAABB.intersects(new AABB(blockPos.offset(0, -1, 0), blockPos))) {
- hitSide = Direction.UP;
- }
- if (hitSide != null) {
- double bounceFactor = 0.5D; // Adjust this value as needed
- // Apply a bounce in the direction of the collision
- switch (hitSide) {
- case WEST:
- entity.setDeltaMovement(new Vec3(-bounceFactor, 0.0D, 0.0D));
- break;
- case NORTH:
- entity.setDeltaMovement(new Vec3(0.0D, 0.0D, -bounceFactor));
- break;
- case EAST:
- entity.setDeltaMovement(new Vec3(bounceFactor, 0.0D, 0.0D));
- break;
- case SOUTH:
- entity.setDeltaMovement(new Vec3(0.0D, 0.0D, bounceFactor));
- break;
- case DOWN:
- entity.setDeltaMovement(new Vec3(0.0D, -bounceFactor, 0.0D));
- break;
- case UP:
- entity.setDeltaMovement(new Vec3(0.0D, bounceFactor, 0.0D));
- break;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement