More work on compile errors, New system for ToolClasses, using a ToolType class instead to de-stringify things.

This commit is contained in:
LexManos committed 2018-09-21 01:47:12 -07:00
1 parent 0cd21ebe7e
commit cdfa7caaeb
33 files changed
+1668 -519

No files matched your search

@@ -9,66 +9,79 @@
protected static final Logger field_196273_d = LogManager.getLogger();
private static final ResourceLocation AIR_ID = new ResourceLocation("air");
public static final RegistryNamespacedDefaultedByKey<ResourceLocation, Block> REGISTRY = new RegistryNamespacedDefaultedByKey<ResourceLocation, Block>(AIR_ID);
@@ -1604,4 +1604,62 @@
@@ -502,8 +502,8 @@
if (f == -1.0F) {
return 0.0F;
} else {
- int i = player.canHarvestBlock(state) ? 30 : 100;
- return player.getDigSpeed(state) / f / (float)i;
+ int i = net.minecraftforge.common.ForgeHooks.canHarvestBlock(state, player, worldIn, pos) ? 30 : 100;
+ return player.getDigSpeed(state, pos) / f / (float)i;
}
}
@@ -625,6 +625,7 @@
}
+ @Deprecated //Use state sensitive version
protected boolean canSilkHarvest() {
return this.getDefaultState().isFullCube() && !this.hasTileEntity();
}
@@ -1604,4 +1605,56 @@
return Objects.hash(this.field_212164_a, this.field_212165_b, this.field_212166_c);
}
}
+ /* ======================================== FORGE START =====================================*/
+
+ private ThreadLocal<IBlockState> silkCheck = new ThreadLocal<>();
+ private String[] harvestTool = new String[16];
+ private int[] harvestLevel = new int[]{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
+ private net.minecraftforge.common.ToolType harvestTool;
+ private int harvestLevel;
+ protected static ThreadLocal<Boolean> captureDrops = ThreadLocal.withInitial(() -> false);
+ protected static ThreadLocal<NonNullList<ItemStack>> capturedDrops = ThreadLocal.withInitial(NonNullList::create);
+ protected NonNullList<ItemStack> captureDrops(boolean start)
+ {
+ if (start)
+ {
+ if (start) {
+ captureDrops.set(true);
+ capturedDrops.get().clear();
+ return NonNullList.create();
+ }
+ else
+ {
+ } else {
+ captureDrops.set(false);
+ return capturedDrops.get();
+ }
+ }
+
+ @Override
+ public float getSlipperiness(IBlockState state, IWorldReader world, BlockPos pos, @Nullable Entity entity)
+ {
+ public float getSlipperiness(IBlockState state, IWorldReader world, BlockPos pos, @Nullable Entity entity) {
+ return this.slipperiness;
+ }
+
+ @Override
+ public boolean canSilkHarvest(IWorldReader world, BlockPos pos, IBlockState state, EntityPlayer player)
+ {
+ silkCheck.set(state);
+ boolean ret = this.canSilkHarvest();
+ return ret;
+ public boolean canSilkHarvest(IBlockState state, IWorldReader world, BlockPos pos, EntityPlayer player) {
+ return this.canSilkHarvest() && !state.hasTileEntity();
+ }
+
+ @Override
+ public void onBlockExploded(World world, BlockPos pos, Explosion explosion)
+ {
+ public void onBlockExploded(IBlockState state, World world, BlockPos pos, Explosion explosion) {
+ world.setBlockToAir(pos);
+ onExplosionDestroy(world, pos, explosion);
+ }
+
+ @Nullable
+ @Override
+ public String getHarvestTool(IBlockState state)
+ {
+ return harvestTool[0]; //TODO: RE-Evaluate
+ public net.minecraftforge.common.ToolType getHarvestTool(IBlockState state) {
+ return harvestTool; //TODO: RE-Evaluate
+ }
+
+ @Override
+ public int getHarvestLevel(IBlockState state)
+ {
+
+ return harvestLevel[0]; //TODO: RE-Evaluate
+ public int getHarvestLevel(IBlockState state) {
+ return harvestLevel; //TODO: RE-Evaluate
+ }
+
+ static {
+ net.minecraftforge.common.ForgeHooks.setBlockToolSetter((block, tool, level) -> {
+ block.harvestTool = tool;
+ block.harvestLevel = level;
+ });
+ }
+ /* ========================================= FORGE END ======================================*/
}
@@ -0,0 +1,11 @@
--- a/net/minecraft/block/state/IBlockState.java
+++ b/net/minecraft/block/state/IBlockState.java
@@ -30,7 +30,7 @@
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
-public interface IBlockState extends IStateHolder<IBlockState> {
+public interface IBlockState extends IStateHolder<IBlockState>, net.minecraftforge.common.extensions.IForgeBlockState {
ThreadLocal<Object2ByteMap<IBlockState>> field_208776_a = ThreadLocal.<Object2ByteMap<IBlockState>>withInitial(() -> {
Object2ByteOpenHashMap<IBlockState> object2byteopenhashmap = new Object2ByteOpenHashMap<IBlockState>();
object2byteopenhashmap.defaultReturnValue((byte)127);
@@ -0,0 +1,21 @@
--- a/net/minecraft/client/gui/GuiBossOverlay.java
+++ b/net/minecraft/client/gui/GuiBossOverlay.java
@@ -28,12 +28,17 @@
for(BossInfoClient bossinfoclient : this.mapBossInfos.values()) {
int k = i / 2 - 91;
+ net.minecraftforge.client.event.RenderGameOverlayEvent.BossInfo event =
+ net.minecraftforge.client.ForgeHooksClient.bossBarRenderPre(this.client.field_195558_d, bossinfoclient, k, j, 10 + this.client.fontRenderer.FONT_HEIGHT);
+ if (!event.isCanceled()) {
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.client.getTextureManager().bindTexture(GUI_BARS_TEXTURES);
this.render(k, j, bossinfoclient);
String s = bossinfoclient.getName().getFormattedText();
this.client.fontRenderer.drawStringWithShadow(s, (float)(i / 2 - this.client.fontRenderer.getStringWidth(s) / 2), (float)(j - 9), 16777215);
- j += 10 + this.client.fontRenderer.FONT_HEIGHT;
+ }
+ j += event.getIncrement();
+ net.minecraftforge.client.ForgeHooksClient.bossBarRenderPost(this.client.field_195558_d);
if (j >= this.client.field_195558_d.func_198087_p() / 3) {
break;
}
@@ -9,3 +9,24 @@
private static final DataParameter<Float> ABSORPTION = EntityDataManager.<Float>createKey(EntityPlayer.class, DataSerializers.FLOAT);
private static final DataParameter<Integer> PLAYER_SCORE = EntityDataManager.<Integer>createKey(EntityPlayer.class, DataSerializers.VARINT);
protected static final DataParameter<Byte> PLAYER_MODEL_FLAG = EntityDataManager.<Byte>createKey(EntityPlayer.class, DataSerializers.BYTE);
@@ -663,7 +665,12 @@
return p_184816_1_.getItem();
}
+ @Deprecated //Use location sensitive version below
public float getDigSpeed(IBlockState state) {
+ return getDigSpeed(state, null);
+ }
+
+ public float getDigSpeed(IBlockState state, @Nullable BlockPos pos) {
float f = this.inventory.getDestroySpeed(state);
if (f > 1.0F) {
int i = EnchantmentHelper.getEfficiencyModifier(this);
@@ -705,6 +712,7 @@
f /= 5.0F;
}
+ f = net.minecraftforge.event.ForgeEventFactory.getBreakSpeed(this, state, f, pos);
return f;
}
@@ -73,7 +73,7 @@
ItemGroup itemgroup = this.getCreativeTab();
return itemgroup != null && (targetTab == ItemGroup.SEARCH || targetTab == itemgroup);
}
@@ -310,10 +318,49 @@
@@ -310,10 +318,48 @@
return false;
}
@@ -87,7 +87,7 @@
+ @Nullable
+ private final java.util.function.Supplier<net.minecraft.client.renderer.tileentity.TileEntityItemStackRenderer> teisr;
+
+ private final java.util.Map<String, Integer> toolClasses = new java.util.HashMap<String, Integer>();
+ private final java.util.Map<net.minecraftforge.common.ToolType, Integer> toolClasses = Maps.newHashMap();
+
+ protected final boolean canRepair;
+
@@ -98,16 +98,15 @@
+ }
+
+ @Override
+ public java.util.Set<String> getToolClasses(ItemStack stack)
+ public java.util.Set<net.minecraftforge.common.ToolType> getToolTypes(ItemStack stack)
+ {
+ return toolClasses.keySet();
+ }
+
+ @Override
+ public int getHarvestLevel(ItemStack stack, String toolClass, @Nullable EntityPlayer player, @Nullable IBlockState blockState)
+ public int getHarvestLevel(ItemStack stack, net.minecraftforge.common.ToolType tool, @Nullable EntityPlayer player, @Nullable IBlockState blockState)
+ {
+ Integer ret = toolClasses.get(toolClass);
+ return ret == null ? -1 : ret;
+ return toolClasses.getOrDefault(tool, -1);
+ }
+
+ @OnlyIn(Dist.CLIENT)
@@ -123,24 +122,34 @@
public static void registerItems() {
registerItemBlock(Blocks.AIR, new ItemAir(Blocks.AIR, new Item.Builder()));
func_200879_a(Blocks.STONE, ItemGroup.BUILDING_BLOCKS);
@@ -1147,6 +1194,9 @@
@@ -1147,6 +1193,9 @@
private Item field_200922_c;
private ItemGroup field_200923_d;
private EnumRarity field_208104_e = EnumRarity.COMMON;
+ private boolean canRepair = true;
+ private java.util.Map<String, Integer> toolClasses = new java.util.HashMap<String, Integer>();
+ private java.util.Map<net.minecraftforge.common.ToolType, Integer> toolClasses = Maps.newHashMap();
+ private java.util.function.Supplier<java.util.concurrent.Callable<net.minecraft.client.renderer.tileentity.TileEntityItemStackRenderer>> teisr;
public Item.Builder func_200917_a(int p_200917_1_) {
if (this.field_200921_b > 0) {
@@ -1181,5 +1231,10 @@
@@ -1181,5 +1230,20 @@
this.field_208104_e = p_208103_1_;
return this;
}
+
+ public Item.Builder setNoRepair() {
+ canRepair = false;
+ return this;
+ canRepair = false;
+ return this;
+ }
+
+ public Item.Builder addToolType(net.minecraftforge.common.ToolType type, int level) {
+ toolClasses.put(type, level);
+ return this;
+ }
+
+ public Item.Builder setTEISR(java.util.function.Supplier<java.util.concurrent.Callable<net.minecraft.client.renderer.tileentity.TileEntityItemStackRenderer>> teisr) {
+ this.teisr = teisr;
+ return this;
+ }
}
}
@@ -0,0 +1,25 @@
--- a/net/minecraft/item/ItemPickaxe.java
+++ b/net/minecraft/item/ItemPickaxe.java
@@ -17,18 +17,11 @@
public boolean canHarvestBlock(IBlockState blockIn) {
Block block = blockIn.getBlock();
int i = this.func_200891_e().func_200925_d();
- if (block == Blocks.OBSIDIAN) {
- return i == 3;
- } else if (block != Blocks.DIAMOND_BLOCK && block != Blocks.DIAMOND_ORE && block != Blocks.EMERALD_ORE && block != Blocks.EMERALD_BLOCK && block != Blocks.GOLD_BLOCK && block != Blocks.GOLD_ORE && block != Blocks.REDSTONE_ORE) {
- if (block != Blocks.IRON_BLOCK && block != Blocks.IRON_ORE && block != Blocks.LAPIS_BLOCK && block != Blocks.LAPIS_ORE) {
- Material material = blockIn.getMaterial();
- return material == Material.ROCK || material == Material.IRON || material == Material.ANVIL;
- } else {
- return i >= 1;
- }
- } else {
- return i >= 2;
+ if (blockIn.getHarvestTool() == net.minecraftforge.common.ToolType.PICKAXE) {
+ return i >= blockIn.getHarvestLevel();
}
+ Material material = blockIn.getMaterial();
+ return material == Material.ROCK || material == Material.IRON || material == Material.ANVIL;
}
public float getDestroySpeed(ItemStack stack, IBlockState state) {
@@ -5,7 +5,7 @@
import org.apache.logging.log4j.Logger;
-public final class ItemStack {
+public final class ItemStack extends net.minecraftforge.common.capabilities.CapabilityProvider implements net.minecraftforge.common.capabilities.ICapabilitySerializable<NBTTagCompound>, net.minecraftforge.common.extensions.IForgeItemStack {
+public final class ItemStack extends net.minecraftforge.common.capabilities.CapabilityProvider implements net.minecraftforge.common.extensions.IForgeItemStack {
private static final Logger field_199558_c = LogManager.getLogger();
public static final ItemStack EMPTY = new ItemStack((Item)null);
public static final DecimalFormat DECIMALFORMAT = func_208306_D();
@@ -68,7 +68,7 @@
}
public EnumActionResult func_196084_a(ItemUseContext p_196084_1_) {
+ if (!p_196084_1_.field_196006_g.isRemote) return net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(p_196084_1_);
+ //if (!p_196084_1_.field_196006_g.isRemote) return net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(p_196084_1_);
EntityPlayer entityplayer = p_196084_1_.func_195999_j();
BlockPos blockpos = p_196084_1_.func_195995_a();
BlockWorldState blockworldstate = new BlockWorldState(p_196084_1_.func_195991_k(), blockpos, false);
@@ -153,7 +153,7 @@
public boolean canHarvestBlock(IBlockState blockIn) {
- return this.getItem().canHarvestBlock(blockIn);
+ return this.getItem().canHarvestBlock(blockIn, this);
+ return this.getItem().canHarvestBlock(this, blockIn);
}
public boolean interactWithEntity(EntityPlayer playerIn, EntityLivingBase entityIn, EnumHand hand) {
@@ -9,6 +9,17 @@
public class BannerDuplicateRecipe extends IRecipeHidden {
public BannerDuplicateRecipe(ResourceLocation p_i48171_1_) {
@@ -77,8 +75,8 @@
for(int i = 0; i < nonnulllist.size(); ++i) {
ItemStack itemstack = inv.getStackInSlot(i);
if (!itemstack.isEmpty()) {
- if (itemstack.getItem().hasContainerItem()) {
- nonnulllist.set(i, new ItemStack(itemstack.getItem().getContainerItem()));
+ if (itemstack.hasContainerItem()) {
+ nonnulllist.set(i, itemstack.getContainerItem());
} else if (itemstack.hasTagCompound() && TileEntityBanner.getPatterns(itemstack) > 0) {
ItemStack itemstack1 = itemstack.copy();
itemstack1.setCount(1);
@@ -94,7 +92,6 @@
return RecipeSerializers.field_199586_l;
}
@@ -0,0 +1,70 @@
--- a/net/minecraft/network/ServerStatusResponse.java
+++ b/net/minecraft/network/ServerStatusResponse.java
@@ -26,6 +26,7 @@
public void setServerDescription(ITextComponent descriptionIn) {
this.description = descriptionIn;
+ invalidateJson();
}
public ServerStatusResponse.Players getPlayers() {
@@ -34,6 +35,7 @@
public void setPlayers(ServerStatusResponse.Players playersIn) {
this.players = playersIn;
+ invalidateJson();
}
public ServerStatusResponse.Version getVersion() {
@@ -42,16 +44,51 @@
public void setVersion(ServerStatusResponse.Version versionIn) {
this.version = versionIn;
+ invalidateJson();
}
public void setFavicon(String faviconBlob) {
this.favicon = faviconBlob;
+ invalidateJson();
}
public String getFavicon() {
return this.favicon;
}
+ private java.util.concurrent.Semaphore mutex = new java.util.concurrent.Semaphore(1);
+ private String json = null;
+ /**
+ * Returns this object as a Json string.
+ * Converting to JSON if a cached version is not available.
+ *
+ * Also to prevent potentially large memory allocations on the server
+ * this is moved from the SPacketServerInfo writePacket function
+ *
+ * As this method is called from the network threads so thread safety is important!
+ */
+ public String getJson() {
+ String ret = this.json;
+ if (ret == null) {
+ mutex.acquireUninterruptibly();
+ ret = this.json;
+ if (ret == null) {
+ ret = net.minecraft.network.status.server.SPacketServerInfo.GSON.toJson(this);
+ this.json = ret;
+ }
+ mutex.release();
+ }
+ return ret;
+ }
+
+ /**
+ * Invalidates the cached json, causing the next call to getJson to rebuild it.
+ * This is needed externally because PlayerCountData.setPlayer's is public.
+ */
+ public void invalidateJson() {
+ this.json = null;
+ }
+
public static class Players {
private final int maxPlayers;
private final int onlinePlayerCount;
@@ -0,0 +1,11 @@
--- a/net/minecraft/network/status/server/SPacketServerInfo.java
+++ b/net/minecraft/network/status/server/SPacketServerInfo.java
@@ -30,7 +30,7 @@
}
public void writePacketData(PacketBuffer buf) throws IOException {
- buf.writeString(GSON.toJson(this.response));
+ buf.writeString(this.response.getJson()); //Forge: Let the response cache the JSON
}
public void processPacket(INetHandlerStatusClient handler) {
@@ -1,34 +1,67 @@
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -130,7 +130,7 @@
private final DataFixer dataFixer;
private String hostname;
private int serverPort = -1;
- public WorldServer[] worlds;
+ public WorldServer[] worlds = new WorldServer[0];
private PlayerList playerList;
private boolean serverRunning = true;
private boolean serverStopped;
@@ -148,7 +148,8 @@
@@ -148,7 +148,6 @@
private int buildLimit;
private int maxPlayerIdleMinutes;
public final long[] tickTimeArray = new long[100];
- public long[][] timeOfLastDimensionTick;
+ //public long[][] timeOfLastDimensionTick;
+ public java.util.Hashtable<Integer, long[]> worldTickTimes = new java.util.Hashtable<Integer, long[]>();
private KeyPair serverKeyPair;
private String serverOwner;
private String folderName;
@@ -287,8 +288,6 @@
@@ -287,8 +286,7 @@
public void loadAllWorlds(String saveName, String worldNameIn, long seed, WorldType type, JsonElement generatorOptions) {
this.convertMapIfNeeded(saveName);
this.func_200245_b(new TextComponentTranslation("menu.loadingLevel", new Object[0]));
- this.worlds = new WorldServer[3];
- this.timeOfLastDimensionTick = new long[this.worlds.length][100];
+ this.worlds = new WorldServer[1]; //Forge only initialize overworld, we will do the rest.
ISaveHandler isavehandler = this.anvilConverterForAnvilFile.func_197715_a(saveName, this);
this.setResourcePackFromWorld(this.getFolderName(), isavehandler);
WorldInfo worldinfo = isavehandler.loadWorldInfo();
@@ -523,6 +522,7 @@
@@ -340,6 +338,18 @@
}
}
+ for (int dim : net.minecraftforge.common.DimensionManager.getStaticDimensionIDs()) {
+ WorldServer world = this.worlds[0];
+ if (dim != 0) {
+ world = (WorldServer)(new WorldServerMulti(this, isavehandler, dim, this.worlds[0], this.profiler).init());
+ world.addEventListener(new ServerWorldEventHandler(this, world));
+ if (!this.isSinglePlayer()) {
+ world.getWorldInfo().setGameType(getGameType());
+ }
+ }
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.WorldEvent.Load(world));
+ }
+
this.playerList.setPlayerManager(this.worlds);
if (worldinfo.func_201357_P() != null) {
this.func_201300_aS().func_201381_a(worldinfo.func_201357_P());
@@ -378,7 +388,7 @@
this.func_200245_b(new TextComponentTranslation("menu.generatingTerrain", new Object[0]));
int j1 = 0;
LOGGER.info("Preparing start region for level 0");
- WorldServer worldserver = this.worlds[0];
+ WorldServer worldserver = getWorld(0);
BlockPos blockpos = worldserver.getSpawnPoint();
List<ChunkPos> list = Lists.<ChunkPos>newArrayList();
Set<ChunkPos> set = Sets.<ChunkPos>newConcurrentHashSet();
@@ -493,9 +503,14 @@
for(WorldServer worldserver1 : this.worlds) {
if (worldserver1 != null) {
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.WorldEvent.Unload(worldserver1));
worldserver1.close();
}
}
+
+ WorldServer[] tmp = this.worlds;
+ for (WorldServer world : tmp)
+ net.minecraftforge.common.DimensionManager.setWorld(world.provider.getId(), null, this);
}
if (this.usageSnooper.isSnooperRunning()) {
@@ -523,6 +538,7 @@
public void run() {
try {
if (this.init()) {
@@ -36,7 +69,7 @@
this.field_211151_aa = Util.func_211177_b();
this.statusResponse.setServerDescription(new TextComponentString(this.motd));
this.statusResponse.setVersion(new ServerStatusResponse.Version("1.13", 393));
@@ -546,7 +546,10 @@
@@ -546,7 +562,10 @@
this.serverIsRunning = true;
}
@@ -47,7 +80,7 @@
this.finalTick((CrashReport)null);
}
} catch (Throwable throwable1) {
@@ -565,6 +568,7 @@
@@ -565,6 +584,7 @@
LOGGER.error("We were unable to save this crash report to disk.");
}
@@ -55,7 +88,7 @@
this.finalTick(crashreport);
} finally {
try {
@@ -573,6 +577,7 @@
@@ -573,6 +593,7 @@
} catch (Throwable throwable) {
LOGGER.error("Exception stopping the server", throwable);
} finally {
@@ -63,7 +96,15 @@
this.systemExitNow();
}
@@ -686,10 +691,12 @@
@@ -648,6 +669,7 @@
Collections.shuffle(Arrays.asList(agameprofile));
this.statusResponse.getPlayers().setPlayers(agameprofile);
+ this.statusResponse.invalidateJson();
}
if (this.tickCounter % 900 == 0) {
@@ -686,16 +708,18 @@
this.getFunctionManager().update();
this.profiler.endStartSection("levels");
@@ -74,17 +115,74 @@
long j = Util.func_211178_c();
- if (i == 0 || this.getAllowNether()) {
- WorldServer worldserver = this.worlds[i];
+ WorldServer worldserver = getWorld(id);
+ if (id == 0 || this.getAllowNether()) {
+ WorldServer worldserver = net.minecraftforge.common.DimensionManager.getWorld(id);
this.profiler.func_194340_a(() -> {
return worldserver.getWorldInfo().getWorldName();
});
@@ -724,7 +731,7 @@
if (this.tickCounter % 20 == 0) {
this.profiler.startSection("timeSync");
- this.playerList.sendPacketToAllPlayersInDimension(new SPacketTimeUpdate(worldserver.getTotalWorldTime(), worldserver.getWorldTime(), worldserver.getGameRules().getBoolean("doDaylightCycle")), worldserver.provider.getDimensionType().getId());
+ this.playerList.sendPacketToAllPlayersInDimension(new SPacketTimeUpdate(worldserver.getTotalWorldTime(), worldserver.getWorldTime(), worldserver.getGameRules().getBoolean("doDaylightCycle")), worldserver.provider.getId());
this.profiler.endSection();
}
@@ -724,9 +748,11 @@
this.profiler.endSection();
}
- this.timeOfLastDimensionTick[i][this.tickCounter % 100] = Util.func_211178_c() - j;
+ worldTickTimes.get(id)[this.tickCounter % 100] = Util.func_211178_c() - j;
+ worldserver.setTickTime(this.tickCounter, Util.func_211178_c() - j);
}
+ this.profiler.endStartSection("dim_unloading");
+ net.minecraftforge.common.DimensionManager.unloadWorlds();
this.profiler.endStartSection("connection");
this.getNetworkSystem().networkTick();
this.profiler.endStartSection("players");
@@ -749,6 +775,14 @@
}
public static void main(String[] p_main_0_) {
+ //Forge: Copied from DedicatedServer.init as to run as early as possible, Old code left in place intentionally.
+ //Done in good faith with permission: https://github.com/MinecraftForge/MinecraftForge/issues/3659#issuecomment-390467028
+ ServerEula eula = new ServerEula(new File("eula.txt"));
+ if (!eula.hasAcceptedEULA()) {
+ LOGGER.info("You need to agree to the EULA in order to run the server. Go to eula.txt for more info.");
+ eula.createEULAFile();
+ return;
+ }
Bootstrap.register();
try {
@@ -851,7 +885,7 @@
}
public void startServerThread() {
- this.serverThread = new Thread(this, "Server thread");
+ this.serverThread = new Thread(net.minecraftforge.fml.common.thread.SidedThreadGroups.SERVER, this, "Server thread");
this.serverThread.setUncaughtExceptionHandler((p_195574_0_, p_195574_1_) -> {
LOGGER.error(p_195574_1_);
});
@@ -871,11 +905,7 @@
}
public WorldServer getWorld(int dimension) {
- if (dimension == -1) {
- return this.worlds[1];
- } else {
- return dimension == 1 ? this.worlds[2] : this.worlds[0];
- }
+ return net.minecraftforge.common.DimensionManager.getWorld(dimension, true, true);
}
public WorldServer func_200667_a(DimensionType p_200667_1_) {
@@ -918,7 +948,7 @@
}
public String getServerModName() {
- return "vanilla";
+ return net.minecraftforge.common.ForgeHooks.getServerModName();
}
public CrashReport addServerInfoToCrashReport(CrashReport report) {
@@ -1,6 +1,35 @@
--- a/net/minecraft/server/integrated/IntegratedServer.java
+++ b/net/minecraft/server/integrated/IntegratedServer.java
@@ -121,9 +121,10 @@
@@ -62,8 +62,7 @@
public void loadAllWorlds(String saveName, String worldNameIn, long seed, WorldType type, JsonElement generatorOptions) {
this.convertMapIfNeeded(saveName);
- this.worlds = new WorldServer[3];
- this.timeOfLastDimensionTick = new long[this.worlds.length][100];
+ this.worlds = new WorldServer[1]; //Forge only initialize overworld, we will do the rest.
ISaveHandler isavehandler = this.getActiveAnvilConverter().func_197715_a(saveName, this);
this.setResourcePackFromWorld(this.getFolderName(), isavehandler);
WorldInfo worldinfo = isavehandler.loadWorldInfo();
@@ -100,6 +99,18 @@
this.worlds[i].addEventListener(new ServerWorldEventHandler(this, this.worlds[i]));
}
+ for (int dim : net.minecraftforge.common.DimensionManager.getStaticDimensionIDs()) {
+ WorldServer world = this.worlds[0];
+ if (dim != 0) {
+ world = (WorldServer)(new WorldServerMulti(this, isavehandler, dim, this.worlds[0], this.profiler).init());
+ world.addEventListener(new ServerWorldEventHandler(this, world));
+ if (!this.isSinglePlayer()) {
+ world.getWorldInfo().setGameType(getGameType());
+ }
+ }
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.WorldEvent.Load(world));
+ }
+
this.getPlayerList().setPlayerManager(this.worlds);
if (worldinfo.func_201357_P() != null) {
this.func_201300_aS().func_201381_a(worldinfo.func_201357_P());
@@ -121,9 +132,10 @@
this.setAllowFlight(true);
LOGGER.info("Generating keypair");
this.setKeyPair(CryptManager.generateKeyPair());
@@ -12,3 +41,19 @@
}
public void tick() {
@@ -176,6 +188,7 @@
}
public EnumDifficulty getDifficulty() {
+ if (this.mc.world == null) return this.mc.gameSettings.difficulty; // Fix NPE just in case.
return this.mc.world.getWorldInfo().getDifficulty();
}
@@ -275,6 +288,7 @@
}
public void initiateShutdown() {
+ if (isServerRunning())
Futures.getUnchecked(this.addScheduledTask(() -> {
for(EntityPlayerMP entityplayermp : Lists.newArrayList(this.getPlayerList().getPlayers())) {
if (!entityplayermp.getUniqueID().equals(this.field_211528_n)) {
@@ -0,0 +1,105 @@
--- a/net/minecraft/tileentity/TileEntityFurnace.java
+++ b/net/minecraft/tileentity/TileEntityFurnace.java
@@ -185,9 +185,9 @@
super.readFromNBT(compound);
this.furnaceItemStacks = NonNullList.<ItemStack>withSize(this.getSizeInventory(), ItemStack.EMPTY);
ItemStackHelper.loadAllItems(compound, this.furnaceItemStacks);
- this.furnaceBurnTime = compound.getShort("BurnTime");
- this.cookTime = compound.getShort("CookTime");
- this.totalCookTime = compound.getShort("CookTimeTotal");
+ this.furnaceBurnTime = compound.getInteger("BurnTime");
+ this.cookTime = compound.getInteger("CookTime");
+ this.totalCookTime = compound.getInteger("CookTimeTotal");
this.currentItemBurnTime = getItemBurnTime(this.furnaceItemStacks.get(1));
int i = compound.getShort("RecipesUsedSize");
@@ -205,9 +205,9 @@
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
super.writeToNBT(compound);
- compound.setShort("BurnTime", (short)this.furnaceBurnTime);
- compound.setShort("CookTime", (short)this.cookTime);
- compound.setShort("CookTimeTotal", (short)this.totalCookTime);
+ compound.setInteger("BurnTime", this.furnaceBurnTime);
+ compound.setInteger("CookTime", this.cookTime);
+ compound.setInteger("CookTimeTotal", this.totalCookTime);
ItemStackHelper.saveAllItems(compound, this.furnaceItemStacks);
compound.setShort("RecipesUsedSize", (short)this.field_203901_m.size());
int i = 0;
@@ -254,6 +254,10 @@
this.currentItemBurnTime = this.furnaceBurnTime;
if (this.isBurning()) {
flag1 = true;
+ if (itemstack.hasContainerItem()) {
+ this.furnaceItemStacks.set(1, itemstack.getContainerItem());
+ }
+ else
if (!itemstack.isEmpty()) {
Item item = itemstack.getItem();
itemstack.shrink(1);
@@ -308,10 +312,10 @@
return true;
} else if (!itemstack1.isItemEqual(itemstack)) {
return false;
- } else if (itemstack1.getCount() < this.getInventoryStackLimit() && itemstack1.getCount() < itemstack1.getMaxStackSize()) {
+ } else if (itemstack1.getCount() + itemstack.getCount() <= this.getInventoryStackLimit() && itemstack1.getCount() < itemstack1.getMaxStackSize()) { // Forge fix: make furnace respect stack sizes in furnace recipes
return true;
} else {
- return itemstack1.getCount() < itemstack.getMaxStackSize();
+ return itemstack1.getCount() + itemstack.getCount() <= itemstack.getMaxStackSize(); // Forge fix: make furnace respect stack sizes in furnace recipes
}
}
} else {
@@ -327,7 +331,7 @@
if (itemstack2.isEmpty()) {
this.furnaceItemStacks.set(2, itemstack1.copy());
} else if (itemstack2.getItem() == itemstack1.getItem()) {
- itemstack2.grow(1);
+ itemstack2.grow(itemstack1.getCount());
}
if (!this.world.isRemote) {
@@ -347,12 +351,13 @@
return 0;
} else {
Item item = stack.getItem();
- return func_201564_p().getOrDefault(item, 0);
+ int ret = stack.getBurnTime();
+ return net.minecraftforge.event.ForgeEventFactory.getItemBurnTime(stack, ret == -1 ? func_201564_p().getOrDefault(item, 0) : ret);
}
}
public static boolean isItemFuel(ItemStack stack) {
- return func_201564_p().containsKey(stack.getItem());
+ return getItemBurnTime(stack) > 0;
}
public boolean isUsableByPlayer(EntityPlayer player) {
@@ -501,4 +506,27 @@
this.field_203901_m.clear();
}
+
+ net.minecraftforge.common.capabilities.OptionalCapabilityInstance<? extends net.minecraftforge.items.IItemHandler>[] handlers =
+ net.minecraftforge.items.wrapper.SidedInvWrapper.create(this, EnumFacing.UP, EnumFacing.DOWN, EnumFacing.NORTH);
+
+ @Override
+ public <T> net.minecraftforge.common.capabilities.OptionalCapabilityInstance<T> getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, @Nullable EnumFacing facing) {
+ if (facing != null && capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
+ if (facing == EnumFacing.UP)
+ return handlers[0].cast();
+ else if (facing == EnumFacing.UP)
+ return handlers[1].cast();
+ else
+ return handlers[2].cast();
+ }
+ return super.getCapability(capability, facing);
+ }
+
+ @Override
+ public void invalidate() {
+ super.invalidate();
+ for (int x = 0; x < handlers.length; x++)
+ handlers[x].invalidate();
+ }
}
@@ -17,3 +17,16 @@
return this;
}
@@ -957,4 +958,12 @@
public NetworkTagManager func_205772_D() {
return this.server.func_199731_aO();
}
+
+ private long[] tickTime = new long[100];
+ public void setTickTime(int tick, long time) {
+ this.tickTime[tick % 100] = time;
+ }
+ public long[] getTickTimes() {
+ return this.tickTime;
+ }
}