Edit assets
This commit is contained in:
parent
16d7e58b8a
commit
06e5f220bd
BIN
assets/Casing.aseprite
Normal file
BIN
assets/Casing.aseprite
Normal file
Binary file not shown.
BIN
assets/Controller.aseprite
Normal file
BIN
assets/Controller.aseprite
Normal file
Binary file not shown.
BIN
assets/Drive.aseprite
Normal file
BIN
assets/Drive.aseprite
Normal file
Binary file not shown.
BIN
assets/DriveContainer.aseprite
Normal file
BIN
assets/DriveContainer.aseprite
Normal file
Binary file not shown.
BIN
assets/Head.aseprite
Normal file
BIN
assets/Head.aseprite
Normal file
Binary file not shown.
BIN
assets/Platter.aseprite
Normal file
BIN
assets/Platter.aseprite
Normal file
Binary file not shown.
BIN
assets/Tiers.aseprite
Normal file
BIN
assets/Tiers.aseprite
Normal file
Binary file not shown.
13
build.gradle
13
build.gradle
@ -17,6 +17,16 @@ repositories {
|
||||
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
|
||||
// for more information about repositories.
|
||||
maven { url 'https://maven.nucleoid.xyz' }
|
||||
|
||||
maven {
|
||||
url 'https://kneelawk.com/maven/'
|
||||
name 'Kneelawk Maven'
|
||||
}
|
||||
maven {
|
||||
// For LibNetworkStack, if using 'syncing' module
|
||||
url 'https://maven.alexiil.uk/'
|
||||
name 'AlexIIL Maven'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@ -32,6 +42,7 @@ dependencies {
|
||||
modImplementation include("eu.pb4:polymer-resource-pack:${project.polymer_version}")
|
||||
modImplementation include("eu.pb4:polymer-autohost:${project.polymer_version}")
|
||||
modImplementation include("eu.pb4:polymer-blocks:${project.polymer_version}")
|
||||
modImplementation include("eu.pb4:polymer-virtual-entity:${project.polymer_version}")
|
||||
include(modImplementation("xyz.nucleoid:server-translations-api:${project.server_translations_api_version}"))
|
||||
modImplementation include("eu.pb4:sgui:${project.servergui_version}")
|
||||
|
||||
@ -41,11 +52,13 @@ processResources {
|
||||
inputs.property "version", project.version
|
||||
inputs.property "minecraft_version", project.minecraft_version
|
||||
inputs.property "loader_version", project.loader_version
|
||||
inputs.property "fabric_version", project.fabric_version
|
||||
filteringCharset "UTF-8"
|
||||
|
||||
filesMatching("fabric.mod.json") {
|
||||
expand "version": project.version,
|
||||
"minecraft_version": project.minecraft_version,
|
||||
"fabric_version": project.fabric_version,
|
||||
"loader_version": project.loader_version
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ loader_version=0.15.11
|
||||
fabric_version=0.100.3+1.21
|
||||
|
||||
# Mod Properties
|
||||
mod_version=2.6.1
|
||||
mod_version=2.6.2
|
||||
maven_group=systems.brn
|
||||
archives_base_name=Server_storage
|
||||
|
||||
|
@ -5,26 +5,49 @@ import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory;
|
||||
import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.world.GameRules;
|
||||
import systems.brn.server_storage.blockentities.HardDriveContainerBlockEntity;
|
||||
import systems.brn.server_storage.blockentities.StorageBlockEntity;
|
||||
import systems.brn.server_storage.blocks.HardDriveContainerBlock;
|
||||
import systems.brn.server_storage.blocks.StorageBlock;
|
||||
import systems.brn.server_storage.items.HardDriveContainerBlockItem;
|
||||
import systems.brn.server_storage.items.HardDriveItem;
|
||||
import systems.brn.server_storage.items.StorageBlockItem;
|
||||
|
||||
public class ServerStorage implements ModInitializer {
|
||||
public static final String MODID = "serverstorage";
|
||||
public static final String MODELID = "storage";
|
||||
public static final String MOD_ID = "serverstorage";
|
||||
|
||||
public static final String STORAGE_MODEL_ID = "storage";
|
||||
public static final String HARD_DRIVE_MODEL_ID = "drive";
|
||||
public static final String HARD_DRIVE_CONTAINER_BLOCK_MODEL_ID = "drive_container";
|
||||
|
||||
public static BlockEntityType<HardDriveContainerBlockEntity> HARD_DRIVE_CONTAINER_BLOCK_ENTITY;
|
||||
public static HardDriveContainerBlock HARD_DRIVE_CONTAINER_BLOCK;
|
||||
|
||||
public static StorageBlock STORAGE_BLOCK;
|
||||
public static BlockEntityType<StorageBlockEntity> STORAGE_BLOCK_ENTITY;
|
||||
|
||||
public static final GameRules.Key<GameRules.BooleanRule> ServerStorage_Crafting_Enable =
|
||||
GameRuleRegistry.register("enableserverstoragecrafting", GameRules.Category.MISC, GameRuleFactory.createBooleanRule(false));
|
||||
|
||||
|
||||
public static Identifier id(String path) {
|
||||
return Identifier.of(MOD_ID, path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInitialize()
|
||||
{
|
||||
StorageBlock.register();
|
||||
StorageBlockItem.register();
|
||||
PolymerResourcePackUtils.addModAssets(MODID);
|
||||
|
||||
HardDriveContainerBlock.register();
|
||||
HardDriveContainerBlockItem.register();
|
||||
|
||||
HardDriveItem.register();
|
||||
|
||||
PolymerResourcePackUtils.addModAssets(MOD_ID);
|
||||
PolymerResourcePackUtils.markAsRequired();
|
||||
|
||||
|
||||
|
13
src/main/java/systems/brn/server_storage/blockentities/HardDriveContainerBlockEntity.java
Normal file
13
src/main/java/systems/brn/server_storage/blockentities/HardDriveContainerBlockEntity.java
Normal file
@ -0,0 +1,13 @@
|
||||
package systems.brn.server_storage.blockentities;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import static systems.brn.server_storage.ServerStorage.HARD_DRIVE_CONTAINER_BLOCK_ENTITY;
|
||||
|
||||
public class HardDriveContainerBlockEntity extends BlockEntity {
|
||||
public HardDriveContainerBlockEntity(BlockPos pos, BlockState state) {
|
||||
super(HARD_DRIVE_CONTAINER_BLOCK_ENTITY, pos, state);
|
||||
}
|
||||
}
|
@ -0,0 +1,109 @@
|
||||
package systems.brn.server_storage.blocks;
|
||||
|
||||
import eu.pb4.polymer.blocks.api.BlockModelType;
|
||||
import eu.pb4.polymer.blocks.api.PolymerBlockModel;
|
||||
import eu.pb4.polymer.blocks.api.PolymerBlockResourceUtils;
|
||||
import eu.pb4.polymer.blocks.api.PolymerTexturedBlock;
|
||||
import eu.pb4.polymer.core.api.block.PolymerBlockUtils;
|
||||
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockEntityProvider;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.component.DataComponentTypes;
|
||||
import net.minecraft.component.type.WrittenBookContentComponent;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.RawFilteredPair;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import systems.brn.server_storage.ServerStorage;
|
||||
import systems.brn.server_storage.blockentities.HardDriveContainerBlockEntity;
|
||||
import systems.brn.server_storage.blockentities.StorageBlockEntity;
|
||||
import systems.brn.server_storage.screens.StorageScreen;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static systems.brn.server_storage.ServerStorage.*;
|
||||
import static systems.brn.server_storage.lib.Util.generateBookContent;
|
||||
|
||||
public class HardDriveContainerBlock extends Block implements PolymerTexturedBlock, BlockEntityProvider {
|
||||
|
||||
String modelID;
|
||||
|
||||
BlockModelType blockModelType;
|
||||
|
||||
public HardDriveContainerBlock(Settings settings, BlockModelType type, String modelId) {
|
||||
super(settings);
|
||||
this.modelID = modelId;
|
||||
this.blockModelType = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getPolymerBlockState(BlockState state) {
|
||||
return PolymerBlockResourceUtils.requestBlock(BlockModelType.FULL_BLOCK, PolymerBlockModel.of(id(this.modelID)));
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
var modId = id(STORAGE_MODEL_ID);
|
||||
HARD_DRIVE_CONTAINER_BLOCK = Registry.register(Registries.BLOCK, modId,
|
||||
new HardDriveContainerBlock(Settings.copy(Blocks.WHITE_WOOL), BlockModelType.FULL_BLOCK, ServerStorage.HARD_DRIVE_CONTAINER_BLOCK_MODEL_ID));
|
||||
UseBlockCallback.EVENT.register(HardDriveContainerBlock::onUse);
|
||||
|
||||
HARD_DRIVE_CONTAINER_BLOCK_ENTITY = Registry.register(
|
||||
Registries.BLOCK_ENTITY_TYPE,
|
||||
modId,
|
||||
BlockEntityType.Builder.create(HardDriveContainerBlockEntity::new, HARD_DRIVE_CONTAINER_BLOCK).build(null)
|
||||
);
|
||||
PolymerBlockUtils.registerBlockEntity(STORAGE_BLOCK_ENTITY);
|
||||
}
|
||||
|
||||
private static ActionResult onUse(PlayerEntity player, World world, Hand hand, BlockHitResult hitResult) {
|
||||
BlockPos pos = hitResult.getBlockPos();
|
||||
BlockState state = world.getBlockState(pos);
|
||||
Block block = state.getBlock();
|
||||
|
||||
if (block instanceof HardDriveContainerBlock) {
|
||||
if (!world.isClient && !player.isSpectator()) {
|
||||
if (!player.isSneaking()) {
|
||||
StorageScreen storageScreen = new StorageScreen((ServerPlayerEntity) player, pos, null);
|
||||
storageScreen.open();
|
||||
|
||||
} else if (player.getStackInHand(hand).getItem() == Items.WRITTEN_BOOK) {
|
||||
ItemStack book = player.getStackInHand(hand);
|
||||
StorageBlockEntity storageBlockEntity = (StorageBlockEntity) world.getBlockEntity(pos);
|
||||
assert storageBlockEntity != null;
|
||||
List<RawFilteredPair<Text>> generatedContent = generateBookContent(storageBlockEntity.chests.inventory);
|
||||
book.set(DataComponentTypes.WRITTEN_BOOK_CONTENT, new WrittenBookContentComponent(
|
||||
RawFilteredPair.of("Item Listing"),
|
||||
player.getGameProfile().getName(),
|
||||
0,
|
||||
generatedContent,
|
||||
false
|
||||
));
|
||||
} else {
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
}
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
|
||||
return new StorageBlockEntity(pos, state);
|
||||
}
|
||||
}
|
@ -37,27 +37,24 @@ import static systems.brn.server_storage.lib.Util.generateBookContent;
|
||||
|
||||
public class StorageBlock extends Block implements PolymerTexturedBlock, BlockEntityProvider {
|
||||
|
||||
private final BlockState polymerBlockState;
|
||||
|
||||
public StorageBlock(Settings settings, BlockModelType type, String modelId) {
|
||||
super(settings);
|
||||
this.polymerBlockState = PolymerBlockResourceUtils.requestBlock(type, PolymerBlockModel.of(Identifier.of(ServerStorage.MODID, modelId)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getPolymerBlockState(BlockState state) {
|
||||
return this.polymerBlockState;
|
||||
return PolymerBlockResourceUtils.requestBlock(BlockModelType.FULL_BLOCK, PolymerBlockModel.of(Identifier.of(MOD_ID, STORAGE_MODEL_ID)));
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
var modId = Identifier.of(ServerStorage.MODID, ServerStorage.MODELID);
|
||||
var modId = id(STORAGE_MODEL_ID);
|
||||
STORAGE_BLOCK = Registry.register(Registries.BLOCK, modId,
|
||||
new StorageBlock(AbstractBlock.Settings.copy(Blocks.WHITE_WOOL), BlockModelType.FULL_BLOCK, ServerStorage.MODELID));
|
||||
new StorageBlock(AbstractBlock.Settings.copy(Blocks.WHITE_WOOL), BlockModelType.FULL_BLOCK, ServerStorage.STORAGE_MODEL_ID));
|
||||
UseBlockCallback.EVENT.register(StorageBlock::onUse);
|
||||
|
||||
STORAGE_BLOCK_ENTITY = Registry.register(
|
||||
Registries.BLOCK_ENTITY_TYPE,
|
||||
Identifier.of(MODID, MODELID),
|
||||
modId,
|
||||
BlockEntityType.Builder.create(StorageBlockEntity::new, STORAGE_BLOCK).build(null)
|
||||
);
|
||||
PolymerBlockUtils.registerBlockEntity(STORAGE_BLOCK_ENTITY);
|
||||
@ -74,8 +71,7 @@ public class StorageBlock extends Block implements PolymerTexturedBlock, BlockEn
|
||||
StorageScreen storageScreen = new StorageScreen((ServerPlayerEntity) player, pos, null);
|
||||
storageScreen.open();
|
||||
|
||||
}
|
||||
else if(player.getStackInHand(hand).getItem() == Items.WRITTEN_BOOK) {
|
||||
} else if (player.getStackInHand(hand).getItem() == Items.WRITTEN_BOOK) {
|
||||
ItemStack book = player.getStackInHand(hand);
|
||||
StorageBlockEntity storageBlockEntity = (StorageBlockEntity) world.getBlockEntity(pos);
|
||||
assert storageBlockEntity != null;
|
||||
|
@ -0,0 +1,41 @@
|
||||
package systems.brn.server_storage.items;
|
||||
|
||||
import eu.pb4.polymer.core.api.item.PolymerItem;
|
||||
import eu.pb4.polymer.resourcepack.api.PolymerModelData;
|
||||
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
|
||||
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.*;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import systems.brn.server_storage.ServerStorage;
|
||||
|
||||
import static systems.brn.server_storage.ServerStorage.*;
|
||||
|
||||
public class HardDriveContainerBlockItem extends BlockItem implements PolymerItem {
|
||||
private final PolymerModelData polymerModel;
|
||||
|
||||
public HardDriveContainerBlockItem(Item.Settings settings, Block block, Identifier identifier) {
|
||||
super(block, settings);
|
||||
this.polymerModel = PolymerResourcePackUtils.requestModel(Items.BARRIER, identifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getPolymerItem(ItemStack itemStack, @Nullable ServerPlayerEntity player) {
|
||||
return this.polymerModel.item();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPolymerCustomModelData(ItemStack itemStack, @Nullable ServerPlayerEntity player) {
|
||||
return this.polymerModel.value();
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
Identifier identifier= id(ServerStorage.HARD_DRIVE_CONTAINER_BLOCK_MODEL_ID);
|
||||
Item item = Registry.register(Registries.ITEM, identifier, new HardDriveContainerBlockItem(new Item.Settings(), HARD_DRIVE_CONTAINER_BLOCK, identifier));
|
||||
ItemGroupEvents.modifyEntriesEvent(ItemGroups.FUNCTIONAL).register(content -> content.add(item));
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package systems.brn.server_storage.items;
|
||||
|
||||
import eu.pb4.polymer.core.api.item.PolymerItem;
|
||||
import eu.pb4.polymer.resourcepack.api.PolymerModelData;
|
||||
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
|
||||
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroups;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import systems.brn.server_storage.ServerStorage;
|
||||
|
||||
import static systems.brn.server_storage.ServerStorage.id;
|
||||
|
||||
public class HardDriveItem extends Item implements PolymerItem {
|
||||
private final PolymerModelData polymerModel;
|
||||
|
||||
public HardDriveItem(Settings settings, Identifier identifier) {
|
||||
super(settings);
|
||||
this.polymerModel = PolymerResourcePackUtils.requestModel(Items.BARRIER, identifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getPolymerItem(ItemStack itemStack, @Nullable ServerPlayerEntity player) {
|
||||
return this.polymerModel.item();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPolymerCustomModelData(ItemStack itemStack, @Nullable ServerPlayerEntity player) {
|
||||
return this.polymerModel.value();
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
Identifier identifier = id(ServerStorage.HARD_DRIVE_MODEL_ID);
|
||||
Item item = Registry.register(Registries.ITEM, identifier, new HardDriveItem(new Settings(), identifier));
|
||||
ItemGroupEvents.modifyEntriesEvent(ItemGroups.FUNCTIONAL).register(content -> content.add(item));
|
||||
}
|
||||
}
|
@ -14,13 +14,14 @@ import org.jetbrains.annotations.Nullable;
|
||||
import systems.brn.server_storage.ServerStorage;
|
||||
|
||||
import static systems.brn.server_storage.ServerStorage.STORAGE_BLOCK;
|
||||
import static systems.brn.server_storage.ServerStorage.id;
|
||||
|
||||
public class StorageBlockItem extends BlockItem implements PolymerItem {
|
||||
private final PolymerModelData polymerModel;
|
||||
|
||||
public StorageBlockItem(Settings settings, Block block, String modelId) {
|
||||
public StorageBlockItem(Settings settings, Block block, Identifier identifier) {
|
||||
super(block, settings);
|
||||
this.polymerModel = PolymerResourcePackUtils.requestModel(Items.BARRIER, Identifier.of(ServerStorage.MODID, modelId));
|
||||
this.polymerModel = PolymerResourcePackUtils.requestModel(Items.BARRIER, identifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -34,8 +35,8 @@ public class StorageBlockItem extends BlockItem implements PolymerItem {
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
var modId = Identifier.of(ServerStorage.MODID, ServerStorage.MODELID);
|
||||
Item item = Registry.register(Registries.ITEM, modId, new StorageBlockItem(new Item.Settings(), STORAGE_BLOCK, ServerStorage.MODELID));
|
||||
Identifier identifier = id(ServerStorage.STORAGE_MODEL_ID);
|
||||
Item item = Registry.register(Registries.ITEM, identifier, new StorageBlockItem(new Item.Settings(), STORAGE_BLOCK, identifier));
|
||||
ItemGroupEvents.modifyEntriesEvent(ItemGroups.FUNCTIONAL).register(content -> content.add(item));
|
||||
}
|
||||
}
|
@ -1,17 +1,44 @@
|
||||
package systems.brn.server_storage.lib;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.recipe.CraftingRecipe;
|
||||
import net.minecraft.recipe.RecipeEntry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static systems.brn.server_storage.lib.Util.addCountToLore;
|
||||
|
||||
public class CraftingEntry {
|
||||
public final ItemStack itemStack;
|
||||
public final ArrayList<ItemStack> outputStacks;
|
||||
public final RecipeEntry<CraftingRecipe> recipeEntry;
|
||||
public final ArrayList<MyCraftingRecipe> myCraftingRecipeEntries;
|
||||
public CraftingEntry(ItemStack itemStack, RecipeEntry<CraftingRecipe> recipeEntry) {
|
||||
this.itemStack = itemStack;
|
||||
|
||||
public CraftingEntry(ItemStack itemStack, RecipeEntry<CraftingRecipe> recipeEntry, HashMap<ItemStack, Integer> inputs, Integer maxCount) {
|
||||
ArrayList<ItemStack> tempOutputStacks = new ArrayList<>();
|
||||
ItemStack outputStack = itemStack.copy();
|
||||
outputStack.setCount(maxCount);
|
||||
outputStack = addCountToLore(itemStack.getCount() * maxCount, outputStack, "Total max: ");
|
||||
outputStack = addCountToLore(itemStack.getCount(), outputStack, "Each craft: ");
|
||||
outputStack = addCountToLore(maxCount, outputStack, "Max crafts: ");
|
||||
tempOutputStacks.add(outputStack);
|
||||
for (Map.Entry<ItemStack, Integer> entry : inputs.entrySet()) {
|
||||
ItemStack stackIn = entry.getKey();
|
||||
Integer count = entry.getValue();
|
||||
if (count > 0 && stackIn.isEmpty() && stackIn.getItem().hasRecipeRemainder()) {
|
||||
Item remainderItem = stackIn.getItem().getRecipeRemainder();
|
||||
if (remainderItem != null) {
|
||||
ItemStack remainderStack = new ItemStack(stackIn.getItem().getRecipeRemainder(), count);
|
||||
tempOutputStacks.add(remainderStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.outputStacks = tempOutputStacks;
|
||||
this.recipeEntry = recipeEntry;
|
||||
this.myCraftingRecipeEntries = new ArrayList<>();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,6 @@ public class MyCraftingRecipe {
|
||||
HashMap<ItemStack, Integer> inputs = new HashMap<>();
|
||||
HashMap<ItemStack, Integer> outputs = new HashMap<>();
|
||||
MyCraftingRecipe(RecipeEntry<CraftingRecipe> recipeEntry) {
|
||||
recipeEntry.value().getIngredients()
|
||||
recipeEntry.value().getIngredients();
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import net.minecraft.component.type.LoreComponent;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.recipe.*;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.text.RawFilteredPair;
|
||||
@ -63,11 +64,12 @@ public class Util {
|
||||
return pages;
|
||||
}
|
||||
|
||||
public static ItemStack addCountToLore(final int count, ItemStack stack) {
|
||||
public static ItemStack addCountToLore(final int count, ItemStack stack, String name) {
|
||||
if (count > 0) {
|
||||
ItemStack newStack = stack.copy();
|
||||
LoreComponent lore = stack.get(DataComponentTypes.LORE);
|
||||
Text countLine = Text.literal("Amount: " + count).setStyle(Style.EMPTY.withColor(Formatting.GOLD).withItalic(true));
|
||||
name = name != null ? name : "Amount: ";
|
||||
Text countLine = Text.literal(name + count).setStyle(Style.EMPTY.withColor(Formatting.GOLD).withItalic(true));
|
||||
|
||||
LoreComponent newLore;
|
||||
if (lore == null) {
|
||||
@ -113,6 +115,9 @@ public class Util {
|
||||
for (RecipeEntry<CraftingRecipe> recipe : allRecipes) {
|
||||
int maxAmount = -1;
|
||||
boolean canMake = true;
|
||||
boolean needToAdd = true;
|
||||
CraftingEntry finalEntry;
|
||||
HashMap<ItemStack, Integer> finalInputs = new HashMap<>();
|
||||
for (Ingredient ingredient : recipe.value().getIngredients()) {
|
||||
HashMap<ItemStack, Integer> inputsTemp = new HashMap<>();
|
||||
for (ItemStack stack : ingredient.getMatchingStacks()) {
|
||||
@ -143,18 +148,23 @@ public class Util {
|
||||
stackIn.setCount(count);
|
||||
inputs.put(stackIn, stackIn.getCount());
|
||||
}
|
||||
for (Map.Entry<ItemStack, Integer> entry : inputs.entrySet()) {
|
||||
ItemStack stackIn = entry.getKey();
|
||||
Integer count = entry.getValue();
|
||||
boolean itemFound = false;
|
||||
for (int i = 0; i < inventory.size(); i++) {
|
||||
ItemStack slotStack = inventory.getStack(i);
|
||||
Item slotItem = slotStack.getItem();
|
||||
int slotCount = slotStack.getCount();
|
||||
for (Map.Entry<ItemStack, Integer> entry : inputs.entrySet()) {
|
||||
ItemStack stackIn = entry.getKey();
|
||||
Integer count = entry.getValue();
|
||||
if (stackIn.getItem() == slotItem) {
|
||||
count -= slotCount;
|
||||
entry.setValue(count);
|
||||
itemFound = true;
|
||||
}
|
||||
}
|
||||
if (!itemFound) {
|
||||
maxAmount = 0;
|
||||
}
|
||||
}
|
||||
for (Map.Entry<ItemStack, Integer> entry : inputs.entrySet()) {
|
||||
ItemStack stackIn = entry.getKey();
|
||||
@ -162,6 +172,9 @@ public class Util {
|
||||
if (count > 0) {
|
||||
canMake = false;
|
||||
} else {
|
||||
if(recipe.value().getResult(server.getRegistryManager()).getItem() == Items.REDSTONE_BLOCK){
|
||||
int asdasd = 0;
|
||||
}
|
||||
int thisMaxAmount = Math.floorDivExact(Math.abs(count), stackIn.getCount());
|
||||
if (maxAmount == -1) {
|
||||
maxAmount = thisMaxAmount;
|
||||
@ -170,27 +183,31 @@ public class Util {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (maxAmount > 1 && canMake) {
|
||||
Item outputItem = recipe.value().getResult(server.getRegistryManager()).getItem();
|
||||
CraftingEntry entry = new CraftingEntry(new ItemStack(outputItem, maxAmount), recipe);
|
||||
boolean needToAdd = true;
|
||||
if (maxAmount > 0 && canMake && needToAdd) {
|
||||
ItemStack outputItem = recipe.value().getResult(server.getRegistryManager()).copy();
|
||||
finalEntry = new CraftingEntry(outputItem, recipe, inputs, maxAmount);
|
||||
finalInputs.putAll(inputs);
|
||||
for (int i = 0; i < craftingEntries.size(); i++) {
|
||||
CraftingEntry entryLoop = craftingEntries.get(i);
|
||||
if (entryLoop.itemStack.getItem().equals(outputItem)) {
|
||||
for (ItemStack outputStack : entryLoop.outputStacks) {
|
||||
if (ItemStack.areItemsAndComponentsEqual(outputStack, outputItem)) {
|
||||
needToAdd = false;
|
||||
if (maxAmount > entryLoop.itemStack.getCount()) {
|
||||
craftingEntries.set(i, entry);
|
||||
if (maxAmount > outputStack.getCount()) {
|
||||
craftingEntries.set(i, finalEntry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (needToAdd) {
|
||||
craftingEntries.add(entry);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (needToAdd && maxAmount > 0) {
|
||||
ItemStack outputItem = recipe.value().getResult(server.getRegistryManager()).copy();
|
||||
finalEntry = new CraftingEntry(outputItem, recipe, finalInputs, maxAmount);
|
||||
craftingEntries.add(finalEntry);
|
||||
}
|
||||
}
|
||||
return craftingEntries;
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static systems.brn.server_storage.lib.StorageOperations.*;
|
||||
import static systems.brn.server_storage.lib.Util.addCountToLore;
|
||||
import static systems.brn.server_storage.lib.Util.getCraftableRecipes;
|
||||
|
||||
public class CraftingScreen extends PagedGui {
|
||||
@ -50,7 +49,7 @@ public class CraftingScreen extends PagedGui {
|
||||
ArrayList<DisplayElement> recipes = new ArrayList<>();
|
||||
|
||||
for (CraftingEntry craftingEntry : craftingEntries) {
|
||||
ItemStack stackWithCount = addCountToLore(craftingEntry.itemStack.getCount(), craftingEntry.itemStack);
|
||||
ItemStack stackWithCount = craftingEntry.outputStacks.getFirst().copy();
|
||||
if (stackWithCount.getCount() > stackWithCount.getMaxCount()) {
|
||||
stackWithCount.setCount(stackWithCount.getMaxCount());
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ public class StorageScreen extends PagedGui {
|
||||
protected DisplayElement getElement(int id) {
|
||||
if (blockEntity.chests.inventory.size() > id) {
|
||||
ItemStack itemStack = blockEntity.chests.inventory.getStack(id);
|
||||
ItemStack newStack = addCountToLore(itemStack.getCount(), itemStack);
|
||||
ItemStack newStack = addCountToLore(itemStack.getCount(), itemStack, null);
|
||||
GuiElementBuilder guiElement = new GuiElementBuilder(newStack);
|
||||
return DisplayElement.of(guiElement);
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
{
|
||||
"variants": {
|
||||
"": {
|
||||
"model": "serverstorage:block/drive_container"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
{
|
||||
"block.serverstorage.storage": "Chest storage controller",
|
||||
"block.serverstorage.fast_hopper": "Fast hopper"
|
||||
"block.serverstorage.drive": "Hard drive",
|
||||
"block.serverstorage.drive_container": "Hard drive container"
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "block/cube_all",
|
||||
"textures": {
|
||||
"all": "serverstorage:block/drive_container"
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "minecraft:item/drive"
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"parent": "storage:block/drive_container"
|
||||
}
|
Loading…
Reference in New Issue
Block a user