use of net.minecraft.item.ItemSword in project Tropicraft by Tropicraft.
the class BlockEvents method handleCoconutBreakEvent.
@SubscribeEvent
public void handleCoconutBreakEvent(HarvestDropsEvent event) {
World world = event.getWorld();
Block block = event.getState().getBlock();
int x = event.getPos().getX();
int y = event.getPos().getY();
int z = event.getPos().getZ();
EntityPlayer player = event.getHarvester();
if (world.isRemote)
return;
if (block != BlockRegistry.coconut)
return;
ItemStack handItemStack = player.getHeldItemMainhand();
Item inHand;
if (!handItemStack.isEmpty())
inHand = handItemStack.getItem();
else
inHand = null;
ItemStack drop = ItemStack.EMPTY;
if (inHand != null && (inHand instanceof ItemSword || inHand.getItemUseAction(new ItemStack(inHand)) == EnumAction.BLOCK))
drop = new ItemStack(ItemRegistry.coconutChunk);
else
drop = new ItemStack(block, 1, 0);
int numDrops = drop.getItem() == ItemRegistry.coconutChunk ? world.rand.nextInt(3) + 2 : 1;
world.setBlockToAir(event.getPos());
for (int i = 0; i < numDrops; i++) dropBlockAsItem(world, x, y, z, drop);
}
use of net.minecraft.item.ItemSword in project Adventurers-Toolbox by the-realest-stu.
the class CommonProxy method processRecipes.
protected void processRecipes() {
if (ForgeRegistries.RECIPES instanceof IForgeRegistryModifiable) {
IForgeRegistryModifiable registry = (IForgeRegistryModifiable) ForgeRegistries.RECIPES;
Entry<ResourceLocation, IRecipe>[] recipeEntries = ForgeRegistries.RECIPES.getEntries().toArray(new Entry[ForgeRegistries.RECIPES.getEntries().size()]);
for (int recipeIndex = 0; recipeIndex < recipeEntries.length; recipeIndex++) {
Entry<ResourceLocation, IRecipe> recipeEntry = recipeEntries[recipeIndex];
IRecipe recipe = recipeEntry.getValue();
NonNullList<Ingredient> ingredients = recipe.getIngredients();
Item output = recipe.getRecipeOutput().getItem();
String rp = output.getRegistryName().getResourcePath();
boolean exception = false;
for (String s : Config.REMOVAL_EXCEPTIONS) {
if (output.getRegistryName().toString().contains(s)) {
exception = true;
}
}
if (exception == false && (output instanceof ItemHoe || output instanceof ItemAxe || output instanceof ItemSpade || output instanceof ItemPickaxe || output instanceof ItemSword) || (output instanceof ItemTool && (rp.contains("pick") || rp.contains("axe") || rp.contains("shovel") || rp.contains("spade"))) || (output instanceof ItemTool && (output.getRegistryName().getResourceDomain().equals("thermalfoundation") && rp.contains("hammer")))) {
String materialName = output instanceof ItemHoe ? ((ItemHoe) output).getMaterialName() : output instanceof ItemSword ? ((ItemSword) output).getToolMaterialName() : ((ItemTool) output).getToolMaterialName();
if (Materials.canReplaceMaterial(materialName, recipe.getRecipeOutput())) {
// System.out.println(materialName);
registry.remove(recipeEntry.getKey());
registry.register(new IRecipe() {
private ResourceLocation registryName;
@Override
public IRecipe setRegistryName(ResourceLocation name) {
this.registryName = name;
return this;
}
@Override
public ResourceLocation getRegistryName() {
return this.registryName;
}
@Override
public Class<IRecipe> getRegistryType() {
return IRecipe.class;
}
@Override
public boolean matches(InventoryCrafting inv, World worldIn) {
return false;
}
@Override
public ItemStack getCraftingResult(InventoryCrafting inv) {
return ItemStack.EMPTY;
}
@Override
public boolean canFit(int width, int height) {
return false;
}
@Override
public ItemStack getRecipeOutput() {
return ItemStack.EMPTY;
}
}.setRegistryName(recipeEntry.getKey()));
removed_recipes.add(recipeEntry.getKey());
} else {
System.out.println(output.getRegistryName() + " -> " + materialName);
}
} else {
for (int i = 0; i < ingredients.size(); i++) {
ItemStack[] matchingStacks = ingredients.get(i).getMatchingStacks();
boolean flag = false;
Item ingredientItem = null;
for (int j = 0; j < matchingStacks.length && !flag; j++) {
Item item = matchingStacks[j].getItem();
if (!getToolReplacement(item).isEmpty()) {
ingredientItem = item;
flag = true;
}
}
if (flag && ingredientItem != null && !getToolReplacement(ingredientItem).isEmpty()) {
ingredients.set(i, new IngredientNBT(getToolReplacement(ingredientItem)) {
});
}
}
}
}
}
}
use of net.minecraft.item.ItemSword in project Adventurers-Toolbox by the-realest-stu.
the class SpecialToolAbilityHandler method onAttack.
@SubscribeEvent
public void onAttack(AttackEntityEvent event) {
EntityPlayer player = event.getEntityPlayer();
Entity targetEntity = event.getTarget();
ItemStack weapon = player.getHeldItemMainhand();
if (targetEntity instanceof EntityLivingBase) {
EntityLivingBase target = (EntityLivingBase) targetEntity;
if (!player.world.isRemote && isVoidTool(weapon)) {
target.addPotionEffect(new PotionEffect(MobEffects.WEAKNESS, weapon.getItem() instanceof ItemSword ? 60 : 80));
}
}
}
use of net.minecraft.item.ItemSword in project Wurst-MC-1.12 by Wurst-Imperium.
the class AutoSwordMod method setSlot.
public void setSlot() {
// check if active
if (!isActive())
return;
// wait for AutoEat
if (wurst.mods.autoEatMod.isEating())
return;
// find best weapon
float bestDamage = 0;
int bestSlot = -1;
for (int i = 0; i < 9; i++) {
// skip empty slots
if (InventoryUtils.isSlotEmpty(i))
continue;
Item item = WMinecraft.getPlayer().inventory.getStackInSlot(i).getItem();
// get damage
float damage = 0;
if (item instanceof ItemSword)
damage = ((ItemSword) item).attackDamage;
else if (item instanceof ItemTool)
damage = ((ItemTool) item).damageVsEntity;
// compare with previous best weapon
if (damage > bestDamage) {
bestDamage = damage;
bestSlot = i;
}
}
// check if any weapon was found
if (bestSlot == -1)
return;
// save old slot
if (oldSlot == -1)
oldSlot = WMinecraft.getPlayer().inventory.currentItem;
// set slot
WMinecraft.getPlayer().inventory.currentItem = bestSlot;
// start timer
timer = 4;
wurst.events.add(UpdateListener.class, this);
}
use of net.minecraft.item.ItemSword in project Wurst-MC-1.12 by Wurst-Imperium.
the class AutoToolMod method setSlot.
public void setSlot(BlockPos pos) {
// check if active
if (!isActive())
return;
// check gamemode
EntityPlayer player = WMinecraft.getPlayer();
if (player.capabilities.isCreativeMode)
return;
// check if block can be clicked
if (!WBlock.canBeClicked(pos))
return;
// initialize speed & slot
IBlockState state = WBlock.getState(pos);
float bestSpeed = getDestroySpeed(player.getHeldItemMainhand(), state);
int bestSlot = -1;
// find best tool
for (int slot = 0; slot < 9; slot++) {
if (slot == player.inventory.currentItem)
continue;
ItemStack stack = player.inventory.getStackInSlot(slot);
float speed = getDestroySpeed(stack, state);
if (speed <= bestSpeed)
continue;
if (!useSwords.isChecked() && stack.getItem() instanceof ItemSword)
continue;
bestSpeed = speed;
bestSlot = slot;
}
// check if any tool was found
if (bestSlot == -1)
return;
// save old slot
if (oldSlot == -1)
oldSlot = player.inventory.currentItem;
// set slot
player.inventory.currentItem = bestSlot;
// save position
this.pos = pos;
// start timer
timer = 4;
}
Aggregations