Jump to content

I want my event to be canceled when the player is in the end dimension, how?


Recommended Posts

Posted
@SubscribeEvent
    public void onPlayerInteract(PlayerInteractEvent.RightClickBlock evt) {
        // only handle right clicks on blocks
        // TODO: port for 1.9
//        if (evt.action != PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
//            return;
 
        BlockPos pos = evt.getPos();
        World world = evt.getWorld();
        IBlockState state = world.getBlockState(pos);
        Block block = world.getBlockState(pos).getBlock();
        
        // don't interact with vanilla egg blocks if configured
        if (RealmOfTheDragons.instance.getConfig().isDisableBlockOverride() && block == Blocks.DRAGON_EGG) {
            return;
        }
        
        // ignore non-egg blocks
        if (block != Blocks.DRAGON_EGG && block != BlockDragonBreedEgg.DRAGON_BREED_EGG) {
            return;
        }
        
        // deny action
        evt.setResult(Event.Result.DENY);
        
        // clear dragon egg block to avoid teleportation
        boolean setair = world.setBlockToAir(pos);
        
        // create dragon egg entity on server // put else
        if (!world.isRemote) { // this was inverted, i.e. evt.world.isRemote, but it should surely be this way
            EntityTameableDragon dragon = new EntityTameableDragon(world);
            dragon.setPosition(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
            dragon.getReproductionHelper().setBreeder(evt.getEntityPlayer());
            dragon.getLifeStageHelper().setLifeStage(EnumDragonLifeStage.EGG);  
            boolean spawn = world.spawnEntity(dragon);
            
            // set breed type (custom dragon egg only, otherwise use default breed)
            if (block == BlockDragonBreedEgg.DRAGON_BREED_EGG) {
                EnumDragonBreed breed = state.getValue(BlockDragonBreedEgg.BREED);
                dragon.getBreedHelper().setBreedType(breed);
            }
              spawn = true;     
        }
        
        if (world.provider.getDimensionType().equals(DimensionType.THE_END)) {
        	evt.setCanceled(true);
        }
    }
}

        if (world.provider.getDimensionType().equals(DimensionType.THE_END)) {
            evt.setCanceled(true);
        }

how do I arrange this exactly? 

Posted (edited)

What specifically are you trying to cancel? If it's the entire thing in there wouldn't you just surround the entire thing with that if?

And wouldn't using:

 

 if (world.provider instanceof WorldProviderEnd) {
            evt.setCanceled(true);
        } 

 

Work a lot better?

 

Edited by SubDivide
Posted
9 hours ago, SubDivide said:

What specifically are you trying to cancel? If it's the entire thing in there wouldn't you just surround the entire thing with that if?

And wouldn't using:

 

 if (world.provider instanceof WorldProviderEnd) {
            evt.setCanceled(true);
        } 

 

Work a lot better?

 

SOLVED! Just gotta put the source code so I can help kids who would check this

public class DragonEggBlockHandler {

    @SubscribeEvent
    public void onPlayerInteract(PlayerInteractEvent.RightClickBlock evt) {
 
        BlockPos pos = evt.getPos();
        World world = evt.getWorld();
        IBlockState state = world.getBlockState(pos);
        Block block = world.getBlockState(pos).getBlock();
        
        if (world.provider.getDimensionType().getId() != 1) {
    	
        
        // don't interact with vanilla egg blocks if configured
        if (RealmOfTheDragons.instance.getConfig().isDisableBlockOverride() && block == Blocks.DRAGON_EGG) {
            return;
        }
        
        // ignore non-egg blocks
        if (block != Blocks.DRAGON_EGG && block != BlockDragonBreedEgg.DRAGON_BREED_EGG) {
            return;
        }
        
        // deny action
        evt.setResult(Event.Result.DENY);
        
        // clear dragon egg block to avoid teleportation
        world.setBlockToAir(pos);
        
        // create dragon egg entity on server // put else
        if (!world.isRemote) { // this was inverted, i.e. evt.world.isRemote, but it should surely be this way
            EntityTameableDragon dragon = new EntityTameableDragon(world);
            dragon.setPosition(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
            dragon.getReproductionHelper().setBreeder(evt.getEntityPlayer());
            dragon.getLifeStageHelper().setLifeStage(EnumDragonLifeStage.EGG); 
            
            // set breed type (custom dragon egg only, otherwise use default breed)
            if (block == BlockDragonBreedEgg.DRAGON_BREED_EGG) {
                EnumDragonBreed breed = state.getValue(BlockDragonBreedEgg.BREED);
                dragon.getBreedHelper().setBreedType(breed);
                
                } world.spawnEntity(dragon);       
            }
        }       
    }
}

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
    • Maybe you need to create file in assets/<modid>/items/<itemname>.json with content like this:   { "model": { "type": "minecraft:model", "model": "modname:item/itemname" } }  
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.