Skip to content

Commit

Permalink
add tutorial sign with balise
Browse files Browse the repository at this point in the history
  • Loading branch information
Dolu1990 committed Jun 5, 2014
1 parent 03fd624 commit c901890
Show file tree
Hide file tree
Showing 7 changed files with 424 additions and 1 deletion.
13 changes: 13 additions & 0 deletions mods/eln/Eln.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@
import mods.eln.turbine.TurbineDescriptor;
import mods.eln.turbine.TurbineElement;
import mods.eln.turbine.TurbineRender;
import mods.eln.tutorialsign.TutorialSignDescriptor;
import mods.eln.tutorialsign.TutorialSignElement;
import mods.eln.waterturbine.WaterTurbineDescriptor;
import mods.eln.wiki.Data;
import mods.eln.windturbine.WindTurbineDescriptor;
Expand Down Expand Up @@ -852,6 +854,7 @@ public void postInit(FMLPostInitializationEvent event) {
@EventHandler
/* Remember to use the right event! */
public void onServerStopping(FMLServerStoppingEvent ev) {
TutorialSignElement.resetBalise();
modbusServer.destroy();
LightBlockEntity.observers.clear();
TeleporterElement.teleporterList.clear();
Expand Down Expand Up @@ -1700,6 +1703,16 @@ private void registerSixNodeMisc(int id) {

sixNodeItem.addDescriptor(subId + (id << 6), desc);
}


{
subId = 8;
name = "Tutorial sign";

TutorialSignDescriptor desc = new TutorialSignDescriptor(
name, obj.getObj("voltagesource"));
sixNodeItem.addDescriptor(subId + (id << 6), desc);
}
}

void registerElectricalBreaker(int id) {
Expand Down
11 changes: 10 additions & 1 deletion mods/eln/electricalsource/ElectricalSourceElement.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package mods.eln.electricalsource;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

import javax.swing.text.MaskFormatter;

import cpw.mods.fml.common.FMLCommonHandler;


import mods.eln.Eln;
import mods.eln.generic.GenericItemUsingDamageDescriptor;
Expand All @@ -30,6 +38,7 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;

public class ElectricalSourceElement extends SixNodeElement {

Expand Down Expand Up @@ -65,7 +74,7 @@ public static boolean canBePlacedOnSide(Direction side, int type) {

@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
super.writeToNBT(nbt);
nbt.setByte("color", (byte)(color + (colorCare << 4)));

nbt.setDouble("voltage",groundProcess.Uc);
Expand Down
22 changes: 22 additions & 0 deletions mods/eln/misc/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.Field;
import java.text.DecimalFormat;
Expand Down Expand Up @@ -44,6 +47,7 @@
import net.minecraft.nbt.NBTTagList;

import net.minecraft.network.play.server.S3FPacketCustomPayload;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.util.AxisAlignedBB;
Expand All @@ -61,6 +65,7 @@

import org.lwjgl.opengl.GL11;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
Expand Down Expand Up @@ -1402,4 +1407,21 @@ public static NBTTagCompound newNbtTagCompund(NBTTagCompound nbt, String string)
return cmp;
}


public static File getMapFile(String name){
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
File f = server.getFile("saves/" + server.getFolderName() + "/" + name);
return f;
}

public static String readMapFile(String name) throws IOException{
File file = getMapFile(name);
FileInputStream fis = new FileInputStream(file);
byte[] data = new byte[(int)file.length()];
fis.read(data);
fis.close();
String s = new String(data, "UTF-8");
return s;
}

}
33 changes: 33 additions & 0 deletions mods/eln/tutorialsign/TutorialSignDescriptor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package mods.eln.tutorialsign;

import java.util.List;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import mods.eln.misc.Obj3D;
import mods.eln.misc.Obj3D.Obj3DPart;
import mods.eln.node.SixNodeDescriptor;

public class TutorialSignDescriptor extends SixNodeDescriptor {

private Obj3D obj;
private Obj3DPart main;

public TutorialSignDescriptor(String name, Obj3D obj) {
super(name, TutorialSignElement.class, TutorialSignRender.class);
this.obj = obj;
if(obj != null) {
main = obj.getPart("main");
}
}

void draw() {
if(main != null) main.draw();
}

@Override
public void addInformation(ItemStack itemStack, EntityPlayer entityPlayer, List list, boolean par4) {
super.addInformation(itemStack, entityPlayer, list, par4);
//list.add("");
}
}
210 changes: 210 additions & 0 deletions mods/eln/tutorialsign/TutorialSignElement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
package mods.eln.tutorialsign;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;

import javax.swing.text.MaskFormatter;

import cpw.mods.fml.common.FMLCommonHandler;


import mods.eln.Eln;
import mods.eln.generic.GenericItemUsingDamageDescriptor;
import mods.eln.item.BrushDescriptor;
import mods.eln.misc.Direction;
import mods.eln.misc.LRDU;
import mods.eln.misc.Utils;
import mods.eln.node.NodeBase;
import mods.eln.node.NodeElectricalLoad;
import mods.eln.node.NodeThermalLoad;
import mods.eln.node.NodeThermalWatchdogProcess;
import mods.eln.node.SixNode;
import mods.eln.node.SixNodeDescriptor;
import mods.eln.node.SixNodeElement;
import mods.eln.sim.ElectricalLoad;
import mods.eln.sim.ElectricalLoadDynamicProcess;
import mods.eln.sim.ElectricalLoadHeatThermalLoadProcess;
import mods.eln.sim.ElectricalSourceRefGroundProcess;
import mods.eln.sim.IProcess;
import mods.eln.sim.ThermalLoad;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;

public class TutorialSignElement extends SixNodeElement {
static HashMap<String, String> baliseMap = null;

public static void resetBalise(){
baliseMap = null;
}
public static String getText(String balise){
if(baliseMap == null){
baliseMap = new HashMap<String, String>();

try {
String file = Utils.readMapFile("EA/tutorialSign.txt");
String ret;
if(file.contains("\r\n"))
ret = "\r\n";
else
ret = "\n";

file = file.replaceAll("#"+ret, "#");
file = file.replaceAll(ret + "#", "#");

String[] split = file.split("#");

boolean first = true;
int counter = 0;
String baliseTag = "";
for(String str : split){
if(first) {
first = false;
continue;
}
if(counter == 0){
baliseTag = str;
}
if(counter == 1){
baliseMap.put(baliseTag, str);
}

counter = (counter + 1) & 1;
}


} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
String text = baliseMap.get(balise);
if(text == null) return "No balise found";
return text;
}


public TutorialSignElement(SixNode sixNode, Direction side, SixNodeDescriptor descriptor) {
super(sixNode, side, descriptor);

}


public static final int setTextFileId = 1;

String baliseName = "";

void setBalise(String name){
baliseName = name;
needPublish();
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
setBalise(nbt.getString("baliseName"));
}

/*
private void setTextFile(String name) {
if(name.matches("^[a-zA-Z0-9]*$") == false){
fileName = "OnlyAlphaNumeric";
text = "OnlyAlphaNumeric";
} else {
fileName = name;
try {
text = Utils.readMapFile("EATuto/" + fileName + ".txt");
} catch (IOException e) {
text = "file not found";
}
}
needPublish();
}*/


@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
nbt.setString("baliseName", baliseName);
}

@Override
public ElectricalLoad getElectricalLoad(LRDU lrdu) {
return null;
}

@Override
public ThermalLoad getThermalLoad(LRDU lrdu) {
return null;
}

@Override
public int getConnectionMask(LRDU lrdu) {
return 0;
}

@Override
public String multiMeterString() {
return "";
}

@Override
public String thermoMeterString() {
return "";
}

@Override
public void networkSerialize(DataOutputStream stream) {
super.networkSerialize(stream);
try {
stream.writeUTF(baliseName);
stream.writeUTF(getText(baliseName));
} catch (IOException e) {
e.printStackTrace();
}
}



@Override
public void networkUnserialize(DataInputStream stream) {
super.networkUnserialize(stream);
try {
switch(stream.readByte()) {
case setTextFileId:
setBalise(stream.readUTF());
break;
}
} catch (IOException e) {
e.printStackTrace();
}
}

@Override
public boolean hasGui() {
return true;
}


@Override
public void initialize() {
// TODO Auto-generated method stub

}


@Override
public boolean onBlockActivated(EntityPlayer entityPlayer, Direction side, float vx, float vy, float vz) {
// TODO Auto-generated method stub
return false;
}
}
Loading

0 comments on commit c901890

Please sign in to comment.