Skip to content

Commit

Permalink
fix item equipping
Browse files Browse the repository at this point in the history
  • Loading branch information
TropheusJ committed Jul 8, 2023
1 parent 518e972 commit 4cd892d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
27 changes: 27 additions & 0 deletions src/main/java/one/devos/nautical/succ/SimpleEquipableItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package one.devos.nautical.succ;

import java.util.Objects;

import org.jetbrains.annotations.NotNull;

import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.Equipable;
import net.minecraft.world.item.Item;

/**
* Workaround for QSL bug: <a href="https://github.com/QuiltMC/quilt-standard-libraries/issues/320">QSL#320</a>
*/
public class SimpleEquipableItem extends Item implements Equipable {
private final EquipmentSlot slot;

public SimpleEquipableItem(Properties settings, EquipmentSlot slot) {
super(settings);
this.slot = Objects.requireNonNull(slot);
}

@Override
@NotNull
public EquipmentSlot getEquipmentSlot() {
return slot;
}
}
4 changes: 2 additions & 2 deletions src/main/java/one/devos/nautical/succ/Succ.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public class Succ implements ModInitializer {

public static TwisterChampionTrigger TWISTER_CHAMPION = CriteriaTriggers.register(new TwisterChampionTrigger());

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));
public static Item SUCTION_CUP = new SuctionCupItem(new QuiltItemSettings().maxCount(2));
public static Item SUCTION_CUP_BOOTS = new SimpleEquipableItem(new QuiltItemSettings().maxCount(1), EquipmentSlot.FEET);
@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 Down
18 changes: 12 additions & 6 deletions src/main/java/one/devos/nautical/succ/SuctionCupItem.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package one.devos.nautical.succ;

import org.jetbrains.annotations.NotNull;

import net.minecraft.core.BlockPos;
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;
Expand All @@ -14,6 +15,7 @@
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.Pose;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Equipable;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
Expand All @@ -22,7 +24,7 @@
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;

public class SuctionCupItem extends Item {
public class SuctionCupItem extends Item implements Equipable {
public static final EquipmentSlot[] CUP_SLOTS = { EquipmentSlot.MAINHAND, EquipmentSlot.OFFHAND, EquipmentSlot.FEET };
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"));
Expand All @@ -38,6 +40,7 @@ public SuctionCupItem(Properties properties) {
}

@Override
@NotNull
public InteractionResult useOn(UseOnContext context) {
Player player = context.getPlayer();
if (player instanceof ServerPlayer serverPlayer) {
Expand All @@ -46,6 +49,12 @@ public InteractionResult useOn(UseOnContext context) {
return InteractionResult.FAIL;
}

@Override
@NotNull
public EquipmentSlot getEquipmentSlot() {
return EquipmentSlot.HEAD;
}

public void tryStartClimbing(ServerPlayer player, UseOnContext ctx) {
if (GlobalClimbingManager.isClimbing(player)) {
return;
Expand All @@ -56,9 +65,6 @@ public void tryStartClimbing(ServerPlayer player, UseOnContext ctx) {
return;
}
Level level = ctx.getLevel();
if (level == null) {
return;
}
if (missingCups(player)) {
fail(player, MISSING_CUPS);
return;
Expand All @@ -74,7 +80,7 @@ public void tryStartClimbing(ServerPlayer player, UseOnContext ctx) {
return;
}
// offset to the center of the block to prevent getting stuck in adjacent walls
clickPos = new Vec3(Math.floor(headPos.getX()) + 0.5, clickPos.y, Math.floor(headPos.getZ()) + 0.5);
clickPos = new Vec3(headPos.getX() + 0.5, clickPos.y, headPos.getZ() + 0.5);
GlobalClimbingManager.startClimbing(player, clickPos, clickedFace);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import net.minecraft.world.entity.player.Inventory;
import one.devos.nautical.succ.LocalClimbingManager;

@Mixin(Inventory.class) // note: this is a client-only mixin despite entity not being client only
@Mixin(Inventory.class) // note: this is a client-only mixin despite Inventory not being client only
public class InventoryMixin {
@Inject(method = "swapPaint", at = @At("HEAD"), cancellable = true)
private void succ$preventItemSwapping(double scrollAmount, CallbackInfo ci) {
private void succ$preventItemSwappingWhileClimbing(double scrollAmount, CallbackInfo ci) {
if (LocalClimbingManager.INSTANCE != null) {
ci.cancel();
}
Expand Down

0 comments on commit 4cd892d

Please sign in to comment.