Skip to content
Merged

Dev #34

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
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ dependencies {
compileOnly "mezz.jei:jei-${minecraft_version}-common-api:${jei_version}"
compileOnly "mezz.jei:jei-${minecraft_version}-neoforge-api:${jei_version}"
runtimeOnly "mezz.jei:jei-${minecraft_version}-neoforge:${jei_version}"
implementation "curse.maven:jade-324717:7886513"
implementation "curse.maven:jade-324717:${jade_version}"

}
8 changes: 5 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ org.gradle.caching=true
org.gradle.configuration-cache=true
minecraft_version=26.1.2
minecraft_version_range=[26.1,26.2]
neo_version=26.1.2.75
neo_version=26.1.2.99

## Mod Properties

mod_id=cakesticklib
mod_name=CakeStickLib
mod_license=Ora Et Labora License
mod_version=1.17.3
mod_version=1.17.4
mod_group_id=com.devdyna.cakestick
mod_authors=DevDyna
mod_description=A standalone port of JustDynaThings and Synergy API to unify most of the code

## Compats

jei_version=29.5.0.28
jei_version=29.37.0.98

jade_version=8857417
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
"cakesticklib.screen.upgrades": "Supported Upgrades:",
"cakesticklib.tank_interact.empty": "Empty",
"cakesticklib.ui.dont_consume": "§cNot consume",
"cakesticklib.upgrades.modifier.eject": "§7Ejection to: %s [%s]",
"cakesticklib.upgrades.modifier.eject": "§7Ejection to: %s §7| Type : %s",
"cakesticklib.upgrades.modifier.eject.shift": "§8§o<Shift-RightClick to configure>",
"cakesticklib.upgrades.modifier.empty": "§8§o<Put on a crafting grid to reset>",
"cakesticklib.upgrades.modifier.energy": "§7Energy Usage: %s",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_plates/steel": {
"conditions": {
"items": [
{
"items": "#c:plates/steel"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "cakesticklib:upgrade_application/eject_upgrade_fluid"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_the_recipe",
"has_plates/steel"
]
],
"rewards": {
"recipes": [
"cakesticklib:upgrade_application/eject_upgrade_fluid"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"type": "minecraft:crafting_shaped",
"category": "misc",
"group": "upgrade_application",
"key": {
"B": "#c:dusts/emerald",
"C": "cakesticklib:chip",
"R": "minecraft:piston",
"S": "#c:plates/steel"
},
"pattern": [
" R ",
"CSC",
" B "
],
"result": {
"components": {
"cakesticklib:modifiers": {
"eject": {
"type": "fluid",
"dir": "north"
}
}
},
"id": "cakesticklib:eject_upgrade"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.devdyna.cakesticklib.api.aspect.logic;

import net.minecraft.world.Clearable;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.BlockState;
Expand All @@ -12,7 +13,7 @@
* <br/>
* It doesn't restrict IO , for that you need to use {@link MachineItemStorage}
*/
public interface ItemStorageBlock {
public interface ItemStorageBlock extends Clearable{

ItemStacksResourceHandler getItemStorage();

Expand All @@ -21,7 +22,7 @@ public interface ItemStorageBlock {
BlockState getBlockState();

default boolean dropOnBreak(Player player) {
return dropOnBreak();
return dropOnBreak();
}

@Deprecated
Expand Down Expand Up @@ -61,7 +62,12 @@ default boolean isSlotsEmpty() {
return isSlotsEmpty(0, getSlots());
}

default void clear() {
@Deprecated
default void clear(){
this.clearContent();
}

default void clearContent() {
if (!isSlotsEmpty())
try (var tx = Transaction.openRoot()) {
for (int i = 0; i < getSlots(); i++)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.devdyna.cakesticklib.api.factories.plants;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Set;
import java.util.function.BiFunction;

import javax.annotation.Nullable;

import com.devdyna.cakesticklib.api.primitive.QueueUtil;
import com.devdyna.cakesticklib.setup.Config;

import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -188,81 +186,79 @@ public static void onClientClick(Level level, Player player, InteractionHand han

}

public static List<ItemStack> checkTree(Level level, BlockPos pos, boolean simulate) {
return checkTree(level, pos, simulate, (s, p) -> false);
}

public static List<ItemStack> checkTree(Level level, BlockPos pos) {
return checkTree(level, pos, (i, p) -> false);
return checkTree(level, pos, false);
}

public static List<ItemStack> checkTree(Level level, BlockPos pos,
public static List<ItemStack> checkTree(Level level, BlockPos pos, boolean simulate,
BiFunction<BlockState, BlockPos, Boolean> tool) {

var state = level.getBlockState(pos);

boolean canProcede = false;
var validTree = false;

if (state.is(BlockTags.COMPLETES_FIND_TREE_TUTORIAL))
for (Direction dir : Direction.values()) {
for (Direction dir : Direction.values())
if (level.getBlockState(pos.relative(dir)).is(BlockTags.COMPLETES_FIND_TREE_TUTORIAL)) {
canProcede = true;
validTree = true;
break;
}
}

if (canProcede) {
if (!validTree)
return null;

ArrayList<ItemStack> itemList = new ArrayList<>();
List<ItemStack> items = new ArrayList<>();
List<SoundEvent> sounds = new ArrayList<>();

ArrayList<SoundEvent> souldList = new ArrayList<>();
sounds.add(state.getSoundType(level, pos, null).getBreakSound());

souldList.add(state.getSoundType(level, pos, null).getBreakSound());
QueueUtil.of(pos)
.limit(treeHarvestingBlockLimit)
.define((queue, current) -> {

Queue<BlockPos> queue = new LinkedList<>();
Set<BlockPos> visited = new HashSet<>();
for (List<Integer> off : getTreeDirections()) {
var offset = current.offset(off.get(0), off.get(1), off.get(2));

queue.add(pos);
visited.add(pos);
var offstate = level.getBlockState(offset);

int checkBlocks = 0;
boolean toolFlag = false;
if (!offstate.is(BlockTags.COMPLETES_FIND_TREE_TUTORIAL))
continue;

while (!queue.isEmpty()) {
BlockPos currentPos = queue.poll();
Block.getDrops(offstate, (ServerLevel) level, offset, null)
.forEach(items::add);

for (List<Integer> off : getTreeDirections()) {
BlockPos adjacentPos = currentPos.offset(off.get(0), off.get(1), off.get(2));
BlockState adjacentState = level.getBlockState(adjacentPos);
if (!simulate)
level.setBlockAndUpdate(offset, Blocks.AIR.defaultBlockState());

if (adjacentState.is(BlockTags.COMPLETES_FIND_TREE_TUTORIAL) && !visited.contains(adjacentPos)) {
queue.add(adjacentPos);
visited.add(adjacentPos);
level.setBlockAndUpdate(adjacentPos, Blocks.AIR.defaultBlockState());
Block.getDrops(adjacentState, (ServerLevel) level, adjacentPos, null)
.forEach(t -> itemList.add(t));
var sound = offstate.getSoundType(level, offset, null).getBreakSound();

toolFlag = tool.apply(adjacentState, adjacentPos);
if (!sounds.contains(sound))
sounds.add(sound);

if (!souldList.contains(adjacentState.getSoundType(level, adjacentPos, null).getBreakSound())) {
souldList.add(adjacentState.getSoundType(level, adjacentPos, null).getBreakSound());
}
if (tool.apply(offstate, offset))
return QueueUtil.QueueStatus.SUCCESS;

queue.add(offset);
}
}
checkBlocks++;

if (checkBlocks >= treeHarvestingBlockLimit)
break;
return QueueUtil.QueueStatus.CONTINUE;
})
.run();

if (toolFlag)
break;
}
Block.getDrops(state, (ServerLevel) level, pos, null)
.forEach(items::add);

if (!simulate)
level.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
Block.getDrops(state, (ServerLevel) level, pos, null).forEach(t -> itemList.add(t));

souldList.forEach(s -> level.playSound(null, pos, s, SoundSource.BLOCKS));
if (!simulate)
sounds.forEach(sound -> level.playSound(null, pos, sound, SoundSource.BLOCKS));

return itemList;
}

return null;
return items;
}

public static List<ItemStack> checkBigPlant(Level level, BlockPos pos) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
import static com.devdyna.cakesticklib.CakeStickLib.MODULE_ID;

import java.util.List;

import com.devdyna.cakesticklib.api.utils.x;

import java.util.function.BiConsumer;
import net.minecraft.client.gui.GuiGraphicsExtractor;
import net.minecraft.client.renderer.RenderPipelines;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.Identifier;

public class DirectionalItemButton extends ItemButton {

private final Direction direction;
private BiConsumer<GuiGraphicsExtractor, Boolean> sprites;

public DirectionalItemButton(int x, int y, int width, int height, Direction dir, boolean flag, OnPress onPress) {
super(x, y, width, height, onPress, Component.translatable(MODULE_ID + ".widgets.button." + dir.name()));

Expand All @@ -25,21 +26,23 @@ public Direction getDirection() {
return direction;
}

public DirectionalItemButton defineSprites(BiConsumer<GuiGraphicsExtractor, Boolean> clicked) {
this.sprites = clicked;
return this;
}

public void draw(GuiGraphicsExtractor graphics, Identifier rl) {
graphics.blit(RenderPipelines.GUI_TEXTURED,
rl,
getX(), getY(),
0, 0,
getWidth(), getHeight(), getWidth(), getHeight());
}

@Override
protected void extractContents(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float partialTick) {

if (isClicked())
graphics.blit(RenderPipelines.GUI_TEXTURED,
x.rl(MODULE_ID, "textures/gui/modifier/buttons/on.png"),
getX(), getY(),
0, 0,
getWidth(), getHeight(), getWidth(), getHeight());
else
graphics.blit(RenderPipelines.GUI_TEXTURED,
x.rl(MODULE_ID, "textures/gui/modifier/buttons/off.png"),
getX(), getY(),
0, 0,
getWidth(), getHeight(), getWidth(), getHeight());
sprites.accept(graphics, isClicked());

if (!item.isEmpty())
graphics.item(item, getX(), getY());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
*/
public class QueueUtil<T> {

private boolean add_start = true;
private int limit = Integer.MAX_VALUE;
private boolean ignoreStart = false;
private Function<Queue<T>, Boolean> loop_when = q -> !q.isEmpty();
private T start;
private List<BiFunction<Queue<T>, T, QueueStatus>> chain = List
Expand All @@ -24,7 +25,12 @@ public static <T> QueueUtil<T> of(T v) {
}

public QueueUtil<T> ignoreStart() {
this.add_start = false;
this.ignoreStart = true;
return this;
}

public QueueUtil<T> limit(int limit) {
this.limit = limit;
return this;
}

Expand Down Expand Up @@ -52,15 +58,19 @@ public boolean run() {
Set<T> visited = new HashSet<>();
Queue<T> queue = new LinkedList<>();

if (add_start)
if (!ignoreStart)
queue.add(start);

main: while (loop_when.apply(queue)) {
int checked = 0;

main: while (loop_when.apply(queue) && checked < limit) {
var v = queue.poll();

if (!visited.add(v))
continue;

checked++;

for (var operation : chain)
switch (operation.apply(queue, v)) {
case QueueStatus.SUCCESS:
Expand All @@ -70,7 +80,6 @@ public boolean run() {
case QueueStatus.CONTINUE:
continue main;
}

}

return false;
Expand Down
Loading
Loading