Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/client/java/com/example/moonarg/client/MoonArgClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.moonarg.client;

import com.example.moonarg.client.moon.MoonStareClient;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;

public final class MoonArgClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
ClientTickEvents.END_CLIENT_TICK.register(MoonStareClient::onClientTick);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.example.moonarg.client.moon;

import com.example.moonarg.MoonArgMod;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.RaycastContext;

public final class MoonStareClient {
private static final int MAX_PACKET_INTERVAL = 5;
private static int stareTicks = 0;
private static int packetCooldown = 0;

private MoonStareClient() {
}

public static void onClientTick(MinecraftClient client) {
ClientPlayerEntity player = client.player;
ClientWorld world = client.world;
if (player == null || world == null) {
return;
}

boolean staring = isPlayerStaringAtMoon(player, world);
if (staring) {
stareTicks++;
} else if (stareTicks > 0) {
stareTicks = Math.max(0, stareTicks - 2);
}

if (packetCooldown <= 0) {
packetCooldown = MAX_PACKET_INTERVAL;
PacketByteBuf buf = PacketByteBufs.create();
buf.writeBoolean(staring);
ClientPlayNetworking.send(MoonArgMod.MOON_STARE_PACKET, buf);
} else {
packetCooldown--;
}
}

public static int getStareTicks() {
return stareTicks;
}

private static boolean isPlayerStaringAtMoon(ClientPlayerEntity player, ClientWorld world) {
float skyAngle = world.getSkyAngle(1.0F);
float angleDegrees = skyAngle * 360.0F;
float pitch = 90.0F - angleDegrees;
Vec3d sunDirection = Vec3d.fromPolar(pitch, 0.0F);
Vec3d moonDirection = sunDirection.multiply(-1.0D).normalize();
Vec3d look = player.getRotationVec(1.0F).normalize();
double dot = look.dotProduct(moonDirection);
if (dot < 0.985D) {
return false;
}

Vec3d eyePos = player.getCameraPosVec(1.0F);
Vec3d target = eyePos.add(look.multiply(256.0D));
HitResult hit = world.raycast(new RaycastContext(eyePos, target, RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.NONE, player));
return hit.getType() == HitResult.Type.MISS;
}
}
14 changes: 0 additions & 14 deletions src/client/resources/modid.client.mixins.json

This file was deleted.

31 changes: 31 additions & 0 deletions src/main/java/com/example/moonarg/MoonArgMod.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.moonarg;

import com.example.moonarg.registry.MoonArgBlocks;
import com.example.moonarg.registry.MoonArgEntities;
import com.example.moonarg.registry.MoonArgFluids;
import com.example.moonarg.registry.MoonArgItems;
import com.example.moonarg.world.BloodMoonManager;
import com.example.moonarg.world.MoonPortalEvents;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class MoonArgMod implements ModInitializer {
public static final String MOD_ID = "moonarg";
public static final Logger LOGGER = LoggerFactory.getLogger(MoonArgMod.class);
public static final Identifier MOON_STARE_PACKET = new Identifier(MOD_ID, "moon_stare");

@Override
public void onInitialize() {
MoonArgFluids.register();
MoonArgBlocks.register();
MoonArgItems.register();
MoonArgEntities.register();
BloodMoonManager.init();
MoonPortalEvents.init();
ServerPlayNetworking.registerGlobalReceiver(MOON_STARE_PACKET, BloodMoonManager::handleMoonStarePacket);
LOGGER.info("Moon ARG initialized.");
}
}
93 changes: 93 additions & 0 deletions src/main/java/com/example/moonarg/entity/GlitchEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package com.example.moonarg.entity;

