Update furnace fuels to not recreate it's list every query, and update when tags are reloaded. Add Tag update events. (#6140)

This commit is contained in:
Brennan Ward 2019-09-16 17:04:32 -04:00 committed by LexManos
parent bb83e11a7c
commit 79ce18ac3e
8 changed files with 138 additions and 18 deletions

View file

@ -64,7 +64,7 @@
clientrecipebook.func_199644_c(); clientrecipebook.func_199644_c();
clientrecipebook.func_199642_d().forEach(imutablesearchtree::func_217872_a); clientrecipebook.func_199642_d().forEach(imutablesearchtree::func_217872_a);
imutablesearchtree.func_194040_a(); imutablesearchtree.func_194040_a();
+ net.minecraftforge.client.ForgeHooksClient.onRecipesUpdated(); + net.minecraftforge.client.ForgeHooksClient.onRecipesUpdated(this.field_199528_o);
} }
public void func_200232_a(SPlayerLookPacket p_200232_1_) { public void func_200232_a(SPlayerLookPacket p_200232_1_) {
@ -77,7 +77,15 @@
if (effect != null) { if (effect != null) {
EffectInstance effectinstance = new EffectInstance(effect, p_147260_1_.func_180755_e(), p_147260_1_.func_149428_f(), p_147260_1_.func_186984_g(), p_147260_1_.func_179707_f(), p_147260_1_.func_205527_h()); EffectInstance effectinstance = new EffectInstance(effect, p_147260_1_.func_180755_e(), p_147260_1_.func_149428_f(), p_147260_1_.func_186984_g(), p_147260_1_.func_179707_f(), p_147260_1_.func_205527_h());
effectinstance.func_100012_b(p_147260_1_.func_149429_c()); effectinstance.func_100012_b(p_147260_1_.func_149429_c());
@@ -1766,10 +1779,12 @@ @@ -1353,6 +1366,7 @@
}
this.field_147299_f.func_213253_a(SearchTreeManager.field_215360_b).func_194040_a();
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.TagsUpdatedEvent(this.field_199725_m));
}
public void func_175098_a(SCombatPacket p_175098_1_) {
@@ -1766,10 +1780,12 @@
this.field_147299_f.field_184132_p.field_217741_m.func_217692_a(pointofinterestdebugrenderer$braininfo); this.field_147299_f.field_184132_p.field_217741_m.func_217692_a(pointofinterestdebugrenderer$braininfo);
} else { } else {
@ -91,7 +99,7 @@
packetbuffer.release(); packetbuffer.release();
} }
@@ -1909,7 +1924,7 @@ @@ -1909,7 +1925,7 @@
for(SEntityPropertiesPacket.Snapshot sentitypropertiespacket$snapshot : p_147290_1_.func_149441_d()) { for(SEntityPropertiesPacket.Snapshot sentitypropertiespacket$snapshot : p_147290_1_.func_149441_d()) {
IAttributeInstance iattributeinstance = abstractattributemap.func_111152_a(sentitypropertiespacket$snapshot.func_151409_a()); IAttributeInstance iattributeinstance = abstractattributemap.func_111152_a(sentitypropertiespacket$snapshot.func_151409_a());
if (iattributeinstance == null) { if (iattributeinstance == null) {

View file

@ -0,0 +1,10 @@
--- a/net/minecraft/tags/NetworkTagManager.java
+++ b/net/minecraft/tags/NetworkTagManager.java
@@ -69,6 +69,7 @@
ItemTags.func_199902_a(this.field_199720_b);
FluidTags.func_206953_a(this.field_205705_c);
EntityTypeTags.func_219759_a(this.field_215299_d);
+ net.minecraftforge.fml.DeferredWorkQueue.runLater(() -> net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.TagsUpdatedEvent(this)));
}, p_215226_6_);
}

View file

