Make FlowerPotBlock extensible and reusable for mods

- Change static lookup map to an instance variable
- Add an instance variable for the "empty pot" for the current block
- Keep one instance of the lookup map between the empty pot and all its full versions
- Convert everything to use delegates
This commit is contained in:
tterrag committed 2019-09-17 19:57:58 -04:00
1 parent af8074cc39
commit 6fda1e968d
8 files changed
+160 -5

No files matched your search

+1 -1
View File
@@ -1,5 +1,5 @@
net/minecraft/block/FireBlock.tryCatchFire(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;ILjava/util/Random;ILnet/minecraft/util/Direction;)V=|p_176536_1_,p_176536_2_,p_176536_3_,p_176536_4_,p_176536_5_,face
net/minecraft/block/FlowerPotBlock.<init>(Lnet/minecraft/block/FlowerPotBlock;Lnet/minecraft/block/Block;Lnet/minecraft/block/Block$Properties;)V=|emptyPot,p_i48395_1_,p_i48395_2_
net/minecraft/block/RedstoneWireBlock.canConnectTo(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/IBlockReader;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/Direction;)Z=|p_176343_0_,world,pos,p_176343_1_
net/minecraft/block/PoweredRailBlock.<init>(Lnet/minecraft/block/Block$Properties;Z)=|p_i48349_1_,isActivator
@@ -0,0 +1,59 @@
/*
* 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.block;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.FlowerPotBlock;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
import net.minecraftforge.registries.ObjectHolder;
@Mod(FlowerPotTest.MODID)
@Mod.EventBusSubscriber(bus = Bus.MOD)
public class FlowerPotTest
{
static final String MODID = "flower_pot_test";
static final String BLOCK_ID = "test_flower_pot";
@ObjectHolder(BLOCK_ID)
public static FlowerPotBlock EMPTY_FLOWER_POT;
@ObjectHolder(BLOCK_ID)
public static FlowerPotBlock OAK_FLOWER_POT;
@SubscribeEvent
public static void registerBlocks(RegistryEvent.Register<Block> event)
{
FlowerPotBlock empty = new FlowerPotBlock(null, Blocks.AIR, Block.Properties.from(Blocks.FLOWER_POT));
event.getRegistry().register(empty.setRegistryName(BLOCK_ID));
event.getRegistry().register(new FlowerPotBlock(empty, Blocks.OAK_SAPLING, Block.Properties.from(empty)).setRegistryName(BLOCK_ID + "_oak"));
}
@SubscribeEvent
public static void registerItems(RegistryEvent.Register<Item> event)
{
event.getRegistry().register(new BlockItem(EMPTY_FLOWER_POT, new Item.Properties()).setRegistryName(MODID, BLOCK_ID));
}
}
@@ -27,10 +27,11 @@ import net.minecraft.item.Item;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
import net.minecraftforge.registries.ObjectHolder;
@Mod(StickyBlockTest.MODID)
@Mod.EventBusSubscriber
@Mod.EventBusSubscriber(bus = Bus.MOD)
public class StickyBlockTest
{
static final String MODID = "custom_slime_block_test";
+2
View File
@@ -51,3 +51,5 @@ loaderVersion="[28,)"
modId="data_gen_test"
[[mods]]
modId="piston_event_test"
[[mods]]
modId="flower_pot_test"
@@ -0,0 +1,5 @@
{
"variants": {
"": { "model": "block/flower_pot" }
}
}
@@ -0,0 +1,5 @@
{
"variants": {
"": { "model": "block/potted_oak_sapling" }
}
}
@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "item/flower_pot"
}
}