mirror of
https://github.com/TechnoVisionDev/Forge-Modding-Tutorial-1.16
synced 2024-10-27 20:34:04 +00:00
Events
This commit is contained in:
parent
f1d33727a9
commit
510ab93367
@ -14,7 +14,7 @@ import org.apache.logging.log4j.Logger;
|
||||
@Mod("tutorial")
|
||||
public class Tutorial
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
public static final Logger LOGGER = LogManager.getLogger();
|
||||
public static final String MOD_ID = "tutorial";
|
||||
|
||||
public Tutorial() {
|
||||
|
@ -0,0 +1,66 @@
|
||||
package com.technovision.tutorial.events;
|
||||
|
||||
import com.technovision.tutorial.Tutorial;
|
||||
import com.technovision.tutorial.util.RegistryHandler;
|
||||
import net.minecraft.client.gui.screen.inventory.CraftingScreen;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.passive.SheepEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.potion.EffectInstance;
|
||||
import net.minecraft.potion.Effects;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.GuiOpenEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent;
|
||||
import net.minecraftforge.event.entity.player.AttackEntityEvent;
|
||||
import net.minecraftforge.eventbus.api.EventPriority;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = Tutorial.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
|
||||
public class ModClientEvents {
|
||||
|
||||
@SubscribeEvent (priority = EventPriority.HIGHEST)
|
||||
public static void onCraftingTableOpen(GuiOpenEvent event) {
|
||||
if (event.isCancelable()) {
|
||||
if (event.getGui() instanceof CraftingScreen) {
|
||||
event.setCanceled(true);
|
||||
Tutorial.LOGGER.info("Player tried to open a crafting table!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent // LivingEntity#func_233580_cy_c() ----> LivingEntity#getPosition()
|
||||
public static void onJumpWithStick(LivingEvent.LivingJumpEvent event) {
|
||||
LivingEntity player = event.getEntityLiving();
|
||||
if (player.getHeldItemMainhand().getItem() == Items.STICK) {
|
||||
Tutorial.LOGGER.info("Player tried to jump with a stick!");
|
||||
World world = player.getEntityWorld();
|
||||
world.setBlockState(player.func_233580_cy_().add(0, -1, 0), RegistryHandler.RUBY_BLOCK.get().getDefaultState());
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onDamageSheep(AttackEntityEvent event) {
|
||||
if (event.getEntityLiving().getHeldItemMainhand().getItem() == RegistryHandler.POISON_APPLE.get()) {
|
||||
if (event.getTarget().isAlive()) {
|
||||
LivingEntity target = (LivingEntity) event.getTarget();
|
||||
if (target instanceof SheepEntity) {
|
||||
|
||||
PlayerEntity player = event.getPlayer();
|
||||
target.addPotionEffect(new EffectInstance(Effects.POISON, 200));
|
||||
target.setGlowing(true);
|
||||
|
||||
// Client Only
|
||||
if (!event.getPlayer().getEntityWorld().isRemote) {
|
||||
String msg = TextFormatting.RED + "That sheep isn't feeling so good...";
|
||||
player.sendMessage(new StringTextComponent(msg), player.getUniqueID());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.technovision.tutorial.events;
|
||||
|
||||
import com.technovision.tutorial.Tutorial;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.event.ServerChatEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = Tutorial.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.DEDICATED_SERVER)
|
||||
public class ModServerEvents {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onCraftingTableOpen(ServerChatEvent event) {
|
||||
// Your Code Here
|
||||
}
|
||||
}
|
14
src/main/resources/data/minecraft/tags/blocks/planks.json
Normal file
14
src/main/resources/data/minecraft/tags/blocks/planks.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"minecraft:oak_planks",
|
||||
"minecraft:spruce_planks",
|
||||
"minecraft:birch_planks",
|
||||
"minecraft:jungle_planks",
|
||||
"minecraft:acacia_planks",
|
||||
"minecraft:dark_oak_planks",
|
||||
"minecraft:crimson_planks",
|
||||
"minecraft:warped_planks",
|
||||
"tutorial:ruby_block"
|
||||
]
|
||||
}
|
@ -10,11 +10,11 @@
|
||||
{
|
||||
"x":
|
||||
{
|
||||
"tag": "tutorial:ruby"
|
||||
"tag": "tutorial:gems"
|
||||
},
|
||||
"d":
|
||||
{
|
||||
"item": "minecraft:diamond"
|
||||
"tag": "forge:gems/diamond"
|
||||
}
|
||||
},
|
||||
"result":
|
||||
|
7
src/main/resources/data/tutorial/tags/items/gems.json
Normal file
7
src/main/resources/data/tutorial/tags/items/gems.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"minecraft:emerald",
|
||||
"tutorial:ruby"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user