Skip to content

Commit

Permalink
Various api changes, added new player entity.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hilligans committed Apr 21, 2024
1 parent 7b94e9b commit 95e0ca0
Show file tree
Hide file tree
Showing 19 changed files with 148 additions and 27 deletions.
7 changes: 4 additions & 3 deletions src/main/java/dev/hilligans/ourcraft/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import dev.hilligans.ourcraft.save.WorldLoader;
import dev.hilligans.ourcraft.server.MultiPlayerServer;
import dev.hilligans.ourcraft.util.Settings;
import io.netty.channel.ChannelFuture;
import org.lwjgl.BufferUtils;
import org.lwjgl.openal.AL11;

Expand Down Expand Up @@ -401,9 +402,9 @@ public DoubleBuffer getMousePos() {
}

public CompoundNBTTag readUsernameAndPassword(CompoundNBTTag tag) {
playerData.userName = tag.getFullString("username").val;
playerData.login_token = tag.getFullString("loginToken").val;
playerData.email = tag.getFullString("email").val;
playerData.userName = tag.getFullStringTag("username").val;
playerData.login_token = tag.getFullStringTag("loginToken").val;
playerData.email = tag.getFullStringTag("email").val;
return tag;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import dev.hilligans.ourcraft.container.containers.InventoryContainer;
import dev.hilligans.ourcraft.data.UUID;
import dev.hilligans.ourcraft.data.other.Inventory;
import dev.hilligans.ourcraft.entity.IPlayerEntity;
import dev.hilligans.ourcraft.entity.living.entities.PlayerEntity;
import dev.hilligans.ourcraft.item.ItemStack;
import dev.hilligans.ourcraft.network.IServerPacketHandler;
Expand All @@ -19,11 +20,17 @@
import dev.hilligans.ourcraft.world.newworldsystem.IServerWorld;
import io.netty.channel.ChannelId;

import java.util.HashMap;

public class ServerPlayerData implements IServerPacketHandler {

IServer server;

public HashMap<String, Object> arbDataMap = new HashMap<>();

public PlayerEntity playerEntity;
public IPlayerEntity entity;

public ItemStack heldStack = ItemStack.emptyStack();
public Container openContainer;
public Inventory playerInventory;
Expand Down Expand Up @@ -55,6 +62,10 @@ public ServerPlayerData(GameInstance gameInstance, PlayerEntity playerEntity, St
playerInventory.setItem(5,new ItemStack(gameInstance.getItem("blue"),(byte)63));
}

public ServerPlayerData(GameInstance gameInstance, String name) {
this.playerName = name;
}

public ServerPlayerData(PlayerEntity playerEntity, String id, CompoundNBTTag tag) {
this.playerEntity = playerEntity;
this.id = id;
Expand Down Expand Up @@ -123,8 +134,8 @@ public void read(CompoundNBTTag tag) {
}
if (playerEntity != null) {
playerEntity.position = new EntityPosition(tag);
playerEntity.pitch = tag.getFloat("pitch").val;
playerEntity.yaw = tag.getFloat("yaw").val;
playerEntity.pitch = tag.getFloat("pitch");
playerEntity.yaw = tag.getFloat("yaw");
}
} catch (Exception ignored) {}
}
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/dev/hilligans/ourcraft/entity/IEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,26 @@ public interface IEntity {
IWorld getWorld();
void setWorld(IWorld world);

void setRot(float pitch, float yaw);
void setVel(float velX, float velY, float velZ);
void setRot(float pitch, float yaw, float roll);

long getID();
void setID(long id);




float getPitch();
float getYaw();
float getRoll();

void setVel(float velX, float velY, float velZ);
float getVelX();
float getVelY();
float getVelZ();

void setPosition(double x, double y, double z);

double getX();
double getY();
double getZ();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dev.hilligans.ourcraft.entity;

public interface IPlayerEntity extends IEntity {

String getName();

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,24 @@
public class RegistryView {

public GameInstance gameInstance;
public String owner;

public RegistryView(GameInstance gameInstance) {
public RegistryView(GameInstance gameInstance, String owner) {
this.gameInstance = gameInstance;
this.owner = owner;
}

public GameInstance getGameInstance() {
return gameInstance;
}

public void registerRegistry(Supplier<Registry<?>> registry) {
gameInstance.REGISTRIES.put(registry.get());
gameInstance.REGISTRIES.put(registry.get().assignOwner(owner));
}

public void registerRegistry(Supplier<Registry<?>>... registries) {
for(Supplier<Registry<?>> registrySupplier : registries) {
gameInstance.REGISTRIES.put(registrySupplier.get());
gameInstance.REGISTRIES.put(registrySupplier.get().assignOwner(owner));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public StandardPipeline(GameInstance gameInstance) {
public static InstanceLoaderPipeline get(GameInstance gameInstance) {

StandardPipeline pipeline = new StandardPipeline(gameInstance);
RegistryView registryView = new RegistryView(gameInstance);
//RegistryView registryView = new RegistryView(gameInstance);


//load all mods
Expand All @@ -34,7 +34,7 @@ public static InstanceLoaderPipeline get(GameInstance gameInstance) {

//load all the registries defined in each mod
pipeline.addStage("Register Registries", (pipeline16, section) -> {
pipeline16.getModList().foreach(container -> container.modClass.registerRegistries(registryView));
pipeline16.getModList().foreach(container -> container.modClass.registerRegistries(new RegistryView(gameInstance, container.getModID())));
pipeline16.getGameInstance().copyRegistries();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import dev.hilligans.ourcraft.GameInstance;
import dev.hilligans.ourcraft.client.Client;
import dev.hilligans.ourcraft.world.newworldsystem.IWorld;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;

public interface IClientPacketHandler extends IPacketHandler {

void sendPacket(PacketBase<?> packetBase);

Client getClient();

IWorld getWorld();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
@ChannelHandler.Sharable
public class ServerNetworkHandler extends SimpleChannelInboundHandler<IPacketByteArray> implements IServerPacketHandler {

final ChannelGroup channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
public final ChannelGroup channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
public ArrayList<ChannelId> channelIds = new ArrayList<>();
public HashMap<ChannelId, ServerPlayerData> mappedPlayerData = new HashMap<>();
public HashMap<String, ServerPlayerData> nameToPlayerData = new HashMap<>();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/hilligans/ourcraft/save/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public int ensureHasBlock(Block block) {
public void read(CompoundNBTTag compoundTag) {
CompoundNBTTag blocks = compoundTag.getCompoundTag("blocks");
for(String string : blocks.tags.keySet()) {
long val = blocks.getLong(string).val;
long val = blocks.getLong(string);
this.blocks.put(string,new Tuple<>((int)(val >> 32),(int)val));
this.idToNames.put((int) (val >> 32),string);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public Schematic read(ByteBuffer buffer) {
}

CompoundNBTTag metaData = compoundTag.getCompoundTag("Metadata");
Schematic schematic = new Schematic(metaData.getString("Name").getVal());
schematic.withAuthor(metaData.getString("Author").val);
Schematic schematic = new Schematic(metaData.getString("Name"));
schematic.withAuthor(metaData.getString("Author"));

CompoundNBTTag regions = compoundTag.getCompoundTag("Regions");

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/dev/hilligans/ourcraft/server/IServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public interface IServer {

void setTime(long time);

void tick();

Object executeCommand(String command);

ServerNetworkHandler getServerNetworkHandler();
Expand All @@ -27,6 +29,8 @@ public interface IServer {

void sendPacket(PacketBase<?> packetBase, PlayerEntity playerEntity);

void sendPacket(PacketBase<?> packetBase, ServerPlayerData playerData);

GameInstance getGameInstance();

void stop();
Expand All @@ -41,6 +45,7 @@ public Server(IServer server) {
public void run() {
server.setTime(server.getTime() + 1);
Ourcraft.GAME_INSTANCE.EVENT_BUS.postEvent(new ServerTickEvent(server));
server.tick();
// gameProcessor.tickServer(server);
//for(World world : server.getWorlds()) {
// world.tick();
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/dev/hilligans/ourcraft/server/IntegratedServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public void setTime(long time) {
this.time = time;
}

@Override
public void tick() {

}

public Object executeCommand(String command) {
if(!command.startsWith("/")) {
command = "/" + command;
Expand All @@ -81,6 +86,11 @@ public void sendPacket(PacketBase<?> packetBase, PlayerEntity playerEntity) {
sendPacket(packetBase);
}

@Override
public void sendPacket(PacketBase<?> packetBase, ServerPlayerData playerData) {
sendPacket(packetBase);
}

@Override
public GameInstance getGameInstance() {
return null;
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/dev/hilligans/ourcraft/server/MultiPlayerServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public void setTime(long time) {
this.time = time;
}

@Override
public void tick() {

}

public Object executeCommand(String command) {
if(!command.startsWith("/")) {
command = "/" + command;
Expand All @@ -103,6 +108,11 @@ public void sendPacket(PacketBase<?> packetBase, PlayerEntity playerEntity) {
getServerNetworkHandler().sendPacket(packetBase,playerEntity);
}

@Override
public void sendPacket(PacketBase<?> packetBase, ServerPlayerData playerData) {
getServerNetworkHandler().sendPacket(packetBase, playerData.getChannelId());
}

@Override
public GameInstance getGameInstance() {
return gameInstance;
Expand Down
49 changes: 43 additions & 6 deletions src/main/java/dev/hilligans/ourcraft/tag/CompoundNBTTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,38 +84,75 @@ public NBTTag getTag(String name) {
return tags.get(name);
}

public ByteNBTTag getByteTag(String name) {
return (ByteNBTTag) getTag(name);
}

public ShortNBTTag getShortTag(String name) {
return (ShortNBTTag) getTag(name);
}

public IntegerNBTTag getIntTag(String name) {
return (IntegerNBTTag)getTag(name);
}

public StringNBTTag getString(String id) {
public StringNBTTag getStringTag(String id) {
return (StringNBTTag)getTag(id);
}

public DoubleNBTTag getDouble(String id) {
public DoubleNBTTag getDoubleTag(String id) {
return (DoubleNBTTag)getTag(id);
}

public FloatNBTTag getFloat(String id) {
public FloatNBTTag getFloatTag(String id) {
return (FloatNBTTag)getTag(id);
}

public LongNBTTag getLong(String id) {
public LongNBTTag getLongTag(String id) {
return (LongNBTTag)getTag(id);
}

public boolean getBoolean(String id) {
public boolean getBooleanTag(String id) {
return ((ByteNBTTag)getTag(id)).val == 1;
}

public FullStringNBTTag getFullString(String id) {
public FullStringNBTTag getFullStringTag(String id) {
return (FullStringNBTTag)getTag(id);
}


public byte getByte(String name) {
return getByteTag(name).val;
}

public short getShort(String name) {
return getShortTag(name).val;
}

public int getInt(String name) {
return ((IntegerNBTTag)getTag(name)).val;
}

public long getLong(String name) {
return getLongTag(name).val;
}

public String getString(String name) {
return getStringTag(name).val;
}

public float getFloat(String name) {
return getFloatTag(name).val;
}

public double getDouble(String name) {
return getDoubleTag(name).val;
}

public boolean getBoolean(String name) {
return getBooleanTag(name);
}

public CompoundNBTTag getCompoundTag(String name) {
return (CompoundNBTTag) tags.get(name);
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/dev/hilligans/ourcraft/util/EntityPosition.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public EntityPosition(CompoundNBTTag tag) {
chunkY = tag.getInt("cy");
chunkZ = tag.getInt("cz");

x = tag.getFloat("x").val;
y = tag.getFloat("y").val;
z = tag.getFloat("z").val;
x = tag.getFloat("x");
y = tag.getFloat("y");
z = tag.getFloat("z");

int val = tag.getInt("w");
chunkWidth = (short) (val);
Expand Down
Loading

0 comments on commit 95e0ca0

Please sign in to comment.