Skip to content

Commit

Permalink
Make some fixes to the PR
Browse files Browse the repository at this point in the history
  • Loading branch information
OroArmor committed Jun 29, 2024
1 parent cd2a834 commit 9c6a0b7
Show file tree
Hide file tree
Showing 22 changed files with 153 additions and 87 deletions.
6 changes: 2 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'com.oroarmor.general-gradle-plugin' version '1.2.2'
id 'com.oroarmor.minecraft-gradle-plugin' version '1.2.2'

// id 'org.barfuin.gradle.taskinfo' version '1.0.5'
}

sourceCompatibility = JavaVersion.VERSION_17
Expand Down Expand Up @@ -93,4 +91,4 @@ task github(type: PublishProjectToGithubTask) {

import com.oroarmor.orogradleplugin.minecraft.*
task curseforge(type: CurseforgePublishTask)
task modrinth(type: ModrinthPublishTask)
task modrinth(type: ModrinthPublishTask)
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ loader_version=0.15.11
mod_version=1.6.3
maven_group=com.oroarmor
archives_base_name=multi-item-lib
discord_hook_image_url = https://raw.githubusercontent.com/OroArmor/Multi-Item-Lib/9027fbe02c73d3a2f2c480a26c0a3c049d49f36d/src/main/resources/assets/multi-item-lib/icon.png
discord_hook_image_url = https://raw.githubusercontent.com/OroArmor/Multi-Item-Lib/9027fbe02c73d3a2f2c480a26c0a3c049d49f36d/src/main/resources/assets/multi-item-lib/icon.png
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2021 OroArmor (Eli Orona)
* Copyright (c) 2024 OroArmor (Eli Orona)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -24,18 +24,27 @@

package com.oroarmor.multiitemlib.api;

import net.minecraft.item.ItemStack;

public interface ShieldCooldownSettings {

/**
* If the shield is disabled by an axe, how long should the cooldown last for?
* Set to 0 to make the shield never suffer from being disabled by an axe. (Other shields in your inventory still get disabled)
* Default value is 100.
* Returns the shield disable cooldown, such as when attacked by an axe.
*
* @param shieldStack the stack for the shield
* @return the number of ticks to disable the shield
*/
int getDisableCooldown();
default int getDisableCooldown(ItemStack shieldStack) {
return 100;
}

/**
* How many ticks should it take between right clicking the shield, and its protection being effective?
* Default value is 5.
* Returns how long it takes for the shield to be raised.
*
* @param shield the stack for the shield
* @return the number of ticks before the shield is raised
*/
int getRaiseCooldown();
}
default int getRaiseCooldown(ItemStack shield) {
return 5;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public final class UniqueItemRegistry {
*/
public static final UniqueItemRegistry TRIDENT = new UniqueItemRegistry(Items.TRIDENT);
/**
* The {@link UniqueItemRegistry} for tridents. Allows for some correct rendering. Mixins will be needed for full correct rendering.
* The {@link UniqueItemRegistry} for elytras. Allows for some correct rendering. Mixins will be needed for full correct rendering.
*/
public static final UniqueItemRegistry ELYTRA = new UniqueItemRegistry(Items.ELYTRA);

Expand Down Expand Up @@ -90,7 +90,7 @@ public boolean isItemInRegistry(Item item) {
return itemList.contains(item);
}

public Set<Item> getValues() {
public Collection<Item> getValues() {
return Collections.unmodifiableSet(itemList);
}
}
}
54 changes: 54 additions & 0 deletions src/main/java/com/oroarmor/multiitemlib/impl/ShieldUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* MIT License
*
* Copyright (c) 2024 OroArmor (Eli Orona)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package com.oroarmor.multiitemlib.impl;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.oroarmor.multiitemlib.api.ShieldCooldownSettings;
import com.oroarmor.multiitemlib.api.UniqueItemRegistry;

import net.minecraft.entity.player.ItemCooldownManager;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

public final class ShieldUtil {
/**
* Sets the shield cooldown for all shields.
*
* @param cooldownManager the item cooldown manager
* @param duration the original duration (100 ticks)
* @param original the original method for the cooldown
* @param shield the shield stack
*/
public static void addShieldCooldown(ItemCooldownManager cooldownManager, int duration, Operation<Void> original, ItemStack shield) {
for (Item registryEntry : UniqueItemRegistry.SHIELD.getValues()) {
int disableTime = duration;
if (registryEntry instanceof ShieldCooldownSettings) {
disableTime = ((ShieldCooldownSettings) registryEntry).getDisableCooldown(shield);
}

original.call(cooldownManager, registryEntry, disableTime);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.oroarmor.multiitemlib.api.UniqueItemRegistry;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import net.minecraft.block.BeehiveBlock;
import net.minecraft.item.Item;
Expand All @@ -41,4 +40,4 @@ public class BeehiveBlockMixin {
private boolean onUse(ItemStack instance, Item item, Operation<Boolean> original) {
return UniqueItemRegistry.SHEARS.isItemInRegistry(instance.getItem());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2021 OroArmor (Eli Orona)
* Copyright (c) 2024 OroArmor (Eli Orona)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -27,16 +27,17 @@
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.oroarmor.multiitemlib.api.UniqueItemRegistry;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(ClientPlayerEntity.class)
public class ClientPlayerEntityMixin {
@WrapOperation(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isOf(Lnet/minecraft/item/Item;)Z"))
private boolean handleDisableShield(ItemStack instance, Item item, Operation<Boolean> original) {
return UniqueItemRegistry.ELYTRA.isItemInRegistry(instance.getItem());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.oroarmor.multiitemlib.api.UniqueItemRegistry;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import net.minecraft.enchantment.EfficiencyEnchantment;
import net.minecraft.item.Item;
Expand All @@ -41,4 +40,4 @@ public class EfficiencyEnchantmentMixin {
private boolean isAcceptableItem(ItemStack instance, Item item, Operation<Boolean> original) {
return UniqueItemRegistry.SHEARS.isItemInRegistry(instance.getItem());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.oroarmor.multiitemlib.api.UniqueItemRegistry;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import net.minecraft.entity.passive.SheepEntity;
import net.minecraft.entity.passive.SnowGolemEntity;
Expand All @@ -42,4 +41,4 @@ public class EntityInteractShearsMixin {
private boolean interactMob(ItemStack instance, Item item, Operation<Boolean> original) {
return UniqueItemRegistry.SHEARS.isItemInRegistry(instance.getItem());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.oroarmor.multiitemlib.api.UniqueItemRegistry;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import net.minecraft.entity.projectile.FishingBobberEntity;
import net.minecraft.item.Item;
Expand All @@ -41,4 +40,4 @@ public class FishBobberEntityMixin {
private boolean removeIfInvalid(ItemStack instance, Item item, Operation<Boolean> original) {
return UniqueItemRegistry.FISHING_ROD.isItemInRegistry(instance.getItem());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2021 OroArmor (Eli Orona)
* Copyright (c) 2024 OroArmor (Eli Orona)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -28,18 +28,20 @@
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.oroarmor.multiitemlib.api.ShieldCooldownSettings;
import com.oroarmor.multiitemlib.api.UniqueItemRegistry;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

import net.minecraft.entity.LivingEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

@Mixin(LivingEntity.class)
public class LivingEntityMixin {
@Shadow protected ItemStack activeItemStack;
@Shadow
protected ItemStack activeItemStack;

@WrapOperation(method = "tickFallFlying", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isOf(Lnet/minecraft/item/Item;)Z"))
private boolean handleElytra(ItemStack instance, Item item, Operation<Boolean> original) {
Expand All @@ -48,9 +50,9 @@ private boolean handleElytra(ItemStack instance, Item item, Operation<Boolean> o

@ModifyConstant(method = "isBlocking", constant = @Constant(intValue = 5))
private int getShieldHoldDelay(int constant) {
if(activeItemStack.getItem() instanceof ShieldCooldownSettings) {
return ((ShieldCooldownSettings) activeItemStack.getItem()).getRaiseCooldown();
if (activeItemStack.getItem() instanceof ShieldCooldownSettings shield) {
return shield.getRaiseCooldown(activeItemStack);
}
return constant;
}
}
}
43 changes: 29 additions & 14 deletions src/main/java/com/oroarmor/multiitemlib/mixin/MobEntityMixin.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2021 OroArmor (Eli Orona)
* Copyright (c) 2024 OroArmor (Eli Orona)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -26,26 +26,41 @@

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.oroarmor.multiitemlib.api.ShieldCooldownSettings;
import com.oroarmor.multiitemlib.api.UniqueItemRegistry;
import com.oroarmor.multiitemlib.impl.ShieldUtil;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.ItemCooldownManager;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import net.minecraft.item.ItemStack;

@Mixin(MobEntity.class)
public class MobEntityMixin {
@Unique
ThreadLocal<ItemStack> shieldStack = new ThreadLocal<>();

@Unique
ThreadLocal<ItemStack> attackingStack = new ThreadLocal<>();

@Inject(method = "disablePlayerShield", at = @At("HEAD"))
public void captureItemStacks(PlayerEntity player, ItemStack mobStack, ItemStack playerStack, CallbackInfo ci) {
shieldStack.set(playerStack);
attackingStack.set(mobStack);
}

@WrapOperation(method = "disablePlayerShield", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isOf(Lnet/minecraft/item/Item;)Z"))
public boolean allowMoreShields(ItemStack instance, Item item, Operation<Boolean> original) {
return UniqueItemRegistry.SHIELD.isItemInRegistry(instance.getItem());
}

@WrapOperation(method = "disablePlayerShield", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/ItemCooldownManager;set(Lnet/minecraft/item/Item;I)V"))
private void handleDisableShield(ItemCooldownManager instance, Item item, int duration, Operation<Void> original) {
for(Item registryEntry : UniqueItemRegistry.SHIELD.getValues()) {
int disableTime;
if(registryEntry instanceof ShieldCooldownSettings) {
disableTime = ((ShieldCooldownSettings) registryEntry).getDisableCooldown();
} else {
disableTime = duration;
}
original.call(instance, registryEntry, disableTime);
}
ShieldUtil.addShieldCooldown(instance, duration, original, this.shieldStack.get());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.oroarmor.multiitemlib.api.UniqueItemRegistry;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import net.minecraft.entity.passive.MooshroomEntity;
import net.minecraft.item.Item;
Expand All @@ -41,4 +40,4 @@ public class MooshroomEntityInteractShearsMixin {
private boolean interactMob(ItemStack instance, Item item, Operation<Boolean> original) {
return UniqueItemRegistry.SHEARS.isItemInRegistry(instance.getItem());
}
}
}
Loading

0 comments on commit 9c6a0b7

Please sign in to comment.