mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-21 20:52:21 +00:00
Initial 1.7 commit
This commit is contained in:
1 parent
2f2a18052a
commit
d89bc3848c
69 files changed
+1232
-1573
No files matched your search
File renamed without changes.
@@ -1,3 +1,6 @@
|
||||
microblock.missing=The following microblocks are not installed on this client: %s
|
||||
multipart.missing=The following multiparts are not installed on this client: %s
|
||||
|
||||
item.microblock:sawStone.name=Stone Saw
|
||||
item.microblock:sawIron.name=Iron Saw
|
||||
item.microblock:sawDiamond.name=Diamond Saw
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -15,7 +15,6 @@ import java.net.URLConnection;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.ZipEntry;
|
||||
@@ -31,12 +30,9 @@ import javax.swing.WindowConstants;
|
||||
import javax.swing.event.HyperlinkEvent;
|
||||
import javax.swing.event.HyperlinkListener;
|
||||
|
||||
import argo.jdom.JdomParser;
|
||||
import argo.jdom.JsonNode;
|
||||
import argo.jdom.JsonRootNode;
|
||||
import argo.jdom.JsonStringNode;
|
||||
import argo.saj.InvalidSyntaxException;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
|
||||
import cpw.mods.fml.common.versioning.ComparableVersion;
|
||||
@@ -51,14 +47,12 @@ import sun.net.util.URLUtil;
|
||||
* For autodownloading stuff.
|
||||
* This is really unoriginal, mostly ripped off FML, credits to cpw.
|
||||
*/
|
||||
public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook
|
||||
{
|
||||
public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
private static ByteBuffer downloadBuffer = ByteBuffer.allocateDirect(1 << 23);
|
||||
private static final String owner = "CB's DepLoader";
|
||||
private static DepLoadInst inst;
|
||||
|
||||
public interface IDownloadDisplay
|
||||
{
|
||||
|
||||
public interface IDownloadDisplay {
|
||||
void resetProgress(int sizeGuess);
|
||||
|
||||
void setPokeThread(Thread currentThread);
|
||||
@@ -67,59 +61,53 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook
|
||||
|
||||
boolean shouldStopIt();
|
||||
|
||||
void updateProgressString(String string, Object ... data);
|
||||
void updateProgressString(String string, Object... data);
|
||||
|
||||
Object makeDialog();
|
||||
|
||||
void showErrorDialog(String name, String url);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public static class Downloader extends JOptionPane implements IDownloadDisplay
|
||||
{
|
||||
public static class Downloader extends JOptionPane implements IDownloadDisplay {
|
||||
private JDialog container;
|
||||
private JLabel currentActivity;
|
||||
private JProgressBar progress;
|
||||
boolean stopIt;
|
||||
Thread pokeThread;
|
||||
|
||||
private Box makeProgressPanel()
|
||||
{
|
||||
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>");
|
||||
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>");
|
||||
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)));
|
||||
box.add(Box.createRigidArea(new Dimension(0, 10)));
|
||||
currentActivity = new JLabel("Currently doing ...");
|
||||
box.add(currentActivity);
|
||||
box.add(Box.createRigidArea(new Dimension(0,10)));
|
||||
box.add(Box.createRigidArea(new Dimension(0, 10)));
|
||||
progress = new JProgressBar(0, 100);
|
||||
progress.setStringPainted(true);
|
||||
box.add(progress);
|
||||
box.add(Box.createRigidArea(new Dimension(0,30)));
|
||||
box.add(Box.createRigidArea(new Dimension(0, 30)));
|
||||
return box;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JDialog makeDialog()
|
||||
{
|
||||
if(container != null)
|
||||
public JDialog makeDialog() {
|
||||
if (container != null)
|
||||
return container;
|
||||
|
||||
|
||||
setMessageType(JOptionPane.INFORMATION_MESSAGE);
|
||||
setMessage(makeProgressPanel());
|
||||
setOptions(new Object[] { "Stop" });
|
||||
addPropertyChangeListener(new PropertyChangeListener()
|
||||
{
|
||||
setOptions(new Object[]{"Stop"});
|
||||
addPropertyChangeListener(new PropertyChangeListener() {
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt)
|
||||
{
|
||||
if (evt.getSource() == Downloader.this && evt.getPropertyName()==VALUE_PROPERTY)
|
||||
{
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (evt.getSource() == Downloader.this && evt.getPropertyName() == VALUE_PROPERTY) {
|
||||
requestClose("This will stop minecraft from launching\nAre you sure you want to do this?");
|
||||
}
|
||||
}
|
||||
@@ -133,164 +121,140 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook
|
||||
container.setMinimumSize(container.getPreferredSize());
|
||||
container.setVisible(true);
|
||||
container.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
|
||||
container.addWindowListener(new WindowAdapter()
|
||||
{
|
||||
container.addWindowListener(new WindowAdapter() {
|
||||
@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?");
|
||||
}
|
||||
});
|
||||
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);
|
||||
if (shouldClose == JOptionPane.YES_OPTION)
|
||||
container.dispose();
|
||||
|
||||
|
||||
stopIt = true;
|
||||
if (pokeThread != null)
|
||||
pokeThread.interrupt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProgressString(String progressUpdate, Object... data)
|
||||
{
|
||||
public void updateProgressString(String progressUpdate, Object... data) {
|
||||
//FMLLog.finest(progressUpdate, data);
|
||||
if (currentActivity!=null)
|
||||
if (currentActivity != null)
|
||||
currentActivity.setText(String.format(progressUpdate, data));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetProgress(int sizeGuess)
|
||||
{
|
||||
if (progress!=null)
|
||||
public void resetProgress(int sizeGuess) {
|
||||
if (progress != null)
|
||||
progress.getModel().setRangeProperties(0, 0, 0, sizeGuess, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProgress(int fullLength)
|
||||
{
|
||||
if (progress!=null)
|
||||
public void updateProgress(int fullLength) {
|
||||
if (progress != null)
|
||||
progress.getModel().setValue(fullLength);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPokeThread(Thread currentThread)
|
||||
{
|
||||
public void setPokeThread(Thread currentThread) {
|
||||
this.pokeThread = currentThread;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldStopIt()
|
||||
{
|
||||
public boolean shouldStopIt() {
|
||||
return stopIt;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void showErrorDialog(String name, String url) {
|
||||
JEditorPane ep = new JEditorPane("text/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>");
|
||||
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);
|
||||
ep.addHyperlinkListener(new HyperlinkListener()
|
||||
{
|
||||
ep.addHyperlinkListener(new HyperlinkListener() {
|
||||
@Override
|
||||
public void hyperlinkUpdate(HyperlinkEvent event)
|
||||
{
|
||||
try
|
||||
{
|
||||
public void hyperlinkUpdate(HyperlinkEvent event) {
|
||||
try {
|
||||
if (event.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED))
|
||||
Desktop.getDesktop().browse(event.getURL().toURI());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch(Exception e)
|
||||
{}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
JOptionPane.showMessageDialog(null, ep, "A download error has occured", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
public static class DummyDownloader implements IDownloadDisplay
|
||||
{
|
||||
|
||||
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()
|
||||
{
|
||||
public boolean shouldStopIt() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProgressString(String string, Object... data)
|
||||
{
|
||||
public void updateProgressString(String string, Object... data) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object makeDialog()
|
||||
{
|
||||
public Object makeDialog() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void showErrorDialog(String name, String url) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Dependancy
|
||||
{
|
||||
|
||||
public static class Dependancy {
|
||||
public String url;
|
||||
public String[] filesplit;
|
||||
public ComparableVersion version;
|
||||
|
||||
|
||||
public String existing;
|
||||
/**
|
||||
* Flag set to add this dep to the classpath immediately because it is required for a coremod.
|
||||
*/
|
||||
public boolean coreLib;
|
||||
|
||||
public Dependancy(String url, String[] filesplit, boolean coreLib)
|
||||
{
|
||||
|
||||
public Dependancy(String url, String[] filesplit, boolean coreLib) {
|
||||
this.url = url;
|
||||
this.filesplit = filesplit;
|
||||
this.coreLib = coreLib;
|
||||
version = new ComparableVersion(filesplit[1]);
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
public String getName() {
|
||||
return filesplit[0];
|
||||
}
|
||||
|
||||
public String fileName()
|
||||
{
|
||||
return filesplit[0]+filesplit[1]+filesplit[2];
|
||||
public String fileName() {
|
||||
return filesplit[0] + filesplit[1] + filesplit[2];
|
||||
}
|
||||
}
|
||||
|
||||
public static class DepLoadInst
|
||||
{
|
||||
|
||||
public static class DepLoadInst {
|
||||
private File modsDir;
|
||||
private File v_modsDir;
|
||||
private IDownloadDisplay downloadMonitor;
|
||||
@@ -298,36 +262,30 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook
|
||||
|
||||
private Map<String, Dependancy> depMap = new HashMap<String, Dependancy>();
|
||||
private HashSet<String> depSet = new HashSet<String>();
|
||||
|
||||
public DepLoadInst()
|
||||
{
|
||||
|
||||
public DepLoadInst() {
|
||||
String mcVer = (String) FMLInjectionData.data()[4];
|
||||
File mcDir = (File) FMLInjectionData.data()[6];
|
||||
|
||||
|
||||
modsDir = new File(mcDir, "mods");
|
||||
v_modsDir = new File(mcDir, "mods/"+mcVer);
|
||||
if(!v_modsDir.exists())
|
||||
v_modsDir = new File(mcDir, "mods/" + mcVer);
|
||||
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());
|
||||
}
|
||||
catch(MalformedURLException e)
|
||||
{
|
||||
|
||||
private void addClasspath(String name) {
|
||||
try {
|
||||
((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())
|
||||
if (mod.delete())
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
ClassLoader cl = DepLoader.class.getClassLoader();
|
||||
URL url = mod.toURI().toURL();
|
||||
Field f_ucp = URLClassLoader.class.getDeclaredField("ucp");
|
||||
@@ -338,81 +296,71 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook
|
||||
f_lmap.setAccessible(true);
|
||||
|
||||
URLClassPath ucp = (URLClassPath) f_ucp.get(cl);
|
||||
Closeable loader = ((Map<String, Closeable>)f_lmap.get(ucp)).remove(URLUtil.urlNoFragString(url));
|
||||
if(loader != null) {
|
||||
Closeable loader = ((Map<String, Closeable>) f_lmap.get(ucp)).remove(URLUtil.urlNoFragString(url));
|
||||
if (loader != null) {
|
||||
loader.close();
|
||||
((List<?>)f_loaders.get(ucp)).remove(loader);
|
||||
((List<?>) f_loaders.get(ucp)).remove(loader);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(!mod.delete()) {
|
||||
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())
|
||||
if (!GraphicsEnvironment.isHeadless())
|
||||
JOptionPane.showMessageDialog(null, msg, "An update error has occured", JOptionPane.ERROR_MESSAGE);
|
||||
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
private void download(Dependancy dep)
|
||||
{
|
||||
private void download(Dependancy dep) {
|
||||
popupWindow = (JDialog) downloadMonitor.makeDialog();
|
||||
File libFile = new File(v_modsDir, dep.fileName());
|
||||
try
|
||||
{
|
||||
URL libDownload = new URL(dep.url+'/'+dep.fileName());
|
||||
try {
|
||||
URL libDownload = new URL(dep.url + '/' + dep.fileName());
|
||||
downloadMonitor.updateProgressString("Downloading file %s", libDownload.toString());
|
||||
System.out.format("Downloading file %s\n", libDownload.toString());
|
||||
URLConnection connection = libDownload.openConnection();
|
||||
connection.setConnectTimeout(5000);
|
||||
connection.setReadTimeout(5000);
|
||||
connection.setRequestProperty("User-Agent", ""+owner+" Downloader");
|
||||
connection.setRequestProperty("User-Agent", "" + owner + " Downloader");
|
||||
int sizeGuess = connection.getContentLength();
|
||||
download(connection.getInputStream(), sizeGuess, libFile);
|
||||
downloadMonitor.updateProgressString("Download complete");
|
||||
System.out.println("Download complete");
|
||||
|
||||
|
||||
scanDepInfo(libFile);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
libFile.delete();
|
||||
if (downloadMonitor.shouldStopIt())
|
||||
{
|
||||
if (downloadMonitor.shouldStopIt()) {
|
||||
System.err.println("You have stopped the downloading operation before it could complete");
|
||||
System.exit(1);
|
||||
return;
|
||||
}
|
||||
downloadMonitor.showErrorDialog(dep.fileName(), dep.url+'/'+dep.fileName());
|
||||
downloadMonitor.showErrorDialog(dep.fileName(), dep.url + '/' + dep.fileName());
|
||||
throw new RuntimeException("A download error occured", e);
|
||||
}
|
||||
}
|
||||
|
||||
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())
|
||||
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();
|
||||
|
||||
int bytesRead, fullLength = 0;
|
||||
|
||||
downloadMonitor.resetProgress(sizeGuess);
|
||||
try
|
||||
{
|
||||
try {
|
||||
downloadMonitor.setPokeThread(Thread.currentThread());
|
||||
byte[] smallBuffer = new byte[1024];
|
||||
while ((bytesRead = is.read(smallBuffer)) >= 0) {
|
||||
downloadBuffer.put(smallBuffer, 0, bytesRead);
|
||||
fullLength += bytesRead;
|
||||
if (downloadMonitor.shouldStopIt())
|
||||
{
|
||||
if (downloadMonitor.shouldStopIt()) {
|
||||
break;
|
||||
}
|
||||
downloadMonitor.updateProgress(fullLength);
|
||||
@@ -421,76 +369,64 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook
|
||||
downloadMonitor.setPokeThread(null);
|
||||
downloadBuffer.limit(fullLength);
|
||||
downloadBuffer.position(0);
|
||||
}
|
||||
catch (InterruptedIOException e)
|
||||
{
|
||||
} catch (InterruptedIOException e) {
|
||||
// We were interrupted by the stop button. We're stopping now.. clear interruption flag.
|
||||
Thread.interrupted();
|
||||
throw new Exception("Stop");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
try {
|
||||
/*String cksum = generateChecksum(downloadBuffer);
|
||||
if (cksum.equals(validationHash))
|
||||
{*/
|
||||
if(!target.exists())
|
||||
target.createNewFile();
|
||||
|
||||
|
||||
downloadBuffer.position(0);
|
||||
FileOutputStream fos = new FileOutputStream(target);
|
||||
fos.getChannel().write(downloadBuffer);
|
||||
fos.close();
|
||||
if (!target.exists())
|
||||
target.createNewFile();
|
||||
|
||||
|
||||
downloadBuffer.position(0);
|
||||
FileOutputStream fos = new FileOutputStream(target);
|
||||
fos.getChannel().write(downloadBuffer);
|
||||
fos.close();
|
||||
/*}
|
||||
else
|
||||
{
|
||||
throw new RuntimeException(String.format("The downloaded file %s has an invalid checksum %s (expecting %s). The download did not succeed correctly and the file has been deleted. Please try launching again.", target.getName(), cksum, validationHash));
|
||||
}*/
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private String checkExisting(String[] dependency)
|
||||
{
|
||||
for(File f : modsDir.listFiles())
|
||||
{
|
||||
private String checkExisting(String[] dependency) {
|
||||
for (File f : modsDir.listFiles()) {
|
||||
String[] split = splitFileName(f.getName());
|
||||
if(split == null || !split[0].equals(dependency[0]))
|
||||
if (split == null || !split[0].equals(dependency[0]))
|
||||
continue;
|
||||
|
||||
if(f.renameTo(new File(v_modsDir, f.getName())))
|
||||
if (f.renameTo(new File(v_modsDir, f.getName())))
|
||||
continue;
|
||||
|
||||
|
||||
deleteMod(f);
|
||||
}
|
||||
|
||||
for(File f : v_modsDir.listFiles())
|
||||
{
|
||||
|
||||
for (File f : v_modsDir.listFiles()) {
|
||||
String[] split = splitFileName(f.getName());
|
||||
if(split == null || !split[0].equals(dependency[0]))
|
||||
if (split == null || !split[0].equals(dependency[0]))
|
||||
continue;
|
||||
|
||||
|
||||
ComparableVersion found = new ComparableVersion(split[1]);
|
||||
ComparableVersion requested = new ComparableVersion(dependency[1]);
|
||||
|
||||
|
||||
int cmp = found.compareTo(requested);
|
||||
if(cmp < 0)
|
||||
{
|
||||
System.out.println("Deleted old version "+f.getName());
|
||||
if (cmp < 0) {
|
||||
System.out.println("Deleted old version " + f.getName());
|
||||
deleteMod(f);
|
||||
return null;
|
||||
}
|
||||
if(cmp > 0)
|
||||
{
|
||||
System.err.println("Warning: version of "+dependency[0]+", "+split[1]+" is newer than request "+dependency[1]);
|
||||
if (cmp > 0) {
|
||||
System.err.println("Warning: version of " + dependency[0] + ", " + split[1] + " is newer than request " + dependency[1]);
|
||||
return f.getName();
|
||||
}
|
||||
return f.getName();//found dependency
|
||||
@@ -498,215 +434,176 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook
|
||||
return null;
|
||||
}
|
||||
|
||||
public void load()
|
||||
{
|
||||
public void load() {
|
||||
scanDepInfos();
|
||||
if(depMap.isEmpty())
|
||||
if (depMap.isEmpty())
|
||||
return;
|
||||
|
||||
|
||||
loadDeps();
|
||||
activateDeps();
|
||||
}
|
||||
|
||||
private void activateDeps()
|
||||
{
|
||||
for(Dependancy dep : depMap.values())
|
||||
if(dep.coreLib)
|
||||
private void activateDeps() {
|
||||
for (Dependancy dep : depMap.values())
|
||||
if (dep.coreLib)
|
||||
addClasspath(dep.existing);
|
||||
}
|
||||
|
||||
private void loadDeps()
|
||||
{
|
||||
private void loadDeps() {
|
||||
downloadMonitor = FMLLaunchHandler.side().isClient() ? new Downloader() : new DummyDownloader();
|
||||
try
|
||||
{
|
||||
while(!depSet.isEmpty())
|
||||
{
|
||||
try {
|
||||
while (!depSet.isEmpty()) {
|
||||
Iterator<String> it = depSet.iterator();
|
||||
Dependancy dep = depMap.get(it.next());
|
||||
it.remove();
|
||||
load(dep);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (popupWindow != null)
|
||||
{
|
||||
} finally {
|
||||
if (popupWindow != null) {
|
||||
popupWindow.setVisible(false);
|
||||
popupWindow.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void load(Dependancy dep)
|
||||
{
|
||||
|
||||
private void load(Dependancy dep) {
|
||||
dep.existing = checkExisting(dep.filesplit);
|
||||
if(dep.existing == null)//download dep
|
||||
if (dep.existing == null)//download dep
|
||||
{
|
||||
download(dep);
|
||||
dep.existing = dep.fileName();
|
||||
}
|
||||
}
|
||||
|
||||
private List<File> modFiles()
|
||||
{
|
||||
private List<File> modFiles() {
|
||||
List<File> list = new LinkedList<File>();
|
||||
list.addAll(Arrays.asList(modsDir.listFiles()));
|
||||
list.addAll(Arrays.asList(v_modsDir.listFiles()));
|
||||
return list;
|
||||
}
|
||||
|
||||
private void scanDepInfos()
|
||||
{
|
||||
for(File file : modFiles())
|
||||
{
|
||||
if(!file.getName().endsWith(".jar") && !file.getName().endsWith(".zip"))
|
||||
private void scanDepInfos() {
|
||||
for (File file : modFiles()) {
|
||||
if (!file.getName().endsWith(".jar") && !file.getName().endsWith(".zip"))
|
||||
continue;
|
||||
|
||||
|
||||
scanDepInfo(file);
|
||||
}
|
||||
}
|
||||
|
||||
private void scanDepInfo(File file)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
private void scanDepInfo(File file) {
|
||||
try {
|
||||
ZipFile zip = new ZipFile(file);
|
||||
ZipEntry e = zip.getEntry("dependancies.info");
|
||||
if(e == null) e = zip.getEntry("dependencies.info");
|
||||
if(e != null)
|
||||
if (e == null) e = zip.getEntry("dependencies.info");
|
||||
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");
|
||||
} catch (Exception e) {
|
||||
System.err.println("Failed to load dependencies.info from " + file.getName() + " as JSON");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void loadJSon(InputStream input) throws IOException, InvalidSyntaxException
|
||||
{
|
||||
private void loadJSon(InputStream input) throws IOException {
|
||||
InputStreamReader reader = new InputStreamReader(input);
|
||||
JsonRootNode root = new JdomParser().parse(reader);
|
||||
if(root.hasElements())
|
||||
JsonElement root = new JsonParser().parse(reader);
|
||||
if (root.isJsonArray())
|
||||
loadJSonArr(root);
|
||||
else
|
||||
loadJson(root);
|
||||
loadJson(root.getAsJsonObject());
|
||||
reader.close();
|
||||
}
|
||||
|
||||
private void loadJSonArr(JsonRootNode root) throws IOException
|
||||
{
|
||||
for(JsonNode node : root.getElements())
|
||||
loadJson(node);
|
||||
private void loadJSonArr(JsonElement root) throws IOException {
|
||||
for (JsonElement node : root.getAsJsonArray())
|
||||
loadJson(node.getAsJsonObject());
|
||||
}
|
||||
|
||||
private void loadJson(JsonNode node) throws IOException
|
||||
{
|
||||
boolean obfuscated = ((LaunchClassLoader)DepLoader.class.getClassLoader())
|
||||
private void loadJson(JsonObject node) throws IOException {
|
||||
boolean obfuscated = ((LaunchClassLoader) DepLoader.class.getClassLoader())
|
||||
.getClassBytes("net.minecraft.world.World") == null;
|
||||
|
||||
String testClass = node.getStringValue("class");
|
||||
if(DepLoader.class.getResource("/"+testClass.replace('.', '/')+".class") != null)
|
||||
|
||||
String testClass = node.get("class").getAsString();
|
||||
if (DepLoader.class.getResource("/" + testClass.replace('.', '/') + ".class") != null)
|
||||
return;
|
||||
|
||||
String repo = node.getStringValue("repo");
|
||||
String file = node.getStringValue("file");
|
||||
if(!obfuscated && node.isNode("dev"))
|
||||
file = node.getStringValue("dev");
|
||||
|
||||
boolean coreLib = node.isNode("coreLib") && node.getBooleanValue("coreLib");
|
||||
|
||||
List<String> reserved = Arrays.asList("repo", "file", "class", "dev", "coreLib");
|
||||
for(Entry<JsonStringNode, JsonNode> e : node.getFields().entrySet())
|
||||
{
|
||||
String s = e.getKey().getText();
|
||||
if(!e.getValue().hasText() || reserved.contains(s))
|
||||
continue;
|
||||
|
||||
file = file.replaceAll("@"+s.toUpperCase(Locale.ENGLISH)+"@", e.getValue().getText());
|
||||
}
|
||||
|
||||
|
||||
String repo = node.get("repo").getAsString();
|
||||
String file = node.get("file").getAsString();
|
||||
if (!obfuscated && node.has("dev"))
|
||||
file = node.get("dev").getAsString();
|
||||
|
||||
boolean coreLib = node.has("coreLib") && node.get("coreLib").getAsBoolean();
|
||||
|
||||
String[] split = splitFileName(file);
|
||||
if(split == null)
|
||||
throw new RuntimeException("Invalid filename format for dependency: "+file);
|
||||
|
||||
if (split == null)
|
||||
throw new RuntimeException("Invalid filename format for dependency: " + file);
|
||||
|
||||
addDep(new Dependancy(repo, split, coreLib));
|
||||
}
|
||||
|
||||
private void addDep(Dependancy newDep)
|
||||
{
|
||||
if(mergeNew(depMap.get(newDep.getName()), newDep))
|
||||
{
|
||||
private void addDep(Dependancy newDep) {
|
||||
if (mergeNew(depMap.get(newDep.getName()), newDep)) {
|
||||
depMap.put(newDep.getName(), newDep);
|
||||
depSet.add(newDep.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean mergeNew(Dependancy oldDep, Dependancy newDep) {
|
||||
if(oldDep == null)
|
||||
if (oldDep == null)
|
||||
return true;
|
||||
|
||||
|
||||
Dependancy newest = newDep.version.compareTo(oldDep.version) > 0 ? newDep : oldDep;
|
||||
newest.coreLib = newDep.coreLib || oldDep.coreLib;
|
||||
|
||||
|
||||
return newest == newDep;
|
||||
}
|
||||
}
|
||||
|
||||
public static void load()
|
||||
{
|
||||
if(inst == null)
|
||||
{
|
||||
|
||||
public static void load() {
|
||||
if (inst == null) {
|
||||
inst = new DepLoadInst();
|
||||
inst.load();
|
||||
}
|
||||
}
|
||||
|
||||
private static String[] splitFileName(String filename)
|
||||
{
|
||||
private static String[] splitFileName(String filename) {
|
||||
Pattern p = Pattern.compile("(.+?)([\\d\\.\\w]+)(\\.[^\\d]+)");
|
||||
Matcher m = p.matcher(filename);
|
||||
if(!m.matches())
|
||||
if (!m.matches())
|
||||
return null;
|
||||
|
||||
|
||||
return new String[]{m.group(1), m.group(2), m.group(3)};
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String[] getASMTransformerClass()
|
||||
{
|
||||
public String[] getASMTransformerClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getModContainerClass()
|
||||
{
|
||||
public String getModContainerClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getSetupClass()
|
||||
{
|
||||
public String getSetupClass() {
|
||||
return getClass().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectData(Map<String, Object> data)
|
||||
{
|
||||
public void injectData(Map<String, Object> data) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Void call()
|
||||
{
|
||||
public Void call() {
|
||||
load();
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String[] getLibraryRequestClass() {
|
||||
@Override
|
||||
public String getAccessTransformerClass() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -2,92 +2,83 @@ package codechicken.microblock
|
||||
|
||||
import net.minecraft.block.Block
|
||||
import codechicken.microblock.MicroMaterialRegistry.IMicroMaterial
|
||||
import net.minecraft.util.Icon
|
||||
import codechicken.lib.lighting.LC
|
||||
import codechicken.lib.lighting.LightMatrix
|
||||
import net.minecraft.util.IIcon
|
||||
import cpw.mods.fml.relauncher.SideOnly
|
||||
import cpw.mods.fml.relauncher.Side
|
||||
import codechicken.lib.render.MultiIconTransformation
|
||||
import codechicken.lib.render.IUVTransformation
|
||||
import net.minecraft.item.ItemStack
|
||||
import codechicken.lib.vec.Vector3
|
||||
import codechicken.lib.vec.{Cuboid6, Vector3}
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import codechicken.lib.render.Vertex5
|
||||
import codechicken.lib.render.UV
|
||||
import net.minecraft.client.renderer.Tessellator
|
||||
import codechicken.lib.render.CCRenderState
|
||||
import codechicken.lib.vec.Rotation
|
||||
import net.minecraftforge.common.MinecraftForge
|
||||
import codechicken.lib.render.{CCRenderPipeline, ColourMultiplier, CCRenderState}
|
||||
import codechicken.microblock.handler.MicroblockProxy
|
||||
import net.minecraft.entity.Entity
|
||||
import codechicken.lib.render.uv.{UVTransformation, MultiIconTransformation}
|
||||
|
||||
object MaterialRenderHelper
|
||||
{
|
||||
private var pass = 0
|
||||
private var builder:CCRenderPipeline#PipelineBuilder = _
|
||||
|
||||
def start(pos:Vector3, pass:Int, uvt:UVTransformation) = {
|
||||
this.pass = pass
|
||||
builder = CCRenderState.pipeline.builder()
|
||||
builder.add(pos.translation()).add(uvt)
|
||||
this
|
||||
}
|
||||
|
||||
def blockColour(colour:Int) = {
|
||||
builder.add(ColourMultiplier.instance(colour))
|
||||
this
|
||||
}
|
||||
|
||||
def lighting() = {
|
||||
if(pass != -1)
|
||||
builder.add(CCRenderState.lightMatrix)
|
||||
this
|
||||
}
|
||||
|
||||
def render() = builder.render()
|
||||
}
|
||||
|
||||
/**
|
||||
* Standard micro material class suitable for most blocks.
|
||||
*/
|
||||
class BlockMicroMaterial(val block:Block, val meta:Int = 0) extends IMicroMaterial
|
||||
{
|
||||
val blockKey = Block.blockRegistry.getNameForObject(block)
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
var icont:MultiIconTransformation = _
|
||||
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def loadIcons()
|
||||
{
|
||||
val iblock = Block.blocksList(block.blockID)//Reacquire the block instance incase a mod replaced it.
|
||||
val icons = new Array[Icon](6)
|
||||
|
||||
if(iblock == null)
|
||||
for(i <- 0 until 6)
|
||||
icons(i) = MicroblockProxy.renderBlocks.getIconSafe(null)
|
||||
else
|
||||
for(i <- 0 until 6)
|
||||
icons(i) = MicroblockProxy.renderBlocks.getIconSafe(iblock.getIcon(i, meta))
|
||||
|
||||
icont = new MultiIconTransformation(icons:_*)
|
||||
override def loadIcons() {
|
||||
def safeIcon(block:Block, side:Int):IIcon = {
|
||||
try {
|
||||
return MicroblockProxy.renderBlocks.getIconSafe(block.getIcon(side, meta))
|
||||
}
|
||||
catch {
|
||||
case e:Exception =>
|
||||
}
|
||||
return MicroblockProxy.renderBlocks.getIconSafe(null)
|
||||
}
|
||||
|
||||
val iblock = Block.getBlockFromName(blockKey)//reacquire block instance incase a mod replcaed it
|
||||
icont = new MultiIconTransformation(Array.tabulate(6)(side => safeIcon(iblock, side)):_*)
|
||||
}
|
||||
|
||||
def getRenderPass = if(block.canRenderInPass(1)) 1 else 0
|
||||
|
||||
def renderMicroFace(verts:Array[Vertex5], side:Int, pos:Vector3, lightMatrix:LightMatrix, part:IMicroMaterialRender)
|
||||
{
|
||||
renderMicroFace(verts, side, pos, lightMatrix, getColour(part), icont)
|
||||
|
||||
def renderMicroFace(pos:Vector3, pass:Int, bounds:Cuboid6) {
|
||||
MaterialRenderHelper.start(pos, pass, icont).blockColour(getColour(pass)).lighting().render()
|
||||
}
|
||||
|
||||
def renderMicroFace(verts:Array[Vertex5], side:Int, pos:Vector3, lightMatrix:LightMatrix, colour:Int, uvt:IUVTransformation)
|
||||
{
|
||||
val uv = new UV
|
||||
val t = Tessellator.instance
|
||||
var i = 0
|
||||
while(i < 4)
|
||||
{
|
||||
if(CCRenderState.useNormals)
|
||||
{
|
||||
val n = Rotation.axes(side%6)
|
||||
t.setNormal(n.x.toFloat, n.y.toFloat, n.z.toFloat)
|
||||
}
|
||||
val vert = verts(i)
|
||||
if(lightMatrix != null)
|
||||
{
|
||||
val lc = LC.computeO(vert.vec, side)
|
||||
if(CCRenderState.useModelColours)
|
||||
lightMatrix.setColour(t, lc, colour)
|
||||
lightMatrix.setBrightness(t, lc)
|
||||
}
|
||||
else
|
||||
{
|
||||
if(CCRenderState.useModelColours)
|
||||
CCRenderState.vertexColour(colour)
|
||||
}
|
||||
uvt.transform(uv.set(vert.uv))
|
||||
t.addVertexWithUV(vert.vec.x+pos.x, vert.vec.y+pos.y, vert.vec.z+pos.z, uv.u, uv.v)
|
||||
i+=1
|
||||
|
||||
def getColour(pass:Int) = {
|
||||
if(pass == -1)
|
||||
block.getBlockColor<<8|0xFF
|
||||
else {
|
||||
val pos = CCRenderState.lightMatrix.pos
|
||||
block.colorMultiplier(CCRenderState.lightMatrix.access, pos.x, pos.y, pos.z)<<8|0xFF
|
||||
}
|
||||
}
|
||||
|
||||
def getColour(part:IMicroMaterialRender) =
|
||||
if(part.world == null)
|
||||
block.getBlockColor<<8|0xFF
|
||||
else
|
||||
block.colorMultiplier(part.world, part.x, part.y, part.z)<<8|0xFF
|
||||
|
||||
override def canRenderInPass(pass:Int) = block.canRenderInPass(pass)
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
def getBreakingIcon(side:Int) = block.getIcon(side, meta)
|
||||
@@ -96,15 +87,23 @@ class BlockMicroMaterial(val block:Block, val meta:Int = 0) extends IMicroMateri
|
||||
|
||||
def getLocalizedName = getItem.getDisplayName
|
||||
|
||||
def getStrength(player:EntityPlayer) = player.getCurrentPlayerStrVsBlock(block, false, meta)/block.blockHardness
|
||||
def getStrength(player:EntityPlayer) = {
|
||||
var hardness = 30F
|
||||
try {
|
||||
hardness = block.getBlockHardness(null, 0, 0, 0)
|
||||
} catch {
|
||||
case e:Exception =>
|
||||
}
|
||||
player.getBreakSpeed(block, false, meta) / hardness
|
||||
}
|
||||
|
||||
def isTransparent = !block.isOpaqueCube
|
||||
|
||||
def getLightValue = Block.lightValue(block.blockID)
|
||||
def getLightValue = block.getLightValue
|
||||
|
||||
def toolClasses = Seq("axe", "pickaxe", "shovel")
|
||||
|
||||
def getCutterStrength = toolClasses.foldLeft(0)((level, tool) => Math.max(level, MinecraftForge.getBlockHarvestLevel(block, meta, tool)))
|
||||
def getCutterStrength = block.getHarvestLevel(meta)
|
||||
|
||||
def getSound = block.stepSound
|
||||
|
||||
@@ -116,20 +115,31 @@ class BlockMicroMaterial(val block:Block, val meta:Int = 0) extends IMicroMateri
|
||||
*/
|
||||
object BlockMicroMaterial
|
||||
{
|
||||
def materialKey(block:Block, meta:Int) = block.getUnlocalizedName+(if(meta > 0) "_"+meta else "")
|
||||
|
||||
def createAndRegister(block:Block)
|
||||
def materialKey(block:Block, meta:Int):String = materialKey(block.getUnlocalizedName, meta)
|
||||
def materialKey(name:String, meta:Int) = name+(if(meta > 0) "_"+meta else "")
|
||||
|
||||
def createAndRegister(block:Block, name:String)
|
||||
{
|
||||
createAndRegister(block, 0)
|
||||
createAndRegister(block, 0, name)
|
||||
}
|
||||
|
||||
def createAndRegister(block:Block, meta:Int)
|
||||
|
||||
def createAndRegister(block:Block, meta:Int = 0)
|
||||
{
|
||||
MicroMaterialRegistry.registerMaterial(new BlockMicroMaterial(block, meta), materialKey(block, meta))
|
||||
}
|
||||
|
||||
|
||||
def createAndRegister(block:Block, meta:Seq[Int])
|
||||
{
|
||||
meta.foreach(m => createAndRegister(block, m))
|
||||
}
|
||||
|
||||
def createAndRegister(block:Block, meta:Int, name:String)
|
||||
{
|
||||
MicroMaterialRegistry.registerMaterial(new BlockMicroMaterial(block, meta), materialKey(name, meta))
|
||||
}
|
||||
|
||||
def createAndRegister(block:Block, meta:Seq[Int], name:String)
|
||||
{
|
||||
meta.foreach(m => createAndRegister(block, m, name))
|
||||
}
|
||||
}
|
||||
@@ -9,9 +9,8 @@ import codechicken.lib.render.CCRenderState
|
||||
import net.minecraft.world.World
|
||||
import codechicken.lib.vec.Cuboid6
|
||||
import codechicken.lib.vec.Vector3
|
||||
import codechicken.lib.lighting.LazyLightMatrix
|
||||
import codechicken.multipart.TIconHitEffects
|
||||
import net.minecraft.util.Icon
|
||||
import net.minecraft.util.IIcon
|
||||
import net.minecraft.block.Block
|
||||
import codechicken.multipart.TCuboidPart
|
||||
import net.minecraft.util.MovingObjectPosition
|
||||
@@ -28,13 +27,22 @@ import codechicken.multipart.TSlottedPart
|
||||
import scala.collection.JavaConversions._
|
||||
import codechicken.lib.render.TextureUtils
|
||||
import net.minecraft.entity.Entity
|
||||
import net.minecraft.init.Blocks
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import codechicken.lib.render.BlockRenderer.BlockFace
|
||||
|
||||
object CommonMicroblock
|
||||
object MicroblockRender
|
||||
{
|
||||
val face = Array[Vertex5](new Vertex5, new Vertex5, new Vertex5, new Vertex5)
|
||||
|
||||
def renderHighlight(world:World, pos:BlockCoord, part:MicroblockClient)
|
||||
def renderHighlight(player:EntityPlayer, hit:MovingObjectPosition, mcrClass:MicroblockClass, size:Int, material:Int)
|
||||
{
|
||||
mcrClass.placementProperties.placementGrid.render(new Vector3(hit.hitVec), hit.sideHit)
|
||||
|
||||
val placement = MicroblockPlacement(player, hit, size, material, !player.capabilities.isCreativeMode, mcrClass.placementProperties)
|
||||
if(placement == null)
|
||||
return
|
||||
val pos = placement.pos
|
||||
val part = placement.part.asInstanceOf[MicroblockClient]
|
||||
|
||||
GL11.glPushMatrix()
|
||||
GL11.glTranslated(pos.x+0.5, pos.y+0.5, pos.z+0.5)
|
||||
GL11.glScaled(1.002, 1.002, 1.002)
|
||||
@@ -43,60 +51,56 @@ object CommonMicroblock
|
||||
GL11.glEnable(GL11.GL_BLEND)
|
||||
GL11.glDepthMask(false)
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA)
|
||||
|
||||
CCRenderState.reset()
|
||||
|
||||
TextureUtils.bindAtlas(0)
|
||||
CCRenderState.useNormals(true)
|
||||
CCRenderState.setBrightness(world, pos.x, pos.y, pos.z)
|
||||
CCRenderState.setAlpha(80)
|
||||
CCRenderState.useModelColours(true)
|
||||
CCRenderState.startDrawing(7)
|
||||
part.render(new Vector3(), null, MicroMaterialRegistry.getMaterial(part.material), part.getBounds, 0)
|
||||
CCRenderState.reset()
|
||||
CCRenderState.alphaOverride = 80
|
||||
CCRenderState.useNormals = true
|
||||
CCRenderState.startDrawing()
|
||||
part.render(Vector3.zero, -1)
|
||||
CCRenderState.draw()
|
||||
|
||||
GL11.glDisable(GL11.GL_BLEND)
|
||||
GL11.glDepthMask(true)
|
||||
GL11.glPopMatrix()
|
||||
}
|
||||
}
|
||||
|
||||
object JMicroblockClient
|
||||
{
|
||||
def renderCuboid(pos:Vector3, olm:LazyLightMatrix, mat:IMicroMaterial, c:Cuboid6, sideMask:Int, part:IMicroMaterialRender)
|
||||
{
|
||||
var lightMatrix:LightMatrix = null
|
||||
if(olm != null)
|
||||
lightMatrix = olm.lightMatrix
|
||||
|
||||
RenderUtils.renderBlock(c, sideMask, new IFaceRenderer()
|
||||
{
|
||||
def renderFace(face:Array[Vertex5], side:Int) =
|
||||
mat.renderMicroFace(face, side, pos, lightMatrix, part)
|
||||
})
|
||||
val face = new BlockFace()
|
||||
def renderCuboid(pos:Vector3, mat:IMicroMaterial, pass:Int, c:Cuboid6, faces:Int) {
|
||||
CCRenderState.setModel(face)
|
||||
for(s <- 0 until 6 if (faces & 1<<s) == 0) {
|
||||
face.loadCuboidFace(c, s)
|
||||
mat.renderMicroFace(pos, pass, c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
trait MicroblockClient extends Microblock with TIconHitEffects with IMicroMaterialRender
|
||||
{
|
||||
def getBrokenIcon(side:Int) = MicroMaterialRegistry.getMaterial(material) match {
|
||||
case null => Block.stone.getIcon(0, 0)
|
||||
def getBrokenIcon(side:Int) = getIMaterial match {
|
||||
case null => Blocks.stone.getIcon(0, 0)
|
||||
case mat => mat.getBreakingIcon(side)
|
||||
}
|
||||
|
||||
def render(pos:Vector3, olm:LazyLightMatrix, mat:IMicroMaterial, c:Cuboid6, sideMask:Int) =
|
||||
renderCuboid(pos, olm, mat, c, sideMask)
|
||||
|
||||
def renderCuboid(pos:Vector3, olm:LazyLightMatrix, mat:IMicroMaterial, c:Cuboid6, sideMask:Int) =
|
||||
JMicroblockClient.renderCuboid(pos, olm, mat, c, sideMask, this)
|
||||
|
||||
override def renderStatic(pos:Vector3, pass:Int) = {
|
||||
if(getIMaterial.canRenderInPass(pass)) {
|
||||
render(pos, pass)
|
||||
true
|
||||
}
|
||||
else
|
||||
false
|
||||
}
|
||||
|
||||
def render(pos:Vector3, pass:Int)
|
||||
|
||||
override def getRenderBounds = getBounds
|
||||
}
|
||||
|
||||
abstract class Microblock(var shape:Byte = 0, var material:Int = 0) extends TCuboidPart
|
||||
{
|
||||
{
|
||||
def this(size:Int, shape:Int, material:Int) = this((size<<4|shape).toByte, material)
|
||||
|
||||
override def getStrength(hit:MovingObjectPosition, player:EntityPlayer) = MicroMaterialRegistry.getMaterial(material) match {
|
||||
override def getStrength(hit:MovingObjectPosition, player:EntityPlayer) = getIMaterial match {
|
||||
case null => super.getStrength(hit, player)
|
||||
case mat => mat.getStrength(player)
|
||||
}
|
||||
@@ -106,9 +110,11 @@ abstract class Microblock(var shape:Byte = 0, var material:Int = 0) extends TCub
|
||||
def getSize = shape>>4
|
||||
|
||||
def getShape = shape&0xF
|
||||
|
||||
|
||||
def getMaterial = material
|
||||
|
||||
def getIMaterial = MicroMaterialRegistry.getMaterial(material)
|
||||
|
||||
def itemClassID:Int = -1
|
||||
|
||||
override def getDrops =
|
||||
@@ -137,13 +143,13 @@ abstract class Microblock(var shape:Byte = 0, var material:Int = 0) extends TCub
|
||||
override def writeDesc(packet:MCDataOutput)
|
||||
{
|
||||
packet.writeByte(shape)
|
||||
writePartID(packet, material)
|
||||
writeMaterialID(packet, material)
|
||||
}
|
||||
|
||||
override def readDesc(packet:MCDataInput)
|
||||
{
|
||||
shape = packet.readByte
|
||||
material = readPartID(packet)
|
||||
material = readMaterialID(packet)
|
||||
}
|
||||
|
||||
override def read(packet:MCDataInput)
|
||||
@@ -165,28 +171,22 @@ abstract class Microblock(var shape:Byte = 0, var material:Int = 0) extends TCub
|
||||
material = materialID(tag.getString("material"))
|
||||
}
|
||||
|
||||
def isTransparent = MicroMaterialRegistry.getMaterial(material).isTransparent
|
||||
def isTransparent = getIMaterial.isTransparent
|
||||
|
||||
override def getLightValue = MicroMaterialRegistry.getMaterial(material).getLightValue
|
||||
override def getLightValue = getIMaterial.getLightValue
|
||||
|
||||
def getResistanceFactor:Float
|
||||
|
||||
override def explosionResistance(entity:Entity) = MicroMaterialRegistry.getMaterial(material).explosionResistance(entity)*getResistanceFactor
|
||||
override def explosionResistance(entity:Entity) = getIMaterial.explosionResistance(entity)*getResistanceFactor
|
||||
}
|
||||
|
||||
trait CommonMicroblockClient extends CommonMicroblock with MicroblockClient with TMicroOcclusionClient
|
||||
{
|
||||
override def renderStatic(pos:Vector3, olm:LazyLightMatrix, pass:Int)
|
||||
{
|
||||
val mat = MicroMaterialRegistry.getMaterial(material)
|
||||
if(mat != null && pass == mat.getRenderPass)
|
||||
render(pos, olm, mat, renderBounds, renderMask)
|
||||
}
|
||||
|
||||
override def read(packet:MCDataInput)
|
||||
{
|
||||
super.read(packet)
|
||||
recalcBounds()
|
||||
def render(pos:Vector3, pass:Int) {
|
||||
if(pass < 0)
|
||||
MicroblockRender.renderCuboid(pos, getIMaterial, pass, getBounds, 0)
|
||||
else
|
||||
MicroblockRender.renderCuboid(pos, getIMaterial, pass, renderBounds, renderMask)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,16 +7,20 @@ import java.io.BufferedReader
|
||||
import java.io.FileReader
|
||||
import scala.collection.mutable.{Map => MMap}
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.item.Item
|
||||
import java.lang.Exception
|
||||
import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage
|
||||
import net.minecraft.item.ItemStack
|
||||
import BlockMicroMaterial.createAndRegister
|
||||
import BlockMicroMaterial.materialKey
|
||||
import java.util.ArrayList
|
||||
import scala.collection.JavaConversions._
|
||||
import net.minecraft.init.Blocks
|
||||
|
||||
object ConfigContent
|
||||
{
|
||||
private val nameMap = MMap[String, Seq[Int]]()
|
||||
private val idMap = new Array[Seq[Int]](Block.blocksList.length)
|
||||
private val idMap = new ArrayList[Seq[Int]]()
|
||||
|
||||
def parse(cfgDir:File)
|
||||
{
|
||||
@@ -116,12 +120,12 @@ object ConfigContent
|
||||
|
||||
def load()
|
||||
{
|
||||
for(i <- 0 until idMap.length)
|
||||
for(i <- 0 until idMap.size)
|
||||
{
|
||||
val block = Block.blocksList(i)
|
||||
val block = Block.getBlockById(i)
|
||||
if(idMap(i) != null)
|
||||
{
|
||||
if(block == null)
|
||||
if(block == Blocks.air)
|
||||
System.err.println("Warning: Unable to add micro material for block with ID "+i+" as it doesn't exist")
|
||||
else
|
||||
createAndRegister(block, idMap(i))
|
||||
@@ -163,17 +167,17 @@ object ConfigContent
|
||||
error("value is not an instanceof ItemStack")
|
||||
else {
|
||||
val stack = msg.getItemStackValue
|
||||
if(stack.itemID >= Block.blocksList.length || Block.blocksList(stack.itemID) == null)
|
||||
System.err.println("Invalid blockID: "+stack.itemID)
|
||||
if(Block.blockRegistry.containsId(Item.getIdFromItem(stack.getItem)))
|
||||
System.err.println("Invalid Block: "+stack.getItem)
|
||||
else if(stack.getItemDamage < 0 || stack.getItemDamage >= 16)
|
||||
System.err.println("Invalid metadata: "+stack.getItemDamage)
|
||||
else {
|
||||
try {
|
||||
createAndRegister(Block.blocksList(stack.itemID), stack.getItemDamage)
|
||||
createAndRegister(Block.getBlockFromItem(stack.getItem), stack.getItemDamage)
|
||||
}
|
||||
catch {
|
||||
case e:IllegalStateException => System.err.println("Unable to register micro material: "+
|
||||
materialKey(Block.blocksList(stack.itemID), stack.getItemDamage)+"\n\t"+e.getMessage)
|
||||
materialKey(Block.getBlockFromItem(stack.getItem), stack.getItemDamage)+"\n\t"+e.getMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package codechicken.microblock
|
||||
|
||||
import net.minecraft.block.Block._
|
||||
import net.minecraft.init.Blocks._
|
||||
import BlockMicroMaterial._
|
||||
import MicroMaterialRegistry._
|
||||
|
||||
@@ -18,35 +18,38 @@ object DefaultContent
|
||||
createAndRegister(dirt)
|
||||
createAndRegister(cobblestone)
|
||||
createAndRegister(planks, 0 to 3)
|
||||
createAndRegister(wood, 0 to 3)
|
||||
createAndRegister(log, 0 to 3)
|
||||
createAndRegister(log2, 0 to 1, "tile.log2")
|
||||
createAndRegister(leaves, 0 to 3)
|
||||
createAndRegister(sponge)
|
||||
createAndRegister(glass)
|
||||
createAndRegister(blockLapis)
|
||||
createAndRegister(sandStone, 0 to 2)
|
||||
createAndRegister(cloth, 0 to 15)
|
||||
createAndRegister(blockGold)
|
||||
createAndRegister(blockIron)
|
||||
createAndRegister(brick)
|
||||
createAndRegister(bookShelf)
|
||||
createAndRegister(cobblestoneMossy)
|
||||
createAndRegister(lapis_block)
|
||||
createAndRegister(sandstone, 0 to 2)
|
||||
createAndRegister(wool, 0 to 15)
|
||||
createAndRegister(gold_block)
|
||||
createAndRegister(iron_block)
|
||||
createAndRegister(brick_block)
|
||||
createAndRegister(bookshelf)
|
||||
createAndRegister(mossy_cobblestone)
|
||||
createAndRegister(obsidian)
|
||||
createAndRegister(blockDiamond)
|
||||
createAndRegister(diamond_block)
|
||||
createAndRegister(ice)
|
||||
createAndRegister(snow)
|
||||
createAndRegister(blockClay)
|
||||
createAndRegister(clay)
|
||||
createAndRegister(netherrack)
|
||||
createAndRegister(slowSand)
|
||||
createAndRegister(glowStone)
|
||||
createAndRegister(stoneBrick, 0 to 3)
|
||||
createAndRegister(netherBrick)
|
||||
createAndRegister(whiteStone)
|
||||
createAndRegister(blockEmerald)
|
||||
createAndRegister(blockRedstone)
|
||||
createAndRegister(blockNetherQuartz)
|
||||
createAndRegister(stainedClay, 0 to 15)
|
||||
createAndRegister(hardenedClay)
|
||||
createAndRegister(coalBlock)
|
||||
createAndRegister(soul_sand)
|
||||
createAndRegister(glowstone)
|
||||
createAndRegister(stonebrick, 0 to 3)
|
||||
createAndRegister(nether_brick)
|
||||
createAndRegister(end_stone)
|
||||
createAndRegister(emerald_block)
|
||||
createAndRegister(redstone_block)
|
||||
createAndRegister(quartz_block)
|
||||
createAndRegister(stained_hardened_clay, 0 to 15)
|
||||
createAndRegister(hardened_clay)
|
||||
createAndRegister(coal_block)
|
||||
createAndRegister(packed_ice)
|
||||
createAndRegister(stained_glass)
|
||||
registerMaterial(new GrassMicroMaterial, grass.getUnlocalizedName)
|
||||
registerMaterial(new TopMicroMaterial(mycelium), mycelium.getUnlocalizedName)
|
||||
}
|
||||
|
||||
@@ -13,12 +13,12 @@ import codechicken.multipart.TNormalOcclusion
|
||||
import codechicken.multipart.JPartialOcclusion
|
||||
import codechicken.multipart.TileMultipart
|
||||
import codechicken.multipart.MultiPartRegistry
|
||||
import codechicken.lib.lighting.LazyLightMatrix
|
||||
import codechicken.microblock.MicroMaterialRegistry.IMicroMaterial
|
||||
import codechicken.lib.raytracer.ExtendedMOP
|
||||
import codechicken.multipart.TEdgePart
|
||||
import scala.collection.JavaConversions._
|
||||
import codechicken.lib.data.MCDataInput
|
||||
import codechicken.lib.lighting.LightMatrix
|
||||
|
||||
object EdgePlacement extends PlacementProperties
|
||||
{
|
||||
@@ -103,11 +103,6 @@ object EdgeMicroClass extends MicroblockClass
|
||||
def getResistanceFactor = 0.5F
|
||||
}
|
||||
|
||||
class EdgeMicroblockClient(shape$:Byte = 0, material$:Int = 0) extends EdgeMicroblock(shape$, material$) with CommonMicroblockClient
|
||||
{
|
||||
def this(size:Int, slot:Int, material:Int) = this((size<<4|(slot-15)).toByte, material)
|
||||
}
|
||||
|
||||
class EdgeMicroblock(shape$:Byte = 0, material$:Int = 0) extends CommonMicroblock(shape$, material$) with TEdgePart
|
||||
{
|
||||
def this(size:Int, slot:Int, material:Int) = this((size<<4|(slot-15)).toByte, material)
|
||||
@@ -119,6 +114,11 @@ class EdgeMicroblock(shape$:Byte = 0, material$:Int = 0) extends CommonMicrobloc
|
||||
override def getSlot = getShape+15
|
||||
}
|
||||
|
||||
class EdgeMicroblockClient(shape$:Byte = 0, material$:Int = 0) extends EdgeMicroblock(shape$, material$) with CommonMicroblockClient
|
||||
{
|
||||
def this(size:Int, slot:Int, material:Int) = this((size<<4|(slot-15)).toByte, material)
|
||||
}
|
||||
|
||||
object PostMicroClass
|
||||
{
|
||||
var aBounds:Array[Cuboid6] = new Array(256)
|
||||
@@ -160,18 +160,16 @@ class PostMicroblockClient(shape$:Byte = 0, material$:Int = 0) extends PostMicro
|
||||
|
||||
def this(size:Int, orient:Int, material:Int) = this((size<<4|orient).toByte, material)
|
||||
|
||||
override def renderStatic(pos:Vector3, olm:LazyLightMatrix, pass:Int)
|
||||
override def render(pos:Vector3, pass:Int)
|
||||
{
|
||||
val mat = MicroMaterialRegistry.getMaterial(material)
|
||||
if(mat != null && pass == mat.getRenderPass)
|
||||
render(pos, olm, mat)
|
||||
}
|
||||
|
||||
def render(pos:Vector3, olm:LazyLightMatrix, mat:IMicroMaterial)
|
||||
{
|
||||
renderCuboid(pos, olm, mat, renderBounds1, 0)
|
||||
if(renderBounds2 != null)
|
||||
renderCuboid(pos, olm, mat, renderBounds2, 0)
|
||||
val mat = getIMaterial
|
||||
if(pass == -1)
|
||||
MicroblockRender.renderCuboid(pos, mat, pass, getBounds, 0)
|
||||
else {
|
||||
MicroblockRender.renderCuboid(pos, mat, pass, renderBounds1, 0)
|
||||
if (renderBounds2 != null)
|
||||
MicroblockRender.renderCuboid(pos, mat, pass, renderBounds2, 0)
|
||||
}
|
||||
}
|
||||
|
||||
override def onPartChanged(part:TMultiPart)
|
||||
@@ -184,7 +182,7 @@ class PostMicroblockClient(shape$:Byte = 0, material$:Int = 0) extends PostMicro
|
||||
super.onAdded()
|
||||
recalcBounds()
|
||||
}
|
||||
|
||||
|
||||
override def read(packet:MCDataInput)
|
||||
{
|
||||
super.read(packet)
|
||||
@@ -220,15 +218,9 @@ class PostMicroblockClient(shape$:Byte = 0, material$:Int = 0) extends PostMicro
|
||||
if(thisShrinks(post))
|
||||
{
|
||||
if(renderBounds2 == null)
|
||||
{
|
||||
renderBounds2 = renderBounds1.copy
|
||||
getShape match
|
||||
{
|
||||
case 0 => renderBounds2.min.y = 0.5; renderBounds1.max.y = 0.5
|
||||
case 1 => renderBounds2.min.z = 0.5; renderBounds1.max.z = 0.5
|
||||
case 2 => renderBounds2.min.x = 0.5; renderBounds1.max.x = 0.5
|
||||
}
|
||||
}
|
||||
else
|
||||
renderBounds2.set(renderBounds1)
|
||||
MicroOcclusion.shrink(renderBounds1, post.getBounds, getShape<<1|1)
|
||||
MicroOcclusion.shrink(renderBounds2, post.getBounds, getShape<<1)
|
||||
}
|
||||
@@ -264,7 +256,7 @@ class PostMicroblock(shape$:Byte = 0, material$:Int = 0) extends Microblock(shap
|
||||
if(npart.getType.equals("mcr_face"))
|
||||
if(npart.asInstanceOf[CommonMicroblock].getSlot>>1 == getShape)
|
||||
return true
|
||||
|
||||
|
||||
return super.occlusionTest(npart)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@ import codechicken.multipart.TFacePart
|
||||
import codechicken.lib.vec.Vector3
|
||||
import codechicken.lib.vec.Rotation
|
||||
import codechicken.microblock.MicroMaterialRegistry.IMicroMaterial
|
||||
import codechicken.lib.lighting.LazyLightMatrix
|
||||
import Rotation._
|
||||
import Vector3._
|
||||
import codechicken.lib.lighting.LightMatrix
|
||||
|
||||
object FacePlacement extends PlacementProperties
|
||||
{
|
||||
@@ -58,15 +58,16 @@ object FaceMicroClass extends MicroblockClass
|
||||
class FaceMicroblockClient(shape$:Byte = 0, material$:Int = 0) extends FaceMicroblock(shape$, material$) with CommonMicroblockClient
|
||||
{
|
||||
def this(size:Int, shape:Int, material:Int) = this((size<<4|shape).toByte, material)
|
||||
|
||||
override def render(pos:Vector3, olm:LazyLightMatrix, mat:IMicroMaterial, c:Cuboid6, sideMask:Int)
|
||||
{
|
||||
if(isTransparent)
|
||||
renderCuboid(pos, olm, mat, c, sideMask)
|
||||
else
|
||||
{
|
||||
renderCuboid(pos, olm, mat, c, sideMask|1<<getSlot)
|
||||
renderCuboid(pos, olm, mat, new Cuboid6(0, 0, 0, 1, 1, 1), ~(1<<getSlot))
|
||||
|
||||
override def render(pos:Vector3, pass:Int) {
|
||||
if(pass < 0)
|
||||
MicroblockRender.renderCuboid(pos, getIMaterial, pass, getBounds, 0)
|
||||
else if(isTransparent)
|
||||
MicroblockRender.renderCuboid(pos, getIMaterial, pass, renderBounds, renderMask)
|
||||
else {
|
||||
val mat = getIMaterial
|
||||
MicroblockRender.renderCuboid(pos, mat, pass, renderBounds, renderMask | 1<<getSlot)
|
||||
MicroblockRender.renderCuboid(pos, mat, pass, Cuboid6.full, ~(1<<getSlot))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,5 +80,5 @@ class FaceMicroblock(shape$:Byte = 0, material$:Int = 0) extends CommonMicrobloc
|
||||
|
||||
def getBounds = FaceMicroClass.aBounds(shape)
|
||||
|
||||
override def solid(side:Int) = MicroMaterialRegistry.getMaterial(material).isSolid
|
||||
override def solid(side:Int) = getIMaterial.isSolid
|
||||
}
|
||||
@@ -1,24 +1,14 @@
|
||||
package codechicken.microblock
|
||||
|
||||
import codechicken.lib.vec.Vector3
|
||||
import codechicken.lib.vec.{Cuboid6, Vector3}
|
||||
import net.minecraft.block.Block
|
||||
import codechicken.lib.render.Vertex5
|
||||
import codechicken.lib.render.IconTransformation
|
||||
import codechicken.lib.render.{ColourMultiplier, CCRenderState}
|
||||
import net.minecraft.block.BlockGrass
|
||||
import codechicken.lib.render.IUVTransformation
|
||||
import codechicken.lib.render.UV
|
||||
import codechicken.lib.lighting.LightMatrix
|
||||
import net.minecraft.init.Blocks
|
||||
import codechicken.lib.render.uv.{UVTranslation, IconTransformation}
|
||||
import codechicken.lib.render.BlockRenderer.BlockFace
|
||||
|
||||
class TopIconTransformation(h:Double, uvt:IUVTransformation) extends IUVTransformation
|
||||
{
|
||||
def transform(uv:UV)
|
||||
{
|
||||
uv.v -= 1-h
|
||||
uvt.transform(uv)
|
||||
}
|
||||
}
|
||||
|
||||
class GrassMicroMaterial extends BlockMicroMaterial(Block.grass, 0)
|
||||
class GrassMicroMaterial extends BlockMicroMaterial(Blocks.grass, 0)
|
||||
{
|
||||
var sideIconT:IconTransformation = _
|
||||
|
||||
@@ -27,27 +17,32 @@ class GrassMicroMaterial extends BlockMicroMaterial(Block.grass, 0)
|
||||
super.loadIcons()
|
||||
sideIconT = new IconTransformation(BlockGrass.getIconSideOverlay)
|
||||
}
|
||||
|
||||
override def renderMicroFace(verts:Array[Vertex5], side:Int, pos:Vector3, lightMatrix:LightMatrix, part:IMicroMaterialRender)
|
||||
{
|
||||
val colour = getColour(part)
|
||||
if(side%6 == 1)
|
||||
renderMicroFace(verts, side, pos, lightMatrix, colour, icont)
|
||||
|
||||
override def renderMicroFace(pos:Vector3, pass:Int, bounds:Cuboid6) {
|
||||
val face = CCRenderState.model.asInstanceOf[BlockFace]
|
||||
if(pass != -1)
|
||||
face.computeLightCoords()
|
||||
|
||||
if(face.side == 1)
|
||||
MaterialRenderHelper.start(pos, pass, icont).blockColour(getColour(pass)).lighting().render()
|
||||
else
|
||||
renderMicroFace(verts, side, pos, lightMatrix, -1, icont)
|
||||
|
||||
if(side%6 > 1 && side%6 < 6)
|
||||
renderMicroFace(verts, side, pos, lightMatrix, colour, new TopIconTransformation(part.getRenderBounds.max.y, sideIconT))
|
||||
MaterialRenderHelper.start(pos, pass, icont).lighting().render()
|
||||
|
||||
if(face.side > 1)
|
||||
MaterialRenderHelper.start(pos, pass, new UVTranslation(0, bounds.max.y-1) ++ sideIconT)
|
||||
.blockColour(getColour(pass)).lighting().render()
|
||||
}
|
||||
}
|
||||
|
||||
class TopMicroMaterial($block:Block, $meta:Int = 0) extends BlockMicroMaterial($block, $meta)
|
||||
{
|
||||
override def renderMicroFace(verts:Array[Vertex5], side:Int, pos:Vector3, lightMatrix:LightMatrix, part:IMicroMaterialRender)
|
||||
override def renderMicroFace(pos:Vector3, pass:Int, bounds:Cuboid6)
|
||||
{
|
||||
if(side%6 > 1 && side%6 < 6)
|
||||
renderMicroFace(verts, side, pos, lightMatrix, getColour(part), new TopIconTransformation(part.getRenderBounds.max.y, icont))
|
||||
val face = CCRenderState.model.asInstanceOf[BlockFace]
|
||||
if(face.side <= 1)
|
||||
MaterialRenderHelper.start(pos, pass, icont).blockColour(getColour(pass)).lighting().render()
|
||||
else
|
||||
super.renderMicroFace(verts, side, pos, lightMatrix, part)
|
||||
MaterialRenderHelper.start(pos, pass, new UVTranslation(0, bounds.max.y-1) ++ icont)
|
||||
.blockColour(getColour(pass)).lighting().render()
|
||||
}
|
||||
}
|
||||
@@ -3,173 +3,161 @@ package codechicken.microblock
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.util.MovingObjectPosition
|
||||
import codechicken.multipart.TFacePart
|
||||
import codechicken.lib.vec.Cuboid6
|
||||
import codechicken.lib.vec.Rotation
|
||||
import codechicken.lib.vec.Vector3
|
||||
import codechicken.lib.vec.{Translation, Cuboid6, Rotation, Vector3}
|
||||
import codechicken.multipart.TNormalOcclusion
|
||||
import codechicken.lib.lighting.LazyLightMatrix
|
||||
import codechicken.microblock.MicroMaterialRegistry.IMicroMaterial
|
||||
import net.minecraft.client.renderer.RenderBlocks
|
||||
import codechicken.lib.render.IconTransformation
|
||||
import codechicken.lib.render.RenderUtils
|
||||
import codechicken.lib.render.CCRenderState
|
||||
import codechicken.lib.render.{BlockRenderer, RenderUtils, CCRenderState}
|
||||
import scala.collection.JavaConversions._
|
||||
import Rotation._
|
||||
import Vector3._
|
||||
import codechicken.lib.raytracer.IndexedCuboid6
|
||||
import org.lwjgl.opengl.GL11
|
||||
import codechicken.lib.render.uv.IconTransformation
|
||||
import codechicken.lib.lighting.LightMatrix
|
||||
|
||||
object HollowPlacement extends PlacementProperties
|
||||
{
|
||||
object HollowPlacementGrid extends FaceEdgeGrid(3/8D)
|
||||
|
||||
|
||||
object HollowPlacementGrid extends FaceEdgeGrid(3 / 8D)
|
||||
|
||||
def microClass = HollowMicroClass
|
||||
|
||||
|
||||
def placementGrid = HollowPlacementGrid
|
||||
|
||||
def opposite(slot:Int, side:Int) = slot^1
|
||||
|
||||
override def expand(slot:Int, side:Int) = sneakOpposite(slot, side)
|
||||
|
||||
override def sneakOpposite(slot:Int, side:Int) = slot == (side^1)
|
||||
|
||||
def opposite(slot: Int, side: Int) = slot ^ 1
|
||||
|
||||
override def expand(slot: Int, side: Int) = sneakOpposite(slot, side)
|
||||
|
||||
override def sneakOpposite(slot: Int, side: Int) = slot == (side ^ 1)
|
||||
}
|
||||
|
||||
object HollowMicroClass extends MicroblockClass
|
||||
{
|
||||
var pBoxes:Array[Seq[Cuboid6]] = new Array(256)
|
||||
var occBounds:Array[Cuboid6] = new Array(256)
|
||||
for(s <- 0 until 6)
|
||||
{
|
||||
var pBoxes: Array[Seq[Cuboid6]] = new Array(256)
|
||||
var occBounds: Array[Cuboid6] = new Array(256)
|
||||
for (s <- 0 until 6) {
|
||||
val transform = sideRotations(s).at(center)
|
||||
for(t <- 1 until 8)
|
||||
{
|
||||
val d = t/8D
|
||||
val w1 = 1/8D
|
||||
val w2 = 3/16D
|
||||
pBoxes(t<<4|s) = Seq(
|
||||
for (t <- 1 until 8) {
|
||||
val d = t / 8D
|
||||
val w1 = 1 / 8D
|
||||
val w2 = 3 / 16D
|
||||
pBoxes(t << 4 | s) = Seq(
|
||||
new Cuboid6(0, 0, 0, w1, d, 1),
|
||||
new Cuboid6(1-w1, 0, 0, 1, d, 1),
|
||||
new Cuboid6(w1, 0, 0, 1-w1, d, w1),
|
||||
new Cuboid6(w1, 0, 1-w1, 1-w1, d, 1))
|
||||
new Cuboid6(1 - w1, 0, 0, 1, d, 1),
|
||||
new Cuboid6(w1, 0, 0, 1 - w1, d, w1),
|
||||
new Cuboid6(w1, 0, 1 - w1, 1 - w1, d, 1))
|
||||
.map(_.apply(transform))
|
||||
occBounds(t<<4|s) = new Cuboid6(1/8D, 0, 1/8D, 7/8D, d, 7/8D).apply(transform)
|
||||
occBounds(t << 4 | s) = new Cuboid6(1 / 8D, 0, 1 / 8D, 7 / 8D, d, 7 / 8D).apply(transform)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def getName = "mcr_hllw"
|
||||
|
||||
def create(client:Boolean) =
|
||||
if(client)
|
||||
|
||||
def create(client: Boolean) =
|
||||
if (client)
|
||||
new HollowMicroblockClient
|
||||
else
|
||||
new HollowMicroblock
|
||||
|
||||
def create(size:Int, slot:Int, material:Int, client:Boolean) =
|
||||
if(client)
|
||||
|
||||
def create(size: Int, slot: Int, material: Int, client: Boolean) =
|
||||
if (client)
|
||||
new HollowMicroblockClient(size, slot, material)
|
||||
else
|
||||
new HollowMicroblock(size, slot, material)
|
||||
|
||||
|
||||
def placementProperties = HollowPlacement
|
||||
|
||||
def getResistanceFactor = 1
|
||||
}
|
||||
|
||||
class HollowMicroblockClient(shape$:Byte = 0, material$:Int = 0) extends HollowMicroblock(shape$, material$) with CommonMicroblockClient
|
||||
class HollowMicroblockClient(shape$: Byte = 0, material$: Int = 0) extends HollowMicroblock(shape$, material$) with CommonMicroblockClient
|
||||
{
|
||||
renderMask |= 8<<8
|
||||
|
||||
def this(size:Int, shape:Int, material:Int) = this((size<<4|shape).toByte, material)
|
||||
|
||||
override def recalcBounds()
|
||||
{
|
||||
renderMask |= 8 << 8
|
||||
|
||||
def this(size: Int, shape: Int, material: Int) = this((size << 4 | shape).toByte, material)
|
||||
|
||||
override def recalcBounds() {
|
||||
super.recalcBounds()
|
||||
renderMask = renderMask&0xFF | getHollowSize<<8
|
||||
renderMask = renderMask & 0xFF | getHollowSize << 8
|
||||
}
|
||||
|
||||
override def drawBreaking(renderBlocks:RenderBlocks)
|
||||
{
|
||||
|
||||
override def drawBreaking(renderBlocks: RenderBlocks) {
|
||||
CCRenderState.reset()
|
||||
val icont = new IconTransformation(renderBlocks.overrideBlockTexture)
|
||||
renderHollow(Vector3.fromTileEntity(tile), null, null, getBounds, 0, false,
|
||||
(pos:Vector3, olm:LazyLightMatrix, mat:IMicroMaterial, c:Cuboid6, sideMask:Int)=>
|
||||
RenderUtils.renderBlock(c, sideMask, pos.translation(), icont, null))
|
||||
CCRenderState.setPipeline(new Translation(x, y, z), new IconTransformation(renderBlocks.overrideBlockTexture))
|
||||
renderHollow(null, 0, getBounds, 0, false,
|
||||
(pos: Vector3, mat: IMicroMaterial, pass: Int, c: Cuboid6, sideMask: Int) =>
|
||||
BlockRenderer.renderCuboid(c, sideMask))
|
||||
}
|
||||
|
||||
override def render(pos:Vector3, olm:LazyLightMatrix, mat:IMicroMaterial, c:Cuboid6, sideMask:Int)
|
||||
{
|
||||
if(isTransparent)
|
||||
renderHollow(pos, olm, mat, c, sideMask, false, renderCuboid)
|
||||
else
|
||||
{
|
||||
renderHollow(pos, olm, mat, c, sideMask|1<<getSlot, false, renderCuboid)
|
||||
renderHollow(pos, olm, mat, Cuboid6.full, sideMask, true, renderCuboid)
|
||||
|
||||
override def render(pos: Vector3, pass: Int) {
|
||||
if (pass == -1)
|
||||
renderHollow(pos, pass, getBounds, 0, false, MicroblockRender.renderCuboid)
|
||||
else if (isTransparent)
|
||||
renderHollow(pos, pass, renderBounds, renderMask, false, MicroblockRender.renderCuboid)
|
||||
else {
|
||||
renderHollow(pos, pass, renderBounds, renderMask | 1 << getSlot, false, MicroblockRender.renderCuboid)
|
||||
renderHollow(pos, pass, Cuboid6.full, ~(1 << getSlot), true, MicroblockRender.renderCuboid)
|
||||
}
|
||||
}
|
||||
|
||||
def renderHollow(pos:Vector3, olm:LazyLightMatrix, mat:IMicroMaterial, c:Cuboid6, sideMask:Int, face:Boolean,
|
||||
f:(Vector3, LazyLightMatrix, IMicroMaterial, Cuboid6, Int)=>Unit)
|
||||
{
|
||||
|
||||
def renderHollow(pos: Vector3, pass: Int, c: Cuboid6, sideMask: Int, face: Boolean,
|
||||
f: (Vector3, IMicroMaterial, Int, Cuboid6, Int) => Unit) {
|
||||
val mat = getIMaterial
|
||||
val size = renderMask >> 8
|
||||
val d1 = 0.5-size/32D
|
||||
val d2 = 0.5+size/32D
|
||||
val d1 = 0.5 - size / 32D
|
||||
val d2 = 0.5 + size / 32D
|
||||
val x1 = c.min.x
|
||||
val x2 = c.max.x
|
||||
val y1 = c.min.y
|
||||
val y2 = c.max.y
|
||||
val z1 = c.min.z
|
||||
val z2 = c.max.z
|
||||
|
||||
var faceMask = sideMask
|
||||
|
||||
var iMask = 0
|
||||
if(face)
|
||||
faceMask = ~(1<<getSlot)
|
||||
|
||||
getSlot match
|
||||
{
|
||||
case 0 | 1 =>
|
||||
if(face)
|
||||
getSlot match {
|
||||
case 0 | 1 =>
|
||||
if (face)
|
||||
iMask = 0x3C
|
||||
f(pos, olm, mat, new Cuboid6(d1, y1, d2, d2, y2, z2), 0x3B|iMask)//-z internal
|
||||
f(pos, olm, mat, new Cuboid6(d1, y1, z1, d2, y2, d1), 0x37|iMask)//+z internal
|
||||
f(pos, mat, pass, new Cuboid6(d1, y1, d2, d2, y2, z2), 0x3B | iMask) //-z internal
|
||||
f(pos, mat, pass, new Cuboid6(d1, y1, z1, d2, y2, d1), 0x37 | iMask) //+z internal
|
||||
|
||||
f(pos, olm, mat, new Cuboid6(d2, y1, d1, x2, y2, d2), faceMask&0x23|0xC|iMask)//-x internal -y+y+x external
|
||||
f(pos, olm, mat, new Cuboid6(x1, y1, d1, d1, y2, d2), faceMask&0x13|0xC|iMask)//+x internal -y+y-x external
|
||||
f(pos, mat, pass, new Cuboid6(d2, y1, d1, x2, y2, d2), sideMask & 0x23 | 0xC | iMask) //-x internal -y+y+x external
|
||||
f(pos, mat, pass, new Cuboid6(x1, y1, d1, d1, y2, d2), sideMask & 0x13 | 0xC | iMask) //+x internal -y+y-x external
|
||||
|
||||
f(pos, olm, mat, new Cuboid6(x1, y1, d2, x2, y2, z2), faceMask&0x3B|4|iMask)//-y+y+z-x+x external
|
||||
f(pos, olm, mat, new Cuboid6(x1, y1, z1, x2, y2, d1), faceMask&0x37|8|iMask)//-y+y-z-x+x external
|
||||
f(pos, mat, pass, new Cuboid6(x1, y1, d2, x2, y2, z2), sideMask & 0x3B | 4 | iMask) //-y+y+z-x+x external
|
||||
f(pos, mat, pass, new Cuboid6(x1, y1, z1, x2, y2, d1), sideMask & 0x37 | 8 | iMask) //-y+y-z-x+x external
|
||||
case 2 | 3 =>
|
||||
if(face)
|
||||
if (face)
|
||||
iMask = 0x33
|
||||
f(pos, olm, mat, new Cuboid6(d2, d1, z1, x2, d2, z2), 0x2F|iMask)//-x internal
|
||||
f(pos, olm, mat, new Cuboid6(x1, d1, z1, d1, d2, z2), 0x1F|iMask)//+x internal
|
||||
|
||||
f(pos, olm, mat, new Cuboid6(d1, d2, z1, d2, y2, z2), faceMask&0xE|0x30|iMask)//-y internal -z+z+y external
|
||||
f(pos, olm, mat, new Cuboid6(d1, y1, z1, d2, d1, z2), faceMask&0xD|0x30|iMask)//+y internal -z+z-y external
|
||||
|
||||
f(pos, olm, mat, new Cuboid6(d2, y1, z1, x2, y2, z2), faceMask&0x2F|0x10|iMask)//-z+z+x-y+y external
|
||||
f(pos, olm, mat, new Cuboid6(x1, y1, z1, d1, y2, z2), faceMask&0x1F|0x20|iMask)//-z+z-x-y+y external
|
||||
f(pos, mat, pass, new Cuboid6(d2, d1, z1, x2, d2, z2), 0x2F | iMask) //-x internal
|
||||
f(pos, mat, pass, new Cuboid6(x1, d1, z1, d1, d2, z2), 0x1F | iMask) //+x internal
|
||||
|
||||
f(pos, mat, pass, new Cuboid6(d1, d2, z1, d2, y2, z2), sideMask & 0xE | 0x30 | iMask) //-y internal -z+z+y external
|
||||
f(pos, mat, pass, new Cuboid6(d1, y1, z1, d2, d1, z2), sideMask & 0xD | 0x30 | iMask) //+y internal -z+z-y external
|
||||
|
||||
f(pos, mat, pass, new Cuboid6(d2, y1, z1, x2, y2, z2), sideMask & 0x2F | 0x10 | iMask) //-z+z+x-y+y external
|
||||
f(pos, mat, pass, new Cuboid6(x1, y1, z1, d1, y2, z2), sideMask & 0x1F | 0x20 | iMask) //-z+z-x-y+y external
|
||||
case 4 | 5 =>
|
||||
if(face)
|
||||
if (face)
|
||||
iMask = 0xF
|
||||
f(pos, olm, mat, new Cuboid6(x1, d2, d1, x2, y2, d2), 0x3E|iMask)//-y internal
|
||||
f(pos, olm, mat, new Cuboid6(x1, y1, d1, x2, d1, d2), 0x3D|iMask)//+y internal
|
||||
|
||||
f(pos, olm, mat, new Cuboid6(x1, d1, d2, x2, d2, z2), faceMask&0x38|3|iMask)//-z internal -x+x+z external
|
||||
f(pos, olm, mat, new Cuboid6(x1, d1, z1, x2, d2, d1), faceMask&0x34|3|iMask)//+z internal -x+x-z external
|
||||
|
||||
f(pos, olm, mat, new Cuboid6(x1, d2, z1, x2, y2, z2), faceMask&0x3E|1|iMask)//-x+x+y-z+z external
|
||||
f(pos, olm, mat, new Cuboid6(x1, y1, z1, x2, d1, z2), faceMask&0x3D|2|iMask)//-x+x-y-z+z external
|
||||
f(pos, mat, pass, new Cuboid6(x1, d2, d1, x2, y2, d2), 0x3E | iMask) //-y internal
|
||||
f(pos, mat, pass, new Cuboid6(x1, y1, d1, x2, d1, d2), 0x3D | iMask) //+y internal
|
||||
|
||||
f(pos, mat, pass, new Cuboid6(x1, d1, d2, x2, d2, z2), sideMask & 0x38 | 3 | iMask) //-z internal -x+x+z external
|
||||
f(pos, mat, pass, new Cuboid6(x1, d1, z1, x2, d2, d1), sideMask & 0x34 | 3 | iMask) //+z internal -x+x-z external
|
||||
|
||||
f(pos, mat, pass, new Cuboid6(x1, d2, z1, x2, y2, z2), sideMask & 0x3E | 1 | iMask) //-x+x+y-z+z external
|
||||
f(pos, mat, pass, new Cuboid6(x1, y1, z1, x2, d1, z2), sideMask & 0x3D | 2 | iMask) //-x+x-y-z+z external
|
||||
}
|
||||
}
|
||||
|
||||
override def drawHighlight(hit:MovingObjectPosition, player:EntityPlayer, frame:Float):Boolean =
|
||||
{
|
||||
|
||||
override def drawHighlight(hit: MovingObjectPosition, player: EntityPlayer, frame: Float): Boolean = {
|
||||
val size = getHollowSize
|
||||
val d1 = 0.5-size/32D
|
||||
val d2 = 0.5+size/32D
|
||||
val t = (shape>>4)/8D
|
||||
|
||||
val d1 = 0.5 - size / 32D
|
||||
val d2 = 0.5 + size / 32D
|
||||
val t = (shape >> 4) / 8D
|
||||
|
||||
import GL11._
|
||||
glEnable(GL_BLEND)
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
|
||||
@@ -178,12 +166,12 @@ class HollowMicroblockClient(shape$:Byte = 0, material$:Int = 0) extends HollowM
|
||||
glLineWidth(2)
|
||||
glDepthMask(false)
|
||||
glPushMatrix()
|
||||
RenderUtils.translateToWorldCoords(player, frame)
|
||||
glTranslated(x, y, z)
|
||||
sideRotations(shape&0xF).at(center).glApply()
|
||||
|
||||
RenderUtils.drawCuboidOutline(new Cuboid6(0, 0, 0, 1, t, 1).expand(0.001))
|
||||
RenderUtils.drawCuboidOutline(new Cuboid6(d1, 0, d1, d2, t, d2).expand(-0.001))
|
||||
RenderUtils.translateToWorldCoords(player, frame)
|
||||
glTranslated(x, y, z)
|
||||
sideRotations(shape & 0xF).at(center).glApply()
|
||||
|
||||
RenderUtils.drawCuboidOutline(new Cuboid6(0, 0, 0, 1, t, 1).expand(0.001))
|
||||
RenderUtils.drawCuboidOutline(new Cuboid6(d1, 0, d1, d2, t, d2).expand(-0.001))
|
||||
glPopMatrix()
|
||||
glDepthMask(true)
|
||||
glEnable(GL_TEXTURE_2D)
|
||||
@@ -192,80 +180,74 @@ class HollowMicroblockClient(shape$:Byte = 0, material$:Int = 0) extends HollowM
|
||||
}
|
||||
}
|
||||
|
||||
class HollowMicroblock(shape$:Byte = 0, material$:Int = 0) extends CommonMicroblock(shape$, material$) with TFacePart with TNormalOcclusion
|
||||
class HollowMicroblock(shape$: Byte = 0, material$: Int = 0) extends CommonMicroblock(shape$, material$) with TFacePart with TNormalOcclusion
|
||||
{
|
||||
def this(size:Int, shape:Int, material:Int) = this((size<<4|shape).toByte, material)
|
||||
def this(size: Int, shape: Int, material: Int) = this((size << 4 | shape).toByte, material)
|
||||
|
||||
def microClass = HollowMicroClass
|
||||
|
||||
def getBounds:Cuboid6 = FaceMicroClass.aBounds(shape)
|
||||
|
||||
|
||||
def getBounds: Cuboid6 = FaceMicroClass.aBounds(shape)
|
||||
|
||||
override def getPartialOcclusionBoxes = HollowMicroClass.pBoxes(shape)
|
||||
|
||||
def getHollowSize = tile match
|
||||
{
|
||||
|
||||
def getHollowSize = tile match {
|
||||
case null => 8
|
||||
case _ => tile.partMap(6) match
|
||||
{
|
||||
case part:IHollowConnect => part.getHollowSize
|
||||
case part:ISidedHollowConnect => part.getHollowSize(getSlot)
|
||||
case _ => tile.partMap(6) match {
|
||||
case part: ISidedHollowConnect => part.getHollowSize(getSlot)
|
||||
case _ => 8
|
||||
}
|
||||
}
|
||||
|
||||
def getOcclusionBoxes =
|
||||
{
|
||||
|
||||
def getOcclusionBoxes = {
|
||||
val size = getHollowSize
|
||||
val c = HollowMicroClass.occBounds(shape)
|
||||
val d1 = 0.5-size/32D
|
||||
val d2 = 0.5+size/32D
|
||||
val d1 = 0.5 - size / 32D
|
||||
val d2 = 0.5 + size / 32D
|
||||
val x1 = c.min.x
|
||||
val x2 = c.max.x
|
||||
val y1 = c.min.y
|
||||
val y2 = c.max.y
|
||||
val z1 = c.min.z
|
||||
val z2 = c.max.z
|
||||
|
||||
getSlot match
|
||||
{
|
||||
case 0 | 1 =>
|
||||
|
||||
getSlot match {
|
||||
case 0 | 1 =>
|
||||
Seq(new Cuboid6(d2, y1, d1, x2, y2, d2),
|
||||
new Cuboid6(x1, y1, d1, d1, y2, d2),
|
||||
new Cuboid6(x1, y1, d2, x2, y2, z2),
|
||||
new Cuboid6(x1, y1, z1, x2, y2, d1))
|
||||
new Cuboid6(x1, y1, d1, d1, y2, d2),
|
||||
new Cuboid6(x1, y1, d2, x2, y2, z2),
|
||||
new Cuboid6(x1, y1, z1, x2, y2, d1))
|
||||
case 2 | 3 =>
|
||||
Seq(new Cuboid6(d1, d2, z1, d2, y2, z2),
|
||||
new Cuboid6(d1, y1, z1, d2, d1, z2),
|
||||
new Cuboid6(d2, y1, z1, x2, y2, z2),
|
||||
new Cuboid6(x1, y1, z1, d1, y2, z2))
|
||||
new Cuboid6(d1, y1, z1, d2, d1, z2),
|
||||
new Cuboid6(d2, y1, z1, x2, y2, z2),
|
||||
new Cuboid6(x1, y1, z1, d1, y2, z2))
|
||||
case 4 | 5 =>
|
||||
Seq(new Cuboid6(x1, d1, d2, x2, d2, z2),
|
||||
new Cuboid6(x1, d1, z1, x2, d2, d1),
|
||||
new Cuboid6(x1, d2, z1, x2, y2, z2),
|
||||
new Cuboid6(x1, y1, z1, x2, d1, z2))
|
||||
new Cuboid6(x1, d1, z1, x2, d2, d1),
|
||||
new Cuboid6(x1, d2, z1, x2, y2, z2),
|
||||
new Cuboid6(x1, y1, z1, x2, d1, z2))
|
||||
}
|
||||
}
|
||||
|
||||
override def getCollisionBoxes =
|
||||
{
|
||||
|
||||
override def getCollisionBoxes = {
|
||||
val size = getHollowSize
|
||||
val d1 = 0.5-size/32D
|
||||
val d2 = 0.5+size/32D
|
||||
val t = (shape>>4)/8D
|
||||
|
||||
val tr = sideRotations(shape&0xF).at(center)
|
||||
val d1 = 0.5 - size / 32D
|
||||
val d2 = 0.5 + size / 32D
|
||||
val t = (shape >> 4) / 8D
|
||||
|
||||
val tr = sideRotations(shape & 0xF).at(center)
|
||||
Seq(new Cuboid6(0, 0, 0, 1, t, d1),
|
||||
new Cuboid6(0, 0, d2, 1, t, 1),
|
||||
new Cuboid6(0, 0, d1, d1, t, d2),
|
||||
new Cuboid6(d2, 0, d1, 1, t, d2))
|
||||
.map(c => c.apply(tr))
|
||||
}
|
||||
|
||||
|
||||
override def getSubParts = getCollisionBoxes.map(c => new IndexedCuboid6(0, c))
|
||||
|
||||
|
||||
override def allowCompleteOcclusion = true
|
||||
|
||||
override def solid(side:Int) = false
|
||||
|
||||
|
||||
override def solid(side: Int) = false
|
||||
|
||||
override def redstoneConductionMap = 0x10
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package codechicken.microblock
|
||||
|
||||
/**
|
||||
* Implement this on center parts that connect through hollow covers to have the covers render their hollows to fit the connection size
|
||||
*/
|
||||
trait IHollowConnect
|
||||
{
|
||||
/**
|
||||
* @return The size (width and height) of the connection in pixels. Must be be less than 12 and more than 0
|
||||
*/
|
||||
def getHollowSize:Int
|
||||
}
|
||||
@@ -2,8 +2,6 @@ package codechicken.microblock
|
||||
|
||||
/**
|
||||
* Implement this on center parts that connect through hollow covers to have the covers render their hollows to fit the connection size
|
||||
*
|
||||
* Will replace IHollowConnect as of 1.7
|
||||
*/
|
||||
trait ISidedHollowConnect
|
||||
{
|
||||
|
||||
@@ -13,22 +13,22 @@ import java.util.List
|
||||
import net.minecraft.creativetab.CreativeTabs
|
||||
import codechicken.microblock.MicroblockClassRegistry._
|
||||
import codechicken.lib.render.CCRenderState
|
||||
import net.minecraft.client.renderer.texture.IconRegister
|
||||
import net.minecraft.client.renderer.texture.IIconRegister
|
||||
import codechicken.microblock.handler.MicroblockProxy
|
||||
import net.minecraft.util.MovingObjectPosition
|
||||
import net.minecraft.util.{StatCollector, MovingObjectPosition}
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.world.World
|
||||
import codechicken.lib.raytracer.RayTracer
|
||||
import net.minecraft.util.EnumMovingObjectType
|
||||
import codechicken.lib.vec.Vector3
|
||||
import codechicken.lib.render.TextureUtils
|
||||
import codechicken.lib.lang.LangUtil
|
||||
import net.minecraft.util.MovingObjectPosition.MovingObjectType
|
||||
|
||||
class ItemMicroPart(id:Int) extends Item(id)
|
||||
class ItemMicroPart extends Item
|
||||
{
|
||||
setUnlocalizedName("microblock")
|
||||
setHasSubtypes(true)
|
||||
|
||||
override def getItemDisplayName(stack:ItemStack):String =
|
||||
override def getItemStackDisplayName(stack:ItemStack):String =
|
||||
{
|
||||
val material = getMaterial(stack)
|
||||
val mcrClass = MicroblockClassRegistry.getMicroClass(stack.getItemDamage)
|
||||
@@ -36,10 +36,10 @@ class ItemMicroPart(id:Int) extends Item(id)
|
||||
if(material == null || mcrClass == null)
|
||||
return "Unnamed"
|
||||
|
||||
return LangUtil.translateG(mcrClass.getName+"."+size+".name", material.getLocalizedName)
|
||||
return StatCollector.translateToLocalFormatted(mcrClass.getName+"."+size+".name", material.getLocalizedName)
|
||||
}
|
||||
|
||||
override def getSubItems(id:Int, tab:CreativeTabs, list$:List[_])
|
||||
override def getSubItems(item:Item, tab:CreativeTabs, list$:List[_])
|
||||
{
|
||||
val list = list$.asInstanceOf[List[ItemStack]]
|
||||
for(classId <- 0 until classes.length)
|
||||
@@ -51,7 +51,7 @@ class ItemMicroPart(id:Int) extends Item(id)
|
||||
}
|
||||
}
|
||||
|
||||
override def registerIcons(register:IconRegister){}
|
||||
override def registerIcons(register:IIconRegister){}
|
||||
|
||||
override def onItemUse(item:ItemStack, player:EntityPlayer, world:World, x:Int, y:Int, z:Int, s:Int, hitX:Float, hitY:Float, hitZ:Float):Boolean =
|
||||
{
|
||||
@@ -62,9 +62,9 @@ class ItemMicroPart(id:Int) extends Item(id)
|
||||
return false
|
||||
|
||||
val hit = RayTracer.retraceBlock(world, player, x, y, z)
|
||||
if(hit != null && hit.typeOfHit == EnumMovingObjectType.TILE)
|
||||
if(hit != null && hit.typeOfHit == MovingObjectType.BLOCK)
|
||||
{
|
||||
val placement = MicroblockPlacement(world, player, hit, size, material, !player.capabilities.isCreativeMode, mcrClass.placementProperties)
|
||||
val placement = MicroblockPlacement(player, hit, size, material, !player.capabilities.isCreativeMode, mcrClass.placementProperties)
|
||||
if(placement == null)
|
||||
return false
|
||||
|
||||
@@ -76,7 +76,7 @@ class ItemMicroPart(id:Int) extends Item(id)
|
||||
|
||||
val sound = MicroMaterialRegistry.getMaterial(material).getSound
|
||||
if(sound != null)
|
||||
world.playSoundEffect(placement.pos.x + 0.5D, placement.pos.y + 0.5D, placement.pos.z + 0.5D, sound.getPlaceSound, (sound.getVolume + 1.0F) / 2.0F, sound.getPitch * 0.8F)
|
||||
world.playSoundEffect(placement.pos.x + 0.5D, placement.pos.y + 0.5D, placement.pos.z + 0.5D, sound.func_150496_b, (sound.getVolume + 1.0F) / 2.0F, sound.getPitch * 0.8F)
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -91,7 +91,7 @@ object ItemMicroPart
|
||||
def checkTagCompound(stack:ItemStack)
|
||||
{
|
||||
if(!stack.hasTagCompound)
|
||||
stack.setTagCompound(new NBTTagCompound("tag"))
|
||||
stack.setTagCompound(new NBTTagCompound())
|
||||
}
|
||||
|
||||
def create(damage:Int, material:Int):ItemStack = create(damage, MicroMaterialRegistry.materialName(material))
|
||||
@@ -144,20 +144,19 @@ object ItemMicroPartRenderer extends IItemRenderer
|
||||
GL11.glScaled(0.5, 0.5, 0.5)
|
||||
if(t == ItemRenderType.INVENTORY || t == ItemRenderType.ENTITY)
|
||||
GL11.glTranslatef(-0.5F, -0.5F, -0.5F)
|
||||
|
||||
CCRenderState.reset()
|
||||
|
||||
TextureUtils.bindAtlas(0)
|
||||
CCRenderState.useNormals(true)
|
||||
CCRenderState.useModelColours(true)
|
||||
CCRenderState.reset()
|
||||
CCRenderState.useNormals = true
|
||||
CCRenderState.pullLightmap()
|
||||
CCRenderState.startDrawing(7)
|
||||
val part = mcrClass.create(size, mcrClass.itemSlot, 0, true).asInstanceOf[MicroblockClient]
|
||||
part.render(new Vector3(0.5, 0.5, 0.5).subtract(part.getBounds.center), null, material, part.getBounds, 0)
|
||||
CCRenderState.startDrawing()
|
||||
val part = mcrClass.create(size, mcrClass.itemSlot, getMaterialID(item), true).asInstanceOf[MicroblockClient]
|
||||
part.render(new Vector3(0.5, 0.5, 0.5).subtract(part.getBounds.center), -1)
|
||||
CCRenderState.draw()
|
||||
GL11.glPopMatrix()
|
||||
}
|
||||
|
||||
def renderHighlight(world:World, player:EntityPlayer, stack:ItemStack, hit:MovingObjectPosition):Boolean =
|
||||
def renderHighlight(player:EntityPlayer, stack:ItemStack, hit:MovingObjectPosition):Boolean =
|
||||
{
|
||||
val material = getMaterialID(stack)
|
||||
val mcrClass = MicroblockClassRegistry.getMicroClass(stack.getItemDamage)
|
||||
@@ -165,6 +164,6 @@ object ItemMicroPartRenderer extends IItemRenderer
|
||||
if(material < 0 || mcrClass == null)
|
||||
return false
|
||||
|
||||
return MicroMaterialRegistry.renderHighlight(world, player, hit, mcrClass, size, material)
|
||||
return MicroMaterialRegistry.renderHighlight(player, hit, mcrClass, size, material)
|
||||
}
|
||||
}
|
||||
@@ -15,11 +15,11 @@ import codechicken.lib.vec.Translation
|
||||
import codechicken.lib.vec.Scale
|
||||
import codechicken.lib.vec.Rotation
|
||||
import org.lwjgl.opengl.GL11
|
||||
import codechicken.lib.render.UVTranslation
|
||||
import ItemRenderType._
|
||||
import codechicken.lib.math.MathHelper._
|
||||
import net.minecraft.util.ResourceLocation
|
||||
import net.minecraft.client.renderer.texture.IconRegister
|
||||
import net.minecraft.client.renderer.texture.IIconRegister
|
||||
import codechicken.lib.render.uv.UVTranslation
|
||||
|
||||
/**
|
||||
* Interface for items that are 'saws'
|
||||
@@ -36,7 +36,7 @@ trait Saw extends Item
|
||||
def getCuttingStrength(item:ItemStack):Int
|
||||
}
|
||||
|
||||
class ItemSaw(sawTag:ConfigTag, val harvestLevel:Int) extends Item(sawTag.getTag("id").getIntValue(nextItemID)) with Saw
|
||||
class ItemSaw(sawTag:ConfigTag, val harvestLevel:Int) extends Item with Saw
|
||||
{
|
||||
{
|
||||
val maxDamage = sawTag.getTag("durability").getIntValue(1<<harvestLevel+8)
|
||||
@@ -47,9 +47,9 @@ class ItemSaw(sawTag:ConfigTag, val harvestLevel:Int) extends Item(sawTag.getTag
|
||||
|
||||
override def hasContainerItem = true
|
||||
|
||||
override def getContainerItemStack(stack:ItemStack) =
|
||||
override def getContainerItem(stack:ItemStack) =
|
||||
if(isDamageable)
|
||||
new ItemStack(stack.itemID, 1, stack.getItemDamage+1)
|
||||
new ItemStack(stack.getItem, 1, stack.getItemDamage+1)
|
||||
else
|
||||
stack
|
||||
|
||||
@@ -57,7 +57,7 @@ class ItemSaw(sawTag:ConfigTag, val harvestLevel:Int) extends Item(sawTag.getTag
|
||||
|
||||
def getCuttingStrength(item:ItemStack) = harvestLevel
|
||||
|
||||
override def registerIcons(register:IconRegister){}
|
||||
override def registerIcons(register:IIconRegister){}
|
||||
}
|
||||
|
||||
object ItemSawRenderer extends IItemRenderer
|
||||
@@ -82,16 +82,15 @@ object ItemSawRenderer extends IItemRenderer
|
||||
}
|
||||
|
||||
CCRenderState.reset()
|
||||
CCRenderState.useNormals(true)
|
||||
CCRenderState.useNormals = true
|
||||
CCRenderState.pullLightmap()
|
||||
CCRenderState.changeTexture("microblock:textures/items/saw.png")
|
||||
CCRenderState.setColour(0xFFFFFFFF)
|
||||
CCRenderState.startDrawing(7)
|
||||
handle.render(t, null)
|
||||
holder.render(t, null)
|
||||
CCRenderState.startDrawing()
|
||||
handle.render(t)
|
||||
holder.render(t)
|
||||
CCRenderState.draw()
|
||||
GL11.glDisable(GL11.GL_CULL_FACE)
|
||||
CCRenderState.startDrawing(7)
|
||||
CCRenderState.startDrawing()
|
||||
blade.render(t, new UVTranslation(0, (item.getItem.asInstanceOf[Saw].getCuttingStrength(item)-1)*4/64D))
|
||||
CCRenderState.draw()
|
||||
GL11.glEnable(GL11.GL_CULL_FACE)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package codechicken.microblock
|
||||
|
||||
import codechicken.multipart.IDWriter
|
||||
import codechicken.lib.lighting.LightMatrix
|
||||
import codechicken.lib.packet.PacketCustom
|
||||
import scala.collection.mutable.HashMap
|
||||
import codechicken.lib.data.MCDataOutput
|
||||
@@ -9,19 +8,20 @@ import codechicken.lib.data.MCDataInput
|
||||
import codechicken.multipart.MultiPartRegistry
|
||||
import cpw.mods.fml.relauncher.SideOnly
|
||||
import cpw.mods.fml.relauncher.Side
|
||||
import codechicken.lib.vec.Vector3
|
||||
import net.minecraft.util.Icon
|
||||
import codechicken.lib.vec.{Cuboid6, Vector3}
|
||||
import net.minecraft.util.IIcon
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import codechicken.lib.render.Vertex5
|
||||
import net.minecraft.item.{Item, ItemStack}
|
||||
import scala.collection.mutable.ListBuffer
|
||||
import net.minecraft.block.StepSound
|
||||
import net.minecraft.util.MovingObjectPosition
|
||||
import net.minecraft.world.World
|
||||
import net.minecraft.entity.Entity
|
||||
import scala.collection.JavaConversions._
|
||||
import java.util.{Iterator => JIterator}
|
||||
import net.minecraft.block.Block.SoundType
|
||||
|
||||
object MicroMaterialRegistry
|
||||
{
|
||||
|
||||
/**
|
||||
* Interface for defining a micro material
|
||||
*/
|
||||
@@ -31,63 +31,64 @@ object MicroMaterialRegistry
|
||||
* The icon to be used for breaking particles on side
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
def getBreakingIcon(side:Int):Icon
|
||||
|
||||
def getBreakingIcon(side: Int): IIcon
|
||||
|
||||
/**
|
||||
* Callback to load icons from the underlying block/etc
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
def loadIcons(){}
|
||||
|
||||
def loadIcons() {}
|
||||
|
||||
/**
|
||||
* This function must render the quad face specified by verts facing on side, at pos (x, y, z)
|
||||
* @param lightMatrix A helper class provided for calculating minecraft smooth lighting on the face.
|
||||
* @param part An IMicroMaterialRender callback for some information about the caller such as bounds and world for grass decals.
|
||||
* This function must configure and use the CCRenderState pipeline to draw from the current vertex source.
|
||||
* CCRenderState.lightMatrix will be set.
|
||||
* @param pass The current render pass, -1 for inventory rendering
|
||||
* @param bounds The cuboid bounds of the face being rendered
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
def renderMicroFace(verts:Array[Vertex5], side:Int, pos:Vector3, lightMatrix:LightMatrix, part:IMicroMaterialRender)
|
||||
|
||||
def renderMicroFace(pos: Vector3, pass: Int, bounds: Cuboid6)
|
||||
|
||||
/**
|
||||
* Get the render pass for which this material renders in.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
def getRenderPass:Int
|
||||
|
||||
def canRenderInPass(pass: Int) = pass == 0
|
||||
|
||||
/**
|
||||
* Return true if this material is not opaque (glass, ice).
|
||||
*/
|
||||
def isTransparent:Boolean
|
||||
|
||||
def isTransparent: Boolean
|
||||
|
||||
/**
|
||||
* Return the light level emitted by this material (glowstone)
|
||||
*/
|
||||
def getLightValue:Int
|
||||
|
||||
def getLightValue: Int
|
||||
|
||||
/**
|
||||
* Return the strength of this material
|
||||
*/
|
||||
def getStrength(player:EntityPlayer):Float
|
||||
|
||||
def getStrength(player: EntityPlayer): Float
|
||||
|
||||
/**
|
||||
* Return the localised name of this material (normally the block name)
|
||||
*/
|
||||
def getLocalizedName:String
|
||||
|
||||
def getLocalizedName: String
|
||||
|
||||
/**
|
||||
* Get the item that this material is cut from (full block -> slabs)
|
||||
*/
|
||||
def getItem:ItemStack
|
||||
|
||||
def getItem: ItemStack
|
||||
|
||||
/**
|
||||
* Get the strength of saw requried to cut this material
|
||||
*/
|
||||
def getCutterStrength:Int
|
||||
|
||||
def getCutterStrength: Int
|
||||
|
||||
/**
|
||||
* Get the breaking/walking sound
|
||||
*/
|
||||
def getSound:StepSound
|
||||
|
||||
def getSound: SoundType
|
||||
|
||||
/**
|
||||
* Return true if this material is solid and opaque (can run wires on etc)
|
||||
*/
|
||||
@@ -96,9 +97,9 @@ object MicroMaterialRegistry
|
||||
/**
|
||||
* Get the explosion resistance of this part to an explosion caused by entity
|
||||
*/
|
||||
def explosionResistance(entity:Entity):Float
|
||||
def explosionResistance(entity: Entity): Float
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Interface for overriding the default micro placement highlight handler to show the effect of placement on a certain block/part
|
||||
*/
|
||||
@@ -107,96 +108,94 @@ object MicroMaterialRegistry
|
||||
/**
|
||||
* Return true if a custom highlight was rendered and the default should be skipped
|
||||
*/
|
||||
def renderHighlight(world:World, player:EntityPlayer, hit:MovingObjectPosition, mcrClass:MicroblockClass, size:Int, material:Int):Boolean
|
||||
def renderHighlight(player: EntityPlayer, hit: MovingObjectPosition, mcrClass: MicroblockClass, size: Int, material: Int): Boolean
|
||||
}
|
||||
|
||||
|
||||
private val typeMap = HashMap[String, IMicroMaterial]()
|
||||
private val nameMap = HashMap[String, Int]()
|
||||
private var idMap:Array[(String, IMicroMaterial)] = _
|
||||
private var idMap: Array[(String, IMicroMaterial)] = _
|
||||
private val idWriter = new IDWriter
|
||||
|
||||
|
||||
private val highlightRenderers = ListBuffer[IMicroHighlightRenderer]()
|
||||
private var maxCuttingStrength:Int = _
|
||||
|
||||
private var maxCuttingStrength: Int = _
|
||||
|
||||
/**
|
||||
* Register a micro material with unique identifier name
|
||||
*/
|
||||
def registerMaterial(material:IMicroMaterial, name:String)
|
||||
{
|
||||
if(MultiPartRegistry.loaded)
|
||||
def registerMaterial(material: IMicroMaterial, name: String) {
|
||||
if (MultiPartRegistry.loaded)
|
||||
throw new IllegalStateException("You must register your materials in the init methods.")
|
||||
|
||||
if(typeMap.contains(name)) {
|
||||
System.err.println("Material with id "+name+" is already registered.")
|
||||
|
||||
if (typeMap.contains(name)) {
|
||||
System.err.println("Material with id " + name + " is already registered.")
|
||||
return
|
||||
}
|
||||
|
||||
System.out.println("Registered micro material: "+name)
|
||||
|
||||
System.out.println("Registered micro material: " + name)
|
||||
|
||||
typeMap.put(name, material)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Replace a micro material with unique identifier name
|
||||
*/
|
||||
def replaceMaterial(material:IMicroMaterial, name:String) {
|
||||
if(MultiPartRegistry.loaded)
|
||||
def replaceMaterial(material: IMicroMaterial, name: String) {
|
||||
if (MultiPartRegistry.loaded)
|
||||
throw new IllegalStateException("You must register your materials in the init methods.")
|
||||
|
||||
if(typeMap.remove(name).isEmpty)
|
||||
System.err.println("Material with id "+name+" is was not registered.")
|
||||
|
||||
System.out.println("Replaced micro material: "+name)
|
||||
|
||||
|
||||
if (typeMap.remove(name).isEmpty)
|
||||
System.err.println("Material with id " + name + " is was not registered.")
|
||||
|
||||
System.out.println("Replaced micro material: " + name)
|
||||
|
||||
typeMap.put(name, material)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Registers a highlight renderer
|
||||
*/
|
||||
def registerHighlightRenderer(handler:IMicroHighlightRenderer)
|
||||
{
|
||||
highlightRenderers+=handler
|
||||
def registerHighlightRenderer(handler: IMicroHighlightRenderer) {
|
||||
highlightRenderers += handler
|
||||
}
|
||||
|
||||
private [microblock] def setupIDMap()
|
||||
{
|
||||
|
||||
private[microblock] def setupIDMap() {
|
||||
idMap = typeMap.toList.sortBy(_._1).toArray
|
||||
idWriter.setMax(idMap.length)
|
||||
nameMap.clear()
|
||||
for(i <- 0 until idMap.length)
|
||||
for (i <- 0 until idMap.length)
|
||||
nameMap.put(idMap(i)._1, i)
|
||||
}
|
||||
|
||||
private [microblock] def calcMaxCuttingStrength()
|
||||
{
|
||||
maxCuttingStrength = Item.itemsList.flatMap {
|
||||
private[microblock] def calcMaxCuttingStrength() {
|
||||
val it = Item.itemRegistry.iterator.asInstanceOf[JIterator[Item]]
|
||||
maxCuttingStrength = it.flatMap {
|
||||
case saw: Saw => Some(saw.getMaxCuttingStrength)
|
||||
case _ => None
|
||||
}.max
|
||||
}
|
||||
|
||||
private[microblock] def loadIcons() {
|
||||
MicroMaterialRegistry.getIdMap.foreach(e => e._2.loadIcons())
|
||||
}
|
||||
|
||||
def getMaxCuttingStrength = maxCuttingStrength
|
||||
|
||||
def writeIDMap(packet:PacketCustom)
|
||||
{
|
||||
|
||||
def writeIDMap(packet: PacketCustom) {
|
||||
packet.writeInt(idMap.size)
|
||||
idMap.foreach(e => packet.writeString(e._1))
|
||||
}
|
||||
|
||||
def readIDMap(packet:PacketCustom):Seq[String] =
|
||||
{
|
||||
|
||||
def readIDMap(packet: PacketCustom): Seq[String] = {
|
||||
val k = packet.readInt()
|
||||
idWriter.setMax(k)
|
||||
idMap = new Array(k)
|
||||
nameMap.clear()
|
||||
val missing = ListBuffer[String]()
|
||||
for(i <- 0 until k)
|
||||
{
|
||||
for (i <- 0 until k) {
|
||||
val s = packet.readString()
|
||||
val v = typeMap.get(s)
|
||||
if(v.isEmpty)
|
||||
missing+=s
|
||||
if (v.isEmpty)
|
||||
missing += s
|
||||
else {
|
||||
idMap(i) = (s, v.get)
|
||||
nameMap.put(s, i)
|
||||
@@ -205,36 +204,33 @@ object MicroMaterialRegistry
|
||||
return missing
|
||||
}
|
||||
|
||||
//TODO: change to material
|
||||
def writePartID(data:MCDataOutput, id:Int)
|
||||
{
|
||||
def writeMaterialID(data: MCDataOutput, id: Int) {
|
||||
idWriter.write(data, id)
|
||||
}
|
||||
|
||||
//TODO: change to material
|
||||
def readPartID(data:MCDataInput) = idWriter.read(data)
|
||||
|
||||
def materialName(id:Int) = idMap(id)._1
|
||||
|
||||
def materialID(name:String) = nameMap.get(name) match {
|
||||
def readMaterialID(data: MCDataInput) = idWriter.read(data)
|
||||
|
||||
def materialName(id: Int) = idMap(id)._1
|
||||
|
||||
def materialID(name: String) = nameMap.get(name) match {
|
||||
case Some(v) => v
|
||||
case None =>
|
||||
System.err.println("Missing mapping for part with ID: "+name)
|
||||
System.err.println("Missing mapping for part with ID: " + name)
|
||||
0
|
||||
}
|
||||
|
||||
def getMaterial(name:String) = typeMap.getOrElse(name, null)
|
||||
|
||||
def getMaterial(id:Int) = idMap(id)._2
|
||||
|
||||
|
||||
def getMaterial(name: String) = typeMap.getOrElse(name, null)
|
||||
|
||||
def getMaterial(id: Int) = idMap(id)._2
|
||||
|
||||
def getIdMap = idMap
|
||||
|
||||
def renderHighlight(world:World, player:EntityPlayer, hit:MovingObjectPosition, mcrClass:MicroblockClass, size:Int, material:Int):Boolean =
|
||||
{
|
||||
val overridden = highlightRenderers.find(_.renderHighlight(world, player, hit, mcrClass, size, material))
|
||||
if(overridden.isDefined)
|
||||
|
||||
def renderHighlight(player: EntityPlayer, hit: MovingObjectPosition, mcrClass: MicroblockClass, size: Int, material: Int): Boolean = {
|
||||
val overridden = highlightRenderers.find(_.renderHighlight(player, hit, mcrClass, size, material))
|
||||
if (overridden.isDefined)
|
||||
return true
|
||||
|
||||
return mcrClass.renderHighlight(world, player, hit, size, material)
|
||||
|
||||
MicroblockRender.renderHighlight(player, hit, mcrClass, size, material)
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,12 @@ import net.minecraft.world.World
|
||||
import net.minecraft.inventory.InventoryCrafting
|
||||
import net.minecraft.item.ItemStack
|
||||
import codechicken.microblock.handler.MicroblockProxy._
|
||||
import net.minecraftforge.oredict.RecipeSorter
|
||||
|
||||
object MicroRecipe extends IRecipe
|
||||
{
|
||||
RecipeSorter.register("fmp:micro", getClass, RecipeSorter.Category.SHAPED, "after:forge:shapelessore")
|
||||
|
||||
def getRecipeOutput = new ItemStack(sawStone)
|
||||
|
||||
def getRecipeSize = 9
|
||||
@@ -178,7 +181,7 @@ object MicroRecipe extends IRecipe
|
||||
|
||||
def findMaterial(item:ItemStack):Int =
|
||||
MicroMaterialRegistry.getIdMap.find{m => val mitem = m._2.getItem
|
||||
item.itemID == mitem.itemID &&
|
||||
item.getItem == mitem.getItem &&
|
||||
item.getItemDamage == mitem.getItemDamage &&
|
||||
ItemStack.areItemStackTagsEqual(item, mitem)} match {
|
||||
case None => -1
|
||||
|
||||
@@ -1,30 +1,11 @@
|
||||
package codechicken.microblock
|
||||
|
||||
import net.minecraft.util.MovingObjectPosition
|
||||
import net.minecraft.world.World
|
||||
import codechicken.lib.vec.Vector3
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import cpw.mods.fml.relauncher.SideOnly
|
||||
import cpw.mods.fml.relauncher.Side
|
||||
|
||||
trait MicroblockClass
|
||||
{
|
||||
var classID:Int = _
|
||||
|
||||
def itemSlot = 3
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
def renderHighlight(world:World, player:EntityPlayer, hit:MovingObjectPosition, size:Int, material:Int):Boolean =
|
||||
{
|
||||
placementProperties.placementGrid.render(new Vector3(hit.hitVec), hit.sideHit)
|
||||
|
||||
val placement = MicroblockPlacement(world, player, hit, size, material, !player.capabilities.isCreativeMode, placementProperties)
|
||||
if(placement != null)
|
||||
CommonMicroblock.renderHighlight(world, placement.pos, placement.part.asInstanceOf[MicroblockClient])
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
def getName:String
|
||||
|
||||
def create(client:Boolean):CommonMicroblock
|
||||
|
||||
@@ -62,12 +62,13 @@ abstract class PlacementProperties
|
||||
|
||||
object MicroblockPlacement
|
||||
{
|
||||
def apply(world:World, player:EntityPlayer, hit:MovingObjectPosition, size:Int, material:Int, checkMaterial:Boolean, pp:PlacementProperties):ExecutablePlacement =
|
||||
new MicroblockPlacement(world, player, hit, size, material, checkMaterial, pp)()
|
||||
def apply(player:EntityPlayer, hit:MovingObjectPosition, size:Int, material:Int, checkMaterial:Boolean, pp:PlacementProperties):ExecutablePlacement =
|
||||
new MicroblockPlacement(player, hit, size, material, checkMaterial, pp)()
|
||||
}
|
||||
|
||||
class MicroblockPlacement(val world:World, val player:EntityPlayer, val hit:MovingObjectPosition, val size:Int, val material:Int, val checkMaterial:Boolean, val pp:PlacementProperties)
|
||||
class MicroblockPlacement(val player:EntityPlayer, val hit:MovingObjectPosition, val size:Int, val material:Int, val checkMaterial:Boolean, val pp:PlacementProperties)
|
||||
{
|
||||
val world = player.worldObj
|
||||
val mcrClass = pp.microClass
|
||||
val pos = new BlockCoord(hit.blockX, hit.blockY, hit.blockZ)
|
||||
val vhit = new Vector3(hit.hitVec).add(-pos.x, -pos.y, -pos.z)
|
||||
|
||||
@@ -3,6 +3,7 @@ package codechicken.microblock
|
||||
import codechicken.multipart.TMultiPart
|
||||
import codechicken.lib.vec.Cuboid6
|
||||
import codechicken.multipart.PartMap._
|
||||
import codechicken.lib.data.MCDataInput
|
||||
|
||||
/**
|
||||
* Suite of classes for performing microblock style occlusion and shrink rendering. Use at your own peril.
|
||||
@@ -180,6 +181,12 @@ trait TMicroOcclusionClient extends TMicroOcclusion with JMicroShrinkRender
|
||||
super.onAdded()
|
||||
recalcBounds()
|
||||
}
|
||||
|
||||
override def read(packet:MCDataInput)
|
||||
{
|
||||
super.read(packet)
|
||||
recalcBounds()
|
||||
}
|
||||
|
||||
def recalcBounds()
|
||||
{
|
||||
|
||||
@@ -1,62 +1,40 @@
|
||||
package codechicken.microblock.handler
|
||||
|
||||
import cpw.mods.fml.common.network.IConnectionHandler
|
||||
import net.minecraftforge.event.ForgeSubscribe
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent
|
||||
import cpw.mods.fml.relauncher.SideOnly
|
||||
import cpw.mods.fml.relauncher.Side
|
||||
import net.minecraftforge.client.event.TextureStitchEvent
|
||||
import codechicken.microblock.MicroMaterialRegistry
|
||||
import net.minecraftforge.client.event.DrawBlockHighlightEvent
|
||||
import net.minecraft.util.EnumMovingObjectType
|
||||
import org.lwjgl.opengl.GL11
|
||||
import codechicken.lib.render.RenderUtils
|
||||
import codechicken.microblock.ItemMicroPartRenderer
|
||||
import net.minecraft.network.NetLoginHandler
|
||||
import net.minecraft.network.INetworkManager
|
||||
import codechicken.lib.packet.PacketCustom
|
||||
import net.minecraft.network.packet.NetHandler
|
||||
import net.minecraft.server.MinecraftServer
|
||||
import net.minecraft.network.packet.Packet1Login
|
||||
import cpw.mods.fml.common.Loader
|
||||
import cpw.mods.fml.common.network.Player
|
||||
import cpw.mods.fml.common.LoaderState
|
||||
import net.minecraft.util.MovingObjectPosition.MovingObjectType
|
||||
|
||||
object MicroblockEventHandler extends IConnectionHandler
|
||||
object MicroblockEventHandler
|
||||
{
|
||||
@ForgeSubscribe
|
||||
@SubscribeEvent
|
||||
@SideOnly(Side.CLIENT)
|
||||
def postTextureStitch(event:TextureStitchEvent.Post)
|
||||
{
|
||||
if(event.map.textureType == 0 && Loader.instance.hasReachedState(LoaderState.POSTINITIALIZATION))
|
||||
MicroMaterialRegistry.getIdMap.foreach(e => e._2.loadIcons())
|
||||
if(event.map.getTextureType == 0 && Loader.instance.hasReachedState(LoaderState.POSTINITIALIZATION))
|
||||
MicroMaterialRegistry.loadIcons()
|
||||
}
|
||||
|
||||
@ForgeSubscribe
|
||||
|
||||
@SubscribeEvent
|
||||
@SideOnly(Side.CLIENT)
|
||||
def drawBlockHighlight(event:DrawBlockHighlightEvent)
|
||||
{
|
||||
if(event.currentItem != null && event.currentItem.getItem == MicroblockProxy.itemMicro &&
|
||||
event.target != null && event.target.typeOfHit == EnumMovingObjectType.TILE)
|
||||
event.target != null && event.target.typeOfHit == MovingObjectType.BLOCK)
|
||||
{
|
||||
GL11.glPushMatrix()
|
||||
RenderUtils.translateToWorldCoords(event.player, event.partialTicks)
|
||||
if(ItemMicroPartRenderer.renderHighlight(event.player.worldObj, event.player, event.currentItem, event.target))
|
||||
if(ItemMicroPartRenderer.renderHighlight(event.player, event.currentItem, event.target))
|
||||
event.setCanceled(true)
|
||||
GL11.glPopMatrix()
|
||||
}
|
||||
}
|
||||
|
||||
def connectionReceived(loginHandler:NetLoginHandler, netManager:INetworkManager):String =
|
||||
{
|
||||
val packet = new PacketCustom(MicroblockSPH.registryChannel, 1)
|
||||
MicroMaterialRegistry.writeIDMap(packet)
|
||||
netManager.addToSendQueue(packet.toPacket)
|
||||
return null
|
||||
}
|
||||
|
||||
def clientLoggedIn(netHandler:NetHandler, netManager:INetworkManager, packet:Packet1Login){}
|
||||
def playerLoggedIn(player:Player, netHandler:NetHandler, netManager:INetworkManager){}
|
||||
def connectionOpened(netHandler:NetHandler, server:String, port:Int, netManager:INetworkManager){}
|
||||
def connectionOpened(netHandler:NetHandler, server:MinecraftServer, netManager:INetworkManager){}
|
||||
def connectionClosed(netManager:INetworkManager){}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import codechicken.microblock.ConfigContent
|
||||
import cpw.mods.fml.common.event.FMLInterModComms.IMCEvent
|
||||
import scala.collection.JavaConversions._
|
||||
|
||||
@Mod(modid = "ForgeMicroblock", acceptedMinecraftVersions = "[1.6.4]",
|
||||
@Mod(modid = "ForgeMicroblock", acceptedMinecraftVersions = "[1.7.2]",
|
||||
dependencies="required-after:ForgeMultipart;after:*", modLanguage="scala")
|
||||
object MicroblockMod
|
||||
{
|
||||
@@ -34,8 +34,8 @@ object MicroblockMod
|
||||
@EventHandler
|
||||
def postInit(event:FMLPostInitializationEvent)
|
||||
{
|
||||
MicroblockProxy.postInit()
|
||||
MicroMaterialRegistry.setupIDMap()
|
||||
MicroblockProxy.postInit()
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
||||
@@ -1,39 +1,42 @@
|
||||
package codechicken.microblock.handler
|
||||
|
||||
import codechicken.lib.packet.PacketCustom.IClientPacketHandler
|
||||
import codechicken.lib.packet.PacketCustom.IServerPacketHandler
|
||||
import codechicken.lib.packet.PacketCustom.{IHandshakeHandler, IClientPacketHandler, IServerPacketHandler}
|
||||
import codechicken.lib.packet.PacketCustom
|
||||
import net.minecraft.client.multiplayer.NetClientHandler
|
||||
import net.minecraft.client.Minecraft
|
||||
import codechicken.microblock.MicroMaterialRegistry
|
||||
import net.minecraft.network.packet.Packet255KickDisconnect
|
||||
import net.minecraft.network.NetServerHandler
|
||||
import net.minecraft.entity.player.EntityPlayerMP
|
||||
import net.minecraft.network.play.{INetHandlerPlayServer, INetHandlerPlayClient}
|
||||
import net.minecraft.network.play.server.S40PacketDisconnect
|
||||
import net.minecraft.util.ChatComponentTranslation
|
||||
import net.minecraft.network.NetHandlerPlayServer
|
||||
|
||||
class MicroblockPH
|
||||
{
|
||||
val registryChannel = "ForgeMicroblock"//Must use the 250 system for ID registry as the NetworkMod idMap hasn't been properly initialized from the server yet.
|
||||
val registryChannel = "ForgeMicroblock" //Must use the 250 system for ID registry as the NetworkMod idMap hasn't been properly initialized from the server yet.
|
||||
}
|
||||
|
||||
object MicroblockCPH extends MicroblockPH with IClientPacketHandler
|
||||
{
|
||||
def handlePacket(packet:PacketCustom, netHandler:NetClientHandler, mc:Minecraft)
|
||||
{
|
||||
packet.getType match
|
||||
{
|
||||
def handlePacket(packet: PacketCustom, mc: Minecraft, netHandler:INetHandlerPlayClient) {
|
||||
packet.getType match {
|
||||
case 1 => handleMaterialRegistration(packet, netHandler)
|
||||
}
|
||||
}
|
||||
|
||||
def handleMaterialRegistration(packet:PacketCustom, netHandler:NetClientHandler)
|
||||
{
|
||||
|
||||
def handleMaterialRegistration(packet: PacketCustom, netHandler: INetHandlerPlayClient) {
|
||||
val missing = MicroMaterialRegistry.readIDMap(packet)
|
||||
if(!missing.isEmpty)
|
||||
netHandler.handleKickDisconnect(new Packet255KickDisconnect("The following microblocks are not installed on this client: "+missing.mkString(", ")))
|
||||
if (!missing.isEmpty)
|
||||
netHandler.handleDisconnect(new S40PacketDisconnect(new ChatComponentTranslation("microblock.missing", missing.mkString(", "))))
|
||||
}
|
||||
}
|
||||
|
||||
object MicroblockSPH extends MicroblockPH with IServerPacketHandler
|
||||
object MicroblockSPH extends MicroblockPH with IServerPacketHandler with IHandshakeHandler
|
||||
{
|
||||
def handlePacket(packet:PacketCustom, netHandler:NetServerHandler, sender:EntityPlayerMP){}
|
||||
def handlePacket(packet: PacketCustom, sender: EntityPlayerMP, netHandler:INetHandlerPlayServer) {}
|
||||
|
||||
def handshakeRecieved(netHandler: NetHandlerPlayServer) {
|
||||
val packet = new PacketCustom(registryChannel, 1)
|
||||
MicroMaterialRegistry.writeIDMap(packet)
|
||||
netHandler.sendPacket(packet.toPacket)
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import codechicken.lib.packet.PacketCustom
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import cpw.mods.fml.common.network.NetworkRegistry
|
||||
import net.minecraft.client.renderer.RenderBlocks
|
||||
import net.minecraft.init.{Blocks, Items}
|
||||
|
||||
class MicroblockProxy_serverImpl
|
||||
{
|
||||
@@ -34,27 +35,23 @@ class MicroblockProxy_serverImpl
|
||||
|
||||
def preInit()
|
||||
{
|
||||
itemMicro = new ItemMicroPart(config.getTag("itemMicro.id").getIntValue(nextItemID))
|
||||
itemMicro.setUnlocalizedName("microblock")
|
||||
itemMicro = new ItemMicroPart
|
||||
GameRegistry.registerItem(itemMicro, "microblock")
|
||||
|
||||
sawStone = createSaw(config, "sawStone", 1)
|
||||
GameRegistry.registerItem(sawStone, "sawStone")
|
||||
sawIron = createSaw(config, "sawIron", 2)
|
||||
GameRegistry.registerItem(sawIron, "sawIron")
|
||||
sawDiamond = createSaw(config, "sawDiamond", 3)
|
||||
GameRegistry.registerItem(sawDiamond, "sawDiamond")
|
||||
stoneRod = new Item(config.getTag("stoneRod.id").getIntValue(nextItemID))
|
||||
.setUnlocalizedName("microblock:stoneRod").setTextureName("microblock:stoneRod")
|
||||
stoneRod = new Item().setUnlocalizedName("microblock:stoneRod").setTextureName("microblock:stoneRod")
|
||||
GameRegistry.registerItem(stoneRod, "stoneRod")
|
||||
|
||||
OreDictionary.registerOre("stoneRod", stoneRod)
|
||||
OreDictionary.registerOre("rodStone", stoneRod)
|
||||
MinecraftForge.EVENT_BUS.register(MicroblockEventHandler)
|
||||
NetworkRegistry.instance.registerConnectionHandler(MicroblockEventHandler)
|
||||
}
|
||||
|
||||
def createSaw(config:ConfigFile, name:String, strength:Int) =
|
||||
new ItemSaw(config.getTag(name).useBraces(), strength).setUnlocalizedName("microblock:"+name)
|
||||
def createSaw(config:ConfigFile, name:String, strength:Int) = {
|
||||
val saw = new ItemSaw(config.getTag(name).useBraces(), strength).setUnlocalizedName("microblock:"+name)
|
||||
GameRegistry.registerItem(saw, name)
|
||||
saw
|
||||
}
|
||||
|
||||
def addSawRecipe(saw:Item, blade:Item)
|
||||
{
|
||||
@@ -62,23 +59,25 @@ class MicroblockProxy_serverImpl
|
||||
new ShapedOreRecipe(new ItemStack(saw),
|
||||
"srr",
|
||||
"sbr",
|
||||
's':Character, Item.stick,
|
||||
'r':Character, "stoneRod",
|
||||
's':Character, Items.stick,
|
||||
'r':Character, "rodStone",
|
||||
'b':Character, blade))
|
||||
}
|
||||
|
||||
def init()
|
||||
{
|
||||
CraftingManager.getInstance.getRecipeList.asInstanceOf[JList[IRecipe]].add(MicroRecipe)
|
||||
CraftingManager.getInstance.addRecipe(new ItemStack(stoneRod, 4), "s", "s", 's':Character, Block.stone)
|
||||
addSawRecipe(sawStone, Item.flint)
|
||||
addSawRecipe(sawIron, Item.ingotIron)
|
||||
addSawRecipe(sawDiamond, Item.diamond)
|
||||
CraftingManager.getInstance.addRecipe(new ItemStack(stoneRod, 4), "s", "s", 's':Character, Blocks.stone)
|
||||
addSawRecipe(sawStone, Items.flint)
|
||||
addSawRecipe(sawIron, Items.iron_ingot)
|
||||
addSawRecipe(sawDiamond, Items.diamond)
|
||||
}
|
||||
|
||||
def postInit()
|
||||
{
|
||||
MicroMaterialRegistry.loadIcons()
|
||||
MicroMaterialRegistry.calcMaxCuttingStrength()
|
||||
PacketCustom.assignHandshakeHandler(MicroblockSPH.registryChannel, MicroblockSPH)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,15 +97,15 @@ class MicroblockProxy_clientImpl extends MicroblockProxy_serverImpl
|
||||
override def postInit()
|
||||
{
|
||||
super.postInit()
|
||||
MinecraftForgeClient.registerItemRenderer(itemMicro.itemID, ItemMicroPartRenderer)
|
||||
PacketCustom.assignHandler(MicroblockCPH.registryChannel, 1, 127, MicroblockCPH)
|
||||
MinecraftForgeClient.registerItemRenderer(itemMicro, ItemMicroPartRenderer)
|
||||
PacketCustom.assignHandler(MicroblockCPH.registryChannel, MicroblockCPH)
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def createSaw(config:ConfigFile, name:String, strength:Int) =
|
||||
{
|
||||
val saw = super.createSaw(config, name, strength)
|
||||
MinecraftForgeClient.registerItemRenderer(saw.itemID, ItemSawRenderer)
|
||||
MinecraftForgeClient.registerItemRenderer(saw, ItemSawRenderer)
|
||||
saw
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.minecraft.block.material.Material
|
||||
import net.minecraft.entity.Entity
|
||||
import net.minecraft.util.AxisAlignedBB
|
||||
import net.minecraft.world.World
|
||||
import net.minecraftforge.common.ForgeDirection
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import net.minecraft.util.Vec3
|
||||
import net.minecraft.util.MovingObjectPosition
|
||||
import codechicken.lib.raytracer.RayTracer
|
||||
@@ -17,7 +17,7 @@ import java.util.ArrayList
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.client.particle.EffectRenderer
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.renderer.texture.IconRegister
|
||||
import net.minecraft.client.renderer.texture.IIconRegister
|
||||
import codechicken.lib.render.TextureUtils
|
||||
import net.minecraft.world.IBlockAccess
|
||||
import codechicken.lib.raytracer.ExtendedMOP
|
||||
@@ -27,7 +27,7 @@ object BlockMultipart
|
||||
{
|
||||
def getTile(world:IBlockAccess, x:Int, y:Int, z:Int):TileMultipart =
|
||||
{
|
||||
val tile = world.getBlockTileEntity(x, y, z)
|
||||
val tile = world.getTileEntity(x, y, z)
|
||||
if(tile.isInstanceOf[TileMultipart])
|
||||
tile.asInstanceOf[TileMultipart]
|
||||
else
|
||||
@@ -36,7 +36,7 @@ object BlockMultipart
|
||||
|
||||
def getClientTile(world:IBlockAccess, x:Int, y:Int, z:Int):TileMultipartClient =
|
||||
{
|
||||
val tile = world.getBlockTileEntity(x, y, z)
|
||||
val tile = world.getTileEntity(x, y, z)
|
||||
if(tile.isInstanceOf[TileMultipartClient])
|
||||
tile.asInstanceOf[TileMultipartClient]
|
||||
else
|
||||
@@ -67,20 +67,19 @@ object BlockMultipart
|
||||
/**
|
||||
* Block class for all multiparts, should be internal use only.
|
||||
*/
|
||||
class BlockMultipart(id:Int) extends Block(id, Material.rock)
|
||||
class BlockMultipart extends Block(Material.rock)
|
||||
{
|
||||
import BlockMultipart._
|
||||
|
||||
override def hasTileEntity(meta:Int = 0) = true
|
||||
|
||||
override def isBlockSolidOnSide(world:World, x:Int, y:Int, z:Int, side:ForgeDirection):Boolean =
|
||||
override def isBlockSolid(world:IBlockAccess, x:Int, y:Int, z:Int, side:Int):Boolean =
|
||||
getTile(world, x, y, z) match {
|
||||
case null => false
|
||||
case tile => tile.isSolid(side.ordinal())
|
||||
case tile => tile.isSolid(side)
|
||||
}
|
||||
|
||||
override def onNeighborBlockChange(world:World, x:Int, y:Int, z:Int, id:Int)
|
||||
{
|
||||
override def onNeighborBlockChange(world:World, x:Int, y:Int, z:Int, block:Block) {
|
||||
val tile = getTile(world, x, y, z)
|
||||
if(tile != null)
|
||||
tile.onNeighborBlockChange()
|
||||
@@ -98,8 +97,7 @@ class BlockMultipart(id:Int) extends Block(id, Material.rock)
|
||||
case tile => tile.rayTraceAll(start, end)
|
||||
}
|
||||
|
||||
override def removeBlockByPlayer(world:World, player:EntityPlayer, x:Int, y:Int, z:Int):Boolean =
|
||||
{
|
||||
override def removedByPlayer(world:World, player:EntityPlayer, x:Int, y:Int, z:Int):Boolean = {
|
||||
val hit = RayTracer.retraceBlock(world, player, x, y, z)
|
||||
val tile = getTile(world, x, y, z)
|
||||
|
||||
@@ -117,22 +115,20 @@ class BlockMultipart(id:Int) extends Block(id, Material.rock)
|
||||
}
|
||||
|
||||
tile.harvestPart(index, mop, player)
|
||||
return world.getBlockTileEntity(x, y, z) == null
|
||||
return world.getTileEntity(x, y, z) == null
|
||||
}
|
||||
|
||||
def dropAndDestroy(world:World, x:Int, y:Int, z:Int)
|
||||
{
|
||||
def dropAndDestroy(world:World, x:Int, y:Int, z:Int) {
|
||||
val tile = getTile(world, x, y, z)
|
||||
if(tile != null && !world.isRemote)
|
||||
tile.dropItems(getBlockDropped(world, x, y, z, 0, 0))
|
||||
tile.dropItems(getDrops(world, x, y, z, 0, 0))
|
||||
|
||||
world.setBlockToAir(x, y, z)
|
||||
}
|
||||
|
||||
override def quantityDropped(meta:Int, fortune:Int, random:Random) = 0
|
||||
|
||||
override def getBlockDropped(world:World, x:Int, y:Int, z:Int, meta:Int, fortune:Int):ArrayList[ItemStack] =
|
||||
{
|
||||
override def getDrops(world:World, x:Int, y:Int, z:Int, meta:Int, fortune:Int):ArrayList[ItemStack] = {
|
||||
val ai = new ArrayList[ItemStack]()
|
||||
if(world.isRemote)
|
||||
return ai
|
||||
@@ -144,8 +140,7 @@ class BlockMultipart(id:Int) extends Block(id, Material.rock)
|
||||
return ai
|
||||
}
|
||||
|
||||
override def addCollisionBoxesToList(world:World, x:Int, y:Int, z:Int, ebb:AxisAlignedBB, list$:List[_], entity:Entity)
|
||||
{
|
||||
override def addCollisionBoxesToList(world:World, x:Int, y:Int, z:Int, ebb:AxisAlignedBB, list$:List[_], entity:Entity) {
|
||||
val list = list$.asInstanceOf[List[AxisAlignedBB]]
|
||||
val tile = getTile(world, x, y, z)
|
||||
if(tile != null)
|
||||
@@ -157,18 +152,18 @@ class BlockMultipart(id:Int) extends Block(id, Material.rock)
|
||||
})
|
||||
}
|
||||
|
||||
override def addBlockHitEffects(world:World, hit:MovingObjectPosition, effectRenderer:EffectRenderer):Boolean =
|
||||
{
|
||||
override def addHitEffects(world:World, hit:MovingObjectPosition, effectRenderer:EffectRenderer):Boolean = {
|
||||
val tile = getClientTile(world, hit.blockX, hit.blockY, hit.blockZ)
|
||||
if(tile != null) {
|
||||
val (index, mop) = reduceMOP(hit)
|
||||
tile.partList(index).addHitEffects(mop, effectRenderer)
|
||||
if(index < tile.partList.size)
|
||||
tile.partList(index).addHitEffects(mop, effectRenderer)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override def addBlockDestroyEffects(world:World, x:Int, y:Int, z:Int, s:Int, effectRenderer:EffectRenderer) = true
|
||||
override def addDestroyEffects(world:World, x:Int, y:Int, z:Int, s:Int, effectRenderer:EffectRenderer) = true
|
||||
|
||||
override def renderAsNormalBlock() = false
|
||||
|
||||
@@ -176,24 +171,22 @@ class BlockMultipart(id:Int) extends Block(id, Material.rock)
|
||||
|
||||
override def getRenderType = TileMultipart.renderID
|
||||
|
||||
override def isAirBlock(world:World, x:Int, y:Int, z:Int):Boolean =
|
||||
override def isAir(world:IBlockAccess, x:Int, y:Int, z:Int):Boolean =
|
||||
getTile(world, x, y, z) match {
|
||||
case null => true
|
||||
case tile => tile.partList.isEmpty
|
||||
}
|
||||
|
||||
override def isBlockReplaceable(world:World, x:Int, y:Int, z:Int) = isAirBlock(world, x, y, z)
|
||||
override def isReplaceable(world:IBlockAccess, x:Int, y:Int, z:Int) = isAir(world, x, y, z)
|
||||
|
||||
override def getRenderBlockPass = 1
|
||||
|
||||
override def canRenderInPass(pass:Int):Boolean =
|
||||
{
|
||||
override def canRenderInPass(pass:Int):Boolean = {
|
||||
MultipartRenderer.pass = pass
|
||||
return true
|
||||
}
|
||||
|
||||
override def getPickBlock(hit:MovingObjectPosition, world:World, x:Int, y:Int, z:Int):ItemStack =
|
||||
{
|
||||
override def getPickBlock(hit:MovingObjectPosition, world:World, x:Int, y:Int, z:Int):ItemStack = {
|
||||
val tile = getTile(world, x, y, z)
|
||||
if(tile != null)
|
||||
{
|
||||
@@ -202,9 +195,8 @@ class BlockMultipart(id:Int) extends Block(id, Material.rock)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
override def getPlayerRelativeBlockHardness(player:EntityPlayer, world:World, x:Int, y:Int, z:Int):Float =
|
||||
{
|
||||
|
||||
override def getPlayerRelativeBlockHardness(player:EntityPlayer, world:World, x:Int, y:Int, z:Int):Float = {
|
||||
val hit = RayTracer.retraceBlock(world, player, x, y, z)
|
||||
val tile = getTile(world, x, y, z)
|
||||
if(hit != null && tile != null) {
|
||||
@@ -218,11 +210,10 @@ class BlockMultipart(id:Int) extends Block(id, Material.rock)
|
||||
/**
|
||||
* Kludge to set PROTECTED blockIcon to a blank icon
|
||||
*/
|
||||
override def registerIcons(register:IconRegister)
|
||||
{
|
||||
override def registerBlockIcons(register:IIconRegister) {
|
||||
val icon = TextureUtils.getBlankIcon(16, register)
|
||||
setTextureName(icon.getIconName)
|
||||
super.registerIcons(register)
|
||||
setBlockTextureName(icon.getIconName)
|
||||
super.registerBlockIcons(register)
|
||||
}
|
||||
|
||||
override def getLightValue(world:IBlockAccess, x:Int, y:Int, z:Int):Int =
|
||||
@@ -231,15 +222,13 @@ class BlockMultipart(id:Int) extends Block(id, Material.rock)
|
||||
case tile => tile.getLightValue
|
||||
}
|
||||
|
||||
override def randomDisplayTick(world:World, x:Int, y:Int, z:Int, random:Random)
|
||||
{
|
||||
override def randomDisplayTick(world:World, x:Int, y:Int, z:Int, random:Random) {
|
||||
val tile = getClientTile(world, x, y, z)
|
||||
if(tile != null)
|
||||
tile.randomDisplayTick(random)
|
||||
}
|
||||
|
||||
override def onBlockActivated(world:World, x:Int, y:Int, z:Int, player:EntityPlayer, side:Int, hitX:Float, hitY:Float, hitZ:Float):Boolean =
|
||||
{
|
||||
override def onBlockActivated(world:World, x:Int, y:Int, z:Int, player:EntityPlayer, side:Int, hitX:Float, hitY:Float, hitZ:Float):Boolean = {
|
||||
val hit = RayTracer.retraceBlock(world, player, x, y, z)
|
||||
if(hit == null)
|
||||
return false
|
||||
@@ -252,8 +241,7 @@ class BlockMultipart(id:Int) extends Block(id, Material.rock)
|
||||
return tile.partList(index).activate(player, mop, player.getHeldItem)
|
||||
}
|
||||
|
||||
override def onBlockClicked(world:World, x:Int, y:Int, z:Int, player:EntityPlayer)
|
||||
{
|
||||
override def onBlockClicked(world:World, x:Int, y:Int, z:Int, player:EntityPlayer) {
|
||||
val hit = RayTracer.retraceBlock(world, player, x, y, z)
|
||||
if(hit == null)
|
||||
return
|
||||
@@ -284,19 +272,16 @@ class BlockMultipart(id:Int) extends Block(id, Material.rock)
|
||||
case tile => tile.canConnectRedstone(side)
|
||||
}
|
||||
|
||||
override def onEntityCollidedWithBlock(world:World, x:Int, y:Int, z:Int, entity:Entity)
|
||||
{
|
||||
override def onEntityCollidedWithBlock(world:World, x:Int, y:Int, z:Int, entity:Entity) {
|
||||
val tile = getTile(world, x, y, z)
|
||||
if(tile != null)
|
||||
tile.onEntityCollision(entity)
|
||||
}
|
||||
|
||||
override def onNeighborTileChange(world:World, x:Int, y:Int, z:Int, tileX:Int, tileY:Int, tileZ:Int)
|
||||
{
|
||||
getTile(world, x, y, z) match {
|
||||
case null => world.setBlockToAir(x, y, z)
|
||||
case tile => tile.onNeighborTileChange(tileX, tileY, tileZ)
|
||||
}
|
||||
|
||||
override def onNeighborChange(world:IBlockAccess, x:Int, y:Int, z:Int, tileX:Int, tileY:Int, tileZ:Int) {
|
||||
val tile = getTile(world, x, y, z)
|
||||
if(tile != null)
|
||||
tile.onNeighborTileChange(tileX, tileY, tileZ)
|
||||
}
|
||||
|
||||
override def getExplosionResistance(entity:Entity, world:World, x:Int, y:Int, z:Int, explosionX:Double, explosionY:Double, explosionZ:Double):Float =
|
||||
@@ -305,7 +290,11 @@ class BlockMultipart(id:Int) extends Block(id, Material.rock)
|
||||
case tile => tile.getExplosionResistance(entity)
|
||||
}
|
||||
|
||||
override def weakTileChanges() = true
|
||||
|
||||
override def getWeakChanges(world:IBlockAccess, x:Int, y:Int, z:Int) =
|
||||
getTile(world, x, y, z) match {
|
||||
case null => false
|
||||
case tile => tile.getWeakChanges()
|
||||
}
|
||||
|
||||
override def canProvidePower = true
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
package codechicken.multipart
|
||||
|
||||
import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler
|
||||
import net.minecraft.client.settings.KeyBinding
|
||||
import org.lwjgl.input.Keyboard
|
||||
import cpw.mods.fml.common.registry.LanguageRegistry
|
||||
import java.util.EnumSet
|
||||
import cpw.mods.fml.common.TickType
|
||||
import net.minecraft.client.Minecraft
|
||||
import codechicken.lib.packet.PacketCustom
|
||||
import codechicken.multipart.handler.MultipartCPH
|
||||
import scala.collection.mutable.HashMap
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent
|
||||
import cpw.mods.fml.common.gameevent.InputEvent.KeyInputEvent
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent
|
||||
|
||||
/**
|
||||
* A class that maintains a map server<->client of which players are holding the control (or placement modifier key) much like sneaking.
|
||||
@@ -35,37 +35,24 @@ object ControlKeyModifer
|
||||
/**
|
||||
* Key Handler implementation
|
||||
*/
|
||||
object ControlKeyHandler extends KeyHandler (
|
||||
Array(new KeyBinding("key.control", Keyboard.KEY_LCONTROL)),
|
||||
Array(false))
|
||||
object ControlKeyHandler extends KeyBinding("key.control", Keyboard.KEY_LCONTROL, "key.categories.gameplay")
|
||||
{
|
||||
import ControlKeyModifer._
|
||||
|
||||
LanguageRegistry.instance.addStringLocalization("key.control", "Placement Modifier")
|
||||
|
||||
def keyDown(types:EnumSet[TickType], kb:KeyBinding, tickEnd:Boolean, isRepeat:Boolean)
|
||||
{
|
||||
if(!tickEnd && Minecraft.getMinecraft.getNetHandler != null)
|
||||
{
|
||||
map.put(Minecraft.getMinecraft.thePlayer, true)
|
||||
val packet = new PacketCustom(MultipartCPH.channel, 1)
|
||||
packet.writeBoolean(true)
|
||||
packet.sendToServer()
|
||||
}
|
||||
}
|
||||
|
||||
def keyUp(types:EnumSet[TickType], kb:KeyBinding, tickEnd:Boolean)
|
||||
{
|
||||
if(!tickEnd && Minecraft.getMinecraft.getNetHandler != null)
|
||||
{
|
||||
map.put(Minecraft.getMinecraft.thePlayer, false)
|
||||
val packet = new PacketCustom(MultipartCPH.channel, 1)
|
||||
packet.writeBoolean(false)
|
||||
packet.sendToServer()
|
||||
}
|
||||
}
|
||||
|
||||
def getLabel = "Control Key Modifer"
|
||||
var wasPressed = false
|
||||
|
||||
def ticks = EnumSet.of(TickType.CLIENT)
|
||||
@SubscribeEvent
|
||||
@SideOnly(Side.CLIENT)
|
||||
def tick(event:ClientTickEvent) {
|
||||
val pressed = getIsKeyPressed
|
||||
if(pressed != wasPressed) {
|
||||
wasPressed = pressed
|
||||
if(Minecraft.getMinecraft.getNetHandler != null)
|
||||
{
|
||||
map.put(Minecraft.getMinecraft.thePlayer, pressed)
|
||||
val packet = new PacketCustom(MultipartCPH.channel, 1)
|
||||
packet.writeBoolean(pressed)
|
||||
packet.sendToServer()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import net.minecraft.block.Block
|
||||
import net.minecraft.world.IBlockAccess
|
||||
import net.minecraft.util.Direction
|
||||
import codechicken.lib.vec.Rotation._
|
||||
import net.minecraft.init.Blocks
|
||||
|
||||
/**
|
||||
* Interface for parts with redstone interaction
|
||||
@@ -105,14 +106,13 @@ object RedstoneInteractions
|
||||
/**
|
||||
* Hardcoded vanilla overrides for Block.canConnectRedstone (see @IRedstoneConnectorBlock)
|
||||
*/
|
||||
val fullVanillaBlocks = Array.ofDim[Boolean](Block.blocksList.length)
|
||||
Seq(Block.torchRedstoneActive,
|
||||
Block.torchRedstoneIdle,
|
||||
Block.lever,
|
||||
Block.stoneButton,
|
||||
Block.woodenButton,
|
||||
Block.blockRedstone
|
||||
).foreach(b => fullVanillaBlocks(b.blockID) = true)
|
||||
val fullVanillaBlocks = Set(
|
||||
Blocks.redstone_torch,
|
||||
Blocks.unlit_redstone_torch,
|
||||
Blocks.lever,
|
||||
Blocks.stone_button,
|
||||
Blocks.wooden_button,
|
||||
Blocks.redstone_block)
|
||||
|
||||
/**
|
||||
* Get the direct power to p on side
|
||||
@@ -120,7 +120,7 @@ object RedstoneInteractions
|
||||
def getPowerTo(p:TMultiPart, side:Int):Int =
|
||||
{
|
||||
val tile = p.tile
|
||||
return getPowerTo(tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord, side,
|
||||
return getPowerTo(tile.getWorldObj, tile.xCoord, tile.yCoord, tile.zCoord, side,
|
||||
tile.asInstanceOf[IRedstoneTile].openConnections(side)&connectionMask(p, side))
|
||||
}
|
||||
|
||||
@@ -135,14 +135,11 @@ object RedstoneInteractions
|
||||
*/
|
||||
def getPower(world:World, x:Int, y:Int, z:Int, side:Int, mask:Int):Int =
|
||||
{
|
||||
val tile = world.getBlockTileEntity(x, y, z)
|
||||
val tile = world.getTileEntity(x, y, z)
|
||||
if(tile.isInstanceOf[IRedstoneConnector])
|
||||
return tile.asInstanceOf[IRedstoneConnector].weakPowerLevel(side, mask)
|
||||
|
||||
val block = Block.blocksList(world.getBlockId(x, y, z))
|
||||
if(block == null)
|
||||
return 0
|
||||
|
||||
val block = world.getBlock(x, y, z)
|
||||
if(block.isInstanceOf[IRedstoneConnectorBlock])
|
||||
return block.asInstanceOf[IRedstoneConnectorBlock].weakPowerLevel(world, x, y, z, side, mask)
|
||||
|
||||
@@ -150,7 +147,7 @@ object RedstoneInteractions
|
||||
if((vmask&mask) > 0)
|
||||
{
|
||||
var m = world.getIndirectPowerLevelTo(x, y, z, side^1)
|
||||
if(m < 15 && block == Block.redstoneWire)
|
||||
if(m < 15 && block == Blocks.redstone_wire)
|
||||
m = Math.max(m, world.getBlockMetadata(x, y, z))//painful vanilla kludge
|
||||
return m
|
||||
}
|
||||
@@ -195,14 +192,11 @@ object RedstoneInteractions
|
||||
*/
|
||||
def getConnectionMask(world:IBlockAccess, x:Int, y:Int, z:Int, side:Int, power:Boolean):Int =
|
||||
{
|
||||
val tile = world.getBlockTileEntity(x, y, z)
|
||||
val tile = world.getTileEntity(x, y, z)
|
||||
if(tile.isInstanceOf[IRedstoneConnector])
|
||||
return tile.asInstanceOf[IRedstoneConnector].getConnectionMask(side)
|
||||
|
||||
val block = Block.blocksList(world.getBlockId(x, y, z))
|
||||
if(block == null)
|
||||
return 0
|
||||
|
||||
val block = world.getBlock(x, y, z)
|
||||
if(block.isInstanceOf[IRedstoneConnectorBlock])
|
||||
return block.asInstanceOf[IRedstoneConnectorBlock].getConnectionMask(world, x, y, z, side)
|
||||
|
||||
@@ -214,7 +208,7 @@ object RedstoneInteractions
|
||||
*/
|
||||
def vanillaConnectionMask(block:Block, world:IBlockAccess, x:Int, y:Int, z:Int, side:Int, power:Boolean):Int =
|
||||
{
|
||||
if(fullVanillaBlocks(block.blockID))
|
||||
if(fullVanillaBlocks(block))
|
||||
return 0x1F
|
||||
|
||||
if(side == 0)//vanilla doesn't handle side 0
|
||||
@@ -224,7 +218,7 @@ object RedstoneInteractions
|
||||
* so that these can be conducted to from face parts on the other side of the block.
|
||||
* Due to vanilla's in adequecy with redstone/logic on walls
|
||||
*/
|
||||
if(block == Block.redstoneWire || block == Block.redstoneComparatorActive || block == Block.redstoneComparatorIdle) {
|
||||
if(block == Blocks.redstone_wire || block == Blocks.powered_comparator || block == Blocks.unpowered_comparator) {
|
||||
if(side != 0)
|
||||
return if(power) 0x1F else 4
|
||||
|
||||
@@ -232,7 +226,7 @@ object RedstoneInteractions
|
||||
}
|
||||
|
||||
val vside = vanillaSideMap(side)
|
||||
if(block == Block.redstoneRepeaterActive || block == Block.redstoneRepeaterIdle)//stupid minecraft hardcodes
|
||||
if(block == Blocks.powered_repeater || block == Blocks.unpowered_repeater)//stupid minecraft hardcodes
|
||||
{
|
||||
val meta = world.getBlockMetadata(x, y, z)
|
||||
if(vside == (meta & 3) || vside == Direction.rotateOpposite(meta & 3))
|
||||
|
||||
@@ -11,7 +11,7 @@ import codechicken.lib.vec.BlockCoord
|
||||
/**
|
||||
* Java class implementation
|
||||
*/
|
||||
abstract class JItemMultiPart(id:Int) extends Item(id) with TItemMultiPart
|
||||
abstract class JItemMultiPart extends Item with TItemMultiPart
|
||||
|
||||
/**
|
||||
* Simple multipart item class for easy placement. Simply override the newPart function and it the part will be added to the block space if it passes the occlusion tests.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package codechicken.multipart
|
||||
|
||||
import scala.collection.mutable.HashMap
|
||||
import scala.collection.mutable.{Map => MMap}
|
||||
import codechicken.lib.packet.PacketCustom
|
||||
import codechicken.lib.data.MCDataOutput
|
||||
import codechicken.lib.data.MCDataInput
|
||||
@@ -9,6 +9,10 @@ import codechicken.lib.vec.BlockCoord
|
||||
import scala.collection.mutable.ListBuffer
|
||||
import cpw.mods.fml.common.ModContainer
|
||||
import cpw.mods.fml.common.Loader
|
||||
import net.minecraft.block.Block
|
||||
import java.lang.Iterable
|
||||
import com.google.common.collect.ArrayListMultimap
|
||||
import scala.collection.JavaConversions._
|
||||
|
||||
/**
|
||||
* This class handles the registration and internal ID mapping of all multipart classes.
|
||||
@@ -25,9 +29,9 @@ object MultiPartRegistry
|
||||
* Create a new instance of the part with the specified type name identifier
|
||||
* @param client If the part instance is for the client or the server
|
||||
*/
|
||||
def createPart(name:String, client:Boolean):TMultiPart
|
||||
def createPart(name: String, client: Boolean): TMultiPart
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* An interface for converting existing blocks/tile entities to multipart versions.
|
||||
*/
|
||||
@@ -36,93 +40,86 @@ object MultiPartRegistry
|
||||
/**
|
||||
* Return true if this converter can handle the specific blockID (may or may not actually convert the block)
|
||||
*/
|
||||
def canConvert(blockID:Int):Boolean
|
||||
def blockTypes: Iterable[Block]
|
||||
|
||||
/**
|
||||
* Return a multipart version of the block at pos in world. Return null if no conversion is possible.
|
||||
*/
|
||||
def convert(world:World, pos:BlockCoord):TMultiPart
|
||||
def convert(world: World, pos: BlockCoord): TMultiPart
|
||||
}
|
||||
|
||||
private val typeMap:HashMap[String, (Boolean)=>TMultiPart] = new HashMap
|
||||
private val nameMap:HashMap[String, Int] = new HashMap
|
||||
private var idMap:Array[(String, (Boolean)=>TMultiPart)] = _
|
||||
|
||||
private val typeMap = MMap[String, (Boolean) => TMultiPart]()
|
||||
private val nameMap = MMap[String, Int]()
|
||||
private var idMap: Array[(String, (Boolean) => TMultiPart)] = _
|
||||
private val idWriter = new IDWriter
|
||||
private val converters:Array[Seq[IPartConverter]] = Array.fill(4096)(Seq())
|
||||
private val containers:HashMap[String, ModContainer] = new HashMap()
|
||||
|
||||
private val converters = ArrayListMultimap.create[Block, IPartConverter]()
|
||||
private val containers = MMap[String, ModContainer]()
|
||||
|
||||
/**
|
||||
* The state of the registry. 0 = no parts, 1 = registering, 2 = registered
|
||||
*/
|
||||
private var state:Int = 0
|
||||
|
||||
private var state: Int = 0
|
||||
|
||||
/**
|
||||
* Register a part factory with an array of types it is capable of instantiating. Must be called before postInit
|
||||
*/
|
||||
def registerParts(partFactory:IPartFactory, types:Array[String])
|
||||
{
|
||||
registerParts(partFactory.createPart _, types:_*)
|
||||
def registerParts(partFactory: IPartFactory, types: Array[String]) {
|
||||
registerParts(partFactory.createPart _, types: _*)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Scala function version of registerParts
|
||||
*/
|
||||
def registerParts(partFactory:(String, Boolean)=>TMultiPart, types:String*)
|
||||
{
|
||||
if(loaded)
|
||||
def registerParts(partFactory: (String, Boolean) => TMultiPart, types: String*) {
|
||||
if (loaded)
|
||||
throw new IllegalStateException("Parts must be registered in the init methods.")
|
||||
state=1
|
||||
|
||||
val container = Loader.instance.activeModContainer
|
||||
if(container == null)
|
||||
throw new IllegalStateException("Parts must be registered during the initialization phase of a mod container")
|
||||
|
||||
types.foreach{s =>
|
||||
if(typeMap.contains(s))
|
||||
throw new IllegalStateException("Part with id "+s+" is already registered.")
|
||||
state = 1
|
||||
|
||||
typeMap.put(s, (c:Boolean) => partFactory(s, c))
|
||||
containers.put(s, container)
|
||||
val container = Loader.instance.activeModContainer
|
||||
if (container == null)
|
||||
throw new IllegalStateException("Parts must be registered during the initialization phase of a mod container")
|
||||
|
||||
types.foreach {
|
||||
s =>
|
||||
if (typeMap.contains(s))
|
||||
throw new IllegalStateException("Part with id " + s + " is already registered.")
|
||||
|
||||
typeMap.put(s, (c: Boolean) => partFactory(s, c))
|
||||
containers.put(s, container)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register a part converter instance
|
||||
*/
|
||||
def registerConverter(c:IPartConverter)
|
||||
{
|
||||
for(i <- 0 until 4096)
|
||||
if(c.canConvert(i))
|
||||
converters(i) = converters(i):+c
|
||||
def registerConverter(c: IPartConverter) {
|
||||
c.blockTypes.foreach(converters.put(_, c))
|
||||
}
|
||||
|
||||
private[multipart] def beforeServerStart()
|
||||
{
|
||||
|
||||
private[multipart] def beforeServerStart() {
|
||||
idMap = typeMap.toList.sortBy(_._1).toArray
|
||||
idWriter.setMax(idMap.length)
|
||||
nameMap.clear()
|
||||
for(i <- 0 until idMap.length)
|
||||
for (i <- 0 until idMap.length)
|
||||
nameMap.put(idMap(i)._1, i)
|
||||
}
|
||||
|
||||
private[multipart] def writeIDMap(packet:PacketCustom)
|
||||
{
|
||||
|
||||
private[multipart] def writeIDMap(packet: PacketCustom) {
|
||||
packet.writeInt(idMap.length)
|
||||
idMap.foreach(e => packet.writeString(e._1))
|
||||
}
|
||||
|
||||
private[multipart] def readIDMap(packet:PacketCustom):Seq[String] =
|
||||
{
|
||||
|
||||
private[multipart] def readIDMap(packet: PacketCustom): Seq[String] = {
|
||||
val k = packet.readInt()
|
||||
idWriter.setMax(k)
|
||||
idMap = new Array(k)
|
||||
nameMap.clear()
|
||||
val missing = ListBuffer[String]()
|
||||
for(i <- 0 until k)
|
||||
{
|
||||
for (i <- 0 until k) {
|
||||
val s = packet.readString()
|
||||
val v = typeMap.get(s)
|
||||
if(v.isEmpty)
|
||||
missing+=s
|
||||
if (v.isEmpty)
|
||||
missing += s
|
||||
else {
|
||||
idMap(i) = (s, v.get)
|
||||
nameMap.put(s, i)
|
||||
@@ -130,59 +127,57 @@ object MultiPartRegistry
|
||||
}
|
||||
return missing
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return true if any multiparts have been registered
|
||||
*/
|
||||
private[multipart] def required = state > 0
|
||||
|
||||
|
||||
/**
|
||||
* Return true if no more parts can be registered
|
||||
*/
|
||||
def loaded = state == 2
|
||||
|
||||
private[multipart] def postInit(){state = 2}
|
||||
|
||||
|
||||
private[multipart] def postInit() {
|
||||
state = 2
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the id of part to data
|
||||
*/
|
||||
def writePartID(data:MCDataOutput, part:TMultiPart)
|
||||
{
|
||||
def writePartID(data: MCDataOutput, part: TMultiPart) {
|
||||
idWriter.write(data, nameMap.get(part.getType).get)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Uses instantiators to creat a new part from the id read from data
|
||||
*/
|
||||
def readPart(data:MCDataInput) = idMap(idWriter.read(data))._2(true)
|
||||
|
||||
def readPart(data: MCDataInput) = idMap(idWriter.read(data))._2(true)
|
||||
|
||||
/**
|
||||
* Uses instantiators to create a new part with specified identifier on side
|
||||
*/
|
||||
def createPart(name:String, client:Boolean):TMultiPart =
|
||||
{
|
||||
def createPart(name: String, client: Boolean): TMultiPart = {
|
||||
val part = typeMap.get(name)
|
||||
if(part.isDefined)
|
||||
if (part.isDefined)
|
||||
return part.get(client)
|
||||
else
|
||||
{
|
||||
System.err.println("Missing mapping for part with ID: "+name)
|
||||
else {
|
||||
System.err.println("Missing mapping for part with ID: " + name)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calls converters to create a multipart version of the block at pos
|
||||
*/
|
||||
def convertBlock(world:World, pos:BlockCoord, id:Int):TMultiPart =
|
||||
{
|
||||
converters(id).foreach{c =>
|
||||
def convertBlock(world: World, pos: BlockCoord, block: Block): TMultiPart = {
|
||||
for (c <- converters.get(block)) {
|
||||
val ret = c.convert(world, pos)
|
||||
if(ret != null)
|
||||
if (ret != null)
|
||||
return ret
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
def getModContainer(name:String) = containers(name)
|
||||
|
||||
def getModContainer(name: String) = containers(name)
|
||||
}
|
||||
@@ -6,9 +6,9 @@ import net.minecraft.world.World
|
||||
import codechicken.lib.vec.BlockCoord
|
||||
import codechicken.multipart.handler.MultipartProxy
|
||||
import codechicken.lib.packet.PacketCustom
|
||||
import net.minecraft.network.packet.Packet53BlockChange
|
||||
import codechicken.multipart.asm.IMultipartFactory
|
||||
import codechicken.multipart.asm.ASMMixinFactory
|
||||
import net.minecraft.network.play.server.S23PacketBlockChange
|
||||
|
||||
/**
|
||||
* This class manages the dynamic construction and allocation of container TileMultipart instances.
|
||||
@@ -71,9 +71,9 @@ object MultipartGenerator
|
||||
if(converted)//perform client conversion
|
||||
{
|
||||
ntile.partList(0).invalidateConvertedTile()
|
||||
world.setBlock(pos.x, pos.y, pos.z, MultipartProxy.block.blockID, 0, 0)
|
||||
world.setBlock(pos.x, pos.y, pos.z, MultipartProxy.block, 0, 0)
|
||||
silentAddTile(world, pos, ntile)
|
||||
PacketCustom.sendToChunk(new Packet53BlockChange(pos.x, pos.y, pos.z, world), world, pos.x>>4, pos.z>>4)
|
||||
PacketCustom.sendToChunk(new S23PacketBlockChange(pos.x, pos.y, pos.z, world), world, pos.x>>4, pos.z>>4)
|
||||
ntile.partList(0).onConverted()
|
||||
ntile.writeAddPart(ntile.partList(0))
|
||||
}
|
||||
@@ -90,7 +90,7 @@ object MultipartGenerator
|
||||
}
|
||||
else
|
||||
{
|
||||
world.setBlock(pos.x, pos.y, pos.z, MultipartProxy.block.blockID, 0, 0)
|
||||
world.setBlock(pos.x, pos.y, pos.z, MultipartProxy.block, 0, 0)
|
||||
ntile = factory.generateTile(partTraits, world.isRemote)
|
||||
silentAddTile(world, pos, ntile)
|
||||
}
|
||||
@@ -105,7 +105,7 @@ object MultipartGenerator
|
||||
{
|
||||
val chunk = world.getChunkFromBlockCoords(pos.x, pos.z)
|
||||
if(chunk != null)
|
||||
chunk.setChunkBlockTileEntity(pos.x & 15, pos.y, pos.z & 15, tile)
|
||||
chunk.func_150812_a(pos.x & 15, pos.y, pos.z & 15, tile)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,10 +113,10 @@ object MultipartGenerator
|
||||
*/
|
||||
private[multipart] def generateCompositeTile(tile:TileEntity, parts:Seq[TMultiPart], client:Boolean):TileMultipart =
|
||||
{
|
||||
var partTraits = parts.flatMap(traitsForPart(_, client)).distinct
|
||||
val partTraits = parts.flatMap(traitsForPart(_, client)).distinct
|
||||
if(tile != null && tile.isInstanceOf[TileMultipart])
|
||||
{
|
||||
var tileTraits = tileTraitMap(tile.getClass)
|
||||
val tileTraits = tileTraitMap(tile.getClass)
|
||||
if(partTraits.forall(tileTraits(_)) && partTraits.size == tileTraits.size)//equal contents
|
||||
return tile.asInstanceOf[TileMultipart]
|
||||
|
||||
@@ -129,14 +129,14 @@ object MultipartGenerator
|
||||
*/
|
||||
private[multipart] def partRemoved(tile:TileMultipart, part:TMultiPart):TileMultipart =
|
||||
{
|
||||
val client = tile.worldObj.isRemote
|
||||
var partTraits = tile.partList.flatMap(traitsForPart(_, client))
|
||||
var testSet = partTraits.toSet
|
||||
val client = tile.getWorldObj.isRemote
|
||||
val partTraits = tile.partList.flatMap(traitsForPart(_, client))
|
||||
val testSet = partTraits.toSet
|
||||
if(!traitsForPart(part, client).forall(testSet(_)))
|
||||
{
|
||||
val ntile = factory.generateTile(testSet.toSeq, client)
|
||||
tile.setValid(false)
|
||||
silentAddTile(tile.worldObj, new BlockCoord(tile), ntile)
|
||||
silentAddTile(tile.getWorldObj, new BlockCoord(tile), ntile)
|
||||
ntile.from(tile)
|
||||
ntile.notifyTileChange()
|
||||
return ntile
|
||||
|
||||
@@ -9,8 +9,6 @@ import scala.collection.JavaConversions._
|
||||
import codechicken.multipart.handler.MultipartSPH
|
||||
import net.minecraft.world.WorldServer
|
||||
import java.util.Arrays
|
||||
import net.minecraft.server.management.PlayerInstance
|
||||
import codechicken.lib.asm.ObfMapping
|
||||
|
||||
/**
|
||||
* Static helper class for handling the unusual way that multipart tile entities load from nbt and send description packets
|
||||
@@ -27,12 +25,12 @@ import codechicken.lib.asm.ObfMapping
|
||||
*/
|
||||
object MultipartHelper
|
||||
{
|
||||
val f_playersInChunk = classOf[PlayerInstance].getDeclaredField(
|
||||
/*val f_playersInChunk = classOf[PlayerInstance].getDeclaredField(
|
||||
new ObfMapping("net/minecraft/server/management/PlayerInstance", "playersInChunk", "Ljava/util/List;")
|
||||
.toRuntime.s_name)
|
||||
f_playersInChunk.setAccessible(true)
|
||||
|
||||
def playersInChunk(inst:PlayerInstance) = f_playersInChunk.get(inst).asInstanceOf[List[_]]
|
||||
def playersInChunk(inst:PlayerInstance) = f_playersInChunk.get(inst).asInstanceOf[List[_]]*/
|
||||
|
||||
def createTileFromNBT(world:World, tag:NBTTagCompound):TileEntity = {
|
||||
if(!tag.getString("id").equals("savedMultipart"))
|
||||
@@ -62,7 +60,7 @@ object MultipartHelper
|
||||
val c = world.getChunkFromBlockCoords((coord>>32).toInt, coord.toInt)
|
||||
lazy val pkt = MultipartSPH.getDescPacket(c, e.getValue.iterator)
|
||||
val inst = mgr.getOrCreateChunkWatcher(c.xPosition, c.zPosition, false)
|
||||
if(!playersInChunk(inst).isEmpty)
|
||||
if(!inst.playersWatchingChunk.isEmpty)
|
||||
inst.sendToAllPlayersWatchingChunk(pkt.toPacket)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import codechicken.lib.vec.Vector3
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.client.renderer.RenderBlocks
|
||||
import net.minecraft.client.renderer.{Tessellator, RenderBlocks}
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraft.world.IBlockAccess
|
||||
@@ -13,7 +13,7 @@ import net.minecraft.client.Minecraft
|
||||
import cpw.mods.fml.relauncher.SideOnly
|
||||
import cpw.mods.fml.relauncher.Side
|
||||
import codechicken.lib.raytracer.ExtendedMOP
|
||||
import codechicken.lib.lighting.LazyLightMatrix
|
||||
import codechicken.lib.lighting.LightMatrix
|
||||
|
||||
/**
|
||||
* Internal class for rendering callbacks. Should be moved to the handler package
|
||||
@@ -22,8 +22,6 @@ import codechicken.lib.lighting.LazyLightMatrix
|
||||
object MultipartRenderer extends TileEntitySpecialRenderer with ISimpleBlockRenderingHandler
|
||||
{
|
||||
TileMultipart.renderID = RenderingRegistry.getNextAvailableRenderId
|
||||
private val olm = new LazyLightMatrix
|
||||
|
||||
var pass:Int = 0
|
||||
|
||||
override def renderTileEntityAt(t:TileEntity, x:Double, y:Double, z:Double, f:Float)
|
||||
@@ -34,7 +32,7 @@ object MultipartRenderer extends TileEntitySpecialRenderer with ISimpleBlockRend
|
||||
|
||||
CCRenderState.reset()
|
||||
CCRenderState.pullLightmap()
|
||||
CCRenderState.useNormals(true)
|
||||
CCRenderState.useNormals = true
|
||||
|
||||
val pos = new Vector3(x, y, z)
|
||||
tmpart.renderDynamic(pos, f, pass)
|
||||
@@ -44,7 +42,7 @@ object MultipartRenderer extends TileEntitySpecialRenderer with ISimpleBlockRend
|
||||
|
||||
override def renderWorldBlock(world:IBlockAccess, x:Int, y:Int, z:Int, block:Block, modelId:Int, renderer:RenderBlocks):Boolean =
|
||||
{
|
||||
val t = world.getBlockTileEntity(x, y, z)
|
||||
val t = world.getTileEntity(x, y, z)
|
||||
if(!t.isInstanceOf[TileMultipartClient])
|
||||
return false
|
||||
|
||||
@@ -65,14 +63,12 @@ object MultipartRenderer extends TileEntitySpecialRenderer with ISimpleBlockRend
|
||||
}
|
||||
|
||||
CCRenderState.reset()
|
||||
CCRenderState.useModelColours(true)
|
||||
val pos = new Vector3(x, y, z)
|
||||
olm.setPos(world, x, y, z)
|
||||
tmpart.renderStatic(pos, olm, pass)
|
||||
return true
|
||||
CCRenderState.lightMatrix.locate(world, x, y, z)
|
||||
return tmpart.renderStatic(new Vector3(x, y, z), pass)
|
||||
}
|
||||
|
||||
override def renderInventoryBlock(block:Block, meta:Int, modelId:Int, renderer:RenderBlocks) {}
|
||||
|
||||
override def shouldRender3DInInventory = false
|
||||
|
||||
|
||||
def shouldRender3DInInventory(modelId:Int) = false
|
||||
}
|
||||
@@ -17,7 +17,7 @@ object PacketScheduler
|
||||
/**
|
||||
* Add bits to the current update mask for part. (binary OR)
|
||||
*/
|
||||
def schedulePacket(part:TMultiPart, mask:Long) = {//TODO remove = in 1.7
|
||||
def schedulePacket(part:TMultiPart, mask:Long) {
|
||||
if(part.world.isRemote)
|
||||
throw new IllegalArgumentException("Cannot use PacketScheduler on a client world")
|
||||
|
||||
|
||||
@@ -3,12 +3,11 @@ package codechicken.multipart
|
||||
import codechicken.lib.vec.Cuboid6
|
||||
import codechicken.lib.raytracer.IndexedCuboid6
|
||||
import net.minecraft.client.renderer.RenderBlocks
|
||||
import codechicken.lib.render.CCRenderState
|
||||
import codechicken.lib.render.RenderUtils
|
||||
import codechicken.lib.render.IconTransformation
|
||||
import codechicken.lib.render.{BlockRenderer, CCRenderState, RenderUtils}
|
||||
import scala.collection.JavaConversions._
|
||||
import java.lang.Iterable
|
||||
import codechicken.lib.vec.Translation
|
||||
import codechicken.lib.render.uv.IconTransformation
|
||||
|
||||
/**
|
||||
* Java class implementation
|
||||
@@ -32,6 +31,7 @@ trait TCuboidPart extends TMultiPart
|
||||
override def drawBreaking(renderBlocks:RenderBlocks)
|
||||
{
|
||||
CCRenderState.reset()
|
||||
RenderUtils.renderBlock(getBounds, 0, new Translation(x, y, z), new IconTransformation(renderBlocks.overrideBlockTexture), null)
|
||||
CCRenderState.setPipeline(new Translation(x, y, z), new IconTransformation(renderBlocks.overrideBlockTexture))
|
||||
BlockRenderer.renderCuboid(getBounds, 0)
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package codechicken.multipart
|
||||
import codechicken.lib.vec.Cuboid6
|
||||
import cpw.mods.fml.relauncher.SideOnly
|
||||
import cpw.mods.fml.relauncher.Side
|
||||
import net.minecraft.util.Icon
|
||||
import net.minecraft.util.IIcon
|
||||
import net.minecraft.util.MovingObjectPosition
|
||||
import net.minecraft.client.particle.EffectRenderer
|
||||
import codechicken.lib.vec.Vector3
|
||||
@@ -24,7 +24,7 @@ object IconHitEffects
|
||||
{
|
||||
def addHitEffects(part:JIconHitEffects, hit:MovingObjectPosition, effectRenderer:EffectRenderer)
|
||||
{
|
||||
EntityDigIconFX.addBlockHitEffects(part.tile.worldObj,
|
||||
EntityDigIconFX.addBlockHitEffects(part.tile.getWorldObj,
|
||||
part.getBounds.copy.add(Vector3.fromTileEntity(part.tile)), hit.sideHit,
|
||||
part.getBreakingIcon(ExtendedMOP.getData(hit), hit.sideHit), effectRenderer)
|
||||
}
|
||||
@@ -36,13 +36,13 @@ object IconHitEffects
|
||||
|
||||
def addDestroyEffects(part:JIconHitEffects, effectRenderer:EffectRenderer, scaleDensity:Boolean)
|
||||
{
|
||||
val icons = new Array[Icon](6)
|
||||
val icons = new Array[IIcon](6)
|
||||
for(i <- 0 until 6)
|
||||
icons(i) = part.getBrokenIcon(i)
|
||||
val bounds =
|
||||
if(scaleDensity) part.getBounds.copy
|
||||
else Cuboid6.full.copy
|
||||
EntityDigIconFX.addBlockDestroyEffects(part.tile.worldObj,
|
||||
EntityDigIconFX.addBlockDestroyEffects(part.tile.getWorldObj,
|
||||
bounds.add(Vector3.fromTileEntity(part.tile)), icons, effectRenderer)
|
||||
}
|
||||
}
|
||||
@@ -56,10 +56,10 @@ trait JIconHitEffects extends TMultiPart
|
||||
def getBounds:Cuboid6
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
def getBreakingIcon(subPart:Any, side:Int):Icon = getBrokenIcon(side)
|
||||
def getBreakingIcon(subPart:Any, side:Int):IIcon = getBrokenIcon(side)
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
def getBrokenIcon(side:Int):Icon
|
||||
def getBrokenIcon(side:Int):IIcon
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,7 +13,7 @@ import net.minecraft.client.particle.EffectRenderer
|
||||
import net.minecraft.client.renderer.RenderBlocks
|
||||
import codechicken.lib.vec.BlockCoord
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import codechicken.lib.lighting.LazyLightMatrix
|
||||
import codechicken.lib.lighting.LightMatrix
|
||||
import codechicken.lib.data.MCDataOutput
|
||||
import codechicken.lib.data.MCDataInput
|
||||
import net.minecraft.entity.Entity
|
||||
@@ -38,7 +38,7 @@ abstract class TMultiPart
|
||||
/**
|
||||
* Getter for tile.worldObj
|
||||
*/
|
||||
def world = if(tile == null) null else tile.worldObj
|
||||
def world = if(tile == null) null else tile.getWorldObj
|
||||
/**
|
||||
* Short getter for xCoord
|
||||
*/
|
||||
@@ -140,11 +140,11 @@ abstract class TMultiPart
|
||||
/**
|
||||
* Render the static, unmoving faces of this part into the world renderer.
|
||||
* The Tessellator is already drawing.
|
||||
* @param olm An optional light matrix to be used for rendering things with perfect MC blended lighting (eg microblocks). Only use this if you have to.
|
||||
* @param pass The render pass, 1 or 0
|
||||
* @return true if vertices were added to the tessellator
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
def renderStatic(pos:Vector3, olm:LazyLightMatrix, pass:Int){}
|
||||
def renderStatic(pos:Vector3, pass:Int) = false
|
||||
/**
|
||||
* Render the dynamic, changing faces of this part and other gfx as in a TESR.
|
||||
* The Tessellator will need to be started if it is to be used.
|
||||
|
||||
@@ -5,9 +5,8 @@ import codechicken.lib.world.WorldExtension
|
||||
import codechicken.lib.world.ChunkExtension
|
||||
import net.minecraft.world.chunk.Chunk
|
||||
import net.minecraft.world.World
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.nbt.{NBTBase, NBTTagCompound, NBTTagList, CompressedStreamTools}
|
||||
import scala.collection.mutable.ListBuffer
|
||||
import net.minecraft.nbt.NBTTagList
|
||||
import codechicken.lib.vec.BlockCoord
|
||||
import net.minecraft.world.ChunkCoordIntPair
|
||||
import net.minecraft.world.ChunkPosition
|
||||
@@ -16,7 +15,6 @@ import java.io.DataOutputStream
|
||||
import net.minecraftforge.common.DimensionManager
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import net.minecraft.nbt.CompressedStreamTools
|
||||
import java.io.DataInputStream
|
||||
import java.io.FileInputStream
|
||||
import net.minecraft.world.storage.SaveHandler
|
||||
@@ -218,11 +216,11 @@ object TickScheduler extends WorldExtensionInstantiator
|
||||
if(!data.hasKey("multipartTicks"))
|
||||
return
|
||||
|
||||
val tagList = data.getTagList("multipartTicks")
|
||||
val tagList = data.getTagList("multipartTicks", 10)
|
||||
val cc = new ChunkCoordIntPair(0, 0)
|
||||
for(i <- 0 until tagList.tagCount)
|
||||
{
|
||||
val tag = tagList.tagAt(i).asInstanceOf[NBTTagCompound]
|
||||
val tag = tagList.getCompoundTagAt(i)
|
||||
val pos = indexInChunk(cc, tag.getShort("pos"))
|
||||
val tile = chunk.chunkTileEntityMap.get(new ChunkPosition(pos.x, pos.y, pos.z))
|
||||
if(tile.isInstanceOf[TileMultipart])
|
||||
@@ -261,7 +259,7 @@ object TickScheduler extends WorldExtensionInstantiator
|
||||
|
||||
private[multipart] def loadRandomTick(part:TMultiPart)
|
||||
{
|
||||
getExtension(part.tile.worldObj).asInstanceOf[WorldTickScheduler].loadRandom(part)
|
||||
getExtension(part.tile.getWorldObj).asInstanceOf[WorldTickScheduler].loadRandom(part)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -269,7 +267,7 @@ object TickScheduler extends WorldExtensionInstantiator
|
||||
*/
|
||||
def scheduleTick(part:TMultiPart, ticks:Int)
|
||||
{
|
||||
getExtension(part.tile.worldObj).asInstanceOf[WorldTickScheduler].scheduleTick(part, ticks, false)
|
||||
getExtension(part.tile.getWorldObj).asInstanceOf[WorldTickScheduler].scheduleTick(part, ticks, false)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,7 +13,7 @@ import net.minecraft.block.Block
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagList
|
||||
import java.util.Random
|
||||
import codechicken.lib.lighting.LazyLightMatrix
|
||||
import codechicken.lib.lighting.LightMatrix
|
||||
import net.minecraft.entity.item.EntityItem
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.entity.Entity
|
||||
@@ -129,8 +129,8 @@ class TileMultipart extends TileEntity
|
||||
{
|
||||
internalPartChange(part)
|
||||
|
||||
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, MultipartProxy.block.blockID)
|
||||
worldObj.updateAllLightTypes(xCoord, yCoord, zCoord)
|
||||
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, MultipartProxy.block)
|
||||
worldObj.func_147451_t(xCoord, yCoord, zCoord)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,7 +154,7 @@ class TileMultipart extends TileEntity
|
||||
*/
|
||||
def notifyTileChange()
|
||||
{
|
||||
worldObj.func_96440_m(xCoord, yCoord, zCoord, 0)
|
||||
worldObj.func_147453_f(xCoord, yCoord, zCoord, MultipartProxy.block)
|
||||
}
|
||||
|
||||
def onNeighborBlockChange()
|
||||
@@ -166,6 +166,11 @@ class TileMultipart extends TileEntity
|
||||
* Blank implementation, overriden by TTileChangeTile
|
||||
*/
|
||||
def onNeighborTileChange(tileX:Int, tileY:Int, tileZ:Int) {}
|
||||
|
||||
/**
|
||||
* Blank implementation, overriden by TTileChangeTile
|
||||
*/
|
||||
def getWeakChanges() = false
|
||||
|
||||
def getLightValue = partList.view.map(_.getLightValue).max
|
||||
|
||||
@@ -174,7 +179,7 @@ class TileMultipart extends TileEntity
|
||||
/**
|
||||
* Callback for parts to mark the chunk as needs saving
|
||||
*/
|
||||
def markDirty()
|
||||
override def markDirty()
|
||||
{
|
||||
worldObj.markTileEntityChunkModified(xCoord, yCoord, zCoord, this)
|
||||
}
|
||||
@@ -184,7 +189,7 @@ class TileMultipart extends TileEntity
|
||||
*/
|
||||
def markRender()
|
||||
{
|
||||
worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord)
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -193,7 +198,7 @@ class TileMultipart extends TileEntity
|
||||
def notifyNeighborChange(side:Int)
|
||||
{
|
||||
val pos = new BlockCoord(this).offset(side)
|
||||
worldObj.notifyBlocksOfNeighborChange(pos.x, pos.y, pos.z, MultipartProxy.block.blockID)
|
||||
worldObj.notifyBlocksOfNeighborChange(pos.x, pos.y, pos.z, MultipartProxy.block)
|
||||
}
|
||||
|
||||
def isSolid(side:Int):Boolean =
|
||||
@@ -211,12 +216,12 @@ class TileMultipart extends TileEntity
|
||||
return
|
||||
|
||||
doesTick = tick
|
||||
if(worldObj != null && worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this)
|
||||
if(worldObj != null && worldObj.getTileEntity(xCoord, yCoord, zCoord) == this)
|
||||
{
|
||||
if(tick)
|
||||
worldObj.addTileEntity(this)
|
||||
else
|
||||
worldObj.markTileEntityForDespawn(this)
|
||||
worldObj.func_147457_a(this)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -484,11 +489,9 @@ class TileMultipart extends TileEntity
|
||||
|
||||
class TileMultipartClient extends TileMultipart
|
||||
{
|
||||
def renderStatic(pos:Vector3, olm:LazyLightMatrix, pass:Int)
|
||||
{
|
||||
partList.foreach(part => part.renderStatic(pos, olm, pass))
|
||||
}
|
||||
|
||||
def renderStatic(pos:Vector3, pass:Int) =
|
||||
partList.foldLeft(false)((r, part) => part.renderStatic(pos, pass) || r)
|
||||
|
||||
def renderDynamic(pos:Vector3, frame:Float, pass:Int)
|
||||
{
|
||||
partList.foreach(part => part.renderDynamic(pos, frame, pass:Int))
|
||||
@@ -539,12 +542,11 @@ object TileMultipart
|
||||
*/
|
||||
def getOrConvertTile2(world:World, pos:BlockCoord):(TileMultipart, Boolean) =
|
||||
{
|
||||
val t = world.getBlockTileEntity(pos.x, pos.y, pos.z)
|
||||
val t = world.getTileEntity(pos.x, pos.y, pos.z)
|
||||
if(t.isInstanceOf[TileMultipart])
|
||||
return (t.asInstanceOf[TileMultipart], false)
|
||||
|
||||
val id = world.getBlockId(pos.x, pos.y, pos.z)
|
||||
val p = MultiPartRegistry.convertBlock(world, pos, id)
|
||||
val p = MultiPartRegistry.convertBlock(world, pos, world.getBlock(pos.x, pos.y, pos.z))
|
||||
if(p != null)
|
||||
{
|
||||
val t = MultipartGenerator.generateCompositeTile(null, Seq(p), world.isRemote)
|
||||
@@ -562,7 +564,7 @@ object TileMultipart
|
||||
* Gets the multipart tile instance at pos, or null if it doesn't exist or is not a multipart tile
|
||||
*/
|
||||
def getTile(world:World, pos:BlockCoord) =
|
||||
world.getBlockTileEntity(pos.x, pos.y, pos.z) match {
|
||||
world.getTileEntity(pos.x, pos.y, pos.z) match {
|
||||
case t:TileMultipart => t
|
||||
case _ => null
|
||||
}
|
||||
@@ -596,8 +598,8 @@ object TileMultipart
|
||||
*/
|
||||
def replaceable(world:World, pos:BlockCoord):Boolean =
|
||||
{
|
||||
val block = Block.blocksList(world.getBlockId(pos.x, pos.y, pos.z))
|
||||
return block == null || block.isAirBlock(world, pos.x, pos.y, pos.z) || block.isBlockReplaceable(world, pos.x, pos.y, pos.z)
|
||||
val block = world.getBlock(pos.x, pos.y, pos.z)
|
||||
return block.isAir(world, pos.x, pos.y, pos.z) || block.isReplaceable(world, pos.x, pos.y, pos.z)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -627,10 +629,10 @@ object TileMultipart
|
||||
if(parts.size == 0)
|
||||
return
|
||||
|
||||
val t = world.getBlockTileEntity(pos.x, pos.y, pos.z)
|
||||
val t = world.getTileEntity(pos.x, pos.y, pos.z)
|
||||
val tilemp = MultipartGenerator.generateCompositeTile(t, parts, true)
|
||||
if(tilemp != t) {
|
||||
world.setBlock(pos.x, pos.y, pos.z, MultipartProxy.block.blockID)
|
||||
world.setBlock(pos.x, pos.y, pos.z, MultipartProxy.block)
|
||||
MultipartGenerator.silentAddTile(world, pos, tilemp)
|
||||
}
|
||||
|
||||
@@ -662,12 +664,12 @@ object TileMultipart
|
||||
*/
|
||||
def createFromNBT(tag:NBTTagCompound):TileMultipart =
|
||||
{
|
||||
val partList = tag.getTagList("parts")
|
||||
val partList = tag.getTagList("parts", 10)
|
||||
val parts = ListBuffer[TMultiPart]()
|
||||
|
||||
for(i <- 0 until partList.tagCount)
|
||||
{
|
||||
val partTag = partList.tagAt(i).asInstanceOf[NBTTagCompound]
|
||||
val partTag = partList.getCompoundTagAt(i)
|
||||
val partID = partTag.getString("id")
|
||||
val part = MultiPartRegistry.createPart(partID, false)
|
||||
if(part != null)
|
||||
|
||||
@@ -1,92 +1,67 @@
|
||||
package codechicken.multipart.handler
|
||||
|
||||
import codechicken.multipart.TileMultipart
|
||||
import net.minecraftforge.event.ForgeSubscribe
|
||||
import cpw.mods.fml.common.network.IConnectionHandler
|
||||
import net.minecraft.network.packet.NetHandler
|
||||
import net.minecraft.network.INetworkManager
|
||||
import net.minecraft.network.packet.Packet1Login
|
||||
import cpw.mods.fml.common.network.Player
|
||||
import net.minecraft.network.NetLoginHandler
|
||||
import cpw.mods.fml.common.eventhandler.{EventPriority, SubscribeEvent}
|
||||
import net.minecraft.server.MinecraftServer
|
||||
import codechicken.lib.packet.PacketCustom
|
||||
import codechicken.multipart.MultiPartRegistry
|
||||
import net.minecraftforge.event.world._
|
||||
import cpw.mods.fml.common.ITickHandler
|
||||
import java.util.EnumSet
|
||||
import cpw.mods.fml.common.TickType
|
||||
import scala.collection.JavaConverters._
|
||||
import java.util.List
|
||||
import net.minecraft.entity.player.EntityPlayerMP
|
||||
import net.minecraftforge.event.EventPriority
|
||||
import cpw.mods.fml.relauncher.SideOnly
|
||||
import cpw.mods.fml.relauncher.Side
|
||||
import net.minecraftforge.client.event.DrawBlockHighlightEvent
|
||||
import net.minecraft.util.EnumMovingObjectType
|
||||
import codechicken.multipart.BlockMultipart
|
||||
import net.minecraft.util.MovingObjectPosition
|
||||
import net.minecraft.util.MovingObjectPosition.MovingObjectType
|
||||
import cpw.mods.fml.common.gameevent.TickEvent
|
||||
|
||||
object MultipartEventHandler extends IConnectionHandler with ITickHandler
|
||||
object MultipartEventHandler
|
||||
{
|
||||
@ForgeSubscribe(priority = EventPriority.HIGHEST)
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
def tileEntityLoad(event:ChunkDataEvent.Load)
|
||||
{
|
||||
MultipartSaveLoad.loadTiles(event.getChunk)
|
||||
}
|
||||
|
||||
@ForgeSubscribe
|
||||
@SubscribeEvent
|
||||
def worldUnLoad(event:WorldEvent.Unload)
|
||||
{
|
||||
MultipartSPH.onWorldUnload(event.world)
|
||||
}
|
||||
|
||||
@ForgeSubscribe
|
||||
@SubscribeEvent
|
||||
def chunkWatch(event:ChunkWatchEvent.Watch)
|
||||
{
|
||||
MultipartSPH.onChunkWatch(event.player, event.chunk)
|
||||
}
|
||||
|
||||
@ForgeSubscribe
|
||||
@SubscribeEvent
|
||||
def chunkUnWatch(event:ChunkWatchEvent.UnWatch)
|
||||
{
|
||||
MultipartSPH.onChunkUnWatch(event.player, event.chunk)
|
||||
}
|
||||
|
||||
@ForgeSubscribe
|
||||
@SubscribeEvent
|
||||
@SideOnly(Side.CLIENT)
|
||||
def drawBlockHighlight(event:DrawBlockHighlightEvent)
|
||||
{
|
||||
if(event.target != null && event.target.typeOfHit == EnumMovingObjectType.TILE &&
|
||||
event.player.worldObj.getBlockTileEntity(event.target.blockX, event.target.blockY, event.target.blockZ).isInstanceOf[TileMultipart])
|
||||
if(event.target != null && event.target.typeOfHit == MovingObjectType.BLOCK &&
|
||||
event.player.worldObj.getTileEntity(event.target.blockX, event.target.blockY, event.target.blockZ).isInstanceOf[TileMultipart])
|
||||
{
|
||||
if(BlockMultipart.drawHighlight(event.player.worldObj, event.player, event.target, event.partialTicks))
|
||||
event.setCanceled(true)
|
||||
}
|
||||
}
|
||||
|
||||
def connectionReceived(loginHandler:NetLoginHandler, netManager:INetworkManager):String =
|
||||
|
||||
@SubscribeEvent
|
||||
def serverTick(event:TickEvent.ServerTickEvent)
|
||||
{
|
||||
val packet = new PacketCustom(MultipartSPH.registryChannel, 1)
|
||||
MultiPartRegistry.writeIDMap(packet)
|
||||
netManager.addToSendQueue(packet.toPacket)
|
||||
return null
|
||||
}
|
||||
|
||||
def clientLoggedIn(netHandler:NetHandler, netManager:INetworkManager, packet:Packet1Login){}
|
||||
def playerLoggedIn(player:Player, netHandler:NetHandler, netManager:INetworkManager){}
|
||||
def connectionOpened(netHandler:NetHandler, server:String, port:Int, netManager:INetworkManager){}
|
||||
def connectionOpened(netHandler:NetHandler, server:MinecraftServer, netManager:INetworkManager){}
|
||||
def connectionClosed(netManager:INetworkManager){}
|
||||
|
||||
def ticks = EnumSet.of(TickType.SERVER)
|
||||
def getLabel = "Multipart"
|
||||
def tickStart(tickType:EnumSet[TickType], data:Object*){}
|
||||
def tickEnd(tickType:EnumSet[TickType], data:Object*)
|
||||
{
|
||||
if(tickType.contains(TickType.SERVER))
|
||||
{
|
||||
if(event.phase == TickEvent.Phase.END)
|
||||
MultipartSPH.onTickEnd(
|
||||
MinecraftServer.getServer.getConfigurationManager.playerEntityList
|
||||
.asInstanceOf[List[EntityPlayerMP]].asScala)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package codechicken.multipart.handler
|
||||
|
||||
import cpw.mods.fml.common.network.NetworkMod
|
||||
import cpw.mods.fml.common.Mod
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent
|
||||
@@ -8,11 +7,9 @@ import cpw.mods.fml.common.event.FMLInitializationEvent
|
||||
import cpw.mods.fml.common.Mod.EventHandler
|
||||
import cpw.mods.fml.common.event.FMLServerAboutToStartEvent
|
||||
import codechicken.multipart.MultiPartRegistry
|
||||
import codechicken.lib.packet.PacketCustom.CustomTinyPacketHandler
|
||||
|
||||
@Mod(modid = "ForgeMultipart", acceptedMinecraftVersions = "[1.6.4]",
|
||||
@Mod(modid = "ForgeMultipart", acceptedMinecraftVersions = "[1.7.2]",
|
||||
modLanguage="scala")
|
||||
@NetworkMod(clientSideRequired = true, serverSideRequired = true, tinyPacketHandler=classOf[CustomTinyPacketHandler])
|
||||
object MultipartMod
|
||||
{
|
||||
@EventHandler
|
||||
|
||||
@@ -14,57 +14,50 @@ import net.minecraft.world.World
|
||||
*/
|
||||
object MultipartSaveLoad
|
||||
{
|
||||
var loadingWorld:World = _
|
||||
|
||||
var loadingWorld: World = _
|
||||
|
||||
class TileNBTContainer extends TileEntity
|
||||
{
|
||||
var tag:NBTTagCompound = _
|
||||
|
||||
override def readFromNBT(t:NBTTagCompound)
|
||||
{
|
||||
var tag: NBTTagCompound = _
|
||||
|
||||
override def readFromNBT(t: NBTTagCompound) {
|
||||
super.readFromNBT(t)
|
||||
tag = t
|
||||
}
|
||||
}
|
||||
|
||||
def hookLoader()
|
||||
{
|
||||
|
||||
def hookLoader() {
|
||||
val field = classOf[TileEntity].getDeclaredField(
|
||||
new ObfMapping("net/minecraft/tileentity/TileEntity", "nameToClassMap", "Ljava/util/Map;")
|
||||
new ObfMapping("net/minecraft/tileentity/TileEntity", "field_145855_i", "Ljava/util/Map;")
|
||||
.toRuntime.s_name)
|
||||
field.setAccessible(true)
|
||||
val map = field.get(null).asInstanceOf[Map[String, Class[_ <: TileEntity]]]
|
||||
map.put("savedMultipart", classOf[TileNBTContainer])
|
||||
}
|
||||
|
||||
|
||||
private val classToNameMap = getClassToNameMap
|
||||
def registerTileClass(t:Class[_ <: TileEntity])
|
||||
{
|
||||
|
||||
def registerTileClass(t: Class[_ <: TileEntity]) {
|
||||
classToNameMap.put(t, "savedMultipart")
|
||||
}
|
||||
|
||||
def getClassToNameMap =
|
||||
{
|
||||
|
||||
def getClassToNameMap = {
|
||||
val field = classOf[TileEntity].getDeclaredField(
|
||||
new ObfMapping("net/minecraft/tileentity/TileEntity", "classToNameMap", "Ljava/util/Map;")
|
||||
new ObfMapping("net/minecraft/tileentity/TileEntity", "field_145853_j", "Ljava/util/Map;")
|
||||
.toRuntime.s_name)
|
||||
field.setAccessible(true)
|
||||
field.get(null).asInstanceOf[Map[Class[_ <: TileEntity], String]]
|
||||
}
|
||||
|
||||
def loadTiles(chunk:Chunk)
|
||||
{
|
||||
|
||||
def loadTiles(chunk: Chunk) {
|
||||
loadingWorld = chunk.worldObj
|
||||
val iterator = chunk.chunkTileEntityMap.asInstanceOf[Map[ChunkPosition, TileEntity]].entrySet.iterator
|
||||
while(iterator.hasNext)
|
||||
{
|
||||
while (iterator.hasNext) {
|
||||
val e = iterator.next
|
||||
if(e.getValue.isInstanceOf[TileNBTContainer])
|
||||
{
|
||||
if (e.getValue.isInstanceOf[TileNBTContainer]) {
|
||||
val t = TileMultipart.createFromNBT(e.getValue.asInstanceOf[TileNBTContainer].tag)
|
||||
if(t != null)
|
||||
{
|
||||
t.setWorldObj(e.getValue.worldObj)
|
||||
if (t != null) {
|
||||
t.setWorldObj(e.getValue.getWorldObj)
|
||||
t.validate()
|
||||
e.setValue(t)
|
||||
}
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
package codechicken.multipart.handler
|
||||
|
||||
import codechicken.lib.packet.PacketCustom.IClientPacketHandler
|
||||
import codechicken.lib.packet.PacketCustom.IServerPacketHandler
|
||||
import codechicken.lib.packet.PacketCustom.{IHandshakeHandler, IClientPacketHandler, IServerPacketHandler}
|
||||
import codechicken.lib.packet.PacketCustom
|
||||
import net.minecraft.client.multiplayer.NetClientHandler
|
||||
import net.minecraft.client.Minecraft
|
||||
import codechicken.multipart.MultiPartRegistry
|
||||
import net.minecraft.network.NetServerHandler
|
||||
import net.minecraft.entity.player.EntityPlayerMP
|
||||
import codechicken.multipart.ControlKeyModifer
|
||||
import net.minecraft.network.packet.Packet255KickDisconnect
|
||||
import net.minecraft.world.World
|
||||
import net.minecraft.world.chunk.Chunk
|
||||
import java.util.{Map => JMap}
|
||||
@@ -27,49 +23,46 @@ import MultipartProxy._
|
||||
import codechicken.multipart.PacketScheduler
|
||||
import java.util.LinkedList
|
||||
import scala.collection.JavaConversions._
|
||||
import net.minecraft.network.play.{INetHandlerPlayServer, INetHandlerPlayClient}
|
||||
import net.minecraft.network.play.server.S40PacketDisconnect
|
||||
import net.minecraft.util.ChatComponentTranslation
|
||||
import net.minecraft.network.NetHandlerPlayServer
|
||||
|
||||
class MultipartPH
|
||||
{
|
||||
val channel = MultipartMod
|
||||
val registryChannel = "ForgeMultipart"//Must use the 250 system for ID registry as the NetworkMod idMap hasn't been properly initialized from the server yet.
|
||||
val registryChannel = "ForgeMultipart"
|
||||
}
|
||||
|
||||
object MultipartCPH extends MultipartPH with IClientPacketHandler
|
||||
{
|
||||
def handlePacket(packet:PacketCustom, netHandler:NetClientHandler, mc:Minecraft)
|
||||
{
|
||||
packet.getType match
|
||||
{
|
||||
def handlePacket(packet: PacketCustom, mc: Minecraft, netHandler:INetHandlerPlayClient) {
|
||||
packet.getType match {
|
||||
case 1 => handlePartRegistration(packet, netHandler)
|
||||
case 2 => handleCompressedTileDesc(packet, mc.theWorld)
|
||||
case 3 => handleCompressedTileData(packet, mc.theWorld)
|
||||
}
|
||||
}
|
||||
|
||||
def handlePartRegistration(packet:PacketCustom, netHandler:NetClientHandler)
|
||||
{
|
||||
|
||||
def handlePartRegistration(packet: PacketCustom, netHandler: INetHandlerPlayClient) {
|
||||
val missing = MultiPartRegistry.readIDMap(packet)
|
||||
if(!missing.isEmpty)
|
||||
netHandler.handleKickDisconnect(new Packet255KickDisconnect("The following multiparts are not installed on this client: "+missing.mkString(", ")))
|
||||
if (!missing.isEmpty)
|
||||
netHandler.handleDisconnect(new S40PacketDisconnect(new ChatComponentTranslation("multipart.missing", missing.mkString(", "))))
|
||||
}
|
||||
|
||||
def handleCompressedTileDesc(packet:PacketCustom, world:World)
|
||||
{
|
||||
|
||||
def handleCompressedTileDesc(packet: PacketCustom, world: World) {
|
||||
val cc = new ChunkCoordIntPair(packet.readInt, packet.readInt)
|
||||
val num = packet.readUShort
|
||||
for(i <- 0 until num)
|
||||
for (i <- 0 until num)
|
||||
TileMultipart.handleDescPacket(world, indexInChunk(cc, packet.readShort), packet)
|
||||
}
|
||||
|
||||
def handleCompressedTileData(packet:PacketCustom, world:World)
|
||||
{
|
||||
|
||||
def handleCompressedTileData(packet: PacketCustom, world: World) {
|
||||
var x = packet.readInt
|
||||
while(x != Int.MaxValue)
|
||||
{
|
||||
while (x != Int.MaxValue) {
|
||||
val pos = new BlockCoord(x, packet.readInt, packet.readInt)
|
||||
var i = packet.readUByte
|
||||
while(i < 255)
|
||||
{
|
||||
while (i < 255) {
|
||||
TileMultipart.handlePacket(pos, world, i, packet)
|
||||
i = packet.readUByte
|
||||
}
|
||||
@@ -79,34 +72,37 @@ object MultipartCPH extends MultipartPH with IClientPacketHandler
|
||||
}
|
||||
}
|
||||
|
||||
object MultipartSPH extends MultipartPH with IServerPacketHandler
|
||||
object MultipartSPH extends MultipartPH with IServerPacketHandler with IHandshakeHandler
|
||||
{
|
||||
class MCByteStream(bout:ByteArrayOutputStream) extends MCOutputStreamWrapper(new DataOutputStream(bout))
|
||||
class MCByteStream(bout: ByteArrayOutputStream) extends MCOutputStreamWrapper(new DataOutputStream(bout))
|
||||
{
|
||||
def getBytes = bout.toByteArray
|
||||
}
|
||||
|
||||
|
||||
private val updateMap = Map[World, Map[BlockCoord, MCByteStream]]()
|
||||
private val chunkWatchers = new HashMap[EntityPlayer, Set[ChunkCoordIntPair]] with MultiMap[EntityPlayer, ChunkCoordIntPair]
|
||||
private val newWatchers = Map[EntityPlayer, LinkedList[ChunkCoordIntPair]]()
|
||||
|
||||
def handlePacket(packet:PacketCustom, netHandler:NetServerHandler, sender:EntityPlayerMP)
|
||||
{
|
||||
packet.getType match
|
||||
{
|
||||
def handlePacket(packet: PacketCustom, sender: EntityPlayerMP, netHandler:INetHandlerPlayServer) {
|
||||
packet.getType match {
|
||||
case 1 => ControlKeyModifer.map.put(sender, packet.readBoolean)
|
||||
}
|
||||
}
|
||||
|
||||
def onWorldUnload(world:World)
|
||||
{
|
||||
if(!world.isRemote)
|
||||
|
||||
def handshakeRecieved(netHandler: NetHandlerPlayServer) {
|
||||
val packet = new PacketCustom(registryChannel, 1)
|
||||
MultiPartRegistry.writeIDMap(packet)
|
||||
netHandler.sendPacket(packet.toPacket)
|
||||
}
|
||||
|
||||
def onWorldUnload(world: World) {
|
||||
if (!world.isRemote)
|
||||
updateMap.remove(world)
|
||||
}
|
||||
|
||||
def getTileStream(world:World, pos:BlockCoord) =
|
||||
|
||||
def getTileStream(world: World, pos: BlockCoord) =
|
||||
updateMap.getOrElseUpdate(world, {
|
||||
if(world.isRemote)
|
||||
if (world.isRemote)
|
||||
throw new IllegalArgumentException("Cannot use MultipartSPH on a client world")
|
||||
Map()
|
||||
}).getOrElseUpdate(pos, {
|
||||
@@ -114,73 +110,67 @@ object MultipartSPH extends MultipartPH with IServerPacketHandler
|
||||
s.writeCoord(pos)
|
||||
s
|
||||
})
|
||||
|
||||
def onTickEnd(players:Seq[EntityPlayerMP])
|
||||
{
|
||||
|
||||
def onTickEnd(players: Seq[EntityPlayerMP]) {
|
||||
PacketScheduler.sendScheduled()
|
||||
|
||||
for(p <- players if chunkWatchers.containsKey(p)) {
|
||||
for (p <- players if chunkWatchers.containsKey(p)) {
|
||||
updateMap.get(p.worldObj) match {
|
||||
case Some(m) if !m.isEmpty =>
|
||||
val chunks = chunkWatchers(p)
|
||||
val packet = new PacketCustom(channel, 3).setChunkDataPacket().compressed()
|
||||
val packet = new PacketCustom(channel, 3).compress()
|
||||
var send = false
|
||||
for((pos, stream) <- m if chunks(new ChunkCoordIntPair(pos.x>>4, pos.z>>4))) {
|
||||
for ((pos, stream) <- m if chunks(new ChunkCoordIntPair(pos.x >> 4, pos.z >> 4))) {
|
||||
send = true
|
||||
packet.writeByteArray(stream.getBytes)
|
||||
packet.writeByte(255)//terminator
|
||||
packet.writeByte(255) //terminator
|
||||
}
|
||||
if(send) {
|
||||
packet.writeInt(Int.MaxValue)//terminator
|
||||
if (send) {
|
||||
packet.writeInt(Int.MaxValue) //terminator
|
||||
packet.sendToPlayer(p)
|
||||
}
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
updateMap.foreach(_._2.clear())
|
||||
for((p, chunks) <- newWatchers) {
|
||||
chunks.foreach{ c =>
|
||||
val chunk = p.worldObj.getChunkFromChunkCoords(c.chunkXPos, c.chunkZPos)
|
||||
val pkt = getDescPacket(chunk, chunk.chunkTileEntityMap.asInstanceOf[JMap[_, TileEntity]].values.iterator)
|
||||
if(pkt != null) pkt.sendToPlayer(p)
|
||||
chunkWatchers.addBinding(p, c)
|
||||
for ((p, chunks) <- newWatchers) {
|
||||
chunks.foreach {
|
||||
c =>
|
||||
val chunk = p.worldObj.getChunkFromChunkCoords(c.chunkXPos, c.chunkZPos)
|
||||
val pkt = getDescPacket(chunk, chunk.chunkTileEntityMap.asInstanceOf[JMap[_, TileEntity]].values.iterator)
|
||||
if (pkt != null) pkt.sendToPlayer(p)
|
||||
chunkWatchers.addBinding(p, c)
|
||||
}
|
||||
chunks.clear()
|
||||
}
|
||||
}
|
||||
|
||||
def onChunkWatch(player:EntityPlayer, c:ChunkCoordIntPair)
|
||||
{
|
||||
|
||||
def onChunkWatch(player: EntityPlayer, c: ChunkCoordIntPair) {
|
||||
newWatchers.getOrElseUpdate(player, new LinkedList).add(c)
|
||||
}
|
||||
|
||||
def onChunkUnWatch(player:EntityPlayer, c:ChunkCoordIntPair)
|
||||
{
|
||||
def onChunkUnWatch(player: EntityPlayer, c: ChunkCoordIntPair) {
|
||||
newWatchers.get(player) match {
|
||||
case Some(chunks) => chunks.remove(c)
|
||||
case _ =>
|
||||
}
|
||||
chunkWatchers.removeBinding(player, c)
|
||||
}
|
||||
|
||||
def getDescPacket(chunk:Chunk, it:Iterator[TileEntity]):PacketCustom =
|
||||
{
|
||||
|
||||
def getDescPacket(chunk: Chunk, it: Iterator[TileEntity]): PacketCustom = {
|
||||
val s = new MCByteStream(new ByteArrayOutputStream)
|
||||
|
||||
|
||||
var num = 0
|
||||
while(it.hasNext)
|
||||
{
|
||||
while (it.hasNext) {
|
||||
val tile = it.next
|
||||
if(tile.isInstanceOf[TileMultipart])
|
||||
{
|
||||
if (tile.isInstanceOf[TileMultipart]) {
|
||||
s.writeShort(indexInChunk(new BlockCoord(tile)))
|
||||
tile.asInstanceOf[TileMultipart].writeDesc(s)
|
||||
num+=1
|
||||
num += 1
|
||||
}
|
||||
}
|
||||
if(num != 0)
|
||||
{
|
||||
return new PacketCustom(channel, 2).setChunkDataPacket().compressed()
|
||||
if (num != 0) {
|
||||
return new PacketCustom(channel, 2).compress()
|
||||
.writeInt(chunk.xPosition).writeInt(chunk.zPosition)
|
||||
.writeShort(num)
|
||||
.writeByteArray(s.getBytes)
|
||||
|
||||
@@ -1,27 +1,22 @@
|
||||
package codechicken.multipart.handler
|
||||
|
||||
import codechicken.multipart.BlockMultipart
|
||||
import codechicken.multipart._
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry
|
||||
import cpw.mods.fml.client.registry.ClientRegistry
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import codechicken.lib.config.ConfigFile
|
||||
import java.io.File
|
||||
import codechicken.multipart.handler.MultipartProxy._
|
||||
import codechicken.multipart.MultipartRenderer
|
||||
import net.minecraftforge.common.MinecraftForge
|
||||
import codechicken.multipart.MultipartGenerator
|
||||
import cpw.mods.fml.relauncher.SideOnly
|
||||
import cpw.mods.fml.relauncher.Side
|
||||
import codechicken.lib.packet.PacketCustom
|
||||
import cpw.mods.fml.client.registry.KeyBindingRegistry
|
||||
import codechicken.multipart.ControlKeyHandler
|
||||
import cpw.mods.fml.common.network.NetworkRegistry
|
||||
import cpw.mods.fml.common.registry.TickRegistry
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.world.ChunkCoordIntPair
|
||||
import codechicken.lib.vec.BlockCoord
|
||||
import codechicken.lib.world.WorldExtensionManager
|
||||
import codechicken.multipart.TickScheduler
|
||||
import cpw.mods.fml.common.FMLCommonHandler
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import net.minecraft.block.Block
|
||||
|
||||
class MultipartProxy_serverImpl
|
||||
{
|
||||
@@ -29,7 +24,10 @@ class MultipartProxy_serverImpl
|
||||
{
|
||||
config = new ConfigFile(new File(cfgdir, "multipart.cfg"))
|
||||
.setComment("Multipart API config file")
|
||||
|
||||
|
||||
GameRegistry.registerBlock(new BlockMultipart().setBlockName("multipart"), null, "block")
|
||||
block = Block.blockRegistry.getObject("ForgeMultipart:block").asInstanceOf[BlockMultipart]
|
||||
|
||||
MultipartGenerator.registerTrait("codechicken.multipart.TSlottedPart", "codechicken.multipart.scalatraits.TSlottedTile")
|
||||
MultipartGenerator.registerTrait("net.minecraftforge.fluids.IFluidHandler", "codechicken.multipart.scalatraits.TFluidHandlerTile")
|
||||
MultipartGenerator.registerTrait("net.minecraft.inventory.IInventory", "codechicken.multipart.scalatraits.JInventoryTile")
|
||||
@@ -41,33 +39,21 @@ class MultipartProxy_serverImpl
|
||||
|
||||
MultipartSaveLoad.hookLoader()
|
||||
}
|
||||
|
||||
def init()
|
||||
{
|
||||
block = new BlockMultipart(config.getTag("block.id").getIntValue(getFreeBlockID(1281)))
|
||||
block.setUnlocalizedName("ccmultipart")
|
||||
}
|
||||
|
||||
|
||||
def init(){}
|
||||
|
||||
def postInit()
|
||||
{
|
||||
FMLCommonHandler.instance().bus().register(MultipartEventHandler)
|
||||
MinecraftForge.EVENT_BUS.register(MultipartEventHandler)
|
||||
PacketCustom.assignHandler(MultipartSPH.channel, MultipartSPH)
|
||||
NetworkRegistry.instance.registerConnectionHandler(MultipartEventHandler)
|
||||
TickRegistry.registerTickHandler(MultipartEventHandler, Side.SERVER)
|
||||
|
||||
PacketCustom.assignHandshakeHandler(MultipartSPH.registryChannel, MultipartSPH)
|
||||
|
||||
WorldExtensionManager.registerWorldExtension(TickScheduler)
|
||||
|
||||
MultipartCompatiblity.load()
|
||||
}
|
||||
|
||||
def getFreeBlockID(preferred:Int):Int =
|
||||
{
|
||||
for(i <- (preferred until 4096) ++ (preferred-1 until 255))
|
||||
if(Block.blocksList(i) == null)
|
||||
return i
|
||||
throw new RuntimeException("Out of Block IDs")
|
||||
}
|
||||
|
||||
def onTileClassBuilt(t:Class[_ <: TileEntity])
|
||||
{
|
||||
MultipartSaveLoad.registerTileClass(t)
|
||||
@@ -82,8 +68,10 @@ class MultipartProxy_clientImpl extends MultipartProxy_serverImpl
|
||||
super.postInit()
|
||||
RenderingRegistry.registerBlockHandler(MultipartRenderer)
|
||||
PacketCustom.assignHandler(MultipartCPH.channel, MultipartCPH)
|
||||
PacketCustom.assignHandler(MultipartCPH.registryChannel, 1, 127, MultipartCPH)
|
||||
KeyBindingRegistry.registerKeyBinding(ControlKeyHandler)
|
||||
PacketCustom.assignHandler(MultipartCPH.registryChannel, MultipartCPH)
|
||||
|
||||
FMLCommonHandler.instance().bus().register(ControlKeyHandler)
|
||||
ClientRegistry.registerKeyBinding(ControlKeyHandler)
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
||||
@@ -10,15 +10,16 @@ import net.minecraft.block.BlockButton;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.projectile.EntityArrow;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class ButtonPart extends McSidedMetaPart implements IFaceRedstonePart
|
||||
{
|
||||
public static BlockButton stoneButton = (BlockButton) Block.stoneButton;
|
||||
public static BlockButton woodenButton = (BlockButton) Block.woodenButton;
|
||||
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};
|
||||
|
||||
@@ -88,7 +89,7 @@ public class ButtonPart extends McSidedMetaPart implements IFaceRedstonePart
|
||||
return null;
|
||||
|
||||
pos = pos.copy().offset(side^1);
|
||||
if(!world.isBlockSolidOnSide(pos.x, pos.y, pos.z, ForgeDirection.getOrientation(side)))
|
||||
if(!world.isSideSolid(pos.x, pos.y, pos.z, ForgeDirection.getOrientation(side)))
|
||||
return null;
|
||||
|
||||
return new ButtonPart(sideMetaMap[side^1]|type<<4);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package codechicken.multipart.minecraft;
|
||||
|
||||
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;
|
||||
@@ -8,6 +9,8 @@ import codechicken.multipart.MultiPartRegistry.IPartFactory;
|
||||
import codechicken.multipart.MultiPartRegistry;
|
||||
import codechicken.multipart.TMultiPart;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Content implements IPartFactory, IPartConverter
|
||||
{
|
||||
@Override
|
||||
@@ -33,32 +36,26 @@ public class Content implements IPartFactory, IPartConverter
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConvert(int blockID)
|
||||
{
|
||||
return blockID == Block.torchWood.blockID ||
|
||||
blockID == Block.lever.blockID ||
|
||||
blockID == Block.stoneButton.blockID ||
|
||||
blockID == Block.woodenButton.blockID ||
|
||||
blockID == Block.torchRedstoneIdle.blockID ||
|
||||
blockID == Block.torchRedstoneActive.blockID;
|
||||
public Iterable<Block> blockTypes() {
|
||||
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)
|
||||
{
|
||||
int id = world.getBlockId(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);
|
||||
if(id == Block.torchWood.blockID)
|
||||
if(b == Blocks.torch)
|
||||
return new TorchPart(meta);
|
||||
if(id == Block.lever.blockID)
|
||||
if(b == Blocks.lever)
|
||||
return new LeverPart(meta);
|
||||
if(id == Block.stoneButton.blockID)
|
||||
if(b == Blocks.stone_button)
|
||||
return new ButtonPart(meta);
|
||||
if(id == Block.woodenButton.blockID)
|
||||
if(b == Blocks.wooden_button)
|
||||
return new ButtonPart(meta|0x10);
|
||||
if(id == Block.torchRedstoneIdle.blockID)
|
||||
if(b == Blocks.redstone_torch)
|
||||
return new RedstoneTorchPart(meta);
|
||||
if(id == Block.torchRedstoneActive.blockID)
|
||||
if(b == Blocks.unlit_redstone_torch)
|
||||
return new RedstoneTorchPart(meta|0x10);
|
||||
|
||||
return null;
|
||||
|
||||
@@ -8,12 +8,13 @@ import codechicken.multipart.TileMultipart;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockFence;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.packet.Packet15Place;
|
||||
import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeSubscribe;
|
||||
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;
|
||||
@@ -22,7 +23,7 @@ public class EventHandler
|
||||
{
|
||||
private ThreadLocal<Object> placing = new ThreadLocal<Object>();
|
||||
|
||||
@ForgeSubscribe
|
||||
@SubscribeEvent
|
||||
public void playerInteract(PlayerInteractEvent event)
|
||||
{
|
||||
if(event.action == Action.RIGHT_CLICK_BLOCK && event.entityPlayer.worldObj.isRemote)
|
||||
@@ -47,16 +48,20 @@ public class EventHandler
|
||||
McBlockPart part = null;
|
||||
if(held == null)
|
||||
return false;
|
||||
|
||||
if(held.itemID == Block.torchWood.blockID)
|
||||
|
||||
Block heldBlock = Block.getBlockFromItem(held.getItem());
|
||||
if(heldBlock == Blocks.air)
|
||||
return false;
|
||||
|
||||
if(heldBlock == Blocks.torch)
|
||||
part = TorchPart.placement(world, pos, hit.sideHit);
|
||||
else if(held.itemID == Block.lever.blockID)
|
||||
else if(heldBlock == Blocks.lever)
|
||||
part = LeverPart.placement(world, pos, player, hit.sideHit);
|
||||
else if(held.itemID == Block.stoneButton.blockID)
|
||||
else if(heldBlock == Blocks.stone_button)
|
||||
part = ButtonPart.placement(world, pos, hit.sideHit, 0);
|
||||
else if(held.itemID == Block.woodenButton.blockID)
|
||||
else if(heldBlock == Blocks.wooden_button)
|
||||
part = ButtonPart.placement(world, pos, hit.sideHit, 1);
|
||||
else if(held.itemID == Block.torchRedstoneActive.blockID)
|
||||
else if(heldBlock == Blocks.redstone_torch)
|
||||
part = RedstoneTorchPart.placement(world, pos, hit.sideHit);
|
||||
|
||||
if(part == null)
|
||||
@@ -65,11 +70,11 @@ public class EventHandler
|
||||
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 = Block.blocksList[world.getBlockId(hit.blockX, hit.blockY, hit.blockZ)];
|
||||
if(block != null && !ignoreActivate(block) && block.onBlockActivated(world, hit.blockX, hit.blockY, hit.blockZ, player, hit.sideHit, (float)f.x, (float)f.y, (float)f.z))
|
||||
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))
|
||||
{
|
||||
player.swingItem();
|
||||
PacketCustom.sendToServer(new Packet15Place(
|
||||
PacketCustom.sendToServer(new C08PacketPlayerBlockPlacement(
|
||||
hit.blockX, hit.blockY, hit.blockZ, hit.sideHit,
|
||||
player.inventory.getCurrentItem(),
|
||||
(float)f.x, (float)f.y, (float)f.z));
|
||||
@@ -85,7 +90,7 @@ public class EventHandler
|
||||
{
|
||||
TileMultipart.addPart(world, pos, part);
|
||||
world.playSoundEffect(pos.x + 0.5, pos.y + 0.5, pos.z + 0.5,
|
||||
part.getBlock().stepSound.getPlaceSound(),
|
||||
part.getBlock().stepSound.func_150496_b(),
|
||||
(part.getBlock().stepSound.getVolume() + 1.0F) / 2.0F,
|
||||
part.getBlock().stepSound.getPitch() * 0.8F);
|
||||
if(!player.capabilities.isCreativeMode)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package codechicken.multipart.minecraft;
|
||||
|
||||
import codechicken.lib.vec.BlockCoord;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IPartMeta
|
||||
@@ -9,7 +10,7 @@ public interface IPartMeta
|
||||
|
||||
public World getWorld();
|
||||
|
||||
public int getBlockId();
|
||||
public Block getBlock();
|
||||
|
||||
public BlockCoord getPos();
|
||||
}
|
||||
@@ -4,18 +4,19 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockLever;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.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 static BlockLever lever = (BlockLever) Block.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[] sideMetaMap = new int[]{6, 0, 3, 4, 1, 2};
|
||||
public static int[] metaSwapMap = new int[]{5, 7};
|
||||
@@ -77,7 +78,7 @@ public class LeverPart extends McSidedMetaPart implements IFaceRedstonePart
|
||||
public static McBlockPart placement(World world, BlockCoord pos, EntityPlayer player, int side)
|
||||
{
|
||||
pos = pos.copy().offset(side^1);
|
||||
if(!world.isBlockSolidOnSide(pos.x, pos.y, pos.z, ForgeDirection.getOrientation(side)))
|
||||
if(!world.isSideSolid(pos.x, pos.y, pos.z, ForgeDirection.getOrientation(side)))
|
||||
return null;
|
||||
|
||||
int meta = sideMetaMap[side^1];
|
||||
|
||||
@@ -7,7 +7,7 @@ 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.Icon;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import codechicken.lib.vec.Cuboid6;
|
||||
import codechicken.multipart.IconHitEffects;
|
||||
@@ -60,14 +60,14 @@ public abstract class McBlockPart extends JCuboidPart implements JNormalOcclusio
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getBreakingIcon(Object subPart, int side)
|
||||
public IIcon getBreakingIcon(Object subPart, int side)
|
||||
{
|
||||
return getBlock().getIcon(0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public Icon getBrokenIcon(int side)
|
||||
public IIcon getBrokenIcon(int side)
|
||||
{
|
||||
return getBlock().getIcon(0, 0);
|
||||
}
|
||||
@@ -87,6 +87,6 @@ public abstract class McBlockPart extends JCuboidPart implements JNormalOcclusio
|
||||
@Override
|
||||
public int getLightValue()
|
||||
{
|
||||
return Block.lightValue[getBlock().blockID];
|
||||
return getBlock().getLightValue();
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package codechicken.multipart.minecraft;
|
||||
|
||||
import codechicken.lib.data.MCDataInput;
|
||||
import codechicken.lib.data.MCDataOutput;
|
||||
import codechicken.lib.lighting.LazyLightMatrix;
|
||||
import codechicken.lib.lighting.LightMatrix;
|
||||
import codechicken.lib.vec.BlockCoord;
|
||||
import codechicken.lib.vec.Vector3;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
@@ -58,12 +58,6 @@ public abstract class McMetaPart extends McBlockPart implements IPartMeta
|
||||
return meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockId()
|
||||
{
|
||||
return getBlock().blockID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockCoord getPos()
|
||||
{
|
||||
@@ -77,9 +71,12 @@ public abstract class McMetaPart extends McBlockPart implements IPartMeta
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderStatic(Vector3 pos, LazyLightMatrix olm, 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());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,30 @@
|
||||
package codechicken.multipart.minecraft;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.NetClientHandler;
|
||||
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.network.play.INetHandlerPlayClient;
|
||||
|
||||
public class McMultipartCPH implements IClientPacketHandler
|
||||
{
|
||||
public static Object channel = MinecraftMultipartMod.instance;
|
||||
|
||||
|
||||
@Override
|
||||
public void handlePacket(PacketCustom packet, NetClientHandler nethandler, Minecraft mc)
|
||||
{
|
||||
switch(packet.getType())
|
||||
{
|
||||
public void handlePacket(PacketCustom packet, Minecraft mc, INetHandlerPlayClient netHandler) {
|
||||
switch (packet.getType()) {
|
||||
case 1:
|
||||
spawnBurnoutSmoke(mc.theWorld, packet.readCoord());
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void spawnBurnoutSmoke(WorldClient world, BlockCoord pos)
|
||||
{
|
||||
for(int l = 0; l < 5; l++)
|
||||
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);
|
||||
private void spawnBurnoutSmoke(WorldClient world, BlockCoord pos) {
|
||||
for (int l = 0; l < 5; l++)
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package codechicken.multipart.minecraft;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.NetServerHandler;
|
||||
import net.minecraft.network.play.INetHandlerPlayServer;
|
||||
import net.minecraft.world.World;
|
||||
import codechicken.lib.packet.PacketCustom;
|
||||
import codechicken.lib.packet.PacketCustom.IServerPacketHandler;
|
||||
@@ -9,20 +9,17 @@ import codechicken.lib.packet.PacketCustom.IServerPacketHandler;
|
||||
public class McMultipartSPH implements IServerPacketHandler
|
||||
{
|
||||
public static Object channel = MinecraftMultipartMod.instance;
|
||||
|
||||
|
||||
@Override
|
||||
public void handlePacket(PacketCustom packet, NetServerHandler nethandler, EntityPlayerMP sender)
|
||||
{
|
||||
switch(packet.getType())
|
||||
{
|
||||
public void handlePacket(PacketCustom packet, EntityPlayerMP sender, INetHandlerPlayServer netHandler) {
|
||||
switch (packet.getType()) {
|
||||
case 1:
|
||||
EventHandler.place(sender, sender.worldObj);
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void spawnBurnoutSmoke(World world, int x, int y, int z)
|
||||
{
|
||||
new PacketCustom(channel, 1).writeCoord(x, y, z).sendToChunk(world, x>>4, z>>4);
|
||||
public static void spawnBurnoutSmoke(World world, int x, int y, int z) {
|
||||
new PacketCustom(channel, 1).writeCoord(x, y, z).sendToChunk(world, x >> 4, z >> 4);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package codechicken.multipart.minecraft;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import codechicken.lib.vec.BlockCoord;
|
||||
import codechicken.lib.vec.Vector3;
|
||||
import codechicken.multipart.TFacePart;
|
||||
@@ -30,7 +30,7 @@ public abstract class McSidedMetaPart extends McMetaPart implements TFacePart
|
||||
public boolean canStay()
|
||||
{
|
||||
BlockCoord pos = new BlockCoord(tile()).offset(sideForMeta(meta));
|
||||
return world().isBlockSolidOnSide(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()
|
||||
|
||||
@@ -2,15 +2,12 @@ package codechicken.multipart.minecraft;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import codechicken.lib.packet.PacketCustom;
|
||||
import codechicken.lib.packet.PacketCustom.CustomTinyPacketHandler;
|
||||
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 cpw.mods.fml.common.network.NetworkMod;
|
||||
|
||||
@Mod(modid = "McMultipart", acceptedMinecraftVersions="[1.6.4]")
|
||||
@NetworkMod(clientSideRequired = true, serverSideRequired = true, tinyPacketHandler=CustomTinyPacketHandler.class)
|
||||
@Mod(modid = "McMultipart", acceptedMinecraftVersions="[1.7.2]")
|
||||
public class MinecraftMultipartMod
|
||||
{
|
||||
@Instance("McMultipart")
|
||||
|
||||
@@ -9,133 +9,80 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Vec3Pool;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class PartMetaAccess implements IBlockAccess
|
||||
{
|
||||
public class PartMetaAccess implements IBlockAccess {
|
||||
public IPartMeta part;
|
||||
private BlockCoord pos;
|
||||
|
||||
public PartMetaAccess(IPartMeta p)
|
||||
{
|
||||
|
||||
public PartMetaAccess(IPartMeta p) {
|
||||
part = p;
|
||||
pos = p.getPos();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getBlockId(int i, int j, int k)
|
||||
{
|
||||
if(i == pos.x && j == pos.y && k == pos.z)
|
||||
return part.getBlockId();
|
||||
return part.getWorld().getBlockId(i, j, k);
|
||||
public Block getBlock(int i, int j, int k) {
|
||||
if (i == pos.x && j == pos.y && k == pos.z)
|
||||
return part.getBlock();
|
||||
return part.getWorld().getBlock(i, j, k);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getBlockTileEntity(int i, int j, int k)
|
||||
{
|
||||
if(i == pos.x && j == pos.y && k == pos.z)
|
||||
public TileEntity getTileEntity(int i, int j, int k) {
|
||||
if (i == pos.x && j == pos.y && k == pos.z)
|
||||
throw new IllegalArgumentException("Unsupported Operation");
|
||||
return part.getWorld().getBlockTileEntity(i, j, k);
|
||||
return part.getWorld().getTileEntity(i, j, k);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getLightBrightnessForSkyBlocks(int i, int j, int k, int l)
|
||||
{
|
||||
public int getLightBrightnessForSkyBlocks(int i, int j, int k, int l) {
|
||||
return part.getWorld().getLightBrightnessForSkyBlocks(i, j, k, l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockMetadata(int i, int j, int k)
|
||||
{
|
||||
if(i == pos.x && j == pos.y && k == pos.z)
|
||||
return part.getMetadata()&0xF;
|
||||
public int getBlockMetadata(int i, int j, int k) {
|
||||
if (i == pos.x && j == pos.y && k == pos.z)
|
||||
return part.getMetadata() & 0xF;
|
||||
return part.getWorld().getBlockMetadata(i, j, k);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getBrightness(int i, int j, int k, int l)
|
||||
{
|
||||
return part.getWorld().getBrightness(i, j, k, l);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getLightBrightness(int i, int j, int k)
|
||||
{
|
||||
return part.getWorld().getLightBrightness(i, j, k);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material getBlockMaterial(int i, int j, int k)
|
||||
{
|
||||
return Block.blocksList[getBlockId(i, j, k)].blockMaterial;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean isBlockOpaqueCube(int i, int j, int k)
|
||||
{
|
||||
return part.getWorld().isBlockOpaqueCube(i, j, k);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlockNormalCube(int i, int j, int k)
|
||||
{
|
||||
return part.getWorld().isBlockNormalCube(i, j, k);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean isAirBlock(int i, int j, int k)
|
||||
{
|
||||
public boolean isAirBlock(int i, int j, int k) {
|
||||
throw new IllegalArgumentException("Unsupported Operation");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public BiomeGenBase getBiomeGenForCoords(int i, int j)
|
||||
{
|
||||
public BiomeGenBase getBiomeGenForCoords(int i, int j) {
|
||||
return part.getWorld().getBiomeGenForCoords(i, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getHeight()
|
||||
{
|
||||
public int getHeight() {
|
||||
return part.getWorld().getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean extendedLevelsInChunkCache()
|
||||
{
|
||||
public boolean extendedLevelsInChunkCache() {
|
||||
return part.getWorld().extendedLevelsInChunkCache();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean doesBlockHaveSolidTopSurface(int i, int j, int k)
|
||||
{
|
||||
throw new IllegalArgumentException("Unsupported Operation");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec3Pool getWorldVec3Pool()
|
||||
{
|
||||
public Vec3Pool getWorldVec3Pool() {
|
||||
return part.getWorld().getWorldVec3Pool();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isBlockProvidingPowerTo(int i, int j, int k, int l)
|
||||
{
|
||||
public int isBlockProvidingPowerTo(int i, int j, int k, int l) {
|
||||
throw new IllegalArgumentException("Unsupported Operation");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isBlockSolidOnSide(int x, int y, int z, ForgeDirection side, boolean _default)
|
||||
{
|
||||
return part.getWorld().isBlockSolidOnSide(x, y, z, side, _default);
|
||||
public boolean isSideSolid(int x, int y, int z, ForgeDirection side, boolean _default) {
|
||||
return part.getWorld().isSideSolid(x, y, z, side, _default);
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,11 @@ import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockRedstoneTorch;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import codechicken.lib.vec.BlockCoord;
|
||||
import codechicken.lib.vec.Cuboid6;
|
||||
import codechicken.multipart.IFaceRedstonePart;
|
||||
@@ -16,8 +17,8 @@ import codechicken.multipart.RedstoneInteractions;
|
||||
|
||||
public class RedstoneTorchPart extends TorchPart implements IFaceRedstonePart, IRandomUpdateTick
|
||||
{
|
||||
public static BlockRedstoneTorch torchActive = (BlockRedstoneTorch) Block.torchRedstoneActive;
|
||||
public static BlockRedstoneTorch torchIdle = (BlockRedstoneTorch) Block.torchRedstoneIdle;
|
||||
public static BlockRedstoneTorch torchActive = (BlockRedstoneTorch) Blocks.redstone_torch;
|
||||
public static BlockRedstoneTorch torchIdle = (BlockRedstoneTorch) Blocks.unlit_redstone_torch;
|
||||
|
||||
public class BurnoutEntry
|
||||
{
|
||||
@@ -75,7 +76,7 @@ public class RedstoneTorchPart extends TorchPart implements IFaceRedstonePart, I
|
||||
if(side == 0)
|
||||
return null;
|
||||
pos = pos.copy().offset(side^1);
|
||||
if(!world.isBlockSolidOnSide(pos.x, pos.y, pos.z, ForgeDirection.getOrientation(side)))
|
||||
if(!world.isSideSolid(pos.x, pos.y, pos.z, ForgeDirection.getOrientation(side)))
|
||||
return null;
|
||||
|
||||
return new RedstoneTorchPart(sideMetaMap[side^1]|0x10);
|
||||
|
||||
@@ -4,15 +4,15 @@ 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 net.minecraftforge.common.ForgeDirection;
|
||||
import codechicken.multipart.IRandomDisplayTick;
|
||||
import codechicken.lib.vec.BlockCoord;
|
||||
import codechicken.lib.vec.Cuboid6;
|
||||
|
||||
public class TorchPart extends McSidedMetaPart implements IRandomDisplayTick
|
||||
{
|
||||
public static BlockTorch torch = (BlockTorch) Block.torchWood;
|
||||
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};
|
||||
|
||||
@@ -68,13 +68,7 @@ public class TorchPart extends McSidedMetaPart implements IRandomDisplayTick
|
||||
@Override
|
||||
public boolean canStay()
|
||||
{
|
||||
if(sideForMeta(meta) == 0)
|
||||
{
|
||||
Block block = Block.blocksList[world().getBlockId(x(), y()-1, z())];
|
||||
if(block != null && block.canPlaceTorchOnTop(world(), x(), y()-1, z()))
|
||||
return true;
|
||||
}
|
||||
return super.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)
|
||||
@@ -82,20 +76,10 @@ public class TorchPart extends McSidedMetaPart implements IRandomDisplayTick
|
||||
if(side == 0)
|
||||
return null;
|
||||
pos = pos.copy().offset(side^1);
|
||||
if(!world.isBlockSolidOnSide(pos.x, pos.y, pos.z, ForgeDirection.getOrientation(side)))
|
||||
{
|
||||
if(side == 1)
|
||||
{
|
||||
Block block = Block.blocksList[world.getBlockId(pos.x, pos.y, pos.z)];
|
||||
if(block == null || !block.canPlaceTorchOnTop(world, pos.x, pos.y, pos.z))
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Block block = world.getBlock(pos.x, pos.y, pos.z);
|
||||
if(!block.isBlockSolid(world, pos.x, pos.y, pos.z, side) && (side != 1 || block.canPlaceTorchOnTop(world, pos.x, pos.y, pos.z)))
|
||||
return null;
|
||||
|
||||
return new TorchPart(sideMetaMap[side^1]);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
package codechicken.multipart.nei;
|
||||
|
||||
import codechicken.lib.lang.LangUtil;
|
||||
import codechicken.microblock.MicroblockClass;
|
||||
import codechicken.microblock.MicroblockClassRegistry;
|
||||
import codechicken.microblock.handler.MicroblockProxy;
|
||||
import codechicken.nei.MultiItemRange;
|
||||
import codechicken.nei.api.API;
|
||||
import codechicken.nei.api.IConfigureNEI;
|
||||
|
||||
public class NEI_MicroblockConfig implements IConfigureNEI
|
||||
@@ -13,8 +9,6 @@ public class NEI_MicroblockConfig implements IConfigureNEI
|
||||
@Override
|
||||
public void loadConfig()
|
||||
{
|
||||
int microID = MicroblockProxy.itemMicro().itemID;
|
||||
|
||||
MicroblockClass[] microClasses = MicroblockClassRegistry.classes();
|
||||
for(int c = 0; c < microClasses.length; c++)
|
||||
{
|
||||
@@ -22,16 +16,16 @@ public class NEI_MicroblockConfig implements IConfigureNEI
|
||||
if(mcrClass == null)
|
||||
continue;
|
||||
|
||||
addSubset(mcrClass, microID, c<<8|1);
|
||||
addSubset(mcrClass, microID, c<<8|2);
|
||||
addSubset(mcrClass, microID, c<<8|4);
|
||||
addSubset(mcrClass, c<<8|1);
|
||||
addSubset(mcrClass, c<<8|2);
|
||||
addSubset(mcrClass, c<<8|4);
|
||||
}
|
||||
}
|
||||
|
||||
private void addSubset(MicroblockClass mcrClass, int microID, int i)
|
||||
private void addSubset(MicroblockClass mcrClass, int i)
|
||||
{
|
||||
API.addSetRange("Microblocks."+LangUtil.translateG(mcrClass.getName()+"."+(i&0xFF)+".subset"),
|
||||
new MultiItemRange().add(microID, i, i));
|
||||
/*API.addSetRange("Microblocks."+LangUtil.translateG(mcrClass.getName()+"."+(i&0xFF)+".subset"),
|
||||
new MultiItemRange().add(MicroblockProxy.itemMicro(), i, i));*/
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package codechicken.multipart.scalatraits
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import codechicken.multipart.TMultiPart
|
||||
import codechicken.multipart.TileMultipart
|
||||
import net.minecraftforge.fluids.IFluidHandler
|
||||
|
||||
@@ -78,17 +78,17 @@ trait TIInventoryTile extends TileMultipart with ISidedInventory
|
||||
inv.setInventorySlotContents(slot, itemstack)
|
||||
}
|
||||
|
||||
def getInvName = "Multipart Inventory"
|
||||
def getInventoryName = "Multipart Inventory"
|
||||
|
||||
def isInvNameLocalized = false
|
||||
def hasCustomInventoryName = false
|
||||
|
||||
def getInventoryStackLimit = 64
|
||||
|
||||
def isUseableByPlayer(entityplayer:EntityPlayer) = true
|
||||
|
||||
def openChest(){}
|
||||
def openInventory(){}
|
||||
|
||||
def closeChest(){}
|
||||
def closeInventory(){}
|
||||
|
||||
def isItemValidForSlot(i:Int, itemstack:ItemStack) = {
|
||||
val (inv, slot) = slotMap(i)
|
||||
|
||||
@@ -54,12 +54,12 @@ trait TRedstoneTile extends TileMultipart with IRedstoneTile
|
||||
}
|
||||
|
||||
override def weakPowerLevel(side:Int):Int =
|
||||
weakPowerLevel(side, otherConnectionMask(worldObj, xCoord, yCoord, zCoord, side, true))
|
||||
weakPowerLevel(side, otherConnectionMask(getWorldObj, xCoord, yCoord, zCoord, side, true))
|
||||
|
||||
override def canConnectRedstone(side:Int):Boolean =
|
||||
{
|
||||
val vside = vanillaToSide(side)
|
||||
return (getConnectionMask(vside) & otherConnectionMask(worldObj, xCoord, yCoord, zCoord, vside, false)) > 0
|
||||
return (getConnectionMask(vside) & otherConnectionMask(getWorldObj, xCoord, yCoord, zCoord, vside, false)) > 0
|
||||
}
|
||||
|
||||
def getConnectionMask(side:Int):Int =
|
||||
|
||||
@@ -49,12 +49,11 @@ trait TTileChangeTile extends TileMultipart {
|
||||
return
|
||||
|
||||
val weak = diff == 2
|
||||
if(weak && !weakTileChanges)
|
||||
return
|
||||
|
||||
operate{ p =>
|
||||
operate{ p =>
|
||||
if(p.isInstanceOf[INeighborTileChange])
|
||||
p.asInstanceOf[INeighborTileChange].onNeighborTileChanged(side, weak)
|
||||
}
|
||||
}
|
||||
|
||||
override def getWeakChanges() = weakTileChanges
|
||||
}
|
||||
Reference in new issue
Block a user