use of net.minecraft.item.ItemSword in project clientcommands by Earthcomputer.
the class ToolDamageManager method registerEvents.
public static void registerEvents() {
EventManager.addOutboundPacketPreListener(e -> {
Iterator<Class<? extends Packet<?>>> packetItr = packetsToBlock.iterator();
while (packetItr.hasNext()) {
if (packetItr.next().isInstance(e.getPacket())) {
e.setCanceled(true);
packetItr.remove();
return;
}
}
});
EventManager.addPlayerTickListener(e -> {
EntityPlayer player = e.player;
if (player.isElytraFlying()) {
ItemStack elytra = player.inventory.armorItemInSlot(2);
if (!elytra.isEmpty() && elytra.getItem() == Items.ELYTRA) {
if (postToolDamaged(player, elytra, 1)) {
NetUtils.sendPacket(new CPacketEntityAction(player, CPacketEntityAction.Action.START_FALL_FLYING));
}
}
}
});
EventManager.addUseBlockListener(e -> {
ItemStack stack = e.getItemStack();
if (stack.isEmpty()) {
return;
}
Item item = stack.getItem();
IBlockState state = e.getWorld().getBlockState(e.getPos());
if (state.getBlock() == Blocks.TNT) {
if (item == Items.FLINT_AND_STEEL) {
if (postToolDamaged(e.getEntityPlayer(), stack, 1)) {
e.setCanceled(true);
packetsToBlock.add(CPacketPlayerTryUseItemOnBlock.class);
}
return;
}
}
if (e.getEntityPlayer().canPlayerEdit(e.getPos().offset(e.getFace()), e.getFace(), stack)) {
if (item instanceof ItemHoe) {
boolean usedHoe = false;
if (state.getBlock() == Blocks.GRASS || state.getBlock() == Blocks.GRASS_PATH) {
usedHoe = true;
} else if (state.getBlock() == Blocks.DIRT) {
BlockDirt.DirtType variant = state.getValue(BlockDirt.VARIANT);
usedHoe = variant == BlockDirt.DirtType.DIRT || variant == BlockDirt.DirtType.COARSE_DIRT;
}
if (usedHoe) {
if (postToolDamaged(e.getEntityPlayer(), stack, 1)) {
e.setCanceled(true);
packetsToBlock.add(CPacketPlayerTryUseItemOnBlock.class);
}
}
return;
} else if (item == Items.FLINT_AND_STEEL) {
if (postToolDamaged(e.getEntityPlayer(), stack, 1)) {
e.setCanceled(true);
packetsToBlock.add(CPacketPlayerTryUseItemOnBlock.class);
}
return;
} else if (item instanceof ItemSpade) {
// creating a grass path
if (e.getFace() != EnumFacing.DOWN && e.getWorld().getBlockState(e.getPos().up()).getMaterial() == Material.AIR && e.getWorld().getBlockState(e.getPos()).getBlock() == Blocks.GRASS) {
if (postToolDamaged(e.getEntityPlayer(), stack, 1)) {
e.setCanceled(true);
packetsToBlock.add(CPacketPlayerTryUseItemOnBlock.class);
}
return;
}
}
}
});
EventManager.addAttackBlockListener(e -> {
if (!Minecraft.getMinecraft().playerController.isInCreativeMode()) {
IBlockState hitState = e.getWorld().getBlockState(e.getPos());
int damage = getDestroyBlockDamage(e.getWorld(), e.getPos(), e.getEntityPlayer());
if (damage != 0) {
if (postToolDamagedPre(e.getEntityPlayer(), e.getItemStack(), damage)) {
e.setCanceled(true);
packetsToBlock.add(CPacketPlayerDigging.class);
} else if (hitState.getMaterial() != Material.AIR && hitState.getPlayerRelativeBlockHardness(e.getEntityPlayer(), e.getWorld(), e.getPos()) >= 1) {
// handle end of instant-mine
postToolDamagedPost(e.getEntityPlayer(), e.getItemStack(), damage);
}
}
}
});
// need to listen for the packet since it's dispatched before the normal event
EventManager.addOutboundPacketPreListener(e -> {
Packet<?> packet = e.getPacket();
if (packet instanceof CPacketPlayerTryUseItem) {
CPacketPlayerTryUseItem useItem = (CPacketPlayerTryUseItem) packet;
EntityPlayer player = Minecraft.getMinecraft().player;
ItemStack stack = player.getHeldItem(useItem.getHand());
if (stack.isEmpty()) {
return;
}
Item item = stack.getItem();
if (player.getCooldownTracker().hasCooldown(item)) {
return;
}
if (item == Items.CARROT_ON_A_STICK) {
if (postToolDamaged(player, stack, 7)) {
e.setCanceled(true);
timesToBlockUseItem++;
}
return;
} else if (item instanceof ItemFishingRod) {
if (postToolDamaged(player, stack, 5)) {
// assume 5 (max in vanilla)
e.setCanceled(true);
timesToBlockUseItem++;
}
return;
}
} else if (packet instanceof CPacketUseEntity) {
CPacketUseEntity useEntity = (CPacketUseEntity) packet;
if (Minecraft.getMinecraft().playerController.isSpectator()) {
return;
}
if (useEntity.getAction() == CPacketUseEntity.Action.ATTACK) {
EntityPlayer player = Minecraft.getMinecraft().player;
ItemStack stack = player.getHeldItemMainhand();
if (stack.isEmpty()) {
return;
}
Item item = stack.getItem();
int damage = 0;
if (item instanceof ItemSword || item instanceof ItemHoe) {
damage = 1;
} else if (item instanceof ItemTool) {
damage = 2;
}
if (damage != 0) {
if (postToolDamaged(player, stack, damage)) {
e.setCanceled(true);
timesToBlockAttackEntity++;
}
}
} else if (useEntity.getAction() == CPacketUseEntity.Action.INTERACT) {
boolean isDamagingItem = false;
EntityPlayer player = Minecraft.getMinecraft().player;
ItemStack stack = player.getHeldItem(useEntity.getHand());
if (stack.isEmpty()) {
return;
}
Item item = stack.getItem();
Entity target = useEntity.getEntityFromWorld(Minecraft.getMinecraft().world);
if (item instanceof ItemShears) {
if (target instanceof IShearable) {
if (((IShearable) target).isShearable(stack, target.world, new BlockPos(target))) {
// shearing sheep, snow golems
isDamagingItem = true;
}
}
} else if (item == Items.FLINT_AND_STEEL) {
if (target instanceof EntityCreeper) {
isDamagingItem = true;
}
}
if (isDamagingItem) {
if (postToolDamaged(player, stack, 1)) {
e.setCanceled(true);
timesToBlockUseEntity++;
}
return;
}
}
} else if (packet instanceof CPacketPlayerDigging) {
CPacketPlayerDigging playerDigging = (CPacketPlayerDigging) packet;
if (playerDigging.getAction() == CPacketPlayerDigging.Action.RELEASE_USE_ITEM) {
EntityPlayer player = Minecraft.getMinecraft().player;
if (player.capabilities.isCreativeMode) {
return;
}
ItemStack stack = player.getActiveItemStack();
if (stack.isEmpty()) {
return;
}
Item item = stack.getItem();
if (item instanceof ItemBow) {
boolean hasAmmo = false;
for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
ItemStack arrow = player.inventory.getStackInSlot(i);
if (!arrow.isEmpty() && arrow.getItem() instanceof ItemArrow) {
hasAmmo = true;
break;
}
}
int charge = stack.getMaxItemUseDuration() - player.getItemInUseCount();
if (hasAmmo && ItemBow.getArrowVelocity(charge) >= 0.1) {
if (postToolDamaged(player, stack, 1)) {
e.setCanceled(true);
timesToBlockStopUseItem++;
}
}
}
} else if (playerDigging.getAction() == CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK) {
// the player has completed mining a block
Minecraft mc = Minecraft.getMinecraft();
int damage = getDestroyBlockDamage(mc.world, playerDigging.getPosition(), mc.player);
if (damage != 0) {
postToolDamagedPost(mc.player, mc.player.getHeldItemMainhand(), damage);
}
}
}
});
EventManager.addUseItemListener(e -> {
if (timesToBlockUseItem > 0) {
timesToBlockUseItem--;
e.setCanceled(true);
}
});
EventManager.addStopUseItemListener(e -> {
if (timesToBlockStopUseItem > 0) {
timesToBlockStopUseItem--;
e.setCanceled(true);
}
});
EventManager.addAttackEntityListener(e -> {
if (timesToBlockAttackEntity > 0) {
timesToBlockAttackEntity--;
e.setCanceled(true);
}
});
EventManager.addUseEntityListener(e -> {
if (timesToBlockUseEntity > 0) {
timesToBlockUseEntity--;
e.setCanceled(true);
}
});
}
use of net.minecraft.item.ItemSword in project BapeClient by BapeDeveloperTeam.
the class MurderMystery method o.
@SubscribeEvent
public void o(final RenderWorldLastEvent ev) {
if (MurderMystery.mc.thePlayer.getWorldScoreboard() != null && MurderMystery.mc.thePlayer.getWorldScoreboard().getObjectiveInDisplaySlot(1) != null) {
final String d = MurderMystery.mc.thePlayer.getWorldScoreboard().getObjectiveInDisplaySlot(1).getDisplayName();
if (d.contains("MURDER") || d.contains("MYSTERY")) {
for (final EntityPlayer en : MurderMystery.mc.theWorld.playerEntities) {
if (en != MurderMystery.mc.thePlayer && !en.isInvisible() && !AntiBot.isServerBot(en)) {
if (en.getHeldItem() != null && en.getHeldItem().hasDisplayName()) {
final Item i = en.getHeldItem().getItem();
if (i instanceof ItemSword || i instanceof ItemAxe || en.getHeldItem().getDisplayName().replaceAll("ยง", "").equals("aKnife")) {
if (!MurderMystery.m.contains(en)) {
MurderMystery.m.add(en);
MurderMystery.mc.thePlayer.playSound("note.pling", 1.0f, 1.0f);
Helper.sendMessage(en.getName() + " is the murderer!");
if (this.Murder.getValue()) {
mc.thePlayer.sendChatMessage(en.getName() + " is the murderer!");
}
}
} else if (i instanceof ItemBow && !MurderMystery.bw.contains(en)) {
MurderMystery.bw.add(en);
Helper.sendMessage("[WARNING]" + en.getName() + " have bow! he maybe will kill you.");
if (this.Bow.getValue()) {
mc.thePlayer.sendChatMessage(en.getName() + " have bow.");
}
}
}
int rgb = Color.green.getRGB();
if ((MurderMystery.m.contains(en) && !MurderMystery.bw.contains(en)) || (MurderMystery.m.contains(en) && MurderMystery.bw.contains(en))) {
rgb = Color.red.getRGB();
}
if (!MurderMystery.m.contains(en) && MurderMystery.bw.contains(en)) {
rgb = Color.orange.getRGB();
}
}
}
} else {
this.c();
}
} else {
this.c();
}
}
use of net.minecraft.item.ItemSword in project Lands-of-Icaria by Axanthic-Game-Studios.
the class ClientProxy method onWeaponBreaks.
public void onWeaponBreaks(LivingAttackEvent event) {
DamageSource source = event.getSource();
if (source instanceof EntityDamageSource) {
EntityDamageSource damageSource = (EntityDamageSource) source;
Entity entitySource = damageSource.getTrueSource();
if (entitySource instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) entitySource;
for (int slot = 0; slot < 9; slot++) {
ItemStack totem = player.inventory.getStackInSlot(slot);
if (totem.getItem().equals(Resources.totem_unshattering)) {
ItemStack tools = player.getHeldItemMainhand();
if (tools.getItem() instanceof ItemTool || tools.getItem() instanceof ItemHoe || tools.getItem() instanceof ItemSword) {
if (tools.getItem().getMaxDamage(tools) - tools.getItem().getDamage(tools) < tools.getItem().getMaxDamage(tools) * 0.1) {
tools.setItemDamage((int) (tools.getItem().getMaxDamage(tools) * 0.1));
((ItemTotem) totem.getItem()).animationTotemUnshattering(player);
totem.shrink(1);
}
}
}
}
ItemStack totem = player.inventory.getStackInSlot(40);
if (totem.getItem().equals(Resources.totem_unshattering)) {
ItemStack tools = player.getHeldItemMainhand();
if (tools.getItem() instanceof ItemTool || tools.getItem() instanceof ItemHoe || tools.getItem() instanceof ItemSword) {
if (tools.getItem().getMaxDamage(tools) - tools.getItem().getDamage(tools) < tools.getItem().getMaxDamage(tools) * 0.1) {
tools.setItemDamage((int) (tools.getItem().getMaxDamage(tools) * 0.1));
((ItemTotem) totem.getItem()).animationTotemUnshattering(player);
totem.shrink(1);
}
}
}
}
}
}
use of net.minecraft.item.ItemSword in project Lands-of-Icaria by Axanthic-Game-Studios.
the class ClientProxy method registerModels.
@SubscribeEvent
public void registerModels(ModelRegistryEvent event) {
for (ItemBlock block : Resources.blocks) {
if (block.getBlock() instanceof BlockFlower || block.getBlock() instanceof BlockTallGrass || block.getBlock() instanceof BlockHerb) {
for (int i = 0; i < ((IBlockMeta) block.getBlock()).getNames().length; i++) {
ModelLoader.setCustomModelResourceLocation(block, i, new ModelResourceLocation(block.getRegistryName() + "_inv", "type=" + ((IBlockMeta) block.getBlock()).getNames()[i]));
}
} else if (block.getBlock() instanceof BlockLeafOlives) {
// olive leaves are weird
ModelLoader.setCustomModelResourceLocation(block, 0, new ModelResourceLocation(block.getRegistryName(), "check_decay=false,decayable=false,type=" + ((IBlockMeta) block.getBlock()).getNameForMeta(0)));
ModelLoader.setCustomModelResourceLocation(block, 1, new ModelResourceLocation(block.getRegistryName(), "check_decay=false,decayable=false,type=" + ((IBlockMeta) block.getBlock()).getNameForMeta(1)));
} else if (block instanceof ItemBlockMeta) {
ModelLoader.setCustomMeshDefinition(block, new ItemMeshDefinition() {
@Override
public ModelResourceLocation getModelLocation(ItemStack stack) {
return new ModelResourceLocation(block.getRegistryName(), "type=" + ((IBlockMeta) block.getBlock()).getNameForMeta(stack.getMetadata()));
}
});
} else if (block.getBlock() instanceof BlockLeaf || block.getBlock() instanceof BlockSapling || block.getBlock() instanceof BlockCustomWorkbench) {
String[] path = block.getRegistryName().getResourcePath().split("_");
if (block.getBlock() instanceof BlockSapling)
ModelLoader.setCustomModelResourceLocation(block, 0, new ModelResourceLocation(new ResourceLocation(block.getRegistryName().getResourceDomain(), "wood_" + path[1]), "inv_" + path[0]));
else
ModelLoader.setCustomModelResourceLocation(block, 0, new ModelResourceLocation(new ResourceLocation(block.getRegistryName().getResourceDomain(), "wood_" + path[1]), path[0]));
ModelLoader.setCustomStateMapper(block.getBlock(), new StateMapperBase() {
@Override
public ModelResourceLocation getModelResourceLocation(IBlockState state) {
return new ModelResourceLocation(new ResourceLocation(block.getRegistryName().getResourceDomain(), "wood_" + path[1]), path[0]);
}
});
} else if (block.getBlock() instanceof BlockLog) {
String[] path = block.getRegistryName().getResourcePath().split("_");
ResourceLocation loc = new ResourceLocation(block.getRegistryName().getResourceDomain(), "wood_" + path[1]);
ModelLoader.setCustomModelResourceLocation(block, 0, new ModelResourceLocation(loc, path[0] + "_y"));
ModelLoader.setCustomStateMapper(block.getBlock(), new StateMapperBase() {
@Override
public ModelResourceLocation getModelResourceLocation(IBlockState state) {
String axis = "bark";
int meta = ((BlockLog) block.getBlock()).getMetaFromState(state);
if (meta == 0) {
axis = "y";
} else if (meta == 4) {
axis = "x";
} else if (meta == 8) {
axis = "z";
}
return new ModelResourceLocation(loc, path[0] + "_" + axis);
}
});
} else if (block.getBlock() instanceof BlockFluidCustom) {
ModelLoader.setCustomModelResourceLocation(block, 0, new ModelResourceLocation(block.getRegistryName(), "normal"));
ModelLoader.setCustomStateMapper(block.getBlock(), new StateMapperBase() {
@Override
public ModelResourceLocation getModelResourceLocation(IBlockState state) {
return new ModelResourceLocation(block.getRegistryName(), "normal");
}
});
} else
ModelLoader.setCustomModelResourceLocation(block, 0, new ModelResourceLocation(block.getRegistryName(), "inventory"));
}
for (Item item : Resources.items) {
if (item instanceof IItemMeta) {
for (int i = 0; i < ((IItemMeta) item).getNames().length; i++) {
ModelLoader.setCustomModelResourceLocation(item, i, new ModelResourceLocation(item.getRegistryName(), "type=" + ((IItemMeta) item).getNames()[i]));
}
} else if (item instanceof ItemTool || item instanceof ItemSword || item instanceof ItemCustomArmor) {
String[] path = item.getRegistryName().getResourcePath().split("_");
ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(new ResourceLocation(item.getRegistryName().getResourceDomain(), "tool_" + path[1]), path[0]));
} else if (item instanceof ItemSpell) {
ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(new ResourceLocation(item.getRegistryName().getResourceDomain(), "spell"), ((ItemSpell) item).getName()));
} else if (item instanceof ItemScroll) {
ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(new ResourceLocation(item.getRegistryName().getResourceDomain(), "spell_scroll"), ((ItemScroll) item).getName()));
} else if (item instanceof ItemConcoctionFlask) {
ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(new ResourceLocation(item.getRegistryName().getResourceDomain(), "concoction_flask_filled"), "inventory"));
} else
ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory"));
}
// register special item renderers here
Resources.saltedFood.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
Resources.grinder.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
Resources.mobHeadRevenant.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
Resources.mobHeadArachne.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
Resources.mobHeadArachneDrone.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
Resources.mobHeadMyrmeke.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
Resources.mobHeadCerver.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
Resources.mobHeadArganHound.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
Resources.mobHeadForesthagPlane.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
Resources.mobHeadForesthagPopulus.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
Resources.mobHeadForesthagCypress.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
Resources.mobHeadForesthagFir.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
Resources.mobHeadForesthagOlive.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
Resources.mobHeadForesthagLaurel.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
Resources.mobHeadForesthagDroughtroot.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
Resources.mobHeadAeternae.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
Resources.mobHeadCatoblepas.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
Resources.mobHeadSow.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
for (ItemScroll scroll : Resources.scrolls) scroll.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
}
use of net.minecraft.item.ItemSword in project Lands-of-Icaria by Axanthic-Game-Studios.
the class CommonProxy method onToolBreaksMainhand.
public void onToolBreaksMainhand(PlayerInteractEvent event) {
EntityPlayer player = event.getEntityPlayer();
for (int slot = 0; slot < 9; slot++) {
ItemStack totem = player.inventory.getStackInSlot(slot);
if (totem.getItem().equals(Resources.totem_unshattering)) {
ItemStack tools = player.getHeldItemMainhand();
if (tools.getItem() instanceof ItemTool || tools.getItem() instanceof ItemHoe || tools.getItem() instanceof ItemSword || tools.getItem() instanceof ItemBow || tools.getItem() instanceof ItemFishingRod || tools.getItem() instanceof ItemFlintAndSteel || tools.getItem() instanceof ItemShears || tools.getItem() instanceof ItemShield) {
if (tools.getItem().getMaxDamage(tools) - tools.getItem().getDamage(tools) < tools.getItem().getMaxDamage(tools) * 0.1) {
tools.setItemDamage((int) (tools.getItem().getMaxDamage(tools) * 0.1));
totem.shrink(1);
}
}
}
}
ItemStack totem = player.inventory.getStackInSlot(40);
if (totem.getItem().equals(Resources.totem_unshattering)) {
ItemStack tools = player.getHeldItemMainhand();
if (tools.getItem() instanceof ItemTool || tools.getItem() instanceof ItemHoe || tools.getItem() instanceof ItemSword || tools.getItem() instanceof ItemBow || tools.getItem() instanceof ItemFishingRod || tools.getItem() instanceof ItemFlintAndSteel || tools.getItem() instanceof ItemShears || tools.getItem() instanceof ItemShield) {
if (tools.getItem().getMaxDamage(tools) - tools.getItem().getDamage(tools) < tools.getItem().getMaxDamage(tools) * 0.1) {
tools.setItemDamage((int) (tools.getItem().getMaxDamage(tools) * 0.1));
totem.shrink(1);
}
}
}
}
Aggregations