Fix dupe glitch, start on modding API

This commit is contained in:
PeytonPlayz595 2024-03-28 23:48:54 -04:00
parent ac548b8c9b
commit 11f28fef53
17 changed files with 365 additions and 31 deletions

Binary file not shown.

View File

@ -0,0 +1,13 @@
package net.PeytonPlayz585;
public class Location {
public int x,y,z;
public Location(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
}

View File

@ -0,0 +1,69 @@
package net.PeytonPlayz585;
import java.util.logging.Logger;
import net.minecraft.server.MinecraftServer;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.EntityPlayerMP;
public class Server {
public static String getName() {
return "Vanilla Server";
}
public static String getVersion() {
return "Alpha v1.2.6";
}
public static EntityPlayer[] getOnlinePlayers() {
return (EntityPlayer[])MinecraftServer.configManager.playerEntities.toArray(new EntityPlayerMP[MinecraftServer.configManager.playerEntities.size()]);
}
public static int getMaxPlayers() {
return MinecraftServer.configManager.maxPlayers;
}
public static int getPort() {
return MinecraftServer.port == 0 ? 25565 : MinecraftServer.port;
}
public static String getIP() {
if(MinecraftServer.serverIP == null) {
return "localhost";
}
return MinecraftServer.serverIP;
}
public static String getLevelName() {
if(MinecraftServer.levelName == null) {
return "world";
}
return MinecraftServer.levelName;
}
public static void broadcastMessage(String message) {
MinecraftServer.configManager.sendChatMessageToAllPlayers("\u00a77(" + message + ")");
}
public static EntityPlayer getPlayerByName(String name) {
for(int var1 = 0; var1 < MinecraftServer.configManager.playerEntities.size(); ++var1) {
EntityPlayerMP player = (EntityPlayerMP)MinecraftServer.configManager.playerEntities.get(var1);
if(player.username.equalsIgnoreCase(name)) {
return player;
}
}
return null;
}
public static void savePlayers() {
if(MinecraftServer.configManager != null) {
MinecraftServer.configManager.savePlayerStates();
}
}
public static Logger getLogger() {
return MinecraftServer.logger;
}
}

View File

@ -0,0 +1,5 @@
package net.PeytonPlayz585;
public enum TreeType {
TREE, BIG_TREE;
}

View File

@ -0,0 +1,106 @@
package net.PeytonPlayz585;
import net.PeytonPlayzt585.entity.CreatureType;
import net.minecraft.server.MinecraftServer;
import net.minecraft.src.Block;
import net.minecraft.src.Chunk;
import net.minecraft.src.Entity;
import net.minecraft.src.IProgressUpdate;
import net.minecraft.src.WorldProvider;
public class World {
public static Block getBlockAt(int var1, int var2, int var3) {
return Block.blocksList[MinecraftServer.worldMngr.getBlockId(var1, var2, var3)];
}
public static Chunk getChunkFromBlockCoords(int var1, int var2) {
return MinecraftServer.worldMngr.getChunkFromBlockCoords(var1, var2);
}
public static Chunk getChunkFromChunkCoords(int var1, int var2) {
return MinecraftServer.worldMngr.getChunkFromChunkCoords(var1, var2);
}
public static boolean isChunkLoaded(int var1, int var2) {
Chunk chunk = getChunkFromChunkCoords(var1, var2);
if(chunk == null) {
chunk = getChunkFromBlockCoords(var1, var2);
if(chunk == null) {
return false;
}
}
return chunk.func_347_a();
}
public static boolean loadChunk(int x, int y, boolean var1) {
Chunk chunk = MinecraftServer.worldMngr.A.loadChunk(x, y);
if(chunk == null) {
return false;
}
return true;
}
public static void spawnCreature(CreatureType type, double x, double y, double z) {
Entity entity = type.nameToEntity(type.name());
entity.func_107_c(x, y, z, MinecraftServer.worldMngr.rand.nextFloat() * 360.0F, 0.0F);
MinecraftServer.worldMngr.entityJoinedWorld(entity);
}
public static void spawnCreature(CreatureType type, float x, float y, float z) {
Entity entity = type.nameToEntity(type.name());
entity.func_107_c(x, y, z, MinecraftServer.worldMngr.rand.nextFloat() * 360.0F, 0.0F);
MinecraftServer.worldMngr.entityJoinedWorld(entity);
}
public static void spawnCreature(CreatureType type, int x, int y, int z) {
Entity entity = type.nameToEntity(type.name());
entity.func_107_c(x, y, z, MinecraftServer.worldMngr.rand.nextFloat() * 360.0F, 0.0F);
MinecraftServer.worldMngr.entityJoinedWorld(entity);
}
public static Location getSpawnLocation() {
int x = MinecraftServer.worldMngr.spawnX;
int y = MinecraftServer.worldMngr.spawnY;
int z = MinecraftServer.worldMngr.spawnZ;
return new Location(x, y, z);
}
public static void setSpawnLocation(int x, int y, int z) {
MinecraftServer.worldMngr.spawnX = x;
MinecraftServer.worldMngr.spawnY = y;
MinecraftServer.worldMngr.spawnZ = z;
}
public static long getWorldTime() {
return MinecraftServer.worldMngr.worldTime;
}
public static void setWorldTime(long time) {
MinecraftServer.worldMngr.worldTime = time;
}
public static void saveWorld() {
MinecraftServer.logger.info("Saving World!");
if(MinecraftServer.configManager != null) {
MinecraftServer.configManager.savePlayerStates();
}
MinecraftServer.worldMngr.func_485_a(true, (IProgressUpdate)null);
}
public static Environment getEnvironment() {
if(WorldProvider.dimension == 0) {
return Environment.NORMAL;
} else {
return Environment.NETHER;
}
}
public enum Environment {
NORMAL, NETHER;
}
}

View File

@ -0,0 +1,87 @@
package net.PeytonPlayzt585.entity;
import java.lang.reflect.InvocationTargetException;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.server.MinecraftServer;
import net.minecraft.src.Entity;
import net.minecraft.src.EntityChicken;
import net.minecraft.src.EntityCow;
import net.minecraft.src.EntityCreeper;
import net.minecraft.src.EntityGhast;
import net.minecraft.src.EntityPig;
import net.minecraft.src.EntitySheep;
import net.minecraft.src.EntitySkeleton;
import net.minecraft.src.EntitySlime;
import net.minecraft.src.EntitySpider;
import net.minecraft.src.EntityZombie;
import net.minecraft.src.World;
public enum CreatureType {
CHICKEN("Chicken"),
COW("Cow"),
CREEPER("Creeper"),
GHAST("Ghast"),
PIG("Pig"),
SHEEP("Sheep"),
SKELETON("Skeleton"),
SLIME("Slime"),
SPIDER("Spider"),
ZOMBIE("Zombie");
private String name;
private static final Map<String, CreatureType> mapping;
static {
mapping = new HashMap<String, CreatureType>();
for (CreatureType type : EnumSet.<CreatureType>allOf(CreatureType.class))
mapping.put(type.name, type);
}
CreatureType(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
public Entity nameToEntity(String name) {
try {
if(name.equals("Chicken")) {
return EntityChicken.class.getConstructor(new Class[]{World.class}).newInstance(new Object[]{MinecraftServer.worldMngr});
} else if(name.equals("Cow")) {
return EntityCow.class.getConstructor(new Class[]{World.class}).newInstance(new Object[]{MinecraftServer.worldMngr});
} else if(name.equals("Creeper")) {
return EntityCreeper.class.getConstructor(new Class[]{World.class}).newInstance(new Object[]{MinecraftServer.worldMngr});
} else if(name.equals("Ghast")) {
return EntityGhast.class.getConstructor(new Class[]{World.class}).newInstance(new Object[]{MinecraftServer.worldMngr});
} else if(name.equals("Pig")) {
return EntityPig.class.getConstructor(new Class[]{World.class}).newInstance(new Object[]{MinecraftServer.worldMngr});
} else if(name.equals("Sheep")) {
return EntitySheep.class.getConstructor(new Class[]{World.class}).newInstance(new Object[]{MinecraftServer.worldMngr});
} else if(name.equals("Skeleton")) {
return EntitySkeleton.class.getConstructor(new Class[]{World.class}).newInstance(new Object[]{MinecraftServer.worldMngr});
} else if(name.equals("Slime")) {
return EntitySlime.class.getConstructor(new Class[]{World.class}).newInstance(new Object[]{MinecraftServer.worldMngr});
} else if(name.equals("Spider")) {
return EntitySpider.class.getConstructor(new Class[]{World.class}).newInstance(new Object[]{MinecraftServer.worldMngr});
} else if(name.equals("Zombie")) {
return EntityZombie.class.getConstructor(new Class[]{World.class}).newInstance(new Object[]{MinecraftServer.worldMngr});
}
} catch(InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
System.err.println("Error mapping entity name to class!");
return null;
}
System.err.println("Entity (" + name + ") not found!");
return null;
}
public static CreatureType fromName(String name) {
return mapping.get(name);
}
}

View File

@ -40,8 +40,8 @@ public class MinecraftServer implements ICommandListener, Runnable {
public static HashMap field_6037_b = new HashMap();
public NetworkListenThread field_6036_c;
public PropertyManager propertyManagerObj;
public WorldServer worldMngr;
public ServerConfigurationManager configManager;
public static WorldServer worldMngr;
public static ServerConfigurationManager configManager;
private boolean field_6025_n = true;
public boolean field_6032_g = false;
int field_9014_h = 0;
@ -53,6 +53,9 @@ public class MinecraftServer implements ICommandListener, Runnable {
public boolean onlineMode;
public boolean noAnimals;
public boolean field_9011_n;
public static int port = 0;
public static String levelName = null;
public static String serverIP = null;
public MinecraftServer() {
new ThreadSleepForever(this);
@ -78,9 +81,11 @@ public class MinecraftServer implements ICommandListener, Runnable {
InetAddress var3 = null;
if(var2.length() > 0) {
var3 = InetAddress.getByName(var2);
serverIP = var3.toString();
}
int var4 = this.propertyManagerObj.getIntProperty("server-port", 25565);
port = var4;
logger.info("Starting Minecraft server on " + (var2.length() == 0 ? "*" : var2) + ":" + var4);
try {
@ -102,6 +107,7 @@ public class MinecraftServer implements ICommandListener, Runnable {
this.configManager = new ServerConfigurationManager(this);
this.field_6028_k = new EntityTracker(this);
String var5 = this.propertyManagerObj.getStringProperty("level-name", "world");
levelName = var5;
logger.info("Preparing level \"" + var5 + "\"");
this.func_6017_c(var5);
logger.info("Done! For help, type \"help\" or \"?\"");
@ -298,6 +304,19 @@ public class MinecraftServer implements ICommandListener, Runnable {
} else if(var2.toLowerCase().startsWith("save-on")) {
this.func_6014_a(var4, "Enabling level saving..");
this.worldMngr.field_816_A = false;
} else if(var2.toLowerCase().startsWith("spawn-protection")) {
boolean b = this.configManager.isOp(var4) || var4.equals("CONSOLE");
if(!b) {
return;
}
String var11 = var2.substring(var2.indexOf(" ")).trim();
if(var11.equals("enable")) {
this.worldMngr.spawnProtection = true;
} else if(var11.equals("disable")) {
this.worldMngr.spawnProtection = false;
} else {
return;
}
} else {
String var11;
if(var2.toLowerCase().startsWith("op ")) {

View File

@ -521,7 +521,7 @@ public class Chunk {
}
public boolean func_347_a(boolean var1) {
public boolean func_347_a() {
return this.field_679_p ? false : (this.field_677_r && this.worldObj.worldTime != this.field_676_s ? true : this.isModified);
}

View File

@ -144,7 +144,7 @@ public class ChunkProviderLoadOrGenerate implements IChunkProvider {
int var5;
if(var2 != null) {
for(var5 = 0; var5 < this.chunks.length; ++var5) {
if(this.chunks[var5] != null && this.chunks[var5].func_347_a(var1)) {
if(this.chunks[var5] != null && this.chunks[var5].func_347_a()) {
++var4;
}
}
@ -158,7 +158,7 @@ public class ChunkProviderLoadOrGenerate implements IChunkProvider {
this.func_371_a(this.chunks[var6]);
}
if(this.chunks[var6].func_347_a(var1)) {
if(this.chunks[var6].func_347_a()) {
this.func_370_b(this.chunks[var6]);
this.chunks[var6].isModified = false;
++var3;

View File

@ -150,7 +150,7 @@ public class ChunkProviderServer implements IChunkProvider {
this.func_375_a(var5);
}
if(var5.func_347_a(var1)) {
if(var5.func_347_a()) {
this.func_373_b(var5);
var5.isModified = false;
++var3;

View File

@ -116,4 +116,8 @@ public final class ItemStack {
public ItemStack copy() {
return new ItemStack(this.itemID, this.stackSize, this.itemDamage);
}
public static ItemStack func_20117_a(ItemStack var0) {
return var0 == null ? null : var0.copy();
}
}

View File

@ -214,13 +214,13 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
}
if(var1.status == 0) {
if(var19 > 16 || var2) {
if(var19 > 16 || var2 || !this.mcServer.worldMngr.spawnProtection) {
this.playerEntity.field_425_ad.func_324_a(var4, var5, var6);
}
} else if(var1.status == 2) {
this.playerEntity.field_425_ad.func_328_a();
} else if(var1.status == 1) {
if(var19 > 16 || var2) {
if(var19 > 16 || var2 || !this.mcServer.worldMngr.spawnProtection) {
this.playerEntity.field_425_ad.func_326_a(var4, var5, var6, var18);
}
} else if(var1.status == 3) {
@ -231,7 +231,7 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
if(var16 < 256.0D) {
this.playerEntity.field_421_a.sendPacket(new Packet53BlockChange(var4, var5, var6, this.mcServer.worldMngr));
}
if(!(var19 > 16 || var2)) {
if(!(var19 > 16 || var2) && this.mcServer.worldMngr.spawnProtection) {
this.playerEntity.field_421_a.sendPacket(new Packet3Chat("You cannot place/break blocks in this area!"));
}
}
@ -241,6 +241,7 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
public void handlePlace(Packet15Place var1) {
boolean var2 = this.mcServer.worldMngr.field_819_z = this.mcServer.configManager.isOp(this.playerEntity.username);
ItemStack stack = this.playerEntity.inventory.getCurrentItem();
if(var1.direction == 255) {
ItemStack var3 = var1.id >= 0 ? new ItemStack(var1.id) : null;
this.playerEntity.field_425_ad.func_6154_a(this.playerEntity, this.mcServer.worldMngr, var3);
@ -255,8 +256,15 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
var8 = var7;
}
ItemStack var9 = var1.id >= 0 ? new ItemStack(var1.id) : null;
this.playerEntity.field_425_ad.func_327_a(this.playerEntity, this.mcServer.worldMngr, var9, var10, var4, var5, var6);
if(this.mcServer.worldMngr.spawnProtection) {
if(var8 > 16 || var2) {
ItemStack var9 = var1.id >= 0 ? new ItemStack(var1.id) : null;
this.playerEntity.field_425_ad.func_327_a(this.playerEntity, this.mcServer.worldMngr, var9, var10, var4, var5, var6);
}
} else {
ItemStack var9 = var1.id >= 0 ? new ItemStack(var1.id) : null;
this.playerEntity.field_425_ad.func_327_a(this.playerEntity, this.mcServer.worldMngr, var9, var10, var4, var5, var6);
}
this.playerEntity.field_421_a.sendPacket(new Packet53BlockChange(var10, var4, var5, this.mcServer.worldMngr));
if(var6 == 0) {
@ -285,21 +293,13 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
this.playerEntity.field_421_a.sendPacket(new Packet53BlockChange(var10, var4, var5, this.mcServer.worldMngr));
if(!(var8 > 16 | var2)) {
if(field_10_k != null) {
this.playerEntity.field_421_a.sendPacket(new Packet3Chat("You cannot place/break blocks in this area!"));
this.playerEntity.field_425_ad.func_323_b(var10, var4, var5);
this.playerEntity.field_421_a.sendPacket(new Packet53BlockChange(var10, var4, var5, this.mcServer.worldMngr));
ItemStack[] stack = this.playerEntity.inventory.mainInventory.clone();
ItemStack stack1 = new ItemStack(var1.id);
if(stack[this.playerEntity.inventory.currentItem] != null) {
stack1.stackSize = stack[this.playerEntity.inventory.currentItem].stackSize + 1;
} else {
stack1.stackSize = 1;
}
stack[this.playerEntity.inventory.currentItem] = stack1;
this.playerEntity.field_421_a.sendPacket(new Packet5PlayerInventory(-1, stack));
if(!(var8 > 16 | var2) && this.mcServer.worldMngr.spawnProtection) {
this.playerEntity.field_421_a.sendPacket(new Packet3Chat("You cannot place/break blocks in this area!"));
if(stack != null && stack.stackSize == 0) {
this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem] = null;
}
this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem] = ItemStack.func_20117_a(this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem]);
this.playerEntity.field_421_a.sendPacket(new Packet5PlayerInventory(-1, this.playerEntity.inventory.mainInventory));
}
}

View File

@ -9,6 +9,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
@ -92,12 +93,22 @@ public class NetworkManager {
DataOutputStream yee = new DataOutputStream(sendBuffer);
Packet.writePacket(var2, yee);
yee.flush();
socketOutputStream.write(sendBuffer.toByteArray());
try {
socketOutputStream.write(sendBuffer.toByteArray());
} catch(SocketException e) {
if (e.getMessage().contains("connection abort") || e.getMessage().contains("connection reset")) {
this.networkShutdown("Connection reset");
return;
} else {
this.onNetworkError(e);
e.printStackTrace();
}
}
sendBuffer.flush();
socketOutputStream.flush();
} catch(Exception e) {
e.printStackTrace();
this.sendQueueByteLength = oldSendQueue;
System.err.println("Error occured while sending data packets! " + e.getStackTrace().toString());
}
}
@ -116,14 +127,24 @@ public class NetworkManager {
DataOutputStream yee = new DataOutputStream(sendBuffer);
Packet.writePacket(var2, yee);
yee.flush();
socketOutputStream.write(sendBuffer.toByteArray());
try {
socketOutputStream.write(sendBuffer.toByteArray());
} catch(SocketException e) {
if (e.getMessage().contains("connection abort") || e.getMessage().contains("connection reset")) {
this.networkShutdown("Connection reset");
return;
} else {
this.onNetworkError(e);
e.printStackTrace();
}
}
sendBuffer.flush();
socketOutputStream.flush();
this.chunkDataSendCounter = 50;
} catch(Exception e) {
e.printStackTrace();
this.sendQueueByteLength = oldSendQueue;
this.chunkDataSendCounter = oldChunkData;
System.err.println("Error occured while sending chunk data! " + e.getStackTrace().toString());
}
}

View File

@ -18,7 +18,7 @@ public class ServerConfigurationManager {
public List playerEntities = new ArrayList();
private MinecraftServer mcServer;
private PlayerManager playerManagerObj;
private int maxPlayers;
public int maxPlayers;
private Set field_9252_f = new HashSet();
private Set bannedIPs = new HashSet();
private Set ops = new HashSet();

View File

@ -54,6 +54,8 @@ public class World implements IBlockAccess {
private int field_4263_L = this.rand.nextInt(12000);
private List field_778_L = new ArrayList();
public boolean multiplayerWorld = false;
public int dimension = 0;
public boolean spawnProtection = true;
public WorldChunkManager func_4077_a() {
return this.field_4272_q.field_4301_b;
@ -92,6 +94,11 @@ public class World implements IBlockAccess {
this.spawnY = var9.getInteger("SpawnY");
this.spawnZ = var9.getInteger("SpawnZ");
this.worldTime = var9.getLong("Time");
if(var9.hasKey("spawnProtection")) {
this.spawnProtection = var9.getBoolean("spawnProtection");
} else {
spawnProtection = true;
}
this.sizeOnDisk = var9.getLong("SizeOnDisk");
if(var9.hasKey("Player")) {
this.nbtCompoundPlayer = var9.getCompoundTag("Player");
@ -170,6 +177,7 @@ public class World implements IBlockAccess {
var1.setLong("Time", this.worldTime);
var1.setLong("SizeOnDisk", this.sizeOnDisk);
var1.setLong("LastPlayed", System.currentTimeMillis());
var1.setBoolean("spawnProtection", this.spawnProtection);
EntityPlayer var2 = null;
if(this.playerEntities.size() > 0) {
var2 = (EntityPlayer)this.playerEntities.get(0);

View File

@ -11,6 +11,7 @@ public class WorldProvider {
public float[] lightBrightnessTable = new float[16];
public int field_6165_g = 0;
private float[] field_6164_h = new float[4];
public static int dimension = 0;
public final void func_4093_a(World var1) {
this.field_4302_a = var1;
@ -63,6 +64,7 @@ public class WorldProvider {
}
public static WorldProvider func_4091_a(int var0) {
dimension = var0;
return (WorldProvider)(var0 == 0 ? new WorldProvider() : (var0 == -1 ? new WorldProviderHell() : null));
}
}

View File

@ -62,7 +62,7 @@ public class WorldServer extends World {
var6 = var5;
}
return var6 > 16 || this.field_6160_D.configManager.isOp(var1.username);
return var6 > 16 || this.field_6160_D.configManager.isOp(var1.username) || !this.spawnProtection;
}
protected void func_479_b(Entity var1) {