use of net.minecraft.item.ToolItem in project minecolonies by Minecolonies.
the class WorkerUtil method getBestToolForBlock.
/**
* Get a Tooltype for a certain block. We need this because minecraft has a lot of blocks which have strange or no required tool.
*
* @param state the target BlockState.
* @param blockHardness the hardness.
* @return the toolType to use.
*/
public static IToolType getBestToolForBlock(final BlockState state, float blockHardness) {
final net.minecraftforge.common.ToolType forgeTool = state.getHarvestTool();
String toolName = "";
if (forgeTool == null) {
if (blockHardness > 0f) {
for (final Tuple<ToolType, ItemStack> tool : getOrInitTestTools()) {
if (tool.getB() != null && tool.getB().getItem() instanceof ToolItem) {
final ToolItem toolItem = (ToolItem) tool.getB().getItem();
if (tool.getB().getDestroySpeed(state) >= toolItem.getTier().getSpeed()) {
toolName = tool.getA().getName();
break;
}
}
}
}
} else {
toolName = forgeTool.getName();
}
final IToolType toolType = ToolType.getToolType(toolName);
if (toolType == ToolType.NONE && state.getMaterial() == Material.WOOD) {
return ToolType.AXE;
} else if (state.getBlock() instanceof GlazedTerracottaBlock) {
return ToolType.PICKAXE;
}
return toolType;
}
use of net.minecraft.item.ToolItem in project BleachHack by BleachDrinker420.
the class AutoArmor method onTick.
@BleachSubscribe
public void onTick(EventTick event) {
if (mc.player.playerScreenHandler != mc.player.currentScreenHandler || !BleachQueue.isEmpty("autoarmor_equip"))
return;
if (tickDelay > 0) {
tickDelay--;
return;
}
tickDelay = (getSetting(2).asToggle().getState() ? getSetting(2).asToggle().getChild(0).asSlider().getValueInt() : 0);
/* [Slot type, [Armor slot, Armor prot, New armor slot, New armor prot]] */
Map<EquipmentSlot, int[]> armorMap = new HashMap<>(4);
armorMap.put(EquipmentSlot.FEET, new int[] { 36, getProtection(mc.player.getInventory().getStack(36)), -1, -1 });
armorMap.put(EquipmentSlot.LEGS, new int[] { 37, getProtection(mc.player.getInventory().getStack(37)), -1, -1 });
armorMap.put(EquipmentSlot.CHEST, new int[] { 38, getProtection(mc.player.getInventory().getStack(38)), -1, -1 });
armorMap.put(EquipmentSlot.HEAD, new int[] { 39, getProtection(mc.player.getInventory().getStack(39)), -1, -1 });
/* Anti Break */
if (getSetting(0).asToggle().getState()) {
for (Entry<EquipmentSlot, int[]> e : armorMap.entrySet()) {
ItemStack is = mc.player.getInventory().getStack(e.getValue()[0]);
int armorSlot = (e.getValue()[0] - 34) + (39 - e.getValue()[0]) * 2;
if (is.isDamageable() && is.getMaxDamage() - is.getDamage() < 7) {
/* Look for an empty slot to quick move to */
int forceMoveSlot = -1;
for (int s = 0; s < 36; s++) {
if (mc.player.getInventory().getStack(s).isEmpty()) {
mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, armorSlot, 1, SlotActionType.QUICK_MOVE, mc.player);
return;
} else if (!(mc.player.getInventory().getStack(s).getItem() instanceof ToolItem) && !(mc.player.getInventory().getStack(s).getItem() instanceof ArmorItem) && !(mc.player.getInventory().getStack(s).getItem() instanceof ElytraItem) && mc.player.getInventory().getStack(s).getItem() != Items.TOTEM_OF_UNDYING && forceMoveSlot == -1) {
forceMoveSlot = s;
}
}
/* Bruh no empty spots, then force move to a non-totem/tool/armor item */
if (forceMoveSlot != -1) {
// System.out.println(forceMoveSlot);
mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, forceMoveSlot < 9 ? 36 + forceMoveSlot : forceMoveSlot, 1, SlotActionType.THROW, mc.player);
mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, armorSlot, 1, SlotActionType.QUICK_MOVE, mc.player);
return;
}
/* No spots to move to, yeet the armor to not cause any bruh moments */
mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, armorSlot, 1, SlotActionType.THROW, mc.player);
return;
}
}
}
for (int s = 0; s < 36; s++) {
int prot = getProtection(mc.player.getInventory().getStack(s));
if (prot > 0) {
EquipmentSlot slot = (mc.player.getInventory().getStack(s).getItem() instanceof ElytraItem ? EquipmentSlot.CHEST : ((ArmorItem) mc.player.getInventory().getStack(s).getItem()).getSlotType());
for (Entry<EquipmentSlot, int[]> e : armorMap.entrySet()) {
if (e.getKey() == slot) {
if (prot > e.getValue()[1] && prot > e.getValue()[3]) {
e.getValue()[2] = s;
e.getValue()[3] = prot;
}
}
}
}
}
for (Entry<EquipmentSlot, int[]> e : armorMap.entrySet()) {
if (e.getValue()[2] != -1) {
if (e.getValue()[1] == -1 && e.getValue()[2] < 9) {
if (e.getValue()[2] != mc.player.getInventory().selectedSlot) {
mc.player.getInventory().selectedSlot = e.getValue()[2];
mc.player.networkHandler.sendPacket(new UpdateSelectedSlotC2SPacket(e.getValue()[2]));
}
mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, 36 + e.getValue()[2], 1, SlotActionType.QUICK_MOVE, mc.player);
} else if (mc.player.playerScreenHandler == mc.player.currentScreenHandler) {
/* Convert inventory slots to container slots */
int armorSlot = (e.getValue()[0] - 34) + (39 - e.getValue()[0]) * 2;
int newArmorslot = e.getValue()[2] < 9 ? 36 + e.getValue()[2] : e.getValue()[2];
mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, newArmorslot, 0, SlotActionType.PICKUP, mc.player);
mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, armorSlot, 0, SlotActionType.PICKUP, mc.player);
if (e.getValue()[1] != -1)
mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, newArmorslot, 0, SlotActionType.PICKUP, mc.player);
}
return;
}
}
}
use of net.minecraft.item.ToolItem in project minecolonies by ldtteam.
the class WorkerUtil method getBestToolForBlock.
/**
* Get a Tooltype for a certain block. We need this because minecraft has a lot of blocks which have strange or no required tool.
*
* @param state the target BlockState.
* @param blockHardness the hardness.
* @return the toolType to use.
*/
public static IToolType getBestToolForBlock(final BlockState state, float blockHardness) {
final net.minecraftforge.common.ToolType forgeTool = state.getHarvestTool();
String toolName = "";
if (forgeTool == null) {
if (blockHardness > 0f) {
for (final Tuple<ToolType, ItemStack> tool : getOrInitTestTools()) {
if (tool.getB() != null && tool.getB().getItem() instanceof ToolItem) {
final ToolItem toolItem = (ToolItem) tool.getB().getItem();
if (tool.getB().getDestroySpeed(state) >= toolItem.getTier().getSpeed()) {
toolName = tool.getA().getName();
break;
}
}
}
}
} else {
toolName = forgeTool.getName();
}
final IToolType toolType = ToolType.getToolType(toolName);
if (toolType == ToolType.NONE && state.getMaterial() == Material.WOOD) {
return ToolType.AXE;
} else if (state.getBlock() instanceof GlazedTerracottaBlock) {
return ToolType.PICKAXE;
}
return toolType;
}
use of net.minecraft.item.ToolItem in project bioplethora by AquexTheSeal.
the class BioItemModelProvider method defaultItem.
/**
* If Item is ToolItem or SwordItem, minecraft/handheld model will be generated for that item.
* Otherwise, minecraft/generated model will be generated for that item.
*/
public void defaultItem(Collection<RegistryObject<Item>> items) {
for (RegistryObject<Item> item : items) {
String name = item.getId().getPath();
Item getItem = item.get();
ResourceLocation datagenLoc = new ResourceLocation(Bioplethora.MOD_ID, "item/" + name);
ModelFile.ExistingModelFile modelType = getItem instanceof ToolItem || getItem instanceof SwordItem ? getMcLoc("item/handheld") : getMcLoc("item/generated");
if (!existingFileHelper.exists(datagenLoc, TEXTURE) || existingFileHelper.exists(datagenLoc, MODEL))
continue;
this.getBuilder(name).parent(modelType).texture("layer0", ITEM_FOLDER + "/" + name);
Bioplethora.LOGGER.info("Generate Item Successful: " + item.getId());
}
}
use of net.minecraft.item.ToolItem in project Hypnotic-Client by Hypnotic-Development.
the class Killaura method onMotionUpdate.
@EventTarget
public void onMotionUpdate(EventMotionUpdate event) {
if (maxAps.getValue() <= minAps.getValue())
maxAps.setValue(minAps.getValue() + 1);
if (event.isPre()) {
try {
if (mc.world != null) {
List<LivingEntity> targets = Lists.<LivingEntity>newArrayList();
for (Entity e : mc.world.getEntities()) {
if (e instanceof LivingEntity && e != mc.player && !FriendManager.INSTANCE.isFriend((LivingEntity) e) && mc.player.distanceTo(e) <= range.getValue() && canAttack((LivingEntity) e))
targets.add((LivingEntity) e);
else {
if (targets.contains(e))
targets.remove(e);
}
}
if (target != null && mc.player.distanceTo(target) > range.getValue()) {
targets.remove(target);
target = null;
if (!ModuleManager.INSTANCE.getModule(Scaffold.class).isEnabled()) {
RotationUtils.resetPitch();
RotationUtils.resetYaw();
}
}
switch(mode.getSelected()) {
case "Sort":
switch(sortMode.getSelected()) {
case "Distance":
targets.sort(Comparator.comparingDouble(entity -> mc.player.distanceTo(entity)));
break;
case "Health":
targets.sort(Comparator.comparingDouble(entity -> ((LivingEntity) entity).getHealth()));
break;
}
if (!targets.isEmpty()) {
if (!FriendManager.INSTANCE.isFriend((LivingEntity) targets.get(0)))
target = (LivingEntity) targets.get(0);
if (mc.player.distanceTo(target) > range.getValue())
target = null;
if (target != null) {
this.setDisplayName("Killaura " + ColorUtils.gray + (target instanceof PlayerEntity ? target.getName().asString().replaceAll(ColorUtils.colorChar, "&") : target.getDisplayName().asString()));
if (canAttack(target)) {
RotationUtils.setSilentPitch(RotationUtils.getRotations(target)[1]);
RotationUtils.setSilentYaw(RotationUtils.getRotations(target)[0]);
if (rotation.is("Lock View")) {
mc.player.setYaw(RotationUtils.getRotations(target)[0]);
mc.player.setPitch(RotationUtils.getRotations(target)[1]);
}
long aps = minAps.getValue() < 20 ? new Random().nextInt((int) (maxAps.getValue() - minAps.getValue())) + (int) minAps.getValue() : 20;
if (delay.isEnabled() && random.isEnabled() && mc.player.getAttackCooldownProgress(0.5F) != 1)
attackTimer.reset();
if (delay.isEnabled() ? mc.player.getAttackCooldownProgress(0.5F) == 1 && (random.isEnabled() ? attackTimer.hasTimeElapsed(new Random().nextInt(300 - 100) + 100, true) : true) : attackTimer.hasTimeElapsed((long) (1000L / aps), true)) {
if (autoBlock.isEnabled() && mc.player.getOffHandStack().getItem() instanceof ShieldItem && (mc.player.getMainHandStack().getItem() instanceof ToolItem || mc.player.getMainHandStack().getItem() == Items.AIR || mc.player.getMainHandStack().getItem() instanceof AxeItem || mc.player.getMainHandStack().getItem() instanceof SwordItem) && autoBlockMode.is("Normal")) {
mc.player.networkHandler.sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.RELEASE_USE_ITEM, BlockPos.ORIGIN, Direction.DOWN));
}
blocking = false;
mc.interactionManager.attackEntity(mc.player, target);
if (swing.isEnabled() && (autoBlock.isEnabled() ? !ModuleManager.INSTANCE.getModule(OldBlock.class).isEnabled() : true) || (ModuleManager.INSTANCE.getModule(OldBlock.class).isEnabled() ? mc.options.getPerspective() != Perspective.FIRST_PERSON : false) && !(mc.player.getMainHandStack().getItem() instanceof SwordItem))
mc.player.swingHand(Hand.MAIN_HAND);
else
mc.player.networkHandler.sendPacket(new HandSwingC2SPacket(Hand.MAIN_HAND));
if (swing.isEnabled() && !(mc.player.getMainHandStack().getItem() instanceof SwordItem) || ModuleManager.INSTANCE.getModule(OldBlock.class).animation.is("Swing"))
mc.player.swingHand(Hand.MAIN_HAND);
}
}
if (target.isDead()) {
RotationUtils.resetYaw();
RotationUtils.resetPitch();
}
} else {
if (blocking)
mc.options.useKey.setPressed(false);
blocking = false;
if (!ModuleManager.INSTANCE.getModule(Scaffold.class).isEnabled()) {
RotationUtils.resetPitch();
RotationUtils.resetYaw();
}
this.setDisplayName("Killaura " + ColorUtils.gray + "None");
}
} else {
if (blocking)
mc.options.useKey.setPressed(false);
blocking = false;
if (!ModuleManager.INSTANCE.getModule(Scaffold.class).isEnabled()) {
RotationUtils.resetPitch();
RotationUtils.resetYaw();
}
}
break;
case "Multi":
if (!targets.isEmpty()) {
for (LivingEntity entity : targets) {
if (entity != null && !FriendManager.INSTANCE.isFriend(entity)) {
this.setDisplayName("Killaura " + ColorUtils.gray + (entity instanceof PlayerEntity ? entity.getName().asString().replaceAll(ColorUtils.colorChar, "&") : entity.getDisplayName().asString()));
if (canAttack(entity)) {
if (target != null)
RotationUtils.setSilentPitch(RotationUtils.getRotations(target)[1]);
if (target != null)
RotationUtils.setSilentYaw(RotationUtils.getRotations(target)[0]);
if (rotation.is("Lock View")) {
if (target != null)
mc.player.setYaw(RotationUtils.getRotations(target)[0]);
if (target != null)
mc.player.setPitch(RotationUtils.getRotations(target)[1]);
}
long aps = minAps.getValue() < 20 ? new Random().nextInt((int) (maxAps.getValue() - minAps.getValue())) + (int) minAps.getValue() : 20;
if (delay.isEnabled() && random.isEnabled() && mc.player.getAttackCooldownProgress(0.5F) != 1)
attackTimer.reset();
if ((delay.isEnabled() ? mc.player.getAttackCooldownProgress(0.5F) == 1 && (random.isEnabled() ? attackTimer.hasTimeElapsed(new Random().nextInt(300 - 100) + 100, true) : true) : attackTimer.hasTimeElapsed((long) (1000L / aps), true)) && targets.indexOf(entity) == new Random().nextInt(targets.size())) {
if (autoBlock.isEnabled() && mc.player.getOffHandStack().getItem() instanceof ShieldItem && (mc.player.getMainHandStack().getItem() instanceof ToolItem || mc.player.getMainHandStack().getItem() == Items.AIR || mc.player.getMainHandStack().getItem() instanceof AxeItem || mc.player.getMainHandStack().getItem() instanceof SwordItem) && autoBlockMode.is("NCP")) {
mc.player.networkHandler.sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.RELEASE_USE_ITEM, BlockPos.ORIGIN, Direction.DOWN));
}
blocking = false;
target = entity;
mc.interactionManager.attackEntity(mc.player, entity);
if (swing.isEnabled() && (autoBlock.isEnabled() ? !ModuleManager.INSTANCE.getModule(OldBlock.class).isEnabled() : true) || (ModuleManager.INSTANCE.getModule(OldBlock.class).isEnabled() ? mc.options.getPerspective() != Perspective.FIRST_PERSON : false) && !(mc.player.getMainHandStack().getItem() instanceof SwordItem))
mc.player.swingHand(Hand.MAIN_HAND);
else
mc.player.networkHandler.sendPacket(new HandSwingC2SPacket(Hand.MAIN_HAND));
if (swing.isEnabled() && !(mc.player.getMainHandStack().getItem() instanceof SwordItem) || ModuleManager.INSTANCE.getModule(OldBlock.class).animation.is("Swing"))
mc.player.swingHand(Hand.MAIN_HAND);
}
}
if (entity.isDead()) {
RotationUtils.resetYaw();
RotationUtils.resetPitch();
}
} else {
}
}
} else {
if (!ModuleManager.INSTANCE.getModule(Scaffold.class).isEnabled()) {
RotationUtils.resetPitch();
RotationUtils.resetYaw();
}
}
break;
}
if (targets.isEmpty())
target = null;
this.setDisplayName("Killaura " + ColorUtils.gray + mode.getSelected());
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
if (target == null)
return;
if (autoBlock.isEnabled() && (mc.player.getMainHandStack().getItem() instanceof ToolItem || mc.player.getMainHandStack().getItem() == Items.AIR || mc.player.getMainHandStack().getItem() instanceof AxeItem || mc.player.getMainHandStack().getItem() instanceof SwordItem) && !autoBlockMode.is("Visual")) {
mc.interactionManager.interactItem(mc.player, mc.world, Hand.OFF_HAND);
mc.interactionManager.interactItem(mc.player, mc.world, Hand.MAIN_HAND);
if (!blocking && autoBlockMode.is("NCP")) {
mc.player.networkHandler.sendPacket(new PlayerInteractBlockC2SPacket(Hand.MAIN_HAND, new BlockHitResult(new Vec3d(0.0f, 0.0f, 0.0f), Direction.DOWN, new BlockPos(-1, -1, -1), false)));
blocking = true;
}
}
}
}
Aggregations