-
Notifications
You must be signed in to change notification settings - Fork 10
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
27 changed files
with
527 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package dev.enjarai.trickster; | ||
|
||
import dev.enjarai.trickster.item.ModItems; | ||
import dev.enjarai.trickster.net.MladyPacket; | ||
import dev.enjarai.trickster.net.ModNetworking; | ||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; | ||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; | ||
import net.minecraft.client.option.KeyBinding; | ||
import net.minecraft.entity.EquipmentSlot; | ||
import org.lwjgl.glfw.GLFW; | ||
|
||
public class ModKeyBindings { | ||
public static final KeyBinding TAKE_HAT = new KeyBinding("key.trickster.take_hat", GLFW.GLFW_KEY_G, "trickster"); | ||
|
||
public static void register() { | ||
KeyBindingHelper.registerKeyBinding(TAKE_HAT); | ||
|
||
ClientTickEvents.END_CLIENT_TICK.register(client -> { | ||
var player = client.player; | ||
if (player != null && client.currentScreen == null) { | ||
if (TAKE_HAT.isPressed()) { | ||
if (player.getEquippedStack(EquipmentSlot.HEAD).isIn(ModItems.HOLDABLE_HAT) && player.getEquippedStack(EquipmentSlot.OFFHAND).isEmpty()) { | ||
ModNetworking.MLADY.clientHandle().send(new MladyPacket(true)); | ||
} | ||
} else { | ||
if (player.getEquippedStack(EquipmentSlot.HEAD).isEmpty() && player.getOffHandStack().isIn(ModItems.HOLDABLE_HAT)) { | ||
ModNetworking.MLADY.clientHandle().send(new MladyPacket(false)); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
src/client/java/dev/enjarai/trickster/screen/ScrollContainerScreen.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,36 @@ | ||
package dev.enjarai.trickster.screen; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.gui.DrawContext; | ||
import net.minecraft.client.gui.screen.ingame.HandledScreen; | ||
import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider; | ||
import net.minecraft.entity.player.PlayerInventory; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Identifier; | ||
|
||
@Environment(EnvType.CLIENT) | ||
public class ScrollContainerScreen extends HandledScreen<ScrollContainerScreenHandler> implements ScreenHandlerProvider<ScrollContainerScreenHandler> { | ||
private static final Identifier TEXTURE = Identifier.ofVanilla("textures/gui/container/generic_54.png"); | ||
private final int rows; | ||
|
||
public ScrollContainerScreen(ScrollContainerScreenHandler handler, PlayerInventory inventory, Text title) { | ||
super(handler, inventory, title); | ||
this.rows = handler.getRows(); | ||
this.backgroundHeight = 114 + this.rows * 18; | ||
this.playerInventoryTitleY = this.backgroundHeight - 94; | ||
} | ||
|
||
public void render(DrawContext context, int mouseX, int mouseY, float delta) { | ||
super.render(context, mouseX, mouseY, delta); | ||
this.drawMouseoverTooltip(context, mouseX, mouseY); | ||
} | ||
|
||
protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) { | ||
int i = (this.width - this.backgroundWidth) / 2; | ||
int j = (this.height - this.backgroundHeight) / 2; | ||
context.drawTexture(TEXTURE, i, j, 0, 0, this.backgroundWidth, this.rows * 18 + 17); | ||
context.drawTexture(TEXTURE, i, j + this.rows * 18 + 17, 0, 126, this.backgroundWidth, 96); | ||
} | ||
} | ||
|
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
50 changes: 50 additions & 0 deletions
50
src/main/java/dev/enjarai/trickster/item/EvaluationMirrorItem.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,50 @@ | ||
package dev.enjarai.trickster.item; | ||
|
||
import dev.enjarai.trickster.item.component.ModComponents; | ||
import dev.enjarai.trickster.item.component.SpellComponent; | ||
import dev.enjarai.trickster.screen.ScrollAndQuillScreenHandler; | ||
import dev.enjarai.trickster.spell.SpellPart; | ||
import net.minecraft.entity.EquipmentSlot; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.entity.player.PlayerInventory; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.screen.NamedScreenHandlerFactory; | ||
import net.minecraft.screen.ScreenHandler; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Hand; | ||
import net.minecraft.util.TypedActionResult; | ||
import net.minecraft.world.World; | ||
|
||
public class EvaluationMirrorItem extends Item { | ||
public EvaluationMirrorItem(Settings settings) { | ||
super(settings); | ||
} | ||
|
||
@Override | ||
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) { | ||
var stack = user.getStackInHand(hand); | ||
var otherStack = user.getStackInHand(hand == Hand.MAIN_HAND ? Hand.OFF_HAND : Hand.MAIN_HAND); | ||
|
||
if (!user.isSneaking()) { | ||
user.openHandledScreen(new NamedScreenHandlerFactory() { | ||
@Override | ||
public Text getDisplayName() { | ||
return Text.translatable("trickster.screen.mirror_of_evaluation"); | ||
} | ||
|
||
@Override | ||
public ScreenHandler createMenu(int syncId, PlayerInventory playerInventory, PlayerEntity player) { | ||
return new ScrollAndQuillScreenHandler( | ||
syncId, playerInventory, stack, otherStack, | ||
hand == Hand.MAIN_HAND ? EquipmentSlot.MAINHAND : EquipmentSlot.OFFHAND, true | ||
); | ||
} | ||
}); | ||
} else { | ||
stack.set(ModComponents.SPELL, new SpellComponent(new SpellPart())); | ||
} | ||
|
||
return TypedActionResult.success(stack); | ||
} | ||
} |
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
30 changes: 30 additions & 0 deletions
30
src/main/java/dev/enjarai/trickster/item/TrickHatItem.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,30 @@ | ||
package dev.enjarai.trickster.item; | ||
|
||
import net.minecraft.entity.EquipmentSlot; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.Equipment; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.Hand; | ||
import net.minecraft.util.TypedActionResult; | ||
import net.minecraft.world.World; | ||
|
||
public class TrickHatItem extends Item implements Equipment { | ||
public TrickHatItem(Settings settings) { | ||
super(settings); | ||
} | ||
|
||
@Override | ||
public EquipmentSlot getSlotType() { | ||
return EquipmentSlot.HEAD; | ||
} | ||
|
||
@Override | ||
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) { | ||
var stack = user.getStackInHand(hand); | ||
|
||
// TODO | ||
|
||
return TypedActionResult.success(stack); | ||
} | ||
} |
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,4 @@ | ||
package dev.enjarai.trickster.net; | ||
|
||
public record MladyPacket(boolean hold) { | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/dev/enjarai/trickster/net/ModNetworking.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,32 @@ | ||
package dev.enjarai.trickster.net; | ||
|
||
import dev.enjarai.trickster.Trickster; | ||
import dev.enjarai.trickster.item.ModItems; | ||
import io.wispforest.owo.network.OwoNetChannel; | ||
import net.minecraft.entity.EquipmentSlot; | ||
import net.minecraft.item.ItemStack; | ||
|
||
public class ModNetworking { | ||
public static final OwoNetChannel MLADY = OwoNetChannel.create(Trickster.id("mlady")); | ||
|
||
public static void register() { | ||
MLADY.registerServerbound(MladyPacket.class, (packet, access) -> { | ||
var player = access.player(); | ||
var inventory = player.getInventory(); | ||
|
||
if (packet.hold()) { | ||
if (player.getEquippedStack(EquipmentSlot.HEAD).isIn(ModItems.HOLDABLE_HAT) && player.getOffHandStack().isEmpty()) { | ||
var headStack = inventory.getArmorStack(EquipmentSlot.HEAD.getEntitySlotId()); | ||
inventory.armor.set(EquipmentSlot.HEAD.getEntitySlotId(), ItemStack.EMPTY); | ||
inventory.offHand.set(0, headStack); | ||
} | ||
} else { | ||
if (player.getEquippedStack(EquipmentSlot.HEAD).isEmpty() && player.getOffHandStack().isIn(ModItems.HOLDABLE_HAT)) { | ||
var offHandStack = inventory.offHand.getFirst(); | ||
inventory.offHand.set(0, ItemStack.EMPTY); | ||
inventory.armor.set(EquipmentSlot.HEAD.getEntitySlotId(), offHandStack); | ||
} | ||
} | ||
}); | ||
} | ||
} |
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
Oops, something went wrong.