mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 19:39:22 +00:00
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:
1 parent
bb83e11a7c
commit
79ce18ac3e
8 files changed
+138
-18
No files matched your search
@@ -64,6 +64,7 @@ import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.fluid.IFluidState;
|
||||
import net.minecraft.inventory.EquipmentSlotType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.RecipeManager;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
@@ -997,9 +998,9 @@ public class ForgeHooksClient
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,19 @@ import net.minecraftforge.eventbus.api.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;
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import java.net.URISyntaxException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Deque;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -85,6 +86,7 @@ import net.minecraft.potion.PotionUtils;
|
||||
import net.minecraft.stats.Stats;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.world.spawner.AbstractSpawner;
|
||||
import net.minecraft.tileentity.FurnaceTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
@@ -145,6 +147,8 @@ import net.minecraftforge.registries.DataSerializerEntry;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.ForgeRegistry;
|
||||
import net.minecraftforge.registries.GameData;
|
||||
import net.minecraftforge.registries.IRegistryDelegate;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.Marker;
|
||||
@@ -1178,4 +1182,30 @@ public class ForgeHooks
|
||||
BlockState state = world.getBlockState(pos);
|
||||
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()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,6 +33,7 @@ import net.minecraftforge.event.world.ChunkEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import net.minecraftforge.eventbus.api.EventPriority;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.event.TagsUpdatedEvent;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.event.TickEvent.ClientTickEvent;
|
||||
import net.minecraftforge.event.TickEvent.Phase;
|
||||
@@ -101,5 +102,11 @@ public class ForgeInternalHandler
|
||||
{
|
||||
UsernameCache.setUsername(event.getPlayer().getUniqueID(), event.getPlayer().getGameProfile().getName());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void tagsUpdated(TagsUpdatedEvent event)
|
||||
{
|
||||
ForgeHooks.updateBurns();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user