Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {
}

dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1+', changing: true
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '[6.0.24,6.2)', changing: true
classpath group: 'org.spongepowered', name: 'mixingradle', version: '0.7-SNAPSHOT'
classpath group: 'gradle.plugin.com.modrinth.minotaur', name: 'Minotaur', version: '1.2.1'
classpath group: 'gradle.plugin.com.matthewprenger', name: 'CurseGradle', version: '1.4.0'
Expand All @@ -19,7 +19,7 @@ buildscript {

plugins {
id 'maven-publish'
id 'net.minecraftforge.gradle' version '5.1.+'
id 'net.minecraftforge.gradle' version '[6.0.24,6.2)'
id 'org.parchmentmc.librarian.forgegradle' version '1.+'
}

Expand Down Expand Up @@ -55,7 +55,7 @@ version = config.VERSION
group = "${config.GROUP}.${config.ARTIFACT}"
archivesBaseName = "${config.ARCHIVES_BASE_NAME}-${config.MINECRAFT_VERSION}"

java.toolchain.languageVersion = JavaLanguageVersion.of(17)
java.toolchain.languageVersion = JavaLanguageVersion.of(21)

minecraft {
mappings channel: config.MAPPINGS_CHANNEL, version: config.MAPPINGS_VERSION
Expand Down Expand Up @@ -120,6 +120,7 @@ repositories {
dependencies {
minecraft "net.minecraftforge:forge:${config.MINECRAFT_VERSION}-${config.FORGE_VERSION}"
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
implementation('net.sf.jopt-simple:jopt-simple:5.0.4') { version { strictly '5.0.4' } }
}

jar {
Expand Down Expand Up @@ -222,3 +223,9 @@ idea {
downloadSources = true
}
}

sourceSets.each {
def dir = layout.buildDirectory.dir("sourcesSets/$it.name")
it.output.resourcesDir = dir
it.java.destinationDirectory = dir
}
6 changes: 3 additions & 3 deletions build.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
VERSION=1.2.0
MINECRAFT_VERSION=1.20.1
FORGE_VERSION=47.1.0
MINECRAFT_VERSION=1.21.1
FORGE_VERSION=52.0.38
MAPPINGS_CHANNEL=parchment
MAPPINGS_VERSION=2023.07.30-1.20.1
MAPPINGS_VERSION=2024.11.17-1.21.1

GROUP=org.infernalstudios
ARTIFACT=shieldexp
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
19 changes: 12 additions & 7 deletions gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
pluginManagement {
repositories {
gradlePluginPortal()
maven { url = 'https://maven.minecraftforge.net/' }
maven {
name = 'MinecraftForge'
url = 'https://maven.minecraftforge.net/'
}
maven { url = 'https://maven.parchmentmc.org' }
}
}

plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public class ShieldExpansion {
public static final String MOD_ID = "shieldexp";
public static final Logger LOGGER = LogManager.getLogger(NAME);

public ShieldExpansion() {
IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus();
public ShieldExpansion(FMLJavaModLoadingContext context) {
IEventBus modBus = context.getModEventBus();
ItemsInit.ITEMS.register(modBus);
SoundsInit.SOUND_EVENTS.register(modBus);

ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, Config.CONFIG, "ShieldExpansion-common.toml");
context.registerConfig(ModConfig.Type.COMMON, Config.CONFIG, "ShieldExpansion-common.toml");

modBus.addListener(this::clientSetup);
modBus.addListener(this::commonSetup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static void register() {
BetterCombatClientEvents.ATTACK_START.register((LocalPlayer player, AttackHand hand) -> {
Item item = player.getOffhandItem().getItem();
if (Boolean.TRUE.equals(Config.isShield(item))) {
player.getAttribute(Attributes.MOVEMENT_SPEED).removeModifier(player.getUUID());
player.getAttribute(Attributes.MOVEMENT_SPEED).removeModifiers();
LivingEntityAccess.get(player).setBlocking(false);
LivingEntityAccess.get(player).setParryWindow(0);
if (!player.getCooldowns().isOnCooldown(item))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static void setup() {
private static void initShields() {
ItemPropertyFunction blockFn = (stack, world, entity, seed) -> entity != null && entity.isUsingItem() && entity.getUseItem() == stack ? 1.0F : 0.0F;
for (RegistryObject<ShieldItem> shieldItem : ItemsInit.SHIELDS)
ItemProperties.register(shieldItem.get(), new ResourceLocation("minecraft:blocking"), blockFn);
ItemProperties.register(shieldItem.get(), ResourceLocation.parse("minecraft:blocking"), blockFn);
}

//desyncs from the server to allow the player to attack despite currently blocking, state is resynced on server-side useTick
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
Expand Down Expand Up @@ -53,8 +54,8 @@ public void onStartUsing(LivingEntityUseItemEvent.Start event) {
LivingEntityAccess.get(player).setParryWindow(parryTicks);
LivingEntityAccess.get(player).setBlockedCooldown(10);
LivingEntityAccess.get(player).setUsedStamina(0);
AttributeModifier speedModifier = new AttributeModifier(player.getUUID() , "Blocking Speed", 4.0*getShieldValue(item, "speedFactor"), AttributeModifier.Operation.MULTIPLY_TOTAL);
if (!player.getAttribute(Attributes.MOVEMENT_SPEED).hasModifier(speedModifier) && !Config.speedModifierDisabled())
AttributeModifier speedModifier = new AttributeModifier(ResourceLocation.parse("blockingspeed"), 4.0*getShieldValue(item, "speedFactor"), AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL);
if (!player.getAttribute(Attributes.MOVEMENT_SPEED).hasModifier(ResourceLocation.parse("blockingspeed")) && !Config.speedModifierDisabled())
player.getAttribute(Attributes.MOVEMENT_SPEED).addTransientModifier(speedModifier);
if (!LivingEntityAccess.get(player).getBlocking())
LivingEntityAccess.get(player).setBlocking(true);
Expand Down Expand Up @@ -164,7 +165,7 @@ public void onProjectileImpact(ProjectileImpactEvent event) {
damageItem(player, 1);
stamina(player, item, 1);
}
event.setCanceled(true);
event.setImpactResult(ProjectileImpactEvent.ImpactResult.STOP_AT_CURRENT_NO_DAMAGE);
}
}

Expand Down Expand Up @@ -231,7 +232,7 @@ public void onExplosionImpact(LivingAttackEvent event) {

//removes the blocking state
public void removeBlocking(Player player) {
player.getAttribute(Attributes.MOVEMENT_SPEED).removeModifier(player.getUUID());
player.getAttribute(Attributes.MOVEMENT_SPEED).removeModifier(ResourceLocation.parse("blockingspeed"));
if (LivingEntityAccess.get(player).getBlocking())
LivingEntityAccess.get(player).setBlocking(false);
LivingEntityAccess.get(player).setParryWindow(0);
Expand Down Expand Up @@ -267,10 +268,6 @@ public void stamina(Player player, Item item, int stamina) {

//reduces durability of the given player's used shield, and removes the blocking state if it breaks
public void damageItem(Player player, int amount) {
player.getUseItem().hurtAndBreak(amount, player, (player1) -> {
player1.broadcastBreakEvent(player.getUsedItemHand() == InteractionHand.MAIN_HAND ? EquipmentSlot.MAINHAND : EquipmentSlot.OFFHAND);
removeBlocking(player);
player.stopUsingItem();
});
player.getUseItem().hurtAndBreak(amount, player, player.getUsedItemHand() == InteractionHand.MAIN_HAND ? EquipmentSlot.MAINHAND : EquipmentSlot.OFFHAND);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.infernalstudios.shieldexp.init;

import net.minecraft.core.registries.Registries;
import net.minecraft.data.worldgen.BootstapContext;
import net.minecraft.data.worldgen.BootstrapContext;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.damagesource.DamageType;

public class DamageTypesInit {
public static final ResourceKey<DamageType> PARTIALBLAST = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation("shieldexp", "partialblast"));
public static final ResourceKey<DamageType> PARTIALBLAST = ResourceKey.create(Registries.DAMAGE_TYPE, ResourceLocation.fromNamespaceAndPath("shieldexp", "partialblast"));

public static void bootstrap(BootstapContext<DamageType> context) { context.register(PARTIALBLAST, new DamageType("partialblast", 0.1F)); }
public static void bootstrap(BootstrapContext<DamageType> context) { context.register(PARTIALBLAST, new DamageType("partialblast", 0.1F)); }
}
23 changes: 14 additions & 9 deletions src/main/java/org/infernalstudios/shieldexp/init/NetworkInit.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
package org.infernalstudios.shieldexp.init;

import com.mojang.blaze3d.platform.InputConstants;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.network.ChannelBuilder;
import net.minecraftforge.network.NetworkDirection;
import net.minecraftforge.network.NetworkRegistry;
import net.minecraftforge.network.simple.SimpleChannel;
import net.minecraftforge.network.SimpleChannel;
import org.infernalstudios.shieldexp.ShieldExpansion;
import org.infernalstudios.shieldexp.network.ClearShields;
import org.infernalstudios.shieldexp.network.SyncShields;

public class NetworkInit {
public static SimpleChannel INSTANCE;
private static int ID = 0;

public static int nextID() {
return ID++;
}

public static void registerPackets() {
INSTANCE = NetworkRegistry.newSimpleChannel(new ResourceLocation(ShieldExpansion.MOD_ID, "packets"), () -> "1.0", s -> true, s -> true);
INSTANCE = ChannelBuilder.named(ResourceLocation.fromNamespaceAndPath(ShieldExpansion.MOD_ID, "packets"))
.optional()
.acceptedVersions((status, version) -> true)
.networkProtocolVersion(1)
.simpleChannel();

INSTANCE.registerMessage(nextID(), SyncShields.class, SyncShields::encode, SyncShields::new, SyncShields::handle);
INSTANCE.messageBuilder(SyncShields.class, NetworkDirection.PLAY_TO_CLIENT).encoder(SyncShields::encode).decoder(SyncShields::new).consumerNetworkThread(SyncShields::handle).add();

// TODO Delete - This is only kept here so the network isn't angry
INSTANCE.registerMessage(nextID(), ClearShields.class, ClearShields::encode, ClearShields::new, ClearShields::handle);
INSTANCE.messageBuilder(ClearShields.class, NetworkDirection.PLAY_TO_CLIENT).encoder(ClearShields::encode).decoder(ClearShields::new).consumerNetworkThread(ClearShields::handle).add();

MinecraftForge.EVENT_BUS.register(new NetworkInit());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ public static void syncShieldsOnJoin(PlayerEvent.PlayerLoggedInEvent event) {
Player player = event.getEntity();

if (!player.level().isClientSide()){
NetworkInit.INSTANCE.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new ClearShields());
NetworkInit.INSTANCE.send(new ClearShields(), PacketDistributor.PLAYER.with((ServerPlayer) player));

for (Map.Entry<ResourceLocation, JsonElement> file : toSync){
NetworkInit.INSTANCE.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new SyncShields(file.getKey(), file.getValue()));
NetworkInit.INSTANCE.send(new SyncShields(file.getKey(), file.getValue()), PacketDistributor.PLAYER.with((ServerPlayer) player));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class SoundsInit {
public static final RegistryObject<SoundEvent> PARRY_SOUND = registerSoundEvent("parry_sound");

private static RegistryObject<SoundEvent> registerSoundEvent(String name) {
ResourceLocation id = new ResourceLocation(ShieldExpansion.MOD_ID, name);
ResourceLocation id = ResourceLocation.fromNamespaceAndPath(ShieldExpansion.MOD_ID, name);
return SOUND_EVENTS.register(name, () -> SoundEvent.createVariableRangeEvent(id));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ public LivingEntityMixin(EntityType<?> type, Level world) {

@Inject(method = "isBlocking", at = @At(value = "RETURN", ordinal = 1), cancellable = true)
private void shieldexp$isBlocking(CallbackInfoReturnable<Boolean> ci) {
ci.setReturnValue(this.useItem.getItem().getUseDuration(this.useItem) - this.useItemRemaining >= 0);
ci.setReturnValue(this.useItem.getItem().getUseDuration(this.useItem, (LivingEntity) (Object) this) - this.useItemRemaining >= 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ protected PlayerMixin(EntityType<? extends LivingEntity> entityType, Level world
}

@Inject(method = "defineSynchedData", at = @At("TAIL"))
private void shieldexp$defineSynchedData(CallbackInfo ci) {
this.entityData.define(PARRY_COOLDOWN, 0);
this.entityData.define(BLOCKED_COOLDOWN, 0);
this.entityData.define(USED_STAMINA, 0);
this.entityData.define(LAST_SHIELD, new ItemStack(Items.AIR));
this.entityData.define(IS_BLOCKING, false);
private void shieldexp$defineSynchedData(SynchedEntityData.Builder pBuilder, CallbackInfo ci) {
pBuilder.define(PARRY_COOLDOWN, 0);
pBuilder.define(BLOCKED_COOLDOWN, 0);
pBuilder.define(USED_STAMINA, 0);
pBuilder.define(LAST_SHIELD, new ItemStack(Items.AIR));
pBuilder.define(IS_BLOCKING, false);
}

@Inject(method = "tick", at = @At("TAIL"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.infernalstudios.shieldexp.network;

import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.network.NetworkEvent;

import java.util.function.Supplier;
import net.minecraftforge.event.network.CustomPayloadEvent;

// TODO Delete - This is only kept here so the network isn't angry
public class ClearShields {
Expand All @@ -16,7 +14,7 @@ public void encode(FriendlyByteBuf buf){
public ClearShields() {
}

public void handle(Supplier<NetworkEvent.Context> ctx){
ctx.get().setPacketHandled(true);
public void handle(CustomPayloadEvent.Context ctx){
ctx.setPacketHandled(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.minecraft.util.GsonHelper;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.network.NetworkEvent;
import net.minecraftforge.event.network.CustomPayloadEvent;
import org.infernalstudios.shieldexp.init.ShieldDataLoader;

import java.util.function.Supplier;
Expand All @@ -31,9 +31,9 @@ public SyncShields(ResourceLocation shield, JsonElement data){
this.data = data;
}

public void handle(Supplier<NetworkEvent.Context> ctx){
ctx.get().enqueueWork(this::handle);
ctx.get().setPacketHandled(true);
public void handle(CustomPayloadEvent.Context ctx){
ctx.enqueueWork(this::handle);
ctx.setPacketHandled(true);
}

@OnlyIn(Dist.CLIENT)
Expand Down
Loading