@ -1,6 +1,14 @@
--- a/net/minecraft/tileentity/AbstractFurnaceTileEntity.java --- a/net/minecraft/tileentity/AbstractFurnaceTileEntity.java
+++ b/net/minecraft/tileentity/AbstractFurnaceTileEntity.java +++ b/net/minecraft/tileentity/AbstractFurnaceTileEntity.java
@@ -169,9 +169,9 @@ @@ -85,6 +85,7 @@
this.field_214014_c = p_i49964_2_;
}
+ @Deprecated //Forge - get burn times by calling ForgeHooks#getBurnTime(ItemStack)
public static Map<Item, Integer> func_214001_f() {
Map<Item, Integer> map = Maps.newLinkedHashMap();
func_213996_a(map, Items.field_151129_at, 20000);
@@ -169,9 +170,9 @@
super.func_145839_a(p_145839_1_); super.func_145839_a(p_145839_1_);
this.field_214012_a = NonNullList.func_191197_a(this.func_70302_i_(), ItemStack.field_190927_a); this.field_214012_a = NonNullList.func_191197_a(this.func_70302_i_(), ItemStack.field_190927_a);
ItemStackHelper.func_191283_b(p_145839_1_, this.field_214012_a); ItemStackHelper.func_191283_b(p_145839_1_, this.field_214012_a);
@ -13,7 +21,7 @@
this.field_214019_k = this.func_213997_a(this.field_214012_a.get(1)); this.field_214019_k = this.func_213997_a(this.field_214012_a.get(1));
int i = p_145839_1_.func_74765_d("RecipesUsedSize"); int i = p_145839_1_.func_74765_d("RecipesUsedSize");
@@ -185,9 +185,9 @@ @@ -185,9 +186,9 @@
public CompoundNBT func_189515_b(CompoundNBT p_189515_1_) { public CompoundNBT func_189515_b(CompoundNBT p_189515_1_) {
super.func_189515_b(p_189515_1_); super.func_189515_b(p_189515_1_);
@ -26,7 +34,7 @@
ItemStackHelper.func_191282_a(p_189515_1_, this.field_214012_a); ItemStackHelper.func_191282_a(p_189515_1_, this.field_214012_a);
p_189515_1_.func_74777_a("RecipesUsedSize", (short)this.field_214022_n.size()); p_189515_1_.func_74777_a("RecipesUsedSize", (short)this.field_214022_n.size());
int i = 0; int i = 0;
@@ -217,12 +217,14 @@ @@ -217,12 +218,14 @@
this.field_214019_k = this.field_214018_j; this.field_214019_k = this.field_214018_j;
if (this.func_214006_r()) { if (this.func_214006_r()) {
flag1 = true; flag1 = true;
@ -43,7 +51,7 @@
} }
} }
} }
@@ -266,10 +268,10 @@ @@ -266,10 +269,10 @@
return true; return true;
} else if (!itemstack1.func_77969_a(itemstack)) { } else if (!itemstack1.func_77969_a(itemstack)) {
return false; return false;
@ -56,7 +64,7 @@
} }
} }
} else { } else {
@@ -285,7 +287,7 @@ @@ -285,7 +288,7 @@
if (itemstack2.func_190926_b()) { if (itemstack2.func_190926_b()) {
this.field_214012_a.set(2, itemstack1.func_77946_l()); this.field_214012_a.set(2, itemstack1.func_77946_l());
} else if (itemstack2.func_77973_b() == itemstack1.func_77973_b()) { } else if (itemstack2.func_77973_b() == itemstack1.func_77973_b()) {
@ -65,27 +73,25 @@
} }
if (!this.field_145850_b.field_72995_K) { if (!this.field_145850_b.field_72995_K) {
@@ -305,7 +307,8 @@ @@ -305,7 +308,7 @@
return 0; return 0;
} else { } else {
Item item = p_213997_1_.func_77973_b(); Item item = p_213997_1_.func_77973_b();
- return func_214001_f().getOrDefault(item, 0); - return func_214001_f().getOrDefault(item, 0);
+ int ret = p_213997_1_.getBurnTime(); + return net.minecraftforge.common.ForgeHooks.getBurnTime(p_213997_1_);
+ return net.minecraftforge.event.ForgeEventFactory.getItemBurnTime(p_213997_1_, ret == -1 ? func_214001_f().getOrDefault(item, 0) : ret);
} }
} }
@@ -314,7 +317,8 @@ @@ -314,7 +317,7 @@
} }
public static boolean func_213991_b(ItemStack p_213991_0_) { public static boolean func_213991_b(ItemStack p_213991_0_) {
- return func_214001_f().containsKey(p_213991_0_.func_77973_b()); - return func_214001_f().containsKey(p_213991_0_.func_77973_b());
+ int ret = p_213991_0_.getBurnTime(); + return net.minecraftforge.common.ForgeHooks.getBurnTime(p_213991_0_) > 0;
+ return net.minecraftforge.event.ForgeEventFactory.getItemBurnTime(p_213991_0_, ret == -1 ? func_214001_f().getOrDefault(p_213991_0_.func_77973_b(), 0) : ret) > 0;
} }
public int[] func_180463_a(Direction p_180463_1_) { public int[] func_180463_a(Direction p_180463_1_) {
@@ -462,4 +466,27 @@ @@ -462,4 +465,27 @@
} }
} }

View file

@ -64,6 +64,7 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.IFluidState; import net.minecraft.fluid.IFluidState;
import net.minecraft.inventory.EquipmentSlotType; import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.RecipeManager;
import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
@ -997,9 +998,9 @@ public class ForgeHooksClient
return MinecraftForge.EVENT_BUS.post(event); return MinecraftForge.EVENT_BUS.post(event);
} }
public static void onRecipesUpdated() public static void onRecipesUpdated(RecipeManager mgr)
{ {
Event event = new RecipesUpdatedEvent(); Event event = new RecipesUpdatedEvent(mgr);
MinecraftForge.EVENT_BUS.post(event); MinecraftForge.EVENT_BUS.post(event);
} }

