Skip to content

Commit

Permalink
Update to 1.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
lowercasebtw committed Nov 11, 2024
1 parent 58c7a0e commit 22e9d7a
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 59 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'fabric-loom' version '1.7-SNAPSHOT'
id 'maven-publish'
}

Expand All @@ -25,13 +25,13 @@ processResources {
}

tasks.withType(JavaCompile).configureEach {
it.options.release = 17
it.options.release = 20
}

java {
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_20
targetCompatibility = JavaVersion.VERSION_20
}

jar {
Expand Down
16 changes: 8 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
org.gradle.jvmargs=-Xmx2G
org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.21
yarn_mappings=1.21+build.1
loader_version=0.15.11
minecraft_version=1.21.3
yarn_mappings=1.21.3+build.2
loader_version=0.16.9

# Fabric API
fabric_version=0.107.3+1.21.3

# Mod Properties
mod_version=1.0.0
maven_group=btw.lowercase.blocking_component
archives_base_name=blocking-component

# Dependencies
fabric_version=0.100.1+1.21
archives_base_name=blocking-component
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/btw/lowercase/blocking_component/Blocking.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import net.fabricmc.api.ModInitializer;

public class Blocking implements ModInitializer {
@Override
public void onInitialize() {
Components.initalize();
}
@Override
public void onInitialize() {
Components.initalize();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import net.minecraft.registry.Registry;

public class Components {
public static ComponentType<BlockingComponent> BLOCKING_COMPONENT_TYPE = ComponentType.<BlockingComponent>builder().codec(BlockingComponent.CODEC).build();
public static ComponentType<BlockingComponent> BLOCKING = ComponentType.<BlockingComponent>builder().codec(BlockingComponent.CODEC).build();

public static void initalize() {
Registry.register(Registries.DATA_COMPONENT_TYPE, "blocking", Components.BLOCKING_COMPONENT_TYPE);
Registry.register(Registries.DATA_COMPONENT_TYPE, "blocking", Components.BLOCKING);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,53 @@
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ShieldItem;
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.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Objects;

@Mixin(LivingEntity.class)
public abstract class MixinLivingEntity {
@Shadow public abstract ItemStack getActiveItem();
@Shadow
public abstract ItemStack getActiveItem();

@Shadow public abstract boolean isBlocking();
@Shadow
public abstract boolean isBlocking();

@Shadow public abstract ItemStack getMainHandStack();
@Shadow
public abstract ItemStack getMainHandStack();

@Inject(method = "blockedByShield", at = @At("RETURN"), cancellable = true)
public void blockedByShield$denyDamageIfValueGreaterThanOrEqualToOne(DamageSource source, CallbackInfoReturnable<Boolean> cir) {
ItemStack stack = this.getActiveItem();
if (!stack.getComponents().contains(Components.BLOCKING_COMPONENT_TYPE)) {
if (!stack.getComponents().contains(Components.BLOCKING)) {
cir.setReturnValue(false);
return;
}
BlockingComponent component = Objects.requireNonNull(stack.getComponents().get(Components.BLOCKING_COMPONENT_TYPE));
BlockingComponent component = Objects.requireNonNull(stack.getComponents().get(Components.BLOCKING));
cir.setReturnValue(isBlocking() && component.getDamageReduceMultiplier() == 1.0F);
}

@ModifyVariable(method = "damage", at = @At("HEAD"), argsOnly = true, index = 2)
public float damage$modifyAmount(float value) {
ItemStack stack = this.getActiveItem();
if (!stack.getComponents().contains(Components.BLOCKING_COMPONENT_TYPE) || !isBlocking())
return value;
BlockingComponent component = Objects.requireNonNull(stack.getComponents().get(Components.BLOCKING_COMPONENT_TYPE));
return value * component.getDamageReduceMultiplier();
}
// @ModifyVariable(method = "damage", at = @At("HEAD"), argsOnly = true, index = 2)
// public DamageSource damage$modifyAmount(DamageSource damageSource) {
// ItemStack stack = this.getActiveItem();
// if (!stack.getComponents().contains(Components.BLOCKING) || !isBlocking())
// return damageSource;
// BlockingComponent component = Objects.requireNonNull(stack.getComponents().get(Components.BLOCKING));
// return value * component.getDamageReduceMultiplier();
// }

@Inject(method = "disablesShield", at = @At("RETURN"), cancellable = true)
public void component$axeDisables(CallbackInfoReturnable<Boolean> cir) {
ItemStack stack = this.getMainHandStack();
if (!stack.getComponents().contains(Components.BLOCKING_COMPONENT_TYPE))
return;
BlockingComponent component = Objects.requireNonNull(stack.getComponents().get(Components.BLOCKING_COMPONENT_TYPE));
cir.setReturnValue(stack.getItem() instanceof ShieldItem && component.canAxeDisable());
if (!stack.getComponents().contains(Components.BLOCKING)) {
cir.setReturnValue(false);
} else {
BlockingComponent component = Objects.requireNonNull(stack.getComponents().get(Components.BLOCKING));
cir.setReturnValue(component.canAxeDisable());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@

@Mixin(PlayerEntity.class)
public abstract class MixinPlayerEntity {
@Shadow @NotNull public abstract ItemStack getWeaponStack();
@Shadow
@NotNull
public abstract ItemStack getWeaponStack();

@ModifyArg(method = "disableShield", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/ItemCooldownManager;set(Lnet/minecraft/item/Item;I)V"), index = 1)
@ModifyArg(method = "disableShield", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/ItemCooldownManager;set(Lnet/minecraft/item/ItemStack;I)V"), index = 1)
public int component$disabledTicks(int duration) {
ItemStack stack = this.getWeaponStack();
if (!stack.getComponents().contains(Components.BLOCKING_COMPONENT_TYPE))
if (!stack.getComponents().contains(Components.BLOCKING))
return duration;
BlockingComponent component = Objects.requireNonNull(stack.getComponents().get(Components.BLOCKING_COMPONENT_TYPE));
BlockingComponent component = Objects.requireNonNull(stack.getComponents().get(Components.BLOCKING));
return component.getTotalDisabledTicks();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.consume.UseAction;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.UseAction;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -19,24 +19,24 @@
public abstract class MixinItem {
@Inject(method = "getUseAction", at = @At("RETURN"), cancellable = true)
public void component$action(ItemStack stack, CallbackInfoReturnable<UseAction> cir) {
if (!stack.contains(Components.BLOCKING_COMPONENT_TYPE) || stack.contains(DataComponentTypes.FOOD))
if (!stack.contains(Components.BLOCKING) || stack.contains(DataComponentTypes.FOOD))
return;
cir.setReturnValue(UseAction.BLOCK);
}

@Inject(method = "getMaxUseTime", at = @At("RETURN"), cancellable = true)
public void component$useTime(ItemStack stack, LivingEntity user, CallbackInfoReturnable<Integer> cir) {
if (!stack.contains(Components.BLOCKING_COMPONENT_TYPE) || stack.contains(DataComponentTypes.FOOD))
if (!stack.contains(Components.BLOCKING) || stack.contains(DataComponentTypes.FOOD))
return;
cir.setReturnValue(72000);
}

@Inject(method = "use", at = @At("RETURN"), cancellable = true)
public void component$use(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<TypedActionResult<ItemStack>> cir) {
public void component$use(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<ActionResult> cir) {
ItemStack stack = user.getStackInHand(hand);
if (stack.contains(Components.BLOCKING_COMPONENT_TYPE) && !stack.contains(DataComponentTypes.FOOD)) {
if (stack.contains(Components.BLOCKING) && !stack.contains(DataComponentTypes.FOOD)) {
user.setCurrentHand(hand);
cir.setReturnValue(TypedActionResult.consume(stack));
cir.setReturnValue(ActionResult.CONSUME);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ShieldItem;
import net.minecraft.item.consume.UseAction;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.UseAction;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -21,28 +21,28 @@
public abstract class MixinShieldItem {
@ModifyVariable(method = "<init>", at = @At("HEAD"), argsOnly = true, index = 1)
private static Item.Settings component$default(Item.Settings settings) {
return settings.component(Components.BLOCKING_COMPONENT_TYPE, new BlockingComponent());
return settings.component(Components.BLOCKING, new BlockingComponent());
}

@Inject(method = "getUseAction", at = @At("RETURN"), cancellable = true)
public void component$action(ItemStack stack, CallbackInfoReturnable<UseAction> cir) {
if (!stack.contains(Components.BLOCKING_COMPONENT_TYPE)) {
if (!stack.contains(Components.BLOCKING)) {
cir.setReturnValue(UseAction.NONE);
}
}

@Inject(method = "getMaxUseTime", at = @At("RETURN"), cancellable = true)
public void component$useTime(ItemStack stack, LivingEntity user, CallbackInfoReturnable<Integer> cir) {
if (!stack.contains(Components.BLOCKING_COMPONENT_TYPE)) {
if (!stack.contains(Components.BLOCKING)) {
cir.setReturnValue(0);
}
}

@Inject(method = "use", at = @At("HEAD"), cancellable = true)
public void component$useTime(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<TypedActionResult<ItemStack>> cir) {
public void component$useTime(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<ActionResult> cir) {
ItemStack stack = user.getStackInHand(hand);
if (!stack.contains(Components.BLOCKING_COMPONENT_TYPE)) {
cir.setReturnValue(TypedActionResult.pass(stack));
if (!stack.contains(Components.BLOCKING)) {
cir.setReturnValue(ActionResult.PASS);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public class MixinHeldItemRenderer {
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(-102.25F));
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(k * 13.365F));
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(k * 78.05F));
} else {
// TODO: Go and remove the blocking model predicate from shield item to fix the issue
}
}
}

0 comments on commit 22e9d7a

Please sign in to comment.