Braking Block

Started by LueLusten on

Topic category: Help with MCreator software

Joined Nov 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Braking Block

How would I make it so a user can only use a block x acount of times I want to create a block that will spawn items but I want a block to be only able to do it X amout of times then the block brakes but I want it to do this for all users not per usres

I thouhgt maybe a verb set but this does not seem right as it would do it for that verb not per block, any ideas?

 

Reason I am doing is that ore blocks are braking for servers so this is another idea i had to include the block in game but I want to add limits to its use.

Joined Dec 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I have an idea on how to make
Sat, 11/19/2016 - 18:41

I have an idea on how to make this. Its lengthy but it could work good (uses alot of events especially stacked events)

If you want explanation let me know.

Joined Nov 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
RE:I have an idea on how to make
Sat, 11/19/2016 - 18:51

@#1 At the moment I am having a big problems with commands set by MCreator saying they wont run on a server and one of them was the extract command.

At the moment its not even listening to my if statement its stll triggering the tellraws even tho another command as fired

If I set
server.getCommandManager().executeCommand(server

to 

server.getCommandManager().executeCommand((EntityPlayer) entity

I get command error but will still fire the command but still firing both commands where am I going wrong?

[spoiler]

public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer entity, EnumHand hand, ItemStack heldItem,
            EnumFacing side, float hitX, float hitY, float hitZ) {
            int i = pos.getX();
            int j = pos.getY();
            int k = pos.getZ();

               boolean hasTriggered = false;
           
               if ((Math.random() * 100) <= 25) {
                    if (!world.isRemote) {
                         EntityItem var14 = new EntityItem(world, (double) (i), (double) (j + 2), (double) (k), new ItemStack(Items.REEDS, 8, 0));
                         var14.setPickupDelay(4);
                         world.spawnEntityInWorld(var14);
                         hasTriggered = true;
                    }
               }
               if ((Math.random() * 100) <= 5 && !hasTriggered) {
                    if (!world.isRemote) {
                         EntityItem var14 = new EntityItem(world, (double) (i), (double) (j + 2), (double) (k), new ItemStack(Items.IRON_INGOT, 1, 0));
                         var14.setPickupDelay(4);
                         world.spawnEntityInWorld(var14);
                         hasTriggered = true;
                    }
               }
               if ((Math.random() * 100) <= 10 && !hasTriggered) {
                    if (!world.isRemote) {
                         EntityItem var14 = new EntityItem(world, (double) (i), (double) (j + 2), (double) (k), new ItemStack(Items.ROTTEN_FLESH, 6, 0));
                         var14.setPickupDelay(4);
                         world.spawnEntityInWorld(var14);
                         hasTriggered = true;
                    }
               }
            if ((Math.random() * 100) <= 1 && !hasTriggered){
                    if (entity instanceof EntityPlayer){
                          if (entity instanceof EntityPlayer)
                                   ((EntityPlayer) entity).setPositionAndUpdate(-200, -200, -200);
                    }
                    hasTriggered = true;
            }
              if(hasTriggered == false){               
                    if (entity instanceof EntityPlayer){
                         MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
                         if ((Math.random() * 100) <= 50) {
                              if (server != null)
                                   server.getCommandManager().executeCommand(server, "tellraw @p [\"\",{\"text\":\"[\"},{\"text\":\"Doctor_Blockhead\",\"color\":\"gold\"},{\"text\":\"]:\",\"color\":\"none\"},{\"selector\":\"@p\",\"color\":\"none\"},{\"text\":\" TRIGGERED\",\"color\":\"none\"}]");
                         }else{
                              if (server != null)
                                   server.getCommandManager().executeCommand(server, "tellraw @p [\"\",{\"text\":\"[\"},{\"text\":\"Doctor_Blockhead\",\"color\":\"gold\"},{\"text\":\"]:\",\"color\":\"none\"},{\"selector\":\"@p\",\"color\":\"none\"},{\"text\":\", Jeff says no, sorry dude!\",\"color\":\"none\"}]");                              
                         }
                    }
                    hasTriggered = true;
              }
            return true;
        }

[/spoiler]

 

if I use the command from a ()

Joined Nov 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
it is 100% not listening to
Sat, 11/19/2016 - 19:25

it is 100% not listening to the boolean I have set up

 

 boolean hasTriggered = false;

this is set before everything, then in every command command soon as the random maths as been met I have 

hasTriggered = true;

I fire a command that shows a tellraw if !hasTriggered but it still fires it not matter what

if(!hasTriggered){

}

 

Full Source:
[spoiler]

package mod.mcreator;

import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraft.world.World;
import net.minecraft.world.IBlockAccess;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumActionResult;
import net.minecraft.server.MinecraftServer;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Item;
import net.minecraft.init.Items;
import net.minecraft.init.Blocks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.Entity;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.Minecraft;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.material.Material;
import net.minecraft.block.SoundType;
import net.minecraft.block.BlockFalling;

import java.util.Random;

public class mcreator_drBlockHead {

    public mcreator_drBlockHead() {
    }

    public static BlockDrBlockHead block;

    public static Object instance;

    public int addFuel(ItemStack fuel) {
        return 0;
    }

    public void serverLoad(FMLServerStartingEvent event) {
    }

    public void preInit(FMLPreInitializationEvent event) {
    }

    public void registerRenderers() {
    }

    public void load(FMLInitializationEvent event) {
        if (event.getSide() == Side.CLIENT) {
            Minecraft.getMinecraft().getRenderItem().getItemModelMesher()
                    .register(Item.getItemFromBlock(block), 0, new ModelResourceLocation("TestEnvironmentMod:DrBlockHead", "inventory"));
        }
    }

    static {

        block = (BlockDrBlockHead) (new BlockDrBlockHead().setHardness(2.0F).setResistance(5.0F).setLightLevel(0.0F)
                .setUnlocalizedName("DrBlockHead").setLightOpacity(0).setCreativeTab(mcreator_fandom.tab));
        block.setHarvestLevel("axe", 0);
    }

    public void generateSurface(World world, Random random, int chunkX, int chunkZ) {
    }

    public void generateNether(World world, Random random, int chunkX, int chunkZ) {
    }

    static class BlockDrBlockHead extends BlockFalling {

        int a1 = 0, a2 = 0, a3 = 0, a4 = 0, a5 = 0, a6 = 0;

        boolean red = false;

        protected BlockDrBlockHead() {
            super(Material.WOOD);

            GameRegistry.registerBlock(this, "DrBlockHead");
            setSoundType(SoundType.WOOD);

        }

        @Override
        public void onBlockAdded(World world, BlockPos pos, IBlockState state) {
            int i = pos.getX();
            int j = pos.getY();
            int k = pos.getZ();
            EntityPlayer entity = Minecraft.getMinecraft().thePlayer;
            world.scheduleUpdate(new BlockPos(i, j, k), this, this.tickRate(world));

        }

        @Override
        public int getWeakPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
            return red ? 15 : 0;
        }

        @Override
        public int getStrongPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
            return red ? 15 : 0;
        }

        @Override
        public void onBlockDestroyedByPlayer(World world, BlockPos pos, IBlockState state) {
            EntityPlayer entity = Minecraft.getMinecraft().thePlayer;
            int i = pos.getX();
            int j = pos.getY();
            int k = pos.getZ();
            if (true) {
                world.createExplosion((Entity) null, i, j, k, 1F, true);
            }

        }

        @Override
        public IBlockState onBlockPlaced(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta,
                EntityLivingBase placer) {
            IBlockState retVal = super.onBlockPlaced(world, pos, facing, hitX, hitY, hitZ, meta, placer);
            EntityPlayer entity = Minecraft.getMinecraft().thePlayer;
            int i = pos.getX();
            int j = pos.getY();
            int k = pos.getZ();
            if (true) {
                if (entity instanceof EntityPlayer)
                    ((EntityPlayer) entity).addStat(mcreator_goldenBlocklings.achievement, 1);
            }

            return retVal;
        }

        @Override
        public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer entity, EnumHand hand, ItemStack heldItem,
            EnumFacing side, float hitX, float hitY, float hitZ) {
            int i = pos.getX();
            int j = pos.getY();
            int k = pos.getZ();

               boolean hasTriggered = false;
           
               if ((Math.random() * 100) <= 25) {
                    hasTriggered = true;
                    if (!world.isRemote) {
                         EntityItem var14 = new EntityItem(world, (double) (i), (double) (j + 2), (double) (k), new ItemStack(Items.REEDS, 8, 0));
                         var14.setPickupDelay(4);
                         world.spawnEntityInWorld(var14);
                    }
               }
               if ((Math.random() * 100) <= 5 && !hasTriggered) {
                    hasTriggered = true;
                    if (!world.isRemote) {
                         EntityItem var14 = new EntityItem(world, (double) (i), (double) (j + 2), (double) (k), new ItemStack(Items.IRON_INGOT, 1, 0));
                         var14.setPickupDelay(4);
                         world.spawnEntityInWorld(var14);
                    }
               }
               if ((Math.random() * 100) <= 10 && !hasTriggered) {
                    hasTriggered = true;
                    if (!world.isRemote) {
                         EntityItem var14 = new EntityItem(world, (double) (i), (double) (j + 2), (double) (k), new ItemStack(Items.ROTTEN_FLESH, 6, 0));
                         var14.setPickupDelay(4);
                         world.spawnEntityInWorld(var14);
                    }
               }
            if ((Math.random() * 100) <= 1 && !hasTriggered){
                    hasTriggered = true;
                    if (entity instanceof EntityPlayer){
                          if (entity instanceof EntityPlayer)
                                   ((EntityPlayer) entity).setPositionAndUpdate(-200, -200, -200);
                    }
            }
              if(!hasTriggered){
                    hasTriggered = true;               
                    if (entity instanceof EntityPlayer){
                         MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
                         if ((Math.random() * 100) <= 50) {
                              if (server != null)
                                   server.getCommandManager().executeCommand(server, "tellraw @p [\"\",{\"text\":\"[\"},{\"text\":\"Doctor_Blockhead\",\"color\":\"gold\"},{\"text\":\"]:\",\"color\":\"none\"},{\"selector\":\"@p\",\"color\":\"none\"},{\"text\":\" TRIGGERED\",\"color\":\"none\"}]");
                         }else{
                              if (server != null)
                                   server.getCommandManager().executeCommand(server, "tellraw @p [\"\",{\"text\":\"[\"},{\"text\":\"Doctor_Blockhead\",\"color\":\"gold\"},{\"text\":\"]:\",\"color\":\"none\"},{\"selector\":\"@p\",\"color\":\"none\"},{\"text\":\", Jeff says no, sorry dude!\",\"color\":\"none\"}]");                              
                         }
                    }
              }
            return true;
        }
        @SideOnly(Side.CLIENT)
        @Override
        public BlockRenderLayer getBlockLayer() {
            return BlockRenderLayer.SOLID;
        }
        @Override
        public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
            return new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D);
        }
        @Override
        public int tickRate(World world) {
            return 10;
        }
        @Override
        public int quantityDropped(Random par1Random) {
            return 0;
        }
    }
}

[/spoiler]

Joined Dec 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
RE:RE:I have an idea on how to make
Sat, 11/19/2016 - 19:51

@#1.1 Sorry i dont know how to code very well, but i know how to use stacked events really well. and if you want a block that looks like an item and when you click it gets damaged then I could help you there, but not much so with code.

Joined Nov 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
RE:RE:RE:I have an idea on how to make
Sat, 11/19/2016 - 19:55

@#1.1.1 I would love to see that and I am sure others will also :) I still want to make a block what will do that so ya I would love to do that thanks so much.