diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionHandler.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionHandler.java index a21df0650..c1c5dfea3 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionHandler.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionHandler.java @@ -27,8 +27,8 @@ public class ContraptionHandler { static WorldAttached> queuedAdditions; static { - loadedContraptions = new WorldAttached<>(HashMap::new); - queuedAdditions = new WorldAttached<>(() -> ObjectLists.synchronize(new ObjectArrayList<>())); + loadedContraptions = new WorldAttached<>($ -> new HashMap<>()); + queuedAdditions = new WorldAttached<>($ -> ObjectLists.synchronize(new ObjectArrayList<>())); } public static void tick(World world) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/capability/CapabilityMinecartController.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/capability/CapabilityMinecartController.java index fa21259c0..c8e790a0b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/capability/CapabilityMinecartController.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/capability/CapabilityMinecartController.java @@ -80,10 +80,10 @@ public class CapabilityMinecartController implements ICapabilitySerializable(HashMap::new); - loadedMinecartsWithCoupling = new WorldAttached<>(HashSet::new); - queuedAdditions = new WorldAttached<>(() -> ObjectLists.synchronize(new ObjectArrayList<>())); - queuedUnloads = new WorldAttached<>(() -> ObjectLists.synchronize(new ObjectArrayList<>())); + loadedMinecartsByUUID = new WorldAttached<>($ -> new HashMap<>()); + loadedMinecartsWithCoupling = new WorldAttached<>($ -> new HashSet<>()); + queuedAdditions = new WorldAttached<>($ -> ObjectLists.synchronize(new ObjectArrayList<>())); + queuedUnloads = new WorldAttached<>($ -> ObjectLists.synchronize(new ObjectArrayList<>())); } public static void tick(World world) { @@ -99,16 +99,16 @@ public class CapabilityMinecartController implements ICapabilitySerializable capability = cart.getCapability(MINECART_CONTROLLER_CAPABILITY); diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/FluidTransportBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/FluidTransportBehaviour.java index 027db42d1..1370d3b5d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/FluidTransportBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/FluidTransportBehaviour.java @@ -131,7 +131,7 @@ public abstract class FluidTransportBehaviour extends TileEntityBehaviour { sendUpdate |= connection.manageFlows(world, pos, internalFluid, extractionPredicate); } - if (sendUpdate) + if (sendUpdate) tileEntity.notifyUpdate(); } @@ -272,7 +272,7 @@ public abstract class FluidTransportBehaviour extends TileEntityBehaviour { // for switching TEs, but retaining flows public static final WorldAttached>> interfaceTransfer = - new WorldAttached<>(HashMap::new); + new WorldAttached<>($ -> new HashMap<>()); public static void cacheFlows(IWorld world, BlockPos pos) { FluidTransportBehaviour pipe = TileEntityBehaviour.get(world, pos, FluidTransportBehaviour.TYPE); diff --git a/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoCannonProjectileTypes.java b/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoCannonProjectileTypes.java index 7fb0265de..9a25260b6 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoCannonProjectileTypes.java +++ b/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoCannonProjectileTypes.java @@ -3,12 +3,15 @@ package com.simibubi.create.content.curiosities.weapons; import java.util.HashMap; import java.util.Map; import java.util.Optional; +import java.util.UUID; import java.util.function.BiPredicate; import java.util.function.Predicate; +import com.mojang.authlib.GameProfile; import com.mojang.datafixers.util.Pair; import com.simibubi.create.AllItems; import com.simibubi.create.Create; +import com.simibubi.create.foundation.utility.WorldAttached; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -18,7 +21,6 @@ import net.minecraft.entity.LivingEntity; import net.minecraft.entity.item.FallingBlockEntity; import net.minecraft.entity.monster.ZombieVillagerEntity; import net.minecraft.entity.passive.FoxEntity; -import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Food; import net.minecraft.item.Foods; import net.minecraft.item.Item; @@ -43,11 +45,16 @@ import net.minecraft.world.IWorld; import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld; import net.minecraftforge.common.IPlantable; -import net.minecraftforge.common.util.FakePlayerFactory; +import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.registries.IRegistryDelegate; public class PotatoCannonProjectileTypes { + private static final GameProfile ZOMBIE_CONVERTER_NAME = + new GameProfile(UUID.fromString("be12d3dc-27d3-4992-8c97-66be53fd49c5"), "Converter"); + private static final WorldAttached ZOMBIE_CONVERTERS = + new WorldAttached<>(w -> new FakePlayer((ServerWorld) w, ZOMBIE_CONVERTER_NAME)); + public static final Map ALL = new HashMap<>(); public static final Map, PotatoCannonProjectileTypes> ITEM_MAP = new HashMap<>(); public static final PotatoCannonProjectileTypes @@ -155,8 +162,8 @@ public class PotatoCannonProjectileTypes { if (world.isRemote) return false; - PlayerEntity dummy = FakePlayerFactory.getMinecraft((ServerWorld) world); - dummy.setHeldItem(Hand.MAIN_HAND, new ItemStack(Items.GOLDEN_APPLE)); + FakePlayer dummy = ZOMBIE_CONVERTERS.get(world); + dummy.setHeldItem(Hand.MAIN_HAND, new ItemStack(Items.GOLDEN_APPLE, 1)); ((ZombieVillagerEntity) entity).interactMob(dummy, Hand.MAIN_HAND); return true; }) diff --git a/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerServerHandler.java b/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerServerHandler.java index 8e35e0cb6..3ec2b3209 100644 --- a/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerServerHandler.java +++ b/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerServerHandler.java @@ -24,7 +24,7 @@ import net.minecraft.world.IWorld; public class LinkedControllerServerHandler { public static WorldAttached>> receivedInputs = - new WorldAttached<>(HashMap::new); + new WorldAttached<>($ -> new HashMap<>()); static final int TIMEOUT = 30; public static void tick(IWorld world) { diff --git a/src/main/java/com/simibubi/create/content/schematics/filtering/SchematicInstances.java b/src/main/java/com/simibubi/create/content/schematics/filtering/SchematicInstances.java index 9ca103e6b..8bd1c542b 100644 --- a/src/main/java/com/simibubi/create/content/schematics/filtering/SchematicInstances.java +++ b/src/main/java/com/simibubi/create/content/schematics/filtering/SchematicInstances.java @@ -23,7 +23,7 @@ public class SchematicInstances { public static WorldAttached> loadedSchematics; static { - loadedSchematics = new WorldAttached<>(() -> CacheBuilder.newBuilder() + loadedSchematics = new WorldAttached<>($ -> CacheBuilder.newBuilder() .expireAfterAccess(5, TimeUnit.MINUTES) .build()); } diff --git a/src/main/java/com/simibubi/create/foundation/utility/WorldAttached.java b/src/main/java/com/simibubi/create/foundation/utility/WorldAttached.java index ee9022165..d8dc4e987 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/WorldAttached.java +++ b/src/main/java/com/simibubi/create/foundation/utility/WorldAttached.java @@ -4,7 +4,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.function.Supplier; +import java.util.function.Function; import javax.annotation.Nullable; @@ -14,9 +14,9 @@ public class WorldAttached { static List> allMaps = new ArrayList<>(); Map attached; - private Supplier factory; + private Function factory; - public WorldAttached(Supplier factory) { + public WorldAttached(Function factory) { this.factory = factory; attached = new HashMap<>(); allMaps.add(attached); @@ -31,7 +31,7 @@ public class WorldAttached { T t = attached.get(world); if (t != null) return t; - T entry = factory.get(); + T entry = factory.apply(world); put(world, entry); return entry; }