Skip to content

Commit

Permalink
plain port (broken catastrophically)
Browse files Browse the repository at this point in the history
  • Loading branch information
TropheusJ committed Jul 8, 2023
1 parent 87996db commit 14656a9
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 60 deletions.
3 changes: 1 addition & 2 deletions src/main/java/one/devos/nautical/succ/ClimbingState.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import java.util.Map;
import java.util.UUID;

import javax.annotation.Nullable;

import org.jetbrains.annotations.Nullable;
import org.quiltmc.qsl.networking.api.PacketByteBufs;

import net.minecraft.core.Direction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

import org.jetbrains.annotations.NotNull;

import net.minecraft.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientPacketListener;
Expand All @@ -25,6 +28,7 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
Expand Down Expand Up @@ -151,6 +155,7 @@ private void updateSuction() {
this.suction = entityData.get(SUCTION);
if (oldSuction == suction)
return;
Level level = level();
level.playSound(null, blockPosition(), SoundEvents.ITEM_FRAME_ADD_ITEM, SoundSource.PLAYERS, 1, suction ? 0.5f : 1);
if (moveDirection == SuctionCupMoveDirection.NONE) {
setMoveTarget(suction ? stuckPos : unstuckPos);
Expand Down Expand Up @@ -244,7 +249,8 @@ protected void addAdditionalSaveData(CompoundTag nbt) {
}

@Override
public Packet<?> getAddEntityPacket() {
@NotNull
public Packet<ClientGamePacketListener> getAddEntityPacket() {
FriendlyByteBuf buf = PacketByteBufs.create();
new ClientboundAddEntityPacket(this).write(buf);
writeExtraPacketData(buf);
Expand All @@ -269,7 +275,7 @@ public void readExtraPacketData(FriendlyByteBuf buf) {
this.limb = buf.readEnum(SuctionCupLimb.class);
UUID playerId = buf.readUUID();
this.facing = buf.readEnum(Direction.class);
this.climbingState = GlobalClimbingManager.getState(playerId, level.isClientSide());
this.climbingState = GlobalClimbingManager.getState(playerId, level().isClientSide());
this.climbingState.entities.put(limb, this);
setYRot(facing.toYRot());
this.stuckPos = SuccUtils.readVec(buf);
Expand All @@ -283,7 +289,7 @@ public void readExtraPacketData(FriendlyByteBuf buf) {

public Player getOwner() {
if (owner == null) {
owner = level.getPlayerByUUID(climbingState.playerUuid);
owner = level().getPlayerByUUID(climbingState.playerUuid);
}
return owner;
}
Expand Down Expand Up @@ -339,7 +345,7 @@ public void checkTwisterChampionStatus() {
@Override
public void remove(RemovalReason reason) {
super.remove(reason);
if (!level.isClientSide()) {
if (!level().isClientSide()) {
if (getOwner() instanceof ServerPlayer player && GlobalClimbingManager.isClimbing(player)) {
GlobalClimbingManager.stopClimbing(player);
}
Expand Down
13 changes: 5 additions & 8 deletions src/main/java/one/devos/nautical/succ/GlobalClimbingManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import java.util.Map;
import java.util.UUID;

import javax.annotation.Nullable;

import org.quiltmc.qsl.networking.api.PacketByteBufs;
import org.quiltmc.qsl.networking.api.PacketSender;
import org.quiltmc.qsl.networking.api.PlayerLookup;
Expand All @@ -14,6 +12,8 @@

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import org.jetbrains.annotations.Nullable;

import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -51,7 +51,7 @@ private GlobalClimbingManager(EnvType env) {
}

public static GlobalClimbingManager get(Player player) {
return get(player.level);
return get(player.level());
}

public static GlobalClimbingManager get(Level level) {
Expand Down Expand Up @@ -134,10 +134,7 @@ private static void changeClimbingState(ServerPlayer player, @Nullable Vec3 clic
}

private static void addCupEntities(ServerPlayer player, ClimbingState state, Vec3 clickPos, Direction facing) {
Level level = player.level;
if (level == null) {
return;
}
Level level = player.level();
for (SuctionCupLimb limb : SuctionCupLimb.values()) {
Vec3 cupPos = clickPos.add(SuccUtils.rotateVec(limb.cupOffset, facing.toYRot()));
ClimbingSuctionCupEntity entity = new ClimbingSuctionCupEntity(level, limb, cupPos, state, facing);
Expand Down Expand Up @@ -204,7 +201,7 @@ public static void stopRequested(MinecraftServer server, ServerPlayer player, Se
player.getGameProfile().getName(), playerPos, stopPos);
return;
}
if (!(player.level instanceof ServerLevel level)) {
if (!(player.level() instanceof ServerLevel level)) {
return;
}
stopClimbing(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
import java.util.List;
import java.util.Optional;

import javax.annotation.Nullable;

import org.apache.commons.lang3.tuple.Triple;
import org.quiltmc.qsl.networking.api.PacketByteBufs;
import org.quiltmc.qsl.networking.api.client.ClientPlayNetworking;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

import org.jetbrains.annotations.Nullable;

import net.minecraft.ChatFormatting;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -135,7 +136,7 @@ && newCupPosNotObstructed(player, level, entity, newPos, direction)) {

// true if trying to stop
private boolean tryStopClimbing(LocalPlayer player, ClientLevel level, ClimbingSuctionCupEntity entity, Vec3 newPos, SuctionCupMoveDirection direction) {
BlockPos blockPos = new BlockPos(newPos);
BlockPos blockPos = BlockPos.containing(newPos);
Direction facing = entity.facing;
BlockPos wallPos = blockPos.relative(facing);
BlockState wallState = level.getBlockState(wallPos);
Expand Down Expand Up @@ -182,7 +183,7 @@ private boolean newCupPosCloseEnough(LocalPlayer player, ClientLevel level, Clim

private boolean newCupPosNotObstructed(LocalPlayer player, ClientLevel level, ClimbingSuctionCupEntity entity,
Vec3 newPos, SuctionCupMoveDirection direction) {
BlockPos newBlockPos = new BlockPos(newPos);
BlockPos newBlockPos = BlockPos.containing(newPos);
BlockState state = level.getBlockState(newBlockPos);
if (!state.getCollisionShape(level, newBlockPos).isEmpty()) {
sendNotification(player, level, direction, CUP_OBSTRUCTED_BLOCK);
Expand Down
30 changes: 22 additions & 8 deletions src/main/java/one/devos/nautical/succ/Succ.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import org.quiltmc.loader.api.ModContainer;
import org.quiltmc.qsl.base.api.entrypoint.ModInitializer;
import org.quiltmc.qsl.item.group.api.QuiltItemGroup;
import org.quiltmc.qsl.item.setting.api.QuiltItemSettings;
import org.quiltmc.qsl.networking.api.ServerPlayConnectionEvents;

import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -13,22 +15,25 @@
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityDimensions;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;

public class Succ implements ModInitializer {
public static final String ID = "succ";
public static final Logger LOGGER = LoggerFactory.getLogger(ID);

public static TwisterChampionTrigger TWISTER_CHAMPION = CriteriaTriggers.register(new TwisterChampionTrigger());
public static final QuiltItemGroup SUCC_ITEM_GROUP = QuiltItemGroup.builder(id("succ")).build();

public static Item SUCTION_CUP = new SuctionCupItem(new QuiltItemSettings().equipmentSlot(EquipmentSlot.HEAD).maxCount(2).group(SUCC_ITEM_GROUP));
public static Item SUCTION_CUP_BOOTS = new Item(new QuiltItemSettings().equipmentSlot(EquipmentSlot.FEET).maxCount(1).group(SUCC_ITEM_GROUP));
public static Item SUCTION_CUP = new SuctionCupItem(new QuiltItemSettings().equipmentSlot(EquipmentSlot.HEAD).maxCount(2));
public static Item SUCTION_CUP_BOOTS = new Item(new QuiltItemSettings().equipmentSlot(EquipmentSlot.FEET).maxCount(1));
@SuppressWarnings("deprecation") // entity constructor deprecated to prevent misuse, should only be used here
public static EntityType<ClimbingSuctionCupEntity> SUCTION_CUP_ENTITY_TYPE = FabricEntityTypeBuilder
.<ClimbingSuctionCupEntity>create(MobCategory.MISC, ClimbingSuctionCupEntity::new)
Expand All @@ -38,14 +43,23 @@ public class Succ implements ModInitializer {
.fireImmune()
.build();

public static final CreativeModeTab SUCC_ITEM_GROUP = FabricItemGroup.builder()
.icon(() -> new ItemStack(SUCTION_CUP))
.displayItems((params, output) -> {
output.accept(SUCTION_CUP);
output.accept(SUCTION_CUP_BOOTS);
})
.title(Component.translatable("itemGroup.succ"))
.build();

@Override
public void onInitialize(ModContainer mod) {
Registry.register(Registry.ITEM, id("suction_cup"), SUCTION_CUP);
Registry.register(Registry.ITEM, id("suction_cup_boots"), SUCTION_CUP_BOOTS);
Registry.register(BuiltInRegistries.ITEM, id("suction_cup"), SUCTION_CUP);
Registry.register(BuiltInRegistries.ITEM, id("suction_cup_boots"), SUCTION_CUP_BOOTS);

Registry.register(Registry.ENTITY_TYPE, id("suction_cup"), SUCTION_CUP_ENTITY_TYPE);
Registry.register(BuiltInRegistries.ENTITY_TYPE, id("suction_cup"), SUCTION_CUP_ENTITY_TYPE);

SUCC_ITEM_GROUP.setIcon(SUCTION_CUP);
Registry.register(BuiltInRegistries.CREATIVE_MODE_TAB, id("item_group"), SUCC_ITEM_GROUP);

ServerPlayConnectionEvents.JOIN.register(GlobalClimbingManager::onPlayerJoin);
ServerPlayConnectionEvents.DISCONNECT.register(GlobalClimbingManager::onPlayerLeave);
Expand Down
12 changes: 0 additions & 12 deletions src/main/java/one/devos/nautical/succ/SuccUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package one.devos.nautical.succ;

import net.minecraft.core.Direction;
import net.minecraft.core.Direction.Axis;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.util.Mth;
Expand Down Expand Up @@ -58,15 +57,4 @@ public static double difference(double a, double b) {
public static double axisChoose(Axis axis, Vec3 vec) {
return axis.choose(vec.x, vec.y, vec.z);
}

public static Vector3f floatNormal(Direction direction) {
return switch (direction) {
case DOWN -> Vector3f.YN;
case UP -> Vector3f.YP;
case NORTH -> Vector3f.ZN;
case SOUTH -> Vector3f.ZP;
case WEST -> Vector3f.XN;
case EAST -> Vector3f.XP;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Vector3f;

import net.minecraft.client.Minecraft;
import net.minecraft.client.model.Model;
Expand Down Expand Up @@ -55,10 +54,10 @@ public void renderEntity(ClimbingSuctionCupEntity entity, float yaw, float tickD
matrices.pushPose();

matrices.scale(0.75f, 0.75f, 0.75f);
matrices.mulPose(Vector3f.XN.rotationDegrees(90));
matrices.mulPose(Vector3f.ZN.rotationDegrees(entity.facing.toYRot() + 180));
matrices.mulPose(com.mojang.math.Axis.XN.rotationDegrees(90));
matrices.mulPose(com.mojang.math.Axis.ZN.rotationDegrees(entity.facing.toYRot() + 180));
if (entity.limb.hand) {
matrices.mulPose(Vector3f.YN.rotationDegrees(90));
matrices.mulPose(com.mojang.math.Axis.YN.rotationDegrees(90));
matrices.translate(0.3, -1.23, 0);
} else {
matrices.translate(-0.01, -1.23, 0.3);
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/one/devos/nautical/succ/SuctionCupItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.core.Direction;
import net.minecraft.core.Direction.Axis;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents;
Expand All @@ -23,8 +24,8 @@

public class SuctionCupItem extends Item {
public static final EquipmentSlot[] CUP_SLOTS = { EquipmentSlot.MAINHAND, EquipmentSlot.OFFHAND, EquipmentSlot.FEET };
public static final TagKey<Item> HAND_CLIMBING_CUPS = TagKey.create(Registry.ITEM_REGISTRY, Succ.id("hand_climbing_cups"));
public static final TagKey<Item> FEET_CLIMBING_CUPS = TagKey.create(Registry.ITEM_REGISTRY, Succ.id("feet_climbing_cups"));
public static final TagKey<Item> HAND_CLIMBING_CUPS = TagKey.create(Registries.ITEM, Succ.id("hand_climbing_cups"));
public static final TagKey<Item> FEET_CLIMBING_CUPS = TagKey.create(Registries.ITEM, Succ.id("feet_climbing_cups"));
public static final Component TOO_FAR = Component.translatable("succ.wallTooFar");
public static final Component MISSING_CUPS = Component.translatable("succ.missingCups");
public static final Component OBSTRUCTED = Component.translatable("succ.obstructed");
Expand Down Expand Up @@ -96,7 +97,7 @@ public static boolean climbPosObstructed(ServerPlayer player, Level level, Vec3
Direction facing = clickedFace.getOpposite();
AABB bounds = player.getDimensions(Pose.STANDING).makeBoundingBox(player.position());
double height = bounds.maxY - bounds.minY;
BlockPos bottomToCheck = new BlockPos(headPos.getX(), clickPos.y - height, headPos.getZ());
BlockPos bottomToCheck = new BlockPos(headPos.getX(), (int) (clickPos.y - height), headPos.getZ());
for (BlockPos pos : BlockPos.betweenClosed(headPos, bottomToCheck)) {
BlockState state = level.getBlockState(pos);
if (!state.getCollisionShape(level, pos).isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,26 @@
import com.google.gson.JsonObject;

import net.minecraft.advancements.critereon.AbstractCriterionTriggerInstance;
import net.minecraft.advancements.critereon.ContextAwarePredicate;
import net.minecraft.advancements.critereon.DeserializationContext;
import net.minecraft.advancements.critereon.EntityPredicate.Composite;
import net.minecraft.advancements.critereon.SimpleCriterionTrigger;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import one.devos.nautical.succ.TwisterChampionTrigger.Instance;

import org.jetbrains.annotations.NotNull;

public class TwisterChampionTrigger extends SimpleCriterionTrigger<Instance> {
public static final ResourceLocation ID = Succ.id("twister_champion");

@Override
protected Instance createInstance(JsonObject obj, Composite playerPredicate, DeserializationContext predicateDeserializer) {
@NotNull
protected Instance createInstance(JsonObject json, ContextAwarePredicate contextAwarePredicate, DeserializationContext deserializationContext) {
return new Instance();
}

@Override
@NotNull
public ResourceLocation getId() {
return ID;
}
Expand All @@ -29,7 +33,7 @@ public void trigger(ServerPlayer player) {

public static class Instance extends AbstractCriterionTriggerInstance {
public Instance() {
super(ID, Composite.ANY);
super(ID, ContextAwarePredicate.ANY);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@
import com.mojang.blaze3d.vertex.PoseStack;

import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.block.model.ItemTransforms.TransformType;
import net.minecraft.client.renderer.entity.layers.PlayerItemInHandLayer;
import net.minecraft.world.entity.HumanoidArm;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import one.devos.nautical.succ.GlobalClimbingManager;

@Mixin(PlayerItemInHandLayer.class)
public class PlayerItemInHandLayerMixin {
@Inject(method = "renderArmWithItem", at = @At("HEAD"), cancellable = true)
private void succ$hideHeldItemsWhenClimbing(LivingEntity entity, ItemStack stack, TransformType transformationMode,
HumanoidArm arm, PoseStack matrices, MultiBufferSource vertexConsumers,
int light, CallbackInfo ci) {
private void succ$hideHeldItemsWhenClimbing(LivingEntity entity, ItemStack stack, ItemDisplayContext transformationMode, HumanoidArm arm,
PoseStack matrices, MultiBufferSource vertexConsumers, int light, CallbackInfo ci) {
if (entity instanceof Player player && GlobalClimbingManager.isClimbing(player)) {
ci.cancel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.commands.CommandSourceStack;
import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket.RelativeArgument;
import net.minecraft.server.commands.TeleportCommand;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.RelativeMovement;
import one.devos.nautical.succ.GlobalClimbingManager;

@Mixin(TeleportCommand.class)
public class TeleportCommandMixin {
@Inject(method = "performTeleport", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;setYHeadRot(F)V", ordinal = 0))
private static void succ$onTeleport(CommandSourceStack source, Entity target, ServerLevel world, double x, double y,
double z, Set<RelativeArgument> movementFlags, float yaw, float pitch,
@SuppressWarnings("InvalidInjectorMethodSignature")
@Inject(method = "performTeleport", at = @At("TAIL"))
private static void succ$onTeleport(CommandSourceStack source, Entity target, ServerLevel world, double x,
double y, double z, Set<RelativeMovement> movementFlags, float yaw, float pitch,
@Nullable @Coerce Object facingLocation, CallbackInfo ci) {
if (target instanceof ServerPlayer player) {
GlobalClimbingManager.onTeleport(player);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/assets/succ/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"advancements.succ.twister_champion.title": "uoᴉdɯɐɥƆ ɹǝʇsᴉʍ┴",
"advancements.succ.twister_champion.description": "sǝuoq ʎɯ ǝᴉʍo ɟoo ɥɔnO",

"itemGroup.succ.succ": "™ɔɔnS",
"itemGroup.succ": "™ɔɔnS",

"tag.succ.hand_climbing_cups": "sdnƆ ƃuᴉqɯᴉlƆ puɐH",
"tag.succ.feet_climbing_cups": "sdnƆ ƃuᴉqɯᴉlƆ ʇǝǝℲ"
Expand Down
Loading

0 comments on commit 14656a9

Please sign in to comment.