Skip to content

Commit

Permalink
Merge pull request #57 from The-Iceburg/back2basics
Browse files Browse the repository at this point in the history
Back2basics
  • Loading branch information
Dockuin authored Sep 22, 2022
2 parents b21ee9c + 1ac72dc commit e0a66d1
Show file tree
Hide file tree
Showing 9 changed files with 265 additions and 9 deletions.
16 changes: 16 additions & 0 deletions ANIM.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,21 @@ def ANI(imageLocation, packName, integrationType, rename):
# saves / closes the file
file.close()

# if the integration type is MCRTX
elif integrationType == "MCRTX":

# creates the .mcmeta in the appropriate location for the integration type (MCRTX)
file = open("C:/Users/" + getpass.getuser() + "/AppData/Roaming/.minecraft/resourcepacks/" + packName + "/assets/minecraft/textures/item/totem_of_undying.png.mcmeta", "w+")

# writes the appropriate data to the file
file.writelines(['{\n',
' "animation": {\n'])
file.write(' "frametime": ' + str(FRAMETIME) + '\n')
file.writelines([' }\n',
'}'])

# saves / closes the file
file.close()

# returns the new / appropriate location for the gif texture
return "C:/Users/" + getpass.getuser() + "/AppData/Roaming/Totems+/giftexture/" + llfilename
228 changes: 228 additions & 0 deletions MCRTX.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
###################################################################
# Totems+ #
# A new and unique way to integrate custom totems into Minecraft! #
# Learn More here:https://github.com/The-Iceburg/TotemsPlus #
# Created By The Totems+ Team - Ormatist + Dockuin #
###################################################################

# imports the libaries used within Totems+
from PIL import Image, ImageSequence
import os.path, getpass, shutil, PySimpleGUI as sg
from ANIM import ANI

# outlines the versions and there pack formats
packFormat4 = ["1.14","1.14.1","1.14.2","1.14.3","1.14.4"]
packFormat5 = ["1.15","1.15.1","1.15.2","1.16","1.16.1"]
packFormat6 = ["1.16.2","1.16.3","1.16.4","1.16.5"]

# defines the RTX function
def RTX(textureList, version):

# makes texttureList an actual list
textureList = textureList.split(";")

# sets deafult index to 0
index = 0

# if the length of texture list is greater than 1
if len(textureList) > 1:

# if the directory resized already exists, then delete it
if os.path.exists('C:/Users/' + getpass.getuser() + '/AppData/Roaming/Totems+/resized'):
shutil.rmtree('C:/Users/' + getpass.getuser() + '/AppData/Roaming/Totems+/resized')

# make the resized folder
os.mkdir("C:/Users/" + getpass.getuser() + "/AppData/Roaming/Totems+/resized")

# new list to hold the new file names
pathList = []

# the path for the resized folder
targetIMG = "C:/Users/" + getpass.getuser() + "/AppData/Roaming/Totems+/resized"

# for loop for each image
for i in range(len(textureList)):

# finds only the names
splitList = textureList[i].split("/")
# makes a new file name
fileName1 = "resize_" + str(splitList[-1])

# Run indented code if it is a GIF
if textureList[i].endswith(".gif") == True:
origIMG = Image.open(textureList[i])
size = 128, 128
frames = ImageSequence.Iterator(origIMG)
def thumbnails(frames):
for frame in frames:
thumbnail = frame.copy()
thumbnail = thumbnail.resize(size)
thumbnail.thumbnail(size, Image.ANTIALIAS)
yield thumbnail
frames = thumbnails(frames)

resizedGIF = next(frames)
resizedGIF.info = origIMG.info
resizedGIF.save(fileName1, save_all=True, append_images=list(frames), loop=0)

# Run Code if it is not a GIF
elif textureList[i].endswith(".gif") == False:

# copies the images to the resized folder
shutil.copy(textureList[i], targetIMG)
IMGpath = targetIMG + "/" + splitList[-1]

# opens and resizes the image, saves with a new name
openIMG = Image.open(IMGpath)
resizedIMG = openIMG.resize((128,128))
resizedIMG.save(fileName1)

# moves to the resized folder and saves the path to the path list
shutil.move(fileName1, targetIMG)
fileName2 = targetIMG + "/" + fileName1
pathList.append(fileName2)

