Skip to content

Commit 546aae6

Browse files
committed
Forgot build.gradle from last commit; clean up packet code; add config options
1 parent 85a2bf5 commit 546aae6

File tree

4 files changed

+44
-50
lines changed

4 files changed

+44
-50
lines changed

build.gradle

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@ buildscript {
1313

1414
apply plugin: 'forge'
1515

16-
ext.configFile = file "build.properties"
17-
18-
configFile.withReader {
19-
// Load config. It shall from now be referenced as simply config or project.config
20-
def prop = new Properties()
21-
prop.load(it)
22-
project.ext.config = new ConfigSlurper().parse prop
23-
}
24-
2516
// Finds and sets version data
2617
task buildInfo {
2718
def cmd = "git rev-parse --short HEAD"
@@ -40,13 +31,13 @@ task buildInfo {
4031
}
4132
ext.artifact_version = 'NFG'
4233
if (System.getenv().ARTIFACT_VERSION == null) {
43-
artifact_version = "${config.mod_version}"
34+
artifact_version = "${mod_version}"
4435
}
4536
if (System.getenv().ARTIFACT_VERSION != null) {
4637
artifact_version = "${system.getenv().ARTIFACT_VERSION}"
4738
}
4839

49-
version = "MC${config.minecraft_version}-${artifact_version}-${buildInfo.buildNum}"
40+
version = "MC${minecraft_version}-${artifact_version}-${buildInfo.buildNum}"
5041
def actualVersion = "${artifact_version}-${buildInfo.buildNum}"
5142

5243
minecraft {
Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package tterrag.treesimulator;
22

3+
import java.io.ByteArrayInputStream;
4+
import java.io.DataInputStream;
5+
import java.io.IOException;
6+
37
import net.minecraft.block.Block;
48
import net.minecraft.block.BlockSapling;
59
import net.minecraft.entity.player.EntityPlayer;
@@ -9,25 +13,25 @@
913
import cpw.mods.fml.common.network.Player;
1014

1115
public class PacketHandlerTGS implements IPacketHandler{
12-
1316
@Override
1417
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) {
15-
16-
if (packet.data.length == 12)
17-
{
18-
byte[] bytes = packet.data;
19-
20-
int x = ((bytes[0] & 255) | ((bytes[1] & 255) << 8) | ((bytes[2] & 255) << 16) | (bytes[3] & 255) << 24);
21-
int y = ((bytes[4] & 255) | ((bytes[5] & 255) << 8) | ((bytes[6] & 255) << 16) | (bytes[7] & 255) << 24);
22-
int z = ((bytes[8] & 255) | ((bytes[9] & 255) << 8) | ((bytes[10] & 255) << 16) | (bytes[11] & 255) << 24);
18+
ByteArrayInputStream byteStream = new ByteArrayInputStream(packet.data);
19+
DataInputStream stream = new DataInputStream(byteStream);
20+
int x, y, z;
21+
try {
22+
x = stream.readInt();
23+
y = stream.readInt();
24+
z = stream.readInt();
25+
} catch (IOException e) {
26+
e.printStackTrace();
27+
return;
28+
}
2329

24-
EntityPlayer entity = (EntityPlayer) player;
25-
Block block = Block.blocksList[entity.worldObj.getBlockId(x, y, z)];
26-
if (block instanceof BlockSapling)
27-
{
28-
entity.worldObj.playAuxSFX(2005, x, y, z, 0);
29-
}
30-
System.out.println(String.format("Packet Recieved! block:%s x:%d y:%d z:%d", block == null ? "null" : block.toString(), x, y, z));
30+
EntityPlayer entity = (EntityPlayer) player;
31+
Block block = Block.blocksList[entity.worldObj.getBlockId(x, y, z)];
32+
if (block instanceof BlockSapling)
33+
{
34+
entity.worldObj.playAuxSFX(2005, x, y, z, 0);
3135
}
3236
}
3337
}

src/main/java/tterrag/treesimulator/TickHandlerTGS.java

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package tterrag.treesimulator;
22

3+
import java.io.ByteArrayOutputStream;
4+
import java.io.DataOutputStream;
5+
import java.io.IOException;
36
import java.util.Arrays;
47
import java.util.EnumSet;
58

@@ -44,11 +47,11 @@ public void tickStart(EnumSet<TickType> type, Object... tickData)
4447
if (pos.length == 0)
4548
return;
4649

47-
if (Math.abs(player.posX - posX) > 0.25 || Math.abs(player.posZ - posZ) > 0.25)
50+
if ((Math.abs(player.posX - posX) > 0.25 || Math.abs(player.posZ - posZ) > 0.25) && TreeSimulator.sprintingWorks)
4851
{
4952
movementCounter++;
5053
}
51-
if (PlayerState.getState(player.isSneaking()) != state)
54+
if ((PlayerState.getState(player.isSneaking()) != state) && TreeSimulator.crouchingWorks)
5255
{
5356
movementCounter++;
5457
}
@@ -88,29 +91,21 @@ private void sendPacket(int x, int y, int z, World worldObj, Player player) {
8891
Packet250CustomPayload packet = new Packet250CustomPayload();
8992

9093
packet.channel = TreeSimulator.CHANNEL;
91-
packet.length = 12;
9294

93-
byte[] bytes = new byte[12];
94-
95-
bytes[0] = (byte) (x & 255);
96-
bytes[1] = (byte) ((x >> 8) & 255);
97-
bytes[2] = (byte) ((x >> 16) & 255);
98-
bytes[3] = (byte) ((x >> 24) & 255);
99-
100-
bytes[4] = (byte) (y & 255);
101-
bytes[5] = (byte) ((y >> 8) & 255);
102-
bytes[6] = (byte) ((y >> 16) & 255);
103-
bytes[7] = (byte) ((y >> 24) & 255);
104-
105-
bytes[8] = (byte) (z & 255);
106-
bytes[9] = (byte) ((z >> 8) & 255);
107-
bytes[10] = (byte) ((z >> 16) & 255);
108-
bytes[11] = (byte) ((z >> 24) & 255);
109-
110-
System.out
111-
.println(x + " " + y + " " + z + " " + Arrays.toString(bytes));
95+
ByteArrayOutputStream byteStream = new ByteArrayOutputStream(12);
96+
DataOutputStream stream = new DataOutputStream(byteStream);
97+
try {
98+
stream.writeInt(x);
99+
stream.writeInt(y);
100+
stream.writeInt(z);
101+
stream.close();
102+
} catch (IOException e) {
103+
e.printStackTrace();
104+
return;
105+
}
112106

113-
packet.data = bytes;
107+
packet.data = byteStream.toByteArray();
108+
packet.length = byteStream.size();
114109
PacketDispatcher.sendPacketToPlayer(packet, player);
115110
}
116111

src/main/java/tterrag/treesimulator/TreeSimulator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public class TreeSimulator {
1818

1919
public static int waitTime;
2020
public static boolean showParticles;
21+
public static boolean crouchingWorks;
22+
public static boolean sprintingWorks;
2123
public static final String CHANNEL = "TGS2014";
2224

2325
@Instance
@@ -43,6 +45,8 @@ private void initConfig(File file)
4345

4446
waitTime = config.get("Tweaks", "waitTime", 100, "The amount of ticks (times 5) you must be sprinting before bonemeal is applied").getInt();
4547
showParticles = config.get("Tweaks", "showParticles", true, "Show bonemeal particles when appropriate. Not sure why you would turn this off, but eh").getBoolean(true);
48+
crouchingWorks = config.get("Tweaks", "crouchingWorks", true, "Enable crouching to speed growth").getBoolean(true);
49+
sprintingWorks = config.get("Tweaks", "sprintingWorks", true, "Enable sprinting to speed growth").getBoolean(true);
4650

4751
config.save();
4852
}

0 commit comments

Comments
 (0)