Use custom FakePlayer for converting Zombie Villagers

This commit is contained in:
reidbhuntley 2021-07-12 00:43:23 -04:00
parent b70608b030
commit cb41ac679d
7 changed files with 28 additions and 21 deletions

View file

@ -27,8 +27,8 @@ public class ContraptionHandler {
static WorldAttached<List<AbstractContraptionEntity>> 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) {

View file

@ -80,10 +80,10 @@ public class CapabilityMinecartController implements ICapabilitySerializable<Com
}
static {
loadedMinecartsByUUID = new WorldAttached<>(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<Com
for (AbstractMinecartEntity cart : queued) {
UUID uniqueID = cart.getUniqueID();
if (world.isRemote && carts.containsKey(uniqueID)) {
MinecartController minecartController = carts.get(uniqueID);
if (minecartController != null) {
AbstractMinecartEntity minecartEntity = minecartController.cart();
if (minecartEntity != null && minecartEntity.getEntityId() != cart.getEntityId())
if (minecartEntity != null && minecartEntity.getEntityId() != cart.getEntityId())
continue; // Away with you, Fake Entities!
}
}
cartsWithCoupling.remove(uniqueID);
LazyOptional<MinecartController> capability = cart.getCapability(MINECART_CONTROLLER_CAPABILITY);

View file

@ -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<Map<BlockPos, Map<Direction, PipeConnection>>> 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);

View file

@ -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<FakePlayer> ZOMBIE_CONVERTERS =
new WorldAttached<>(w -> new FakePlayer((ServerWorld) w, ZOMBIE_CONVERTER_NAME));
public static final Map<ResourceLocation, PotatoCannonProjectileTypes> ALL = new HashMap<>();
public static final Map<IRegistryDelegate<Item>, 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;
})

View file

@ -24,7 +24,7 @@ import net.minecraft.world.IWorld;
public class LinkedControllerServerHandler {
public static WorldAttached<Map<UUID, Collection<ManualFrequencyEntry>>> receivedInputs =
new WorldAttached<>(HashMap::new);
new WorldAttached<>($ -> new HashMap<>());
static final int TIMEOUT = 30;
public static void tick(IWorld world) {

View file

@ -23,7 +23,7 @@ public class SchematicInstances {
public static WorldAttached<Cache<Integer, SchematicWorld>> loadedSchematics;
static {
loadedSchematics = new WorldAttached<>(() -> CacheBuilder.newBuilder()
loadedSchematics = new WorldAttached<>($ -> CacheBuilder.newBuilder()
.expireAfterAccess(5, TimeUnit.MINUTES)
.build());
}

View file

@ -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<T> {
static List<Map<IWorld, ?>> allMaps = new ArrayList<>();
Map<IWorld, T> attached;
private Supplier<T> factory;
private Function<IWorld, T> factory;
public WorldAttached(Supplier<T> factory) {
public WorldAttached(Function<IWorld, T> factory) {
this.factory = factory;
attached = new HashMap<>();
allMaps.add(attached);
@ -31,7 +31,7 @@ public class WorldAttached<T> {
T t = attached.get(world);
if (t != null)
return t;
T entry = factory.get();
T entry = factory.apply(world);
put(world, entry);
return entry;
}