use of net.silentchaos512.lib.collection.ItemStackList in project SilentGems by SilentChaos512.
the class MessageToggleChaosGem method handleMessage.
@Override
public IMessage handleMessage(MessageContext context) {
if (context.side != Side.SERVER)
return null;
EntityPlayer player = context.getServerHandler().player;
Predicate<ItemStack> predicate = s -> s.getItem() instanceof ItemChaosGem;
ItemStackList stacks = BaublesCompat.getBaubles(player, predicate);
stacks.addAll(PlayerHelper.getNonEmptyStacks(player, predicate));
for (ItemStack stack : stacks) {
if (stack.getItem() instanceof ItemChaosGem) {
ItemChaosGem item = (ItemChaosGem) stack.getItem();
item.setEnabled(stack, !item.isEnabled(stack));
if (item.isEnabled(stack))
item.applyEffects(stack, player);
else
item.removeEffects(stack, player);
if (!all)
return null;
}
}
return null;
}
use of net.silentchaos512.lib.collection.ItemStackList in project SilentGems by SilentChaos512.
the class RecipeMixedMaterialItem method getMaterials.
protected ItemStackList getMaterials(InventoryCrafting inv) {
ItemStackList list = ItemStackList.create();
for (int i = 0; i < inv.getSizeInventory(); ++i) {
ItemStack stack = inv.getStackInSlot(i);
ToolPart part = ToolPartRegistry.fromStack(stack);
if (part != null && !part.isBlacklisted(stack) && part instanceof ToolPartMain) {
list.add(stack);
}
}
return list;
}
use of net.silentchaos512.lib.collection.ItemStackList in project SilentGems by SilentChaos512.
the class RecipeMixedMaterialItem method getCraftingResult.
@Override
public ItemStack getCraftingResult(InventoryCrafting inv) {
if (!partTiersMatch(inv)) {
return StackHelper.empty();
}
ItemStack rod = getRod(inv);
ItemStack frame = getFrame(inv);
ItemStackList materials = getMaterials(inv);
ItemStack[] array = materials.toArray(new ItemStack[materials.size()]);
if (toolItem instanceof ITool)
return ((ITool) toolItem).constructTool(rod, array);
if (toolItem instanceof IArmor)
return ((IArmor) toolItem).constructArmor(frame, array);
return StackHelper.empty();
}
use of net.silentchaos512.lib.collection.ItemStackList in project SilentGems by SilentChaos512.
the class NodeEffect method applyToEntity.
public boolean applyToEntity(EntityLivingBase entity, Random random, boolean allowSounds) {
if (random.nextFloat() > successChance || !needsEffect(entity)) {
return false;
}
if (this == ATTACK) {
if (!entity.world.isRemote)
entity.attackEntityFrom(ModDamageSource.NODE_ATTACK, (float) (4.0f + 0.75f * random.nextGaussian()));
return true;
} else if (this == REPAIR) {
// Repair damaged items.
if (!(entity instanceof EntityPlayer))
return false;
EntityPlayer player = (EntityPlayer) entity;
int amount = (int) (10 + 2 * random.nextGaussian());
ItemStack stackToRepair = null;
// Select a random item.
ItemStackList items = PlayerHelper.getNonEmptyStacks(player);
items.removeIf(stack -> !canRepair(stack));
if (items.size() > 0) {
stackToRepair = items.get(random.nextInt(items.size()));
}
if (stackToRepair != null) {
ItemHelper.attemptDamageItem(stackToRepair, (int) -amount, random, player);
if (allowSounds)
entity.world.playSound(null, entity.getPosition(), SoundEvents.BLOCK_ANVIL_USE, SoundCategory.BLOCKS, 0.5f, 2.0f + (float) (0.2 * random.nextGaussian()));
return true;
}
return false;
} else if (this == SATURATION) {
// Saturation. Not using the potion effect, just restore some hunger directly.
if (!(entity instanceof EntityPlayer))
return false;
EntityPlayer player = (EntityPlayer) entity;
player.getFoodStats().addStats(2, 0.1f);
if (allowSounds)
entity.world.playSound(null, entity.getPosition(), SoundEvents.ENTITY_PLAYER_BURP, SoundCategory.BLOCKS, 0.5f, 1.2f + (float) (0.05 * random.nextGaussian()));
return true;
} else if (this instanceof NodeEffectPotion) {
// General potion effect handler.
NodeEffectPotion effect = (NodeEffectPotion) this;
int duration = effect.durationMin + random.nextInt(effect.durationMax - effect.durationMin + 1);
entity.addPotionEffect(new PotionEffect(effect.potion, duration, effect.amplifier));
return true;
}
SilentGems.logHelper.warning("Potentially unknown node effect: " + key);
return false;
}
use of net.silentchaos512.lib.collection.ItemStackList in project SilentGems by SilentChaos512.
the class MessageKeyReturnHome method handleMessage.
@Override
public IMessage handleMessage(MessageContext ctx) {
if (ctx.side != Side.SERVER)
return null;
Predicate<ItemStack> predicate = s -> s.getItem() == ModItems.returnHomeCharm;
EntityPlayer player = ctx.getServerHandler().player;
ItemStackList stacks = BaublesCompat.getBaubles(player, predicate);
stacks.addAll(PlayerHelper.getNonEmptyStacks(player, predicate));
if (stacks.isEmpty())
return null;
ModItems.returnHomeCharm.tryTeleportPlayer(stacks.get(0), player);
return null;
}
Aggregations