Compare commits

...
4 Commits
Author SHA1 Message Date
Martin Robertz 00327aad3b Merge pull request #13 from GTNewHorizons/fix-asm-bad-type
Fix wrong asm types being used for TypeInsnNodes
2023-01-19 18:31:19 +01:00
Raven Szewczyk 1ba2172e8a Fix wrong asm types being used for TypeInsnNodes 2023-01-19 17:12:21 +00:00
Raven Szewczyk ed155c644c Apply spotless 2023-01-19 15:34:07 +00:00
Raven Szewczyk 845b5f68c7 Update buildscript 2023-01-19 15:33:54 +00:00
23 changed files with 1217 additions and 1004 deletions

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
* text eol=lf
*.[jJ][aA][rR] binary
*.[pP][nN][gG] binary
*.[jJ][pP][gG] binary
*.[jJ][pP][eE][gG] binary
*.[gG][iI][fF] binary
*.[tT][iI][fF] binary
*.[tT][iI][fF][fF] binary
*.[iI][cC][oO] binary
*.[sS][vV][gG] text
*.[eE][pP][sS] binary
*.[xX][cC][fF] binary
*.[kK][aA][rR] binary
*.[mM]4[aA] binary
*.[mM][iI][dD] binary
*.[mM][iI][dD][iI] binary
*.[mM][pP]3 binary
*.[oO][gG][gG] binary
*.[rR][aA] binary
*.7[zZ] binary
*.[gG][zZ] binary
*.[tT][aA][rR] binary
*.[tT][gG][zZ] binary
*.[zZ][iI][pP] binary
*.[tT][cC][nN] binary
*.[sS][oO] binary
*.[dD][lL][lL] binary
*.[dD][yY][lL][iI][bB] binary
*.[pP][sS][dD] binary
*.[tT][tT][fF] binary
*.[oO][tT][fF] binary
*.[pP][aA][tT][cC][hH] -text
*.[bB][aA][tT] text eol=crlf
*.[cC][mM][dD] text eol=crlf
*.[pP][sS]1 text eol=crlf
*[aA][uU][tT][oO][gG][eE][nN][eE][rR][aA][tT][eE][dD]* binary
+524 -151
View File
File diff suppressed because it is too large. Load diff
+2 -2
View File
@@ -1,6 +1,6 @@
// Add your dependencies here // Add your dependencies here
dependencies { dependencies {
compile("com.github.GTNewHorizons:CodeChickenLib:1.1.5.5:dev") compile("com.github.GTNewHorizons:CodeChickenLib:1.1.5.7:dev")
compile("com.github.GTNewHorizons:NotEnoughItems:2.3.5-GTNH:dev") compile("com.github.GTNewHorizons:NotEnoughItems:2.3.20-GTNH:dev")
} }
+10
View File
@@ -0,0 +1,10 @@
plugins {
id 'com.diffplug.blowdryerSetup' version '1.6.0'
}
apply plugin: 'com.diffplug.blowdryerSetup'
blowdryerSetup {
github('GTNewHorizons/ExampleMod1.7.10', 'tag', '0.1.5')
//devLocal '.' // Use this when testing config updates locally
}
@@ -8,13 +8,6 @@ import cpw.mods.fml.relauncher.FMLInjectionData;
import cpw.mods.fml.relauncher.FMLLaunchHandler; import cpw.mods.fml.relauncher.FMLLaunchHandler;
import cpw.mods.fml.relauncher.IFMLCallHook; import cpw.mods.fml.relauncher.IFMLCallHook;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin; import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
import net.minecraft.launchwrapper.LaunchClassLoader;
import sun.misc.URLClassPath;
import sun.net.util.URLUtil;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import java.awt.*; import java.awt.*;
import java.awt.Dialog.ModalityType; import java.awt.Dialog.ModalityType;
import java.awt.event.WindowAdapter; import java.awt.event.WindowAdapter;
@@ -35,6 +28,12 @@ import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException; import java.util.regex.PatternSyntaxException;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import net.minecraft.launchwrapper.LaunchClassLoader;
import sun.misc.URLClassPath;
import sun.net.util.URLUtil;
/** /**
* For autodownloading stuff. * For autodownloading stuff.
@@ -72,10 +71,12 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
private Box makeProgressPanel() { private Box makeProgressPanel() {
Box box = Box.createVerticalBox(); Box box = Box.createVerticalBox();
box.add(Box.createRigidArea(new Dimension(0, 10))); box.add(Box.createRigidArea(new Dimension(0, 10)));
JLabel welcomeLabel = new JLabel("<html><b><font size='+1'>" + owner + " is setting up your minecraft environment</font></b></html>"); JLabel welcomeLabel = new JLabel("<html><b><font size='+1'>" + owner
+ " is setting up your minecraft environment</font></b></html>");
box.add(welcomeLabel); box.add(welcomeLabel);
welcomeLabel.setAlignmentY(LEFT_ALIGNMENT); welcomeLabel.setAlignmentY(LEFT_ALIGNMENT);
welcomeLabel = new JLabel("<html>Please wait, " + owner + " has some tasks to do before you can play</html>"); welcomeLabel =
new JLabel("<html>Please wait, " + owner + " has some tasks to do before you can play</html>");
welcomeLabel.setAlignmentY(LEFT_ALIGNMENT); welcomeLabel.setAlignmentY(LEFT_ALIGNMENT);
box.add(welcomeLabel); box.add(welcomeLabel);
box.add(Box.createRigidArea(new Dimension(0, 10))); box.add(Box.createRigidArea(new Dimension(0, 10)));
@@ -91,12 +92,11 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
@Override @Override
public JDialog makeDialog() { public JDialog makeDialog() {
if (container != null) if (container != null) return container;
return container;
setMessageType(JOptionPane.INFORMATION_MESSAGE); setMessageType(JOptionPane.INFORMATION_MESSAGE);
setMessage(makeProgressPanel()); setMessage(makeProgressPanel());
setOptions(new Object[]{"Stop"}); setOptions(new Object[] {"Stop"});
addPropertyChangeListener(new PropertyChangeListener() { addPropertyChangeListener(new PropertyChangeListener() {
@Override @Override
public void propertyChange(PropertyChangeEvent evt) { public void propertyChange(PropertyChangeEvent evt) {
@@ -117,39 +117,40 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
container.addWindowListener(new WindowAdapter() { container.addWindowListener(new WindowAdapter() {
@Override @Override
public void windowClosing(WindowEvent e) { public void windowClosing(WindowEvent e) {
requestClose("Closing this window will stop minecraft from launching\nAre you sure you wish to do this?"); requestClose(
"Closing this window will stop minecraft from launching\nAre you sure you wish to do this?");
} }
}); });
return container; return container;
} }
protected void requestClose(String message) { protected void requestClose(String message) {
int shouldClose = JOptionPane.showConfirmDialog(container, message, "Are you sure you want to stop?", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); int shouldClose = JOptionPane.showConfirmDialog(
if (shouldClose == JOptionPane.YES_OPTION) container,
container.dispose(); message,
"Are you sure you want to stop?",
JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE);
if (shouldClose == JOptionPane.YES_OPTION) container.dispose();
stopIt = true; stopIt = true;
if (pokeThread != null) if (pokeThread != null) pokeThread.interrupt();
pokeThread.interrupt();
} }
@Override @Override
public void updateProgressString(String progressUpdate, Object... data) { public void updateProgressString(String progressUpdate, Object... data) {
//FMLLog.finest(progressUpdate, data); // FMLLog.finest(progressUpdate, data);
if (currentActivity != null) if (currentActivity != null) currentActivity.setText(String.format(progressUpdate, data));
currentActivity.setText(String.format(progressUpdate, data));
} }
@Override @Override
public void resetProgress(int sizeGuess) { public void resetProgress(int sizeGuess) {
if (progress != null) if (progress != null) progress.getModel().setRangeProperties(0, 0, 0, sizeGuess, false);
progress.getModel().setRangeProperties(0, 0, 0, sizeGuess, false);
} }
@Override @Override
public void updateProgress(int fullLength) { public void updateProgress(int fullLength) {
if (progress != null) if (progress != null) progress.getModel().setValue(fullLength);
progress.getModel().setValue(fullLength);
} }
@Override @Override
@@ -164,12 +165,13 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
@Override @Override
public void showErrorDialog(String name, String url) { public void showErrorDialog(String name, String url) {
JEditorPane ep = new JEditorPane("text/html", JEditorPane ep = new JEditorPane(
"<html>" + "text/html",
owner + " was unable to download required library " + name + "<html>" + owner
"<br>Check your internet connection and try restarting or download it manually from" + + " was unable to download required library " + name
"<br><a href=\"" + url + "\">" + url + "</a> and put it in your mods folder" + + "<br>Check your internet connection and try restarting or download it manually from"
"</html>"); + "<br><a href=\""
+ url + "\">" + url + "</a> and put it in your mods folder" + "</html>");
ep.setEditable(false); ep.setEditable(false);
ep.setOpaque(false); ep.setOpaque(false);
@@ -190,16 +192,13 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
public static class DummyDownloader implements IDownloadDisplay { public static class DummyDownloader implements IDownloadDisplay {
@Override @Override
public void resetProgress(int sizeGuess) { public void resetProgress(int sizeGuess) {}
}
@Override @Override
public void setPokeThread(Thread currentThread) { public void setPokeThread(Thread currentThread) {}
}
@Override @Override
public void updateProgress(int fullLength) { public void updateProgress(int fullLength) {}
}
@Override @Override
public boolean shouldStopIt() { public boolean shouldStopIt() {
@@ -207,8 +206,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
} }
@Override @Override
public void updateProgressString(String string, Object... data) { public void updateProgressString(String string, Object... data) {}
}
@Override @Override
public Object makeDialog() { public Object makeDialog() {
@@ -216,12 +214,10 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
} }
@Override @Override
public void showErrorDialog(String name, String url) { public void showErrorDialog(String name, String url) {}
}
} }
public static class VersionedFile public static class VersionedFile {
{
public final Pattern pattern; public final Pattern pattern;
public final String filename; public final String filename;
public final ComparableVersion version; public final ComparableVersion version;
@@ -231,11 +227,10 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
this.pattern = pattern; this.pattern = pattern;
this.filename = filename; this.filename = filename;
Matcher m = pattern.matcher(filename); Matcher m = pattern.matcher(filename);
if(m.matches()) { if (m.matches()) {
name = m.group(1); name = m.group(1);
version = new ComparableVersion(m.group(2)); version = new ComparableVersion(m.group(2));
} } else {
else {
name = null; name = null;
version = null; version = null;
} }
@@ -246,8 +241,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
} }
} }
public static class Dependency public static class Dependency {
{
public String url; public String url;
public VersionedFile file; public VersionedFile file;
@@ -279,21 +273,20 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
modsDir = new File(mcDir, "mods"); modsDir = new File(mcDir, "mods");
v_modsDir = new File(mcDir, "mods/" + mcVer); v_modsDir = new File(mcDir, "mods/" + mcVer);
if (!v_modsDir.exists()) if (!v_modsDir.exists()) v_modsDir.mkdirs();
v_modsDir.mkdirs();
} }
private void addClasspath(String name) { private void addClasspath(String name) {
try { try {
((LaunchClassLoader) DepLoader.class.getClassLoader()).addURL(new File(v_modsDir, name).toURI().toURL()); ((LaunchClassLoader) DepLoader.class.getClassLoader())
.addURL(new File(v_modsDir, name).toURI().toURL());
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
private void deleteMod(File mod) { private void deleteMod(File mod) {
if (mod.delete()) if (mod.delete()) return;
return;
try { try {
ClassLoader cl = DepLoader.class.getClassLoader(); ClassLoader cl = DepLoader.class.getClassLoader();
@@ -317,7 +310,8 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
if (!mod.delete()) { if (!mod.delete()) {
mod.deleteOnExit(); mod.deleteOnExit();
String msg = owner + " was unable to delete file " + mod.getPath() + " the game will now try to delete it on exit. If this dialog appears again, delete it manually."; String msg = owner + " was unable to delete file " + mod.getPath()
+ " the game will now try to delete it on exit. If this dialog appears again, delete it manually.";
System.err.println(msg); System.err.println(msg);
if (!GraphicsEnvironment.isHeadless()) if (!GraphicsEnvironment.isHeadless())
JOptionPane.showMessageDialog(null, msg, "An update error has occured", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(null, msg, "An update error has occured", JOptionPane.ERROR_MESSAGE);
@@ -357,7 +351,9 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
private void download(InputStream is, int sizeGuess, File target) throws Exception { private void download(InputStream is, int sizeGuess, File target) throws Exception {
if (sizeGuess > downloadBuffer.capacity()) if (sizeGuess > downloadBuffer.capacity())
throw new Exception(String.format("The file %s is too large to be downloaded by " + owner + " - the download is invalid", target.getName())); throw new Exception(String.format(
"The file %s is too large to be downloaded by " + owner + " - the download is invalid",
target.getName()));
downloadBuffer.clear(); downloadBuffer.clear();
@@ -391,9 +387,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
/*String cksum = generateChecksum(downloadBuffer); /*String cksum = generateChecksum(downloadBuffer);
if (cksum.equals(validationHash)) if (cksum.equals(validationHash))
{*/ {*/
if (!target.exists()) if (!target.exists()) target.createNewFile();
target.createNewFile();
downloadBuffer.position(0); downloadBuffer.position(0);
FileOutputStream fos = new FileOutputStream(target); FileOutputStream fos = new FileOutputStream(target);
@@ -412,19 +406,16 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
private String checkExisting(Dependency dep) { private String checkExisting(Dependency dep) {
for (File f : modsDir.listFiles()) { for (File f : modsDir.listFiles()) {
VersionedFile vfile = new VersionedFile(f.getName(), dep.file.pattern); VersionedFile vfile = new VersionedFile(f.getName(), dep.file.pattern);
if (!vfile.matches() || !vfile.name.equals(dep.file.name)) if (!vfile.matches() || !vfile.name.equals(dep.file.name)) continue;
continue;
if (f.renameTo(new File(v_modsDir, f.getName()))) if (f.renameTo(new File(v_modsDir, f.getName()))) continue;
continue;
deleteMod(f); deleteMod(f);
} }
for (File f : v_modsDir.listFiles()) { for (File f : v_modsDir.listFiles()) {
VersionedFile vfile = new VersionedFile(f.getName(), dep.file.pattern); VersionedFile vfile = new VersionedFile(f.getName(), dep.file.pattern);
if (!vfile.matches() || !vfile.name.equals(dep.file.name)) if (!vfile.matches() || !vfile.name.equals(dep.file.name)) continue;
continue;
int cmp = vfile.version.compareTo(dep.file.version); int cmp = vfile.version.compareTo(dep.file.version);
if (cmp < 0) { if (cmp < 0) {
@@ -433,27 +424,25 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
return null; return null;
} }
if (cmp > 0) { if (cmp > 0) {
System.err.println("Warning: version of " + dep.file.name + ", " + vfile.version + " is newer than request " + dep.file.version); System.err.println("Warning: version of " + dep.file.name + ", " + vfile.version
+ " is newer than request " + dep.file.version);
return f.getName(); return f.getName();
} }
return f.getName();//found dependency return f.getName(); // found dependency
} }
return null; return null;
} }
public void load() { public void load() {
scanDepInfos(); scanDepInfos();
if (depMap.isEmpty()) if (depMap.isEmpty()) return;
return;
loadDeps(); loadDeps();
activateDeps(); activateDeps();
} }
private void activateDeps() { private void activateDeps() {
for (Dependency dep : depMap.values()) for (Dependency dep : depMap.values()) if (dep.coreLib) addClasspath(dep.existing);
if (dep.coreLib)
addClasspath(dep.existing);
} }
private void loadDeps() { private void loadDeps() {
@@ -475,7 +464,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
private void load(Dependency dep) { private void load(Dependency dep) {
dep.existing = checkExisting(dep); dep.existing = checkExisting(dep);
if (dep.existing == null)//download dep if (dep.existing == null) // download dep
{ {
download(dep); download(dep);
dep.existing = dep.file.filename; dep.existing = dep.file.filename;
@@ -491,8 +480,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
private void scanDepInfos() { private void scanDepInfos() {
for (File file : modFiles()) { for (File file : modFiles()) {
if (!file.getName().endsWith(".jar") && !file.getName().endsWith(".zip")) if (!file.getName().endsWith(".jar") && !file.getName().endsWith(".zip")) continue;
continue;
scanDepInfo(file); scanDepInfo(file);
} }
@@ -503,8 +491,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
ZipFile zip = new ZipFile(file); ZipFile zip = new ZipFile(file);
ZipEntry e = zip.getEntry("dependancies.info"); ZipEntry e = zip.getEntry("dependancies.info");
if (e == null) e = zip.getEntry("dependencies.info"); if (e == null) e = zip.getEntry("dependencies.info");
if (e != null) if (e != null) loadJSon(zip.getInputStream(e));
loadJSon(zip.getInputStream(e));
zip.close(); zip.close();
} catch (Exception e) { } catch (Exception e) {
System.err.println("Failed to load dependencies.info from " + file.getName() + " as JSON"); System.err.println("Failed to load dependencies.info from " + file.getName() + " as JSON");
@@ -515,47 +502,41 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
private void loadJSon(InputStream input) throws IOException { private void loadJSon(InputStream input) throws IOException {
InputStreamReader reader = new InputStreamReader(input); InputStreamReader reader = new InputStreamReader(input);
JsonElement root = new JsonParser().parse(reader); JsonElement root = new JsonParser().parse(reader);
if (root.isJsonArray()) if (root.isJsonArray()) loadJSonArr(root);
loadJSonArr(root); else loadJson(root.getAsJsonObject());
else
loadJson(root.getAsJsonObject());
reader.close(); reader.close();
} }
private void loadJSonArr(JsonElement root) throws IOException { private void loadJSonArr(JsonElement root) throws IOException {
for (JsonElement node : root.getAsJsonArray()) for (JsonElement node : root.getAsJsonArray()) loadJson(node.getAsJsonObject());
loadJson(node.getAsJsonObject());
} }
private void loadJson(JsonObject node) throws IOException { private void loadJson(JsonObject node) throws IOException {
boolean obfuscated = ((LaunchClassLoader) DepLoader.class.getClassLoader()) boolean obfuscated =
.getClassBytes("net.minecraft.world.World") == null; ((LaunchClassLoader) DepLoader.class.getClassLoader()).getClassBytes("net.minecraft.world.World")
== null;
String testClass = node.get("class").getAsString(); String testClass = node.get("class").getAsString();
if (DepLoader.class.getResource("/" + testClass.replace('.', '/') + ".class") != null) if (DepLoader.class.getResource("/" + testClass.replace('.', '/') + ".class") != null) return;
return;
String repo = node.get("repo").getAsString(); String repo = node.get("repo").getAsString();
String filename = node.get("file").getAsString(); String filename = node.get("file").getAsString();
if (!obfuscated && node.has("dev")) if (!obfuscated && node.has("dev")) filename = node.get("dev").getAsString();
filename = node.get("dev").getAsString();
boolean coreLib = node.has("coreLib") && node.get("coreLib").getAsBoolean(); boolean coreLib = node.has("coreLib") && node.get("coreLib").getAsBoolean();
Pattern pattern = null; Pattern pattern = null;
try { try {
if(node.has("pattern")) if (node.has("pattern"))
pattern = Pattern.compile(node.get("pattern").getAsString()); pattern = Pattern.compile(node.get("pattern").getAsString());
} catch (PatternSyntaxException e) { } catch (PatternSyntaxException e) {
System.err.println("Invalid filename pattern: "+node.get("pattern")); System.err.println("Invalid filename pattern: " + node.get("pattern"));
e.printStackTrace(); e.printStackTrace();
} }
if(pattern == null) if (pattern == null) pattern = Pattern.compile("(\\w+).*?([\\d\\.]+)[-\\w]*\\.[^\\d]+");
pattern = Pattern.compile("(\\w+).*?([\\d\\.]+)[-\\w]*\\.[^\\d]+");
VersionedFile file = new VersionedFile(filename, pattern); VersionedFile file = new VersionedFile(filename, pattern);
if (!file.matches()) if (!file.matches()) throw new RuntimeException("Invalid filename format for dependency: " + filename);
throw new RuntimeException("Invalid filename format for dependency: " + filename);
addDep(new Dependency(repo, file, coreLib)); addDep(new Dependency(repo, file, coreLib));
} }
@@ -568,8 +549,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
} }
private boolean mergeNew(Dependency oldDep, Dependency newDep) { private boolean mergeNew(Dependency oldDep, Dependency newDep) {
if (oldDep == null) if (oldDep == null) return true;
return true;
Dependency newest = newDep.file.version.compareTo(oldDep.file.version) > 0 ? newDep : oldDep; Dependency newest = newDep.file.version.compareTo(oldDep.file.version) > 0 ? newDep : oldDep;
newest.coreLib = newDep.coreLib || oldDep.coreLib; newest.coreLib = newDep.coreLib || oldDep.coreLib;
@@ -601,8 +581,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
} }
@Override @Override
public void injectData(Map<String, Object> data) { public void injectData(Map<String, Object> data) {}
}
@Override @Override
public Void call() { public Void call() {
@@ -4,8 +4,7 @@ package codechicken.multipart;
* Defines what each slot in a multipart tile corresponds to and provides some utility functions. * Defines what each slot in a multipart tile corresponds to and provides some utility functions.
* For performance reasons, it is recommended that integer constants be useds as opposed to this enum * For performance reasons, it is recommended that integer constants be useds as opposed to this enum
*/ */
public enum PartMap public enum PartMap {
{
BOTTOM(0), BOTTOM(0),
TOP(1), TOP(1),
NORTH(2), NORTH(2),
@@ -13,122 +12,119 @@ public enum PartMap
WEST(4), WEST(4),
EAST(5), EAST(5),
CENTER(6), CENTER(6),
CORNER_NNN(7),//0 CORNER_NNN(7), // 0
CORNER_NPN(8),//1 CORNER_NPN(8), // 1
CORNER_NNP(9),//2 CORNER_NNP(9), // 2
CORNER_NPP(10),//3 CORNER_NPP(10), // 3
CORNER_PNN(11),//4 CORNER_PNN(11), // 4
CORNER_PPN(12),//5 CORNER_PPN(12), // 5
CORNER_PNP(13),//6 CORNER_PNP(13), // 6
CORNER_PPP(14),//7 CORNER_PPP(14), // 7
EDGE_NYN(15),//0 EDGE_NYN(15), // 0
EDGE_NYP(16),//1 EDGE_NYP(16), // 1
EDGE_PYN(17),//2 EDGE_PYN(17), // 2
EDGE_PYP(18),//3 EDGE_PYP(18), // 3
EDGE_NNZ(19),//4 EDGE_NNZ(19), // 4
EDGE_PNZ(20),//5 EDGE_PNZ(20), // 5
EDGE_NPZ(21),//6 EDGE_NPZ(21), // 6
EDGE_PPZ(22),//7 EDGE_PPZ(22), // 7
EDGE_XNN(23),//8 EDGE_XNN(23), // 8
EDGE_XPN(24),//9 EDGE_XPN(24), // 9
EDGE_XNP(25),//10 EDGE_XNP(25), // 10
EDGE_XPP(26);//11 EDGE_XPP(26); // 11
public final int i; public final int i;
public final int mask; public final int mask;
private PartMap(int i) private PartMap(int i) {
{
this.i = i; this.i = i;
mask = 1<<i; mask = 1 << i;
} }
/** /**
* Don't actually use this. * Don't actually use this.
*/ */
public static PartMap face(int i) public static PartMap face(int i) {
{
return values()[i]; return values()[i];
} }
/** /**
* Don't actually use this. * Don't actually use this.
*/ */
public static PartMap edge(int i) public static PartMap edge(int i) {
{ return values()[i + 15];
return values()[i+15];
} }
/** /**
* Don't actually use this. * Don't actually use this.
*/ */
public static PartMap corner(int i) public static PartMap corner(int i) {
{ return values()[i + 7];
return values()[i+7];
} }
/** /**
* Returns a 3 bit mask of the axis xzy that are variable in this edge. * Returns a 3 bit mask of the axis xzy that are variable in this edge.
* For example, the first 4 edges (15-18) are along the Y axis, variable in x and z, so the mask is 110b. Note axis y is 1<<0, z is 1<<1 and x is 1<<2 * For example, the first 4 edges (15-18) are along the Y axis, variable in x and z, so the mask is 110b. Note axis y is 1<<0, z is 1<<1 and x is 1<<2
* Note the parameter e is relative to the first edge slot and can range from 0-11 * Note the parameter e is relative to the first edge slot and can range from 0-11
*/ */
public static int edgeAxisMask(int e) public static int edgeAxisMask(int e) {
{ switch (e >> 2) {
switch(e>>2) case 0:
{ return 6;
case 0: return 6; case 1:
case 1: return 5; return 5;
case 2: return 3; case 2:
return 3;
} }
throw new IllegalArgumentException("Switch Falloff"); throw new IllegalArgumentException("Switch Falloff");
} }
/** /**
* Unpacks an edge index, to a mask where high values indicate positive positions in that axis. * Unpacks an edge index, to a mask where high values indicate positive positions in that axis.
* Note the parameter e is relative to the first edge slot and can range from 0-11 * Note the parameter e is relative to the first edge slot and can range from 0-11
* For example, edge 1 (slot 16), is EDGE_NYP so the mask returned would be 010 as z is positive. * For example, edge 1 (slot 16), is EDGE_NYP so the mask returned would be 010 as z is positive.
*/ */
public static int unpackEdgeBits(int e) public static int unpackEdgeBits(int e) {
{ switch (e >> 2) {
switch(e>>2) case 0:
{ return (e & 3) << 1;
case 0: return (e&3)<<1; case 1:
case 1: return (e&2)>>1|(e&1)<<2; return (e & 2) >> 1 | (e & 1) << 2;
case 2: return (e&3); case 2:
return (e & 3);
} }
throw new IllegalArgumentException("Switch Falloff"); throw new IllegalArgumentException("Switch Falloff");
} }
/** /**
* Repacks a mask of axis bits indicating positive positions, into an edge in along the same axis as e. * Repacks a mask of axis bits indicating positive positions, into an edge in along the same axis as e.
* Note the parameter e is relative to the first edge slot and can range from 0-11 * Note the parameter e is relative to the first edge slot and can range from 0-11
*/ */
public static int packEdgeBits(int e, int bits) public static int packEdgeBits(int e, int bits) {
{ switch (e >> 2) {
switch(e>>2) case 0:
{ return e & 0xC | bits >> 1;
case 0: return e&0xC|bits>>1; case 1:
case 1: return e&0xC|(bits&4)>>2|(bits&1)<<1; return e & 0xC | (bits & 4) >> 2 | (bits & 1) << 1;
case 2: return e&0xC|bits&3; case 2:
return e & 0xC | bits & 3;
} }
throw new IllegalArgumentException("Switch Falloff"); throw new IllegalArgumentException("Switch Falloff");
} }
private static int[] edgeBetweenMap = new int[]{ private static int[] edgeBetweenMap = new int[] {
-1, -1, 8, 10, 4, 5, -1, -1, 8, 10, 4, 5,
-1, -1, 9, 11, 6, 7, -1, -1, 9, 11, 6, 7,
-1, -1,-1, -1, 0, 2, -1, -1, -1, -1, 0, 2,
-1, -1,-1, -1, 1, 3}; -1, -1, -1, -1, 1, 3
};
/** /**
* Returns the slot of the edge between 2 sides. * Returns the slot of the edge between 2 sides.
*/ */
public static int edgeBetween(int s1, int s2) public static int edgeBetween(int s1, int s2) {
{ if (s2 < s1) return edgeBetween(s2, s1);
if(s2 < s1) if ((s1 & 6) == (s2 & 6)) throw new IllegalArgumentException("Faces " + s1 + " and " + s2 + " are opposites");
return edgeBetween(s2, s1); return 15 + edgeBetweenMap[s1 * 6 + s2];
if((s1&6) == (s2&6))
throw new IllegalArgumentException("Faces "+s1+" and "+s2+" are opposites");
return 15+edgeBetweenMap[s1*6+s2];
} }
} }
@@ -446,7 +446,7 @@ object ASMMixinCompiler
} }
def staticTransform(mnode: MethodNode, base: MethodNode) { def staticTransform(mnode: MethodNode, base: MethodNode) {
val stack = new StackAnalyser(getType(cnode.name), base) val stack = new StackAnalyser(getType(Type.getObjectType(cnode.name).getDescriptor), base)
val insnList = mnode.instructions val insnList = mnode.instructions
var insn = insnList.getFirst var insn = insnList.getFirst
@@ -478,7 +478,7 @@ object ASMMixinCompiler
//cast to parent class and call //cast to parent class and call
val mType = Type.getMethodType(minsn.desc) val mType = Type.getMethodType(minsn.desc)
val instanceEntry = stack.peek(width(mType.getArgumentTypes)) val instanceEntry = stack.peek(width(mType.getArgumentTypes))
insnList.insert(instanceEntry.insn, new TypeInsnNode(CHECKCAST, cnode.superName)) insnList.insert(instanceEntry.insn, new TypeInsnNode(CHECKCAST, Type.getObjectType(cnode.superName).getDescriptor))
minsn.owner = cnode.superName minsn.owner = cnode.superName
} }
} }
@@ -283,10 +283,10 @@ class StackAnalyser(val owner:Type, val m:MethodNode)
} }
case tinsn:TypeInsnNode => ainsn.getOpcode match case tinsn:TypeInsnNode => ainsn.getOpcode match
{ {
case NEW => push(New(getType(tinsn.desc))) case NEW => push(New(getObjectType(tinsn.desc)))
case NEWARRAY => push(NewArray(pop(), getType(tinsn.desc))) case NEWARRAY => push(NewArray(pop(), getObjectType(tinsn.desc)))
case ANEWARRAY => push(NewArray(pop(), getType("["+tinsn.desc))) case ANEWARRAY => push(NewArray(pop(), getObjectType("["+tinsn.desc)))
case CHECKCAST => push(Cast(pop(), getType(tinsn.desc))) case CHECKCAST => push(Cast(pop(), getObjectType(tinsn.desc)))
case INSTANCEOF => push(UnaryOp(INSTANCEOF, pop())) case INSTANCEOF => push(UnaryOp(INSTANCEOF, pop()))
} }
case mainsn:MultiANewArrayInsnNode => case mainsn:MultiANewArrayInsnNode =>
@@ -4,7 +4,6 @@ import codechicken.lib.vec.BlockCoord;
import codechicken.lib.vec.Cuboid6; import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Vector3; import codechicken.lib.vec.Vector3;
import codechicken.multipart.IFaceRedstonePart; import codechicken.multipart.IFaceRedstonePart;
import codechicken.multipart.TickScheduler;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockButton; import net.minecraft.block.BlockButton;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@@ -16,169 +15,136 @@ import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class ButtonPart extends McSidedMetaPart implements IFaceRedstonePart public class ButtonPart extends McSidedMetaPart implements IFaceRedstonePart {
{
public static BlockButton stoneButton = (BlockButton) Blocks.stone_button; public static BlockButton stoneButton = (BlockButton) Blocks.stone_button;
public static BlockButton woodenButton = (BlockButton) Blocks.wooden_button; public static BlockButton woodenButton = (BlockButton) Blocks.wooden_button;
public static int[] metaSideMap = new int[]{-1, 4, 5, 2, 3}; public static int[] metaSideMap = new int[] {-1, 4, 5, 2, 3};
public static int[] sideMetaMap = new int[]{-1, -1, 3, 4, 1, 2}; public static int[] sideMetaMap = new int[] {-1, -1, 3, 4, 1, 2};
public static BlockButton getButton(int meta) public static BlockButton getButton(int meta) {
{ return (meta & 0x10) > 0 ? woodenButton : stoneButton;
return (meta&0x10) > 0 ? woodenButton : stoneButton;
} }
public ButtonPart() public ButtonPart() {}
{
} public ButtonPart(int meta) {
public ButtonPart(int meta)
{
super(meta); super(meta);
} }
@Override @Override
public int sideForMeta(int meta) public int sideForMeta(int meta) {
{ return metaSideMap[meta & 7];
return metaSideMap[meta&7];
} }
@Override @Override
public Block getBlock() public Block getBlock() {
{
return getButton(meta); return getButton(meta);
} }
@Override @Override
public String getType() public String getType() {
{
return "mc_button"; return "mc_button";
} }
public int delay() public int delay() {
{
return sensitive() ? 30 : 20; return sensitive() ? 30 : 20;
} }
public boolean sensitive() public boolean sensitive() {
{ return (meta & 0x10) > 0;
return (meta&0x10) > 0;
} }
@Override @Override
public Cuboid6 getBounds() public Cuboid6 getBounds() {
{
int m = meta & 7; int m = meta & 7;
double d = pressed() ? 0.0625 : 0.125; double d = pressed() ? 0.0625 : 0.125;
if (m == 1) if (m == 1) return new Cuboid6(0.0, 0.375, 0.5 - 0.1875, d, 0.625, 0.5 + 0.1875);
return new Cuboid6(0.0, 0.375, 0.5 - 0.1875, d, 0.625, 0.5 + 0.1875); if (m == 2) return new Cuboid6(1.0 - d, 0.375, 0.5 - 0.1875, 1.0, 0.625, 0.5 + 0.1875);
if (m == 2) if (m == 3) return new Cuboid6(0.5 - 0.1875, 0.375, 0.0, 0.5 + 0.1875, 0.625, d);
return new Cuboid6(1.0 - d, 0.375, 0.5 - 0.1875, 1.0, 0.625, 0.5 + 0.1875); if (m == 4) return new Cuboid6(0.5 - 0.1875, 0.375, 1.0 - d, 0.5 + 0.1875, 0.625, 1.0);
if (m == 3)
return new Cuboid6(0.5 - 0.1875, 0.375, 0.0, 0.5 + 0.1875, 0.625, d); return null; // falloff
if (m == 4)
return new Cuboid6(0.5 - 0.1875, 0.375, 1.0 - d, 0.5 + 0.1875, 0.625, 1.0);
return null;//falloff
} }
public static McBlockPart placement(World world, BlockCoord pos, int side, int type) public static McBlockPart placement(World world, BlockCoord pos, int side, int type) {
{ if (side == 0 || side == 1) return null;
if(side == 0 || side == 1)
return null; pos = pos.copy().offset(side ^ 1);
if (!world.isSideSolid(pos.x, pos.y, pos.z, ForgeDirection.getOrientation(side))) return null;
pos = pos.copy().offset(side^1);
if(!world.isSideSolid(pos.x, pos.y, pos.z, ForgeDirection.getOrientation(side))) return new ButtonPart(sideMetaMap[side ^ 1] | type << 4);
return null;
return new ButtonPart(sideMetaMap[side^1]|type<<4);
} }
@Override @Override
public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item) public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item) {
{ if (pressed()) return false;
if(pressed())
return false; if (!world().isRemote) toggle();
if(!world().isRemote)
toggle();
return true; return true;
} }
@Override @Override
public void scheduledTick() public void scheduledTick() {
{ if (pressed()) updateState();
if(pressed())
updateState();
}
public boolean pressed()
{
return (meta&8) > 0;
}
@Override
public void onEntityCollision(Entity entity)
{
if(!pressed() && !world().isRemote && entity instanceof EntityArrow)
updateState();
} }
private void toggle() public boolean pressed() {
{ return (meta & 8) > 0;
}
@Override
public void onEntityCollision(Entity entity) {
if (!pressed() && !world().isRemote && entity instanceof EntityArrow) updateState();
}
private void toggle() {
boolean in = !pressed(); boolean in = !pressed();
meta^=8; meta ^= 8;
world().playSoundEffect(x() + 0.5, y() + 0.5, z() + 0.5, "random.click", 0.3F, in ? 0.6F : 0.5F); world().playSoundEffect(x() + 0.5, y() + 0.5, z() + 0.5, "random.click", 0.3F, in ? 0.6F : 0.5F);
if(in) if (in) scheduleTick(delay());
scheduleTick(delay());
sendDescUpdate(); sendDescUpdate();
tile().notifyPartChange(this); tile().notifyPartChange(this);
tile().notifyNeighborChange(metaSideMap[meta&7]); tile().notifyNeighborChange(metaSideMap[meta & 7]);
tile().markDirty(); tile().markDirty();
} }
private void updateState() private void updateState() {
{ boolean arrows = sensitive()
boolean arrows = sensitive() && !world().getEntitiesWithinAABB(EntityArrow.class, && !world().getEntitiesWithinAABB(
getBounds().add(Vector3.fromTileEntity(tile())).toAABB()).isEmpty(); EntityArrow.class,
getBounds().add(Vector3.fromTileEntity(tile())).toAABB())
.isEmpty();
boolean pressed = pressed(); boolean pressed = pressed();
if(arrows != pressed) if (arrows != pressed) toggle();
toggle(); if (arrows && pressed) scheduleTick(delay());
if(arrows && pressed)
scheduleTick(delay());
} }
@Override @Override
public void onRemoved() public void onRemoved() {
{ if (pressed()) tile().notifyNeighborChange(metaSideMap[meta & 7]);
if(pressed())
tile().notifyNeighborChange(metaSideMap[meta&7]);
} }
@Override @Override
public int weakPowerLevel(int side) public int weakPowerLevel(int side) {
{
return pressed() ? 15 : 0; return pressed() ? 15 : 0;
} }
@Override @Override
public int strongPowerLevel(int side) public int strongPowerLevel(int side) {
{ return pressed() && side == metaSideMap[meta & 7] ? 15 : 0;
return pressed() && side == metaSideMap[meta&7] ? 15 : 0;
} }
@Override @Override
public boolean canConnectRedstone(int side) public boolean canConnectRedstone(int side) {
{
return true; return true;
} }
@Override @Override
public int getFace() { public int getFace() {
return metaSideMap[meta&7]; return metaSideMap[meta & 7];
} }
} }
@@ -1,63 +1,53 @@
package codechicken.multipart.minecraft; package codechicken.multipart.minecraft;
import codechicken.lib.vec.BlockCoord;
import codechicken.multipart.MultiPartRegistry;
import codechicken.multipart.MultiPartRegistry.IPartConverter;
import codechicken.multipart.MultiPartRegistry.IPartFactory;
import codechicken.multipart.TMultiPart;
import java.util.Arrays;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.world.World; import net.minecraft.world.World;
import codechicken.lib.vec.BlockCoord;
import codechicken.multipart.MultiPartRegistry.IPartConverter;
import codechicken.multipart.MultiPartRegistry.IPartFactory;
import codechicken.multipart.MultiPartRegistry;
import codechicken.multipart.TMultiPart;
import java.util.Arrays; public class Content implements IPartFactory, IPartConverter {
public class Content implements IPartFactory, IPartConverter
{
@Override @Override
public TMultiPart createPart(String name, boolean client) public TMultiPart createPart(String name, boolean client) {
{ if (name.equals("mc_torch")) return new TorchPart();
if(name.equals("mc_torch")) return new TorchPart(); if (name.equals("mc_lever")) return new LeverPart();
if(name.equals("mc_lever")) return new LeverPart(); if (name.equals("mc_button")) return new ButtonPart();
if(name.equals("mc_button")) return new ButtonPart(); if (name.equals("mc_redtorch")) return new RedstoneTorchPart();
if(name.equals("mc_redtorch")) return new RedstoneTorchPart();
return null; return null;
} }
public void init() public void init() {
{
MultiPartRegistry.registerConverter(this); MultiPartRegistry.registerConverter(this);
MultiPartRegistry.registerParts(this, new String[]{ MultiPartRegistry.registerParts(this, new String[] {"mc_torch", "mc_lever", "mc_button", "mc_redtorch"});
"mc_torch",
"mc_lever",
"mc_button",
"mc_redtorch"
});
} }
@Override @Override
public Iterable<Block> blockTypes() { public Iterable<Block> blockTypes() {
return Arrays.asList(Blocks.torch, Blocks.lever, Blocks.stone_button, Blocks.wooden_button, Blocks.redstone_torch, Blocks.unlit_redstone_torch); return Arrays.asList(
Blocks.torch,
Blocks.lever,
Blocks.stone_button,
Blocks.wooden_button,
Blocks.redstone_torch,
Blocks.unlit_redstone_torch);
} }
@Override @Override
public TMultiPart convert(World world, BlockCoord pos) public TMultiPart convert(World world, BlockCoord pos) {
{
Block b = world.getBlock(pos.x, pos.y, pos.z); Block b = world.getBlock(pos.x, pos.y, pos.z);
int meta = world.getBlockMetadata(pos.x, pos.y, pos.z); int meta = world.getBlockMetadata(pos.x, pos.y, pos.z);
if(b == Blocks.torch) if (b == Blocks.torch) return new TorchPart(meta);
return new TorchPart(meta); if (b == Blocks.lever) return new LeverPart(meta);
if(b == Blocks.lever) if (b == Blocks.stone_button) return new ButtonPart(meta);
return new LeverPart(meta); if (b == Blocks.wooden_button) return new ButtonPart(meta | 0x10);
if(b == Blocks.stone_button) if (b == Blocks.redstone_torch) return new RedstoneTorchPart(meta);
return new ButtonPart(meta); if (b == Blocks.unlit_redstone_torch) return new RedstoneTorchPart(meta | 0x10);
if(b == Blocks.wooden_button)
return new ButtonPart(meta|0x10);
if(b == Blocks.redstone_torch)
return new RedstoneTorchPart(meta);
if(b == Blocks.unlit_redstone_torch)
return new RedstoneTorchPart(meta|0x10);
return null; return null;
} }
} }
@@ -6,6 +6,7 @@ import codechicken.lib.vec.BlockCoord;
import codechicken.lib.vec.Vector3; import codechicken.lib.vec.Vector3;
import codechicken.multipart.TileMultipart; import codechicken.multipart.TileMultipart;
import cpw.mods.fml.common.eventhandler.EventPriority; import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockFence; import net.minecraft.block.BlockFence;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
@@ -15,97 +16,94 @@ import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement;
import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent; import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action; import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
public class EventHandler public class EventHandler {
{
private ThreadLocal<Object> placing = new ThreadLocal<Object>(); private ThreadLocal<Object> placing = new ThreadLocal<Object>();
@SubscribeEvent(priority = EventPriority.LOW) @SubscribeEvent(priority = EventPriority.LOW)
public void playerInteract(PlayerInteractEvent event) public void playerInteract(PlayerInteractEvent event) {
{ if (event.action == Action.RIGHT_CLICK_BLOCK && event.entityPlayer.worldObj.isRemote) {
if(event.action == Action.RIGHT_CLICK_BLOCK && event.entityPlayer.worldObj.isRemote) if (placing.get() != null) return; // for mods that do dumb stuff and call this event like MFR
{
if(placing.get() != null)
return;//for mods that do dumb stuff and call this event like MFR
placing.set(event); placing.set(event);
if(place(event.entityPlayer, event.entityPlayer.worldObj)) if (place(event.entityPlayer, event.entityPlayer.worldObj)) event.setCanceled(true);
event.setCanceled(true);
placing.set(null); placing.set(null);
} }
} }
public static boolean place(EntityPlayer player, World world) public static boolean place(EntityPlayer player, World world) {
{
MovingObjectPosition hit = RayTracer.reTrace(world, player); MovingObjectPosition hit = RayTracer.reTrace(world, player);
if(hit == null) if (hit == null) return false;
return false;
BlockCoord pos = new BlockCoord(hit.blockX, hit.blockY, hit.blockZ).offset(hit.sideHit); BlockCoord pos = new BlockCoord(hit.blockX, hit.blockY, hit.blockZ).offset(hit.sideHit);
ItemStack held = player.getHeldItem(); ItemStack held = player.getHeldItem();
McBlockPart part = null; McBlockPart part = null;
if(held == null) if (held == null) return false;
return false;
Block heldBlock = Block.getBlockFromItem(held.getItem()); Block heldBlock = Block.getBlockFromItem(held.getItem());
if(heldBlock == Blocks.air) if (heldBlock == Blocks.air) return false;
return false;
if(heldBlock == Blocks.torch) if (heldBlock == Blocks.torch) part = TorchPart.placement(world, pos, hit.sideHit);
part = TorchPart.placement(world, pos, hit.sideHit); else if (heldBlock == Blocks.lever) part = LeverPart.placement(world, pos, player, hit.sideHit);
else if(heldBlock == Blocks.lever) else if (heldBlock == Blocks.stone_button) part = ButtonPart.placement(world, pos, hit.sideHit, 0);
part = LeverPart.placement(world, pos, player, hit.sideHit); else if (heldBlock == Blocks.wooden_button) part = ButtonPart.placement(world, pos, hit.sideHit, 1);
else if(heldBlock == Blocks.stone_button) else if (heldBlock == Blocks.redstone_torch) part = RedstoneTorchPart.placement(world, pos, hit.sideHit);
part = ButtonPart.placement(world, pos, hit.sideHit, 0);
else if(heldBlock == Blocks.wooden_button)
part = ButtonPart.placement(world, pos, hit.sideHit, 1);
else if(heldBlock == Blocks.redstone_torch)
part = RedstoneTorchPart.placement(world, pos, hit.sideHit);
if(part == null)
return false;
if(world.isRemote && !player.isSneaking())//attempt to use block activated like normal and tell the server the right stuff if (part == null) return false;
if (world.isRemote
&& !player
.isSneaking()) // attempt to use block activated like normal and tell the server the right stuff
{ {
Vector3 f = new Vector3(hit.hitVec).add(-hit.blockX, -hit.blockY, -hit.blockZ); Vector3 f = new Vector3(hit.hitVec).add(-hit.blockX, -hit.blockY, -hit.blockZ);
Block block = world.getBlock(hit.blockX, hit.blockY, hit.blockZ); Block block = world.getBlock(hit.blockX, hit.blockY, hit.blockZ);
if(!ignoreActivate(block) && block.onBlockActivated(world, hit.blockX, hit.blockY, hit.blockZ, player, hit.sideHit, (float)f.x, (float)f.y, (float)f.z)) if (!ignoreActivate(block)
{ && block.onBlockActivated(
world,
hit.blockX,
hit.blockY,
hit.blockZ,
player,
hit.sideHit,
(float) f.x,
(float) f.y,
(float) f.z)) {
player.swingItem(); player.swingItem();
PacketCustom.sendToServer(new C08PacketPlayerBlockPlacement( PacketCustom.sendToServer(new C08PacketPlayerBlockPlacement(
hit.blockX, hit.blockY, hit.blockZ, hit.sideHit, hit.blockX,
player.inventory.getCurrentItem(), hit.blockY,
(float)f.x, (float)f.y, (float)f.z)); hit.blockZ,
hit.sideHit,
player.inventory.getCurrentItem(),
(float) f.x,
(float) f.y,
(float) f.z));
return true; return true;
} }
} }
TileMultipart tile = TileMultipart.getOrConvertTile(world, pos); TileMultipart tile = TileMultipart.getOrConvertTile(world, pos);
if(tile == null || !tile.canAddPart(part)) if (tile == null || !tile.canAddPart(part)) return false;
return false;
if (!world.isRemote) {
if(!world.isRemote)
{
TileMultipart.addPart(world, pos, part); TileMultipart.addPart(world, pos, part);
world.playSoundEffect(pos.x + 0.5, pos.y + 0.5, pos.z + 0.5, world.playSoundEffect(
pos.x + 0.5,
pos.y + 0.5,
pos.z + 0.5,
part.getBlock().stepSound.func_150496_b(), part.getBlock().stepSound.func_150496_b(),
(part.getBlock().stepSound.getVolume() + 1.0F) / 2.0F, (part.getBlock().stepSound.getVolume() + 1.0F) / 2.0F,
part.getBlock().stepSound.getPitch() * 0.8F); part.getBlock().stepSound.getPitch() * 0.8F);
if(!player.capabilities.isCreativeMode) if (!player.capabilities.isCreativeMode) {
{
held.stackSize--; held.stackSize--;
if (held.stackSize == 0) if (held.stackSize == 0) {
{
player.inventory.mainInventory[player.inventory.currentItem] = null; player.inventory.mainInventory[player.inventory.currentItem] = null;
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, held)); MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, held));
} }
} }
} } else {
else
{
player.swingItem(); player.swingItem();
new PacketCustom(McMultipartSPH.channel, 1).sendToServer(); new PacketCustom(McMultipartSPH.channel, 1).sendToServer();
} }
@@ -115,10 +113,8 @@ public class EventHandler
/** /**
* Because vanilla is weird. * Because vanilla is weird.
*/ */
private static boolean ignoreActivate(Block block) private static boolean ignoreActivate(Block block) {
{ if (block instanceof BlockFence) return true;
if(block instanceof BlockFence)
return true;
return false; return false;
} }
} }
@@ -4,13 +4,12 @@ import codechicken.lib.vec.BlockCoord;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.world.World; import net.minecraft.world.World;
public interface IPartMeta public interface IPartMeta {
{
public int getMetadata(); public int getMetadata();
public World getWorld(); public World getWorld();
public Block getBlock(); public Block getBlock();
public BlockCoord getPos(); public BlockCoord getPos();
} }
@@ -1,6 +1,9 @@
package codechicken.multipart.minecraft; package codechicken.multipart.minecraft;
import codechicken.lib.math.MathHelper; import codechicken.lib.math.MathHelper;
import codechicken.lib.vec.BlockCoord;
import codechicken.lib.vec.Cuboid6;
import codechicken.multipart.IFaceRedstonePart;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockLever; import net.minecraft.block.BlockLever;
import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.RenderBlocks;
@@ -11,103 +14,80 @@ import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import codechicken.lib.vec.BlockCoord;
import codechicken.lib.vec.Cuboid6;
import codechicken.multipart.IFaceRedstonePart;
public class LeverPart extends McSidedMetaPart implements IFaceRedstonePart public class LeverPart extends McSidedMetaPart implements IFaceRedstonePart {
{
public static BlockLever lever = (BlockLever) Blocks.lever; public static BlockLever lever = (BlockLever) Blocks.lever;
public static int[] metaSideMap = new int[]{1, 4, 5, 2, 3, 0, 0, 1}; public static int[] metaSideMap = new int[] {1, 4, 5, 2, 3, 0, 0, 1};
public static int[] sideMetaMap = new int[]{6, 0, 3, 4, 1, 2}; public static int[] sideMetaMap = new int[] {6, 0, 3, 4, 1, 2};
public static int[] metaSwapMap = new int[]{5, 7}; public static int[] metaSwapMap = new int[] {5, 7};
public LeverPart() public LeverPart() {}
{
} public LeverPart(int meta) {
public LeverPart(int meta)
{
super(meta); super(meta);
} }
@Override @Override
public Block getBlock() public Block getBlock() {
{
return lever; return lever;
} }
@Override @Override
public String getType() public String getType() {
{
return "mc_lever"; return "mc_lever";
} }
public boolean active() public boolean active() {
{ return (meta & 8) > 0;
return (meta&8) > 0;
} }
@Override @Override
public Cuboid6 getBounds() public Cuboid6 getBounds() {
{
int m = meta & 7; int m = meta & 7;
double d = 0.1875; double d = 0.1875;
if (m == 1) if (m == 1) return new Cuboid6(0, 0.2, 0.5 - d, d * 2, 0.8, 0.5 + d);
return new Cuboid6(0, 0.2, 0.5 - d, d * 2, 0.8, 0.5 + d); if (m == 2) return new Cuboid6(1 - d * 2, 0.2, 0.5 - d, 1, 0.8, 0.5 + d);
if (m == 2) if (m == 3) return new Cuboid6(0.5 - d, 0.2, 0, 0.5 + d, 0.8, d * 2);
return new Cuboid6(1 - d * 2, 0.2, 0.5 - d, 1, 0.8, 0.5 + d); if (m == 4) return new Cuboid6(0.5 - d, 0.2, 1 - d * 2, 0.5 + d, 0.8, 1);
if (m == 3)
return new Cuboid6(0.5 - d, 0.2, 0, 0.5 + d, 0.8, d * 2);
if (m == 4)
return new Cuboid6(0.5 - d, 0.2, 1 - d * 2, 0.5 + d, 0.8, 1);
d = 0.25; d = 0.25;
if (m == 0 || m == 7) if (m == 0 || m == 7) return new Cuboid6(0.5 - d, 0.4, 0.5 - d, 0.5 + d, 1, 0.5 + d);
return new Cuboid6(0.5 - d, 0.4, 0.5 - d, 0.5 + d, 1, 0.5 + d);
return new Cuboid6(0.5 - d, 0, 0.5 - d, 0.5 + d, 0.6, 0.5 + d); return new Cuboid6(0.5 - d, 0, 0.5 - d, 0.5 + d, 0.6, 0.5 + d);
} }
@Override @Override
public int sideForMeta(int meta) public int sideForMeta(int meta) {
{ return metaSideMap[meta & 7];
return metaSideMap[meta&7];
} }
public static McBlockPart placement(World world, BlockCoord pos, EntityPlayer player, int side) public static McBlockPart placement(World world, BlockCoord pos, EntityPlayer player, int side) {
{ pos = pos.copy().offset(side ^ 1);
pos = pos.copy().offset(side^1); if (!world.isSideSolid(pos.x, pos.y, pos.z, ForgeDirection.getOrientation(side))) return null;
if(!world.isSideSolid(pos.x, pos.y, pos.z, ForgeDirection.getOrientation(side)))
return null; int meta = sideMetaMap[side ^ 1];
if (side < 2 && (MathHelper.floor_double(player.rotationYaw / 90 + 0.5) & 1) == 0) meta = metaSwapMap[side ^ 1];
int meta = sideMetaMap[side^1];
if(side < 2 && (MathHelper.floor_double(player.rotationYaw / 90 + 0.5) & 1) == 0)
meta = metaSwapMap[side^1];
return new LeverPart(meta); return new LeverPart(meta);
} }
@Override @Override
public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item) public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item) {
{
World world = world(); World world = world();
if(world.isRemote) if (world.isRemote) return true;
return true;
world.playSoundEffect(x() + 0.5, y() + 0.5, z() + 0.5, "random.click", 0.3F, !active() ? 0.6F : 0.5F); world.playSoundEffect(x() + 0.5, y() + 0.5, z() + 0.5, "random.click", 0.3F, !active() ? 0.6F : 0.5F);
meta ^= 8; meta ^= 8;
sendDescUpdate(); sendDescUpdate();
tile().notifyPartChange(this); tile().notifyPartChange(this);
tile().notifyNeighborChange(metaSideMap[meta&7]); tile().notifyNeighborChange(metaSideMap[meta & 7]);
tile().markDirty(); tile().markDirty();
return true; return true;
} }
@Override @Override
public void drawBreaking(RenderBlocks renderBlocks) public void drawBreaking(RenderBlocks renderBlocks) {
{
IBlockAccess actual = renderBlocks.blockAccess; IBlockAccess actual = renderBlocks.blockAccess;
renderBlocks.blockAccess = new PartMetaAccess(this); renderBlocks.blockAccess = new PartMetaAccess(this);
renderBlocks.renderBlockLever(lever, x(), y(), z()); renderBlocks.renderBlockLever(lever, x(), y(), z());
@@ -115,39 +95,32 @@ public class LeverPart extends McSidedMetaPart implements IFaceRedstonePart
} }
@Override @Override
public void onRemoved() public void onRemoved() {
{ if (active()) tile().notifyNeighborChange(metaSideMap[meta & 7]);
if(active())
tile().notifyNeighborChange(metaSideMap[meta&7]);
}
@Override
public void onConverted()
{
if(active())
tile().notifyNeighborChange(metaSideMap[meta&7]);
} }
@Override @Override
public int weakPowerLevel(int side) public void onConverted() {
{ if (active()) tile().notifyNeighborChange(metaSideMap[meta & 7]);
}
@Override
public int weakPowerLevel(int side) {
return active() ? 15 : 0; return active() ? 15 : 0;
} }
@Override @Override
public int strongPowerLevel(int side) public int strongPowerLevel(int side) {
{ return active() && side == metaSideMap[meta & 7] ? 15 : 0;
return active() && side == metaSideMap[meta&7] ? 15 : 0;
} }
@Override @Override
public boolean canConnectRedstone(int side) public boolean canConnectRedstone(int side) {
{
return true; return true;
} }
@Override @Override
public int getFace() { public int getFace() {
return metaSideMap[meta&7]; return metaSideMap[meta & 7];
} }
} }
@@ -1,14 +1,5 @@
package codechicken.multipart.minecraft; package codechicken.multipart.minecraft;
import java.util.Arrays;
import java.util.Collections;
import net.minecraft.block.Block;
import net.minecraft.client.particle.EffectRenderer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
import codechicken.lib.vec.Cuboid6; import codechicken.lib.vec.Cuboid6;
import codechicken.multipart.IconHitEffects; import codechicken.multipart.IconHitEffects;
import codechicken.multipart.JCuboidPart; import codechicken.multipart.JCuboidPart;
@@ -18,75 +9,72 @@ import codechicken.multipart.NormalOcclusionTest;
import codechicken.multipart.TMultiPart; import codechicken.multipart.TMultiPart;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import java.util.Arrays;
import java.util.Collections;
import net.minecraft.block.Block;
import net.minecraft.client.particle.EffectRenderer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
public abstract class McBlockPart extends JCuboidPart implements JNormalOcclusion, JIconHitEffects public abstract class McBlockPart extends JCuboidPart implements JNormalOcclusion, JIconHitEffects {
{
public abstract Block getBlock(); public abstract Block getBlock();
@Override @Override
public boolean occlusionTest(TMultiPart npart) public boolean occlusionTest(TMultiPart npart) {
{
return NormalOcclusionTest.apply(this, npart); return NormalOcclusionTest.apply(this, npart);
} }
@Override @Override
public Iterable<Cuboid6> getOcclusionBoxes() public Iterable<Cuboid6> getOcclusionBoxes() {
{
return Arrays.asList(getBounds()); return Arrays.asList(getBounds());
} }
@Override @Override
public Iterable<Cuboid6> getCollisionBoxes() public Iterable<Cuboid6> getCollisionBoxes() {
{
return Collections.emptyList(); return Collections.emptyList();
} }
@Override @Override
public Iterable<ItemStack> getDrops() public Iterable<ItemStack> getDrops() {
{
return Arrays.asList(new ItemStack(getBlock())); return Arrays.asList(new ItemStack(getBlock()));
} }
@Override @Override
public ItemStack pickItem(MovingObjectPosition hit) public ItemStack pickItem(MovingObjectPosition hit) {
{
return new ItemStack(getBlock()); return new ItemStack(getBlock());
} }
@Override @Override
public float getStrength(MovingObjectPosition hit, EntityPlayer player) public float getStrength(MovingObjectPosition hit, EntityPlayer player) {
{ return getBlock().getPlayerRelativeBlockHardness(player, player.worldObj, hit.blockX, hit.blockY, hit.blockZ)
return getBlock().getPlayerRelativeBlockHardness(player, player.worldObj, hit.blockX, hit.blockY, hit.blockZ)*30; * 30;
} }
@Override @Override
public IIcon getBreakingIcon(Object subPart, int side) public IIcon getBreakingIcon(Object subPart, int side) {
{
return getBlock().getIcon(0, 0); return getBlock().getIcon(0, 0);
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public IIcon getBrokenIcon(int side) public IIcon getBrokenIcon(int side) {
{
return getBlock().getIcon(0, 0); return getBlock().getIcon(0, 0);
} }
@Override @Override
public void addHitEffects(MovingObjectPosition hit, EffectRenderer effectRenderer) public void addHitEffects(MovingObjectPosition hit, EffectRenderer effectRenderer) {
{
IconHitEffects.addHitEffects(this, hit, effectRenderer); IconHitEffects.addHitEffects(this, hit, effectRenderer);
} }
@Override @Override
public void addDestroyEffects(MovingObjectPosition hit, EffectRenderer effectRenderer) public void addDestroyEffects(MovingObjectPosition hit, EffectRenderer effectRenderer) {
{
IconHitEffects.addDestroyEffects(this, effectRenderer, false); IconHitEffects.addDestroyEffects(this, effectRenderer, false);
} }
@Override @Override
public int getLightValue() public int getLightValue() {
{
return getBlock().getLightValue(); return getBlock().getLightValue();
} }
} }
@@ -2,78 +2,64 @@ package codechicken.multipart.minecraft;
import codechicken.lib.data.MCDataInput; import codechicken.lib.data.MCDataInput;
import codechicken.lib.data.MCDataOutput; import codechicken.lib.data.MCDataOutput;
import codechicken.lib.lighting.LightMatrix;
import codechicken.lib.vec.BlockCoord; import codechicken.lib.vec.BlockCoord;
import codechicken.lib.vec.Vector3; import codechicken.lib.vec.Vector3;
import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World; import net.minecraft.world.World;
public abstract class McMetaPart extends McBlockPart implements IPartMeta public abstract class McMetaPart extends McBlockPart implements IPartMeta {
{
public byte meta; public byte meta;
public McMetaPart() public McMetaPart() {}
{
public McMetaPart(int meta) {
this.meta = (byte) meta;
} }
public McMetaPart(int meta)
{
this.meta = (byte)meta;
}
@Override @Override
public void save(NBTTagCompound tag) public void save(NBTTagCompound tag) {
{
tag.setByte("meta", meta); tag.setByte("meta", meta);
} }
@Override @Override
public void load(NBTTagCompound tag) public void load(NBTTagCompound tag) {
{
meta = tag.getByte("meta"); meta = tag.getByte("meta");
} }
@Override @Override
public void writeDesc(MCDataOutput packet) public void writeDesc(MCDataOutput packet) {
{
packet.writeByte(meta); packet.writeByte(meta);
} }
@Override @Override
public void readDesc(MCDataInput packet) public void readDesc(MCDataInput packet) {
{
meta = packet.readByte(); meta = packet.readByte();
} }
@Override @Override
public World getWorld() public World getWorld() {
{
return world(); return world();
} }
@Override @Override
public int getMetadata() public int getMetadata() {
{
return meta; return meta;
} }
@Override @Override
public BlockCoord getPos() public BlockCoord getPos() {
{
return new BlockCoord(tile()); return new BlockCoord(tile());
} }
@Override @Override
public boolean doesTick() public boolean doesTick() {
{
return false; return false;
} }
@Override @Override
public boolean renderStatic(Vector3 pos, int pass) public boolean renderStatic(Vector3 pos, int pass) {
{ if (pass == 0) {
if(pass == 0) {
new RenderBlocks(new PartMetaAccess(this)).renderBlockByRenderType(getBlock(), x(), y(), z()); new RenderBlocks(new PartMetaAccess(this)).renderBlockByRenderType(getBlock(), x(), y(), z());
return true; return true;
} }
@@ -1,14 +1,13 @@
package codechicken.multipart.minecraft; package codechicken.multipart.minecraft;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.WorldClient;
import codechicken.lib.packet.PacketCustom; import codechicken.lib.packet.PacketCustom;
import codechicken.lib.packet.PacketCustom.IClientPacketHandler; import codechicken.lib.packet.PacketCustom.IClientPacketHandler;
import codechicken.lib.vec.BlockCoord; import codechicken.lib.vec.BlockCoord;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.network.play.INetHandlerPlayClient; import net.minecraft.network.play.INetHandlerPlayClient;
public class McMultipartCPH implements IClientPacketHandler public class McMultipartCPH implements IClientPacketHandler {
{
public static Object channel = MinecraftMultipartMod.instance; public static Object channel = MinecraftMultipartMod.instance;
@Override @Override
@@ -22,9 +21,13 @@ public class McMultipartCPH implements IClientPacketHandler
private void spawnBurnoutSmoke(WorldClient world, BlockCoord pos) { private void spawnBurnoutSmoke(WorldClient world, BlockCoord pos) {
for (int l = 0; l < 5; l++) for (int l = 0; l < 5; l++)
world.spawnParticle("smoke", world.spawnParticle(
"smoke",
pos.x + world.rand.nextDouble() * 0.6 + 0.2, pos.x + world.rand.nextDouble() * 0.6 + 0.2,
pos.y + world.rand.nextDouble() * 0.6 + 0.2, pos.y + world.rand.nextDouble() * 0.6 + 0.2,
pos.z + world.rand.nextDouble() * 0.6 + 0.2, 0, 0, 0); pos.z + world.rand.nextDouble() * 0.6 + 0.2,
0,
0,
0);
} }
} }
@@ -1,13 +1,12 @@
package codechicken.multipart.minecraft; package codechicken.multipart.minecraft;
import codechicken.lib.packet.PacketCustom;
import codechicken.lib.packet.PacketCustom.IServerPacketHandler;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.play.INetHandlerPlayServer; import net.minecraft.network.play.INetHandlerPlayServer;
import net.minecraft.world.World; import net.minecraft.world.World;
import codechicken.lib.packet.PacketCustom;
import codechicken.lib.packet.PacketCustom.IServerPacketHandler;
public class McMultipartSPH implements IServerPacketHandler public class McMultipartSPH implements IServerPacketHandler {
{
public static Object channel = MinecraftMultipartMod.instance; public static Object channel = MinecraftMultipartMod.instance;
@Override @Override
@@ -1,69 +1,56 @@
package codechicken.multipart.minecraft; package codechicken.multipart.minecraft;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import codechicken.lib.vec.BlockCoord; import codechicken.lib.vec.BlockCoord;
import codechicken.lib.vec.Vector3; import codechicken.lib.vec.Vector3;
import codechicken.multipart.TFacePart; import codechicken.multipart.TFacePart;
import codechicken.multipart.TileMultipart; import codechicken.multipart.TileMultipart;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
public abstract class McSidedMetaPart extends McMetaPart implements TFacePart public abstract class McSidedMetaPart extends McMetaPart implements TFacePart {
{ public McSidedMetaPart() {}
public McSidedMetaPart()
{ public McSidedMetaPart(int meta) {
}
public McSidedMetaPart(int meta)
{
super(meta); super(meta);
} }
public abstract int sideForMeta(int meta); public abstract int sideForMeta(int meta);
@Override @Override
public void onNeighborChanged() public void onNeighborChanged() {
{ if (!world().isRemote) dropIfCantStay();
if(!world().isRemote)
dropIfCantStay();
} }
public boolean canStay() public boolean canStay() {
{
BlockCoord pos = new BlockCoord(tile()).offset(sideForMeta(meta)); BlockCoord pos = new BlockCoord(tile()).offset(sideForMeta(meta));
return world().isSideSolid(pos.x, pos.y, pos.z, ForgeDirection.getOrientation(sideForMeta(meta)^1)); return world().isSideSolid(pos.x, pos.y, pos.z, ForgeDirection.getOrientation(sideForMeta(meta) ^ 1));
} }
public boolean dropIfCantStay() public boolean dropIfCantStay() {
{ if (!canStay()) {
if(!canStay())
{
drop(); drop();
return true; return true;
} }
return false; return false;
} }
public void drop() public void drop() {
{
TileMultipart.dropItem(new ItemStack(getBlock()), world(), Vector3.fromTileEntityCenter(tile())); TileMultipart.dropItem(new ItemStack(getBlock()), world(), Vector3.fromTileEntityCenter(tile()));
tile().remPart(this); tile().remPart(this);
} }
@Override @Override
public int getSlotMask() public int getSlotMask() {
{ return 1 << sideForMeta(meta);
return 1<<sideForMeta(meta);
} }
@Override @Override
public boolean solid(int side) public boolean solid(int side) {
{
return false; return false;
} }
@Override @Override
public int redstoneConductionMap() public int redstoneConductionMap() {
{
return 0x1F; return 0x1F;
} }
} }
@@ -1,26 +1,22 @@
package codechicken.multipart.minecraft; package codechicken.multipart.minecraft;
import net.minecraftforge.common.MinecraftForge;
import codechicken.lib.packet.PacketCustom; import codechicken.lib.packet.PacketCustom;
import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.common.MinecraftForge;
@Mod(modid = "McMultipart", acceptedMinecraftVersions="[1.7.10]") @Mod(modid = "McMultipart", acceptedMinecraftVersions = "[1.7.10]")
public class MinecraftMultipartMod public class MinecraftMultipartMod {
{
@Instance("McMultipart") @Instance("McMultipart")
public static MinecraftMultipartMod instance; public static MinecraftMultipartMod instance;
@Mod.EventHandler @Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) public void preInit(FMLPreInitializationEvent event) {
{
new Content().init(); new Content().init();
MinecraftForge.EVENT_BUS.register(new EventHandler()); MinecraftForge.EVENT_BUS.register(new EventHandler());
PacketCustom.assignHandler(this, new McMultipartSPH()); PacketCustom.assignHandler(this, new McMultipartSPH());
if(FMLCommonHandler.instance().getSide().isClient()) if (FMLCommonHandler.instance().getSide().isClient()) PacketCustom.assignHandler(this, new McMultipartCPH());
PacketCustom.assignHandler(this, new McMultipartCPH());
} }
} }
@@ -20,15 +20,13 @@ public class PartMetaAccess implements IBlockAccess {
@Override @Override
public Block getBlock(int i, int j, int k) { public Block getBlock(int i, int j, int k) {
if (i == pos.x && j == pos.y && k == pos.z) if (i == pos.x && j == pos.y && k == pos.z) return part.getBlock();
return part.getBlock();
return part.getWorld().getBlock(i, j, k); return part.getWorld().getBlock(i, j, k);
} }
@Override @Override
public TileEntity getTileEntity(int i, int j, int k) { public TileEntity getTileEntity(int i, int j, int k) {
if (i == pos.x && j == pos.y && k == pos.z) if (i == pos.x && j == pos.y && k == pos.z) throw new IllegalArgumentException("Unsupported Operation");
throw new IllegalArgumentException("Unsupported Operation");
return part.getWorld().getTileEntity(i, j, k); return part.getWorld().getTileEntity(i, j, k);
} }
@@ -40,8 +38,7 @@ public class PartMetaAccess implements IBlockAccess {
@Override @Override
public int getBlockMetadata(int i, int j, int k) { public int getBlockMetadata(int i, int j, int k) {
if (i == pos.x && j == pos.y && k == pos.z) if (i == pos.x && j == pos.y && k == pos.z) return part.getMetadata() & 0xF;
return part.getMetadata() & 0xF;
return part.getWorld().getBlockMetadata(i, j, k); return part.getWorld().getBlockMetadata(i, j, k);
} }
@@ -1,8 +1,12 @@
package codechicken.multipart.minecraft; package codechicken.multipart.minecraft;
import java.util.Random; import codechicken.lib.vec.BlockCoord;
import codechicken.lib.vec.Cuboid6;
import codechicken.multipart.IFaceRedstonePart;
import codechicken.multipart.RedstoneInteractions;
import codechicken.multipart.TRandomUpdateTick;
import codechicken.multipart.TickScheduler; import codechicken.multipart.TickScheduler;
import java.util.Random;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockRedstoneTorch; import net.minecraft.block.BlockRedstoneTorch;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
@@ -10,137 +14,103 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import codechicken.lib.vec.BlockCoord;
import codechicken.lib.vec.Cuboid6;
import codechicken.multipart.IFaceRedstonePart;
import codechicken.multipart.TRandomUpdateTick;
import codechicken.multipart.RedstoneInteractions;
public class RedstoneTorchPart extends TorchPart implements IFaceRedstonePart, TRandomUpdateTick public class RedstoneTorchPart extends TorchPart implements IFaceRedstonePart, TRandomUpdateTick {
{
public static BlockRedstoneTorch torchActive = (BlockRedstoneTorch) Blocks.redstone_torch; public static BlockRedstoneTorch torchActive = (BlockRedstoneTorch) Blocks.redstone_torch;
public static BlockRedstoneTorch torchIdle = (BlockRedstoneTorch) Blocks.unlit_redstone_torch; public static BlockRedstoneTorch torchIdle = (BlockRedstoneTorch) Blocks.unlit_redstone_torch;
public class BurnoutEntry public class BurnoutEntry {
{ public BurnoutEntry(long l) {
public BurnoutEntry(long l)
{
timeout = l; timeout = l;
} }
long timeout; long timeout;
BurnoutEntry next; BurnoutEntry next;
} }
private BurnoutEntry burnout; private BurnoutEntry burnout;
public RedstoneTorchPart() public RedstoneTorchPart() {}
{
} public RedstoneTorchPart(int meta) {
public RedstoneTorchPart(int meta)
{
super(meta); super(meta);
} }
@Override @Override
public Block getBlock() public Block getBlock() {
{
return active() ? torchActive : torchIdle; return active() ? torchActive : torchIdle;
} }
public boolean active() public boolean active() {
{ return (meta & 0x10) > 0;
return (meta&0x10) > 0;
} }
@Override @Override
public String getType() public String getType() {
{
return "mc_redtorch"; return "mc_redtorch";
} }
@Override @Override
public int sideForMeta(int meta) public int sideForMeta(int meta) {
{ return super.sideForMeta(meta & 7);
return super.sideForMeta(meta&7);
} }
@Override @Override
public Cuboid6 getBounds() public Cuboid6 getBounds() {
{ return getBounds(meta & 7);
return getBounds(meta&7);
} }
public static McBlockPart placement(World world, BlockCoord pos, int side) public static McBlockPart placement(World world, BlockCoord pos, int side) {
{ if (side == 0) return null;
if(side == 0) pos = pos.copy().offset(side ^ 1);
return null; if (!world.isSideSolid(pos.x, pos.y, pos.z, ForgeDirection.getOrientation(side))) return null;
pos = pos.copy().offset(side^1);
if(!world.isSideSolid(pos.x, pos.y, pos.z, ForgeDirection.getOrientation(side))) return new RedstoneTorchPart(sideMetaMap[side ^ 1] | 0x10);
return null;
return new RedstoneTorchPart(sideMetaMap[side^1]|0x10);
} }
@Override @Override
public void randomDisplayTick(Random random) public void randomDisplayTick(Random random) {
{ if (!active()) return;
if(!active())
return;
double d0 = x() + 0.5 + (random.nextFloat() - 0.5) * 0.2; double d0 = x() + 0.5 + (random.nextFloat() - 0.5) * 0.2;
double d1 = y() + 0.7 + (random.nextFloat() - 0.5) * 0.2; double d1 = y() + 0.7 + (random.nextFloat() - 0.5) * 0.2;
double d2 = z() + 0.5 + (random.nextFloat() - 0.5) * 0.2; double d2 = z() + 0.5 + (random.nextFloat() - 0.5) * 0.2;
double d3 = 0.22D; double d3 = 0.22D;
double d4 = 0.27D; double d4 = 0.27D;
World world = world(); World world = world();
int m = meta&7; int m = meta & 7;
if (m == 1) if (m == 1) world.spawnParticle("reddust", d0 - d4, d1 + d3, d2, 0, 0, 0);
world.spawnParticle("reddust", d0 - d4, d1 + d3, d2, 0, 0, 0); else if (m == 2) world.spawnParticle("reddust", d0 + d4, d1 + d3, d2, 0, 0, 0);
else if (m == 2) else if (m == 3) world.spawnParticle("reddust", d0, d1 + d3, d2 - d4, 0, 0, 0);
world.spawnParticle("reddust", d0 + d4, d1 + d3, d2, 0, 0, 0); else if (m == 4) world.spawnParticle("reddust", d0, d1 + d3, d2 + d4, 0, 0, 0);
else if (m == 3) else world.spawnParticle("reddust", d0, d1, d2, 0, 0, 0);
world.spawnParticle("reddust", d0, d1 + d3, d2 - d4, 0, 0, 0);
else if (m == 4)
world.spawnParticle("reddust", d0, d1 + d3, d2 + d4, 0, 0, 0);
else
world.spawnParticle("reddust", d0, d1, d2, 0, 0, 0);
}
@Override
public ItemStack pickItem(MovingObjectPosition hit)
{
return new ItemStack(torchActive);
}
@Override
public void onNeighborChanged()
{
if(!world().isRemote)
{
if(!dropIfCantStay() && isBeingPowered() == active())
scheduleTick(2);
}
}
public boolean isBeingPowered()
{
int side = metaSideMap[meta&7];
return RedstoneInteractions.getPowerTo(this, side) > 0;
}
@Override
public void scheduledTick()
{
if(!world().isRemote && isBeingPowered() == active())
toggle();
} }
@Override @Override
public void randomUpdate() public ItemStack pickItem(MovingObjectPosition hit) {
{ return new ItemStack(torchActive);
}
@Override
public void onNeighborChanged() {
if (!world().isRemote) {
if (!dropIfCantStay() && isBeingPowered() == active()) scheduleTick(2);
}
}
public boolean isBeingPowered() {
int side = metaSideMap[meta & 7];
return RedstoneInteractions.getPowerTo(this, side) > 0;
}
@Override
public void scheduledTick() {
if (!world().isRemote && isBeingPowered() == active()) toggle();
}
@Override
public void randomUpdate() {
scheduledTick(); scheduledTick();
} }
@@ -149,104 +119,91 @@ public class RedstoneTorchPart extends TorchPart implements IFaceRedstonePart, T
TickScheduler.loadRandomTick(this); TickScheduler.loadRandomTick(this);
} }
private boolean burnedOut(boolean add) private boolean burnedOut(boolean add) {
{
long time = world().getTotalWorldTime(); long time = world().getTotalWorldTime();
while(burnout != null && burnout.timeout <= time) while (burnout != null && burnout.timeout <= time) burnout = burnout.next;
burnout = burnout.next;
if (add) {
if(add) BurnoutEntry e = new BurnoutEntry(world().getTotalWorldTime() + 60);
{ if (burnout == null) burnout = e;
BurnoutEntry e = new BurnoutEntry(world().getTotalWorldTime()+60); else {
if(burnout == null)
burnout = e;
else
{
BurnoutEntry b = burnout; BurnoutEntry b = burnout;
while(b.next != null) while (b.next != null) b = b.next;
b = b.next;
b.next = e; b.next = e;
} }
} }
if(burnout == null) if (burnout == null) return false;
return false;
int i = 0; int i = 0;
BurnoutEntry b = burnout; BurnoutEntry b = burnout;
while(b != null) while (b != null) {
{
i++; i++;
b = b.next; b = b.next;
} }
return i >= 8; return i >= 8;
} }
private void toggle() private void toggle() {
{ if (active()) // deactivating
if(active())//deactivating
{ {
if(burnedOut(true)) if (burnedOut(true)) {
{
World world = world(); World world = world();
Random rand = world.rand; Random rand = world.rand;
world.playSoundEffect(x()+0.5, y()+0.5, z()+0.5, "random.fizz", 0.5F, 2.6F + (rand.nextFloat() - rand.nextFloat()) * 0.8F); world.playSoundEffect(
x() + 0.5,
y() + 0.5,
z() + 0.5,
"random.fizz",
0.5F,
2.6F + (rand.nextFloat() - rand.nextFloat()) * 0.8F);
McMultipartSPH.spawnBurnoutSmoke(world, x(), y(), z()); McMultipartSPH.spawnBurnoutSmoke(world, x(), y(), z());
} }
} } else if (burnedOut(false)) {
else if(burnedOut(false))
{
return; return;
} }
meta ^= 0x10; meta ^= 0x10;
sendDescUpdate(); sendDescUpdate();
tile().markDirty(); tile().markDirty();
tile().notifyPartChange(this); tile().notifyPartChange(this);
tile().notifyNeighborChange(1); tile().notifyNeighborChange(1);
} }
@Override @Override
public void drop() { public void drop() {
meta|=0x10;//set state to on for drop meta |= 0x10; // set state to on for drop
super.drop(); super.drop();
} }
@Override @Override
public void onRemoved() public void onRemoved() {
{ if (active()) tile().notifyNeighborChange(1);
if(active())
tile().notifyNeighborChange(1);
} }
@Override @Override
public void onAdded() public void onAdded() {
{ if (active()) tile().notifyNeighborChange(1);
if(active())
tile().notifyNeighborChange(1);
onNeighborChanged(); onNeighborChanged();
} }
@Override @Override
public int strongPowerLevel(int side) public int strongPowerLevel(int side) {
{
return side == 1 && active() ? 15 : 0; return side == 1 && active() ? 15 : 0;
} }
@Override @Override
public int weakPowerLevel(int side) public int weakPowerLevel(int side) {
{ return active() && side != metaSideMap[meta & 7] ? 15 : 0;
return active() && side != metaSideMap[meta&7] ? 15 : 0;
} }
@Override @Override
public boolean canConnectRedstone(int side) public boolean canConnectRedstone(int side) {
{
return true; return true;
} }
@Override @Override
public int getFace() { public int getFace() {
return metaSideMap[meta&7]; return metaSideMap[meta & 7];
} }
} }
@@ -1,121 +1,96 @@
package codechicken.multipart.minecraft; package codechicken.multipart.minecraft;
import codechicken.lib.vec.BlockCoord;
import codechicken.lib.vec.Cuboid6;
import codechicken.multipart.IRandomDisplayTick;
import java.util.Random; import java.util.Random;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockTorch; import net.minecraft.block.BlockTorch;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.world.World; import net.minecraft.world.World;
import codechicken.multipart.IRandomDisplayTick;
import codechicken.lib.vec.BlockCoord;
import codechicken.lib.vec.Cuboid6;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TorchPart extends McSidedMetaPart implements IRandomDisplayTick public class TorchPart extends McSidedMetaPart implements IRandomDisplayTick {
{
public static BlockTorch torch = (BlockTorch) Blocks.torch; public static BlockTorch torch = (BlockTorch) Blocks.torch;
public static int[] metaSideMap = new int[]{-1, 4, 5, 2, 3, 0}; public static int[] metaSideMap = new int[] {-1, 4, 5, 2, 3, 0};
public static int[] sideMetaMap = new int[]{5, 0, 3, 4, 1, 2}; public static int[] sideMetaMap = new int[] {5, 0, 3, 4, 1, 2};
public TorchPart() public TorchPart() {}
{
} public TorchPart(int meta) {
public TorchPart(int meta)
{
super(meta); super(meta);
} }
@Override @Override
public Block getBlock() public Block getBlock() {
{
return torch; return torch;
} }
@Override @Override
public String getType() public String getType() {
{
return "mc_torch"; return "mc_torch";
} }
@Override @Override
public Cuboid6 getBounds() public Cuboid6 getBounds() {
{
return getBounds(meta); return getBounds(meta);
} }
public Cuboid6 getBounds(int meta) public Cuboid6 getBounds(int meta) {
{
double d = 0.15; double d = 0.15;
if (meta == 1) if (meta == 1) return new Cuboid6(0, 0.2, 0.5 - d, d * 2, 0.8, 0.5 + d);
return new Cuboid6(0, 0.2, 0.5 - d, d * 2, 0.8, 0.5 + d); if (meta == 2) return new Cuboid6(1 - d * 2, 0.2, 0.5 - d, 1, 0.8, 0.5 + d);
if (meta == 2) if (meta == 3) return new Cuboid6(0.5 - d, 0.2, 0, 0.5 + d, 0.8, d * 2);
return new Cuboid6(1 - d * 2, 0.2, 0.5 - d, 1, 0.8, 0.5 + d); if (meta == 4) return new Cuboid6(0.5 - d, 0.2, 1 - d * 2, 0.5 + d, 0.8, 1);
if (meta == 3)
return new Cuboid6(0.5 - d, 0.2, 0, 0.5 + d, 0.8, d * 2);
if (meta == 4)
return new Cuboid6(0.5 - d, 0.2, 1 - d * 2, 0.5 + d, 0.8, 1);
d = 0.1; d = 0.1;
return new Cuboid6(0.5 - d, 0, 0.5 - d, 0.5 + d, 0.6, 0.5 + d); return new Cuboid6(0.5 - d, 0, 0.5 - d, 0.5 + d, 0.6, 0.5 + d);
} }
@Override @Override
public int sideForMeta(int meta) public int sideForMeta(int meta) {
{
return metaSideMap[meta]; return metaSideMap[meta];
} }
@Override @Override
public boolean canStay() public boolean canStay() {
{ return sideForMeta(meta) == 0
return sideForMeta(meta) == 0 && world().getBlock(x(), y() - 1, z()).canPlaceTorchOnTop(world(), x(), y() - 1, z()) || super.canStay(); && world().getBlock(x(), y() - 1, z()).canPlaceTorchOnTop(world(), x(), y() - 1, z())
|| super.canStay();
} }
public static McBlockPart placement(World world, BlockCoord pos, int side) public static McBlockPart placement(World world, BlockCoord pos, int side) {
{ if (side == 0) return null;
if(side == 0) pos = pos.copy().offset(side ^ 1);
return null;
pos = pos.copy().offset(side^1);
Block block = world.getBlock(pos.x, pos.y, pos.z); Block block = world.getBlock(pos.x, pos.y, pos.z);
if(!block.isSideSolid(world, pos.x, pos.y, pos.z, ForgeDirection.getOrientation(side)) && (side != 1 || block.canPlaceTorchOnTop(world, pos.x, pos.y, pos.z))) if (!block.isSideSolid(world, pos.x, pos.y, pos.z, ForgeDirection.getOrientation(side))
return null; && (side != 1 || block.canPlaceTorchOnTop(world, pos.x, pos.y, pos.z))) return null;
return new TorchPart(sideMetaMap[side^1]); return new TorchPart(sideMetaMap[side ^ 1]);
} }
@Override @Override
public void randomDisplayTick(Random random) public void randomDisplayTick(Random random) {
{
double d0 = x() + 0.5; double d0 = x() + 0.5;
double d1 = y() + 0.7; double d1 = y() + 0.7;
double d2 = z() + 0.5; double d2 = z() + 0.5;
double d3 = 0.22D; double d3 = 0.22D;
double d4 = 0.27D; double d4 = 0.27D;
World world = world(); World world = world();
if (meta == 1) if (meta == 1) {
{
world.spawnParticle("smoke", d0 - d4, d1 + d3, d2, 0, 0, 0); world.spawnParticle("smoke", d0 - d4, d1 + d3, d2, 0, 0, 0);
world.spawnParticle("flame", d0 - d4, d1 + d3, d2, 0, 0, 0); world.spawnParticle("flame", d0 - d4, d1 + d3, d2, 0, 0, 0);
} } else if (meta == 2) {
else if (meta == 2)
{
world.spawnParticle("smoke", d0 + d4, d1 + d3, d2, 0, 0, 0); world.spawnParticle("smoke", d0 + d4, d1 + d3, d2, 0, 0, 0);
world.spawnParticle("flame", d0 + d4, d1 + d3, d2, 0, 0, 0); world.spawnParticle("flame", d0 + d4, d1 + d3, d2, 0, 0, 0);
} } else if (meta == 3) {
else if (meta == 3)
{
world.spawnParticle("smoke", d0, d1 + d3, d2 - d4, 0, 0, 0); world.spawnParticle("smoke", d0, d1 + d3, d2 - d4, 0, 0, 0);
world.spawnParticle("flame", d0, d1 + d3, d2 - d4, 0, 0, 0); world.spawnParticle("flame", d0, d1 + d3, d2 - d4, 0, 0, 0);
} } else if (meta == 4) {
else if (meta == 4)
{
world.spawnParticle("smoke", d0, d1 + d3, d2 + d4, 0, 0, 0); world.spawnParticle("smoke", d0, d1 + d3, d2 + d4, 0, 0, 0);
world.spawnParticle("flame", d0, d1 + d3, d2 + d4, 0, 0, 0); world.spawnParticle("flame", d0, d1 + d3, d2 + d4, 0, 0, 0);
} } else {
else
{
world.spawnParticle("smoke", d0, d1, d2, 0, 0, 0); world.spawnParticle("smoke", d0, d1, d2, 0, 0, 0);
world.spawnParticle("flame", d0, d1, d2, 0, 0, 0); world.spawnParticle("flame", d0, d1, d2, 0, 0, 0);
} }
@@ -1,25 +1,22 @@
package codechicken.multipart.nei; package codechicken.multipart.nei;
import codechicken.lib.inventory.InventoryUtils; import codechicken.lib.inventory.InventoryUtils;
import codechicken.microblock.MicroblockClass;
import codechicken.microblock.CommonMicroClass; import codechicken.microblock.CommonMicroClass;
import codechicken.microblock.MicroblockClass;
import codechicken.microblock.handler.MicroblockProxy; import codechicken.microblock.handler.MicroblockProxy;
import codechicken.nei.ItemStackMap; import codechicken.nei.ItemStackMap;
import codechicken.nei.api.API; import codechicken.nei.api.API;
import codechicken.nei.api.IConfigureNEI; import codechicken.nei.api.IConfigureNEI;
import java.util.Arrays;
import net.minecraft.util.StatCollector; import net.minecraft.util.StatCollector;
import java.util.Arrays; public class NEI_MicroblockConfig implements IConfigureNEI {
public class NEI_MicroblockConfig implements IConfigureNEI
{
@Override @Override
public void loadConfig() { public void loadConfig() {
MicroblockClass[] microClasses = CommonMicroClass.classes(); MicroblockClass[] microClasses = CommonMicroClass.classes();
for (int c = 0; c < microClasses.length; c++) { for (int c = 0; c < microClasses.length; c++) {
MicroblockClass mcrClass = microClasses[c]; MicroblockClass mcrClass = microClasses[c];
if (mcrClass == null) if (mcrClass == null) continue;
continue;
addSubset(mcrClass, c << 8 | 1); addSubset(mcrClass, c << 8 | 1);
addSubset(mcrClass, c << 8 | 2); addSubset(mcrClass, c << 8 | 2);
@@ -28,8 +25,10 @@ public class NEI_MicroblockConfig implements IConfigureNEI
} }
private void addSubset(MicroblockClass mcrClass, int i) { private void addSubset(MicroblockClass mcrClass, int i) {
API.addSubset("Microblocks." + StatCollector.translateToLocal(mcrClass.getName() + "." + (i & 0xFF) + ".subset"), API.addSubset(
Arrays.asList(InventoryUtils.newItemStack(MicroblockProxy.itemMicro(), 1, i, ItemStackMap.WILDCARD_TAG))); "Microblocks." + StatCollector.translateToLocal(mcrClass.getName() + "." + (i & 0xFF) + ".subset"),
Arrays.asList(
InventoryUtils.newItemStack(MicroblockProxy.itemMicro(), 1, i, ItemStackMap.WILDCARD_TAG)));
} }
@Override @Override
@@ -41,4 +40,4 @@ public class NEI_MicroblockConfig implements IConfigureNEI
public String getVersion() { public String getVersion() {
return "1.0.0.0"; return "1.0.0.0";
} }
} }