Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.idea/
/Pistronics-Repo/.gradle
/Pistronics-Repo/.settings
/Pistronics-Repo/.idea
Expand Down
48 changes: 20 additions & 28 deletions Pistronics-Repo/src/main/java/letiu/modbase/tiles/BaseTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,54 +9,46 @@
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;

public class BaseTile extends TileEntity {

public PTile data;

@Override

public void updateEntity() {
data.update();
this.data.update();
}

@Override

public AxisAlignedBB getRenderBoundingBox() {
AxisAlignedBB box = data.getRenderBoundingBox();
return box == null ? super.getRenderBoundingBox() : box;
AxisAlignedBB box = this.data.getRenderBoundingBox();
return (box == null) ? super.getRenderBoundingBox() : box;
}

@Override

public Packet getDescriptionPacket() {
super.getDescriptionPacket();
NBTTagCompound tag = NBTUtil.getNewCompound();
this.writeToNBT(tag);
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag);
writeToNBT(tag);
return (Packet)new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, tag);
}

@Override

public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
readFromNBT(packet.func_148857_g());
}

@Override

public void validate() {
super.validate();
data.postLoad();
this.data.postLoad();
}

@Override

public void writeToNBT(NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
tagCompound.setString("key", data.getKey());
data.writeToNBT(tagCompound);
tagCompound.setString("key", this.data.getKey());
this.data.writeToNBT(tagCompound);
}

@Override

