mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-22 13:09:44 +00:00
Merge pull request #13 from GTNewHorizons/fix-asm-bad-type
Fix wrong asm types being used for TypeInsnNodes
This commit is contained in:
23 files changed
+1217
-1004
No files matched your search
@@ -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
File diff suppressed because it is too large.
Load diff
+2
-2
@@ -1,6 +1,6 @@
|
||||
// Add your dependencies here
|
||||
|
||||
dependencies {
|
||||
compile("com.github.GTNewHorizons:CodeChickenLib:1.1.5.5:dev")
|
||||
compile("com.github.GTNewHorizons:NotEnoughItems:2.3.5-GTNH:dev")
|
||||
compile("com.github.GTNewHorizons:CodeChickenLib:1.1.5.7:dev")
|
||||
compile("com.github.GTNewHorizons:NotEnoughItems:2.3.20-GTNH:dev")
|
||||
}
|
||||
@@ -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.IFMLCallHook;
|
||||
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.Dialog.ModalityType;
|
||||
import java.awt.event.WindowAdapter;
|
||||
@@ -35,6 +28,12 @@ import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
import java.util.zip.ZipEntry;
|
||||
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.
|
||||
@@ -72,10 +71,12 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
private Box makeProgressPanel() {
|
||||
Box box = Box.createVerticalBox();
|
||||
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);
|
||||
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);
|
||||
box.add(welcomeLabel);
|
||||
box.add(Box.createRigidArea(new Dimension(0, 10)));
|
||||
@@ -91,12 +92,11 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
|
||||
@Override
|
||||
public JDialog makeDialog() {
|
||||
if (container != null)
|
||||
return container;
|
||||
if (container != null) return container;
|
||||
|
||||
setMessageType(JOptionPane.INFORMATION_MESSAGE);
|
||||
setMessage(makeProgressPanel());
|
||||
setOptions(new Object[]{"Stop"});
|
||||
setOptions(new Object[] {"Stop"});
|
||||
addPropertyChangeListener(new PropertyChangeListener() {
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
@@ -117,39 +117,40 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
container.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
if (shouldClose == JOptionPane.YES_OPTION)
|
||||
container.dispose();
|
||||
int shouldClose = JOptionPane.showConfirmDialog(
|
||||
container,
|
||||
message,
|
||||
"Are you sure you want to stop?",
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.WARNING_MESSAGE);
|
||||
if (shouldClose == JOptionPane.YES_OPTION) container.dispose();
|
||||
|
||||
stopIt = true;
|
||||
if (pokeThread != null)
|
||||
pokeThread.interrupt();
|
||||
if (pokeThread != null) pokeThread.interrupt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProgressString(String progressUpdate, Object... data) {
|
||||
//FMLLog.finest(progressUpdate, data);
|
||||
if (currentActivity != null)
|
||||
currentActivity.setText(String.format(progressUpdate, data));
|
||||
// FMLLog.finest(progressUpdate, data);
|
||||
if (currentActivity != null) currentActivity.setText(String.format(progressUpdate, data));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetProgress(int sizeGuess) {
|
||||
if (progress != null)
|
||||
progress.getModel().setRangeProperties(0, 0, 0, sizeGuess, false);
|
||||
if (progress != null) progress.getModel().setRangeProperties(0, 0, 0, sizeGuess, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProgress(int fullLength) {
|
||||
if (progress != null)
|
||||
progress.getModel().setValue(fullLength);
|
||||
if (progress != null) progress.getModel().setValue(fullLength);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -164,12 +165,13 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
|
||||
@Override
|
||||
public void showErrorDialog(String name, String url) {
|
||||
JEditorPane ep = new JEditorPane("text/html",
|
||||
"<html>" +
|
||||
owner + " was unable to download required library " + name +
|
||||
"<br>Check your internet connection and try restarting or download it manually from" +
|
||||
"<br><a href=\"" + url + "\">" + url + "</a> and put it in your mods folder" +
|
||||
"</html>");
|
||||
JEditorPane ep = new JEditorPane(
|
||||
"text/html",
|
||||
"<html>" + owner
|
||||
+ " was unable to download required library " + name
|
||||
+ "<br>Check your internet connection and try restarting or download it manually from"
|
||||
+ "<br><a href=\""
|
||||
+ url + "\">" + url + "</a> and put it in your mods folder" + "</html>");
|
||||
|
||||
ep.setEditable(false);
|
||||
ep.setOpaque(false);
|
||||
@@ -190,16 +192,13 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
|
||||
public static class DummyDownloader implements IDownloadDisplay {
|
||||
@Override
|
||||
public void resetProgress(int sizeGuess) {
|
||||
}
|
||||
public void resetProgress(int sizeGuess) {}
|
||||
|
||||
@Override
|
||||
public void setPokeThread(Thread currentThread) {
|
||||
}
|
||||
public void setPokeThread(Thread currentThread) {}
|
||||
|
||||
@Override
|
||||
public void updateProgress(int fullLength) {
|
||||
}
|
||||
public void updateProgress(int fullLength) {}
|
||||
|
||||
@Override
|
||||
public boolean shouldStopIt() {
|
||||
@@ -207,8 +206,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProgressString(String string, Object... data) {
|
||||
}
|
||||
public void updateProgressString(String string, Object... data) {}
|
||||
|
||||
@Override
|
||||
public Object makeDialog() {
|
||||
@@ -216,12 +214,10 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
}
|
||||
|
||||
@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 String filename;
|
||||
public final ComparableVersion version;
|
||||
@@ -231,11 +227,10 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
this.pattern = pattern;
|
||||
this.filename = filename;
|
||||
Matcher m = pattern.matcher(filename);
|
||||
if(m.matches()) {
|
||||
if (m.matches()) {
|
||||
name = m.group(1);
|
||||
version = new ComparableVersion(m.group(2));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
name = 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 VersionedFile file;
|
||||
|
||||
@@ -279,21 +273,20 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
|
||||
modsDir = new File(mcDir, "mods");
|
||||
v_modsDir = new File(mcDir, "mods/" + mcVer);
|
||||
if (!v_modsDir.exists())
|
||||
v_modsDir.mkdirs();
|
||||
if (!v_modsDir.exists()) v_modsDir.mkdirs();
|
||||
}
|
||||
|
||||
private void addClasspath(String name) {
|
||||
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) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteMod(File mod) {
|
||||
if (mod.delete())
|
||||
return;
|
||||
if (mod.delete()) return;
|
||||
|
||||
try {
|
||||
ClassLoader cl = DepLoader.class.getClassLoader();
|
||||
@@ -317,7 +310,8 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
|
||||
if (!mod.delete()) {
|
||||
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);
|
||||
if (!GraphicsEnvironment.isHeadless())
|
||||
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 {
|
||||
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();
|
||||
|
||||
@@ -391,9 +387,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
/*String cksum = generateChecksum(downloadBuffer);
|
||||
if (cksum.equals(validationHash))
|
||||
{*/
|
||||
if (!target.exists())
|
||||
target.createNewFile();
|
||||
|
||||
if (!target.exists()) target.createNewFile();
|
||||
|
||||
downloadBuffer.position(0);
|
||||
FileOutputStream fos = new FileOutputStream(target);
|
||||
@@ -412,19 +406,16 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
private String checkExisting(Dependency dep) {
|
||||
for (File f : modsDir.listFiles()) {
|
||||
VersionedFile vfile = new VersionedFile(f.getName(), dep.file.pattern);
|
||||
if (!vfile.matches() || !vfile.name.equals(dep.file.name))
|
||||
continue;
|
||||
if (!vfile.matches() || !vfile.name.equals(dep.file.name)) continue;
|
||||
|
||||
if (f.renameTo(new File(v_modsDir, f.getName())))
|
||||
continue;
|
||||
if (f.renameTo(new File(v_modsDir, f.getName()))) continue;
|
||||
|
||||
deleteMod(f);
|
||||
}
|
||||
|
||||
for (File f : v_modsDir.listFiles()) {
|
||||
VersionedFile vfile = new VersionedFile(f.getName(), dep.file.pattern);
|
||||
if (!vfile.matches() || !vfile.name.equals(dep.file.name))
|
||||
continue;
|
||||
if (!vfile.matches() || !vfile.name.equals(dep.file.name)) continue;
|
||||
|
||||
int cmp = vfile.version.compareTo(dep.file.version);
|
||||
if (cmp < 0) {
|
||||
@@ -433,27 +424,25 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
return null;
|
||||
}
|
||||
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();//found dependency
|
||||
return f.getName(); // found dependency
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void load() {
|
||||
scanDepInfos();
|
||||
if (depMap.isEmpty())
|
||||
return;
|
||||
if (depMap.isEmpty()) return;
|
||||
|
||||
loadDeps();
|
||||
activateDeps();
|
||||
}
|
||||
|
||||
private void activateDeps() {
|
||||
for (Dependency dep : depMap.values())
|
||||
if (dep.coreLib)
|
||||
addClasspath(dep.existing);
|
||||
for (Dependency dep : depMap.values()) if (dep.coreLib) addClasspath(dep.existing);
|
||||
}
|
||||
|
||||
private void loadDeps() {
|
||||
@@ -475,7 +464,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
|
||||
private void load(Dependency dep) {
|
||||
dep.existing = checkExisting(dep);
|
||||
if (dep.existing == null)//download dep
|
||||
if (dep.existing == null) // download dep
|
||||
{
|
||||
download(dep);
|
||||
dep.existing = dep.file.filename;
|
||||
@@ -491,8 +480,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
|
||||
private void scanDepInfos() {
|
||||
for (File file : modFiles()) {
|
||||
if (!file.getName().endsWith(".jar") && !file.getName().endsWith(".zip"))
|
||||
continue;
|
||||
if (!file.getName().endsWith(".jar") && !file.getName().endsWith(".zip")) continue;
|
||||
|
||||
scanDepInfo(file);
|
||||
}
|
||||
@@ -503,8 +491,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
ZipFile zip = new ZipFile(file);
|
||||
ZipEntry e = zip.getEntry("dependancies.info");
|
||||
if (e == null) e = zip.getEntry("dependencies.info");
|
||||
if (e != null)
|
||||
loadJSon(zip.getInputStream(e));
|
||||
if (e != null) loadJSon(zip.getInputStream(e));
|
||||
zip.close();
|
||||
} catch (Exception e) {
|
||||
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 {
|
||||
InputStreamReader reader = new InputStreamReader(input);
|
||||
JsonElement root = new JsonParser().parse(reader);
|
||||
if (root.isJsonArray())
|
||||
loadJSonArr(root);
|
||||
else
|
||||
loadJson(root.getAsJsonObject());
|
||||
if (root.isJsonArray()) loadJSonArr(root);
|
||||
else loadJson(root.getAsJsonObject());
|
||||
reader.close();
|
||||
}
|
||||
|
||||
private void loadJSonArr(JsonElement root) throws IOException {
|
||||
for (JsonElement node : root.getAsJsonArray())
|
||||
loadJson(node.getAsJsonObject());
|
||||
for (JsonElement node : root.getAsJsonArray()) loadJson(node.getAsJsonObject());
|
||||
}
|
||||
|
||||
private void loadJson(JsonObject node) throws IOException {
|
||||
boolean obfuscated = ((LaunchClassLoader) DepLoader.class.getClassLoader())
|
||||
.getClassBytes("net.minecraft.world.World") == null;
|
||||
boolean obfuscated =
|
||||
((LaunchClassLoader) DepLoader.class.getClassLoader()).getClassBytes("net.minecraft.world.World")
|
||||
== null;
|
||||
|
||||
String testClass = node.get("class").getAsString();
|
||||
if (DepLoader.class.getResource("/" + testClass.replace('.', '/') + ".class") != null)
|
||||
return;
|
||||
if (DepLoader.class.getResource("/" + testClass.replace('.', '/') + ".class") != null) return;
|
||||
|
||||
String repo = node.get("repo").getAsString();
|
||||
String filename = node.get("file").getAsString();
|
||||
if (!obfuscated && node.has("dev"))
|
||||
filename = node.get("dev").getAsString();
|
||||
if (!obfuscated && node.has("dev")) filename = node.get("dev").getAsString();
|
||||
|
||||
boolean coreLib = node.has("coreLib") && node.get("coreLib").getAsBoolean();
|
||||
|
||||
Pattern pattern = null;
|
||||
try {
|
||||
if(node.has("pattern"))
|
||||
if (node.has("pattern"))
|
||||
pattern = Pattern.compile(node.get("pattern").getAsString());
|
||||
} catch (PatternSyntaxException e) {
|
||||
System.err.println("Invalid filename pattern: "+node.get("pattern"));
|
||||
System.err.println("Invalid filename pattern: " + node.get("pattern"));
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(pattern == null)
|
||||
pattern = Pattern.compile("(\\w+).*?([\\d\\.]+)[-\\w]*\\.[^\\d]+");
|
||||
if (pattern == null) pattern = Pattern.compile("(\\w+).*?([\\d\\.]+)[-\\w]*\\.[^\\d]+");
|
||||
|
||||
VersionedFile file = new VersionedFile(filename, pattern);
|
||||
if (!file.matches())
|
||||
throw new RuntimeException("Invalid filename format for dependency: " + filename);
|
||||
if (!file.matches()) throw new RuntimeException("Invalid filename format for dependency: " + filename);
|
||||
|
||||
addDep(new Dependency(repo, file, coreLib));
|
||||
}
|
||||
@@ -568,8 +549,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
}
|
||||
|
||||
private boolean mergeNew(Dependency oldDep, Dependency newDep) {
|
||||
if (oldDep == null)
|
||||
return true;
|
||||
if (oldDep == null) return true;
|
||||
|
||||
Dependency newest = newDep.file.version.compareTo(oldDep.file.version) > 0 ? newDep : oldDep;
|
||||
newest.coreLib = newDep.coreLib || oldDep.coreLib;
|
||||
@@ -601,8 +581,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectData(Map<String, Object> data) {
|
||||
}
|
||||
public void injectData(Map<String, Object> data) {}
|
||||
|
||||
@Override
|
||||
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.
|
||||
* For performance reasons, it is recommended that integer constants be useds as opposed to this enum
|
||||
*/
|
||||
public enum PartMap
|
||||
{
|
||||
public enum PartMap {
|
||||
BOTTOM(0),
|
||||
TOP(1),
|
||||
NORTH(2),
|
||||
@@ -13,122 +12,119 @@ public enum PartMap
|
||||
WEST(4),
|
||||
EAST(5),
|
||||
CENTER(6),
|
||||
CORNER_NNN(7),//0
|
||||
CORNER_NPN(8),//1
|
||||
CORNER_NNP(9),//2
|
||||
CORNER_NPP(10),//3
|
||||
CORNER_PNN(11),//4
|
||||
CORNER_PPN(12),//5
|
||||
CORNER_PNP(13),//6
|
||||
CORNER_PPP(14),//7
|
||||
EDGE_NYN(15),//0
|
||||
EDGE_NYP(16),//1
|
||||
EDGE_PYN(17),//2
|
||||
EDGE_PYP(18),//3
|
||||
EDGE_NNZ(19),//4
|
||||
EDGE_PNZ(20),//5
|
||||
EDGE_NPZ(21),//6
|
||||
EDGE_PPZ(22),//7
|
||||
EDGE_XNN(23),//8
|
||||
EDGE_XPN(24),//9
|
||||
EDGE_XNP(25),//10
|
||||
EDGE_XPP(26);//11
|
||||
|
||||
CORNER_NNN(7), // 0
|
||||
CORNER_NPN(8), // 1
|
||||
CORNER_NNP(9), // 2
|
||||
CORNER_NPP(10), // 3
|
||||
CORNER_PNN(11), // 4
|
||||
CORNER_PPN(12), // 5
|
||||
CORNER_PNP(13), // 6
|
||||
CORNER_PPP(14), // 7
|
||||
EDGE_NYN(15), // 0
|
||||
EDGE_NYP(16), // 1
|
||||
EDGE_PYN(17), // 2
|
||||
EDGE_PYP(18), // 3
|
||||
EDGE_NNZ(19), // 4
|
||||
EDGE_PNZ(20), // 5
|
||||
EDGE_NPZ(21), // 6
|
||||
EDGE_PPZ(22), // 7
|
||||
EDGE_XNN(23), // 8
|
||||
EDGE_XPN(24), // 9
|
||||
EDGE_XNP(25), // 10
|
||||
EDGE_XPP(26); // 11
|
||||
|
||||
public final int i;
|
||||
public final int mask;
|
||||
|
||||
private PartMap(int i)
|
||||
{
|
||||
|
||||
private PartMap(int i) {
|
||||
this.i = i;
|
||||
mask = 1<<i;
|
||||
mask = 1 << i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't actually use this.
|
||||
*/
|
||||
public static PartMap face(int i)
|
||||
{
|
||||
public static PartMap face(int i) {
|
||||
return values()[i];
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't actually use this.
|
||||
*/
|
||||
public static PartMap edge(int i)
|
||||
{
|
||||
return values()[i+15];
|
||||
public static PartMap edge(int i) {
|
||||
return values()[i + 15];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Don't actually use this.
|
||||
*/
|
||||
public static PartMap corner(int i)
|
||||
{
|
||||
return values()[i+7];
|
||||
public static PartMap corner(int i) {
|
||||
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
|
||||
* Note the parameter e is relative to the first edge slot and can range from 0-11
|
||||
*/
|
||||
public static int edgeAxisMask(int e)
|
||||
{
|
||||
switch(e>>2)
|
||||
{
|
||||
case 0: return 6;
|
||||
case 1: return 5;
|
||||
case 2: return 3;
|
||||
public static int edgeAxisMask(int e) {
|
||||
switch (e >> 2) {
|
||||
case 0:
|
||||
return 6;
|
||||
case 1:
|
||||
return 5;
|
||||
case 2:
|
||||
return 3;
|
||||
}
|
||||
throw new IllegalArgumentException("Switch Falloff");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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)
|
||||
{
|
||||
switch(e>>2)
|
||||
{
|
||||
case 0: return (e&3)<<1;
|
||||
case 1: return (e&2)>>1|(e&1)<<2;
|
||||
case 2: return (e&3);
|
||||
public static int unpackEdgeBits(int e) {
|
||||
switch (e >> 2) {
|
||||
case 0:
|
||||
return (e & 3) << 1;
|
||||
case 1:
|
||||
return (e & 2) >> 1 | (e & 1) << 2;
|
||||
case 2:
|
||||
return (e & 3);
|
||||
}
|
||||
throw new IllegalArgumentException("Switch Falloff");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public static int packEdgeBits(int e, int bits)
|
||||
{
|
||||
switch(e>>2)
|
||||
{
|
||||
case 0: return e&0xC|bits>>1;
|
||||
case 1: return e&0xC|(bits&4)>>2|(bits&1)<<1;
|
||||
case 2: return e&0xC|bits&3;
|
||||
public static int packEdgeBits(int e, int bits) {
|
||||
switch (e >> 2) {
|
||||
case 0:
|
||||
return e & 0xC | bits >> 1;
|
||||
case 1:
|
||||
return e & 0xC | (bits & 4) >> 2 | (bits & 1) << 1;
|
||||
case 2:
|
||||
return e & 0xC | bits & 3;
|
||||
}
|
||||
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, 9, 11, 6, 7,
|
||||
-1, -1,-1, -1, 0, 2,
|
||||
-1, -1,-1, -1, 1, 3};
|
||||
|
||||
-1, -1, -1, -1, 0, 2,
|
||||
-1, -1, -1, -1, 1, 3
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the slot of the edge between 2 sides.
|
||||
*/
|
||||
public static int edgeBetween(int s1, int s2)
|
||||
{
|
||||
if(s2 < s1)
|
||||
return edgeBetween(s2, s1);
|
||||
if((s1&6) == (s2&6))
|
||||
throw new IllegalArgumentException("Faces "+s1+" and "+s2+" are opposites");
|
||||
return 15+edgeBetweenMap[s1*6+s2];
|
||||
public static int edgeBetween(int s1, int s2) {
|
||||
if (s2 < s1) return edgeBetween(s2, s1);
|
||||
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) {
|
||||
val stack = new StackAnalyser(getType(cnode.name), base)
|
||||
val stack = new StackAnalyser(getType(Type.getObjectType(cnode.name).getDescriptor), base)
|
||||
val insnList = mnode.instructions
|
||||
var insn = insnList.getFirst
|
||||
|
||||
@@ -478,7 +478,7 @@ object ASMMixinCompiler
|
||||
//cast to parent class and call
|
||||
val mType = Type.getMethodType(minsn.desc)
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,10 +283,10 @@ class StackAnalyser(val owner:Type, val m:MethodNode)
|
||||
}
|
||||
case tinsn:TypeInsnNode => ainsn.getOpcode match
|
||||
{
|
||||
case NEW => push(New(getType(tinsn.desc)))
|
||||
case NEWARRAY => push(NewArray(pop(), getType(tinsn.desc)))
|
||||
case ANEWARRAY => push(NewArray(pop(), getType("["+tinsn.desc)))
|
||||
case CHECKCAST => push(Cast(pop(), getType(tinsn.desc)))
|
||||
case NEW => push(New(getObjectType(tinsn.desc)))
|
||||
case NEWARRAY => push(NewArray(pop(), getObjectType(tinsn.desc)))
|
||||
case ANEWARRAY => push(NewArray(pop(), getObjectType("["+tinsn.desc)))
|
||||
case CHECKCAST => push(Cast(pop(), getObjectType(tinsn.desc)))
|
||||
case INSTANCEOF => push(UnaryOp(INSTANCEOF, pop()))
|
||||
}
|
||||
case mainsn:MultiANewArrayInsnNode =>
|
||||
|
||||
@@ -4,7 +4,6 @@ import codechicken.lib.vec.BlockCoord;
|
||||
import codechicken.lib.vec.Cuboid6;
|
||||
import codechicken.lib.vec.Vector3;
|
||||
import codechicken.multipart.IFaceRedstonePart;
|
||||
import codechicken.multipart.TickScheduler;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockButton;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -16,169 +15,136 @@ import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.World;
|
||||
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 woodenButton = (BlockButton) Blocks.wooden_button;
|
||||
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 BlockButton getButton(int meta)
|
||||
{
|
||||
return (meta&0x10) > 0 ? woodenButton : stoneButton;
|
||||
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 BlockButton getButton(int meta) {
|
||||
return (meta & 0x10) > 0 ? woodenButton : stoneButton;
|
||||
}
|
||||
|
||||
public ButtonPart()
|
||||
{
|
||||
}
|
||||
|
||||
public ButtonPart(int meta)
|
||||
{
|
||||
|
||||
public ButtonPart() {}
|
||||
|
||||
public ButtonPart(int meta) {
|
||||
super(meta);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int sideForMeta(int meta)
|
||||
{
|
||||
return metaSideMap[meta&7];
|
||||
public int sideForMeta(int meta) {
|
||||
return metaSideMap[meta & 7];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getBlock()
|
||||
{
|
||||
public Block getBlock() {
|
||||
return getButton(meta);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getType()
|
||||
{
|
||||
public String getType() {
|
||||
return "mc_button";
|
||||
}
|
||||
|
||||
public int delay()
|
||||
{
|
||||
|
||||
public int delay() {
|
||||
return sensitive() ? 30 : 20;
|
||||
}
|
||||
|
||||
public boolean sensitive()
|
||||
{
|
||||
return (meta&0x10) > 0;
|
||||
|
||||
public boolean sensitive() {
|
||||
return (meta & 0x10) > 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Cuboid6 getBounds()
|
||||
{
|
||||
public Cuboid6 getBounds() {
|
||||
int m = meta & 7;
|
||||
double d = pressed() ? 0.0625 : 0.125;
|
||||
|
||||
if (m == 1)
|
||||
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 == 3)
|
||||
return new Cuboid6(0.5 - 0.1875, 0.375, 0.0, 0.5 + 0.1875, 0.625, d);
|
||||
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
|
||||
|
||||
if (m == 1) 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 == 3) return new Cuboid6(0.5 - 0.1875, 0.375, 0.0, 0.5 + 0.1875, 0.625, d);
|
||||
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)
|
||||
{
|
||||
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;
|
||||
|
||||
return new ButtonPart(sideMetaMap[side^1]|type<<4);
|
||||
public static McBlockPart placement(World world, BlockCoord pos, int side, int type) {
|
||||
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;
|
||||
|
||||
return new ButtonPart(sideMetaMap[side ^ 1] | type << 4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item)
|
||||
{
|
||||
if(pressed())
|
||||
return false;
|
||||
|
||||
if(!world().isRemote)
|
||||
toggle();
|
||||
|
||||
public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item) {
|
||||
if (pressed()) return false;
|
||||
|
||||
if (!world().isRemote) toggle();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void scheduledTick()
|
||||
{
|
||||
if(pressed())
|
||||
updateState();
|
||||
}
|
||||
|
||||
public boolean pressed()
|
||||
{
|
||||
return (meta&8) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityCollision(Entity entity)
|
||||
{
|
||||
if(!pressed() && !world().isRemote && entity instanceof EntityArrow)
|
||||
updateState();
|
||||
public void scheduledTick() {
|
||||
if (pressed()) 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();
|
||||
meta^=8;
|
||||
meta ^= 8;
|
||||
world().playSoundEffect(x() + 0.5, y() + 0.5, z() + 0.5, "random.click", 0.3F, in ? 0.6F : 0.5F);
|
||||
if(in)
|
||||
scheduleTick(delay());
|
||||
|
||||
if (in) scheduleTick(delay());
|
||||
|
||||
sendDescUpdate();
|
||||
tile().notifyPartChange(this);
|
||||
tile().notifyNeighborChange(metaSideMap[meta&7]);
|
||||
tile().notifyNeighborChange(metaSideMap[meta & 7]);
|
||||
tile().markDirty();
|
||||
}
|
||||
|
||||
private void updateState()
|
||||
{
|
||||
boolean arrows = sensitive() && !world().getEntitiesWithinAABB(EntityArrow.class,
|
||||
getBounds().add(Vector3.fromTileEntity(tile())).toAABB()).isEmpty();
|
||||
private void updateState() {
|
||||
boolean arrows = sensitive()
|
||||
&& !world().getEntitiesWithinAABB(
|
||||
EntityArrow.class,
|
||||
getBounds().add(Vector3.fromTileEntity(tile())).toAABB())
|
||||
.isEmpty();
|
||||
boolean pressed = pressed();
|
||||
|
||||
if(arrows != pressed)
|
||||
toggle();
|
||||
if(arrows && pressed)
|
||||
scheduleTick(delay());
|
||||
|
||||
if (arrows != pressed) toggle();
|
||||
if (arrows && pressed) scheduleTick(delay());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onRemoved()
|
||||
{
|
||||
if(pressed())
|
||||
tile().notifyNeighborChange(metaSideMap[meta&7]);
|
||||
public void onRemoved() {
|
||||
if (pressed()) tile().notifyNeighborChange(metaSideMap[meta & 7]);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int weakPowerLevel(int side)
|
||||
{
|
||||
public int weakPowerLevel(int side) {
|
||||
return pressed() ? 15 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int strongPowerLevel(int side)
|
||||
{
|
||||
return pressed() && side == metaSideMap[meta&7] ? 15 : 0;
|
||||
public int strongPowerLevel(int side) {
|
||||
return pressed() && side == metaSideMap[meta & 7] ? 15 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone(int side)
|
||||
{
|
||||
public boolean canConnectRedstone(int side) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getFace() {
|
||||
return metaSideMap[meta&7];
|
||||
return metaSideMap[meta & 7];
|
||||
}
|
||||
}
|
||||
@@ -1,63 +1,53 @@
|
||||
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.init.Blocks;
|
||||
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
|
||||
public TMultiPart createPart(String name, boolean client)
|
||||
{
|
||||
if(name.equals("mc_torch")) return new TorchPart();
|
||||
if(name.equals("mc_lever")) return new LeverPart();
|
||||
if(name.equals("mc_button")) return new ButtonPart();
|
||||
if(name.equals("mc_redtorch")) return new RedstoneTorchPart();
|
||||
|
||||
public TMultiPart createPart(String name, boolean client) {
|
||||
if (name.equals("mc_torch")) return new TorchPart();
|
||||
if (name.equals("mc_lever")) return new LeverPart();
|
||||
if (name.equals("mc_button")) return new ButtonPart();
|
||||
if (name.equals("mc_redtorch")) return new RedstoneTorchPart();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void init()
|
||||
{
|
||||
|
||||
public void init() {
|
||||
MultiPartRegistry.registerConverter(this);
|
||||
MultiPartRegistry.registerParts(this, new String[]{
|
||||
"mc_torch",
|
||||
"mc_lever",
|
||||
"mc_button",
|
||||
"mc_redtorch"
|
||||
});
|
||||
MultiPartRegistry.registerParts(this, new String[] {"mc_torch", "mc_lever", "mc_button", "mc_redtorch"});
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
public TMultiPart convert(World world, BlockCoord pos)
|
||||
{
|
||||
public TMultiPart convert(World world, BlockCoord pos) {
|
||||
Block b = world.getBlock(pos.x, pos.y, pos.z);
|
||||
int meta = world.getBlockMetadata(pos.x, pos.y, pos.z);
|
||||
if(b == Blocks.torch)
|
||||
return new TorchPart(meta);
|
||||
if(b == Blocks.lever)
|
||||
return new LeverPart(meta);
|
||||
if(b == Blocks.stone_button)
|
||||
return new ButtonPart(meta);
|
||||
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);
|
||||
|
||||
if (b == Blocks.torch) return new TorchPart(meta);
|
||||
if (b == Blocks.lever) return new LeverPart(meta);
|
||||
if (b == Blocks.stone_button) return new ButtonPart(meta);
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import codechicken.lib.vec.BlockCoord;
|
||||
import codechicken.lib.vec.Vector3;
|
||||
import codechicken.multipart.TileMultipart;
|
||||
import cpw.mods.fml.common.eventhandler.EventPriority;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockFence;
|
||||
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.world.World;
|
||||
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.PlayerInteractEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
|
||||
|
||||
public class EventHandler
|
||||
{
|
||||
public class EventHandler {
|
||||
private ThreadLocal<Object> placing = new ThreadLocal<Object>();
|
||||
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.LOW)
|
||||
public void playerInteract(PlayerInteractEvent event)
|
||||
{
|
||||
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
|
||||
public void playerInteract(PlayerInteractEvent event) {
|
||||
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
|
||||
placing.set(event);
|
||||
if(place(event.entityPlayer, event.entityPlayer.worldObj))
|
||||
event.setCanceled(true);
|
||||
if (place(event.entityPlayer, event.entityPlayer.worldObj)) event.setCanceled(true);
|
||||
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);
|
||||
if(hit == null)
|
||||
return false;
|
||||
|
||||
if (hit == null) return false;
|
||||
|
||||
BlockCoord pos = new BlockCoord(hit.blockX, hit.blockY, hit.blockZ).offset(hit.sideHit);
|
||||
ItemStack held = player.getHeldItem();
|
||||
McBlockPart part = null;
|
||||
if(held == null)
|
||||
return false;
|
||||
if (held == null) return false;
|
||||
|
||||
Block heldBlock = Block.getBlockFromItem(held.getItem());
|
||||
if(heldBlock == Blocks.air)
|
||||
return false;
|
||||
if (heldBlock == Blocks.air) return false;
|
||||
|
||||
if(heldBlock == Blocks.torch)
|
||||
part = TorchPart.placement(world, pos, hit.sideHit);
|
||||
else if(heldBlock == Blocks.lever)
|
||||
part = LeverPart.placement(world, pos, player, hit.sideHit);
|
||||
else if(heldBlock == Blocks.stone_button)
|
||||
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 (heldBlock == Blocks.torch) part = TorchPart.placement(world, pos, hit.sideHit);
|
||||
else if (heldBlock == Blocks.lever) part = LeverPart.placement(world, pos, player, hit.sideHit);
|
||||
else if (heldBlock == Blocks.stone_button) 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(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);
|
||||
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();
|
||||
PacketCustom.sendToServer(new C08PacketPlayerBlockPlacement(
|
||||
hit.blockX, hit.blockY, hit.blockZ, hit.sideHit,
|
||||
player.inventory.getCurrentItem(),
|
||||
(float)f.x, (float)f.y, (float)f.z));
|
||||
hit.blockX,
|
||||
hit.blockY,
|
||||
hit.blockZ,
|
||||
hit.sideHit,
|
||||
player.inventory.getCurrentItem(),
|
||||
(float) f.x,
|
||||
(float) f.y,
|
||||
(float) f.z));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TileMultipart tile = TileMultipart.getOrConvertTile(world, pos);
|
||||
if(tile == null || !tile.canAddPart(part))
|
||||
return false;
|
||||
|
||||
if(!world.isRemote)
|
||||
{
|
||||
if (tile == null || !tile.canAddPart(part)) return false;
|
||||
|
||||
if (!world.isRemote) {
|
||||
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.getVolume() + 1.0F) / 2.0F,
|
||||
(part.getBlock().stepSound.getVolume() + 1.0F) / 2.0F,
|
||||
part.getBlock().stepSound.getPitch() * 0.8F);
|
||||
if(!player.capabilities.isCreativeMode)
|
||||
{
|
||||
if (!player.capabilities.isCreativeMode) {
|
||||
held.stackSize--;
|
||||
if (held.stackSize == 0)
|
||||
{
|
||||
if (held.stackSize == 0) {
|
||||
player.inventory.mainInventory[player.inventory.currentItem] = null;
|
||||
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, held));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
player.swingItem();
|
||||
new PacketCustom(McMultipartSPH.channel, 1).sendToServer();
|
||||
}
|
||||
@@ -115,10 +113,8 @@ public class EventHandler
|
||||
/**
|
||||
* Because vanilla is weird.
|
||||
*/
|
||||
private static boolean ignoreActivate(Block block)
|
||||
{
|
||||
if(block instanceof BlockFence)
|
||||
return true;
|
||||
private static boolean ignoreActivate(Block block) {
|
||||
if (block instanceof BlockFence) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -4,13 +4,12 @@ import codechicken.lib.vec.BlockCoord;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IPartMeta
|
||||
{
|
||||
public interface IPartMeta {
|
||||
public int getMetadata();
|
||||
|
||||
|
||||
public World getWorld();
|
||||
|
||||
public Block getBlock();
|
||||
|
||||
|
||||
public BlockCoord getPos();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
package codechicken.multipart.minecraft;
|
||||
|
||||
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.BlockLever;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
@@ -11,103 +14,80 @@ import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
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 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[] metaSwapMap = new int[]{5, 7};
|
||||
|
||||
public LeverPart()
|
||||
{
|
||||
}
|
||||
|
||||
public LeverPart(int meta)
|
||||
{
|
||||
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[] metaSwapMap = new int[] {5, 7};
|
||||
|
||||
public LeverPart() {}
|
||||
|
||||
public LeverPart(int meta) {
|
||||
super(meta);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Block getBlock()
|
||||
{
|
||||
public Block getBlock() {
|
||||
return lever;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getType()
|
||||
{
|
||||
public String getType() {
|
||||
return "mc_lever";
|
||||
}
|
||||
|
||||
public boolean active()
|
||||
{
|
||||
return (meta&8) > 0;
|
||||
|
||||
public boolean active() {
|
||||
return (meta & 8) > 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Cuboid6 getBounds()
|
||||
{
|
||||
public Cuboid6 getBounds() {
|
||||
int m = meta & 7;
|
||||
double d = 0.1875;
|
||||
|
||||
if (m == 1)
|
||||
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 == 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);
|
||||
if (m == 1) 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 == 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;
|
||||
if (m == 0 || m == 7)
|
||||
return new Cuboid6(0.5 - d, 0.4, 0.5 - d, 0.5 + d, 1, 0.5 + d);
|
||||
|
||||
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, 0.5 - d, 0.5 + d, 0.6, 0.5 + d);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int sideForMeta(int meta)
|
||||
{
|
||||
return metaSideMap[meta&7];
|
||||
public int sideForMeta(int meta) {
|
||||
return metaSideMap[meta & 7];
|
||||
}
|
||||
|
||||
public static McBlockPart placement(World world, BlockCoord pos, EntityPlayer player, int side)
|
||||
{
|
||||
pos = pos.copy().offset(side^1);
|
||||
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];
|
||||
|
||||
public static McBlockPart placement(World world, BlockCoord pos, EntityPlayer player, int side) {
|
||||
pos = pos.copy().offset(side ^ 1);
|
||||
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];
|
||||
|
||||
return new LeverPart(meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item)
|
||||
{
|
||||
public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item) {
|
||||
World world = world();
|
||||
if(world.isRemote)
|
||||
return true;
|
||||
if (world.isRemote) return true;
|
||||
|
||||
world.playSoundEffect(x() + 0.5, y() + 0.5, z() + 0.5, "random.click", 0.3F, !active() ? 0.6F : 0.5F);
|
||||
meta ^= 8;
|
||||
sendDescUpdate();
|
||||
tile().notifyPartChange(this);
|
||||
tile().notifyNeighborChange(metaSideMap[meta&7]);
|
||||
tile().notifyNeighborChange(metaSideMap[meta & 7]);
|
||||
tile().markDirty();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBreaking(RenderBlocks renderBlocks)
|
||||
{
|
||||
public void drawBreaking(RenderBlocks renderBlocks) {
|
||||
IBlockAccess actual = renderBlocks.blockAccess;
|
||||
renderBlocks.blockAccess = new PartMetaAccess(this);
|
||||
renderBlocks.renderBlockLever(lever, x(), y(), z());
|
||||
@@ -115,39 +95,32 @@ public class LeverPart extends McSidedMetaPart implements IFaceRedstonePart
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemoved()
|
||||
{
|
||||
if(active())
|
||||
tile().notifyNeighborChange(metaSideMap[meta&7]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConverted()
|
||||
{
|
||||
if(active())
|
||||
tile().notifyNeighborChange(metaSideMap[meta&7]);
|
||||
public void onRemoved() {
|
||||
if (active()) tile().notifyNeighborChange(metaSideMap[meta & 7]);
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int strongPowerLevel(int side)
|
||||
{
|
||||
return active() && side == metaSideMap[meta&7] ? 15 : 0;
|
||||
public int strongPowerLevel(int side) {
|
||||
return active() && side == metaSideMap[meta & 7] ? 15 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone(int side)
|
||||
{
|
||||
public boolean canConnectRedstone(int side) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getFace() {
|
||||
return metaSideMap[meta&7];
|
||||
return metaSideMap[meta & 7];
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,5 @@
|
||||
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.multipart.IconHitEffects;
|
||||
import codechicken.multipart.JCuboidPart;
|
||||
@@ -18,75 +9,72 @@ import codechicken.multipart.NormalOcclusionTest;
|
||||
import codechicken.multipart.TMultiPart;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
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();
|
||||
|
||||
|
||||
@Override
|
||||
public boolean occlusionTest(TMultiPart npart)
|
||||
{
|
||||
public boolean occlusionTest(TMultiPart npart) {
|
||||
return NormalOcclusionTest.apply(this, npart);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Cuboid6> getOcclusionBoxes()
|
||||
{
|
||||
public Iterable<Cuboid6> getOcclusionBoxes() {
|
||||
return Arrays.asList(getBounds());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Iterable<Cuboid6> getCollisionBoxes()
|
||||
{
|
||||
public Iterable<Cuboid6> getCollisionBoxes() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Iterable<ItemStack> getDrops()
|
||||
{
|
||||
public Iterable<ItemStack> getDrops() {
|
||||
return Arrays.asList(new ItemStack(getBlock()));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ItemStack pickItem(MovingObjectPosition hit)
|
||||
{
|
||||
public ItemStack pickItem(MovingObjectPosition hit) {
|
||||
return new ItemStack(getBlock());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public float getStrength(MovingObjectPosition hit, EntityPlayer player)
|
||||
{
|
||||
return getBlock().getPlayerRelativeBlockHardness(player, player.worldObj, hit.blockX, hit.blockY, hit.blockZ)*30;
|
||||
public float getStrength(MovingObjectPosition hit, EntityPlayer player) {
|
||||
return getBlock().getPlayerRelativeBlockHardness(player, player.worldObj, hit.blockX, hit.blockY, hit.blockZ)
|
||||
* 30;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IIcon getBreakingIcon(Object subPart, int side)
|
||||
{
|
||||
public IIcon getBreakingIcon(Object subPart, int side) {
|
||||
return getBlock().getIcon(0, 0);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getBrokenIcon(int side)
|
||||
{
|
||||
public IIcon getBrokenIcon(int side) {
|
||||
return getBlock().getIcon(0, 0);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addHitEffects(MovingObjectPosition hit, EffectRenderer effectRenderer)
|
||||
{
|
||||
public void addHitEffects(MovingObjectPosition hit, EffectRenderer effectRenderer) {
|
||||
IconHitEffects.addHitEffects(this, hit, effectRenderer);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addDestroyEffects(MovingObjectPosition hit, EffectRenderer effectRenderer)
|
||||
{
|
||||
public void addDestroyEffects(MovingObjectPosition hit, EffectRenderer effectRenderer) {
|
||||
IconHitEffects.addDestroyEffects(this, effectRenderer, false);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getLightValue()
|
||||
{
|
||||
public int getLightValue() {
|
||||
return getBlock().getLightValue();
|
||||
}
|
||||
}
|
||||
@@ -2,78 +2,64 @@ package codechicken.multipart.minecraft;
|
||||
|
||||
import codechicken.lib.data.MCDataInput;
|
||||
import codechicken.lib.data.MCDataOutput;
|
||||
import codechicken.lib.lighting.LightMatrix;
|
||||
import codechicken.lib.vec.BlockCoord;
|
||||
import codechicken.lib.vec.Vector3;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
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 McMetaPart()
|
||||
{
|
||||
|
||||
public McMetaPart() {}
|
||||
|
||||
public McMetaPart(int meta) {
|
||||
this.meta = (byte) meta;
|
||||
}
|
||||
|
||||
public McMetaPart(int meta)
|
||||
{
|
||||
this.meta = (byte)meta;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void save(NBTTagCompound tag)
|
||||
{
|
||||
public void save(NBTTagCompound tag) {
|
||||
tag.setByte("meta", meta);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void load(NBTTagCompound tag)
|
||||
{
|
||||
public void load(NBTTagCompound tag) {
|
||||
meta = tag.getByte("meta");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeDesc(MCDataOutput packet)
|
||||
{
|
||||
public void writeDesc(MCDataOutput packet) {
|
||||
packet.writeByte(meta);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void readDesc(MCDataInput packet)
|
||||
{
|
||||
public void readDesc(MCDataInput packet) {
|
||||
meta = packet.readByte();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public World getWorld()
|
||||
{
|
||||
public World getWorld() {
|
||||
return world();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getMetadata()
|
||||
{
|
||||
public int getMetadata() {
|
||||
return meta;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockCoord getPos()
|
||||
{
|
||||
public BlockCoord getPos() {
|
||||
return new BlockCoord(tile());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean doesTick()
|
||||
{
|
||||
public boolean doesTick() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean renderStatic(Vector3 pos, int pass)
|
||||
{
|
||||
if(pass == 0) {
|
||||
public boolean renderStatic(Vector3 pos, int pass) {
|
||||
if (pass == 0) {
|
||||
new RenderBlocks(new PartMetaAccess(this)).renderBlockByRenderType(getBlock(), x(), y(), z());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
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.IClientPacketHandler;
|
||||
import codechicken.lib.vec.BlockCoord;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.network.play.INetHandlerPlayClient;
|
||||
|
||||
public class McMultipartCPH implements IClientPacketHandler
|
||||
{
|
||||
public class McMultipartCPH implements IClientPacketHandler {
|
||||
public static Object channel = MinecraftMultipartMod.instance;
|
||||
|
||||
@Override
|
||||
@@ -22,9 +21,13 @@ public class McMultipartCPH implements IClientPacketHandler
|
||||
|
||||
private void spawnBurnoutSmoke(WorldClient world, BlockCoord pos) {
|
||||
for (int l = 0; l < 5; l++)
|
||||
world.spawnParticle("smoke",
|
||||
world.spawnParticle(
|
||||
"smoke",
|
||||
pos.x + 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;
|
||||
|
||||
import codechicken.lib.packet.PacketCustom;
|
||||
import codechicken.lib.packet.PacketCustom.IServerPacketHandler;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.play.INetHandlerPlayServer;
|
||||
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;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,69 +1,56 @@
|
||||
package codechicken.multipart.minecraft;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import codechicken.lib.vec.BlockCoord;
|
||||
import codechicken.lib.vec.Vector3;
|
||||
import codechicken.multipart.TFacePart;
|
||||
import codechicken.multipart.TileMultipart;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public abstract class McSidedMetaPart extends McMetaPart implements TFacePart
|
||||
{
|
||||
public McSidedMetaPart()
|
||||
{
|
||||
}
|
||||
|
||||
public McSidedMetaPart(int meta)
|
||||
{
|
||||
public abstract class McSidedMetaPart extends McMetaPart implements TFacePart {
|
||||
public McSidedMetaPart() {}
|
||||
|
||||
public McSidedMetaPart(int meta) {
|
||||
super(meta);
|
||||
}
|
||||
|
||||
|
||||
public abstract int sideForMeta(int meta);
|
||||
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged()
|
||||
{
|
||||
if(!world().isRemote)
|
||||
dropIfCantStay();
|
||||
public void onNeighborChanged() {
|
||||
if (!world().isRemote) dropIfCantStay();
|
||||
}
|
||||
|
||||
public boolean canStay()
|
||||
{
|
||||
|
||||
public boolean canStay() {
|
||||
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()
|
||||
{
|
||||
if(!canStay())
|
||||
{
|
||||
|
||||
public boolean dropIfCantStay() {
|
||||
if (!canStay()) {
|
||||
drop();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void drop()
|
||||
{
|
||||
public void drop() {
|
||||
TileMultipart.dropItem(new ItemStack(getBlock()), world(), Vector3.fromTileEntityCenter(tile()));
|
||||
tile().remPart(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getSlotMask()
|
||||
{
|
||||
return 1<<sideForMeta(meta);
|
||||
public int getSlotMask() {
|
||||
return 1 << sideForMeta(meta);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean solid(int side)
|
||||
{
|
||||
public boolean solid(int side) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int redstoneConductionMap()
|
||||
{
|
||||
public int redstoneConductionMap() {
|
||||
return 0x1F;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,22 @@
|
||||
package codechicken.multipart.minecraft;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import codechicken.lib.packet.PacketCustom;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.Mod.Instance;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
@Mod(modid = "McMultipart", acceptedMinecraftVersions="[1.7.10]")
|
||||
public class MinecraftMultipartMod
|
||||
{
|
||||
@Mod(modid = "McMultipart", acceptedMinecraftVersions = "[1.7.10]")
|
||||
public class MinecraftMultipartMod {
|
||||
@Instance("McMultipart")
|
||||
public static MinecraftMultipartMod instance;
|
||||
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
new Content().init();
|
||||
MinecraftForge.EVENT_BUS.register(new EventHandler());
|
||||
PacketCustom.assignHandler(this, new McMultipartSPH());
|
||||
if(FMLCommonHandler.instance().getSide().isClient())
|
||||
PacketCustom.assignHandler(this, new McMultipartCPH());
|
||||
|
||||
if (FMLCommonHandler.instance().getSide().isClient()) PacketCustom.assignHandler(this, new McMultipartCPH());
|
||||
}
|
||||
}
|
||||
@@ -20,15 +20,13 @@ public class PartMetaAccess implements IBlockAccess {
|
||||
|
||||
@Override
|
||||
public Block getBlock(int i, int j, int k) {
|
||||
if (i == pos.x && j == pos.y && k == pos.z)
|
||||
return part.getBlock();
|
||||
if (i == pos.x && j == pos.y && k == pos.z) return part.getBlock();
|
||||
return part.getWorld().getBlock(i, j, k);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getTileEntity(int i, int j, int k) {
|
||||
if (i == pos.x && j == pos.y && k == pos.z)
|
||||
throw new IllegalArgumentException("Unsupported Operation");
|
||||
if (i == pos.x && j == pos.y && k == pos.z) throw new IllegalArgumentException("Unsupported Operation");
|
||||
return part.getWorld().getTileEntity(i, j, k);
|
||||
}
|
||||
|
||||
@@ -40,8 +38,7 @@ public class PartMetaAccess implements IBlockAccess {
|
||||
|
||||
@Override
|
||||
public int getBlockMetadata(int i, int j, int k) {
|
||||
if (i == pos.x && j == pos.y && k == pos.z)
|
||||
return part.getMetadata() & 0xF;
|
||||
if (i == pos.x && j == pos.y && k == pos.z) return part.getMetadata() & 0xF;
|
||||
return part.getWorld().getBlockMetadata(i, j, k);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
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 java.util.Random;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockRedstoneTorch;
|
||||
import net.minecraft.init.Blocks;
|
||||
@@ -10,137 +14,103 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.World;
|
||||
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 torchIdle = (BlockRedstoneTorch) Blocks.unlit_redstone_torch;
|
||||
|
||||
public class BurnoutEntry
|
||||
{
|
||||
public BurnoutEntry(long l)
|
||||
{
|
||||
|
||||
public class BurnoutEntry {
|
||||
public BurnoutEntry(long l) {
|
||||
timeout = l;
|
||||
}
|
||||
|
||||
|
||||
long timeout;
|
||||
BurnoutEntry next;
|
||||
}
|
||||
|
||||
|
||||
private BurnoutEntry burnout;
|
||||
|
||||
public RedstoneTorchPart()
|
||||
{
|
||||
}
|
||||
|
||||
public RedstoneTorchPart(int meta)
|
||||
{
|
||||
|
||||
public RedstoneTorchPart() {}
|
||||
|
||||
public RedstoneTorchPart(int meta) {
|
||||
super(meta);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Block getBlock()
|
||||
{
|
||||
public Block getBlock() {
|
||||
return active() ? torchActive : torchIdle;
|
||||
}
|
||||
|
||||
public boolean active()
|
||||
{
|
||||
return (meta&0x10) > 0;
|
||||
|
||||
public boolean active() {
|
||||
return (meta & 0x10) > 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getType()
|
||||
{
|
||||
public String getType() {
|
||||
return "mc_redtorch";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int sideForMeta(int meta)
|
||||
{
|
||||
return super.sideForMeta(meta&7);
|
||||
public int sideForMeta(int meta) {
|
||||
return super.sideForMeta(meta & 7);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Cuboid6 getBounds()
|
||||
{
|
||||
return getBounds(meta&7);
|
||||
public Cuboid6 getBounds() {
|
||||
return getBounds(meta & 7);
|
||||
}
|
||||
|
||||
public static McBlockPart placement(World world, BlockCoord pos, int side)
|
||||
{
|
||||
if(side == 0)
|
||||
return null;
|
||||
pos = pos.copy().offset(side^1);
|
||||
if(!world.isSideSolid(pos.x, pos.y, pos.z, ForgeDirection.getOrientation(side)))
|
||||
return null;
|
||||
|
||||
return new RedstoneTorchPart(sideMetaMap[side^1]|0x10);
|
||||
|
||||
public static McBlockPart placement(World world, BlockCoord pos, int side) {
|
||||
if (side == 0) return null;
|
||||
pos = pos.copy().offset(side ^ 1);
|
||||
if (!world.isSideSolid(pos.x, pos.y, pos.z, ForgeDirection.getOrientation(side))) return null;
|
||||
|
||||
return new RedstoneTorchPart(sideMetaMap[side ^ 1] | 0x10);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void randomDisplayTick(Random random)
|
||||
{
|
||||
if(!active())
|
||||
return;
|
||||
|
||||
public void randomDisplayTick(Random random) {
|
||||
if (!active()) return;
|
||||
|
||||
double d0 = x() + 0.5 + (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 d3 = 0.22D;
|
||||
double d4 = 0.27D;
|
||||
|
||||
|
||||
World world = world();
|
||||
int m = meta&7;
|
||||
if (m == 1)
|
||||
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 == 3)
|
||||
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();
|
||||
int m = meta & 7;
|
||||
if (m == 1) 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 == 3) 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 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();
|
||||
}
|
||||
|
||||
@@ -149,104 +119,91 @@ public class RedstoneTorchPart extends TorchPart implements IFaceRedstonePart, T
|
||||
TickScheduler.loadRandomTick(this);
|
||||
}
|
||||
|
||||
private boolean burnedOut(boolean add)
|
||||
{
|
||||
private boolean burnedOut(boolean add) {
|
||||
long time = world().getTotalWorldTime();
|
||||
while(burnout != null && burnout.timeout <= time)
|
||||
burnout = burnout.next;
|
||||
|
||||
if(add)
|
||||
{
|
||||
BurnoutEntry e = new BurnoutEntry(world().getTotalWorldTime()+60);
|
||||
if(burnout == null)
|
||||
burnout = e;
|
||||
else
|
||||
{
|
||||
while (burnout != null && burnout.timeout <= time) burnout = burnout.next;
|
||||
|
||||
if (add) {
|
||||
BurnoutEntry e = new BurnoutEntry(world().getTotalWorldTime() + 60);
|
||||
if (burnout == null) burnout = e;
|
||||
else {
|
||||
BurnoutEntry b = burnout;
|
||||
while(b.next != null)
|
||||
b = b.next;
|
||||
while (b.next != null) b = b.next;
|
||||
b.next = e;
|
||||
}
|
||||
}
|
||||
|
||||
if(burnout == null)
|
||||
return false;
|
||||
|
||||
if (burnout == null) return false;
|
||||
|
||||
int i = 0;
|
||||
BurnoutEntry b = burnout;
|
||||
while(b != null)
|
||||
{
|
||||
while (b != null) {
|
||||
i++;
|
||||
b = b.next;
|
||||
}
|
||||
return i >= 8;
|
||||
}
|
||||
|
||||
private void toggle()
|
||||
{
|
||||
if(active())//deactivating
|
||||
|
||||
private void toggle() {
|
||||
if (active()) // deactivating
|
||||
{
|
||||
if(burnedOut(true))
|
||||
{
|
||||
if (burnedOut(true)) {
|
||||
World world = world();
|
||||
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());
|
||||
}
|
||||
}
|
||||
else if(burnedOut(false))
|
||||
{
|
||||
} else if (burnedOut(false)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
meta ^= 0x10;
|
||||
sendDescUpdate();
|
||||
tile().markDirty();
|
||||
tile().notifyPartChange(this);
|
||||
tile().notifyNeighborChange(1);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drop() {
|
||||
meta|=0x10;//set state to on for drop
|
||||
meta |= 0x10; // set state to on for drop
|
||||
super.drop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemoved()
|
||||
{
|
||||
if(active())
|
||||
tile().notifyNeighborChange(1);
|
||||
public void onRemoved() {
|
||||
if (active()) tile().notifyNeighborChange(1);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onAdded()
|
||||
{
|
||||
if(active())
|
||||
tile().notifyNeighborChange(1);
|
||||
public void onAdded() {
|
||||
if (active()) tile().notifyNeighborChange(1);
|
||||
onNeighborChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int strongPowerLevel(int side)
|
||||
{
|
||||
public int strongPowerLevel(int side) {
|
||||
return side == 1 && active() ? 15 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int weakPowerLevel(int side)
|
||||
{
|
||||
return active() && side != metaSideMap[meta&7] ? 15 : 0;
|
||||
public int weakPowerLevel(int side) {
|
||||
return active() && side != metaSideMap[meta & 7] ? 15 : 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone(int side)
|
||||
{
|
||||
public boolean canConnectRedstone(int side) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getFace() {
|
||||
return metaSideMap[meta&7];
|
||||
return metaSideMap[meta & 7];
|
||||
}
|
||||
}
|
||||
@@ -1,121 +1,96 @@
|
||||
package codechicken.multipart.minecraft;
|
||||
|
||||
import codechicken.lib.vec.BlockCoord;
|
||||
import codechicken.lib.vec.Cuboid6;
|
||||
import codechicken.multipart.IRandomDisplayTick;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockTorch;
|
||||
import net.minecraft.init.Blocks;
|
||||
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;
|
||||
|
||||
public class TorchPart extends McSidedMetaPart implements IRandomDisplayTick
|
||||
{
|
||||
public class TorchPart extends McSidedMetaPart implements IRandomDisplayTick {
|
||||
public static BlockTorch torch = (BlockTorch) Blocks.torch;
|
||||
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 TorchPart()
|
||||
{
|
||||
}
|
||||
|
||||
public TorchPart(int meta)
|
||||
{
|
||||
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 TorchPart() {}
|
||||
|
||||
public TorchPart(int meta) {
|
||||
super(meta);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Block getBlock()
|
||||
{
|
||||
public Block getBlock() {
|
||||
return torch;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getType()
|
||||
{
|
||||
public String getType() {
|
||||
return "mc_torch";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Cuboid6 getBounds()
|
||||
{
|
||||
public Cuboid6 getBounds() {
|
||||
return getBounds(meta);
|
||||
}
|
||||
|
||||
public Cuboid6 getBounds(int meta)
|
||||
{
|
||||
|
||||
public Cuboid6 getBounds(int meta) {
|
||||
double d = 0.15;
|
||||
if (meta == 1)
|
||||
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 == 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);
|
||||
|
||||
if (meta == 1) 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 == 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;
|
||||
return new Cuboid6(0.5 - d, 0, 0.5 - d, 0.5 + d, 0.6, 0.5 + d);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int sideForMeta(int meta)
|
||||
{
|
||||
public int sideForMeta(int meta) {
|
||||
return metaSideMap[meta];
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canStay()
|
||||
{
|
||||
return sideForMeta(meta) == 0 && world().getBlock(x(), y() - 1, z()).canPlaceTorchOnTop(world(), x(), y() - 1, z()) || super.canStay();
|
||||
public boolean canStay() {
|
||||
return sideForMeta(meta) == 0
|
||||
&& world().getBlock(x(), y() - 1, z()).canPlaceTorchOnTop(world(), x(), y() - 1, z())
|
||||
|| super.canStay();
|
||||
}
|
||||
|
||||
public static McBlockPart placement(World world, BlockCoord pos, int side)
|
||||
{
|
||||
if(side == 0)
|
||||
return null;
|
||||
pos = pos.copy().offset(side^1);
|
||||
|
||||
public static McBlockPart placement(World world, BlockCoord pos, int side) {
|
||||
if (side == 0) return null;
|
||||
pos = pos.copy().offset(side ^ 1);
|
||||
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)))
|
||||
return null;
|
||||
if (!block.isSideSolid(world, pos.x, pos.y, pos.z, ForgeDirection.getOrientation(side))
|
||||
&& (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
|
||||
public void randomDisplayTick(Random random)
|
||||
{
|
||||
public void randomDisplayTick(Random random) {
|
||||
double d0 = x() + 0.5;
|
||||
double d1 = y() + 0.7;
|
||||
double d2 = z() + 0.5;
|
||||
double d3 = 0.22D;
|
||||
double d4 = 0.27D;
|
||||
|
||||
|
||||
World world = world();
|
||||
if (meta == 1)
|
||||
{
|
||||
if (meta == 1) {
|
||||
world.spawnParticle("smoke", 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("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("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("flame", d0, d1 + d3, d2 + d4, 0, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
world.spawnParticle("smoke", d0, d1, d2, 0, 0, 0);
|
||||
world.spawnParticle("flame", d0, d1, d2, 0, 0, 0);
|
||||
}
|
||||
|
||||
@@ -1,25 +1,22 @@
|
||||
package codechicken.multipart.nei;
|
||||
|
||||
import codechicken.lib.inventory.InventoryUtils;
|
||||
import codechicken.microblock.MicroblockClass;
|
||||
import codechicken.microblock.CommonMicroClass;
|
||||
import codechicken.microblock.MicroblockClass;
|
||||
import codechicken.microblock.handler.MicroblockProxy;
|
||||
import codechicken.nei.ItemStackMap;
|
||||
import codechicken.nei.api.API;
|
||||
import codechicken.nei.api.IConfigureNEI;
|
||||
import java.util.Arrays;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class NEI_MicroblockConfig implements IConfigureNEI
|
||||
{
|
||||
public class NEI_MicroblockConfig implements IConfigureNEI {
|
||||
@Override
|
||||
public void loadConfig() {
|
||||
MicroblockClass[] microClasses = CommonMicroClass.classes();
|
||||
for (int c = 0; c < microClasses.length; c++) {
|
||||
MicroblockClass mcrClass = microClasses[c];
|
||||
if (mcrClass == null)
|
||||
continue;
|
||||
if (mcrClass == null) continue;
|
||||
|
||||
addSubset(mcrClass, c << 8 | 1);
|
||||
addSubset(mcrClass, c << 8 | 2);
|
||||
@@ -28,8 +25,10 @@ public class NEI_MicroblockConfig implements IConfigureNEI
|
||||
}
|
||||
|
||||
private void addSubset(MicroblockClass mcrClass, int i) {
|
||||
API.addSubset("Microblocks." + StatCollector.translateToLocal(mcrClass.getName() + "." + (i & 0xFF) + ".subset"),
|
||||
Arrays.asList(InventoryUtils.newItemStack(MicroblockProxy.itemMicro(), 1, i, ItemStackMap.WILDCARD_TAG)));
|
||||
API.addSubset(
|
||||
"Microblocks." + StatCollector.translateToLocal(mcrClass.getName() + "." + (i & 0xFF) + ".subset"),
|
||||
Arrays.asList(
|
||||
InventoryUtils.newItemStack(MicroblockProxy.itemMicro(), 1, i, ItemStackMap.WILDCARD_TAG)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -41,4 +40,4 @@ public class NEI_MicroblockConfig implements IConfigureNEI
|
||||
public String getVersion() {
|
||||
return "1.0.0.0";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user