Permalink
Browse files

Biomes topping and contributors file

  • Loading branch information...
1 parent cf4ceec commit c7dcf9ae0e3ea2f83133c0de793a7ef72997c7d1 @sadimusi sadimusi committed Apr 4, 2012
Showing with 125 additions and 4 deletions.
  1. +2 −0 CONTRIBUTORS
  2. +109 −0 burger/toppings/biomes.py
  3. +14 −3 burger/toppings/identify.py
  4. +0 −1 burger/toppings/items.py
View
2 CONTRIBUTORS
@@ -0,0 +1,2 @@
+Tyler Kenendy <tk@tkte.ch>
+Simon Marti <simon@ceilingcat.ch>
View
109 burger/toppings/biomes.py
@@ -0,0 +1,109 @@
+#!/usr/bin/env python
+# -*- coding: utf8 -*-
+"""
+Copyright (c) 2011 Tyler Kenendy <tk@tkte.ch>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+"""
+from solum import ClassFile, ConstantType
+
+from .topping import Topping
+
+
+class BiomeTopping(Topping):
+ """Gets most biome types."""
+
+ PROVIDES = [
+ "biomes"
+ ]
+
+ DEPENDS = [
+ "identify.biome.superclass"
+ ]
+
+ @staticmethod
+ def act(aggregate, jar, verbose=False):
+ superclass = aggregate["classes"]["biome.superclass"]
+ cf = jar.open_class(superclass)
+ method = cf.methods.find_one(name="<clinit>")
+ tmp = None
+ stack = None
+ biomes = aggregate.setdefault("biomes", {})
+ for ins in method.instructions:
+ if ins.opcode == 187: # new
+ if tmp is not None:
+ biomes[tmp["id"]] = tmp
+ stack = []
+ tmp = {
+ "calls": {},
+ "rainfall": 0.5,
+ "height": [0.1, 0.3],
+ "temperature": 0.5,
+ "class": cf.constants[ins.operands[0][1]]["name"]["value"]
+ }
+ elif tmp is None:
+ continue
+ elif ins.opcode == 183: # invokespecial
+ if len(stack) == 1:
+ tmp["id"] = stack.pop()
+ elif len(stack) >= 2:
+ const = cf.constants[ins.operands[0][1]]
+ name = const["name_and_type"]["name"]["value"]
+ tmp["calls"][name] = [stack.pop(), stack.pop()]
+ else:
+ tmp["rainfall"] = 0
+ elif ins.opcode == 182: # invokevirtual
+ if len(stack) == 1 and "color" not in tmp:
+ tmp["color"] = stack.pop()
+
+ # numeric values & constants
+ elif ins.opcode == 18:
+ const = cf.constants[ins.operands[0][1]]
+ if const["tag"] == ConstantType.STRING:
+ tmp["name"] = const["string"]["value"]
+ if const["tag"] in (ConstantType.FLOAT,
+ ConstantType.INTEGER):
+ stack.append(const["value"])
+
+ elif ins.opcode <= 8 and ins.opcode >= 2: # iconst
+ stack.append(ins.opcode - 3)
+ elif ins.opcode >= 0xb and ins.opcode <= 0xd: # fconst
+ stack.append(ins.opcode - 0xb)
+ elif ins.opcode == 16: # bipush
+ stack.append(ins.operands[0][1])
+
+ weather, height = BiomeTopping.map_methods(biomes)
+
+ for biome in biomes.itervalues():
+ calls = biome.pop("calls")
+ if height in calls:
+ biome["height"] = calls[height]
+ biome["height"].reverse()
+ if weather in calls:
+ biome["temperature"] = calls[weather][1]
+ biome["rainfall"] = calls[weather][0]
+
+ @staticmethod
+ def map_methods(biomes):
+ for biome in biomes.itervalues():
+ for call in biome["calls"]:
+ if biome["calls"][call][1] > 1:
+ keys = biome["calls"].keys()
+ keys.remove(call)
+ return (call, keys[0])
View
17 burger/toppings/identify.py
@@ -68,7 +68,7 @@ def identify(cf):
# Item superclass
const = cf.constants.find_one(
ConstantType.STRING,
- lambda c: ("crafting results" in c["string"]["value"] or
+ lambda c: ("crafting results" in c["string"]["value"] or
"CONFLICT @ " in c["string"]["value"])
)
@@ -78,7 +78,7 @@ def identify(cf):
# Entity list
const = cf.constants.find_one(
ConstantType.STRING,
- lambda c: "Skipping Entity with id " in c["string"]["value"]
+ lambda c: "Connection #" in c["string"]["value"]
)
if const:
@@ -102,6 +102,16 @@ def identify(cf):
if const:
return ("nethandler.server", cf.this)
+ # Biome
+ const = cf.constants.find_one(
+ ConstantType.STRING,
+ lambda c: ("Please avoid temperatures in the range 0.1 - 0.2 " +
+ "because of snow") in c["string"]["value"]
+ )
+
+ if const:
+ return ("biome.superclass", cf.this)
+
class IdentifyTopping(Topping):
"""Finds important superclasses needed by other toppings."""
@@ -114,7 +124,8 @@ class IdentifyTopping(Topping):
"identify.recipe.cloth",
"identify.item.superclass",
"identify.entity.list",
- "identify.nethandler"
+ "identify.nethandler",
+ "identify.biome.superclass"
]
DEPENDS = []
View
1 burger/toppings/items.py
@@ -1,7 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf8 -*-
"""
-Copyright (c) 2011 Simon Marti <simon@ceilingcat.ch>
Copyright (c) 2011 Tyler Kenedy <tk@tkte.ch>
Permission is hereby granted, free of charge, to any person obtaining a copy

0 comments on commit c7dcf9a

Please sign in to comment.