#2541 Crafter should post craft event, clean up fake player classes

This commit is contained in:
tterrag1098 committed 2015-06-04 20:03:01 -04:00
1 parent b42ade4226
commit 6d85216bdc
3 files changed
+60 -22

No files matched your search

@@ -0,0 +1,40 @@
package crazypants.enderio.machine;
import com.mojang.authlib.GameProfile;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.IChatComponent;
import net.minecraft.world.World;
import net.minecraftforge.common.util.FakePlayer;
import crazypants.util.BlockCoord;
public class FakePlayerEIO extends FakePlayer {
ItemStack prevWeapon;
public FakePlayerEIO(World world, BlockCoord pos, GameProfile profile) {
super(MinecraftServer.getServer().worldServerForDimension(world.provider.dimensionId), profile);
posX = pos.x + 0.5;
posY = pos.y + 0.5;
posZ = pos.z + 0.5;
}
// These do things with packets...which crash since the net handler is null. Potion effects are not needed anyways.
@Override
protected void onNewPotionEffect(PotionEffect p_70670_1_) {
}
@Override
protected void onChangedPotionEffect(PotionEffect p_70695_1_, boolean p_70695_2_) {
}
@Override
protected void onFinishedPotionEffect(PotionEffect p_70688_1_) {
}
@Override
public void addChatMessage(IChatComponent p_145747_1_) {
}
}
@@ -3,6 +3,7 @@ package crazypants.enderio.machine.crafter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
@@ -10,9 +11,16 @@ import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.FakePlayer;
import com.mojang.authlib.GameProfile;
import cpw.mods.fml.common.gameevent.PlayerEvent.ItemCraftedEvent;
import crazypants.enderio.ModObject;
import crazypants.enderio.config.Config;
import crazypants.enderio.machine.AbstractPowerConsumerEntity;
import crazypants.enderio.machine.FakePlayerEIO;
import crazypants.enderio.machine.IItemBuffer;
import crazypants.enderio.machine.SlotDefinition;
import crazypants.enderio.power.BasicCapacitor;
@@ -29,6 +37,8 @@ public class TileCrafter extends AbstractPowerConsumerEntity implements IItemBuf
private boolean bufferStacks = true;
private long ticksSinceLastCraft = 0;
private FakePlayer playerInst;
public TileCrafter() {
super(new SlotDefinition(9, 1));
@@ -123,6 +133,9 @@ public class TileCrafter extends AbstractPowerConsumerEntity implements IItemBuf
}
}
private static final UUID uuid = UUID.fromString("9b381cae-3c95-4a64-b958-1e25b0a4c790");
private static final GameProfile DUMMY_PROFILE = new GameProfile(uuid, "[EioCrafter]");
private void craftRecipe() {
// (1) Find the items to craft with and put a copy into a temp crafting grid;
@@ -157,6 +170,10 @@ public class TileCrafter extends AbstractPowerConsumerEntity implements IItemBuf
// (3) If we got a result, ...
if (output != null) {
if (playerInst == null) {
playerInst = new FakePlayerEIO(worldObj, getLocation(), DUMMY_PROFILE);
}
MinecraftForge.EVENT_BUS.post(new ItemCraftedEvent(playerInst, output, inv));
// (3a) ... remove the used up items and ...
for (int i = 0; i < 9; i++) {
@@ -32,6 +32,7 @@ import crazypants.enderio.EnderIO;
import crazypants.enderio.ModObject;
import crazypants.enderio.config.Config;
import crazypants.enderio.machine.AbstractMachineEntity;
import crazypants.enderio.machine.FakePlayerEIO;
import crazypants.enderio.machine.SlotDefinition;
import crazypants.enderio.machine.generator.zombie.IHasNutrientTank;
import crazypants.enderio.machine.generator.zombie.PacketNutrientTank;
@@ -496,15 +497,12 @@ public class TileKillerJoe extends AbstractMachineEntity implements IFluidHandle
private static final UUID uuid = UUID.fromString("3baa66fa-a69a-11e4-89d3-123b93f75cba");
private static final GameProfile DUMMY_PROFILE = new GameProfile(uuid, "[EioKillera]");
private class Attackera extends FakePlayer {
private class Attackera extends FakePlayerEIO {
ItemStack prevWeapon;
public Attackera() {
super(MinecraftServer.getServer().worldServerForDimension(getWorldObj().provider.dimensionId), DUMMY_PROFILE);
posX = xCoord + 0.5;
posY = yCoord + 0.5;
posZ = zCoord + 0.5;
super(MinecraftServer.getServer().worldServerForDimension(getWorldObj().provider.dimensionId), getLocation(), DUMMY_PROFILE);
}
@Override
@@ -527,23 +525,6 @@ public class TileKillerJoe extends AbstractMachineEntity implements IFluidHandle
getChargedLocation().chargeItems(inventory.mainInventory);
}
// These do things with packets...which crash since the net handler is null. Potion effects are not needed anyways.
@Override
protected void onNewPotionEffect(PotionEffect p_70670_1_) {
}
@Override
protected void onChangedPotionEffect(PotionEffect p_70695_1_, boolean p_70695_2_) {
}
@Override
protected void onFinishedPotionEffect(PotionEffect p_70688_1_) {
}
@Override
public void addChatMessage(IChatComponent p_145747_1_) {
}
}
@Override