public void readFromNBT(NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
data = TileData.getTile(tagCompound.getString("key"));
data.tileEntity = this;
data.readFromNBT(tagCompound);
this.data = TileData.getTile(tagCompound.getString("key"));
this.data.tileEntity = this;
this.data.readFromNBT(tagCompound);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import letiu.pistronics.config.ConfigData;
import letiu.pistronics.items.ItemSpade;
import letiu.pistronics.util.BlockProxy;
import cpw.mods.fml.common.Loader;
import net.minecraft.block.*;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
Expand All @@ -16,7 +17,10 @@

public class ItemReference {

public static boolean isTFCLoaded = Loader.isModLoaded("terrafirmacraftplus");

public static final Item SLIME = Items.slime_ball;

public static final Block REDSTONE_TORCH = Blocks.redstone_torch;
public static final Block REDSTONE_BLOCK = Blocks.redstone_block;

Expand All @@ -41,10 +45,10 @@ public class ItemReference {
public static final Item WHEAT_SEEDS = Items.wheat_seeds;
public static final Item COMPARATOR = Items.comparator;
public static final Item DIAMOND = Items.diamond;
public static final Item BOW = Items.bow;
public static final Item ARROW = Items.arrow;

public static final Item BOW = TFCItems.bow;
public static final Item ARROW = TFCItems.arrow;

public static final Item ROTTEN_FLESH = Items.rotten_flesh;
public static final Item POISONOUS_POTATO = Items.poisonous_potato;
public static final Item SPIDER_EYE = Items.spider_eye;
Expand All @@ -55,7 +59,7 @@ public class ItemReference {
public static final Item MILK = Items.milk_bucket;

public static final Item BOOK = Items.book;

public static boolean isDye(ItemStack stack, int color) {
if (stack == null) return false;
switch (color) {
Expand Down Expand Up @@ -86,11 +90,15 @@ public static int getStackDyeColor(ItemStack stack) {
}
return -1;
}

public static ItemStack getDye(int dmg) {
return new ItemStack(TFCItems.dye, 1, dmg);
if(isTFCLoaded) {
return new ItemStack(TFCItems.dye, 1, dmg);
} else {
return new ItemStack(Items.dye, 1, dmg);
}
}

public static boolean isHarvestTool(ItemStack stack) {
if (stack == null) return false;
Item item = stack.getItem();
Expand Down
28 changes: 13 additions & 15 deletions Pistronics-Repo/src/main/java/letiu/modbase/util/NBTUtil.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,37 @@
package letiu.modbase.util;

import java.util.Set;

import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;

public class NBTUtil {

public static final int TAG_COMPOUND_ID = NBTBase.NBTTypes.length - 2;

public static NBTTagCompound getCompoundAt(NBTTagList list, int i) {
return list.getCompoundTagAt(i);
}

public static NBTTagList getCompoundList(NBTTagCompound compound, String key) {
return compound.getTagList(key, TAG_COMPOUND_ID);
}

public static boolean compare(NBTTagCompound nbt1, NBTTagCompound nbt2) {

if (nbt1 == null && nbt2 == null) return true;
if (nbt1 == null && nbt2 != null) return false;
if (nbt1 != null && nbt2 == null) return false;

if (nbt1 == null && nbt2 == null)
return true;
if (nbt1 == null && nbt2 != null)
return false;
if (nbt1 != null && nbt2 == null)
return false;
Set keySet = nbt1.func_150296_c();

for (Object obj : keySet) {
String key = (String) obj;
if (!nbt2.hasKey(key) || !(nbt1.getTag(key).equals(nbt2.getTag(key)))) return false;
String key = (String)obj;
if (!nbt2.hasKey(key) || !nbt1.getTag(key).equals(nbt2.getTag(key)))
return false;
}

return true;
}

public static NBTTagCompound getNewCompound() {
return new NBTTagCompound();
}
Expand Down
15 changes: 7 additions & 8 deletions Pistronics-Repo/src/main/java/letiu/pistronics/data/PTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@
import net.minecraft.util.AxisAlignedBB;

public abstract class PTile {

public BaseTile tileEntity;

public abstract String getKey();

public void readFromNBT(NBTTagCompound tagCompound) {}

public void writeToNBT(NBTTagCompound tagCompound) {}
public void readFromNBT(NBTTagCompound tagCompound) {}

public void writeToNBT(NBTTagCompound tagCompound) {}

public void update() {}

public void postLoad() {}

public boolean hasInventory() {
return false;
}

public NBTTagCompound getNBTForItem() {
NBTTagCompound nbt = NBTUtil.getNewCompound();
writeToNBT(nbt);
Expand All @@ -32,4 +31,4 @@ public NBTTagCompound getNBTForItem() {
public AxisAlignedBB getRenderBoundingBox() {
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package letiu.pistronics.piston;

public class ControllerData {
public SystemController controller;

public float lastValue;

public String key;

public void updateController() {
if (this.controller != null)
this.controller.update(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package letiu.pistronics.piston;

import java.util.HashMap;
import letiu.pistronics.util.BlockProxy;
import letiu.pistronics.util.Vector3;

public class ControllerRegistry {
private static HashMap<String, SystemController> mapClient = new HashMap<String, SystemController>();

private static HashMap<String, SystemController> mapServer = new HashMap<String, SystemController>();

public static void register(SystemController ctr, BlockProxy root) {
HashMap<String, SystemController> map = (root.getWorld()).isRemote ? mapClient : mapServer;
Vector3 coords = root.getCoords();
String key = coords.x + "x" + coords.y + "x" + coords.y;
for (; map.get(key) != null; key = key + "I");
map.put(key, ctr);
ctr.setKey(key);
}

public static void remove(String key) {
mapClient.remove(key);
mapServer.remove(key);
}

public static SystemController find(String key) {
SystemController controller = mapServer.get(key);
if (controller == null)
controller = mapClient.get(key);
return controller;
}

public static SystemController create(String key, MoveData moveData, boolean isRemote) {
HashMap<String, SystemController> map = isRemote ? mapClient : mapServer;
SystemController ctr = map.get(key);
if (ctr == null) {
ctr = new SystemController(moveData);
map.put(key, ctr);
ctr.setKey(key);
}
return ctr;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package letiu.pistronics.piston;

import letiu.pistronics.util.Vector3;
import letiu.pistronics.util.VectorUtil;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;

public class MoveData {
public int rotateDir;

public int moveDir;

public float angle;

public float progress;

public float rotateSpeed;

public float moveSpeed;

public Vector3 rotatePoint;

public MoveData(int moveDir, float moveSpeed) {
this.rotateDir = -1;
this.moveDir = -1;
this.moveDir = moveDir;
this.moveSpeed = moveSpeed;
}

public MoveData(int rotateDir, float rotateSpeed, Vector3 rotatePoint) {
this.rotateDir = -1;
this.moveDir = -1;
this.rotateDir = rotateDir;
this.rotateSpeed = rotateSpeed;
this.rotatePoint = rotatePoint;
}

public MoveData(NBTTagCompound nbt) {
this.rotateDir = -1;
this.moveDir = -1;
readFromNBT(nbt);
}

public MoveData() {
this.rotateDir = -1;
this.moveDir = -1;
}

public void update() {
if (!isDone())
if (isRotating()) {
this.angle += this.rotateSpeed;
} else if (isMoving()) {
this.progress += this.moveSpeed;
}
}

public boolean isDone() {
return (this.angle >= 90.0F || this.progress >= 1.0F);
}

public boolean isMoving() {
return (this.moveDir != -1 && this.moveSpeed != 0.0F);
}

public boolean isRotating() {
return (this.rotateDir != -1 && this.rotateSpeed != 0.0F);
}

public float getValue() {
return isMoving() ? this.progress : this.angle;
}

public void writeToNBT(NBTTagCompound nbt) {
nbt.setInteger("rotateDir", this.rotateDir);
nbt.setInteger("moveDir", this.moveDir);
nbt.setFloat("angle", this.angle);
nbt.setFloat("progress", this.progress);
nbt.setFloat("rotateSpeed", this.rotateSpeed);
nbt.setFloat("moveSpeed", this.moveSpeed);
if (this.rotatePoint != null)
nbt.setTag("rotatePoint", (NBTBase)VectorUtil.writeToNBT(this.rotatePoint));
}

public void readFromNBT(NBTTagCompound nbt) {
this.rotateDir = nbt.getInteger("rotateDir");
this.moveDir = nbt.getInteger("moveDir");
this.angle = nbt.getFloat("angle");
this.rotateSpeed = nbt.getFloat("rotateSpeed");
this.moveSpeed = nbt.getFloat("moveSpeed");
this.progress = nbt.getFloat("progress");
if (nbt.hasKey("rotatePoint"))
this.rotatePoint = VectorUtil.readFromNBT(nbt.getCompoundTag("rotatePoint"));
}
}
Loading