import com.example.moonarg.registry.MoonArgBlocks;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.EntityData;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnReason;
import net.minecraft.entity.ai.goal.WanderAroundFarGoal;
import net.minecraft.entity.attribute.DefaultAttributeContainer;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.mob.HostileEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.LocalDifficulty;
import net.minecraft.world.ServerWorldAccess;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class GlitchEntity extends HostileEntity {
private static final int DEFORM_RADIUS = 8;
private static final List<Block> RANDOM_BLOCKS = List.of(
Blocks.STONE,
Blocks.COBBLESTONE,
Blocks.ANDESITE,
Blocks.DIORITE,
Blocks.GRAVEL,
Blocks.DIRT,
Blocks.SAND,
Blocks.NETHERRACK,
Blocks.END_STONE
);

public GlitchEntity(EntityType<? extends HostileEntity> entityType, World world) {
super(entityType, world);
}

public static DefaultAttributeContainer.Builder createGlitchAttributes() {
return HostileEntity.createHostileAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, 30.0D)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.25D)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 32.0D);
}

@Override
protected void initGoals() {
this.goalSelector.add(5, new WanderAroundFarGoal(this, 0.5D));
}

@Override
public EntityData initialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason,
@Nullable EntityData entityData, @Nullable NbtCompound entityNbt) {
EntityData data = super.initialize(world, difficulty, spawnReason, entityData, entityNbt);
deformArea();
return data;
}

@Override
public void remove(RemovalReason reason) {
if (!this.getWorld().isClient && reason != RemovalReason.CHANGED_DIMENSION) {
deformArea();
}
super.remove(reason);
}

private void deformArea() {
if (!(this.getWorld() instanceof ServerWorld serverWorld)) {
return;
}
BlockPos origin = this.getBlockPos();
int radiusSq = DEFORM_RADIUS * DEFORM_RADIUS;
for (BlockPos pos : BlockPos.iterateOutwards(origin, DEFORM_RADIUS, DEFORM_RADIUS, DEFORM_RADIUS)) {
if (pos.getSquaredDistance(origin) > radiusSq) {
continue;
}
BlockState state = serverWorld.getBlockState(pos);
if (state.isAir()) {
continue;
}
if (!state.getFluidState().isEmpty()) {
serverWorld.setBlockState(pos, MoonArgBlocks.BLOOD_FLUID_BLOCK.getDefaultState(), Block.NOTIFY_ALL);
continue;
}
Block block = RANDOM_BLOCKS.get(serverWorld.random.nextInt(RANDOM_BLOCKS.size()));
serverWorld.setBlockState(pos, block.getDefaultState(), Block.NOTIFY_ALL);
}
}
}
95 changes: 95 additions & 0 deletions src/main/java/com/example/moonarg/entity/MoonmanEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.example.moonarg.entity;

import com.example.moonarg.world.MoonArgDimensions;
import net.minecraft.entity.EntityData;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnReason;
import net.minecraft.entity.ai.goal.ActiveTargetGoal;
import net.minecraft.entity.ai.goal.LookAtEntityGoal;
import net.minecraft.entity.ai.goal.MeleeAttackGoal;
import net.minecraft.entity.ai.goal.WanderAroundFarGoal;
import net.minecraft.entity.attribute.DefaultAttributeContainer;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.mob.HostileEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.LocalDifficulty;
import net.minecraft.world.ServerWorldAccess;
import org.jetbrains.annotations.Nullable;

public class MoonmanEntity extends HostileEntity {
private static final double OBSERVE_DOT_THRESHOLD = 0.75D;

public MoonmanEntity(EntityType<? extends HostileEntity> entityType, net.minecraft.world.World world) {
super(entityType, world);
}

public static DefaultAttributeContainer.Builder createMoonmanAttributes() {
return HostileEntity.createHostileAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, 40.0D)
.add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 7.0D)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.32D)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 32.0D);
}

@Override
protected void initGoals() {
this.goalSelector.add(2, new MeleeAttackGoal(this, 1.1D, true));
this.goalSelector.add(5, new WanderAroundFarGoal(this, 0.8D));
this.goalSelector.add(6, new LookAtEntityGoal(this, PlayerEntity.class, 12.0F));
this.targetSelector.add(2, new ActiveTargetGoal<>(this, PlayerEntity.class, true));
}

