Skip to content

Commit

Permalink
Merge pull request #144 from FTBTeam/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
desht authored Jun 10, 2024
2 parents 102dd3e + 9bcce47 commit 0f450c8
Show file tree
Hide file tree
Showing 35 changed files with 259 additions and 383 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
with:
curse-publish-task: ""
maven-snapshots: true
java-version: 21
secrets:
ftb-maven-token: ${{ secrets.FTB_MAVEN_TOKEN }}
saps-token: ${{ secrets.SAPS_TOKEN }}
saps-token: ${{ secrets.SAPS_TOKEN }}
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
uses: FTBTeam/mods-meta/.github/workflows/standard-release.yml@main
with:
curse-publish-task: publishMods
java-version: 21
secrets:
ftb-maven-token: ${{ secrets.FTB_MAVEN_TOKEN }}
saps-token: ${{ secrets.SAPS_TOKEN }}
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2006.1.0]

### Changed
* Ported to Minecraft 1.20.6. Support for Fabric and NeoForge.
* Forge support may be re-added if/when Architectury adds support for Forge

## [2004.1.0]

### Added
Expand Down
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
# FTB Ultimine
# FTB Ultimine

## Tags

### Item Tags

* `ftbultimine:excluded_tools` - items in this tag can't be used for ultimining (applies to main hand slot)
* `ftbultimine:excluded_tools/strict` - items in this tag can't be used for ultimining (applies to main _and_ offhand slots)
* `ftbultimine:included_tools` - if `require_tool` is true in server config, by default only "tool" items can be used (tiered items with durability); this can be used to allow extra items

### Block Tags

* `ftbultimine:excluded_blocks` - blocks in this tag may never be ultimined
* `ftbultimine:block_whitelist` - if this tag is non-empty, then _only_ blocks in this tag may be ultimined
* `ftbultimine:farmland_tillable` - blocks in this tag can be ultimine-tilled with a hoe tool; includes grass & dirt blocks by default
* `ftbultimine:shovel_flattenable` - blocks in this tag can be ultimine-flattened (turned to dirt path) with a shovel tool; includes grass & dirt blocks by default

## FTB Ranks Integration

Following nodes can be configured via [FTB Ranks](https://www.curseforge.com/minecraft/mc-mods/ftb-ranks-forge):

* `ftbultimine.max_blocks` - if present in a player's rank, overrides the server `max_blocks` config setting
* `ftbultimine.ultimine_cooldown` - if present in a player's rank, overrides the server `ultimine_cooldown` setting
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.5-SNAPSHOT" apply false
id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false
id "me.modmuss50.mod-publish-plugin" version "0.4.5"
}

