-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from Chainmail-Studios/shnup
pain
- Loading branch information
Showing
162 changed files
with
2,071 additions
and
1,803 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
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
107 changes: 107 additions & 0 deletions
107
...github/chainmailstudios/astromine/client/screen/CraftingRecipeCreatorContainerScreen.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,107 @@ | ||
package com.github.chainmailstudios.astromine.client.screen; | ||
|
||
import com.github.chainmailstudios.astromine.common.container.CraftingRecipeCreatorContainer; | ||
import com.github.chainmailstudios.astromine.common.utilities.HashUtilities; | ||
import com.google.common.collect.Lists; | ||
import com.google.common.collect.Sets; | ||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonObject; | ||
import net.fabricmc.loader.api.FabricLoader; | ||
import net.fabricmc.loader.launch.common.FabricLauncher; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.registry.Registry; | ||
import spinnery.client.screen.BaseContainerScreen; | ||
import spinnery.widget.*; | ||
import spinnery.widget.api.Position; | ||
import spinnery.widget.api.Size; | ||
|
||
import java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.util.Collection; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
public class CraftingRecipeCreatorContainerScreen extends BaseContainerScreen<CraftingRecipeCreatorContainer> { | ||
private static final int INPUT = 1; | ||
private static final int OUTPUT = 2; | ||
|
||
public CraftingRecipeCreatorContainerScreen(Text name, CraftingRecipeCreatorContainer linkedContainer, PlayerEntity player) { | ||
super(name, linkedContainer, player); | ||
|
||
WInterface mainInterface = getInterface(); | ||
|
||
WPanel mainPanel = mainInterface.createChild(WPanel::new, Position.ORIGIN, Size.of(176, 175)); | ||
mainPanel.center(); | ||
mainPanel.setOnAlign(WAbstractWidget::center); | ||
|
||
WSlot.addPlayerInventory(Position.of(mainPanel, 7, 68, 0), Size.of(18, 18), mainPanel); | ||
|
||
List<WSlot> craftingSlots = Lists.newArrayList(WSlot.addArray(Position.of(mainPanel, 7, 7, 0), Size.of(18, 18), mainPanel, 0, INPUT, 3, 3)); | ||
|
||
craftingSlots.sort(Comparator.comparingInt(WSlot::getSlotNumber)); | ||
|
||
WSlot resultSlot = mainPanel.createChild(WSlot::new, Position.of(mainPanel, 7 + 54 + 27, 7 + 13.5f, 0), Size.of(27, 27)).setSlotNumber(0).setInventoryNumber(OUTPUT); | ||
|
||
mainPanel.createChild(WButton::new, | ||
Position.of( | ||
mainPanel, | ||
mainPanel.getWidth() - 7 - 54, | ||
mainPanel.getHeight() - 7 - 18, | ||
0 | ||
), Size.of(54, 18)) | ||
.setLabel("Save") | ||
.setOnMouseClicked(((widget, mouseX, mouseY, mouseButton) -> { | ||
JsonObject output = new JsonObject(); | ||
|
||
JsonArray pattern = new JsonArray(); | ||
pattern.add("012"); | ||
|
||
pattern.add("345"); | ||
|
||
pattern.add("678"); | ||
|
||
JsonObject key = new JsonObject(); | ||
|
||
int[] i = { 0 }; | ||
|
||
craftingSlots.forEach(slot -> { | ||
JsonObject stack = new JsonObject(); | ||
stack.addProperty("item", Registry.ITEM.getId(slot.getStack().getItem()).toString()); | ||
|
||
key.add(String.valueOf(i[0]), stack); | ||
|
||
++i[0]; | ||
}); | ||
|
||
JsonObject result = new JsonObject(); | ||
result.addProperty("item", Registry.ITEM.getId(resultSlot.getStack().getItem()).toString()); | ||
result.addProperty("count", resultSlot.getStack().getCount()); | ||
|
||
output.addProperty("type", "minecraft:crafting_shaped"); | ||
output.add("pattern", pattern); | ||
output.add("key", key); | ||
output.add("result", result); | ||
|
||
try { | ||
File rootDirectory = FabricLoader.getInstance().getGameDirectory(); | ||
|
||
File outputDirectory = new File(rootDirectory.getPath().replace("\\.", "") + "/output/"); | ||
|
||
outputDirectory.mkdirs(); | ||
|
||
File outputFile = new File(outputDirectory.getPath() + "/" + Registry.ITEM.getId(resultSlot.getStack().getItem()).getPath() + ".json"); | ||
|
||
BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile)); | ||
|
||
writer.write(output.toString()); | ||
|
||
writer.close(); | ||
} catch (Exception exception) { | ||
exception.printStackTrace(); | ||
} | ||
})); | ||
|
||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
...om/github/chainmailstudios/astromine/common/container/CraftingRecipeCreatorContainer.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,34 @@ | ||
package com.github.chainmailstudios.astromine.common.container; | ||
|
||
import com.github.chainmailstudios.astromine.registry.AstromineContainers; | ||
import net.minecraft.entity.player.PlayerInventory; | ||
import net.minecraft.screen.ScreenHandlerType; | ||
import spinnery.common.container.BaseContainer; | ||
import spinnery.common.inventory.BaseInventory; | ||
import spinnery.widget.WButton; | ||
import spinnery.widget.WSlot; | ||
import spinnery.widget.api.Position; | ||
import spinnery.widget.api.Size; | ||
|
||
public class CraftingRecipeCreatorContainer extends BaseContainer { | ||
private static final int INPUT = 1; | ||
private static final int OUTPUT = 2; | ||
|
||
public CraftingRecipeCreatorContainer(int synchronizationID, PlayerInventory playerInventory) { | ||
super(synchronizationID, playerInventory); | ||
|
||
addInventory(INPUT, new BaseInventory(9)); | ||
addInventory(OUTPUT, new BaseInventory(1)); | ||
|
||
WSlot.addHeadlessPlayerInventory(getInterface()); | ||
|
||
WSlot.addHeadlessArray(getInterface(), 0, INPUT, 3, 3); | ||
|
||
getInterface().createChild(WSlot::new).setInventoryNumber(OUTPUT).setSlotNumber(0); | ||
} | ||
|
||
@Override | ||
public ScreenHandlerType<?> getType() { | ||
return AstromineContainers.CRAFTING_RECIPE_CREATOR; | ||
} | ||
} |
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
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
7 changes: 7 additions & 0 deletions
7
src/main/java/com/github/chainmailstudios/astromine/common/utilities/HashUtilities.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,7 @@ | ||
package com.github.chainmailstudios.astromine.common.utilities; | ||
|
||
public class HashUtilities { | ||
public static String firstOf(Object object) { | ||
return String.valueOf(String.valueOf(object.hashCode()).charAt(0)); | ||
} | ||
} |
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
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.