Initial 1.11.2 update
This commit is contained in:
@@ -10,50 +10,48 @@ import net.minecraft.item.ItemStack;
|
||||
// into the damage increase for melee weapons, meaning I don't have to use events - always handy!
|
||||
public class EnchantmentMagicSword extends EnchantmentDamage implements Imbuement {
|
||||
|
||||
public EnchantmentMagicSword() {
|
||||
public EnchantmentMagicSword(){
|
||||
super(Enchantment.Rarity.COMMON, 0, EntityEquipmentSlot.MAINHAND);
|
||||
// Setting this to null stops the book appearing in the creative inventory
|
||||
this.type = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canApply(ItemStack p_92089_1_){
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum level that the enchantment can have.
|
||||
*/
|
||||
/**
|
||||
* Returns the maximum level that the enchantment can have.
|
||||
*/
|
||||
// Here, enchantment level is the damage multiplier of the spell used to apply the enchantment, i.e. with an
|
||||
// non-sorcerer wand it is level 1, a basic sorcerer wand is level 2, and so on. Note that basic sorcerer wands can't
|
||||
// non-sorcerer wand it is level 1, a basic sorcerer wand is level 2, and so on. Note that basic sorcerer wands
|
||||
// can't
|
||||
// cast the imbue weapon spell, so level 2 is actually for apprentice wands.
|
||||
@Override
|
||||
public int getMaxLevel()
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
@Override
|
||||
public int getMaxLevel(){
|
||||
return 4;
|
||||
}
|
||||
|
||||
// Returns the number by which the damage should be increased (or something)
|
||||
@Override
|
||||
public float calcDamageByCreature(int p_152376_1_, EnumCreatureAttribute p_152376_2_)
|
||||
{
|
||||
return (float)p_152376_1_ * 1.25F;
|
||||
}
|
||||
// Returns the number by which the damage should be increased (or something)
|
||||
@Override
|
||||
public float calcDamageByCreature(int p_152376_1_, EnumCreatureAttribute p_152376_2_){
|
||||
return (float)p_152376_1_ * 1.25F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(){
|
||||
return "enchantment." + this.getRegistryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowedOnBooks(){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canApplyAtEnchantingTable(ItemStack stack){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "enchantment." + this.getRegistryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowedOnBooks(){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canApplyAtEnchantingTable(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,43 +6,42 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
// This one is for everything other than imbued swords.
|
||||
public class EnchantmentTimed extends Enchantment implements Imbuement {
|
||||
|
||||
public EnchantmentTimed() {
|
||||
|
||||
public EnchantmentTimed(){
|
||||
// Setting enchantment type to null stops the book appearing in the creative inventory
|
||||
super(Enchantment.Rarity.COMMON, null, new EntityEquipmentSlot[]{EntityEquipmentSlot.MAINHAND});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canApply(ItemStack p_92089_1_){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "enchantment." + this.getRegistryName();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum level that the enchantment can have.
|
||||
*/
|
||||
@Override
|
||||
public String getName(){
|
||||
return "enchantment." + this.getRegistryName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum level that the enchantment can have.
|
||||
*/
|
||||
// Here, enchantment level is the damage multiplier of the spell used to apply the enchantment, i.e. with an
|
||||
// non-sorcerer wand it is level 1, an apprentice sorcerer wand is level 2, and so on. Note that basic sorcerer wands can't
|
||||
// non-sorcerer wand it is level 1, an apprentice sorcerer wand is level 2, and so on. Note that basic sorcerer
|
||||
// wands can't
|
||||
// cast the imbue weapon spell, so level 2 is actually for apprentice wands.
|
||||
@Override
|
||||
public int getMaxLevel()
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowedOnBooks(){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canApplyAtEnchantingTable(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(){
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowedOnBooks(){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canApplyAtEnchantingTable(ItemStack stack){
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,12 +22,15 @@ import net.minecraftforge.event.entity.player.PlayerContainerEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
/** Interface for temporary enchantments that last for a certain duration ('imbuements'). This interface allows
|
||||
* {@link EnchantmentMagicSword} and {@link EnchantmentTimed} to both be treated as instances of a
|
||||
* single type, rather than having to deal with each of them separately,
|
||||
* which would be inefficient and cumbersome (the former of those classes cannot extend the latter because they both
|
||||
* need to extend different subclasses of {@link net.minecraft.enchantment.Enchantment}).
|
||||
* @since Wizardry 1.2 */
|
||||
/**
|
||||
* Interface for temporary enchantments that last for a certain duration ('imbuements'). This interface allows
|
||||
* {@link EnchantmentMagicSword} and {@link EnchantmentTimed} to both be treated as instances of a single type, rather
|
||||
* than having to deal with each of them separately, which would be inefficient and cumbersome (the former of those
|
||||
* classes cannot extend the latter because they both need to extend different subclasses of
|
||||
* {@link net.minecraft.enchantment.Enchantment}).
|
||||
*
|
||||
* @since Wizardry 1.2
|
||||
*/
|
||||
@Mod.EventBusSubscriber
|
||||
public interface Imbuement {
|
||||
|
||||
@@ -46,11 +49,12 @@ public interface Imbuement {
|
||||
// Instantly disenchants an imbued weapon if it is thrown on the ground.
|
||||
removeImbuements(event.getEntityItem().getEntityItem());
|
||||
}
|
||||
|
||||
|
||||
/** Removes all imbuements from the given itemstack. */
|
||||
static void removeImbuements(ItemStack stack){
|
||||
if(stack.isItemEnchanted()){
|
||||
// No need to check what enchantments the item has, since remove() does nothing if the element does not exist.
|
||||
// No need to check what enchantments the item has, since remove() does nothing if the element does not
|
||||
// exist.
|
||||
Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(stack);
|
||||
// Removes the magic weapon enchantments from the enchantment map
|
||||
enchantments.entrySet().removeIf(entry -> entry.getKey() instanceof Imbuement);
|
||||
@@ -58,7 +62,7 @@ public interface Imbuement {
|
||||
EnchantmentHelper.setEnchantments(enchantments, stack);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onPlayerOpenContainerEvent(PlayerContainerEvent event){
|
||||
// Brute-force fix to stop enchanted books in dungeon chests from having imbuements on them.
|
||||
@@ -74,7 +78,7 @@ public interface Imbuement {
|
||||
// If any imbuements were removed, replaces the enchantments on the book with the new ones, or
|
||||
// deletes the book entirely if there are none left.
|
||||
if(enchantments.isEmpty()){
|
||||
slot.putStack(null); // NOTE: Will need changing in 1.11
|
||||
slot.putStack(ItemStack.EMPTY); // NOTE: Will need changing in 1.11
|
||||
Wizardry.logger.info("Deleted enchanted book with illegal enchantments");
|
||||
}else{
|
||||
EnchantmentHelper.setEnchantments(enchantments, slot.getStack());
|
||||
@@ -90,7 +94,7 @@ public interface Imbuement {
|
||||
public static void onEntityJoinWorld(EntityJoinWorldEvent event){
|
||||
// Rather long-winded (but necessary) way of getting an arrow just after it has been fired, checking if the bow
|
||||
// that fired it has the imbuement enchantment, and applying extra damage accordingly.
|
||||
if(!event.getEntity().worldObj.isRemote && event.getEntity() instanceof EntityArrow){
|
||||
if(!event.getEntity().world.isRemote && event.getEntity() instanceof EntityArrow){
|
||||
|
||||
EntityArrow arrow = (EntityArrow)event.getEntity();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user