View file

@ -28,7 +28,19 @@ import net.minecraftforge.eventbus.api.Event;
*/ */
public class RecipesUpdatedEvent extends Event public class RecipesUpdatedEvent extends Event
{ {
public RecipesUpdatedEvent()
private final RecipeManager mgr;
public RecipesUpdatedEvent(RecipeManager mgr)
{ {
this.mgr = mgr;
}
/**
* @return The newly-updated recipe manager that now contains all the recipes that were just received.
*/
public RecipeManager getRecipeManager()
{
return mgr;
} }
} }

View file

@ -25,6 +25,7 @@ import java.net.URISyntaxException;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Deque; import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -85,6 +86,7 @@ import net.minecraft.potion.PotionUtils;
import net.minecraft.stats.Stats; import net.minecraft.stats.Stats;
import net.minecraft.tags.Tag; import net.minecraft.tags.Tag;
import net.minecraft.world.spawner.AbstractSpawner; import net.minecraft.world.spawner.AbstractSpawner;
import net.minecraft.tileentity.FurnaceTileEntity;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.DamageSource; import net.minecraft.util.DamageSource;
import net.minecraft.util.ActionResultType; import net.minecraft.util.ActionResultType;
@ -145,6 +147,8 @@ import net.minecraftforge.registries.DataSerializerEntry;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.ForgeRegistry; import net.minecraftforge.registries.ForgeRegistry;
import net.minecraftforge.registries.GameData; import net.minecraftforge.registries.GameData;
import net.minecraftforge.registries.IRegistryDelegate;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker; import org.apache.logging.log4j.Marker;
@ -1178,4 +1182,30 @@ public class ForgeHooks
BlockState state = world.getBlockState(pos); BlockState state = world.getBlockState(pos);
return ForgeEventFactory.getMobGriefingEvent(world, entity) && state.canEntityDestroy(world, pos, entity) && ForgeEventFactory.onEntityDestroyBlock(entity, pos, state); return ForgeEventFactory.getMobGriefingEvent(world, entity) && state.canEntityDestroy(world, pos, entity) && ForgeEventFactory.onEntityDestroyBlock(entity, pos, state);
} }
private static final Map<IRegistryDelegate<Item>, Integer> VANILLA_BURNS = new HashMap<>();
/**
* Gets the burn time of this itemstack.
*/
public static int getBurnTime(ItemStack stack)
{
if (stack.isEmpty())
{
return 0;
}
else
{
Item item = stack.getItem();
int ret = stack.getBurnTime();
return ForgeEventFactory.getItemBurnTime(stack, ret == -1 ? VANILLA_BURNS.getOrDefault(item.delegate, 0) : ret);
}
}
public static synchronized void updateBurns()
{
VANILLA_BURNS.clear();
FurnaceTileEntity.getBurnTimes().entrySet().forEach(e -> VANILLA_BURNS.put(e.getKey().delegate, e.getValue()));
}
} }

View file

@ -33,6 +33,7 @@ import net.minecraftforge.event.world.ChunkEvent;
import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.event.TagsUpdatedEvent;
import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.TickEvent.ClientTickEvent; import net.minecraftforge.event.TickEvent.ClientTickEvent;
import net.minecraftforge.event.TickEvent.Phase; import net.minecraftforge.event.TickEvent.Phase;
@ -101,5 +102,11 @@ public class ForgeInternalHandler
{ {
UsernameCache.setUsername(event.getPlayer().getUniqueID(), event.getPlayer().getGameProfile().getName()); UsernameCache.setUsername(event.getPlayer().getUniqueID(), event.getPlayer().getGameProfile().getName());
} }
@SubscribeEvent
public void tagsUpdated(TagsUpdatedEvent event)
{
ForgeHooks.updateBurns();
}
} }

View file

@ -0,0 +1,46 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2019.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event;
import net.minecraft.tags.NetworkTagManager;
import net.minecraftforge.eventbus.api.Event;
/**
* Fired on the client when {@link NetworkTagManager} has all of its tags synced from the server to the client (just after a client has connected).
* Fired on the server when {@link NetworkTagManager} has read all tags from disk (during a data reload).
*/
public class TagsUpdatedEvent extends Event
{
private final NetworkTagManager manager;
public TagsUpdatedEvent(NetworkTagManager manager)
{
this.manager = manager;
}
/**
* @return The network tag manager that has been updated with newly received tags.
*/
public NetworkTagManager getTagManager()
{
return manager;
}
}