# defines how the main window will be displayed/layed-out
layout = [
[
sg.Image(filename=pathList[index], key='-IMAGE-'),
sg.Text("You've selected Totems+ RTX Integration!\n" +
'This integration will generate:\n' +
'A Custom Resource Pack\n' +
'Follow the tooltip below to customize your packs!\n' +
' ', font=('Helvetica', 10), justification='left'),
],
[
sg.Text('Select which Totem Texture you want te replace the original\nIt should be noted totems may appear blurred/streched here but\n wont in Minecraft. .GIF files also wont play in this release', key='tooltip')
],
[
sg.Button('Select Texture', key='choose'),
sg.Button('Previous', key='back'),
sg.Button('Next', key='next'),
sg.Button('Cancel', key='cancel'),
],
]

# creates the window
window = sg.Window("CIT", layout, icon="img/totems.ico")

# while window (GUI) is open
while True:

# read all events/actions
event, values = window.read()

# if window closed break while loop and end code
if event == sg.WIN_CLOSED:
break

# if the cancel button is pressed
if event == 'cancel':

# a confirmation window is displayed and if the user agrees all files are removed
result = sg.popup_ok_cancel("Are you sure?")

if result == "OK":
break

# if the next button
if event == 'next':

# increases the index
index += 1

# if it reaches max then resets it
if index == len(textureList):
index = 0

# updates the displayed image
window.Element('-IMAGE-').update(filename=pathList[index])

# if the back button
if event == 'back':

# decreases the index
index -= 1

# if index reaches min then resets it
if index == -1:
index = len(textureList) - 1

# updates the displayed image
window.Element('-IMAGE-').update(filename=pathList[index])

# if the choose button
if event == 'choose':

# resets the texturelIst to the current value
textureList = [textureList[index]]

# breaks the window
break

# sets the base name (for if it isn't changed)
name = "Totems+ RTX"

# checks if the resource pack exists and if it does user is prompted to suggest a new name
if os.path.exists('C:/Users/' + getpass.getuser() + '/AppData/Roaming/.minecraft/resourcepacks/Totems+ RTX'):
name = sg.popup_get_text("An MCRTX Integration resource pack allready exists\nPlease choose a different name for this one:", title = "Duplicate Pack")

# pre-makes the resource pack directory in the minecraft resource pack folder
os.mkdir("C:/Users/" + getpass.getuser() + "/AppData/Roaming/.minecraft/resourcepacks/" + name)
os.mkdir("C:/Users/" + getpass.getuser() + "/AppData/Roaming/.minecraft/resourcepacks/" + name + "/assets")
os.mkdir("C:/Users/" + getpass.getuser() + "/AppData/Roaming/.minecraft/resourcepacks/" + name + "/assets/minecraft")
os.mkdir("C:/Users/" + getpass.getuser() + "/AppData/Roaming/.minecraft/resourcepacks/" + name + "/assets/minecraft/textures")
os.mkdir("C:/Users/" + getpass.getuser() + "/AppData/Roaming/.minecraft/resourcepacks/" + name + "/assets/minecraft/textures/item")

# copys the pack.png file into place
shutil.copy("img/pack.png", "C:/Users/" + getpass.getuser() + "/AppData/Roaming/.minecraft/resourcepacks/" + name)

# creates & opens the pack.mcmeta file
packMeta = open("C:/Users/" + getpass.getuser() + "/AppData/Roaming/.minecraft/resourcepacks/" + name + "/pack.mcmeta", "w+")

# derrives the resource pack format code from the version
if version in packFormat4:
packFormat = 4
elif version in packFormat5:
packFormat = 5
elif version in packFormat6:
packFormat = 6
elif version.startswith("1.17"):
packFormat = 7
elif version.startswith("1.18"):
packFormat = 8
elif version.startswith("1.19"):
packFormat = 9

# adds the needed meta data to the pack.mcmeta file
packMeta.writelines(['{\n',
' "pack": {\n',
' "pack_format": ' + str(packFormat) + ',\n',
' "description": "Version: ' + version + '\n',
'Made By: The Totems+ Team"\n',
' }\n',
'}'])
packMeta.close()

# if the file is a .gif file
if textureList[0].endswith('.gif'):

# copys the new gif texture to the pack
shutil.copy(ANI(textureList[0], name, "MCRTX", None), "C:/Users/" + getpass.getuser() + "/AppData/Roaming/.minecraft/resourcepacks/" + name + "/assets/minecraft/textures/item")