Expand Down Expand Up @@ -34,7 +34,7 @@ allprojects {
// needs to be done AFTER version is set
apply from: "https://raw.githubusercontent.com/FTBTeam/mods-meta/main/gradle/publishing.gradle"

sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = 17
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = 21

compileJava {
options.encoding = "UTF-8"
Expand Down Expand Up @@ -106,7 +106,7 @@ publishMods {

// TODO: Migrate to something else
def tag = providers.environmentVariable("TAG").getOrElse("release")
type = tag == "release" ? STABLE : (tag == "beta" ? BETA : ALPHA)
type = tag == "beta" ? BETA : (tag == "alpha" ? ALPHA : STABLE)

def createOptions = (String projectName) -> {
publishOptions {
Expand Down
24 changes: 1 addition & 23 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies {
def ENV = System.getenv()

architectury {
common("forge", "fabric", "neoforge")
common(/* "forge", */ "fabric", "neoforge")
}

configurations {
Expand All @@ -31,26 +31,4 @@ publishing {
from components.java
}
}

repositories {
if (ftbPublishing.ftbToken) {
maven {
url ftbPublishing.ftbURL
credentials {
username = ftbPublishing.ftbUser
password = ftbPublishing.ftbToken
}
}
}

if (ftbPublishing.sapsToken) {
maven {
url ftbPublishing.sapsURL
credentials {
username = ftbPublishing.sapsUser
password = ftbPublishing.sapsToken
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@

import java.util.function.Consumer;

public class BrokenItemHandler implements Consumer<ServerPlayer> {
public class BrokenItemHandler implements Runnable {
private final ServerPlayer player;
public boolean isBroken = false;

@Override
public void accept(ServerPlayer player) {
public BrokenItemHandler(ServerPlayer player) {
this.player = player;
}

@Override
public void run() {
isBroken = true;
player.broadcastBreakEvent(EquipmentSlot.MAINHAND);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.ftb.mods.ftbultimine;

import dev.architectury.networking.NetworkManager;
import dev.ftb.mods.ftbultimine.config.FTBUltimineServerConfig;
import dev.ftb.mods.ftbultimine.net.SyncUltimineTimePacket;
import dev.ftb.mods.ftbultimine.net.SyncUltimineTimePacket.TimeType;
Expand Down Expand Up @@ -30,7 +31,7 @@ public static void setLastUltimineTime(Player player, long when) {
CooldownTracker instance = player.level().isClientSide ? clientInstance : serverInstance;
instance.lastUltimineTime.put(player.getUUID(), when);
if (player instanceof ServerPlayer sp) {
new SyncUltimineTimePacket(when, TimeType.LAST_USED).sendTo(sp);
NetworkManager.sendToPlayer(sp, new SyncUltimineTimePacket(when, TimeType.LAST_USED));
}
}

Expand Down
19 changes: 11 additions & 8 deletions common/src/main/java/dev/ftb/mods/ftbultimine/FTBUltimine.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dev.architectury.event.EventResult;
import dev.architectury.event.events.common.*;
import dev.architectury.hooks.level.entity.PlayerHooks;
import dev.architectury.networking.NetworkManager;
import dev.architectury.platform.Platform;
import dev.architectury.registry.ReloadListenerRegistry;
import dev.architectury.utils.EnvExecutor;
Expand Down Expand Up @@ -83,6 +84,7 @@ public static void setPermissionOverride(Predicate<Player> p) {

public FTBUltimine() {
instance = this;

FTBUltimineNet.init();

if (Platform.isModLoaded("ftbranks")) {
Expand Down Expand Up @@ -120,8 +122,8 @@ public FTBUltiminePlayerData getOrCreatePlayerData(Player player) {
private void playerJoined(ServerPlayer serverPlayer) {
SNBTCompoundTag config = new SNBTCompoundTag();
FTBUltimineServerConfig.CONFIG.write(config);
new SyncConfigFromServerPacket(config).sendTo(serverPlayer);
new SyncUltimineTimePacket(FTBUltimineServerConfig.getUltimineCooldown(serverPlayer), TimeType.COOLDOWN).sendTo(serverPlayer);
NetworkManager.sendToPlayer(serverPlayer, new SyncConfigFromServerPacket(config));
NetworkManager.sendToPlayer(serverPlayer, new SyncUltimineTimePacket(FTBUltimineServerConfig.getUltimineCooldown(serverPlayer), TimeType.COOLDOWN));
}

private void serverStarting(MinecraftServer server) {
Expand All @@ -136,15 +138,15 @@ public void setKeyPressed(ServerPlayer player, boolean pressed) {
data.clearCache();

if (!data.isPressed()) {
new SendShapePacket(data.getCurrentShapeIndex(), Collections.emptyList()).sendTo(player);
NetworkManager.sendToPlayer(player, new SendShapePacket(data.getCurrentShapeIndex(), Collections.emptyList()));
}
}

public void modeChanged(ServerPlayer player, boolean next) {
FTBUltiminePlayerData data = getOrCreatePlayerData(player);
data.cycleShape(next);
data.clearCache();
new SendShapePacket(data.getCurrentShapeIndex(), Collections.emptyList()).sendTo(player);
NetworkManager.sendToPlayer(player, new SendShapePacket(data.getCurrentShapeIndex(), Collections.emptyList()));
}

/**
Expand Down Expand Up @@ -248,8 +250,9 @@ public EventResult blockBroken(Level world, BlockPos pos, BlockState state, Serv
ItemStack stack = player.getMainHandItem();
if (hadItem && stack.isEmpty()) {
break;
} else if (hadItem && stack.hasTag() && stack.getTag().getBoolean("tic_broken")) {
break;
// TODO update this if & when Tinkers updates to 1.20.6+
// } else if (hadItem && stack.hasTag() && stack.getTag().getBoolean("tic_broken")) {
// break;
} else if (hadItem && FTBUltimineServerConfig.PREVENT_TOOL_BREAK.get() > 0 && stack.isDamageableItem() && stack.getDamageValue() >= stack.getMaxDamage() - FTBUltimineServerConfig.PREVENT_TOOL_BREAK.get()) {
break;
}
Expand All @@ -271,7 +274,7 @@ public EventResult blockBroken(Level world, BlockPos pos, BlockState state, Serv
}

data.clearCache();
new SendShapePacket(data.getCurrentShapeIndex(), Collections.emptyList()).sendTo(player);
NetworkManager.sendToPlayer(player, new SendShapePacket(data.getCurrentShapeIndex(), Collections.emptyList()));

return EventResult.interruptFalse();
}
Expand Down Expand Up @@ -354,7 +357,7 @@ public EventResult entityJoinedWorld(Entity entity, Level level) {
return EventResult.pass();
}

public static ResourceLocation id(String path) {
public static ResourceLocation rl(String path) {
return new ResourceLocation(MOD_ID, path);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.ftb.mods.ftbultimine;

import com.mojang.brigadier.CommandDispatcher;
import dev.architectury.networking.NetworkManager;
import dev.ftb.mods.ftbultimine.net.EditConfigPacket;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack;
Expand All @@ -14,14 +15,14 @@ public static void registerCommands(CommandDispatcher<CommandSourceStack> dispat
.then(Commands.literal("serverconfig")
.requires(sourceStack -> sourceStack.isPlayer() && sourceStack.hasPermission(2))
.executes(context -> {
new EditConfigPacket(false).sendTo(Objects.requireNonNull(context.getSource().getPlayer()));
NetworkManager.sendToPlayer(context.getSource().getPlayerOrException(), new EditConfigPacket(false));
return 1;
})
)
.then(Commands.literal("clientconfig")
.requires(CommandSourceStack::isPlayer)
.executes(context -> {
new EditConfigPacket(true).sendTo(Objects.requireNonNull(context.getSource().getPlayer()));
NetworkManager.sendToPlayer(context.getSource().getPlayerOrException(), new EditConfigPacket(true));
return 1;
})
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package dev.ftb.mods.ftbultimine;

import dev.architectury.networking.NetworkManager;
import dev.ftb.mods.ftbultimine.config.FTBUltimineServerConfig;
import dev.ftb.mods.ftbultimine.net.SendShapePacket;
import dev.ftb.mods.ftbultimine.shape.BlockMatcher;
import dev.ftb.mods.ftbultimine.shape.Shape;
import dev.ftb.mods.ftbultimine.shape.ShapeContext;
import dev.ftb.mods.ftbultimine.shape.ShapeRegistry;
import dev.ftb.mods.ftbultimine.utils.PlatformMethods;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
Expand Down Expand Up @@ -65,7 +66,7 @@ public Collection<BlockPos> cachedPositions() {
}

public static HitResult rayTrace(ServerPlayer player) {
double distance = PlatformMethods.reach(player);
double distance = player.getAttributeValue(Attributes.BLOCK_INTERACTION_RANGE);
return player.pick(player.isCreative() ? distance + 0.5D : distance, 1F, false);
}

Expand Down Expand Up @@ -116,7 +117,7 @@ public void checkBlocks(ServerPlayer player, boolean sendUpdate, int maxBlocks)
clearCache();

if (sendUpdate) {
new SendShapePacket(getCurrentShapeIndex(), Collections.emptyList()).sendTo(player);
NetworkManager.sendToPlayer(player, new SendShapePacket(getCurrentShapeIndex(), Collections.emptyList()));
}
}

Expand Down Expand Up @@ -159,7 +160,7 @@ public ShapeContext updateBlocks(ServerPlayer player, BlockPos pos, Direction di
}

if (sendUpdate) {
new SendShapePacket(getCurrentShapeIndex(), cachedBlocks).sendTo(player);
NetworkManager.sendToPlayer(player, new SendShapePacket(getCurrentShapeIndex(), cachedBlocks));
}

return context;
Expand Down
67 changes: 38 additions & 29 deletions common/src/main/java/dev/ftb/mods/ftbultimine/ItemCollection.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package dev.ftb.mods.ftbultimine;

import dev.ftb.mods.ftbultimine.utils.ItemUtils;
import net.minecraft.core.BlockPos;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class ItemCollection {
private final List<ItemStack> items = new ArrayList<>();
Expand Down Expand Up @@ -56,40 +54,51 @@ public void drop(Level world, BlockPos pos) {
}

private ItemStack insert(List<ItemStack> stacks, ItemStack stack, int slot) {
ItemStack existing = stacks.get(slot);

if (stack.isEmpty() || existing.isEmpty() || stack.getItem() != existing.getItem()) {
return stack;
if (stack.isEmpty()) {
return ItemStack.EMPTY; // degenerate case
}

// intellij doesn't like that we throw something here
//noinspection ConstantConditions
if (!stack.isStackable() || !Objects.equals(stack.getTag(), existing.getTag()) || !ItemUtils.areCompatible(stack, existing)) {
return stack;
}

int limit = stack.getMaxStackSize();

if (!existing.isEmpty()) {
if (!ItemUtils.canItemStacksStack(stack, existing)) {
return stack;
}
ItemStack existing = stacks.get(slot);

limit -= existing.getCount();
if (existing.isEmpty()) {
// trivial case, just put the stack in the slot
stacks.set(slot, stack.copy());
return ItemStack.EMPTY;
}

if (limit <= 0) {
if (!stack.isStackable() || !ItemStack.isSameItemSameComponents(stack, existing)) {
// stack doesn't fit here
return stack;
}

boolean reachedLimit = stack.getCount() > limit;

if (existing.isEmpty()) {
stacks.set(slot, reachedLimit ? stack.copyWithCount(limit) : stack);
} else {
existing.grow(reachedLimit ? limit : stack.getCount());
}

return reachedLimit ? stack.copyWithCount(stack.getCount() - limit) : ItemStack.EMPTY;
// the slot is not empty, and is compatible with the stack to be inserted
// - so at least some of it can be inserted
int available = stack.getMaxStackSize() - existing.getCount();
int toAdd = Math.min(available, stack.getCount());
existing.grow(toAdd);

return toAdd == stack.getCount() ? ItemStack.EMPTY : stack.copyWithCount(stack.getCount() - toAdd);

// if (!existing.isEmpty()) {
// if (!ItemUtils.canItemStacksStack(stack, existing)) {
// return stack;
// }
//
// limit -= existing.getCount();
// }
//
// if (limit <= 0) {
// return stack;
// }
//
// boolean reachedLimit = stack.getCount() > limit;
//
// if (existing.isEmpty()) {
// stacks.set(slot, reachedLimit ? stack.copyWithCount(limit) : stack);
// } else {
// existing.grow(reachedLimit ? limit : stack.getCount());
// }
//
// return reachedLimit ? stack.copyWithCount(stack.getCount() - limit) : ItemStack.EMPTY;
}
}
Loading

0 comments on commit 0f450c8

Please sign in to comment.