-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
130 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/xyz/nucleoid/plasmid/impl/component/PlasmidDataComponentTypes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package xyz.nucleoid.plasmid.impl.component; | ||
|
||
import eu.pb4.polymer.core.api.other.PolymerComponent; | ||
import net.minecraft.component.ComponentType; | ||
import net.minecraft.registry.Registries; | ||
import net.minecraft.registry.Registry; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.Unit; | ||
import xyz.nucleoid.plasmid.impl.Plasmid; | ||
|
||
public final class PlasmidDataComponentTypes { | ||
private PlasmidDataComponentTypes() { | ||
} | ||
|
||
public static final ComponentType<Unit> OLD_COMBAT = register("old_combat", ComponentType.<Unit>builder() | ||
.codec(Unit.CODEC) | ||
.build()); | ||
|
||
private static <T> ComponentType<T> register(String path, ComponentType<T> type) { | ||
return Registry.register(Registries.DATA_COMPONENT_TYPE, Identifier.of(Plasmid.ID, path), type); | ||
} | ||
|
||
public static void register() { | ||
PolymerComponent.registerDataComponent(OLD_COMBAT); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/xyz/nucleoid/plasmid/mixin/game/common/LivingEntityMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package xyz.nucleoid.plasmid.mixin.game.common; | ||
|
||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import com.llamalad7.mixinextras.sugar.Local; | ||
import com.llamalad7.mixinextras.sugar.ref.LocalFloatRef; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.damage.DamageSource; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.item.ShieldItem; | ||
import org.spongepowered.asm.mixin.Final; | ||
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 xyz.nucleoid.plasmid.impl.component.PlasmidDataComponentTypes; | ||
|
||
@Mixin(LivingEntity.class) | ||
public class LivingEntityMixin { | ||
@Shadow | ||
@Final | ||
private ItemStack activeItemStack; | ||
|
||
@WrapOperation( | ||
method = "blockedByShield", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/item/ItemStack;getItem()Lnet/minecraft/item/Item;" | ||
) | ||
) | ||
private Item allowOldCombatSwordBlocking(ItemStack stack, Operation<Item> operation) { | ||
// Allow fulfilling the instanceof ShieldItem check | ||
if (stack.contains(PlasmidDataComponentTypes.OLD_COMBAT)) { | ||
return Items.SHIELD; | ||
} | ||
|
||
return operation.call(stack); | ||
} | ||
|
||
@WrapOperation( | ||
method = "damage", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/entity/LivingEntity;blockedByShield(Lnet/minecraft/entity/damage/DamageSource;)Z" | ||
) | ||
) | ||
private boolean applyHalfDamageFromSwordBlocking(LivingEntity entity, DamageSource source, Operation<Boolean> operation, @Local(ordinal = 0, argsOnly = true) LocalFloatRef amount) { | ||
if (operation.call(entity, source)) { | ||
ItemStack stack = entity.getBlockingItem(); | ||
|
||
if (!stack.contains(PlasmidDataComponentTypes.OLD_COMBAT) || stack.getItem() instanceof ShieldItem) { | ||
return true; | ||
} | ||
|
||
amount.set(Math.max(0, (amount.get() / 2) - 0.5f)); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@ModifyConstant( | ||
method = "getBlockingItem", | ||
constant = @Constant(intValue = 5) | ||
) | ||
private int allowInstantSwordBlocking(int original) { | ||
if (!this.activeItemStack.contains(PlasmidDataComponentTypes.OLD_COMBAT) || this.activeItemStack.getItem() instanceof ShieldItem) { | ||
return original; | ||
} | ||
|
||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters