Skip to content

Commit

Permalink
Add first game event
Browse files Browse the repository at this point in the history
  • Loading branch information
OldSerpskiStalker committed Sep 17, 2024
1 parent 6bd2b7c commit 0080a14
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.imesense.dynamicspawncontrol;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.SidedProxy;
Expand All @@ -11,6 +12,7 @@
import net.minecraftforge.fml.common.event.FMLServerStoppedEvent;

import org.imesense.dynamicspawncontrol.debug.CheckDebugger;
import org.imesense.dynamicspawncontrol.gameplay.events.OnUpdateTorchLogic;
import org.imesense.dynamicspawncontrol.technical.configs.IConfig;
import org.imesense.dynamicspawncontrol.technical.configs.SettingsLogFile;
import org.imesense.dynamicspawncontrol.technical.customlibrary.Log;
Expand Down Expand Up @@ -48,6 +50,16 @@ public class DynamicSpawnControl
*/
public static final String NAME_DIRECTORY = "DynamicsSpawnControl";

/**
*
*/
public static final String CONFIG_FILE_EXTENSION = ".cfg";

/**
*
*/
public static final String SCRIPT_FILE_EXTENSION = ".json";

/**
* Main class instance
*/
Expand Down Expand Up @@ -104,6 +116,8 @@ public synchronized void preInit(FMLPreInitializationEvent event)
Log.createLogFile(globalDirectory.getPath() + File.separator + NAME_DIRECTORY);
Log.writeDataToLogFile(Log.TypeLog[0], "Check debugger -> " + checkDebugger.IsRunDebugger);

MinecraftForge.EVENT_BUS.register(new OnUpdateTorchLogic("OnUpdateTorchLogic"));

Proxy.preInit(event);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,91 @@
package org.imesense.dynamicspawncontrol.gameplay.events;

public class OnUpdateTorchLogic
import net.minecraft.block.Block;
import net.minecraft.block.BlockTorch;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.monster.EntitySkeleton;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Explosion;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.imesense.dynamicspawncontrol.technical.customlibrary.Log;

public final class OnUpdateTorchLogic
{
public OnUpdateTorchLogic(final String nameClass)
{
Log.writeDataToLogFile(Log.TypeLog[0], nameClass);
}

@SubscribeEvent
public synchronized void onHit(LivingHurtEvent event)
{
if ((event.getSource().getDamageType().equalsIgnoreCase("mob") ||
event.getSource().getDamageType().equalsIgnoreCase("player")) && event.getSource().getTrueSource() != null)
{
Entity entity = event.getEntity();
Entity entityGetTrueSource = event.getSource().getTrueSource();

if (entityGetTrueSource instanceof EntityZombie)
{
EntityZombie zombie = (EntityZombie)entityGetTrueSource;

if (Block.getBlockFromItem(zombie.getHeldItemMainhand().getItem()) instanceof BlockTorch)
{
entity.setFire(5);
}
}
else if (entityGetTrueSource instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer)entityGetTrueSource;

if (Block.getBlockFromItem(player.getHeldItemMainhand().getItem()) instanceof BlockTorch)
{
entity.setFire(5);
}
}
else if (entityGetTrueSource instanceof EntitySkeleton)
{
EntitySkeleton skeleton = (EntitySkeleton)entityGetTrueSource;

if (Block.getBlockFromItem(skeleton.getHeldItemMainhand().getItem()) instanceof BlockTorch)
{
entity.setFire(5);
}
}
}
}

@SubscribeEvent
public synchronized void onBreak(BlockEvent.BreakEvent event)
{
EntityPlayer player = event.getPlayer();

if (Block.getBlockFromItem(player.getHeldItemMainhand().getItem()) instanceof BlockTorch)
{
BlockPos blockPos = event.getPos();
Block block = event.getState().getBlock();

if (block == Blocks.TNT)
{
event.setCanceled(true);
Explosion ex = new Explosion(player.world, player, blockPos.getX(), blockPos.getY(), blockPos.getZ(), 100.0F, true, true);
event.getState().getBlock().onBlockExploded(player.world, blockPos, ex);

if (!player.capabilities.isCreativeMode)
{
player.getHeldItemMainhand().setCount(player.getHeldItemMainhand().getCount() - 1);
EntityItem itm = new EntityItem(player.world, player.posX, player.posY, player.posZ, new ItemStack(Items.STICK));
player.world.spawnEntity(itm);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void init(FMLPreInitializationEvent event, String nameClass)
Log.writeDataToLogFile(Log.TypeLog[0], nameClass);

ClientProxy.ConfigLogFile = new Configuration(new File(DynamicSpawnControl.getGlobalPathToConfigs().getPath() +
File.separator + DynamicSpawnControl.NAME_DIRECTORY + File.separator + "configs", "log.ltx"));
File.separator + DynamicSpawnControl.NAME_DIRECTORY + File.separator + "configs", "log" + DynamicSpawnControl.CONFIG_FILE_EXTENSION));

read();
}
Expand Down

0 comments on commit 0080a14

Please sign in to comment.