Skip to content

Commit

Permalink
Merge pull request #300 from AlphaMode/1.19.2
Browse files Browse the repository at this point in the history
1.19.2 port
  • Loading branch information
Rubydesic authored Feb 27, 2023
2 parents 42069e8 + ce123cc commit 080e37b
Show file tree
Hide file tree
Showing 121 changed files with 3,350 additions and 787 deletions.
366 changes: 165 additions & 201 deletions LICENSE

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ independent code lives in [vs-core](https://github.com/ValkyrienSkies/vs-core).
## Troubleshooting

### Running Forge in dev environment
Occasionally forge will break will strange ways. When this occurs, delete all the `build` folders, delete the `.gradle` folder of the `forge` project, and then refresh gradle.
Occasionally forge will break in strange ways. When this occurs, delete all the `build` folders, delete the `.gradle` folder of the `forge` project, and then refresh gradle.
17 changes: 13 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ buildscript {

plugins {
// Needed for Forge+Fabric
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "0.12.0-SNAPSHOT" apply false
id 'io.github.juuxel.loom-quiltflower' version '1.7.1' apply false
id "architectury-plugin" version "3.4.143"
id "dev.architectury.loom" version "1.0.306" apply false
id 'io.github.juuxel.loom-quiltflower' version '1.8.0' apply false
// Kotlin
id "org.jetbrains.kotlin.jvm" version "1.7.10" apply false
// Kotlin linter
Expand Down Expand Up @@ -73,7 +73,7 @@ subprojects {
url = "https://maven.parchmentmc.org"
}
maven { url = "https://cursemaven.com" }
maven { url = "https://maven.terraformersmc.com/releases/" }
maven { url = "https://maven.terraformersmc.com/releases/" } // Mod Menu
maven {
name = 'Kotlin for Forge'
url = 'https://thedarkcolour.github.io/KotlinForForge/'
Expand All @@ -82,6 +82,13 @@ subprojects {
name = 'tterrag maven'
url = 'https://maven.tterrag.com/'
}
maven { url = "https://api.modrinth.com/maven" } // LazyDFU, Suggestion Tweaker
maven { url = "https://maven.shedaniel.me/" } // Cloth Config, REI
maven { url = "https://mvn.devos.one/snapshots/" } // Fabric Create, Porting Lib, Forge Tags, Milk Lib
maven { url = "https://raw.githubusercontent.com/Fuzss/modresources/main/maven/" } // Forge Config API Port
maven { url = "https://maven.tterrag.com/" } // Registrate, Forge Create and Flywheel
maven { url = "https://maven.cafeteria.dev/releases" } // Fake Player API
maven { url = "https://maven.jamieswhiteshirt.com/libs-release" } // Reach Entity Attributes
}
}

Expand All @@ -99,6 +106,8 @@ subprojects {
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}"
// The following line declares the mojmap mappings, you may use other mappings as well
mappings loom.officialMojangMappings()

compileOnly("com.google.code.findbugs:jsr305:3.0.2")
}

// configure checkstyle
Expand Down
14 changes: 14 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ dependencies {
exclude module: "netty-buffer"
exclude module: "fastutil"
}

// FTB Stuffs
modCompileOnly("curse.maven:ftb-util-404465:4210935")
modCompileOnly("curse.maven:ftb-teams-404468:4229138")
modCompileOnly("curse.maven:ftb-chunks-314906:4229120")

//Common create compat,
//We just use a version from a platform and hope the classes exist on both versions and mixins apply correctly
modCompileOnly("com.jozufozu.flywheel:flywheel-fabric-${minecraft_version}:0.6.8.a-4")
}

