use of crazypants.enderio.util.CapturedMob in project EnderIO by SleepyTrousers.
the class SoulBinderRecipeCategory method setRecipe.
@Override
public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull SoulBinderRecipeCategory.SoulBinderRecipeWrapper recipeWrapper, @Nonnull IIngredients ingredients) {
IGuiItemStackGroup guiItemStacks = recipeLayout.getItemStacks();
IGuiIngredientGroup<EnergyIngredient> group = recipeLayout.getIngredientsGroup(EnergyIngredient.class);
guiItemStacks.init(0, true, 37 - xOff, 33 - yOff);
guiItemStacks.init(1, true, 58 - xOff, 33 - yOff);
guiItemStacks.init(2, false, 111 - xOff, 33 - yOff);
guiItemStacks.init(3, false, 133 - xOff, 33 - yOff);
group.init(xOff, true, EnergyIngredientRenderer.INSTANCE, 5, 35, 60, 10, 0, 0);
guiItemStacks.set(ingredients);
IFocus<?> focus = recipeLayout.getFocus();
if (focus != null && focus.getMode() == Mode.INPUT && focus.getValue() instanceof ItemStack && ((ItemStack) focus.getValue()).getItem() == itemSoulVial.getItemNN() && CapturedMob.containsSoul(((ItemStack) focus.getValue())) && ingredients.getOutputs(ItemStack.class).get(1).size() > 1) {
// we are focused on a filled soul vial on the input side and the output has a list
final CapturedMob vialMob = CapturedMob.create(((ItemStack) focus.getValue()));
if (vialMob != null) {
List<ItemStack> newOutputs = new ArrayList<>();
for (ItemStack output : ingredients.getOutputs(ItemStack.class).get(1)) {
if (output != null && vialMob.isSameType(CapturedMob.create(output))) {
newOutputs.add(output);
}
}
guiItemStacks.set(3, newOutputs);
}
}
if (focus != null && focus.getMode() == Mode.OUTPUT && focus.getValue() instanceof ItemStack && CapturedMob.containsSoul(((ItemStack) focus.getValue())) && ingredients.getInputs(ItemStack.class).get(0).size() > 1 && ingredients.getOutputs(ItemStack.class).get(1).size() > 1) {
// we are focused on a output item and the both sides have a list
final CapturedMob resultMob = CapturedMob.create(((ItemStack) focus.getValue()));
if (resultMob != null) {
List<ItemStack> newInputs = new ArrayList<>();
for (ItemStack input : ingredients.getInputs(ItemStack.class).get(0)) {
if (input != null && resultMob.isSameType(CapturedMob.create(input))) {
newInputs.add(input);
}
}
guiItemStacks.set(0, newInputs);
guiItemStacks.set(3, ((ItemStack) focus.getValue()));
}
}
group.set(ingredients);
}
use of crazypants.enderio.util.CapturedMob in project EnderIO by SleepyTrousers.
the class AbstractSoulBinderRecipe method isValidInput.
@Override
public boolean isValidInput(@Nonnull MachineRecipeInput input) {
if (Prep.isInvalid(input.item)) {
return false;
}
int slot = input.slotNumber;
ItemStack item = input.item;
if (slot == 0) {
CapturedMob mobType = CapturedMob.create(item);
return mobType != null && item.getItem() == itemSoulVial.getItem() && isValidInputSoul(mobType);
}
if (slot == 1) {
return isValidInputItem(item);
}
return false;
}
use of crazypants.enderio.util.CapturedMob in project EnderIO by SleepyTrousers.
the class ItemSoulVial method itemInteractionForEntity.
@Override
public boolean itemInteractionForEntity(@Nonnull ItemStack item, @Nonnull EntityPlayer player, @Nonnull EntityLivingBase entity, @Nonnull EnumHand hand) {
if (entity.world.isRemote) {
return false;
}
boolean isCreative = player.capabilities.isCreativeMode;
if (CapturedMob.containsSoul(item) && !isCreative) {
return false;
}
// first check if that entity can be picked up at all
CapturedMob capturedMob = CapturedMob.create(entity);
if (capturedMob == null) {
if (entity instanceof EntityPlayer) {
player.sendMessage(Lang.SOUL_VIAL_DENIED_PLAYER.toChatServer());
} else if (CapturedMob.isBlacklisted(entity)) {
player.sendMessage(Lang.SOUL_VIAL_DENIED_AALISTED.toChatServer());
}
return false;
}
// then check for reasons this specific one cannot
if (entity instanceof IEntityOwnable && ((IEntityOwnable) entity).getOwnerId() != null && !player.equals(((IEntityOwnable) entity).getOwner()) && !PermissionAPI.hasPermission(player.getGameProfile(), permissionPickupOwned, new TargetContext(player, entity))) {
player.sendMessage(Lang.SOUL_VIAL_DENIED_OWNED_PET.toChatServer());
return false;
}
if (!PermissionAPI.hasPermission(player.getGameProfile(), permissionPickup, new TargetContext(player, entity))) {
player.sendMessage(Lang.SOUL_VIAL_DENIED.toChatServer());
return false;
}
ItemStack capturedMobVessel = capturedMob.toStack(this, 1, 1);
player.swingArm(hand);
if (!isCreative) {
entity.setDead();
if (entity.isDead) {
// So we do not shrink the stack when it is 1.
if (item.getCount() > 1) {
item.shrink(1);
// Since this stack still exists, add the new vial to the first location, or drop
if (!player.inventory.addItemStackToInventory(capturedMobVessel)) {
player.dropItem(capturedMobVessel, false);
}
} else {
// Otherwise, just replace the stack
player.setHeldItem(hand, capturedMobVessel);
}
player.inventoryContainer.detectAndSendChanges();
return true;
}
} else {
if (!player.inventory.addItemStackToInventory(capturedMobVessel)) {
player.dropItem(capturedMobVessel, false);
}
player.inventoryContainer.detectAndSendChanges();
return true;
}
return false;
}
use of crazypants.enderio.util.CapturedMob in project EnderIO by SleepyTrousers.
the class BrokenSpawnerHandler method onBreakEvent.
@SubscribeEvent
public static void onBreakEvent(BlockEvent.BreakEvent evt) {
if (evt.getState().getBlock() instanceof BlockMobSpawner) {
if (evt.getPlayer() != null && !evt.getPlayer().capabilities.isCreativeMode && !evt.getPlayer().world.isRemote && !evt.isCanceled()) {
TileEntity tile = evt.getPlayer().world.getTileEntity(NullHelper.notnullF(evt.getPos(), "BlockEvent.BreakEvent.getPos()"));
if (tile instanceof TileEntityMobSpawner) {
if (Math.random() > BrokenSpawnerConfig.brokenSpawnerDropChance.get()) {
return;
}
ItemStack equipped = evt.getPlayer().getHeldItemMainhand();
if (Prep.isValid(equipped) && BrokenSpawnerConfig.brokenSpawnerToolBlacklist.get().contains(equipped)) {
return;
}
TileEntityMobSpawner spawner = (TileEntityMobSpawner) tile;
MobSpawnerBaseLogic logic = spawner.getSpawnerBaseLogic();
ResourceLocation entityName = getEntityName(logic);
if (entityName != null && !isBlackListed(entityName)) {
final CapturedMob capturedMob = CapturedMob.create(entityName);
if (capturedMob != null) {
ItemStack drop = capturedMob.toStack(ModObject.itemBrokenSpawner.getItemNN(), 0, 1);
dropCache.put(evt.getPos().toImmutable(), drop);
for (int i = (int) (Math.random() * 7); i > 0; i--) {
setSpawnDelay(logic);
logic.updateSpawner();
}
} else {
dropCache.put(evt.getPos().toImmutable(), Prep.getEmpty());
}
}
}
} else {
dropCache.put(evt.getPos().toImmutable(), Prep.getEmpty());
}
}
}
use of crazypants.enderio.util.CapturedMob in project EnderIO by SleepyTrousers.
the class BrokenSpawnerHandler method onHarvestDropsEvent.
@SubscribeEvent
public static void onHarvestDropsEvent(BlockEvent.HarvestDropsEvent evt) {
if (!evt.isCanceled() && evt.getState().getBlock() instanceof BlockMobSpawner) {
if (dropCache.containsKey(evt.getPos())) {
ItemStack stack = dropCache.get(evt.getPos());
if (Prep.isValid(stack)) {
evt.getDrops().add(stack);
dropCache.put(evt.getPos().toImmutable(), Prep.getEmpty());
}
} else {
// invalidated already, but we might be able to recover it.
try {
for (Object object : evt.getWorld().loadedTileEntityList) {
if (object instanceof TileEntityMobSpawner) {
TileEntityMobSpawner spawner = (TileEntityMobSpawner) object;
BlockPos p = spawner.getPos();
if (spawner.getWorld() == evt.getWorld() && p.equals(evt.getPos())) {
// Bingo!
MobSpawnerBaseLogic logic = spawner.getSpawnerBaseLogic();
ResourceLocation entityName = getEntityName(logic);
if (entityName != null && !isBlackListed(entityName)) {
final CapturedMob capturedMob = CapturedMob.create(entityName);
if (capturedMob != null) {
evt.getDrops().add(capturedMob.toStack(ModObject.itemBrokenSpawner.getItemNN(), 0, 1));
}
}
}
}
}
} catch (Exception e) {
// Risky recovery failed. Happens.
}
}
}
}
Aggregations