Skip to content
Merged
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
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
matrix:
# Use these Java versions
java: [
21, # Current Java LTS
25, # Current Java LTS
]
runs-on: ubuntu-22.04
runs-on: ubuntu-25.10
steps:
- name: checkout repository
uses: actions/checkout@v4
Expand All @@ -30,7 +30,7 @@ jobs:
- name: build
run: ./gradlew build
- name: capture build artifacts
if: ${{ matrix.java == '21' }} # Only upload artifacts built from latest java
if: ${{ matrix.java == '25' }} # Only upload artifacts built from latest java
uses: actions/upload-artifact@v4
with:
name: Artifacts
Expand Down
13 changes: 6 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.14-SNAPSHOT'
id 'net.fabricmc.fabric-loom' version "${loom_version}"
id 'maven-publish'
}

Expand Down Expand Up @@ -33,11 +33,10 @@ loom {
dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
implementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
implementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}"
}

processResources {
Expand All @@ -49,7 +48,7 @@ processResources {
}

tasks.withType(JavaCompile).configureEach {
it.options.release = 21
it.options.release = 25
}

java {
Expand All @@ -58,8 +57,8 @@ java {
// If you remove this line, sources will not be generated.
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
sourceCompatibility = JavaVersion.VERSION_25
targetCompatibility = JavaVersion.VERSION_25
}

jar {
Expand Down
12 changes: 5 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.21.11
yarn_mappings=1.21.11+build.3
loader_version=0.18.2
loom_version=1.14-SNAPSHOT
minecraft_version=26.1.2
loader_version=0.19.2
loom_version=1.16-SNAPSHOT

# Fabric API
fabric_version=0.140.0+1.21.11

fabric_api_version=0.147.0+26.1.2
# Mod Properties
mod_version=1.1.2
mod_version=1.1.3
maven_group=com.beicekol
archives_base_name=challenge
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-9.2.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
94 changes: 76 additions & 18 deletions src/main/java/com/challenge/ChallengeCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,83 @@
import java.util.LinkedList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.challenge.challenges.BaseChallenge;

import net.minecraft.component.DataComponentTypes;
import net.minecraft.inventory.SimpleInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.text.MutableText;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.text.TextColor;
import net.minecraft.util.Unit;

public class ChallengeCollection extends SimpleInventory {
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TextColor;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.Container;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;

public class ChallengeCollection implements Container {
public static final Logger LOGGER = LoggerFactory.getLogger(ChallengeMod.MOD_ID);

private List<BaseChallenge> challenges = new LinkedList<>();
private List<ItemStack> slots = new LinkedList<>();

private boolean running = false;

public int getContainerSize() {
return 36;
}

public boolean isEmpty() {
return false;
}

public ItemStack getItem(int slot) {
if(slot >= this.slots.size()) {
return ItemStack.EMPTY;
}

return this.slots.get(slot);
}

public ItemStack removeItem(int slot, int count) {
this.toggleChallenge(slot);
return ItemStack.EMPTY;
}

public ItemStack removeItemNoUpdate(int slot) {
this.toggleChallenge(slot);
return ItemStack.EMPTY;
}

public void setItem(int slot, ItemStack itemStack) {
}

public ChallengeCollection() {
super(36);
}

public void clearContent() {
return;
}


public void addChallenge(BaseChallenge challenge) {
this.challenges.add(challenge);
ItemStack newItemStack = getItemStackForChallenge(challenge, false);
this.addStack(newItemStack);
LOGGER.info("Adding challenge: " + challenge.getName());
this.challenges.add(challenge);
ItemStack newItemStack = getItemStackForChallenge(challenge, false);
this.slots.add(newItemStack);
}

private ItemStack getItemStackForChallenge(BaseChallenge challenge, boolean enabled) {
ItemStack newItemStack = challenge.getIndicatorItemStack();
MutableText name = Text.literal(challenge.getName());
MutableComponent name = Component.literal(challenge.getName());
if(enabled) {
name.setStyle(Style.EMPTY.withColor(TextColor.parse("green").getOrThrow()).withBold(true));
name.setStyle(Style.EMPTY.withColor(TextColor.parseColor("green").getOrThrow()).withBold(true));
} else {
name.setStyle(Style.EMPTY.withColor(TextColor.parse("red").getOrThrow()).withBold(false));
name.setStyle(Style.EMPTY.withColor(TextColor.parseColor("red").getOrThrow()).withBold(false));
}
// newItemStack.set(DataComponentTypes.TOOLTIP_DISPLAY, Unit.INSTANCE);
newItemStack.set(DataComponentTypes.ITEM_NAME, name);
newItemStack.set(DataComponents.CUSTOM_NAME, name);
return newItemStack;
}

Expand All @@ -50,7 +92,7 @@ public void toggleChallenge(int slotIndex) {
if(running) challenge.start();
}
ItemStack newItemStack = getItemStackForChallenge(this.challenges.get(slotIndex), challenge.isEnabled());
this.setStack(slotIndex, newItemStack);
this.slots.set(slotIndex, newItemStack);
}

public List<BaseChallenge> getEnabledChallenges() {
Expand All @@ -76,4 +118,20 @@ public void stop() {
}
this.running = false;
}

public void setChanged() {
return;
}

public boolean stillValid(Player player) {
return true;
}

public int size() {
return this.challenges.size();
}

public BaseChallenge getChallenge(int idx) {
return this.challenges.get(idx);
}
}
75 changes: 39 additions & 36 deletions src/main/java/com/challenge/ChallengeConfigManager.java
Original file line number Diff line number Diff line change
@@ -1,50 +1,53 @@
package com.challenge;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.ShulkerBoxScreenHandler;
import net.minecraft.screen.slot.Slot;
import net.minecraft.screen.slot.SlotActionType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ChallengeConfigManager extends ShulkerBoxScreenHandler {
import com.challenge.challenges.BaseChallenge;

private ChallengeCollection inventory;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;

public ChallengeConfigManager(int syncId, PlayerInventory playerInventory, ChallengeCollection inventory) {
super(syncId, playerInventory, inventory);
this.inventory = inventory;
}
public class ChallengeConfigManager extends AbstractContainerMenu {
private static final int COLUMNS = 9;
private static final int ROWS = 6;
public static final Logger LOGGER = LoggerFactory.getLogger(ChallengeMod.MOD_ID);

public void onSlotClick(int slotIndex, int button, SlotActionType actionType, PlayerEntity player) {
// When the player is dragging items the slotIndex is -999...
if(slotIndex >= 0) {
Slot slot = this.slots.get(slotIndex);

// Make sure that the player is interacting with the challenge inventory
if(slot.inventory.equals(this.inventory)) {
// Not all slots in the challenge collection inventory might be filled with challenges
if(this.inventory.getStack(slotIndex) != ItemStack.EMPTY) {
this.inventory.toggleChallenge(slotIndex);
}
return;
}
}
// If the player did not perform any challenge configuration, they are clicking around in their inventory
// Those actions are still allowed, therefore they are passed to the default implementation
super.onSlotClick(slotIndex, button, actionType, player);
}

public boolean canInsertIntoSlot(Slot slot) {
return slot.inventory.equals(this.inventory) ? false : super.canInsertIntoSlot(slot);
private Inventory inventory;
private ChallengeCollection challengeCollection;

public ChallengeConfigManager(int containerId, Inventory Inventory, Player player, ChallengeCollection challengeCollection) {
super(MenuType.GENERIC_9x6, containerId);
this.challengeCollection = challengeCollection;

this.addChallengeGrid();
}

public ItemStack quickMove(PlayerEntity player, int slot) {
return null;

private void addChallengeGrid() {
for (int i = 0; i < COLUMNS * ROWS; i++) {
int x = i % COLUMNS;
int y = (int)(i / COLUMNS);
this.addSlot(new ChallengeSlot(challengeCollection, i, x, y));
}
}

@Override
public boolean stillValid(final Player player) {
return true;
}


@Override
public ItemStack quickMoveStack(final Player player, final int slotIndex) {
return ItemStack.EMPTY;
}

public boolean canUse(PlayerEntity player) {
public boolean canUse(Player player) {
return true;
}
}
Loading
Loading