use of net.minecraft.enchantment.Enchantment in project SilentGems by SilentChaos512.
the class ItemEnchantmentToken method getOutlineColor.
public int getOutlineColor(ItemStack stack) {
Enchantment ench = getSingleEnchantment(stack);
if (ench != null && colorMap.containsKey(ench)) {
int k = colorMap.get(ench);
int r = (k >> 16) & 255;
int g = (k >> 8) & 255;
int b = k & 255;
int j = (int) (160 * MathHelper.sin(ClientTickHandler.ticksInGame * OUTLINE_PULSATE_SPEED));
j = MathHelper.clamp(j, 0, 255);
r = MathHelper.clamp(r + j, 0, 255);
g = MathHelper.clamp(g + j, 0, 255);
b = MathHelper.clamp(b + j, 0, 255);
return (r << 16) | (g << 8) | b;
}
return 0xFFFFFF;
}
use of net.minecraft.enchantment.Enchantment in project SilentGems by SilentChaos512.
the class ItemEnchantmentToken method applyTokenToTool.
// ========
// Crafting
// ========
public boolean applyTokenToTool(ItemStack token, ItemStack tool) {
if (StackHelper.isEmpty(token) || StackHelper.isEmpty(tool)) {
return false;
}
// Get enchantments on token.
Map<Enchantment, Integer> enchantmentsOnToken = getEnchantments(token);
if (enchantmentsOnToken.isEmpty())
return false;
// Get enchantments on tool.
Map<Enchantment, Integer> enchantmentsOnTool = EnchantmentHelper.getEnchantments(tool);
// Make sure all enchantments can apply to the tool.
for (Entry<Enchantment, Integer> entry : enchantmentsOnToken.entrySet()) {
Enchantment ench = entry.getKey();
// Valid for tool?
if (!ench.canApply(tool))
return false;
// Does new enchantment conflict with any existing ones?
for (Enchantment enchTool : enchantmentsOnTool.keySet()) {
if (!ench.equals(enchTool) && !EnchantmentUtils.canApplyTogether(ench, enchTool))
return false;
}
}
// Appy enchantments to new copy of tool.
if (!mergeEnchantmentLists(enchantmentsOnToken, enchantmentsOnTool)) {
return false;
}
EnchantmentHelper.setEnchantments(enchantmentsOnToken, tool);
return true;
}
use of net.minecraft.enchantment.Enchantment in project SilentGems by SilentChaos512.
the class ItemEnchantmentToken method getEnchantments.
public Map<Enchantment, Integer> getEnchantments(ItemStack token) {
if (StackHelper.isEmpty(token) || !token.hasTagCompound())
return new HashMap<>();
NBTTagList tagList = token.getTagCompound().getTagList(NBT_ENCHANTMENTS, 10);
Map<Enchantment, Integer> map = new HashMap<>();
if (tagList != null) {
for (int i = 0; i < tagList.tagCount(); ++i) {
String name = tagList.getCompoundTagAt(i).getString("name");
int level = tagList.getCompoundTagAt(i).getShort("lvl");
Enchantment ench = Enchantment.REGISTRY.getObject(new ResourceLocation(name));
if (ench != null)
map.put(ench, level);
}
}
return map;
}
use of net.minecraft.enchantment.Enchantment in project DefiledLands by Lykrast.
the class EntityBookWyrm method onLivingUpdate.
/**
* Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
* use this to react to sunlight and start to burn.
*/
public void onLivingUpdate() {
super.onLivingUpdate();
if (digesting > 0 && digestTimer > 0) {
digestTimer--;
if (world.isRemote) {
double d0 = this.rand.nextGaussian() * 0.02D;
double d1 = this.rand.nextGaussian() * 0.02D;
double d2 = this.rand.nextGaussian() * 0.02D;
world.spawnParticle(EnumParticleTypes.ENCHANTMENT_TABLE, posX + (double) (rand.nextFloat() * width * 2.0F) - (double) width, posY + 0.25D + (double) (rand.nextFloat() * height), posZ + (double) (rand.nextFloat() * width * 2.0F) - (double) width, d0, d1, d2);
}
if (digestTimer <= 0) {
digested++;
digesting--;
playDigestEffect(false);
if (digesting > 0)
digestTimer = getDigestTime();
}
}
if (digested >= getMaxLevel()) {
// Spawn the books
digested -= getMaxLevel();
playSound(SoundEvents.ENTITY_CHICKEN_EGG, 1.0F, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
playSound(SoundEvents.ENTITY_PLAYER_LEVELUP, 1.0F, 1.0F);
playDigestEffect(true);
if (!world.isRemote) {
List<EnchantmentData> list = EnchantmentHelper.buildEnchantmentList(rand, new ItemStack(Items.BOOK), getMaxLevel(), isGolden());
if (!list.isEmpty()) {
// Sort by descending digested value
Collections.sort(list, Comparator.comparingInt((e) -> -e.enchantment.getMinEnchantability(e.enchantmentLevel)));
// Make sure that whatever books it gives back, it'll never exceed the enchantment level
// To prevent endless loops
int remaining = (int) (getMaxLevel() / Config.conversionRate);
for (EnchantmentData e : list) {
int value = (int) (e.enchantment.getMinEnchantability(e.enchantmentLevel) * Config.conversionRate);
if (remaining >= value) {
remaining -= value;
ItemStack book = new ItemStack(Items.ENCHANTED_BOOK);
ItemEnchantedBook.addEnchantment(book, e);
entityDropItem(book, 0.5F);
if (remaining <= 0)
break;
}
}
}
}
}
}
use of net.minecraft.enchantment.Enchantment in project BloodMagic by WayofTime.
the class OmegaArmour method getSubstituteStack.
public ItemStack getSubstituteStack(ItemStack boundStack, int stability, int affinity, int enchantability, int enchantmentLevel, Random rand) {
ItemStack omegaStack = new ItemStack(this);
if (boundStack != null && boundStack.hasTagCompound()) {
NBTTagCompound tag = (NBTTagCompound) boundStack.getTagCompound().copy();
omegaStack.setTagCompound(tag);
}
this.setContainedArmourStack(omegaStack, boundStack);
SoulNetworkHandler.checkAndSetItemOwner(omegaStack, SoulNetworkHandler.getOwnerName(boundStack));
this.setItemEnchantability(omegaStack, Math.min(enchantability, 70));
EnchantmentHelper.setEnchantments(new HashMap(), omegaStack);
List enchantList = new ArrayList();
int adjustedEnchantLevel = Math.min(enchantmentLevel, 30);
int additionalPasses = enchantmentLevel - adjustedEnchantLevel;
for (int i = 0; i < 1 + additionalPasses; i++) {
List lst = EnchantmentHelper.buildEnchantmentList(rand, omegaStack, adjustedEnchantLevel);
if (lst != null) {
enchantList.addAll(lst);
}
}
Map<Enchantment, Map<Integer, Integer>> map = new HashMap();
for (Object obj : enchantList) {
EnchantmentData enchantmentdata = (EnchantmentData) obj;
if (!map.containsKey(enchantmentdata.enchantmentobj)) {
map.put(enchantmentdata.enchantmentobj, new HashMap());
}
Map<Integer, Integer> numMap = map.get(enchantmentdata.enchantmentobj);
if (numMap.containsKey(enchantmentdata.enchantmentLevel)) {
numMap.put(enchantmentdata.enchantmentLevel, numMap.get(enchantmentdata.enchantmentLevel) + 1);
} else {
numMap.put(enchantmentdata.enchantmentLevel, 1);
}
}
for (Enchantment ench : this.illegalEnchantmentList) {
if (map.containsKey(ench)) {
map.remove(ench);
}
}
List newEnchantList = new ArrayList();
for (Entry<Enchantment, Map<Integer, Integer>> entry : map.entrySet()) {
Enchantment ench = entry.getKey();
Map<Integer, Integer> numMap = entry.getValue();
if (numMap.isEmpty()) {
continue;
}
int[] enchantValues = new int[1];
for (Entry<Integer, Integer> entry1 : numMap.entrySet()) {
int enchantLevel = entry1.getKey();
int number = entry1.getValue();
if (enchantLevel >= enchantValues.length) {
int[] newEnchantValues = new int[enchantLevel + 1];
for (int i = 0; i < enchantValues.length; i++) {
newEnchantValues[i] = enchantValues[i];
}
enchantValues = newEnchantValues;
}
enchantValues[enchantLevel] += number;
}
int size = enchantValues.length;
int i = 0;
while (i < size) {
int number = enchantValues[i];
if (number >= 2 && i + 1 >= size) {
int[] newEnchantValues = new int[i + 2];
for (int z = 0; z < enchantValues.length; z++) {
newEnchantValues[z] = enchantValues[z];
}
enchantValues = newEnchantValues;
enchantValues[i + 1] += number / 2;
size = enchantValues.length;
}
i++;
}
newEnchantList.add(new EnchantmentData(ench, enchantValues.length - 1));
}
Iterator iterator = newEnchantList.iterator();
while (iterator.hasNext()) {
EnchantmentData enchantmentdata = (EnchantmentData) iterator.next();
{
omegaStack.addEnchantment(enchantmentdata.enchantmentobj, enchantmentdata.enchantmentLevel);
}
}
for (int i = 0; i < 1; i++) {
// omegaStack = EnchantmentHelper.addRandomEnchantment(new Random(), omegaStack, 30);
}
return omegaStack;
}
Aggregations