mirror of
https://github.com/GTNewHorizons/StructureLib.git
synced 2026-11-20 20:12:09 +00:00
Implement autoplace (#6)
This commit is contained in:
1 parent
e8f5cd6489
commit
609e50428e
60 files changed
+3699
-702
No files matched your search
@@ -21,8 +21,7 @@ public abstract class AlignmentMessage implements IMessage {
|
||||
int mPosD;
|
||||
int mAlign;
|
||||
|
||||
public AlignmentMessage() {
|
||||
}
|
||||
public AlignmentMessage() {}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf pBuffer) {
|
||||
@@ -47,11 +46,9 @@ public abstract class AlignmentMessage implements IMessage {
|
||||
}
|
||||
|
||||
private AlignmentMessage(IAlignmentProvider provider) {
|
||||
if (!(provider instanceof TileEntity))
|
||||
throw new IllegalArgumentException("Provider must be a TileEntity");
|
||||
if (!(provider instanceof TileEntity)) throw new IllegalArgumentException("Provider must be a TileEntity");
|
||||
IAlignment alignment = provider.getAlignment();
|
||||
if (alignment == null)
|
||||
throw new IllegalArgumentException("Passed in provider does not provide an alignment!");
|
||||
if (alignment == null) throw new IllegalArgumentException("Passed in provider does not provide an alignment!");
|
||||
TileEntity base = (TileEntity) provider;
|
||||
mPosX = base.xCoord;
|
||||
mPosY = base.yCoord;
|
||||
@@ -69,8 +66,7 @@ public abstract class AlignmentMessage implements IMessage {
|
||||
}
|
||||
|
||||
public static class AlignmentQuery extends AlignmentMessage {
|
||||
public AlignmentQuery() {
|
||||
}
|
||||
public AlignmentQuery() {}
|
||||
|
||||
public AlignmentQuery(IAlignmentProvider provider) {
|
||||
super(provider);
|
||||
@@ -82,8 +78,7 @@ public abstract class AlignmentMessage implements IMessage {
|
||||
}
|
||||
|
||||
public static class AlignmentData extends AlignmentMessage {
|
||||
public AlignmentData() {
|
||||
}
|
||||
public AlignmentData() {}
|
||||
|
||||
private AlignmentData(AlignmentQuery query) {
|
||||
mPosX = query.mPosX;
|
||||
@@ -106,7 +101,9 @@ public abstract class AlignmentMessage implements IMessage {
|
||||
@Override
|
||||
public IMessage onMessage(AlignmentData pMessage, MessageContext pCtx) {
|
||||
if (StructureLib.getCurrentPlayer().worldObj.provider.dimensionId == pMessage.mPosD) {
|
||||
TileEntity te = StructureLib.getCurrentPlayer().worldObj.getTileEntity(pMessage.mPosX, pMessage.mPosY, pMessage.mPosZ);
|
||||
TileEntity te = StructureLib.getCurrentPlayer()
|
||||
.worldObj
|
||||
.getTileEntity(pMessage.mPosX, pMessage.mPosY, pMessage.mPosZ);
|
||||
if (te instanceof IAlignmentProvider) {
|
||||
IAlignment alignment = ((IAlignmentProvider) te).getAlignment();
|
||||
if (alignment != null) {
|
||||
@@ -126,8 +123,7 @@ public abstract class AlignmentMessage implements IMessage {
|
||||
TileEntity te = world.getTileEntity(pMessage.mPosX, pMessage.mPosY, pMessage.mPosZ);
|
||||
if (te instanceof IAlignmentProvider) {
|
||||
IAlignment alignment = ((IAlignmentProvider) te).getAlignment();
|
||||
if (alignment == null)
|
||||
return null;
|
||||
if (alignment == null) return null;
|
||||
pMessage.mAlign = alignment.getExtendedFacing().getIndex();
|
||||
return new AlignmentData(pMessage);
|
||||
}
|
||||
@@ -135,4 +131,4 @@ public abstract class AlignmentMessage implements IMessage {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.gtnewhorizon.structurelib.net;
|
||||
|
||||
import static com.gtnewhorizon.structurelib.StructureLib.LOGGER;
|
||||
|
||||
import com.gtnewhorizon.structurelib.StructureLib;
|
||||
import com.gtnewhorizon.structurelib.StructureLibAPI;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class UpdateHintParticleMessage implements IMessage {
|
||||
private int x;
|
||||
private short y;
|
||||
private int z;
|
||||
private short r;
|
||||
private short g;
|
||||
private short b;
|
||||
private short a;
|
||||
|
||||
public UpdateHintParticleMessage() {}
|
||||
|
||||
public UpdateHintParticleMessage(int x, short y, int z, short r, short g, short b, short a) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.r = r;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
this.a = a;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
x = buf.readInt();
|
||||
y = buf.readShort();
|
||||
z = buf.readInt();
|
||||
r = buf.readUnsignedByte();
|
||||
g = buf.readUnsignedByte();
|
||||
b = buf.readUnsignedByte();
|
||||
a = buf.readUnsignedByte();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(x);
|
||||
buf.writeShort(y);
|
||||
buf.writeInt(z);
|
||||
buf.writeByte(r);
|
||||
buf.writeByte(g);
|
||||
buf.writeByte(b);
|
||||
buf.writeByte(a);
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<UpdateHintParticleMessage, IMessage> {
|
||||
@Override
|
||||
public IMessage onMessage(UpdateHintParticleMessage msg, MessageContext ctx) {
|
||||
boolean updateResult = StructureLibAPI.updateHintParticleTint(
|
||||
StructureLib.getCurrentPlayer(),
|
||||
StructureLib.getCurrentPlayer().worldObj,
|
||||
msg.x,
|
||||
msg.y,
|
||||
msg.z,
|
||||
new short[] {
|
||||
msg.r, msg.g, msg.b, msg.a,
|
||||
});
|
||||
if (StructureLib.DEBUG_MODE)
|
||||
LOGGER.debug(
|
||||
"Server instructed to update hint particle at ({}, {}, {}), result {}!",
|
||||
msg.x,
|
||||
msg.y,
|
||||
msg.z,
|
||||
updateResult);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user