# else
else:
# copys the image into the resource pack
shutil.copy(textureList[0], "C:/Users/" + getpass.getuser() + "/AppData/Roaming/.minecraft/resourcepacks/" + name + "/assets/minecraft/textures/item")

# gets the actual file name
textureList[0] = textureList[0].split("/")

# gets the current location of the file
old_file = "C:/Users/" + getpass.getuser() + "/AppData/Roaming/.minecraft/resourcepacks/" + name + "/assets/minecraft/textures/item/" + textureList[0][-1].replace(".gif", ".png")

# renames the file to totem_of_undying.png
os.rename(old_file, "C:/Users/" + getpass.getuser() + "/AppData/Roaming/.minecraft/resourcepacks/" + name + "/assets/minecraft/textures/item/totem_of_undying.png")

# prints completion message to user
sg.popup_ok("Pack creation complete! Load up Minecraft and you Totems+ pack will appear in your resourcepack folder!", title = "Pack Completion", icon="img/totems.ico")
1 change: 0 additions & 1 deletion OFCIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ def thumbnails(frames):

if result == "OK":
shutil.rmtree("C:/Users/" + getpass.getuser() + "/AppData/Roaming/.minecraft/resourcepacks/" + name)
break

# else if the next button and the length of the texture list isn't equal to the counter + 1
elif event == 'next' and len(textureList) != int(counter + 1):
Expand Down
Binary file modified __pycache__/ADVA.cpython-310.pyc
Binary file not shown.
Binary file modified __pycache__/ANIM.cpython-310.pyc
Binary file not shown.
Binary file modified __pycache__/DOC.cpython-310.pyc
Binary file not shown.
Binary file added __pycache__/MCRTX.cpython-310.pyc
Binary file not shown.
Binary file modified __pycache__/OFCIT.cpython-310.pyc
Binary file not shown.
29 changes: 21 additions & 8 deletions totems.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os.path, PySimpleGUI as sg, getpass
from OFCIT import CIT
from MCCMD import CMD
from MCRTX import RTX

# sets window theme
sg.theme('DarkTeal10')
Expand Down Expand Up @@ -42,7 +43,7 @@ def main():
' \n' +
'Minecraft CMD - Allows for custom totems using custom model data and adds\n' +
' these with a given weight to the evoker loot_tabel.'),
sg.Button('Optifine CIT', size=(15,1), button_color=('white','orange'), key='-TOGGLE-')
sg.Button('Minecraft RTX', size=(15,1), button_color=('white','red'), key='-TOGGLE-')
],
[
sg.Text("⚫ Select your totem image files here:")
Expand All @@ -67,7 +68,7 @@ def main():
window = sg.Window("Totems+", layout, icon="img/totems.ico")

# sets the toggle preset
down = True
integration = 0

# while window (GUI) is open
while True:
Expand All @@ -83,29 +84,41 @@ def main():
elif event == '-TOGGLE-':

# program toggle the toggle
down = not down
integration += 1

if integration == 3:
integration = 0

# visual toggle the toggle
window.Element('-TOGGLE-').Update(('Minecraft CMD','Optifine CIT')[down], button_color=(('white', ('teal','orange')[down])))
window.Element('-TOGGLE-').Update(['Minecraft RTX','Minecraft CMD','Optifine CIT'][integration], button_color=(('white', ['red','teal','orange'][integration])))

# if compile and toggle false then
elif event == 'Compile' and down == False:
# if compile and integration type is 1 then
elif event == 'Compile' and integration == 1:

# runs CMD function
CMD(values["-TEXTURES-"], values["-DROPDOWN-"])

# breaks code (hence closing window)
break

# if compile and toggle true then
elif event == 'Compile' and down == True:
# if compile and integration type is 2 then
elif event == 'Compile' and integration == 2:

# runs CIT function
CIT(values["-TEXTURES-"], values["-DROPDOWN-"])

# breaks code (hence closing window)
break

# if compile and integration type is 0 then
elif event == 'Compile' and integration == 0:

# runs RTX functuion
RTX(values["-TEXTURES-"], values["-DROPDOWN-"])

# breaks code (hence closing window)
break

# closes window if called
window.close()

Expand Down

0 comments on commit e0a66d1

Please sign in to comment.