architectury {
Expand All @@ -25,6 +34,11 @@ loom {
accessWidenerPath = file("src/main/resources/valkyrienskies-common.accesswidener")
}

tasks.withType(JavaCompile).configureEach {
// Minecraft 1.18 (1.18-pre2) upwards uses Java 17.
it.options.release = 17
}

jar {
// Exclude dummy Optifine classes
exclude "net/optifine/**"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
package org.valkyrienskies.mod.event;

import java.util.ArrayList;
import java.util.List;
import kotlin.Unit;
import net.minecraft.core.RegistryAccess;
import org.valkyrienskies.mod.common.hooks.VSGameEvents;

public class RegistryEvents {

private static List<Runnable> onTagsLoaded = new ArrayList<>();
private static List<Runnable> onRegistriesComplete = new ArrayList<>();

// this can be beter...
/**
* @deprecated Use VSGameEvents
*/
@Deprecated(forRemoval = true)
public static void onTagsLoaded(final Runnable event) {
onTagsLoaded.add(event);
VSGameEvents.INSTANCE.getTagsAreLoaded().on(x -> event.run());
}

/**
* @deprecated Use VSGameEvents
*/
@Deprecated(forRemoval = true)
public static void tagsAreLoaded(final RegistryAccess registries, final boolean client) {
onTagsLoaded.forEach(Runnable::run);
VSGameEvents.INSTANCE.getTagsAreLoaded().emit(Unit.INSTANCE);
}

/**
* @deprecated Use VSGameEvents
*/
@Deprecated(forRemoval = true)
public static void onRegistriesComplete(final Runnable event) {
onRegistriesComplete.add(event);
VSGameEvents.INSTANCE.getRegistriesCompleted().on(x -> event.run());
}

/**
* @deprecated Use VSGameEvents
*/
@Deprecated(forRemoval = true)
public static void registriesAreComplete() {
onRegistriesComplete.forEach(Runnable::run);
VSGameEvents.INSTANCE.getRegistriesCompleted().emit(Unit.INSTANCE);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.valkyrienskies.mod.mixin.accessors.entity;

import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
Expand All @@ -11,4 +13,13 @@ public interface EntityAccessor {
@Accessor("position")
void setPosNoUpdates(Vec3 pos);

@Accessor("blockPosition")
void setBlockPosition(BlockPos blockPosition);

@Accessor("blockPosition")
BlockPos getBlockPosition();

@Accessor("feetBlockState")
void setFeetBlockState(BlockState feetBlockState);

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.ClipContext.Block;
import net.minecraft.world.level.ClipContext.Fluid;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.HitResult.Type;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import org.joml.Quaterniond;
import org.joml.Quaterniondc;
Expand All @@ -20,6 +27,7 @@
import org.valkyrienskies.core.api.ships.properties.ShipTransform;
import org.valkyrienskies.mod.client.IVSCamera;
import org.valkyrienskies.mod.common.util.VectorConversionsMCKt;
import org.valkyrienskies.mod.common.world.RaycastUtilsKt;

@Mixin(Camera.class)
public abstract class MixinCamera implements IVSCamera {
Expand Down Expand Up @@ -52,6 +60,8 @@ public abstract class MixinCamera implements IVSCamera {
private float eyeHeight;
@Shadow
private float eyeHeightOld;
@Shadow
private Vec3 position;

@Shadow
protected abstract double getMaxZoom(double startingDistance);
Expand Down Expand Up @@ -92,7 +102,12 @@ public void setupWithShipMounted(final @NotNull BlockGetter level, final @NotNul

dist = dist > 4 ? dist : 4;

this.move(-this.getMaxZoom(4.0 * (dist / 4.0)), 0.0, 0.0);
if (this.level instanceof Level) {
this.move(-this.getMaxZoomIgnoringMountedShip((Level) this.level, 4.0 * (dist / 4.0), shipMountedTo),
0.0, 0.0);
} else {
this.move(-this.getMaxZoom(4.0 * (dist / 4.0)), 0.0, 0.0);
}
}
}

Expand All @@ -112,4 +127,35 @@ private void setRotationWithShipTransform(final float yaw, final float pitch, fi
this.left.set(1.0F, 0.0F, 0.0F);
this.left.transform(this.rotation);
}

/**
* When in third person, do not block the camera on the ship the player is mounted to
*/
@Unique
private double getMaxZoomIgnoringMountedShip(final Level level, double maxZoom,
final @NotNull ClientShip toIgnore) {
for (int i = 0; i < 8; ++i) {
float f = (float) ((i & 1) * 2 - 1);
float g = (float) ((i >> 1 & 1) * 2 - 1);
float h = (float) ((i >> 2 & 1) * 2 - 1);
f *= 0.1F;
g *= 0.1F;
h *= 0.1F;
final Vec3 vec3 = this.position.add(f, g, h);
final Vec3 vec32 =
new Vec3(this.position.x - (double) this.forwards.x() * maxZoom + (double) f + (double) h,
this.position.y - (double) this.forwards.y() * maxZoom + (double) g,
this.position.z - (double) this.forwards.z() * maxZoom + (double) h);
final HitResult hitResult = RaycastUtilsKt.clipIncludeShips(level,
new ClipContext(vec3, vec32, Block.VISUAL, Fluid.NONE, this.entity), true, toIgnore.getId());
if (hitResult.getType() != Type.MISS) {
final double e = hitResult.getLocation().distanceTo(this.position);
if (e < maxZoom) {
maxZoom = e;
}
}
}

return maxZoom;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import net.minecraft.world.InteractionResult;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -28,12 +30,16 @@
import org.valkyrienskies.mod.common.IShipObjectWorldServerProvider;
import org.valkyrienskies.mod.common.ValkyrienSkiesMod;
import org.valkyrienskies.mod.common.util.EntityDragger;
import org.valkyrienskies.mod.common.world.DummyShipWorldClient;
import org.valkyrienskies.mod.mixinducks.client.MinecraftDuck;

@Mixin(Minecraft.class)
public abstract class MixinMinecraft
implements MinecraftDuck, IShipObjectWorldClientProvider, IShipObjectWorldClientCreator {

@Unique
private static final Logger log = LogManager.getLogger("VS2 MixinMinecraft");

@Shadow
private boolean pause;

Expand Down Expand Up @@ -63,15 +69,15 @@ public abstract class MixinMinecraft
@WrapOperation(
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;useItemOn(Lnet/minecraft/client/player/LocalPlayer;Lnet/minecraft/client/multiplayer/ClientLevel;Lnet/minecraft/world/InteractionHand;Lnet/minecraft/world/phys/BlockHitResult;)Lnet/minecraft/world/InteractionResult;"
target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;useItemOn(Lnet/minecraft/client/player/LocalPlayer;Lnet/minecraft/world/InteractionHand;Lnet/minecraft/world/phys/BlockHitResult;)Lnet/minecraft/world/InteractionResult;"
),
method = "startUseItem"
)
private InteractionResult useOriginalCrosshairForBlockPlacement(final MultiPlayerGameMode instance,
final LocalPlayer localPlayer, final ClientLevel clientLevel, final InteractionHand interactionHand,
final LocalPlayer localPlayer, final InteractionHand interactionHand,
final BlockHitResult blockHitResult, final Operation<InteractionResult> useItemOn) {

return useItemOn.call(instance, localPlayer, clientLevel, interactionHand,
return useItemOn.call(instance, localPlayer, interactionHand,
this.originalCrosshairTarget);
}

Expand All @@ -81,7 +87,8 @@ public ClientShipWorldCore getShipObjectWorld() {
final ClientShipWorldCore shipObjectWorldCopy = shipObjectWorld;

if (shipObjectWorldCopy == null) {
throw new IllegalStateException("Requested getShipObjectWorld() when shipObjectWorld was null!");
log.warn("Requested getShipObjectWorld() when shipObjectWorld was null!");
return DummyShipWorldClient.INSTANCE;
}
return shipObjectWorldCopy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ private void handleShipMountingEntity(final ClientboundAddEntityPacket packet, f
final double f = packet.getZ();
final Entity entity = ValkyrienSkiesMod.SHIP_MOUNTING_ENTITY_TYPE.create(level);
final int i = packet.getId();
entity.setPacketCoordinates(d, e, f);
entity.syncPacketPositionCodec(d, e, f);
entity.moveTo(d, e, f);
entity.setXRot((float) (packet.getxRot() * 360) / 256.0f);
entity.setYRot((float) (packet.getyRot() * 360) / 256.0f);
entity.setXRot((packet.getXRot() * 360) / 256.0f);
entity.setYRot((packet.getYRot() * 360) / 256.0f);
entity.setId(i);
entity.setUUID(packet.getUUID());
this.level.putNonPlayerEntity(i, entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ private void setupCameraWithMountedShip(final LevelRenderer instance, final Pose
// Use [camera.getPosition()] instead of [vec3] because mounting the player to the ship has changed the camera
// position.
prepareCullFrustum.call(instance, matrixStack, camera.getPosition(),
this.getProjectionMatrix(Math.max(fov, this.minecraft.options.fov)));
this.getProjectionMatrix(Math.max(fov, this.minecraft.options.fov().get())));
}
// endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static org.valkyrienskies.mod.common.ValkyrienSkiesMod.getVsCore;

import java.util.Random;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
Expand All @@ -13,6 +12,7 @@
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.RandomSource;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.block.Blocks;
Expand Down Expand Up @@ -42,7 +42,7 @@
@Mixin(ClientLevel.class)
public abstract class MixinClientLevel implements IShipObjectWorldClientProvider {
@Unique
private final Random vsRandom = new Random();
private final RandomSource vsRandom = RandomSource.create();

@Shadow
@Final
Expand Down Expand Up @@ -188,17 +188,18 @@ private void animateTickVS(
value = "NEW",
target = "net/minecraft/client/resources/sounds/SimpleSoundInstance"
),
method = "playLocalSound(DDDLnet/minecraft/sounds/SoundEvent;Lnet/minecraft/sounds/SoundSource;FFZ)V"
method = "playSound(DDDLnet/minecraft/sounds/SoundEvent;Lnet/minecraft/sounds/SoundSource;FFZJ)V"
)
private SimpleSoundInstance redirectNewSoundInstance(final SoundEvent soundEvent, final SoundSource soundSource,
final float volume, final float pitch, final double x, final double y, final double z) {
final float volume, final float pitch, final RandomSource randomSource, final double x, final double y,
final double z) {

final Ship ship = VSGameUtilsKt.getShipManagingPos(ClientLevel.class.cast(this), x, y, z);
if (ship != null) {
return new SimpleSoundInstanceOnShip(soundEvent, soundSource, volume, pitch, x, y, z,
return new SimpleSoundInstanceOnShip(soundEvent, soundSource, volume, pitch, randomSource, x, y, z,
ship);
}

return new SimpleSoundInstance(soundEvent, soundSource, volume, pitch, x, y, z);
return new SimpleSoundInstance(soundEvent, soundSource, volume, pitch, randomSource, x, y, z);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.ReportedException;
import net.minecraft.core.BlockPos;
import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.ClipContext;
Expand Down
Loading

0 comments on commit 080e37b

Please sign in to comment.