Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Thepigcat76 committed Sep 9, 2024
2 parents 31cdbfa + debdc8b commit 58c5e77
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@ public void handleKeybindPress(Slot slot, Player player) {
public int getId() {
return -1;
}

@Override
public boolean onCooldown(Slot slot, Player player) {
return (AugmentHelper.getCooldown(player, slot)>=0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,4 @@ public int getId() {
public void breakBlock(Slot slot, BlockEvent.BreakEvent event) {
event.setCanceled(true);
}

@Override
public void clientTick(Slot slot, PlayerTickEvent.Post event) {
if (InputUtils.isKeyDown(InputConstants.KEY_Y)){
PacketDistributor.sendToServer(new KeyPressedPayload(getId(),slot.slotId));
}
}

@Override
public void handleKeybindPress(Slot slot, Player player) {
player.addItem(Items.EMERALD.getDefaultInstance());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public int getId() {

@Override
public void clientTick(Slot slot, PlayerTickEvent.Post event) {
// ModJam.LOGGER.info("ClientTick for id {}", getId());
if (InputUtils.isKeyDown(InputConstants.KEY_Y)) {
PacketDistributor.sendToServer(new KeyPressedPayload(getId(), slot.slotId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public interface StaticAugment {
void serverTick(Slot slot, PlayerTickEvent.Post event);
void handleKeybindPress(Slot slot, Player player);
int getId();
boolean onCooldown(Slot slot, Player player);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ public int getId() {

@Override
public void clientTick(Slot slot, PlayerTickEvent.Post event) {
// ModJam.LOGGER.info("ClientTick for id {}", getId());

if (InputUtils.isKeyDown(InputConstants.KEY_Y) && (AugmentHelper.getCooldown(event.getEntity(), slot)<=0)) {
// ModJam.LOGGER.info("Snow");
if (InputUtils.isKeyDown(InputConstants.KEY_Y) && !onCooldown(slot, event.getEntity())) {
PacketDistributor.sendToServer(new KeyPressedPayload(getId(), slot.slotId));
}
}
Expand All @@ -34,6 +31,6 @@ public void handleKeybindPress(Slot slot, Player player) {
snowball.setItem(Items.SNOWBALL.getDefaultInstance());
snowball.shootFromRotation(player, player.getXRot(), player.getYRot(), 0.0F, 1.5F, 1.0F);
player.level().addFreshEntity(snowball);
AugmentHelper.setCooldownAndUpdate(player, slot, 20);
AugmentHelper.setCooldownAndUpdate(player, slot, 20); // Set the cooldown, which decrements by 1 every tick
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.portingdeadmods.modjam.network;

import com.portingdeadmods.modjam.ModJam;
import com.portingdeadmods.modjam.capabilities.augmentation.Slot;
import com.portingdeadmods.modjam.content.augments.AugmentHelper;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;
import net.neoforged.neoforge.network.handling.IPayloadContext;

public record KeyPressedPayload(int augmentId, int slot) implements CustomPacketPayload {
public static final Type<KeyPressedPayload> TYPE = new Type<>(ResourceLocation.fromNamespaceAndPath(ModJam.MODID, "key_pressesd_paylad"));
Expand All @@ -21,4 +26,16 @@ public record KeyPressedPayload(int augmentId, int slot) implements CustomPacket
public Type<? extends CustomPacketPayload> type() {
return TYPE;
}

public static void keyPressedAction(KeyPressedPayload payload, IPayloadContext context){
context.enqueueWork(()->{
Player player = context.player();
int augmentId = payload.augmentId();
AugmentHelper.getAugment(augmentId).handleKeybindPress(Slot.GetValue(payload.slot()), player);
}).exceptionally(e->{
context.disconnect(Component.literal("action failed: "+ e.getMessage()));
return null;
});

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ public static void registerPayloads(final RegisterPayloadHandlersEvent event) {
registrar.playToServer(
KeyPressedPayload.TYPE,
KeyPressedPayload.STREAM_CODEC,
PayloadActions::keyPressedAction
KeyPressedPayload::keyPressedAction
);
registrar.playBidirectional(
SetAugmentDataPayload.TYPE,
SetAugmentDataPayload.STREAM_CODEC,
PayloadActions::setAugmentDataAction
SetAugmentDataPayload::setAugmentDataAction
);
registrar.playBidirectional(
SetCooldownPayload.TYPE,
SetCooldownPayload.STREAM_CODEC,
PayloadActions::setCooldownAction
SetCooldownPayload::setCooldownAction
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,25 @@

public class PayloadActions {

public static void keyPressedAction(KeyPressedPayload payload, IPayloadContext context){
context.enqueueWork(()->{
Player player = context.player();
int augmentId = payload.augmentId();

// ModJam.LOGGER.info("Sent with packetId: {}", augmentId);
AugmentHelper.getAugment(augmentId).handleKeybindPress(Slot.GetValue(payload.slot()), player);
}).exceptionally(e->{
context.disconnect(Component.literal("action failed: "+ e.getMessage()));
return null;
});

}
public static void setAugmentDataAction(SetAugmentDataPayload payload, IPayloadContext context){
context.enqueueWork(()->{
AugmentHelper.setId(context.player(), Slot.GetValue(payload.slot()), payload.augmentId());
// ModJam.LOGGER.debug("Syncing, id: {}",payload.augmentId());
});
}
public static void setCooldownAction(SetCooldownPayload payload, IPayloadContext context){
context.enqueueWork(()->{
AugmentHelper.setCooldown(context.player(), Slot.GetValue(payload.slot()), payload.cooldown());
});
}
// public static void keyPressedAction(KeyPressedPayload payload, IPayloadContext context){
// context.enqueueWork(()->{
// Player player = context.player();
// int augmentId = payload.augmentId();
// AugmentHelper.getAugment(augmentId).handleKeybindPress(Slot.GetValue(payload.slot()), player);
// }).exceptionally(e->{
// context.disconnect(Component.literal("action failed: "+ e.getMessage()));
// return null;
// });
//
// }
// public static void setAugmentDataAction(SetAugmentDataPayload payload, IPayloadContext context){
// context.enqueueWork(()->{
// AugmentHelper.setId(context.player(), Slot.GetValue(payload.slot()), payload.augmentId());
// });
// }
// public static void setCooldownAction(SetCooldownPayload payload, IPayloadContext context){
// context.enqueueWork(()->{
// AugmentHelper.setCooldown(context.player(), Slot.GetValue(payload.slot()), payload.cooldown());
// });
// }
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.portingdeadmods.modjam.network;

import com.portingdeadmods.modjam.ModJam;
import com.portingdeadmods.modjam.capabilities.augmentation.Slot;
import com.portingdeadmods.modjam.content.augments.AugmentHelper;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.neoforge.network.handling.IPayloadContext;
import org.jetbrains.annotations.NotNull;

public record SetAugmentDataPayload(int augmentId, int slot) implements CustomPacketPayload {
Expand All @@ -23,4 +26,9 @@ public record SetAugmentDataPayload(int augmentId, int slot) implements CustomPa
public @NotNull Type<? extends CustomPacketPayload> type() {
return TYPE;
}
public static void setAugmentDataAction(SetAugmentDataPayload payload, IPayloadContext context){
context.enqueueWork(()->{
AugmentHelper.setId(context.player(), Slot.GetValue(payload.slot()), payload.augmentId());
});
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.portingdeadmods.modjam.network;

import com.portingdeadmods.modjam.ModJam;
import com.portingdeadmods.modjam.capabilities.augmentation.Slot;
import com.portingdeadmods.modjam.content.augments.AugmentHelper;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.neoforge.network.handling.IPayloadContext;
import org.jetbrains.annotations.NotNull;

public record SetCooldownPayload (int cooldown, int slot)implements CustomPacketPayload {
Expand All @@ -22,4 +25,10 @@ public record SetCooldownPayload (int cooldown, int slot)implements CustomPacket
public @NotNull Type<? extends CustomPacketPayload> type() {
return TYPE;
}

public static void setCooldownAction(SetCooldownPayload payload, IPayloadContext context){
context.enqueueWork(()->{
AugmentHelper.setCooldown(context.player(), Slot.GetValue(payload.slot()), payload.cooldown());
});
}
}

0 comments on commit 58c5e77

Please sign in to comment.