Allow Music Discs to be created with SoundEvent delegates. (#6523)

This commit is contained in:
TheSilkMiner 2020-05-15 19:38:19 +02:00 committed by GitHub
parent 7fa42ca064
commit 765da1aca8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 164 additions and 3 deletions

View File

@ -85,7 +85,38 @@
if (this.field_72777_q.field_71441_e.field_73011_w.func_186058_p() == DimensionType.field_223229_c_) {
this.func_228444_b_(p_228424_1_);
} else if (this.field_72777_q.field_71441_e.field_73011_w.func_76569_d()) {
@@ -2283,8 +2298,8 @@
@@ -1977,7 +1992,12 @@
this.field_175008_n.func_217628_a(p_215319_1_, p_215319_2_, p_215319_3_, p_215319_4_);
}
+ @Deprecated // Forge: use item aware function below
public void func_184377_a(@Nullable SoundEvent p_184377_1_, BlockPos p_184377_2_) {
+ this.playRecord(p_184377_1_, p_184377_2_, p_184377_1_ == null? null : MusicDiscItem.func_185074_a(p_184377_1_));
+ }
+
+ public void playRecord(@Nullable SoundEvent p_184377_1_, BlockPos p_184377_2_, @Nullable MusicDiscItem musicDiscItem) {
ISound isound = this.field_147593_P.get(p_184377_2_);
if (isound != null) {
this.field_72777_q.func_147118_V().func_147683_b(isound);
@@ -1985,7 +2005,7 @@
}
if (p_184377_1_ != null) {
- MusicDiscItem musicdiscitem = MusicDiscItem.func_185074_a(p_184377_1_);
+ MusicDiscItem musicdiscitem = musicDiscItem;
if (musicdiscitem != null) {
this.field_72777_q.field_71456_v.func_73833_a(musicdiscitem.func_200299_h().func_150254_d());
}
@@ -2133,7 +2153,7 @@
break;
case 1010:
if (Item.func_150899_d(p_180439_4_) instanceof MusicDiscItem) {
- this.func_184377_a(((MusicDiscItem)Item.func_150899_d(p_180439_4_)).func_185075_h(), p_180439_3_);
+ this.playRecord(((MusicDiscItem)Item.func_150899_d(p_180439_4_)).func_185075_h(), p_180439_3_, (MusicDiscItem) Item.func_150899_d(p_180439_4_));
} else {
this.func_184377_a((SoundEvent)null, p_180439_3_);
}
@@ -2283,8 +2303,8 @@
break;
case 2001:
BlockState blockstate = Block.func_196257_b(p_180439_4_);
@ -96,7 +127,7 @@
this.field_72769_h.func_184156_a(p_180439_3_, soundtype.func_185845_c(), SoundCategory.BLOCKS, (soundtype.func_185843_a() + 1.0F) / 2.0F, soundtype.func_185847_b() * 0.8F, false);
}
@@ -2432,7 +2447,7 @@
@@ -2432,7 +2452,7 @@
} else {
int i = p_228420_0_.func_226658_a_(LightType.SKY, p_228420_2_);
int j = p_228420_0_.func_226658_a_(LightType.BLOCK, p_228420_2_);
@ -105,7 +136,7 @@
if (j < k) {
j = k;
}
@@ -2445,6 +2460,11 @@
@@ -2445,6 +2465,11 @@
return this.field_175015_z;
}

View File

@ -0,0 +1,51 @@
--- a/net/minecraft/item/MusicDiscItem.java
+++ b/net/minecraft/item/MusicDiscItem.java
@@ -21,17 +21,40 @@
import net.minecraftforge.api.distmarker.OnlyIn;
public class MusicDiscItem extends Item {
+ @Deprecated // Forge: refer to WorldRender#playRecord. Modders: there's no need to reflectively modify this map!
private static final Map<SoundEvent, MusicDiscItem> field_150928_b = Maps.newHashMap();
private final int field_195977_c;
+ @Deprecated // Forge: refer to soundSupplier
private final SoundEvent field_185076_b;
+ private final java.util.function.Supplier<SoundEvent> soundSupplier;
+ @Deprecated // Forge: Use the constructor that takes a supplier instead
protected MusicDiscItem(int p_i48475_1_, SoundEvent p_i48475_2_, Item.Properties p_i48475_3_) {
super(p_i48475_3_);
this.field_195977_c = p_i48475_1_;
this.field_185076_b = p_i48475_2_;
field_150928_b.put(this.field_185076_b, this);
+ this.soundSupplier = this.field_185076_b.delegate;
}
+ /**
+ * For mod use, allows to create a music disc without having to create a new
+ * SoundEvent before their registry event is fired.
+ *
+ * @param comparatorValue The value this music disc should output on the comparator. Must be between 0 and 15.
+ * @param soundSupplier A supplier that provides the sound that should be played. Use a
+ * {@link net.minecraftforge.fml.RegistryObject}{@code <SoundEvent>} or a
+ * {@link net.minecraftforge.registries.IRegistryDelegate} for this parameter.
+ * @param builder A set of {@link Item.Properties} that describe this item.
+ */
+ public MusicDiscItem(int comparatorValue, java.util.function.Supplier<SoundEvent> soundSupplier, Item.Properties builder)
+ {
+ super(builder);
+ this.field_195977_c = comparatorValue;
+ this.field_185076_b = null;
+ this.soundSupplier = soundSupplier;
+ }
+
public ActionResultType func_195939_a(ItemUseContext p_195939_1_) {
World world = p_195939_1_.func_195991_k();
BlockPos blockpos = p_195939_1_.func_195995_a();
@@ -76,6 +99,6 @@
@OnlyIn(Dist.CLIENT)
public SoundEvent func_185075_h() {
- return this.field_185076_b;
+ return this.soundSupplier.get();
}
}

View File

@ -23,6 +23,8 @@ net/minecraft/client/renderer/chunk/ChunkRenderDispatcher$ChunkRender$SortTransp
net/minecraft/client/renderer/entity/layers/ArmorLayer.renderArmor(Lcom/mojang/blaze3d/matrix/MatrixStack;Lnet/minecraft/client/renderer/IRenderTypeBuffer;IZLnet/minecraft/client/renderer/entity/model/BipedModel;FFFLnet/minecraft/util/ResourceLocation;)V=|p_229128_1_,p_229128_2_,p_229128_3_,p_229128_5_,p_229128_6_,p_229128_8_,p_229128_9_,p_229128_10_,armorResource
net/minecraft/client/renderer/WorldRenderer.playRecord(Lnet/minecraft/util/SoundEvent;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/item/MusicDiscItem;)V=|p_184377_1_,p_184377_2_,musicDiscItem
net/minecraft/client/renderer/model/BakedQuad.<init>([IILnet/minecraft/util/Direction;Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;Z)V=|p_i46574_1_,p_i46574_2_,p_i46574_3_,p_i46574_4_,applyDiffuseLighting
net/minecraft/client/renderer/model/BlockModel.bake(Lnet/minecraft/client/renderer/model/ModelBakery;Lnet/minecraft/client/renderer/model/BlockModel;Ljava/util/function/Function;Lnet/minecraft/client/renderer/texture/IModelTransform;Lnet/minecraft/client/renderer/vertex/VertexFormat;)Lnet/minecraft/client/renderer/model/IBakedModel;=|p_217644_1_,p_217644_2_,p_217644_3_,p_217644_4_,format
net/minecraft/client/renderer/model/BlockModel.bakeVanilla(Lnet/minecraft/client/renderer/model/ModelBakery;Lnet/minecraft/client/renderer/model/BlockModel;Ljava/util/function/Function;Lnet/minecraft/client/renderer/model/IModelTransform;Lnet/minecraft/util/ResourceLocation;Z)Lnet/minecraft/client/renderer/model/IBakedModel;=|p_228813_1_,p_228813_2_,p_228813_3_,p_228813_4_,p_228813_5_,p_228813_6_

View File

@ -0,0 +1,55 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2019.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.debug.item;
import net.minecraft.item.Item;
import net.minecraft.item.MusicDiscItem;
import net.minecraft.item.Rarity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
@Mod(MusicDiscTest.MOD_ID)
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, modid = MusicDiscTest.MOD_ID)
public class MusicDiscTest
{
static final String MOD_ID = "music_disc_test";
private static final DeferredRegister<Item> ITEMS = new DeferredRegister<>(ForgeRegistries.ITEMS, MOD_ID);
private static final DeferredRegister<SoundEvent> SOUND_EVENTS = new DeferredRegister<>(ForgeRegistries.SOUND_EVENTS, MOD_ID);
private static final RegistryObject<SoundEvent> TEST_SOUND_EVENT = SOUND_EVENTS.register("test_sound_event",
() -> new SoundEvent(new ResourceLocation(MOD_ID, "test_sound_event")));
private static final RegistryObject<Item> TEST_MUSIC_DISC = ITEMS.register("test_music_disc",
() -> new MusicDiscItem(1, TEST_SOUND_EVENT, new Item.Properties().maxStackSize(1).rarity(Rarity.EPIC)));
public MusicDiscTest()
{
final IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus();
ITEMS.register(modBus);
SOUND_EVENTS.register(modBus);
}
}

View File

@ -67,6 +67,8 @@ loaderVersion="[28,)"
modId="chunk_data_event_save_null_world_test"
[[mods]]
modId="composite_model_test"
[[mods]]
modId="music_disc_test"
[[dependencies.global_loot_test]]
modId="forge"
mandatory=true

View File

@ -0,0 +1,4 @@
{
"item.music_disc_test.test_music_disc": "Music Disc",
"item.music_disc_test.test_music_disc.desc": "Nuance 2 Ambient Music"
}

View File

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "item/music_disc_13"
}
}

View File

@ -0,0 +1,10 @@
{
"test_sound_event": {
"sounds": [
{
"name": "minecraft:music/game/nuance2",
"stream": true
}
]
}
}