login + network changes, add forms

This commit is contained in:
Sen 2025-05-14 14:58:06 +02:00
parent 111226fe28
commit eba8f6ea98
44 changed files with 894 additions and 224 deletions

View file

@ -28,7 +28,7 @@ public enum BaseBiome {
ICEPLAINS(12, "icePlains", "Eisebene", 0xffffff, -20.0f),
ICEMOUNTAINS(13, "iceMountains", "Vereistes Bergland", 0xa0a0a0, -20.0f),
MUSHROOMPLAINS(14, "mushroomPlains", "Pilzland", 0xff00ff, 16.0f, 100.0f),
BLACKENED(15, "blackened", "Schwarz", 0x000000, 0.0f, 0.0f),
BLACKENED(15, "blackened", "Schwarz", 0x000000, 0.0f, 0.0f, 0x000000, 0x303030, 0x303030),
BEACH(16, "beach", "Strand", 0xfade55, 12.0f, 40.0f),
DESERTHILLS(17, "desertHills", "Wüsten-Bergland", 0xd25f12, 60.0f, 0.0f),
FORESTHILLS(18, "forestHills", "Wald-Bergland", 0x22551c, 8.0f, 80.0f),

View file

@ -1,5 +1,7 @@
package common.block;
import common.entity.npc.EntityNPC;
import common.init.Config;
import common.init.Items;
import common.item.Item;
import common.material.Material;
@ -8,6 +10,7 @@ import common.tileentity.TileEntity;
import common.tileentity.TileEntitySign;
import common.util.BlockPos;
import common.util.BoundingBox;
import common.util.Facing;
import common.world.IBlockAccess;
import common.world.State;
import common.world.World;
@ -22,6 +25,20 @@ public class BlockSign extends BlockContainer
this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f1, 0.5F + f);
}
public boolean onBlockActivated(World worldIn, BlockPos pos, State state, EntityNPC playerIn, Facing side, float hitX, float hitY, float hitZ)
{
if (!worldIn.client && Config.editSigns)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntitySign)
{
playerIn.openEditSign((TileEntitySign)tileentity);
}
}
return true;
}
public BoundingBox getCollisionBoundingBox(World worldIn, BlockPos pos, State state)
{
return null;

View file

@ -333,8 +333,12 @@ public abstract class Config {
public static boolean itemFallDamage = true;
@Var(name = "registration")
public static boolean register = true;
@Var(name = "authentication")
public static boolean auth = true;
@Var(name = "preload_chunks")
public static boolean preload = true;
@Var(name = "signEditing")
public static boolean editSigns = true;
@Var(name = "keepInventory")
public static boolean keepInventory = false;
@ -348,8 +352,6 @@ public abstract class Config {
public static boolean rabidRabbits = false;
@Var(name = "snowStacking")
public static boolean snowStack = false;
@Var(name = "authentication")
public static boolean auth = false;
// @Var(name = "teleportForAll")
// public static boolean teleportAllowed = false;
// @Var(name = "preload_chunks_all") // Vorsicht Lag!!
@ -454,6 +456,8 @@ public abstract class Config {
public static int eggTimer = 6000;
@Var(name = "connectionTimeout", min = 10, max = 300)
public static int timeout = 30;
@Var(name = "passwordMinLength", min = 1, max = 32)
public static int minPassLength = 8;
// @Var(name = "spawnX", min = -World.MAX_SIZE + 1, max = World.MAX_SIZE - 1)
// public static int spawnX = 0;

View file

@ -45,6 +45,7 @@ import common.packet.SPacketCollectItem;
import common.packet.SPacketDestroyEntities;
import common.packet.SPacketDimensionName;
import common.packet.SPacketDisconnect;
import common.packet.SPacketDisplayForm;
import common.packet.SPacketEntityEquipment;
import common.packet.SPacketEntityVelocity;
import common.packet.SPacketHeldItemChange;
@ -146,11 +147,12 @@ public interface IClientPlayer {
void handleTrades(SPacketTrades packetIn);
void handleWorld(SPacketWorld packetIn);
void handleDimName(SPacketDimensionName packetIn);
void handleForm(SPacketDisplayForm packet);
void displayGUIChest(IInventory chestInventory, InventoryPlayer inventory);
void displayGui(IInteractionObject guiOwner, InventoryPlayer inventory, World worldObj);
void displayGuiHorse(EntityHorse horse, InventoryPlayer inventory, IInventory horseInventory);
void displayGuiMerchant(String title, InventoryPlayer inventory, World worldObj);
void displayGuiSign(BlockPos pos, String[] signText);
void displayGuiSign(BlockPos pos, String[] text);
void closeGui();
}

View file

@ -16,6 +16,7 @@ import common.packet.CPacketBreak;
import common.packet.CPacketCheat;
import common.packet.CPacketClick;
import common.packet.CPacketComplete;
import common.packet.CPacketForm;
import common.packet.CPacketInput;
import common.packet.CPacketKeepAlive;
import common.packet.CPacketMessage;
@ -166,6 +167,8 @@ public interface IPlayer {
void processSkin(CPacketSkin packetIn);
void processBook(CPacketBook packetIn);
void processForm(CPacketForm packet);
List<ChunkPos> getLoadedChunkList();
double getManagedX();

View file

@ -11,6 +11,7 @@ import common.packet.CPacketBreak;
import common.packet.CPacketCheat;
import common.packet.CPacketClick;
import common.packet.CPacketComplete;
import common.packet.CPacketForm;
import common.packet.CPacketInput;
import common.packet.CPacketKeepAlive;
import common.packet.CPacketMessage;
@ -63,6 +64,7 @@ import common.packet.SPacketCollectItem;
import common.packet.SPacketDestroyEntities;
import common.packet.SPacketDimensionName;
import common.packet.SPacketDisconnect;
import common.packet.SPacketDisplayForm;
import common.packet.SPacketEntityEquipment;
import common.packet.SPacketEntityVelocity;
import common.packet.SPacketHeldItemChange;
@ -181,6 +183,7 @@ public enum PacketRegistry
this.server(SPacketCharacterList.class);
this.server(SPacketServerTick.class);
this.server(SPacketLoading.class);
this.server(SPacketDisplayForm.class);
this.client(CPacketKeepAlive.class);
this.client(CPacketMessage.class);
@ -198,7 +201,7 @@ public enum PacketRegistry
this.client(CPacketSkin.class);
this.client(CPacketSign.class);
this.client(CPacketBook.class);
// this.client(CPacketCmdBlock.class);
this.client(CPacketForm.class);
}
};

View file

@ -0,0 +1,86 @@
package common.packet;
import java.io.IOException;
import common.network.IPlayer;
import common.network.Packet;
import common.network.PacketBuffer;
public class CPacketForm implements Packet<IPlayer>
{
private int id;
private Object[] data;
public CPacketForm()
{
}
public CPacketForm(int id, Object[] data)
{
this.id = id;
this.data = data;
}
public void readPacketData(PacketBuffer buf) throws IOException
{
this.id = buf.readVarIntFromBuffer();
if(!buf.readBoolean()) {
this.data = null;
return;
}
this.data = new Object[buf.readVarIntFromBuffer()];
for(int z = 0; z < this.data.length; z++) {
Object obj;
switch(buf.readByte()) {
case 0:
obj = buf.readBoolean();
break;
case 1:
obj = buf.readVarIntFromBuffer();
break;
default:
obj = buf.readStringFromBuffer(256);
break;
}
this.data[z] = obj;
}
}
public void writePacketData(PacketBuffer buf) throws IOException
{
buf.writeVarIntToBuffer(this.id);
buf.writeBoolean(this.data != null);
if(this.data == null)
return;
buf.writeVarIntToBuffer(this.data.length);
for(int z = 0; z < this.data.length; z++) {
Object obj = this.data[z];
if(obj instanceof Boolean) {
buf.writeByte(0);
buf.writeBoolean((Boolean)obj);
}
else if(obj instanceof Integer) {
buf.writeByte(1);
buf.writeVarIntToBuffer((Integer)obj);
}
else {
buf.writeByte(2);
buf.writeString((String)obj);
}
}
}
public void processPacket(IPlayer handler)
{
handler.processForm(this);
}
public Object[] getData()
{
return this.data;
}
public int getId() {
return this.id;
}
}

View file

@ -6,22 +6,29 @@ import common.network.IClientPlayer;
import common.network.Packet;
import common.network.PacketBuffer;
public class SPacketDisconnect implements Packet<IClientPlayer>
{
public SPacketDisconnect()
{
}
public void readPacketData(PacketBuffer buf) throws IOException
{
}
public void writePacketData(PacketBuffer buf) throws IOException
{
}
public void processPacket(IClientPlayer handler)
{
handler.handleDisconnect(this);
}
public class SPacketDisconnect implements Packet<IClientPlayer> {
private String message;
public SPacketDisconnect() {
}
public SPacketDisconnect(String message) {
this.message = message;
}
public void readPacketData(PacketBuffer buf) throws IOException {
this.message = buf.readStringFromBuffer(2048);
}
public void writePacketData(PacketBuffer buf) throws IOException {
buf.writeString(this.message);
}
public void processPacket(IClientPlayer handler) {
handler.handleDisconnect(this);
}
public String getMessage() {
return this.message;
}
}

View file

@ -0,0 +1,99 @@
package common.packet;
import java.io.IOException;
import common.network.IClientPlayer;
import common.network.Packet;
import common.network.PacketBuffer;
import common.util.Triplet;
public class SPacketDisplayForm implements Packet<IClientPlayer>
{
private int id;
private String title;
private Triplet<String, Object, Integer>[] data;
public SPacketDisplayForm()
{
}
public SPacketDisplayForm(int id, String title, Triplet<String, Object, Integer>[] data)
{
this.id = id;
this.title = title;
this.data = data;
}
public void processPacket(IClientPlayer handler)
{
handler.handleForm(this);
}
public void readPacketData(PacketBuffer buf) throws IOException
{
this.id = buf.readVarIntFromBuffer();
this.title = buf.readStringFromBuffer(256);
this.data = new Triplet[buf.readVarIntFromBuffer()];
for(int z = 0; z < this.data.length; z++) {
String name = buf.readStringFromBuffer(64);
Object obj;
switch(buf.readByte()) {
case 0:
obj = buf.readBoolean();
break;
case 1:
String[] strs = new String[buf.readVarIntFromBuffer()];
obj = strs;
for(int n = 0; n < strs.length; n++) {
strs[n] = buf.readStringFromBuffer(128);
}
break;
default:
obj = buf.readStringFromBuffer(256);
break;
}
this.data[z] = new Triplet<String, Object, Integer>(name, obj, buf.readVarIntFromBuffer());
}
}
public void writePacketData(PacketBuffer buf) throws IOException
{
buf.writeVarIntToBuffer(this.id);
buf.writeString(this.title);
buf.writeVarIntToBuffer(this.data.length);
for(int z = 0; z < this.data.length; z++) {
buf.writeString(this.data[z].first);
Object obj = this.data[z].second;
if(obj instanceof Boolean) {
buf.writeByte(0);
buf.writeBoolean((Boolean)obj);
}
else if(obj instanceof String[]) {
buf.writeByte(1);
String[] strs = (String[])obj;
buf.writeVarIntToBuffer(strs.length);
for(int n = 0; n < strs.length; n++) {
buf.writeString(strs[n]);
}
}
else {
buf.writeByte(2);
buf.writeString((String)obj);
}
buf.writeVarIntToBuffer(this.data[z].third);
}
}
public Triplet<String, Object, Integer>[] getData()
{
return this.data;
}
public String getTitle() {
return this.title;
}
public int getId() {
return this.id;
}
}

View file

@ -0,0 +1,10 @@
package common.util;
public class Triplet<S, T, U> extends Tuple<S, T> {
public final U third;
public Triplet(S first, T second, U third) {
super(first, second);
this.third = third;
}
}