use of net.minecraftforge.fluids.IFluidBlock in project MinecraftForge by MinecraftForge.
the class ForgeHooks method isInsideOfMaterial.
public static boolean isInsideOfMaterial(Material material, Entity entity, BlockPos pos) {
IBlockState state = entity.world.getBlockState(pos);
Block block = state.getBlock();
double eyes = entity.posY + (double) entity.getEyeHeight();
//If it's not a liquid assume it's a solid block
double filled = 1.0f;
if (block instanceof IFluidBlock) {
filled = ((IFluidBlock) block).getFilledPercentage(entity.world, pos);
} else if (block instanceof BlockLiquid) {
filled = BlockLiquid.getLiquidHeightPercent(block.getMetaFromState(state));
}
if (filled < 0) {
filled *= -1;
//filled -= 0.11111111F; //Why this is needed.. not sure...
return eyes > pos.getY() + 1 + (1 - filled);
} else {
return eyes < pos.getY() + 1 + filled;
}
}
use of net.minecraftforge.fluids.IFluidBlock in project MinecraftForge by MinecraftForge.
the class DynBucketTest method onBucketFill.
@SubscribeEvent
public void onBucketFill(FillBucketEvent event) {
RayTraceResult target = event.getTarget();
if (target != null) {
IBlockState state = event.getWorld().getBlockState(target.getBlockPos());
if (state.getBlock() instanceof IFluidBlock) {
Fluid fluid = ((IFluidBlock) state.getBlock()).getFluid();
FluidStack fs = new FluidStack(fluid, Fluid.BUCKET_VOLUME);
ItemStack bucket = event.getEmptyBucket();
IFluidHandlerItem fluidHandler = FluidUtil.getFluidHandler(bucket);
if (fluidHandler != null) {
int fillAmount = fluidHandler.fill(fs, true);
if (fillAmount > 0) {
ItemStack filledBucket = fluidHandler.getContainer();
event.setFilledBucket(filledBucket);
event.setResult(Result.ALLOW);
}
}
}
}
}
use of net.minecraftforge.fluids.IFluidBlock in project Witchworks by Um-Mitternacht.
the class CommonRegistration method registerItems.
@SubscribeEvent
public static void registerItems(RegistryEvent.Register<Item> event) {
final IForgeRegistry<Item> registry = event.getRegistry();
//Crops
registerCrop(ACONITUM, new ItemAconitum(), LibItemName.SEED_ACONITUM);
registerCrop(ASPHODEL, new ItemAsphodel(), LibItemName.SEED_ASPHODEL);
registerCrop(BELLADONNA, new ItemBelladonna(), LibItemName.SEED_BELLADONNA);
registerCrop(GINGER, new ItemGinger(), LibItemName.SEED_GINGER);
registerCrop(KELP, new ItemKelp(), new ItemKelpSeed());
registerCrop(MINT, new ItemCrop(LibItemName.MINT, 1, 2F, false), LibItemName.SEED_MINT);
registerCrop(WHITE_SAGE, new ItemCrop(LibItemName.WHITE_SAGE, 1, 0.4F, false), LibItemName.SEED_WHITE_SAGE);
registerCrop(MANDRAKE, new ItemCrop(LibItemName.MANDRAKE, 4, 6F, false), LibItemName.SEED_MANDRAKE);
registerCrop(LAVENDER, new ItemLavender(), LibItemName.SEED_LAVENDER);
registerCrop(THISTLE, new ItemThistle(), LibItemName.SEED_THISTLE);
registerCrop(TULSI, new ItemCrop(LibItemName.TULSI, 1, 0.4F, false), LibItemName.SEED_TULSI);
registerCrop(KENAF, new ItemCrop(LibItemName.KENAF, 4, 6F, false), LibItemName.SEED_KENAF);
registerCrop(SILPHIUM, new ItemCrop(LibItemName.SILPHIUM, 4, 6F, false), LibItemName.SEED_SILPHIUM);
registerCrop(GARLIC, new ItemCrop(LibItemName.GARLIC, 4, 6F, false), LibItemName.SEED_GARLIC);
registerCrop(WORMWOOD, new ItemCrop(LibItemName.WORMWOOD, 4, 0.8F, false), LibItemName.SEED_WORMWOOD);
CropRegistry.getFoods().forEach((crop, item) -> registry.register(item));
CropRegistry.getSeeds().forEach((crop, item) -> registry.register(item));
//Normal Items
registry.registerAll(//Gems
new ItemMod(LibItemName.GARNET), new ItemMod(LibItemName.MOLDAVITE), new ItemMod(LibItemName.NUUMMITE), new ItemMod(LibItemName.TIGERS_EYE), new ItemMod(LibItemName.TOURMALINE), new ItemMod(LibItemName.BLOODSTONE), new ItemMod(LibItemName.JASPER), new ItemMod(LibItemName.GEMSTONE_AMALGAM), new ItemMod(LibItemName.MALACHITE), new ItemMod(LibItemName.AMETHYST), new ItemMod(LibItemName.ALEXANDRITE), new ItemMod(LibItemName.SILVER_POWDER), new ItemMod(LibItemName.SILVER_INGOT), new ItemMod(LibItemName.SILVER_NUGGET), //Other
new ItemHoney(), new ItemSalt(), new ItemMod(LibItemName.WAX), new ItemMod(LibItemName.BEE).setMaxDamage(35), new ItemMod(LibItemName.HONEYCOMB), new ItemMod(LibItemName.EMPTY_HONEYCOMB), new ItemMod(LibItemName.MORTAR_AND_PESTLE), new ItemMod(LibItemName.UNREFINED_CHALK), new ItemBrewDrink(), new ItemBrewSplash(), new ItemBrewLinger(), new ItemMod(LibItemName.GLASS_JAR), //Tools
new ItemSilverPickaxe(), new ItemSilverAxe(), new ItemSilverSpade(), new ItemSilverHoe(), new ItemSilverSword(), new ItemAthame(), new ItemBoline(), new ItemTaglock(), new ItemMod(LibItemName.CHALK_ITEM), new ItemMod(LibItemName.NEEDLE_BONE), //Books
new ItemShadowBook(), new ItemDustyGrimoire(), //Equipment
new ItemSilverArmor(LibItemName.SILVER_HELMET, ModMaterials.ARMOR_SILVER, 1, EntityEquipmentSlot.HEAD), new ItemSilverArmor(LibItemName.SILVER_CHESTPLATE, ModMaterials.ARMOR_SILVER, 1, EntityEquipmentSlot.CHEST), new ItemSilverArmor(LibItemName.SILVER_LEGGINGS, ModMaterials.ARMOR_SILVER, 2, EntityEquipmentSlot.LEGS), new ItemSilverArmor(LibItemName.SILVER_BOOTS, ModMaterials.ARMOR_SILVER, 1, EntityEquipmentSlot.FEET));
//Item Blocks
registry.registerAll(itemBlock(ModBlocks.CROP_ACONITUM), itemBlock(ModBlocks.CROP_ASPHODEL), itemBlock(ModBlocks.CROP_BELLADONNA), itemBlock(ModBlocks.CROP_GINGER), itemBlock(ModBlocks.CROP_KELP), itemBlock(ModBlocks.CROP_MINT), itemBlock(ModBlocks.CROP_SILPHIUM), itemBlock(ModBlocks.CROP_WHITE_SAGE), itemBlock(ModBlocks.CROP_MANDRAKE), itemBlock(ModBlocks.CROP_LAVENDER), itemBlock(ModBlocks.CROP_THISTLE), itemBlock(ModBlocks.CROP_TULSI), itemBlock(ModBlocks.CROP_KENAF), itemBlock(ModBlocks.CROP_GARLIC), itemBlock(ModBlocks.CROP_WORMWOOD), itemBlock(ModBlocks.SILVER_BLOCK), itemBlock(ModBlocks.MOLDAVITE_BLOCK), itemBlock(ModBlocks.COQUINA), itemBlock(ModBlocks.BLOODSTONE_BLOCK), itemBlock(ModBlocks.KETTLE), itemBlock(ModBlocks.ALTAR), itemBlock(ModBlocks.APIARY), itemBlock(ModBlocks.BEEHIVE), itemBlock(ModBlocks.SILVER_ORE), itemBlock(ModBlocks.MOLDAVITE_ORE), itemBlock(ModBlocks.MALACHITE_ORE), itemBlock(ModBlocks.BLOODSTONE_ORE), itemBlock(ModBlocks.TIGERS_EYE_ORE), itemBlock(ModBlocks.NUUMMITE_ORE), itemBlock(ModBlocks.JASPER_ORE), itemBlock(ModBlocks.GARNET_ORE), itemBlock(ModBlocks.TOURMALINE_ORE), itemBlock(ModBlocks.TOURMALINE_BLOCK), itemBlock(ModBlocks.SALT_ORE), itemBlock(ModBlocks.AMETHYST_ORE), itemBlock(ModBlocks.ALEXANDRITE_ORE), itemBlock(ModBlocks.NETHERSTEEL), new ItemBlockColor(ModBlocks.CANDLE_LARGE), new ItemBlockColor(ModBlocks.CANDLE_MEDIUM), new ItemBlockColor(ModBlocks.CANDLE_SMALL), itemBlock(ModBlocks.SALT_BARRIER), itemBlock(ModBlocks.CHALK));
for (final IFluidBlock fluidBlock : Fluids.MOD_FLUID_BLOCKS) {
registry.register(itemBlock((Block) fluidBlock));
}
}
use of net.minecraftforge.fluids.IFluidBlock in project ICBM-Classic by BuiltBrokenModding.
the class BlastSonic method doPreExplode.
@Override
public void doPreExplode() {
if (!this.world().isRemote) {
if (this.hasShockWave) {
for (int x = (int) (-this.getRadius() * 2); x < this.getRadius() * 2; ++x) {
for (int y = (int) (-this.getRadius() * 2); y < this.getRadius() * 2; ++y) {
for (int z = (int) (-this.getRadius() * 2); z < this.getRadius() * 2; ++z) {
Location targetPosition = position.add(new Pos(x, y, z));
Block blockID = world().getBlock(targetPosition.xi(), targetPosition.yi(), targetPosition.zi());
if (blockID != Blocks.air) {
Material material = blockID.getMaterial();
if (blockID != Blocks.bedrock && !(material.isLiquid()) && (blockID.getExplosionResistance(this.exploder, world(), targetPosition.xi(), targetPosition.yi(), targetPosition.zi(), position.xi(), position.yi(), position.zi()) > this.nengLiang || material == Material.glass)) {
targetPosition.setBlock(world(), Blocks.air);
}
}
}
}
}
}
this.thread = new ThreadLargeExplosion(this.position, (int) this.getRadius(), this.nengLiang, this.exploder, new IThreadCallBack() {
@Override
public float getResistance(World world, IPos3D explosionPosition, IPos3D targetPosition, Entity source, Block block) {
float resistance = 0;
if (block instanceof BlockLiquid || block instanceof IFluidBlock) {
resistance = 1f;
} else {
resistance = block.getExplosionResistance(source, world, (int) targetPosition.x(), (int) targetPosition.y(), (int) targetPosition.z(), explosionPosition.x(), explosionPosition.y(), explosionPosition.z());
}
return resistance;
}
});
this.thread.start();
}
if (this.hasShockWave) {
this.world().playSoundEffect(position.x(), position.y(), position.z(), ICBMClassic.PREFIX + "hypersonic", 4.0F, (1.0F + (this.world().rand.nextFloat() - this.world().rand.nextFloat()) * 0.2F) * 0.7F);
} else {
this.world().playSoundEffect(position.x(), position.y(), position.z(), ICBMClassic.PREFIX + "sonicwave", 4.0F, (1.0F + (this.world().rand.nextFloat() - this.world().rand.nextFloat()) * 0.2F) * 0.7F);
}
}
use of net.minecraftforge.fluids.IFluidBlock in project ICBM-Classic by BuiltBrokenModding.
the class BlastRedmatter method doDestroyBlocks.
protected void doDestroyBlocks() {
// Try to find and grab some blocks to orbit
int blocksDestroyed = 0;
for (int currentRadius = 1; currentRadius < getRadius(); currentRadius++) {
for (int xr = -currentRadius; xr < currentRadius; xr++) {
for (int yr = -currentRadius; yr < currentRadius; yr++) {
for (int zr = -currentRadius; zr < currentRadius; zr++) {
final Location currentPos = position.add(xr, yr, zr);
final double dist = position.distance(currentPos);
//We are looping in a shell orbit around the center
if (dist < currentRadius && dist > currentRadius - 2) {
final Block block = currentPos.getBlock();
//Null if call was made on an unloaded chunk
if (block != null) {
int meta = currentPos.getBlockMetadata();
//Ignore air blocks and unbreakable blocks
if (!block.isAir(world(), currentPos.xi(), currentPos.yi(), currentPos.zi()) && block.getBlockHardness(this.world(), currentPos.xi(), currentPos.yi(), currentPos.zi()) >= 0) {
//TODO handle multi-blocks
final boolean isFluid = block instanceof BlockLiquid || block instanceof IFluidBlock;
currentPos.setBlock(Blocks.air, 0, isFluid ? 0 : 3);
//TODO: render fluid streams moving into hole
if (!isFluid && doFlyingBlocks) {
//Convert a random amount of destroyed blocks into flying blocks for visuals
if (this.world().rand.nextFloat() > 0.8) {
EntityFlyingBlock entity = new EntityFlyingBlock(this.world(), currentPos.add(0.5D), block, meta);
entity.yawChange = 50 * this.world().rand.nextFloat();
entity.pitchChange = 50 * this.world().rand.nextFloat();
this.world().spawnEntityInWorld(entity);
}
}
//Keep track of blocks removed to keep from lagging the game
blocksDestroyed++;
if (blocksDestroyed > this.MAX_BLOCKS_REMOVED_PER_TICK) {
return;
}
}
}
}
}
}
}
}
}
Aggregations