Skip to content

Commit

Permalink
Update mod to Minecraft 1.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
haykam821 authored and Patbox committed Nov 8, 2024
1 parent 42a2b68 commit 3c9fc8e
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 39 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.7.+'
id 'fabric-loom' version '1.8.+'
id "com.modrinth.minotaur" version "2.+"
}
import com.modrinth.minotaur.TaskModrinthUpload
Expand All @@ -21,10 +21,10 @@ dependencies {

modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modImplementation include('xyz.nucleoid:stimuli:0.4.12+1.21')
modImplementation include('xyz.nucleoid:stimuli:0.5.0+1.21.3')

modCompileOnly "dev.gegy:player-roles-api:1.6.11"
modCompileOnly "me.lucko:fabric-permissions-api:0.3.1"
modCompileOnly "dev.gegy:player-roles-api:1.6.13"
modCompileOnly "me.lucko:fabric-permissions-api:0.3.2"
}

processResources {
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G

minecraft_version=1.21.1
yarn_mappings=1.21.1+build.2
loader_version=0.15.11
minecraft_version=1.21.3
yarn_mappings=1.21.3+build.2
loader_version=0.16.9

#Dependencies
fabric_version=0.100.3+1.21
fabric_version=0.107.0+1.21.3

# Mod Properties
mod_version=0.3.9
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
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.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
5 changes: 4 additions & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/xyz/nucleoid/leukocyte/rule/RuleResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import net.minecraft.text.ClickEvent;
import net.minecraft.text.Text;
import net.minecraft.text.MutableText;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.nucleoid.leukocyte.authority.Authority;
import xyz.nucleoid.stimuli.event.EventResult;

import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -77,11 +77,11 @@ public RuleResult orElse(RuleResult other) {
return this.isDefinitive() ? this : other;
}

public ActionResult asActionResult() {
public EventResult asEventResult() {
return switch (this) {
case ALLOW -> ActionResult.SUCCESS;
case DENY -> ActionResult.FAIL;
default -> ActionResult.PASS;
case ALLOW -> EventResult.ALLOW;
case DENY -> EventResult.DENY;
default -> EventResult.PASS;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
import net.minecraft.item.Items;
import net.minecraft.registry.tag.DamageTypeTags;
import net.minecraft.util.ActionResult;
import net.minecraft.util.TypedActionResult;
import xyz.nucleoid.leukocyte.rule.ProtectionRule;
import xyz.nucleoid.leukocyte.rule.ProtectionRuleMap;
import xyz.nucleoid.stimuli.event.DroppedItemsResult;
import xyz.nucleoid.stimuli.event.EventRegistrar;
import xyz.nucleoid.stimuli.event.EventResult;
import xyz.nucleoid.stimuli.event.block.BlockBreakEvent;
import xyz.nucleoid.stimuli.event.block.BlockDropItemsEvent;
import xyz.nucleoid.stimuli.event.block.BlockPlaceEvent;
Expand Down Expand Up @@ -55,7 +56,7 @@ public void applyTo(ProtectionRuleMap rules, EventRegistrar events) {

this.forRule(events, rules.test(ProtectionRule.PVP))
.applySimple(PlayerAttackEntityEvent.EVENT, rule -> (attacker, hand, attacked, hitResult) -> {
return attacked instanceof PlayerEntity ? rule : ActionResult.PASS;
return attacked instanceof PlayerEntity ? rule : EventResult.PASS;
});

this.forRule(events, rules.test(ProtectionRule.SPECTATE_ENTITIES))
Expand All @@ -72,27 +73,27 @@ public void applyTo(ProtectionRuleMap rules, EventRegistrar events) {

this.forRule(events, rules.test(ProtectionRule.FALL_DAMAGE))
.applySimple(PlayerDamageEvent.EVENT, rule -> {
return (player, source, amount) -> source.isIn(DamageTypeTags.IS_FALL) ? rule : ActionResult.PASS;
return (player, source, amount) -> source.isIn(DamageTypeTags.IS_FALL) ? rule : EventResult.PASS;
});

this.forRule(events, rules.test(ProtectionRule.FIRE_DAMAGE))
.applySimple(PlayerDamageEvent.EVENT, rule -> {
return (player, source, amount) -> source.isIn(DamageTypeTags.IS_FIRE) && !source.isOf(DamageTypes.LAVA) ? rule : ActionResult.PASS;
return (player, source, amount) -> source.isIn(DamageTypeTags.IS_FIRE) && !source.isOf(DamageTypes.LAVA) ? rule : EventResult.PASS;
});

this.forRule(events, rules.test(ProtectionRule.FREEZING_DAMAGE))
.applySimple(PlayerDamageEvent.EVENT, rule -> {
return (player, source, amount) -> source.isIn(DamageTypeTags.IS_FREEZING) ? rule : ActionResult.PASS;
return (player, source, amount) -> source.isIn(DamageTypeTags.IS_FREEZING) ? rule : EventResult.PASS;
});

this.forRule(events, rules.test(ProtectionRule.LAVA_DAMAGE))
.applySimple(PlayerDamageEvent.EVENT, rule -> {
return (player, source, amount) -> source.isOf(DamageTypes.LAVA) ? rule : ActionResult.PASS;
return (player, source, amount) -> source.isOf(DamageTypes.LAVA) ? rule : EventResult.PASS;
});

this.forRule(events, rules.test(ProtectionRule.DAMAGE))
.applySimple(PlayerDamageEvent.EVENT, rule -> {
return (player, source, amount) -> !source.isIn(DamageTypeTags.BYPASSES_INVULNERABILITY) ? rule : ActionResult.PASS;
return (player, source, amount) -> !source.isIn(DamageTypeTags.BYPASSES_INVULNERABILITY) ? rule : EventResult.PASS;
});

this.forRule(events, rules.test(ProtectionRule.THROW_ITEMS))
Expand All @@ -101,20 +102,20 @@ public void applyTo(ProtectionRuleMap rules, EventRegistrar events) {
.applySimple(ItemPickupEvent.EVENT, rule -> (player, entity, stack) -> rule);

this.forRule(events, rules.test(ProtectionRule.SPAWN_MONSTERS))
.applySimple(EntitySpawnEvent.EVENT, rule -> entity -> entity instanceof Monster ? rule : ActionResult.PASS);
.applySimple(EntitySpawnEvent.EVENT, rule -> entity -> entity instanceof Monster ? rule : EventResult.PASS);

this.forRule(events, rules.test(ProtectionRule.SPAWN_ANIMALS))
.applySimple(EntitySpawnEvent.EVENT, rule -> entity -> entity instanceof AnimalEntity ? rule : ActionResult.PASS);
.applySimple(EntitySpawnEvent.EVENT, rule -> entity -> entity instanceof AnimalEntity ? rule : EventResult.PASS);

this.forRule(events, rules.test(ProtectionRule.THROW_PROJECTILES))
.applySimple(ItemUseEvent.EVENT, rule -> {
return (player, hand) -> {
ItemStack stack = player.getStackInHand(hand);
if (stack.isOf(Items.EGG) || stack.isOf(Items.SNOWBALL) || stack.isOf(Items.TRIDENT)) {
return TypedActionResult.fail(stack);
return ActionResult.FAIL;
}

return TypedActionResult.pass(stack);
return ActionResult.PASS;
};
});

Expand All @@ -134,16 +135,16 @@ private void applyBlockRules(ProtectionRuleMap rules, EventRegistrar events) {
this.forRule(events, rules.test(ProtectionRule.BLOCK_DROPS))
.applySimple(BlockDropItemsEvent.EVENT, rule -> {
return (breaker, world, pos, state, dropStacks) -> {
if (rule == ActionResult.FAIL) {
return new TypedActionResult<>(rule, new ArrayList<>());
} else {
return new TypedActionResult<>(rule, dropStacks);
}
return switch (rule) {
case ALLOW -> DroppedItemsResult.allow(dropStacks);
case DENY -> DroppedItemsResult.deny();
default -> DroppedItemsResult.pass(dropStacks);
};
};
});

this.forRule(events, rules.test(ProtectionRule.EXPLOSION))
.applySimple(ExplosionDetonatedEvent.EVENT, rule -> (explosion, particles) -> explosion.clearAffectedBlocks());
.applySimple(ExplosionDetonatedEvent.EVENT, rule -> (explosion, blocksToDestroy) -> rule);

this.forRule(events, rules.test(ProtectionRule.BLOCK_RANDOM_TICK))
.applySimple(BlockRandomTickEvent.EVENT, rule -> (world, pos, state) -> rule);
Expand All @@ -159,19 +160,19 @@ private void applyInteractionRules(ProtectionRuleMap rules, EventRegistrar event
var interactItems = rules.test(ProtectionRule.INTERACT_ITEMS).orElse(interact);

this.forRule(events, interactBlocks)
.applySimple(BlockUseEvent.EVENT, rule -> (player, hand, hitResult) -> rule);
.applySimple(BlockUseEvent.EVENT, rule -> (player, hand, hitResult) -> rule.asActionResult());

this.forRule(events, interactEntities)
.applySimple(EntityUseEvent.EVENT, rule -> (player, entity, hand, hitResult) -> rule);

this.forRule(events, interactItems)
.applySimple(ItemUseEvent.EVENT, rule -> (player, hand) -> new TypedActionResult<>(rule, ItemStack.EMPTY));
.applySimple(ItemUseEvent.EVENT, rule -> (player, hand) -> rule.asActionResult());
}

private void applyWorldRules(ProtectionRuleMap rules, EventRegistrar events) {
this.forRule(events, rules.test(ProtectionRule.UNSTABLE_TNT))
.applySimple(BlockPlaceEvent.AFTER, rule -> (player, world, pos, state) -> {
if (rule == ActionResult.SUCCESS && state.getBlock() == Blocks.TNT) {
if (rule == EventResult.ALLOW && state.getBlock() == Blocks.TNT) {
TntBlock.primeTnt(player.getWorld(), pos);
player.getWorld().setBlockState(pos, Blocks.AIR.getDefaultState());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package xyz.nucleoid.leukocyte.rule.enforcer;

import net.minecraft.util.ActionResult;
import xyz.nucleoid.leukocyte.rule.ProtectionRuleMap;
import xyz.nucleoid.leukocyte.rule.RuleResult;
import xyz.nucleoid.stimuli.event.EventRegistrar;
import xyz.nucleoid.stimuli.event.EventResult;
import xyz.nucleoid.stimuli.event.StimulusEvent;

public interface ProtectionRuleEnforcer {
Expand All @@ -14,13 +14,13 @@ default ForRule forRule(EventRegistrar events, RuleResult result) {
}

interface ListenerFactory<T> {
T createListener(ActionResult rule);
T createListener(EventResult rule);
}

record ForRule(EventRegistrar events, RuleResult result) {
public <T> void applySimple(StimulusEvent<T> event, ListenerFactory<T> factory) {
if (this.result.isDefinitive()) {
this.events.listen(event, factory.createListener(this.result.asActionResult()));
this.events.listen(event, factory.createListener(this.result.asEventResult()));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"depends": {
"fabricloader": ">=0.12",
"fabric": "*",
"minecraft": ">=1.21-",
"minecraft": ">=1.21.2-",
"stimuli": ">=0.4.3",
"java": ">=21"
}
Expand Down

0 comments on commit 3c9fc8e

Please sign in to comment.