use of net.minecraft.block.FlowingFluidBlock in project dynmap by webbukkit.
the class DynmapExpCommand method initializeBlockStates.
/**
* Initialize block states (org.dynmap.blockstate.DynmapBlockState)
*/
/**
*/
public void initializeBlockStates() {
// Simple map - scale as needed
stateByID = new DynmapBlockState[512 * 32];
// Default to air
Arrays.fill(stateByID, DynmapBlockState.AIR);
ObjectIntIdentityMap<BlockState> bsids = Block.BLOCK_STATE_IDS;
DynmapBlockState basebs = null;
Block baseb = null;
int baseidx = 0;
Iterator<BlockState> iter = bsids.iterator();
DynmapBlockState.Builder bld = new DynmapBlockState.Builder();
while (iter.hasNext()) {
BlockState bs = iter.next();
int idx = bsids.getId(bs);
if (idx >= stateByID.length) {
int plen = stateByID.length;
// grow array by 10%
stateByID = Arrays.copyOf(stateByID, idx * 11 / 10);
Arrays.fill(stateByID, plen, stateByID.length, DynmapBlockState.AIR);
}
Block b = bs.getBlock();
// If this is new block vs last, it's the base block state
if (b != baseb) {
basebs = null;
baseidx = idx;
baseb = b;
}
ResourceLocation ui = b.getRegistryName();
if (ui == null) {
continue;
}
String bn = ui.getNamespace() + ":" + ui.getPath();
// Only do defined names, and not "air"
if (!bn.equals(DynmapBlockState.AIR_BLOCK)) {
Material mat = bs.getMaterial();
String statename = "";
for (net.minecraft.state.Property<?> p : bs.getProperties()) {
if (statename.length() > 0) {
statename += ",";
}
statename += p.getName() + "=" + bs.get(p).toString();
}
int lightAtten = 15;
try {
// Workaround for mods with broken block state logic...
lightAtten = bs.isOpaqueCube(EmptyBlockReader.INSTANCE, BlockPos.ZERO) ? 15 : (bs.propagatesSkylightDown(EmptyBlockReader.INSTANCE, BlockPos.ZERO) ? 0 : 1);
} catch (Exception x) {
Log.warning(String.format("Exception while checking lighting data for block state: %s[%s]", bn, statename));
Log.verboseinfo("Exception: " + x.toString());
}
// Log.info("statename=" + bn + "[" + statename + "], lightAtten=" + lightAtten);
// Fill in base attributes
bld.setBaseState(basebs).setStateIndex(idx - baseidx).setBlockName(bn).setStateName(statename).setMaterial(mat.toString()).setLegacyBlockID(idx).setAttenuatesLight(lightAtten);
if (mat.isSolid()) {
bld.setSolid();
}
if (mat == Material.AIR) {
bld.setAir();
}
if (mat == Material.WOOD) {
bld.setLog();
}
if (mat == Material.LEAVES) {
bld.setLeaves();
}
if ((!bs.getFluidState().isEmpty()) && !(bs.getBlock() instanceof FlowingFluidBlock)) {
bld.setWaterlogged();
}
// Build state
DynmapBlockState dbs = bld.build();
stateByID[idx] = dbs;
if (basebs == null) {
basebs = dbs;
}
}
}
for (int gidx = 0; gidx < DynmapBlockState.getGlobalIndexMax(); gidx++) {
DynmapBlockState bs = DynmapBlockState.getStateByGlobalIndex(gidx);
// Log.info(gidx + ":" + bs.toString() + ", gidx=" + bs.globalStateIndex + ", sidx=" + bs.stateIndex);
}
}
use of net.minecraft.block.FlowingFluidBlock in project dynmap by webbukkit.
the class DynmapExpCommand method initializeBlockStates.
/**
* Initialize block states (org.dynmap.blockstate.DynmapBlockState)
*/
public void initializeBlockStates() {
// Simple map - scale as needed
stateByID = new DynmapBlockState[512 * 32];
// Default to air
Arrays.fill(stateByID, DynmapBlockState.AIR);
ObjectIntIdentityMap<BlockState> bsids = Block.BLOCK_STATE_IDS;
DynmapBlockState basebs = null;
Block baseb = null;
int baseidx = 0;
Iterator<BlockState> iter = bsids.iterator();
DynmapBlockState.Builder bld = new DynmapBlockState.Builder();
while (iter.hasNext()) {
BlockState bs = iter.next();
int idx = bsids.get(bs);
if (idx >= stateByID.length) {
int plen = stateByID.length;
// grow array by 10%
stateByID = Arrays.copyOf(stateByID, idx * 11 / 10);
Arrays.fill(stateByID, plen, stateByID.length, DynmapBlockState.AIR);
}
Block b = bs.getBlock();
// If this is new block vs last, it's the base block state
if (b != baseb) {
basebs = null;
baseidx = idx;
baseb = b;
}
ResourceLocation ui = b.getRegistryName();
if (ui == null) {
continue;
}
String bn = ui.getNamespace() + ":" + ui.getPath();
// Only do defined names, and not "air"
if (!bn.equals(DynmapBlockState.AIR_BLOCK)) {
Material mat = bs.getMaterial();
String statename = "";
for (IProperty p : bs.getProperties()) {
if (statename.length() > 0) {
statename += ",";
}
statename += p.getName() + "=" + bs.get(p).toString();
}
int lightAtten = bs.isOpaqueCube(EmptyBlockReader.INSTANCE, BlockPos.ZERO) ? 15 : (bs.propagatesSkylightDown(EmptyBlockReader.INSTANCE, BlockPos.ZERO) ? 0 : 1);
// Log.info("statename=" + bn + "[" + statename + "], lightAtten=" + lightAtten);
// Fill in base attributes
bld.setBaseState(basebs).setStateIndex(idx - baseidx).setBlockName(bn).setStateName(statename).setMaterial(mat.toString()).setLegacyBlockID(idx).setAttenuatesLight(lightAtten);
if (mat.isSolid()) {
bld.setSolid();
}
if (mat == Material.AIR) {
bld.setAir();
}
if (mat == Material.WOOD) {
bld.setLog();
}
if (mat == Material.LEAVES) {
bld.setLeaves();
}
if ((!bs.getFluidState().isEmpty()) && !(bs.getBlock() instanceof FlowingFluidBlock)) {
bld.setWaterlogged();
}
// Build state
DynmapBlockState dbs = bld.build();
stateByID[idx] = dbs;
if (basebs == null) {
basebs = dbs;
}
}
}
for (int gidx = 0; gidx < DynmapBlockState.getGlobalIndexMax(); gidx++) {
DynmapBlockState bs = DynmapBlockState.getStateByGlobalIndex(gidx);
// Log.info(gidx + ":" + bs.toString() + ", gidx=" + bs.globalStateIndex + ", sidx=" + bs.stateIndex);
}
}
use of net.minecraft.block.FlowingFluidBlock in project Spackenmobs by ACGaming.
the class CustomSpawnEggItem method use.
public ActionResult<ItemStack> use(World worldIn, PlayerEntity playerIn, Hand handIn) {
ItemStack itemstack = playerIn.getItemInHand(handIn);
BlockRayTraceResult raytraceresult = getPlayerPOVHitResult(worldIn, playerIn, RayTraceContext.FluidMode.SOURCE_ONLY);
if (raytraceresult.getType() != RayTraceResult.Type.BLOCK) {
return ActionResult.pass(itemstack);
} else if (worldIn.isClientSide) {
return ActionResult.success(itemstack);
} else {
BlockPos blockpos = raytraceresult.getBlockPos();
if (!(worldIn.getBlockState(blockpos).getBlock() instanceof FlowingFluidBlock)) {
return ActionResult.pass(itemstack);
} else if (worldIn.mayInteract(playerIn, blockpos) && playerIn.mayUseItemAt(blockpos, raytraceresult.getDirection(), itemstack)) {
EntityType<?> entitytype = this.getType(itemstack.getTag());
if (entitytype.spawn((ServerWorld) worldIn, itemstack, playerIn, blockpos, SpawnReason.SPAWN_EGG, false, false) == null) {
return ActionResult.pass(itemstack);
} else {
if (!playerIn.abilities.instabuild) {
itemstack.shrink(1);
}
playerIn.awardStat(Stats.ITEM_USED.get(this));
return ActionResult.success(itemstack);
}
} else {
return ActionResult.fail(itemstack);
}
}
}
use of net.minecraft.block.FlowingFluidBlock in project AntimatterAPI by GregTech-Intergalactical.
the class AntimatterFluid method onRegistryBuild.
@Override
public void onRegistryBuild(IForgeRegistry<?> registry) {
if (registry == ForgeRegistries.ITEMS) {
AntimatterAPI.register(Item.class, getId() + "_bucket", containerItem = new BucketItem(this::getFluid, new Item.Properties().maxStackSize(1).containerItem(Items.BUCKET).group(ItemGroup.MISC)).setRegistryName(domain, getId() + "_bucket"));
} else if (registry == ForgeRegistries.BLOCKS) {
this.fluidBlock = new FlowingFluidBlock(this::getFluid, blockProperties);
this.fluidBlock.setRegistryName(domain, "block_fluid_".concat(getId()));
AntimatterAPI.register(Block.class, "block_fluid_".concat(getId()), fluidBlock);
} else if (registry == ForgeRegistries.FLUIDS) {
this.source = new Source(this.fluidProperties);
this.flowing = new Flowing(this.fluidProperties);
this.source.setRegistryName(domain, getId());
this.flowing.setRegistryName(domain, "flowing_".concat(getId()));
}
}
use of net.minecraft.block.FlowingFluidBlock in project MCMOD-Industria by M-Marvin.
the class FluidSulfuricAcid method randomTick.
@SuppressWarnings("deprecation")
@Override
protected void randomTick(World world, BlockPos pos, FluidState state, Random random) {
for (Direction d : Direction.values()) {
BlockState state1 = world.getBlockState(pos.relative(d));
int resistance = (int) state1.getExplosionResistance(world, pos.relative(d), null);
resistance = Math.max(1, resistance);
if (random.nextInt(resistance * 2) == 0) {
if (resistance < 35 && !state1.isAir() && !(state1.getBlock() instanceof FlowingFluidBlock) && !state1.is(BlockTags.BASE_STONE_NETHER) && !state1.is(BlockTags.NYLIUM) && !state1.is(ModItems.sulfur_crust_block) && !state1.is(ModTags.ACID_RESISTANT)) {
world.setBlockAndUpdate(pos.relative(d), d == Direction.DOWN ? ModFluids.FLOWING_SULFURIC_ACID.defaultFluidState().createLegacyBlock() : Blocks.AIR.defaultBlockState());
world.playSound(null, pos.relative(d), SoundEvents.FIRE_EXTINGUISH, SoundCategory.BLOCKS, 1, 1);
}
}
}
}
Aggregations