mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-13 00:37:52 +00:00
Fix some compile errors in test classes.
This commit is contained in:
1 parent
40bdde2043
commit
f01b87fac7
22 files changed
+327
-679
No files matched your search
@@ -19,70 +19,48 @@
|
||||
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.living.PotionEvent;
|
||||
import net.minecraftforge.eventbus.api.Event.Result;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event.Result;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
//@Mod(modid = "potioneventtest", name = "PotionEventTest", version = "1.0.0", acceptableRemoteVersions = "*")
|
||||
@Mod("potion_event_test")
|
||||
@Mod.EventBusSubscriber
|
||||
public class PotionEventTest
|
||||
{
|
||||
public static final boolean ENABLE = false;
|
||||
private Logger log;
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
log = event.getModLog();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent event)
|
||||
{
|
||||
if (ENABLE)
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
private static Logger LOGGER = LogManager.getLogger(PotionEventTest.class);
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPotionAdded(PotionEvent.PotionAddedEvent event)
|
||||
public static void onPotionAdded(PotionEvent.PotionAddedEvent event)
|
||||
{
|
||||
if (!event.getEntity().getEntityWorld().isRemote)
|
||||
{
|
||||
log.info("{} has a new PotionEffect {}, the old one was {}", event.getEntityLiving(), event.getPotionEffect(), event.getOldPotionEffect());
|
||||
}
|
||||
LOGGER.info("{} has a new PotionEffect {}, the old one was {}", event.getEntityLiving(), event.getPotionEffect(), event.getOldPotionEffect());
|
||||
}
|
||||
|
||||
|
||||
@SubscribeEvent
|
||||
public void isPotionApplicable(PotionEvent.PotionApplicableEvent event)
|
||||
public static void isPotionApplicable(PotionEvent.PotionApplicableEvent event)
|
||||
{
|
||||
if (!event.getEntity().getEntityWorld().isRemote)
|
||||
{
|
||||
event.setResult(Result.ALLOW);
|
||||
log.info("Allowed Potion {} for Entity {}", event.getPotionEffect(), event.getEntityLiving());
|
||||
LOGGER.info("Allowed Potion {} for Entity {}", event.getPotionEffect(), event.getEntityLiving());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPotionRemove(PotionEvent.PotionRemoveEvent event)
|
||||
public static void onPotionRemove(PotionEvent.PotionRemoveEvent event)
|
||||
{
|
||||
if (!event.getEntity().getEntityWorld().isRemote)
|
||||
{
|
||||
log.info("Effect {} got Removed from {}", event.getPotionEffect(), event.getEntityLiving());
|
||||
}
|
||||
LOGGER.info("Effect {} got Removed from {}", event.getPotionEffect(), event.getEntityLiving());
|
||||
}
|
||||
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPotionExpiry(PotionEvent.PotionExpiryEvent event)
|
||||
public static void onPotionExpiry(PotionEvent.PotionExpiryEvent event)
|
||||
{
|
||||
if (!event.getEntity().getEntityWorld().isRemote)
|
||||
{
|
||||
log.info("Effect {} expired from {}", event.getPotionEffect(), event.getEntityLiving());
|
||||
}
|
||||
LOGGER.info("Effect {} expired from {}", event.getPotionEffect(), event.getEntityLiving());
|
||||
}
|
||||
}
|
||||
@@ -19,28 +19,19 @@
|
||||
|
||||
package net.minecraftforge.debug.block;
|
||||
|
||||
import net.minecraft.entity.item.EntityFallingBlock;
|
||||
import net.minecraft.entity.item.FallingBlockEntity;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
//@Mod(modid = BasePlaceEventTest.MOD_ID, name = "BaseBlockPlaceEvent test mod", version = "1.0", acceptableRemoteVersions = "*")
|
||||
//@Mod.EventBusSubscriber
|
||||
@Mod("base_block_place_event_test")
|
||||
@Mod.EventBusSubscriber
|
||||
public class BasePlaceEventTest
|
||||
{
|
||||
static final String MOD_ID = "base_block_place_event_test";
|
||||
static final boolean ENABLED = true;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onBlockPlaced(BlockEvent.EntityPlaceEvent event)
|
||||
{
|
||||
if (!ENABLED)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getEntity() instanceof EntityFallingBlock) {
|
||||
if (event.getEntity() instanceof FallingBlockEntity)
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,27 +20,17 @@
|
||||
package net.minecraftforge.debug.block;
|
||||
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
//@Mod(modid = FarmlandTrampleEventTest.MOD_ID, name = "Farmland Trample Event Test", version = "1.0", acceptableRemoteVersions = "*")
|
||||
//@Mod.EventBusSubscriber
|
||||
@Mod("farmland_trample_test")
|
||||
@Mod.EventBusSubscriber
|
||||
public class FarmlandTrampleEventTest
|
||||
{
|
||||
static final String MOD_ID = "farmland_trample_test";
|
||||
static final boolean ENABLED = true;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onFarmlandTrampled(BlockEvent.FarmlandTrampleEvent event)
|
||||
{
|
||||
if (!ENABLED)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(event.getEntity().isSneaking())
|
||||
{
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,109 +20,113 @@
|
||||
package net.minecraftforge.debug.block;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.FarmlandWaterManager;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.ticket.AABBTicket;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.registries.ObjectHolder;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
//@Mod(modid = FarmlandWaterTest.ID, name = "Farmland Water Test", version = "1.0.0", acceptableRemoteVersions = "*")
|
||||
//This adds a block that creates a 4x4x4 watered region when activated
|
||||
@Mod(FarmlandWaterTest.MOD_ID)
|
||||
@Mod.EventBusSubscriber
|
||||
public class FarmlandWaterTest
|
||||
{
|
||||
//This adds a block that creates a 4x4x4 watered region when activated
|
||||
private static Logger logger;
|
||||
private static Block testBlock;
|
||||
static final String ID = "farmlandwatertest";
|
||||
static final String MOD_ID = "farmland_water_test";
|
||||
static final String BLOCK_ID = "test_block";
|
||||
static final String TILE_ID = "test_tile";
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
logger = event.getModLog();
|
||||
MinecraftForge.EVENT_BUS.register(FarmlandWaterTest.class);
|
||||
}
|
||||
private static Logger logger = LogManager.getLogger(FarmlandWaterTest.class);
|
||||
|
||||
@ObjectHolder(BLOCK_ID)
|
||||
public static final Block test_block = null;
|
||||
@ObjectHolder(TILE_ID)
|
||||
public static final TileEntityType<TestTileEntity> test_tile = null;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerBlocks(RegistryEvent.Register<Block> event)
|
||||
{
|
||||
testBlock = new TestBlock();
|
||||
event.getRegistry().register(testBlock.setRegistryName(new ResourceLocation(ID, "test_block")).setCreativeTab(CreativeTabs.MISC).setUnlocalizedName("Farmland Water Test Block"));
|
||||
GameRegistry.registerTileEntity(TestTileEntity.class, new ResourceLocation(ID, "test_te"));
|
||||
event.getRegistry().register(new TestBlock(Block.Properties.create(Material.ROCK)).setRegistryName(MOD_ID, BLOCK_ID));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerTileEntity(RegistryEvent.Register<TileEntityType<?>> event)
|
||||
{
|
||||
event.getRegistry().register(TileEntityType.Builder.func_223042_a(TestTileEntity::new, test_block).build(null).setRegistryName(MOD_ID, TILE_ID));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerItems(RegistryEvent.Register<Item> event)
|
||||
{
|
||||
event.getRegistry().register(new ItemBlock(testBlock).setRegistryName(new ResourceLocation(ID, "test_block")));
|
||||
event.getRegistry().register(new BlockItem(test_block, new Item.Properties()).setRegistryName(new ResourceLocation(MOD_ID, BLOCK_ID)));
|
||||
}
|
||||
|
||||
public static class TestBlock extends Block
|
||||
{
|
||||
|
||||
public TestBlock()
|
||||
public TestBlock(Block.Properties props)
|
||||
{
|
||||
super(Material.ROCK);
|
||||
super(props);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTileEntity(IBlockState state)
|
||||
public boolean hasTileEntity(BlockState state)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public TileEntity createTileEntity(World world, IBlockState state)
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world)
|
||||
{
|
||||
return new TestTileEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
public boolean onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult rayTrace)
|
||||
{
|
||||
if (world.isRemote)
|
||||
return true;
|
||||
TestTileEntity tileEntity = (TestTileEntity) world.getTileEntity(pos);
|
||||
if (tileEntity == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
tileEntity.isActive = !tileEntity.isActive;
|
||||
tileEntity.updateTicket();
|
||||
player.sendStatusMessage(new TextComponentString("Changed block powered state to " + tileEntity.isActive), true);
|
||||
logger.info("Changed block powered state at {} to {}", pos, tileEntity.isActive);
|
||||
return true;
|
||||
Optional<TestTileEntity> opt = getTE(world, pos);
|
||||
opt.ifPresent(tileEntity -> {
|
||||
tileEntity.isActive = !tileEntity.isActive;
|
||||
tileEntity.updateTicket();
|
||||
player.sendStatusMessage(new StringTextComponent("Changed block powered state to " + tileEntity.isActive), true);
|
||||
logger.info("Changed block powered state at {} to {}", pos, tileEntity.isActive);
|
||||
});
|
||||
return opt.isPresent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World world, BlockPos pos, IBlockState state)
|
||||
public void onReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean isMoving)
|
||||
{
|
||||
if (world.isRemote)
|
||||
return;
|
||||
TestTileEntity tileEntity = (TestTileEntity) world.getTileEntity(pos);
|
||||
if (tileEntity == null)
|
||||
return;
|
||||
tileEntity.farmlandTicket.invalidate();
|
||||
getTE(world, pos).ifPresent(TileEntity::remove);
|
||||
}
|
||||
|
||||
private Optional<TestTileEntity> getTE(World world, BlockPos pos)
|
||||
{
|
||||
if (world.isRemote) return Optional.empty();
|
||||
return Optional.ofNullable((TestTileEntity)world.getTileEntity(pos));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,6 +135,11 @@ public class FarmlandWaterTest
|
||||
private AABBTicket farmlandTicket;
|
||||
private boolean isActive = false;
|
||||
|
||||
public TestTileEntity()
|
||||
{
|
||||
super(FarmlandWaterTest.test_tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad()
|
||||
{
|
||||
@@ -146,32 +155,28 @@ public class FarmlandWaterTest
|
||||
if (world.isRemote)
|
||||
return;
|
||||
if (isActive)
|
||||
{
|
||||
farmlandTicket.validate();
|
||||
}
|
||||
else
|
||||
{
|
||||
farmlandTicket.invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound)
|
||||
public CompoundNBT write(CompoundNBT compound)
|
||||
{
|
||||
compound = super.writeToNBT(compound);
|
||||
compound.setBoolean("active", isActive);
|
||||
compound = super.write(compound);
|
||||
compound.putBoolean("active", isActive);
|
||||
return compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound compound)
|
||||
public void read(CompoundNBT compound)
|
||||
{
|
||||
super.readFromNBT(compound);
|
||||
super.read(compound);
|
||||
isActive = compound.getBoolean("active");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload()
|
||||
public void remove()
|
||||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
|
||||
@@ -21,14 +21,9 @@ package net.minecraftforge.debug.block;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
@@ -37,34 +32,28 @@ import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.ModelRegistryEvent;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.fluids.BlockFluidBase;
|
||||
import net.minecraftforge.fluids.BlockFluidClassic;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
import net.minecraftforge.fml.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.registries.ObjectHolder;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry.ObjectHolder;
|
||||
|
||||
//@EventBusSubscriber
|
||||
//@Mod(modid = MaterialFogColorTest.MODID, name = "FogColor inside material debug.", version = "1.0", acceptableRemoteVersions = "*")
|
||||
@Mod(MaterialFogColorTest.MODID)
|
||||
@Mod.EventBusSubscriber
|
||||
public class MaterialFogColorTest
|
||||
{
|
||||
static final boolean ENABLED = false; // <-- enable mod
|
||||
static int color = 0xFFd742f4; // <-- change value for testing
|
||||
|
||||
public static final String MODID = "fogcolorinsidematerialtest";
|
||||
static final String MODID = "fog_color_in_material_test";
|
||||
|
||||
/*
|
||||
static
|
||||
{
|
||||
if (ENABLED)
|
||||
{
|
||||
FluidRegistry.enableUniversalBucket();
|
||||
}
|
||||
FluidRegistry.enableUniversalBucket();
|
||||
}
|
||||
|
||||
static int color = 0xFFd742f4; // <-- change value for testing
|
||||
|
||||
public static final Fluid SLIME = new Fluid("slime", new ResourceLocation(MODID, "slime_still"), new ResourceLocation(MODID, "slime_flow"), new ResourceLocation(MODID, "slime_overlay")) {
|
||||
@Override
|
||||
public int getColor()
|
||||
@@ -73,8 +62,8 @@ public class MaterialFogColorTest
|
||||
}
|
||||
};
|
||||
|
||||
@ObjectHolder("slime")
|
||||
public static final BlockFluidBase SLIME_BLOCK = null;
|
||||
//@ObjectHolder("slime")
|
||||
//public static final BlockFluidBase SLIME_BLOCK = null;
|
||||
@ObjectHolder("test_fluid")
|
||||
public static final Block FLUID_BLOCK = null;
|
||||
@ObjectHolder("test_fluid")
|
||||
@@ -83,64 +72,53 @@ public class MaterialFogColorTest
|
||||
private static final ResourceLocation RES_LOC = new ResourceLocation(MODID, "slime");
|
||||
private static final ResourceLocation testFluidRegistryName = new ResourceLocation(MODID, "test_fluid");
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
@SubscribeEvent
|
||||
public void preInit(FMLCommonSetupEvent event)
|
||||
{
|
||||
if (ENABLED)
|
||||
{
|
||||
FluidRegistry.registerFluid(SLIME);
|
||||
FluidRegistry.addBucketForFluid(SLIME);
|
||||
}
|
||||
FluidRegistry.registerFluid(SLIME);
|
||||
FluidRegistry.addBucketForFluid(SLIME);
|
||||
}
|
||||
|
||||
@net.minecraftforge.eventbus.api.SubscribeEvent
|
||||
@SubscribeEvent
|
||||
public static void registerBlocks(RegistryEvent.Register<Block> event)
|
||||
{
|
||||
if (ENABLED)
|
||||
event.getRegistry().register((new BlockFluidClassic(SLIME, Material.WATER)).setRegistryName(RES_LOC).setUnlocalizedName(RES_LOC.toString()));
|
||||
Fluid fluid = new Fluid("fog_test", new ResourceLocation("blocks/water_still"), new ResourceLocation("blocks/water_flow"), new ResourceLocation("blocks/water_overlay"));
|
||||
FluidRegistry.registerFluid(fluid);
|
||||
Block fluidBlock = new BlockFluidClassic(fluid, Material.WATER)
|
||||
{
|
||||
event.getRegistry().register((new BlockFluidClassic(SLIME, Material.WATER)).setRegistryName(RES_LOC).setUnlocalizedName(RES_LOC.toString()));
|
||||
Fluid fluid = new Fluid("fog_test", new ResourceLocation("blocks/water_still"), new ResourceLocation("blocks/water_flow"), new ResourceLocation("blocks/water_overlay"));
|
||||
FluidRegistry.registerFluid(fluid);
|
||||
Block fluidBlock = new BlockFluidClassic(fluid, Material.WATER)
|
||||
@Override
|
||||
public Vec3d getFogColor(World world, BlockPos pos, BlockState state, Entity entity, Vec3d originalColor, float partialTicks)
|
||||
{
|
||||
@Override
|
||||
public Vec3d getFogColor(World world, BlockPos pos, IBlockState state, Entity entity, Vec3d originalColor, float partialTicks)
|
||||
{
|
||||
return new Vec3d(0.6F, 0.1F, 0.0F);
|
||||
}
|
||||
};
|
||||
event.getRegistry().register(fluidBlock.setCreativeTab(CreativeTabs.BUILDING_BLOCKS).setUnlocalizedName(MODID + ".test_fluid").setRegistryName(testFluidRegistryName));
|
||||
}
|
||||
return new Vec3d(0.6F, 0.1F, 0.0F);
|
||||
}
|
||||
};
|
||||
event.getRegistry().register(fluidBlock.setCreativeTab(CreativeTabs.BUILDING_BLOCKS).setUnlocalizedName(MODID + ".test_fluid").setRegistryName(testFluidRegistryName));
|
||||
}
|
||||
|
||||
@net.minecraftforge.eventbus.api.SubscribeEvent
|
||||
public static void registerItems(RegistryEvent.Register<Item> event)
|
||||
{
|
||||
if (ENABLED)
|
||||
{
|
||||
event.getRegistry().register(new ItemBlock(FLUID_BLOCK).setRegistryName(testFluidRegistryName));
|
||||
}
|
||||
event.getRegistry().register(new ItemBlock(FLUID_BLOCK).setRegistryName(testFluidRegistryName));
|
||||
}
|
||||
|
||||
//@EventBusSubscriber(value = Side.CLIENT, modid = MODID)
|
||||
@EventBusSubscriber(value = Dist.CLIENT, modid = MODID)
|
||||
public static class ClientEventHandler
|
||||
{
|
||||
@SubscribeEvent
|
||||
public static void registerModels(ModelRegistryEvent event)
|
||||
{
|
||||
if (ENABLED)
|
||||
{
|
||||
ModelResourceLocation fluidLocation = new ModelResourceLocation(testFluidRegistryName, "fluid");
|
||||
ModelLoader.registerItemVariants(FLUID_ITEM);
|
||||
ModelLoader.setCustomMeshDefinition(FLUID_ITEM, stack -> fluidLocation);
|
||||
ModelLoader.setCustomStateMapper(FLUID_BLOCK, new StateMapperBase() {
|
||||
@Override
|
||||
protected ModelResourceLocation getModelResourceLocation(IBlockState state)
|
||||
{
|
||||
return fluidLocation;
|
||||
}
|
||||
});
|
||||
}
|
||||
ModelResourceLocation fluidLocation = new ModelResourceLocation(testFluidRegistryName, "fluid");
|
||||
ModelLoader.registerItemVariants(FLUID_ITEM);
|
||||
ModelLoader.setCustomMeshDefinition(FLUID_ITEM, stack -> fluidLocation);
|
||||
ModelLoader.setCustomStateMapper(FLUID_BLOCK, new StateMapperBase() {
|
||||
@Override
|
||||
protected ModelResourceLocation getModelResourceLocation(BlockState state)
|
||||
{
|
||||
return fluidLocation;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -19,35 +19,28 @@
|
||||
|
||||
package net.minecraftforge.debug.block;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraftforge.event.world.BlockEvent.NeighborNotifyEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
import net.minecraftforge.fml.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
//@Mod(modid = "neighbornotifyeventtest", name = "NeighborNotifyEventTest", version = "0.0.0", acceptableRemoteVersions = "*")
|
||||
//Disables update notification from comparators.
|
||||
|
||||
@Mod("neighbor_notify_event_test")
|
||||
@Mod.EventBusSubscriber
|
||||
public class NeighborNotifyEventTest
|
||||
{
|
||||
|
||||
public static final boolean ENABLE = false;
|
||||
private static Logger logger;
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
if (ENABLE)
|
||||
{
|
||||
logger = event.getModLog();
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
}
|
||||
private static Logger logger = LogManager.getLogger(NeighborNotifyEventTest.class);
|
||||
|
||||
@SubscribeEvent
|
||||
public void onNeighborNotify(NeighborNotifyEvent event)
|
||||
public static void onNeighborNotify(NeighborNotifyEvent event)
|
||||
{
|
||||
logger.info("{} with face information: {}", event.getPos().toString(), event.getNotifiedSides());
|
||||
event.setCanceled(true);
|
||||
if (event.getState().getBlock() == Blocks.COMPARATOR) {
|
||||
logger.info("{} with face information: {}", event.getPos().toString(), event.getNotifiedSides());
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,48 +20,41 @@
|
||||
package net.minecraftforge.debug.block;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.particle.ParticleManager;
|
||||
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumParticleTypes;
|
||||
import net.minecraft.particles.ParticleTypes;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.world.ServerWorld;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.client.event.ModelRegistryEvent;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||
import net.minecraftforge.registries.ObjectHolder;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry.ObjectHolder;
|
||||
|
||||
import static net.minecraftforge.debug.block.ParticleEffectsTest.MOD_ID;
|
||||
import static net.minecraftforge.debug.block.ParticleEffectsTest.MOD_NAME;
|
||||
|
||||
//@EventBusSubscriber
|
||||
//@Mod(modid = MOD_ID, name = MOD_NAME, version = "1.0", acceptableRemoteVersions = "*")
|
||||
@Mod(ParticleEffectsTest.MOD_ID)
|
||||
@Mod.EventBusSubscriber
|
||||
public class ParticleEffectsTest
|
||||
{
|
||||
|
||||
public static final String MOD_ID = "blockparticleeffectstest";
|
||||
public static final String MOD_NAME = "Block particle effects test";
|
||||
public static final String MOD_ID = "block_particle_effects_test";
|
||||
public static final String BLOCK_ID = "particle_block";
|
||||
|
||||
@ObjectHolder ("particle_block")
|
||||
@ObjectHolder(BLOCK_ID)
|
||||
public static final Block PARTICLE_BLOCK = null;
|
||||
|
||||
@ObjectHolder ("particle_block")
|
||||
@ObjectHolder(BLOCK_ID)
|
||||
public static final Item PARTICLE_ITEM = null;
|
||||
|
||||
private static final ResourceLocation particleBlockLocation = new ResourceLocation(MOD_ID, "particle_block");
|
||||
@@ -69,55 +62,56 @@ public class ParticleEffectsTest
|
||||
@SubscribeEvent
|
||||
public static void registerBlocks(RegistryEvent.Register<Block> event)
|
||||
{
|
||||
Block block = new Block(Material.ROCK)
|
||||
Block block = new Block(Block.Properties.create(Material.ROCK).hardnessAndResistance(20, 0))
|
||||
{
|
||||
@Override
|
||||
public boolean addLandingEffects(IBlockState state, WorldServer world, BlockPos blockPosition, IBlockState iblockstate, EntityLivingBase entity, int numberOfParticles)
|
||||
public boolean addLandingEffects(BlockState state, ServerWorld world, BlockPos blockPosition, BlockState BlockState, LivingEntity entity, int numberOfParticles)
|
||||
{
|
||||
world.spawnParticle(EnumParticleTypes.REDSTONE, entity.posX, entity.posY, entity.posZ, numberOfParticles, 0, 0, 0, 0.1D);
|
||||
world.spawnParticle(ParticleTypes.EXPLOSION, entity.posX, entity.posY, entity.posZ, numberOfParticles, 0, 0, 0, 0.1D);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addRunningEffects(IBlockState state, World world, BlockPos pos, Entity entity)
|
||||
public boolean addRunningEffects(BlockState state, World world, BlockPos pos, Entity entity)
|
||||
{
|
||||
world.spawnParticle(EnumParticleTypes.REDSTONE, entity.posX, entity.posY, entity.posZ, 1, 0, 0);
|
||||
world.addParticle(ParticleTypes.EXPLOSION, entity.posX, entity.posY, entity.posZ, 1, 0, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public boolean addHitEffects(IBlockState state, World world, RayTraceResult target, ParticleManager manager)
|
||||
public boolean addHitEffects(BlockState state, World world, RayTraceResult target, ParticleManager manager)
|
||||
{
|
||||
world.spawnParticle(EnumParticleTypes.REDSTONE, target.hitVec.x, target.hitVec.y, target.hitVec.z, 0, 1, 0);
|
||||
world.addParticle(ParticleTypes.EXPLOSION, target.getHitVec().x, target.getHitVec().y, target.getHitVec().z, 0, 1, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public boolean addDestroyEffects(World world, BlockPos pos, ParticleManager manager)
|
||||
public boolean addDestroyEffects(BlockState state, World world, BlockPos pos, ParticleManager manager)
|
||||
{
|
||||
world.spawnParticle(EnumParticleTypes.REDSTONE, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 0, 0, 1);
|
||||
world.addParticle(ParticleTypes.EXPLOSION, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 0, 0, 1);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
event.getRegistry().register(block.setCreativeTab(CreativeTabs.BUILDING_BLOCKS).setHardness(20).setRegistryName(particleBlockLocation));
|
||||
event.getRegistry().register(block.setRegistryName(particleBlockLocation));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerItems(RegistryEvent.Register<Item> event)
|
||||
{
|
||||
Item item = new ItemBlock(PARTICLE_BLOCK) {
|
||||
Item item = new BlockItem(PARTICLE_BLOCK, new Item.Properties()) {
|
||||
@Override
|
||||
public String getItemStackDisplayName(ItemStack stack)
|
||||
public ITextComponent getDisplayName(ItemStack stack)
|
||||
{
|
||||
return "Particle Tests Block";
|
||||
return new StringTextComponent("Particle Tests Block");
|
||||
}
|
||||
};
|
||||
event.getRegistry().register(item.setRegistryName(particleBlockLocation));
|
||||
}
|
||||
|
||||
//@EventBusSubscriber (value = Side.CLIENT, modid = MOD_ID)
|
||||
/*
|
||||
@EventBusSubscriber(value = Dist.CLIENT, modid = MOD_ID)
|
||||
public static class ClientEventHandler
|
||||
{
|
||||
|
||||
@@ -129,7 +123,7 @@ public class ParticleEffectsTest
|
||||
ModelLoader.setCustomStateMapper(PARTICLE_BLOCK, new StateMapperBase()
|
||||
{
|
||||
@Override
|
||||
protected ModelResourceLocation getModelResourceLocation(IBlockState state)
|
||||
protected ModelResourceLocation getModelResourceLocation(BlockState state)
|
||||
{
|
||||
return normalLoc;
|
||||
}
|
||||
@@ -137,4 +131,5 @@ public class ParticleEffectsTest
|
||||
ModelLoader.setCustomModelResourceLocation(PARTICLE_ITEM, 0, invLoc);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -20,43 +20,48 @@
|
||||
package net.minecraftforge.debug.block;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.model.ModelBakery;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.entity.MobEntity;
|
||||
import net.minecraft.pathfinding.PathNodeType;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.ModelRegistryEvent;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.registries.ObjectHolder;
|
||||
|
||||
import java.util.Collections;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
//@Mod(modid = PathNodeTypeTest.MOD_ID, name = "AiNodeTypeTest", version = "1.0", acceptableRemoteVersions = "*")
|
||||
//@Mod.EventBusSubscriber
|
||||
@Mod(PathNodeTypeTest.MOD_ID)
|
||||
@Mod.EventBusSubscriber
|
||||
public class PathNodeTypeTest
|
||||
{
|
||||
static final String MOD_ID = "ai_node_type_test";
|
||||
static final boolean ENABLED = false;
|
||||
static final String BLOCK_ID = "test_block";
|
||||
|
||||
private static final Block TEST_BLOCK = new TestBlock();
|
||||
|
||||
@net.minecraftforge.eventbus.api.SubscribeEvent
|
||||
@ObjectHolder(BLOCK_ID)
|
||||
private static final Block TEST_BLOCK = null;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void register(RegistryEvent.Register<Block> event)
|
||||
{
|
||||
if (ENABLED)
|
||||
event.getRegistry().register((new Block(Block.Properties.create(Material.ROCK))
|
||||
{
|
||||
event.getRegistry().register(TEST_BLOCK);
|
||||
}
|
||||
@Override
|
||||
public PathNodeType getAiPathNodeType(BlockState state, IBlockReader world, BlockPos pos, @Nullable MobEntity entity)
|
||||
{
|
||||
return PathNodeType.DOOR_OPEN;
|
||||
}
|
||||
}).setRegistryName(MOD_ID, BLOCK_ID));
|
||||
}
|
||||
|
||||
//@Mod.EventBusSubscriber(value = Side.CLIENT, modid = MOD_ID)
|
||||
/*
|
||||
@Mod.EventBusSubscriber(value = Dist.CLIENT, modid = MOD_ID)
|
||||
public static class ClientEventHandler
|
||||
{
|
||||
@net.minecraftforge.eventbus.api.SubscribeEvent
|
||||
@SubscribeEvent
|
||||
public static void registerModels(ModelRegistryEvent event)
|
||||
{
|
||||
if (ENABLED)
|
||||
@@ -66,19 +71,5 @@ public class PathNodeTypeTest
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final class TestBlock extends Block
|
||||
{
|
||||
TestBlock()
|
||||
{
|
||||
super(Material.ROCK);
|
||||
setRegistryName("test_block");
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathNodeType getAiPathNodeType(IBlockState state, IBlockAccess world, BlockPos pos)
|
||||
{
|
||||
return PathNodeType.DOOR_OPEN;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -19,30 +19,19 @@
|
||||
|
||||
package net.minecraftforge.debug.block;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraftforge.event.world.BlockEvent.EntityPlaceEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
//@Mod(modid = PlaceEventTest.MOD_ID, name = "BlockPlaceEvent test mod", version = "1.0", acceptableRemoteVersions = "*")
|
||||
//@Mod.EventBusSubscriber
|
||||
@Mod("block_place_event_test")
|
||||
@Mod.EventBusSubscriber
|
||||
public class PlaceEventTest
|
||||
{
|
||||
static final String MOD_ID = "block_place_event_test";
|
||||
static final boolean ENABLED = false;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onBlockPlaced(BlockEvent.PlaceEvent event)
|
||||
public static void onBlockPlaced(EntityPlaceEvent event)
|
||||
{
|
||||
if (!ENABLED)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getPlacedBlock().getBlock() == Blocks.CHEST
|
||||
&& event.getPlacedAgainst().getBlock() != Blocks.DIAMOND_BLOCK)
|
||||
{
|
||||
if (event.getPlacedBlock().getBlock() == Blocks.CHEST && event.getPlacedAgainst().getBlock() != Blocks.DIAMOND_BLOCK)
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,28 +19,22 @@
|
||||
|
||||
package net.minecraftforge.debug.block;
|
||||
|
||||
import net.minecraft.init.Biomes;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.biome.Biomes;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
//@Mod(modid = PortalSpawnEventTest.MOD_ID, name = "PortalSpawnEvent test mod", version = "1.0", acceptableRemoteVersions = "*")
|
||||
//@Mod.EventBusSubscriber
|
||||
@Mod("portal_spawn_event_test")
|
||||
@Mod.EventBusSubscriber
|
||||
public class PortalSpawnEventTest
|
||||
{
|
||||
static final String MOD_ID = "portal_spawn_event_test";
|
||||
static final boolean ENABLED = false;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onTrySpawnPortal(BlockEvent.PortalSpawnEvent event)
|
||||
{
|
||||
if (!ENABLED) return;
|
||||
|
||||
World world = event.getWorld();
|
||||
if (world.provider.getDimension() == 0 && world.getBiome(event.getPos()) != Biomes.EXTREME_HILLS)
|
||||
{
|
||||
IWorld world = event.getWorld();
|
||||
if (world.getWorld().getDimension().getType() == DimensionType.OVERWORLD && world.getBiome(event.getPos()) != Biomes.field_222371_ax)
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,57 +20,51 @@
|
||||
package net.minecraftforge.debug.block;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.model.ModelBakery;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityBoat;
|
||||
import net.minecraft.entity.item.BoatEntity;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.ModelRegistryEvent;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraft.world.IWorldReader;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||
import net.minecraftforge.registries.ObjectHolder;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
//@Mod(modid = SlipperinessTest.MOD_ID, name = "Slipperiness Test", version = "0.0.0", acceptableRemoteVersions = "*")
|
||||
//@EventBusSubscriber
|
||||
@Mod(SlipperinessTest.MOD_ID)
|
||||
@EventBusSubscriber
|
||||
public class SlipperinessTest
|
||||
{
|
||||
static final String MOD_ID = "slipperiness_test";
|
||||
static final String BLOCK_ID = "test_block";
|
||||
|
||||
public static final Block BB_BLOCK = new Block(Material.PACKED_ICE)
|
||||
{
|
||||
@Override
|
||||
public float getSlipperiness(IBlockState state, IBlockAccess world, BlockPos pos, Entity entity)
|
||||
{
|
||||
return entity instanceof EntityBoat ? 2 : super.getSlipperiness(state, world, pos, entity);
|
||||
}
|
||||
};
|
||||
@ObjectHolder(BLOCK_ID)
|
||||
public static final Block BB_BLOCK = null;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerBlocks(RegistryEvent.Register<Block> e)
|
||||
{
|
||||
e.getRegistry().register(BB_BLOCK
|
||||
.setUnlocalizedName("boat_blaster")
|
||||
.setRegistryName("boat_blaster")
|
||||
.setCreativeTab(CreativeTabs.BUILDING_BLOCKS));
|
||||
e.getRegistry().register((new Block(Block.Properties.create(Material.PACKED_ICE))
|
||||
{
|
||||
@Override
|
||||
public float getSlipperiness(BlockState state, IWorldReader world, BlockPos pos, Entity entity)
|
||||
{
|
||||
return entity instanceof BoatEntity ? 2 : super.getSlipperiness(state, world, pos, entity);
|
||||
}
|
||||
}).setRegistryName(MOD_ID, BLOCK_ID));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerItems(RegistryEvent.Register<Item> e)
|
||||
{
|
||||
e.getRegistry().register(new ItemBlock(BB_BLOCK).setRegistryName(BB_BLOCK.getRegistryName()));
|
||||
e.getRegistry().register(new BlockItem(BB_BLOCK, new Item.Properties()).setRegistryName(BB_BLOCK.getRegistryName()));
|
||||
}
|
||||
|
||||
//@EventBusSubscriber(value = Side.CLIENT, modid = MOD_ID)
|
||||
/*
|
||||
@EventBusSubscriber(value = Dist.CLIENT, modid = MOD_ID)
|
||||
public static class ClientEventHandler
|
||||
{
|
||||
@SubscribeEvent
|
||||
@@ -80,4 +74,5 @@ public class SlipperinessTest
|
||||
ModelBakery.registerItemVariants(Item.getItemFromBlock(BB_BLOCK));
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -20,122 +20,41 @@
|
||||
package net.minecraftforge.debug.block;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockSlime;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemMultiTexture;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.client.event.ModelRegistryEvent;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
import net.minecraftforge.fml.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.registries.ObjectHolder;
|
||||
|
||||
//@Mod(modid = StickyBlockTest.MODID, name = "ForgeDebugCustomSlimeBlock", version = StickyBlockTest.VERSION, acceptableRemoteVersions = "*")
|
||||
@Mod(StickyBlockTest.MODID)
|
||||
@Mod.EventBusSubscriber
|
||||
public class StickyBlockTest
|
||||
{
|
||||
public static final String MODID = "forgedebugcustomslimeblock";
|
||||
public static final String ASSETS = "forgedebugcustomslimeblock:";
|
||||
public static final String VERSION = "1.0";
|
||||
public static Block CUSTOM_SLIME_BLOCK;
|
||||
static final String MODID = "custom_slime_block_test";
|
||||
static final String BLOCK_ID = "test_block";
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
@ObjectHolder(BLOCK_ID)
|
||||
public static Block BLUE_BLOCK;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerBlocks(RegistryEvent.Register<Block> event)
|
||||
{
|
||||
CUSTOM_SLIME_BLOCK = new CustomSlime();
|
||||
ForgeRegistries.BLOCKS.register(CUSTOM_SLIME_BLOCK);
|
||||
ForgeRegistries.ITEMS.register(new ItemMultiTexture(CUSTOM_SLIME_BLOCK, CUSTOM_SLIME_BLOCK, stack -> CustomSlime.BlockType.values[stack.getMetadata()].toString()).setRegistryName(CUSTOM_SLIME_BLOCK.getRegistryName()));
|
||||
}
|
||||
|
||||
//@EventBusSubscriber(value = Side.CLIENT, modid = MODID)
|
||||
public static class BakeEventHandler
|
||||
{
|
||||
@net.minecraftforge.eventbus.api.SubscribeEvent
|
||||
public static void registerModels(ModelRegistryEvent event)
|
||||
event.getRegistry().register((new Block(Block.Properties.create(Material.ROCK))
|
||||
{
|
||||
Item item = Item.getItemFromBlock(CUSTOM_SLIME_BLOCK);
|
||||
ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(ASSETS + "blue_slime_block", "inventory"));
|
||||
ModelLoader.setCustomModelResourceLocation(item, 1, new ModelResourceLocation(ASSETS + "obsidian_slime_block", "inventory"));
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomSlime extends BlockSlime
|
||||
{
|
||||
private static final PropertyEnum<BlockType> VARIANT = PropertyEnum.create("variant", BlockType.class);
|
||||
|
||||
private CustomSlime()
|
||||
{
|
||||
super();
|
||||
this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, BlockType.BLUE_SLIME_BLOCK));
|
||||
this.setCreativeTab(CreativeTabs.DECORATIONS);
|
||||
this.setUnlocalizedName("custom_slime_block");
|
||||
this.setRegistryName("forgedebugcustomslimeblock:custom_slime_block");
|
||||
this.setSoundType(SoundType.SLIME);
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void getSubBlocks(CreativeTabs creativeTabs, NonNullList<ItemStack> list)
|
||||
{
|
||||
for (int i = 0; i < BlockType.values.length; ++i)
|
||||
{
|
||||
list.add(new ItemStack(this, 1, i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState()
|
||||
{
|
||||
return new BlockStateContainer(this, VARIANT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta)
|
||||
{
|
||||
return this.getDefaultState().withProperty(VARIANT, BlockType.values[meta]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state)
|
||||
{
|
||||
return state.getValue(VARIANT).ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStickyBlock(IBlockState state)
|
||||
{
|
||||
return state.getValue(VARIANT) != BlockType.OBSIDIAN_SLIME_BLOCK;
|
||||
}
|
||||
|
||||
public static enum BlockType implements IStringSerializable
|
||||
{
|
||||
BLUE_SLIME_BLOCK,
|
||||
OBSIDIAN_SLIME_BLOCK;
|
||||
|
||||
protected static final BlockType[] values = BlockType.values();
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
public boolean isStickyBlock(BlockState state)
|
||||
{
|
||||
return this.name().toLowerCase();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return this.name().toLowerCase();
|
||||
}
|
||||
}
|
||||
}).setRegistryName(MODID, BLOCK_ID));
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerItems(RegistryEvent.Register<Item> event)
|
||||
{
|
||||
event.getRegistry().register(new BlockItem(BLUE_BLOCK, new Item.Properties()).setRegistryName(MODID, BLOCK_ID));
|
||||
}
|
||||
}
|
||||
@@ -20,36 +20,19 @@
|
||||
package net.minecraftforge.debug.chat;
|
||||
|
||||
import net.minecraftforge.client.event.ClientChatEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
import net.minecraftforge.fml.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
|
||||
//@Mod(modid = "clientchateventtest", name = "Client Chat Event Test", version = "0.0.0", clientSideOnly = true)
|
||||
@Mod("client_chat_event_test")
|
||||
@Mod.EventBusSubscriber
|
||||
public class ClientChatEventTest
|
||||
{
|
||||
static final boolean ENABLED = false;
|
||||
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent event)
|
||||
{
|
||||
if (ENABLED)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
}
|
||||
|
||||
@net.minecraftforge.eventbus.api.SubscribeEvent
|
||||
public void onPlayerAttemptChat(ClientChatEvent event)
|
||||
@SubscribeEvent
|
||||
public static void onPlayerAttemptChat(ClientChatEvent event)
|
||||
{
|
||||
if (event.getMessage().equals("Cancel"))
|
||||
{
|
||||
event.setCanceled(true);
|
||||
}
|
||||
else if (event.getMessage().equals("Replace this text"))
|
||||
{
|
||||
event.setMessage("Text replaced.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,17 +19,12 @@
|
||||
|
||||
package net.minecraftforge.debug.chat;
|
||||
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraftforge.client.ClientCommandHandler;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
import net.minecraftforge.fml.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.GameData;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -37,9 +32,10 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
//@Mod(modid = "clientcommandtest", name = "Client Command Test", version = "0.0.0", clientSideOnly = true)
|
||||
@Mod("client_command_test")
|
||||
public class ClientCommandTest
|
||||
{
|
||||
/*
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent event)
|
||||
{
|
||||
@@ -82,12 +78,13 @@ public class ClientCommandTest
|
||||
{
|
||||
if (args.length > 0)
|
||||
{
|
||||
sender.sendMessage(new TextComponentString("Input: " + Arrays.toString(args)));
|
||||
sender.sendMessage(new StringTextComponent("Input: " + Arrays.toString(args)));
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.sendMessage(new TextComponentString("No arguments."));
|
||||
sender.sendMessage(new StringTextComponent("No arguments."));
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -20,56 +20,50 @@
|
||||
package net.minecraftforge.debug.chat;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
import com.mojang.brigadier.context.ParsedCommandNode;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraftforge.event.CommandEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
//@Mod("command_event_test")
|
||||
@Mod("command_event_test")
|
||||
@Mod.EventBusSubscriber
|
||||
public class CommandEventTest
|
||||
{
|
||||
public final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
public CommandEventTest()
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onCommand(CommandEvent event)
|
||||
public static void onCommand(CommandEvent event)
|
||||
{
|
||||
CommandDispatcher<CommandSource> dispatcher = event.getParseResults().getContext().getDispatcher();
|
||||
List<CommandNode<CommandSource>> nodes = new ArrayList<>(event.getParseResults().getContext().getNodes().keySet());
|
||||
List<ParsedCommandNode<CommandSource>> nodes = event.getParseResults().getContext().getNodes();
|
||||
CommandSource source = event.getParseResults().getContext().getSource();
|
||||
|
||||
// test: when the /time command is used with no arguments, automatically add default arguments (/time set day)
|
||||
if (nodes.size() == 1 && nodes.get(0) == dispatcher.getRoot().getChild("time"))
|
||||
if (nodes.size() == 1 && nodes.get(0).getNode() == dispatcher.getRoot().getChild("time"))
|
||||
{
|
||||
event.setParseResults(dispatcher.parse("time set day", source));
|
||||
return;
|
||||
}
|
||||
|
||||
// test: whenever a player uses the /give command, let everyone on the server know
|
||||
if (nodes.size() > 0 && nodes.get(0) == dispatcher.getRoot().getChild("give"))
|
||||
if (nodes.size() > 0 && nodes.get(0).getNode() == dispatcher.getRoot().getChild("give"))
|
||||
{
|
||||
String msg = source.getName() + " used the give command: " + event.getParseResults().getReader().getString();
|
||||
source.getServer().getPlayerList().getPlayers().forEach(entityPlayerMP -> entityPlayerMP.sendMessage(new TextComponentString(msg)));
|
||||
source.getServer().getPlayerList().getPlayers().forEach(PlayerEntityMP -> PlayerEntityMP.sendMessage(new StringTextComponent(msg)));
|
||||
return;
|
||||
}
|
||||
|
||||
// test: when the /kill command is used with no arguments, throw a custom exception
|
||||
if (nodes.size() == 1 && nodes.get(0) == dispatcher.getRoot().getChild("kill"))
|
||||
if (nodes.size() == 1 && nodes.get(0).getNode() == dispatcher.getRoot().getChild("kill"))
|
||||
{
|
||||
event.setException(new CommandException(new TextComponentString("You tried to use the /kill command with no arguments")));
|
||||
event.setException(new CommandException(new StringTextComponent("You tried to use the /kill command with no arguments")));
|
||||
event.setCanceled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,152 +0,0 @@
|
||||
/*
|
||||
* 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.chat;
|
||||
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.FMLServerStartingEvent;
|
||||
import net.minecraftforge.server.command.CommandTreeBase;
|
||||
|
||||
//@Mod(modid = CommandTreeBaseTest.MOD_ID, name = "CommandTreeBaseTest", version = "1.0.0", acceptableRemoteVersions = "*")
|
||||
public class CommandTreeBaseTest
|
||||
{
|
||||
public static final String MOD_ID = "command_tree_base_test";
|
||||
|
||||
@Mod.Instance(CommandTreeBaseTest.MOD_ID)
|
||||
public static CommandTreeBaseTest inst;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onServerStarted(FMLServerStartingEvent event)
|
||||
{
|
||||
event.registerServerCommand(new CommandTreeTest());
|
||||
}
|
||||
|
||||
public static class CommandTreeTest extends CommandTreeBase
|
||||
{
|
||||
public CommandTreeTest()
|
||||
{
|
||||
addSubcommand(new CommandPing());
|
||||
addSubcommand(new CommandValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "treecommand_test";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.treecommand_test.usage";
|
||||
}
|
||||
|
||||
public static class CommandPing extends CommandBase
|
||||
{
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "ping";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.treecommand_test.ping.usage";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
sender.sendMessage(new TextComponentString("Pong!"));
|
||||
}
|
||||
}
|
||||
|
||||
public static class CommandValue extends CommandTreeBase
|
||||
{
|
||||
private static int value = 0;
|
||||
|
||||
public CommandValue()
|
||||
{
|
||||
addSubcommand(new CommandSet());
|
||||
addSubcommand(new CommandGet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "value";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.treecommand_test.value.usage";
|
||||
}
|
||||
|
||||
public static class CommandSet extends CommandBase
|
||||
{
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "set";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.treecommand_test.value.set.usage";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
value = CommandTreeTest.parseInt(args[0]);
|
||||
sender.sendMessage(new TextComponentString("Test value set to: " + value));
|
||||
}
|
||||
}
|
||||
|
||||
public static class CommandGet extends CommandBase
|
||||
{
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "get";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.treecommand_test.value.get.usage";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
sender.sendMessage(new TextComponentString("Test value: " + value));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,27 +25,26 @@ import net.minecraft.command.arguments.EntityOptions;
|
||||
import net.minecraft.command.arguments.EntitySelector;
|
||||
import net.minecraft.command.arguments.EntitySelectorParser;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraftforge.common.command.EntitySelectorManager;
|
||||
import net.minecraftforge.common.command.IEntitySelectorType;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLModLoadingContext;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
|
||||
//@Mod("entity_selector_test")
|
||||
@Mod("entity_selector_test")
|
||||
public class EntitySelectorTest
|
||||
{
|
||||
public EntitySelectorTest()
|
||||
{
|
||||
FMLModLoadingContext.get().getModEventBus().addListener(this::setup);
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
|
||||
}
|
||||
|
||||
public void setup(FMLCommonSetupEvent event)
|
||||
{
|
||||
EntityOptions.register("health", this::healthArgument, parser -> true,
|
||||
new TextComponentString("Selects entities based on their current health."));
|
||||
EntityOptions.register("health", this::healthArgument, parser -> true, new StringTextComponent("Selects entities based on their current health."));
|
||||
EntitySelectorManager.register("er", new ExampleCustomSelector());
|
||||
}
|
||||
|
||||
@@ -55,7 +54,7 @@ public class EntitySelectorTest
|
||||
private void healthArgument(EntitySelectorParser parser) throws CommandSyntaxException
|
||||
{
|
||||
MinMaxBounds.FloatBound bound = MinMaxBounds.FloatBound.fromReader(parser.getReader());
|
||||
parser.addFilter(entity -> entity instanceof EntityLivingBase && bound.test(((EntityLivingBase) entity).getHealth()));
|
||||
parser.addFilter(entity -> entity instanceof LivingEntity && bound.test(((LivingEntity) entity).getHealth()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,7 +90,7 @@ public class EntitySelectorTest
|
||||
@Override
|
||||
public ITextComponent getSuggestionTooltip()
|
||||
{
|
||||
return new TextComponentString("Example: Selects a random entity");
|
||||
return new StringTextComponent("Example: Selects a random entity");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user