Let constructor & destructor interact with world using their owner's profile. + Fixed CraftingTask duplication bug (#2158)

* Let constructor & destructor interact with world using their owner's profile.

* Fixed CraftingTask duplication dupe (credits to @notcake)
This commit is contained in:
Radviger
2019-03-04 14:35:16 +02:00
committed by Raoul
parent 10e8496d38
commit e25b59161a
3 changed files with 39 additions and 6 deletions

View File

@@ -551,7 +551,7 @@ public class CraftingTask implements ICraftingTask {
ItemStack result = network.extractItem(toExtract, toExtract.getCount(), Action.PERFORM); ItemStack result = network.extractItem(toExtract, toExtract.getCount(), Action.PERFORM);
if (result != null) { if (result != null) {
internalStorage.insert(toExtract, toExtract.getCount(), Action.PERFORM); internalStorage.insert(toExtract, result.getCount(), Action.PERFORM);
toRemove.add(result); toRemove.add(result);
} }
@@ -573,7 +573,7 @@ public class CraftingTask implements ICraftingTask {
FluidStack result = network.extractFluid(toExtract, toExtract.amount, Action.PERFORM); FluidStack result = network.extractFluid(toExtract, toExtract.amount, Action.PERFORM);
if (result != null) { if (result != null) {
internalFluidStorage.insert(toExtract, toExtract.amount, Action.PERFORM); internalFluidStorage.insert(toExtract, result.amount, Action.PERFORM);
toRemove.add(result); toRemove.add(result);
} }

View File

@@ -28,6 +28,7 @@ import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTUtil; import net.minecraft.nbt.NBTUtil;
import net.minecraft.server.management.PlayerProfileCache;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntitySkull; import net.minecraft.tileentity.TileEntitySkull;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
@@ -39,6 +40,7 @@ import net.minecraft.world.WorldServer;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.BlockSnapshot; import net.minecraftforge.common.util.BlockSnapshot;
import net.minecraftforge.common.util.Constants; import net.minecraftforge.common.util.Constants;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.FakePlayerFactory; import net.minecraftforge.common.util.FakePlayerFactory;
import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.Fluid;
@@ -48,6 +50,7 @@ import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.wrapper.CombinedInvWrapper; import net.minecraftforge.items.wrapper.CombinedInvWrapper;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.UUID;
public class NetworkNodeConstructor extends NetworkNode implements IComparable, IType, ICoverable { public class NetworkNodeConstructor extends NetworkNode implements IComparable, IType, ICoverable {
public static final String ID = "constructor"; public static final String ID = "constructor";
@@ -145,8 +148,21 @@ public class NetworkNodeConstructor extends NetworkNode implements IComparable,
} }
} }
private FakePlayer getFakePlayer() {
WorldServer world = (WorldServer) this.world;
UUID owner = getOwner();
if (owner != null) {
PlayerProfileCache profileCache = world.getMinecraftServer().getPlayerProfileCache();
GameProfile profile = profileCache.getProfileByUUID(owner);
if (profile != null) {
return FakePlayerFactory.get(world, profile);
}
}
return FakePlayerFactory.getMinecraft(world);
}
private boolean canPlace(BlockPos pos, IBlockState state) { private boolean canPlace(BlockPos pos, IBlockState state) {
BlockEvent.PlaceEvent e = new BlockEvent.PlaceEvent(new BlockSnapshot(world, pos, state), world.getBlockState(pos), FakePlayerFactory.getMinecraft((WorldServer) world), EnumHand.MAIN_HAND); BlockEvent.PlaceEvent e = new BlockEvent.PlaceEvent(new BlockSnapshot(world, pos, state), world.getBlockState(pos), getFakePlayer(), EnumHand.MAIN_HAND);
return !MinecraftForge.EVENT_BUS.post(e); return !MinecraftForge.EVENT_BUS.post(e);
} }
@@ -174,7 +190,7 @@ public class NetworkNodeConstructor extends NetworkNode implements IComparable,
if (item.getItem() instanceof ItemBlock) { if (item.getItem() instanceof ItemBlock) {
((ItemBlock) item.getItem()).placeBlockAt( ((ItemBlock) item.getItem()).placeBlockAt(
took, took,
FakePlayerFactory.getMinecraft((WorldServer) world), getFakePlayer(),
world, world,
front, front,
getDirection(), getDirection(),

View File

@@ -1,5 +1,6 @@
package com.raoulvdberge.refinedstorage.apiimpl.network.node; package com.raoulvdberge.refinedstorage.apiimpl.network.node;
import com.mojang.authlib.GameProfile;
import com.raoulvdberge.refinedstorage.RS; import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.api.util.Action; import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.api.util.IComparer; import com.raoulvdberge.refinedstorage.api.util.IComparer;
@@ -24,6 +25,7 @@ import net.minecraft.entity.item.EntityItem;
import net.minecraft.inventory.InventoryHelper; import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.management.PlayerProfileCache;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityShulkerBox; import net.minecraft.tileentity.TileEntityShulkerBox;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
@@ -37,6 +39,7 @@ import net.minecraft.world.WorldServer;
import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.Constants; import net.minecraftforge.common.util.Constants;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.FakePlayerFactory; import net.minecraftforge.common.util.FakePlayerFactory;
import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.Fluid;
@@ -52,6 +55,7 @@ import net.minecraftforge.items.wrapper.CombinedInvWrapper;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID;
public class NetworkNodeDestructor extends NetworkNode implements IComparable, IFilterable, IType, ICoverable { public class NetworkNodeDestructor extends NetworkNode implements IComparable, IFilterable, IType, ICoverable {
public static final String ID = "destructor"; public static final String ID = "destructor";
@@ -86,6 +90,19 @@ public class NetworkNodeDestructor extends NetworkNode implements IComparable, I
return RS.INSTANCE.config.destructorUsage + upgrades.getEnergyUsage(); return RS.INSTANCE.config.destructorUsage + upgrades.getEnergyUsage();
} }
private FakePlayer getFakePlayer() {
WorldServer world = (WorldServer) this.world;
UUID owner = getOwner();
if (owner != null) {
PlayerProfileCache profileCache = world.getMinecraftServer().getPlayerProfileCache();
GameProfile profile = profileCache.getProfileByUUID(owner);
if (profile != null) {
return FakePlayerFactory.get(world, profile);
}
}
return FakePlayerFactory.getMinecraft(world);
}
@Override @Override
public void update() { public void update() {
super.update(); super.update();
@@ -121,7 +138,7 @@ public class NetworkNodeDestructor extends NetworkNode implements IComparable, I
new RayTraceResult(new Vec3d(pos.getX(), pos.getY(), pos.getZ()), getDirection().getOpposite()), new RayTraceResult(new Vec3d(pos.getX(), pos.getY(), pos.getZ()), getDirection().getOpposite()),
world, world,
front, front,
FakePlayerFactory.getMinecraft((WorldServer) world) getFakePlayer()
); );
if (!frontStack.isEmpty()) { if (!frontStack.isEmpty()) {
@@ -150,7 +167,7 @@ public class NetworkNodeDestructor extends NetworkNode implements IComparable, I
} }
} }
BlockEvent.BreakEvent e = new BlockEvent.BreakEvent(world, front, frontBlockState, FakePlayerFactory.getMinecraft((WorldServer) world)); BlockEvent.BreakEvent e = new BlockEvent.BreakEvent(world, front, frontBlockState, getFakePlayer());
if (!MinecraftForge.EVENT_BUS.post(e)) { if (!MinecraftForge.EVENT_BUS.post(e)) {
world.playEvent(null, 2001, front, Block.getStateId(frontBlockState)); world.playEvent(null, 2001, front, Block.getStateId(frontBlockState));