@Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) { ItemStack stack = player.getHeldItem(hand); //Not entirely convinced it works RayTraceResult result = world.isRemote ? RayTraceHelper.tracePlayerHighlight((EntityPlayerSP) player) : RayTraceHelper.tracePlayerHighlight((EntityPlayerMP) player); if(result.typeOfHit != RayTraceResult.Type.BLOCK) { if(!world.isRemote) { Vector3 vec = Vector3.create(player.posX, player.posY + player.getEyeHeight(), player.posZ); vec.add(Vector3.create(player.getLookVec()).multiply(2.5D)); BlockPos pos = new BlockPos(vec.toVec3d()); IBlockState replaced = world.getBlockState(pos); if(world.isAirBlock(pos) || replaced.getBlock().isReplaceable(world, pos)) { IBlockState state = ModBlocks.ANGSTROM.getDefaultState(); SoundType type = ModBlocks.ANGSTROM.getSoundType(state, world, pos, player); world.setBlockState(pos, state); world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), type.getPlaceSound(), SoundCategory.BLOCKS, 0.75F, 0.8F); } if(!player.capabilities.isCreativeMode) { stack.shrink(1); } } return ActionResult.newResult(EnumActionResult.SUCCESS, stack); } return ActionResult.newResult(EnumActionResult.PASS, stack); }
public BlockWopper(String name){ super(Material.WOOD); this.setRegistryName(name); GameRegistry.register(this); ItemBlock item = new ItemBlock(this); item.setRegistryName(name); GameRegistry.register(item); this.setUnlocalizedName(Wopper.MOD_ID+"."+name); this.setHardness(5F); this.setHarvestLevel("axe", 0); this.setCreativeTab(CreativeTabs.REDSTONE); this.setSoundType(SoundType.WOOD); }
@Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { ItemStack stack = player.getHeldItem(hand); boolean isBlock = stack.getItem() instanceof ItemBlock && stack.getItem() != ModItems.ANGSTROM; if(!world.isRemote && isBlock) { //Replace ItemBlock item = (ItemBlock) stack.getItem(); Block block = Block.getBlockFromItem(item); int meta = item.getMetadata(stack); IBlockState inState = block.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, meta, player, hand); world.setBlockState(pos, inState); block.onBlockPlacedBy(world, pos, inState, player, stack); SoundType sound = block.getSoundType(inState, world, pos, player); world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), sound.getPlaceSound(), SoundCategory.BLOCKS, 0.75F, 0.8F); //Exchange ItemStack drop = new ItemStack(Item.getItemFromBlock(this)); ItemHandlerHelper.giveItemToPlayer(player, drop); if(!player.capabilities.isCreativeMode) { stack.shrink(1); } } return isBlock; }
public BlockRubberSlab() { super(Material.WOOD, MapColor.WOOD); IBlockState iblockstate = this.blockState.getBaseState(); if (!this.isDouble()) { iblockstate = iblockstate.withProperty(HALF, BlockSlab.EnumBlockHalf.BOTTOM); setRegistryName(new ResourceLocation(TRConstants.MOD_ID, "rubber_slab")); } else { setRegistryName(new ResourceLocation(TRConstants.MOD_ID, "rubber_double_slab")); } setCreativeTab(TechRebornCreativeTab.TECHREBORN); setUnlocalizedName(getRegistryName().toString()); setHarvestLevel("axe", 0); setHardness(2.0F); setResistance(15); setSoundType(SoundType.WOOD); TechReborn.blockModelsToRegister.add(this); this.setDefaultState(iblockstate.withProperty(VARIANT, BlockRubberSlab.Variant.DEFAULT)); }
public BlockWoodSlab(WoodMaterial wd) { super(Material.WOOD); this.setSoundType(SoundType.WOOD); this.wood = wd; this.blockHardness = wood.getPlankBlockHardness(); this.blockResistance = wood.getBlastResistance(); this.setHarvestLevel("axe", wood.getRequiredHarvestLevel()); Blocks.FIRE.setFireInfo(this, 5, 20); IBlockState iblockstate = this.blockState.getBaseState(); if (!this.isDouble()) { iblockstate = iblockstate.withProperty(HALF, BlockSlab.EnumBlockHalf.BOTTOM); } this.setDefaultState(iblockstate.withProperty(VARIANT, BlockWoodSlab.Variant.DEFAULT)); this.useNeighborBrightness = !this.isDouble(); }
public BlockPlanks(WoodMaterial wood) { super(Material.WOOD); this.setSoundType(SoundType.WOOD); this.fullBlock = true; this.lightOpacity = 255; this.translucent = false; this.wood = wood; this.oreDict = "plank" + wood.getCapitalizedName(); this.blockHardness = wood.getPlankBlockHardness(); this.blockResistance = wood.getBlastResistance(); this.setHarvestLevel("axe", wood.getRequiredHarvestLevel()); this.setDefaultState(this.blockState.getBaseState()); Blocks.FIRE.setFireInfo(this, 5, 20); this.setRegistryName(wood.getName() + "_planks"); }
private boolean tryPlace(EntityPlayer player, ItemStack stack, World worldIn, BlockPos pos, int subtype) { IBlockState iblockstate = worldIn.getBlockState(pos); if (iblockstate.getBlock() == this.singleSlab) { int subtype1 = singleSlabCS.getSubtype(iblockstate); if (subtype1 == subtype) { IBlockState stateDouble = this.makeState(subtype1); AxisAlignedBB axisalignedbb = stateDouble == null ? Block.NULL_AABB : stateDouble.getCollisionBoundingBox(worldIn, pos); if (stateDouble != null && axisalignedbb != Block.NULL_AABB && worldIn.checkNoEntityCollision(axisalignedbb.offset(pos)) && worldIn.setBlockState(pos, stateDouble, 11)) { SoundType soundtype = stateDouble.getBlock().getSoundType(stateDouble, worldIn, pos, player); worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F); stack.shrink(1); } return true; } } return false; }
public BlockLattice (String registryName, String unlocalizedName) { super(Material.IRON); setRegistryName(registryName); setUnlocalizedName(unlocalizedName); setCreativeTab(ModCreativeTabs.tabGardenStuff); setHardness(2.5f); setResistance(5); setSoundType(SoundType.METAL); setDefaultState(blockState.getBaseState() .withProperty(NORTH, Connection.NONE) .withProperty(EAST, Connection.NONE) .withProperty(SOUTH, Connection.NONE) .withProperty(WEST, Connection.NONE) .withProperty(UP, Connection.NONE) .withProperty(DOWN, Connection.NONE) .withProperty(VARIANT, Variant.IRON) ); }
public PatternMolderBlock() { super(Material.IRON); setUnlocalizedName(Defier.MODID + ".patternmolder"); setRegistryName("patternmolder"); setHardness(3.0F); setResistance(5.0F); setSoundType(SoundType.METAL); setHarvestLevel("pickaxe", 1); setCreativeTab(Defier.CTAB); }
/** * Creates a simple ore. * @param name * @param hardness * @param resistance * @param lightValue * @param harvestLevel */ public BlockOre(String name, float hardness, float resistance, float lightValue, int harvestLevel) { super(Material.ROCK, name); this.setCreativeTab(ModTabs.tabLE); this.setSoundType(SoundType.STONE); this.setHardness(hardness); this.setResistance(resistance); this.setLightLevel(lightValue); this.setHarvestLevel("pickaxe", harvestLevel); }
public BlockSlimeBlock() { super(Material.ROCK); setUnlocalizedName("slimeBlock"); setHardness(1.5F); setSoundType(SoundType.STONE); setHarvestLevel("pickaxe", 1); setResistance(10); setCreativeTab(CreativeTabsLoader.tabEasyCraft); }
public BlockBarrel() { super(Material.WOOD); setRegistryName(new ResourceLocation(TRConstants.MOD_ID, "barrel")); setCreativeTab(TechRebornCreativeTab.TECHREBORN); setUnlocalizedName(getRegistryName().toString()); setHarvestLevel("axe", 0); setHardness(2.0F); setResistance(10); setSoundType(SoundType.WOOD); TechReborn.blockModelsToRegister.add(this); }
public ContentBlockSnow() { opacity = Attribute.constant(0); isOpaqueCube = Attribute.constant(false); isFullCube = Attribute.constant(false); soundType = Attribute.constant(SoundType.SNOW); harvestTool = Attribute.constant("shovel"); harvestLevel = Attribute.constant(0); }
public BasicBlock(CreativeTabs creativeTab, Material material, String blockName, float hardness, SoundType soundType) { super(material); name = blockName; setUnlocalizedName(name); setHardness(hardness); setRegistryName(name); setCreativeTab(creativeTab); setSoundType(soundType); }
@Override protected boolean doBlockInteraction(BlockPos pos, double distToBlock) { if (drone.getPathNavigator().hasNoPath()) { EnumFacing side = ProgWidgetPlace.getDirForSides(((ISidedWidget) widget).getSides()); for (int i = 0; i < drone.getInv().getSlots(); i++) { ItemStack droneStack = drone.getInv().getStackInSlot(i); if (droneStack.getItem() instanceof ItemBlock && ((ItemBlock) droneStack.getItem()).getBlock().canPlaceBlockOnSide(drone.world(), pos, ProgWidgetPlace.getDirForSides(((ISidedWidget) widget).getSides()))) { if (widget.isItemValidForFilters(droneStack)) { ItemBlock itemBlock = (ItemBlock) droneStack.getItem(); Block block = itemBlock.getBlock(); if (drone.world().mayPlace(block, pos, false, side, drone instanceof EntityDrone ? (EntityDrone) drone : null)) { int newMeta = itemBlock.getMetadata(droneStack.getMetadata()); setFakePlayerAccordingToDir(); IBlockState iblockstate1 = block.getStateForPlacement(drone.world(), pos, side, side.getFrontOffsetX(), side.getFrontOffsetY(), side.getFrontOffsetZ(), newMeta, drone.getFakePlayer(), EnumHand.MAIN_HAND); if (itemBlock.placeBlockAt(droneStack, drone.getFakePlayer(), drone.world(), pos, side, side.getFrontOffsetX(), side.getFrontOffsetY(), side.getFrontOffsetZ(), iblockstate1)) { drone.addAir(null, -PneumaticValues.DRONE_USAGE_PLACE); SoundType soundType = block.getSoundType(iblockstate1, drone.world(), pos, drone.getFakePlayer()); drone.world().playSound(pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F, soundType.getPlaceSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F, false); droneStack.shrink(1); if (droneStack.getCount() <= 0) { drone.getInv().setStackInSlot(i, ItemStack.EMPTY); } } return false; } } } } return false; } else { return true; } }
public BlockMicroscope() { super("microscope", Material.IRON); setHarvestLevel("pickaxe", 0); setHardness(1.2f); setSoundType(SoundType.METAL); }
private boolean interact(PlayerInteractEvent.RightClickBlock event, ItemStack curItem, BlockPos pos){ ISemiBlock newBlock = ((ISemiBlockItem) curItem.getItem()).getSemiBlock(event.getWorld(), pos, curItem); newBlock.initialize(event.getWorld(), pos); newBlock.prePlacement(event.getEntityPlayer(), curItem, event.getFace()); Stream<ISemiBlock> existingSemiblocks = getSemiBlocks(event.getWorld(), pos); List<ISemiBlock> collidingBlocks = existingSemiblocks.filter(s -> !s.canCoexistInSameBlock(newBlock)).collect(Collectors.toList()); if (!collidingBlocks.isEmpty()) { for(ISemiBlock collidingBlock : collidingBlocks){ if (event.getEntityPlayer().capabilities.isCreativeMode) { removeSemiBlock(collidingBlock); } else { breakSemiBlock(collidingBlock, event.getEntityPlayer()); } } return true; } else { if (newBlock.canPlace(event.getFace())) { addSemiBlock(event.getWorld(), pos, newBlock); newBlock.onPlaced(event.getEntityPlayer(), curItem, event.getFace()); event.getWorld().playSound(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, SoundType.GLASS.getPlaceSound(), SoundCategory.BLOCKS, (SoundType.GLASS.getVolume() + 1.0F) / 2.0F, SoundType.GLASS.getPitch() * 0.8F, false); if (!event.getEntityPlayer().capabilities.isCreativeMode) { curItem.shrink(1); if (curItem.getCount() <= 0) event.getEntityPlayer().setHeldItem(event.getHand(), ItemStack.EMPTY); } return true; } } return false; }
public HeroHead() { super(Material.ROCK); this.blockHardness = 4F; this.blockResistance = 20F; this.setSoundType(SoundType.CLOTH); this.setLightLevel(0.9F); this.blockParticleGravity = 0.1F; this.setHarvestLevel("pickaxe", 3); }
public BlockWickerBasket() { super(Material.WOOD); setCreativeTab(ModMain.tabBetterBeginnings); setHardness(1.25F); setSoundType(SoundType.WOOD); }
public blockRamen() { super(Material.PORTAL); setUnlocalizedName(Reference.RTAPBlocks.BLOCKRAMEN.getUnlocalizedName()); setRegistryName(Reference.RTAPBlocks.BLOCKRAMEN.getRegistryName()); setCreativeTab(Reference.tabRTAP); setHardness(1F); setResistance(1.5F); setSoundType(SoundType.SLIME); }
public blockBologna() { super(Material.SPONGE); setUnlocalizedName(Reference.RTAPBlocks.BLOCKBOLOGNA.getUnlocalizedName()); setRegistryName(Reference.RTAPBlocks.BLOCKBOLOGNA.getRegistryName()); setCreativeTab(Reference.tabRTAP); setHardness(1F); setResistance(1F); setSoundType(SoundType.SLIME); }
public BlockHourglass() { super("hourglass", Material.IRON); setSoundType(SoundType.GLASS); setHardness(1.0F); setTickRandomly(true); GameRegistry.register(new ItemBlockHourglass(this), getRegistryName()); }
public BlockPot() { super(Material.ROCK); setLightLevel(0.0f); setHardness(8f); setSoundType(SoundType.STONE); setCreativeTab(ExSartagineItems.pots); setHarvestLevel("pickaxe", 1); setUnlocalizedName(ExSartagine.MODID+".pot"); setRegistryName("pot"); setHardness(3.5f); this.setLightOpacity(0); this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(FULL, false)); }
public BlockSmelter() { super(Material.ROCK); setLightLevel(0.0f); setHardness(8f); setSoundType(SoundType.STONE); setCreativeTab(ExSartagineItems.pots); setHarvestLevel("pickaxe", 1); setUnlocalizedName(ExSartagine.MODID+".smelter"); setRegistryName("smelter"); setHardness(3.5f); this.setLightOpacity(0); this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(FULL, false)); }
public BlockPan() { super(Material.IRON); setLightLevel(0.0f); setSoundType(SoundType.METAL); setCreativeTab(ExSartagineItems.pots); setHarvestLevel("pickaxe", 1); setUnlocalizedName(ExSartagine.MODID+".pan"); setRegistryName("pan"); setHardness(3.5f); this.setLightOpacity(0); }
@Override public void initBlock() { this.setHardness(1); this.setRegistryName(ExPRegistryNames.asLocation(this.shrubState == EnumShrubState.BLOOMING ? ExPRegistryNames.blockBerryBushBerries : this.shrubState == EnumShrubState.AUTUMN ? ExPRegistryNames.blockBerryBushAutumn : this.shrubState == EnumShrubState.DEAD ? ExPRegistryNames.blockBerryBushDead : ExPRegistryNames.blockBerryBushNormal)); this.setResistance(0); this.setSoundType(SoundType.PLANT); this.setUnlocalizedName(this.getRegistryName().toString().replace(':', '.')); this.setDefaultState(this.blockState.getBaseState().withProperty(ExPBlockProperties.BERRY_BUSH_TYPE, EnumBerry.BLACKBERRY).withProperty(ExPBlockProperties.SHRUB_IS_TALL, false)); this.setCreativeTab(ExPCreativeTabs.tabPlantlife); this.setTickRandomly(true); Blocks.FIRE.setFireInfo(this, 60, 100); }
@SuppressWarnings("deprecation") public BlockFakeIce() { super(LibBlockName.FAKE_ICE, Material.ICE); setSound(SoundType.STONE); setResistance(2F); setHardness(2F); slipperiness = 0.98F; }
@Override public void initBlock() { this.setHardness(3); this.setRegistryName(ExPRegistryNames.asLocation(ExPRegistryNames.blockOre)); this.setResistance(10); this.setSoundType(SoundType.STONE); this.setUnlocalizedName(this.getRegistryName().toString().replace(':', '.')); this.setDefaultState(this.blockState.getBaseState().withProperty(ROCK_CLASS, ANDESITE).withProperty(ExPBlockProperties.ORE_TEXTURE_ID, 0)); this.setCreativeTab(ExPCreativeTabs.tabOres); }
public BlockModSapling(String id) { setUnlocalizedName(id); setRegistryName(LibMod.MOD_ID, id); setCreativeTab(BewitchmentCreativeTabs.PLANTS_CREATIVE_TAB); this.setTickRandomly(true); this.setSoundType(SoundType.PLANT); this.setDefaultState(blockState.getBaseState().withProperty(STAGE, 0).withProperty(TYPE, EnumSaplingType.ELDER)); }
public BlockMoonbell() { super("moonbell"); MinecraftForge.EVENT_BUS.register(this); this.setLightOpacity(16).setLightLevel(0.5f).setTickRandomly(true); this.setDefaultState(this.blockState.getBaseState().withProperty(placed, false)); this.setSoundType(SoundType.PLANT); }
public BlockDoubleWorkbench() { super(Material.WOOD); setSoundType(SoundType.WOOD); setCreativeTab(ModMain.tabBetterBeginnings); setDefaultState(blockState.getBaseState().withProperty(CONNECTION, EnumFacing.UP)); setHardness(2.0f); setResistance(5.0f); }
public BlockEmberGrass() { super(LibBlockName.EMBER_GRASS, Material.PLANTS); setResistance(0.1F); setHardness(0.1F); setSound(SoundType.PLANT); this.setLightLevel(0.1F); this.setTickRandomly(true); setCreativeTab(BewitchmentCreativeTabs.PLANTS_CREATIVE_TAB); }
@Nonnull public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { IBlockState iblockstate = worldIn.getBlockState(pos); Block block = iblockstate.getBlock(); Block cake = Block.REGISTRY.getObject(new ResourceLocation(FoodCraftReloaded.MODID, NameBuilder.buildRegistryName(vegetableType.toString(), "cake"))); if (block == Blocks.SNOW_LAYER && iblockstate.getValue(BlockSnow.LAYERS) < 1) facing = EnumFacing.UP; else if (!block.isReplaceable(worldIn, pos)) pos = pos.offset(facing); ItemStack itemstack = player.getHeldItem(hand); if (!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(cake, pos, false, facing, null)) { IBlockState blockState = cake.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, 0, player, hand); if (!worldIn.setBlockState(pos, blockState, 11)) return EnumActionResult.FAIL; else { blockState = worldIn.getBlockState(pos); if (blockState.getBlock() == cake) { ItemBlock.setTileEntityNBT(worldIn, player, pos, itemstack); blockState.getBlock().onBlockPlacedBy(worldIn, pos, blockState, player, itemstack); } SoundType soundtype = blockState.getBlock().getSoundType(blockState, worldIn, pos, player); worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F); itemstack.shrink(1); return EnumActionResult.SUCCESS; } } else return EnumActionResult.FAIL; }
public BlockTorchwood() { super(LibBlockName.TORCHWOOD, Material.WOOD); setResistance(0.3F); setHardness(0.3F); setSound(SoundType.WOOD); this.setLightLevel(0.7F); this.setTickRandomly(true); setCreativeTab(BewitchmentCreativeTabs.PLANTS_CREATIVE_TAB); }
@Test public void test_clay() { Map<String, SoundType> map = gson.fromJson("{ \"sound\": \"glass\" }", new TypeToken<Map<String, SoundType>>() {}.getType()); SoundType sound = map.get("sound"); assertNotNull(sound); assertSame(SoundType.GLASS, sound); }
public BlockOldGrass() { setRegistryName("oldgrass"); setUnlocalizedName(UniqueCrops.MOD_ID + ".oldgrass"); setCreativeTab(UniqueCrops.TAB); setSoundType(SoundType.PLANT); setHardness(0.6F); setTickRandomly(true); GameRegistry.register(this); GameRegistry.register(new ItemBlock(this), getRegistryName()); }
@Override public void initBlock() { this.setHardness(0.2f); this.setResistance(0); this.setRegistryName(ExPRegistryNames.asLocation(ExPRegistryNames.blockPebble)); this.setSoundType(SoundType.STONE); this.setUnlocalizedName(this.getRegistryName().toString().replace(':', '.')); this.setDefaultState(this.blockState.getBaseState().withProperty(ROCK_CLASS, ANDESITE).withProperty(MODEL_INDEX, 0)); this.setCreativeTab(ExPCreativeTabs.tabUnderground); }
public BlockTranslationDesk() { super("translation_desk", Material.WOOD); setHarvestLevel("axe", 0); setHardness(1.7f); setSoundType(SoundType.WOOD); }
public BlockTeaTrunk(String name, boolean addToTab) { super(Material.WOOD); this.setSoundType(SoundType.WOOD); setHarvestLevel("axe",-1); setHardness(1.8f); setUnlocalizedName(name); setRegistryName(SimplyTea.MODID+":"+name); if (addToTab){ setCreativeTab(SimplyTea.tab); } this.setTickRandomly(true); itemBlock = (new ItemBlock(this).setRegistryName(this.getRegistryName())); }
public BlockPedestal() { super(Material.ROCK); this.setRegistryName("pedestal"); this.setUnlocalizedName(Infernum.MODID + ".pedestal"); GameRegistry.register(this); GameRegistry.register(new ItemBlock(this), getRegistryName()); setCreativeTab(Infernum.tab); setSoundType(SoundType.STONE); setHardness(0.8F); }