Skip to content

Commit

Permalink
feat: MarkFiveCase equips mk5 suit
Browse files Browse the repository at this point in the history
chore: util methods in SuitSet
  • Loading branch information
Duzos committed Aug 26, 2024
1 parent fa6281a commit f95454c
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 25 deletions.
23 changes: 0 additions & 23 deletions src/main/java/mc/duzo/timeless/mixin/PlayerEntityMixin.java

This file was deleted.

6 changes: 6 additions & 0 deletions src/main/java/mc/duzo/timeless/registry/Register.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@

import mc.duzo.timeless.Timeless;
import mc.duzo.timeless.suit.SuitRegistry;
import mc.duzo.timeless.suit.ironman.mk5.MarkFiveCase;
import mc.duzo.timeless.suit.set.SetRegistry;

public class Register {
public static class Items {
public static MarkFiveCase MARK_FIVE_CASE = register("mk_five_case", new MarkFiveCase());

public static <T extends Item> T register(Identifier id, T entry) {
return Registry.register(Registries.ITEM, id, entry);
}
private static <T extends Item> T register(String name, T entry) {
return register(new Identifier(Timeless.MOD_ID, name), entry);
}
}

public static void init() {
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/mc/duzo/timeless/suit/ironman/mk5/MarkFiveCase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package mc.duzo.timeless.suit.ironman.mk5;

import net.fabricmc.fabric.api.item.v1.FabricItemSettings;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.world.World;

import mc.duzo.timeless.registry.Register;
import mc.duzo.timeless.suit.set.SetRegistry;
import mc.duzo.timeless.suit.set.SuitSet;

public class MarkFiveCase extends Item {
public MarkFiveCase() {
super(new FabricItemSettings().maxCount(1));
}

@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
if (world.isClient()) return TypedActionResult.consume(user.getStackInHand(hand));

boolean success = fromCase((ServerPlayerEntity) user, false);
return (success) ? TypedActionResult.consume(user.getStackInHand(hand)) : TypedActionResult.fail(user.getStackInHand(hand));
}

public static boolean toCase(ServerPlayerEntity player, boolean force) {
if (!force) {
if (!(getSet().isWearing(player))) return false;
}

player.getInventory().offerOrDrop(new ItemStack(Register.Items.MARK_FIVE_CASE));
return true;
}
public static boolean fromCase(ServerPlayerEntity player, boolean force) {
if (!force) {
if (!player.getMainHandStack().isOf(Register.Items.MARK_FIVE_CASE)) return false; // not holding
if (getSet().isWearing(player)) return false; // already wearing

player.getMainHandStack().setCount(0);
}

getSet().wear(player);
return true;
}

private static SuitSet getSet() {
return SetRegistry.MARK_FIVE;
}
}
24 changes: 24 additions & 0 deletions src/main/java/mc/duzo/timeless/suit/set/SuitSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import java.util.HashMap;
import java.util.function.BiFunction;

import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;

import mc.duzo.timeless.registry.Identifiable;
Expand Down Expand Up @@ -41,4 +43,26 @@ private void put(SuitItem... items) {
public Identifier id() {
return this.id;
}
public Suit suit() {
return this.suit;
}

public boolean isWearing(LivingEntity entity) {
int target = this.values().size();
int count = 0;

for (ItemStack stack : entity.getArmorItems()) {
if (this.containsValue(stack.getItem())) {
count++;
}
}

return count == target;
}
public void wear(LivingEntity entity) {
this.values().forEach(item -> this.wear(entity, item));
}
private void wear(LivingEntity entity, SuitItem item) {
entity.equipStack(item.getSlotType(), new ItemStack(item));
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions src/main/resources/timeless.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"package": "mc.duzo.timeless.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"EnchantmentHelperMixin",
"PlayerEntityMixin"
"EnchantmentHelperMixin"
],
"client": [
"client.ArmorFeatureRendererMixin"
Expand Down

0 comments on commit f95454c

Please sign in to comment.