Changes

213 bytes added ,  18:05, 20 April 2021
m
more runtime issues
Line 128: Line 128:  
public void onFluidPlace(final BlockEvent.FluidPlaceBlockEvent event)
 
public void onFluidPlace(final BlockEvent.FluidPlaceBlockEvent event)
 
     {
 
     {
 +
        IWorld world = event.getWorld();
 
         if (world.isClientSide()) return;
 
         if (world.isClientSide()) return;
 
         BlockState newState = event.getNewState();
 
         BlockState newState = event.getNewState();
         if (newState.is(Blocks.FIRE))
+
         if (newState.is(Blocks.COBBLESTONE) && world.dayTime() > 14000L)
        {
  −
            event.setCanceled(true); // prevent fire placing from lava
  −
        }
  −
        else if (newState.is(Blocks.COBBLESTONE) && event.getWorld().dayTime() > 14000L)
   
         {
 
         {
 
             event.setNewState(Blocks.ANDESITE.defaultBlockState()); // change the block if done during nighttime.
 
             event.setNewState(Blocks.ANDESITE.defaultBlockState()); // change the block if done during nighttime.
Line 157: Line 154:  
public void onCropGrowPre(final BlockEvent.CropGrowEvent.Pre event)
 
public void onCropGrowPre(final BlockEvent.CropGrowEvent.Pre event)
 
     {
 
     {
 +
        IWorld world = event.getWorld();
 
         if (world.isClientSide()) return;
 
         if (world.isClientSide()) return;
 
         BlockState state = event.getState();
 
         BlockState state = event.getState();
Line 165: Line 163:  
         else if (state.is(Blocks.BAMBOO))
 
         else if (state.is(Blocks.BAMBOO))
 
         {
 
         {
             if (event.getWorld().getRandom().nextFloat() > 0.2F) // take a 4/5 chance
+
             if (world.getRandom().nextFloat() > 0.2F) // take a 4/5 chance
 
             {
 
             {
 
                 event.setResult(Event.Result.DENY); // make bamboo grow less often
 
                 event.setResult(Event.Result.DENY); // make bamboo grow less often
Line 189: Line 187:  
public void onTrample(final BlockEvent.FarmlandTrampleEvent event)
 
public void onTrample(final BlockEvent.FarmlandTrampleEvent event)
 
     {
 
     {
 +
        IWorld world = event.getWorld();
 
         if (!world.isClientSide() && event.getFallDistance() < 10.0F)
 
         if (!world.isClientSide() && event.getFallDistance() < 10.0F)
 
         {
 
         {
Line 208: Line 207:  
<code>setFinalState()</code>: Set what you want the result to be.
 
<code>setFinalState()</code>: Set what you want the result to be.
   −
<code>getFinalState()</code>: Returns what it will be changed to.
+
<code>getFinalState()</code>: Returns what it will be changed to. This will normally just return whatever the original block is unless you or another modder has set it. It can't check, for example, if something *will* turn into farmland in the future.
    
Example usage:
 
Example usage:
Line 214: Line 213:  
public void onToolInteract(final BlockEvent.BlockToolInteractEvent event)
 
public void onToolInteract(final BlockEvent.BlockToolInteractEvent event)
 
     {
 
     {
         if (!world.isClientSide() && event.getFinalState().is(Blocks.FARMLAND) && event.getHeldItemStack().getItem() == Items.NETHERITE_HOE)
+
        IWorld world = event.getWorld();
 +
         if (!world.isClientSide() && event.getHeldItemStack().getItem() == Items.NETHERITE_HOE)
 
         {
 
         {
             event.setFinalState(Blocks.NETHERRACK.defaultBlockState()); // change the final state under certain conditions
+
             event.setFinalState(Blocks.NETHERRACK.defaultBlockState()); // set the block to netherrack
 +
            // note that this happens for any right click on a block, not just dirt
 
         }
 
         }
 
     }
 
     }
16

edits