@Override
public void tickMovement() {
if (!this.getWorld().isClient && isObservedByPlayer()) {
this.getNavigation().stop();
this.setVelocity(Vec3d.ZERO);
this.velocityDirty = true;
return;
}
super.tickMovement();
}

@Override
public void onPlayerCollision(PlayerEntity player) {
if (this.getWorld().isClient) {
return;
}
if (player instanceof ServerPlayerEntity serverPlayer) {
ServerWorld moonWorld = MoonArgDimensions.getMoonWorld(serverPlayer.getServer());
if (moonWorld != null) {
Vec3d spawn = MoonArgDimensions.getSafeSpawnPos(moonWorld);
serverPlayer.teleport(moonWorld, spawn.x, spawn.y, spawn.z, serverPlayer.getYaw(), serverPlayer.getPitch());
}
}
}

@Override
public EntityData initialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason,
@Nullable EntityData entityData, @Nullable NbtCompound entityNbt) {
EntityData data = super.initialize(world, difficulty, spawnReason, entityData, entityNbt);
world.playSound(null, this.getBlockPos(), SoundEvents.ENTITY_ENDERMAN_SCREAM, SoundCategory.HOSTILE, 1.0F, 0.55F);
return data;
}

private boolean isObservedByPlayer() {
for (PlayerEntity player : this.getWorld().getPlayers()) {
if (!player.canSee(this)) {
continue;
}
Vec3d toEntity = this.getPos().add(0.0D, this.getStandingEyeHeight() * 0.5D, 0.0D).subtract(player.getEyePos()).normalize();
Vec3d look = player.getRotationVec(1.0F).normalize();
double dot = look.dotProduct(toEntity);
if (dot > OBSERVE_DOT_THRESHOLD && player.squaredDistanceTo(this) < 48.0D * 48.0D) {
return true;
}
}
return false;
}
}
65 changes: 65 additions & 0 deletions src/main/java/com/example/moonarg/entity/StalkerEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.example.moonarg.entity;

import com.example.moonarg.registry.MoonArgEntities;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ai.goal.LookAtEntityGoal;
import net.minecraft.entity.ai.goal.WanderAroundFarGoal;
import net.minecraft.entity.attribute.DefaultAttributeContainer;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.mob.HostileEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.Heightmap;
import net.minecraft.world.World;

public class StalkerEntity extends HostileEntity {
private static final int DESPAWN_DISTANCE = 20;

public StalkerEntity(EntityType<? extends HostileEntity> entityType, World world) {
super(entityType, world);
}

public static DefaultAttributeContainer.Builder createStalkerAttributes() {
return HostileEntity.createHostileAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, 20.0D)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.35D)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 48.0D);
}

public static boolean trySpawnAtEdge(ServerWorld world, ServerPlayerEntity player) {
int viewDistanceChunks = world.getServer().getPlayerManager().getViewDistance();
double radius = Math.max(48.0D, viewDistanceChunks * 16.0D - 8.0D);
float angle = world.getRandom().nextFloat() * MathHelper.TAU;
Vec3d offset = new Vec3d(MathHelper.cos(angle), 0.0D, MathHelper.sin(angle)).multiply(radius);
BlockPos base = BlockPos.ofFloored(player.getPos().add(offset));
int y = world.getTopY(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, base.getX(), base.getZ());
BlockPos spawnPos = new BlockPos(base.getX(), y, base.getZ());
StalkerEntity stalker = MoonArgEntities.STALKER.create(world);
if (stalker == null) {
return false;
}
stalker.refreshPositionAndAngles(spawnPos, player.getYaw() + 180.0F, 0.0F);
return world.spawnEntity(stalker);
}

@Override
protected void initGoals() {
this.goalSelector.add(4, new WanderAroundFarGoal(this, 0.6D));
this.goalSelector.add(5, new LookAtEntityGoal(this, PlayerEntity.class, 16.0F));
}

@Override
public void tick() {
super.tick();
if (!this.getWorld().isClient) {
PlayerEntity player = this.getWorld().getClosestPlayer(this, DESPAWN_DISTANCE);
if (player != null) {
this.discard();
}
}
}
}
Loading
Loading