public void playRecord(String recordName, BlockPos blockPosIn) { ISound isound = (ISound)this.mapSoundPositions.get(blockPosIn); if (isound != null) { this.mc.getSoundHandler().stopSound(isound); this.mapSoundPositions.remove(blockPosIn); } if (recordName != null) { ItemRecord itemrecord = ItemRecord.getRecord(recordName); if (itemrecord != null) { this.mc.ingameGUI.setRecordPlayingMessage(itemrecord.getRecordNameLocal()); } PositionedSoundRecord positionedsoundrecord = PositionedSoundRecord.create(new ResourceLocation(recordName), (float)blockPosIn.getX(), (float)blockPosIn.getY(), (float)blockPosIn.getZ()); this.mapSoundPositions.put(blockPosIn, positionedsoundrecord); this.mc.getSoundHandler().playSound(positionedsoundrecord); } }
public void playRecord(@Nullable SoundEvent soundIn, BlockPos pos) { ISound isound = (ISound)this.mapSoundPositions.get(pos); if (isound != null) { this.mc.getSoundHandler().stopSound(isound); this.mapSoundPositions.remove(pos); } if (soundIn != null) { ItemRecord itemrecord = ItemRecord.getBySound(soundIn); if (itemrecord != null) { this.mc.ingameGUI.setRecordPlayingMessage(itemrecord.getRecordNameLocal()); } PositionedSoundRecord positionedsoundrecord = PositionedSoundRecord.getRecordSoundRecord(soundIn, (float)pos.getX(), (float)pos.getY(), (float)pos.getZ()); this.mapSoundPositions.put(pos, positionedsoundrecord); this.mc.getSoundHandler().playSound(positionedsoundrecord); } }
@Override public void update() { World world = entity.getWorld(); if(!world.isRemote && entity.ticksExisted()==Refs.TPS*5){ //grab the list of records Map<String,ItemRecord> recordMap = ReflectionHelper.getPrivateValue(ItemRecord.class, (ItemRecord)Items.RECORD_13, "RECORDS","field_150928_b");//XXX recheck name when update Collection<ItemRecord> records = recordMap.values(); //select a random number Random rand = new Random(); int idx = rand.nextInt(records.size()); //grab the record that matches our random number Iterator<ItemRecord> it = records.iterator(); ItemRecord current=it.next(); for(int i=1;i<idx;i++){ current = it.next(); } //spawn the record Utils.spawnItemCentered(world, getPos(), new ItemStack(current)); //world.playSoundEffect(getPos().getX(), getPos().getY(), getPos().getZ(), "mob.chicken.plop", 0.5F, 0.8F + (world.rand.nextFloat() - world.rand.nextFloat())); world.playSound(null,getPos().getX(), getPos().getY(), getPos().getZ(), SoundEvents.ENTITY_CHICKEN_EGG, SoundCategory.BLOCKS, 0.5F, 0.8F + (world.rand.nextFloat() - world.rand.nextFloat())); this.onPatternBroken();//deactivate } }
/** * Plays the specified record. Arg: recordName, x, y, z */ public void playRecord(String par1Str, int par2, int par3, int par4) { ChunkCoordinates var5 = new ChunkCoordinates(par2, par3, par4); ISound var6 = (ISound)this.mapSoundPositions.get(var5); if (var6 != null) { this.mc.getSoundHandler().func_147683_b(var6); this.mapSoundPositions.remove(var5); } if (par1Str != null) { ItemRecord var7 = ItemRecord.func_150926_b(par1Str); if (var7 != null) { this.mc.ingameGUI.setRecordPlayingMessage(var7.func_150927_i()); } PositionedSoundRecord var8 = PositionedSoundRecord.func_147675_a(new ResourceLocation(par1Str), (float)par2, (float)par3, (float)par4); this.mapSoundPositions.put(var5, var8); this.mc.getSoundHandler().playSound(var8); } }
@Nullable public static String getIdentifierForRecord(ItemRecord record, int x, int y, int z) { ResourceLocation resource = record.getRecordResource("records." + record.recordName); // if (resource == null) return null; SoundEventAccessorComposite sound = getSoundHandler().getSound(resource); float f1 = 16F; if (sound == null) { return null; } SoundPoolEntry soundpoolentry = sound.cloneEntry(); SoundCategory soundcategory = sound.getSoundCategory(); float volume = (float) MathHelper.clamp_double((double) f1 * soundpoolentry.getVolume() * (double) mc().gameSettings.getSoundLevel(soundcategory), 0.0D, MAX_VOLUME); float pitch = (float) MathHelper.clamp_double((double) f1 * soundpoolentry.getVolume() * (double) mc().gameSettings.getSoundLevel(soundcategory), 0.0D, 1.0D); // ResourceLocation resourcelocation = soundpoolentry.getSoundPoolEntryLocation(); // I know the type. //noinspection unchecked HashBiMap<String, ISound> playingSounds = (HashBiMap<String, ISound>) getSoundManager().playingSounds; BiMap<ISound, String> inverse = playingSounds.inverse(); return inverse.get(new CustomSound(volume, resource, false, 0, pitch, x, y, z)); }
@Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float px, float py, float pz) { boolean ejected = super.onBlockActivated(world, x, y, z, player, side, px, py, pz); if (!ejected && player != null && player.getHeldItem() != null && (player.getHeldItem().getItem() instanceof ItemRecord)) { ItemStack held = player.getHeldItem(); this.func_149926_b(world, x, y, z, held); world.playAuxSFXAtEntity((EntityPlayer)null, 1005, x, y, z, Item.getIdFromItem(held.getItem())); --held.stackSize; return true; } return false; }
@SubscribeEvent(priority = EventPriority.LOWEST) public void onLivingDrop(LivingDropsEvent event) { if (event.entityLiving instanceof EntityCreeper) { boolean foundRecord = false; Iterator<EntityItem> iter = event.drops.iterator(); while (iter.hasNext()) { EntityItem e = iter.next(); if (e.getEntityItem().getItem() instanceof ItemRecord) { foundRecord = true; } } if (foundRecord) { addRandomRecordToDrops(event.drops); } } }
@Override public ItemStack attached(ItemStack i, Random rand, int[] eff) { ArrayList<ItemRecord> recordList = new ArrayList<ItemRecord>(); //Fill record list with everything considered a record (vanilla or modded). Iterator<Item> it = Item.itemRegistry.iterator(); while(it.hasNext()) { Item item = it.next(); if(item instanceof ItemRecord) { recordList.add((ItemRecord)item); } } //If records were found (and there should always be some!), choose one randomly. if(recordList.size() > 0) { String record = recordList.get(rand.nextInt(recordList.size())).recordName; i.getTagCompound().setString("record", record); } else { System.out.println("No records?!?"); } return i; }
public static void init(Item item) { if (item instanceof ItemRecord) { String key = Tool.<String>$(item, "displayName"); miscMap.put(key, getName(key, 1)); } else if (!(item instanceof ItemBlock)) itemMap.put(item.getUnlocalizedName() + ".name", getName(item.getUnlocalizedName())); }
@Override public boolean isItemValidForSlot( int slot, ItemStack stack ) { if ( stack == null ) { return true; } return ( stack.getItem() instanceof ItemRecord ); }
@Override public IMessage onMessage(ServerPlayRecord message, MessageContext ctx) { TileJukebox jukebox = Util.getTileEntity(ClientUtil.mc().thePlayer.worldObj, message.x, message.y, message.z, TileJukebox.class); if (jukebox == null) { //TODO: log; return null; } if (jukebox.getStackInSlot(message.slot) == null) return null; jukebox.setPlaying(true); SoundSystemHelper.playRecord((ItemRecord) jukebox.getStackInSlot(message.slot).getItem(), message.x, message.y, message.z, jukebox.getIdentifier()); return null; }
public void playSelectedRecord() { if (getStackInSlot(recordNumber) == null) return; if (worldObj.isRemote) { PacketHandler.INSTANCE.sendToServer(new ClientPlayRecord(this)); return; } lastPlayingRecord = ((ItemRecord) getStackInSlot(recordNumber).getItem()).recordName; playing = true; waitTicks = 20; PacketHandler.INSTANCE.sendToAll(new ServerPlayRecord(this)); }
public void playRecord(String p_72702_1_, int p_72702_2_, int p_72702_3_, int p_72702_4_) { ChunkCoordinates chunkcoordinates = new ChunkCoordinates(p_72702_2_, p_72702_3_, p_72702_4_); ISound isound = (ISound)this.mapSoundPositions.get(chunkcoordinates); if (isound != null) { this.mc.getSoundHandler().stopSound(isound); this.mapSoundPositions.remove(chunkcoordinates); } if (p_72702_1_ != null) { ItemRecord itemrecord = ItemRecord.getRecord(p_72702_1_); ResourceLocation resource = null; if (itemrecord != null) { this.mc.ingameGUI.setRecordPlayingMessage(itemrecord.getRecordNameLocal()); resource = itemrecord.getRecordResource(p_72702_1_); } if (resource == null) resource = new ResourceLocation(p_72702_1_); PositionedSoundRecord positionedsoundrecord = PositionedSoundRecord.func_147675_a(resource, (float)p_72702_2_, (float)p_72702_3_, (float)p_72702_4_); this.mapSoundPositions.put(chunkcoordinates, positionedsoundrecord); this.mc.getSoundHandler().playSound(positionedsoundrecord); } }
@SubscribeEvent public void onTooltip(ItemTooltipEvent event) { if (event.itemStack.getItem() instanceof INBTDamageItem) { INBTDamageItem nitem = (INBTDamageItem)(event.itemStack.getItem()); boolean show = Minecraft.getMinecraft().gameSettings.advancedItemTooltips; if (show && nitem.getNBTDamage(event.itemStack) > 0) { event.toolTip.add("Durability: " + (nitem.getNBTMaxDamage(event.itemStack) - event.itemStack.getItemDamageForDisplay()) + " / " + nitem.getNBTMaxDamage(event.itemStack)); } } if (event.itemStack.stackTagCompound != null){ if (event.itemStack.stackTagCompound.hasKey(PhysisArtifacts.SOCKETEDTAG)) { int index = -1; for(int i=0; i<event.toolTip.size(); i++) { if (event.toolTip.get(i).isEmpty()) { index = i; } } if (index != -1) { addSocketTooltip(event.entityPlayer, event.itemStack, event.toolTip, index); } else { addSocketTooltip(event.entityPlayer, event.itemStack, event.toolTip, event.toolTip.size()); } } if (event.itemStack.stackTagCompound.hasKey(PhysisArtifacts.ARTIFACTTAG)) { List<String> content = Physis.text.translateAndWrap(this.getTooltipForSocketable(event.itemStack), tipWidth); event.toolTip.addAll(content); } } else if (event.itemStack.getItem() instanceof ItemRecord) { ItemStack held = event.entityPlayer.getHeldItem(); if (held != null && held.getItem() == PhysisItems.addsocket) { addRecordTooltip(event.itemStack, event.toolTip, event.toolTip.size()); } } }
public void func_72702_a(String p_72702_1_, int p_72702_2_, int p_72702_3_, int p_72702_4_) { ItemRecord var5 = ItemRecord.func_90042_d(p_72702_1_); if(p_72702_1_ != null && var5 != null) { this.field_72777_q.field_71456_v.func_73833_a(var5.func_90043_g()); } this.field_72777_q.field_71416_A.func_77368_a(p_72702_1_, (float)p_72702_2_, (float)p_72702_3_, (float)p_72702_4_); }
/** * Plays the specified record. Arg: recordName, x, y, z */ public void playRecord(String par1Str, int par2, int par3, int par4) { ItemRecord itemrecord = ItemRecord.getRecord(par1Str); if (par1Str != null && itemrecord != null) { this.mc.ingameGUI.setRecordPlayingMessage(itemrecord.getRecordTitle()); } this.mc.sndManager.playStreaming(par1Str, (float)par2, (float)par3, (float)par4); }
private void addRandomRecordToDrops(ArrayList<EntityItem> drops) { ArrayList<EntityItem> temp = new ArrayList<EntityItem>(); temp.addAll(drops); drops.clear(); for (EntityItem item : temp) { if (item.getEntityItem().getItem() instanceof ItemRecord) { int max = 12 + RecordType.getLootRecordCount(); int random = rand.nextInt(max); ItemStack record; if (random < 12) { int id = Item.getIdFromItem(Items.record_13) + random; record = new ItemStack(Item.getItemById(id)); } else { random -= 12; record = getDroppableRecord(random); } EntityItem entity = new EntityItem(item.worldObj, item.posX, item.posY, item.posZ, record); drops.add(entity); } else { drops.add(item); } } }
@Override public void addInformation(ItemStack itemStack, EntityPlayer player, List list, String trigger, boolean advTooltip) { String play = StatCollector.translateToLocal("effect.Play"); if(play.equals("{Play}")) play = "" + EnumChatFormatting.GREEN + ((char) 0x266A) + EnumChatFormatting.LIGHT_PURPLE + ((char) 0x266B) + EnumChatFormatting.GOLD + ((char) 0x266A); //Get the localized record description String recordDescription = "Unknown"; ItemRecord record = ItemRecord.getRecord("records."+itemStack.getTagCompound().getString("record")); if(record != null) { //If the record was from a mod that is no longer loaded, the description will stay "Unknown" recordDescription = record.getRecordNameLocal(); } list.add(StatCollector.translateToLocal("effect.Plays the record") + " " + recordDescription + " " + StatCollector.translateToLocal("tool." + trigger) + " " + (itemStack.getTagCompound().getBoolean("playing") ? play : "")); }
/** * play a record at the specific location * * @param record the record name * @param x the x pos * @param y the y pos * @param z the z pos */ public static void playRecord(ItemRecord record, int x, int y, int z, String identifier) { ResourceLocation resource; if (record == null) { stop(identifier); return; } mc().ingameGUI.setRecordPlayingMessage(record.getRecordNameLocal()); resource = record.getRecordResource("records." + record.recordName); // if (resource == null) return; if (getSoundSystem().playing(identifier)) getSoundSystem().stop(identifier); SoundEventAccessorComposite sound = getSoundHandler().getSound(resource); float f1 = 16F; if (sound == null) { return; } SoundPoolEntry soundpoolentry = sound.cloneEntry(); SoundCategory soundcategory = sound.getSoundCategory(); float volume = (float) MathHelper.clamp_double((double) f1 * soundpoolentry.getVolume() * (double) mc().gameSettings.getSoundLevel(soundcategory), 0.0D, MAX_VOLUME); float pitch = (float) MathHelper.clamp_double((double) f1 * soundpoolentry.getVolume() * (double) mc().gameSettings.getSoundLevel(soundcategory), 0.0D, 1.0D); //noinspection unchecked CustomSound customSound = new CustomSound(volume, resource, false, 0, pitch, x, y, z); //Do not break the game if (getSoundManager().delayedSounds.containsKey(customSound)) { getSoundManager().delayedSounds.remove(customSound); // do not break the game, just trod along all twe want. } if (getSoundManager().playingSounds.containsValue(customSound)) { return; // do not break the game } getSoundManager().playDelayedSound(customSound, 1); }
/** * Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot. */ @Override public boolean isItemValidForSlot(int i, ItemStack itemstack) { return itemstack.getItem() instanceof ItemRecord; }
public String getIdentifier() { if (getStackInSlot(getCurrentRecordNumber()) == null) return ""; return SoundSystemHelper.getIdentifierForRecord(((ItemRecord) getStackInSlot(getCurrentRecordNumber()).getItem()), pos.getX(), pos.getY(), pos.getZ()); }
@Override public boolean isItemValid(ItemStack item) { return (item.getItem() instanceof ItemRecord); }
@Override protected boolean mergeItemStack(ItemStack par1ItemStack, int par2, int par3, boolean par4) { return par1ItemStack.getItem() instanceof ItemRecord && super.mergeItemStack(par1ItemStack, par2, par3, par4); }
@SuppressWarnings("unchecked") public void addSocketTooltip(EntityPlayer player, ItemStack stack, List<String> lines, int index) { NBTTagCompound[] sockets = PhysisArtifacts.getSocketablesFromStack(stack); lines.add(index, ""); index++; int totaloffset = 0; int postoffset = 0; for (int i=0; i<sockets.length; i++) { int offset = totaloffset + i; if (sockets[i] != null) { ItemStack socketed = ItemStack.loadItemStackFromNBT(sockets[i]); List<String> stt = socketed.getTooltip(player, false); String format = socketed.getItem().getRarity(socketed).rarityColor.toString(); int socketColour = 3; if (socketed.getItem() instanceof ISocketable) { socketColour = ((ISocketable)socketed.getItem()).getSocketColour(socketed); } socketColour = Math.max(Math.min(15, socketColour), 0); postoffset++; if (InputHelper.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindSneak.getKeyCode())) { for(int j=0; j<stt.size(); j++) { if (j == 0) { stt.set(j, " \u00A7"+socketColour+"\u25a0\u00A7r "+format+stt.get(j)); } else { stt.set(j, " "+stt.get(j)); } } lines.addAll(index+offset, stt); totaloffset += stt.size() - 1; } else { String name = socketed.getDisplayName(); lines.add(index+offset, " \u00A7"+socketColour+"\u25a0\u00A7r "+format+name+ (stt.size() > 1 ? " \u00A78+" : "")); } } else { lines.add(index+offset, " \u00A78\u25a0 Empty socket"); } } if (stack.getItem() instanceof ItemRecord) { addRecordTooltip(stack, lines, index+totaloffset+postoffset); } }