Skip to content

Instantly share code, notes, and snippets.

@Podshot
Last active August 29, 2015 14:08
Show Gist options
  • Save Podshot/26af45b9a18a4a73596f to your computer and use it in GitHub Desktop.
Save Podshot/26af45b9a18a4a73596f to your computer and use it in GitHub Desktop.
How to have a filter support both MCEdit-Legacy and MCEdit-Unified
# Thanks to TexelElf for this faster method of version independent editor grabbing code
def perform(level, box, options):
global editor
try:
editor
except:
import inspect
editor = inspect.stack()[1][0].f_locals.get('self', None).editor
# This test filter has to have access to the editor instance
# NOTE: this filter will not work, it is just a guide for implementation
# Some where in your imports
import release
# My personal way of storing the data, you can change this to whatever
# way you like to use
class StoreData:
def __init__(self):
self._isFork = False
self._editor = None
@property
def isFork(self):
return self._isFork
@property
def editor(self):
return self._editor
# Outside all functions
data = StoreData()
# In the perform function
ver = release.get_version()
if "unified" in ver.lower():
try:
data.editor = editor
data.isFork = True
except NameError:
import inspect
data.editor = inspect.stack()[1][0].f_locals.get('self', None).editor
pass
else:
import inspect
data.editor = inspect.stack()[1][0].f_locals.get('self', None).editor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment