use of net.minecraft.world.level.block.state.BlockState in project Tropicraft by Tropicraft.
the class RainforestVinesFeature method place.
@Override
public boolean place(FeaturePlaceContext<RainforestVinesConfig> context) {
WorldGenLevel world = context.level();
Random rand = context.random();
BlockPos pos = context.origin();
RainforestVinesConfig config = context.config();
BlockPos.MutableBlockPos mutablePos = pos.mutable();
int maxY = Math.min(pos.getY() + config.height, world.getHeight());
for (int y = pos.getY(); y < maxY; ++y) {
for (int i = 0; i < config.rollsPerY; i++) {
mutablePos.set(pos);
mutablePos.move(rand.nextInt(config.xzSpread * 2) - config.xzSpread, 0, rand.nextInt(config.xzSpread * 2) - config.xzSpread);
mutablePos.setY(y);
if (world.isEmptyBlock(mutablePos)) {
for (Direction direction : DIRECTIONS) {
mutablePos.move(direction);
BlockState attaching = world.getBlockState(mutablePos);
if ((attaching.getBlock() == Blocks.GRASS_BLOCK && rand.nextInt(4) == 0) || attaching.is(BlockTags.LEAVES)) {
if (direction != Direction.DOWN && VineBlock.isAcceptableNeighbour(world, mutablePos, direction)) {
mutablePos.move(direction.getOpposite());
int len = rand.nextInt(3) + 2;
for (int j = 0; j < len && world.isEmptyBlock(mutablePos); j++) {
world.setBlock(mutablePos, Blocks.VINE.defaultBlockState().setValue(VineBlock.getPropertyForFace(direction), true), Block.UPDATE_CLIENTS);
mutablePos.move(Direction.DOWN);
}
break;
}
}
}
}
}
}
return true;
}
use of net.minecraft.world.level.block.state.BlockState in project Tropicraft by Tropicraft.
the class EntityAIPartyTime method tick.
@Override
public void tick() {
super.tick();
boolean isClose = false;
BlockPos blockposGoal = null;
if (this.entityObj.listPosDrums.size() > assignedDrumIndex) {
blockposGoal = entityObj.listPosDrums.get(assignedDrumIndex);
}
if (entityObj.level.getGameTime() % 200 == 0) {
if (this.entityObj.listPosDrums.size() > 0) {
assignedDrumIndex = entityObj.level.random.nextInt(entityObj.listPosDrums.size());
}
// if (wasClose) {
bangDrum = entityObj.level.random.nextBoolean();
// }
}
if (blockposGoal == null) {
stop();
return;
}
// prevent walking onto source
double dist = entityObj.position().distanceTo(new Vec3(blockposGoal.getX(), blockposGoal.getY(), blockposGoal.getZ()));
if (dist < 8D) {
wasClose = true;
}
if (dist < 3D && entityObj.isOnGround()) {
isClose = true;
entityObj.getNavigation().stop();
if (!bangDrum) {
// entityObj.setSitting(true);
entityObj.setDancing(true);
this.entityObj.getJumpControl().jump();
this.entityObj.setYRot(entityObj.level.random.nextInt(360));
} else {
entityObj.setDancing(false);
if (true || lookUpdateTimer <= 0) {
entityObj.setItemSlot(EquipmentSlot.MAINHAND, ItemStack.EMPTY);
// keep for testing, was neat sounding
// entityObj.level.random.nextInt(10) + 1;
int amp = 1;
int rate = 4 + (entityObj.getId() % 7);
int index1 = 0;
HashMap<Integer, List<Integer>> lookupStateToSequence = new HashMap<>();
List<Integer> listDelays = Lists.newArrayList(9, 3, 3, 3, 6);
lookupStateToSequence.put(index1++, listDelays);
lookupStateToSequence.put(index1++, listDelays);
lookupStateToSequence.put(index1++, listDelays);
lookupStateToSequence.put(index1++, Lists.newArrayList(9, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 12));
int nightStart = 12500;
int nightEnd = 23500;
int phases = 4;
int phaseSplit = (nightEnd - nightStart) / phases;
int timeOfDay = (int) (entityObj.level.getDayTime() % 24000);
int nightTime = (timeOfDay - nightStart);
if (nightTime > phaseSplit * 3) {
amp = 1;
} else if (nightTime > phaseSplit * 2) {
amp = 2;
} else if (nightTime > phaseSplit * 1) {
amp = 3;
} else {
amp = 4;
}
if (entityObj.hitIndex2 >= lookupStateToSequence.get(entityObj.hitIndex).size()) {
entityObj.hitIndex2 = 0;
entityObj.hitIndex++;
}
if (entityObj.hitIndex >= lookupStateToSequence.size()) {
entityObj.hitIndex = 0;
}
rate = lookupStateToSequence.get(entityObj.hitIndex).get(entityObj.hitIndex2);
if (entityObj.hitDelay > 0) {
entityObj.hitDelay--;
}
boolean perEntDelay = false;
boolean hit = false;
if (perEntDelay) {
if (entityObj.hitDelay <= 0) {
entityObj.hitDelay = (amp * rate);
hit = true;
}
} else {
hit = entityObj.level.getGameTime() % (amp * rate) == 0;
}
if (hit) {
// System.out.println("stage: " + entityObj.hitIndex + " - " + entityObj.hitIndex2);
entityObj.hitIndex2++;
BlockState state = entityObj.level.getBlockState(blockposGoal);
/*if (state.getBlock() instanceof BlockBongoDrum) {
//((BlockBongoDrum) state.getOwner()).playBongoSound(entityObj.world, null, blockposGoal, state);
TropicraftBongos bongo = ((BlockBongoDrum) state.getOwner()).getVariant(state);
float pitch = (entityObj.level.random.nextFloat() * 1F) + 0F;
entityObj.world.playSound(null, blockposGoal.getX(), blockposGoal.getY() + 0.5D, blockposGoal.getZ(),
bongo.getSoundEvent(), SoundCategory.BLOCKS, 2.5F, pitch);
entityObj.swingArm(Hand.MAIN_HAND);
} else */
if (state.getBlock() instanceof NoteBlock) {
if (entityObj.level.random.nextInt(10) == 0) {
for (int i = 0; i < 1 + entityObj.level.random.nextInt(4); i++) {
// note.changePitch();
state.cycle(NoteBlock.NOTE).getValue(NoteBlock.NOTE);
}
} else {
// note.triggerNote(entityObj.world, blockposGoal);
state.getBlock().attack(state, entityObj.level, blockposGoal, FakePlayerFactory.get((ServerLevel) entityObj.level, new GameProfile(UUID.fromString(" e517cf6a-ce31-4ac8-b48d-44b4f0f918a7"), "tropicraftKoa")));
}
entityObj.swing(InteractionHand.MAIN_HAND);
}
}
entityObj.syncBPM();
}
this.entityObj.getLookControl().setLookAt(blockposGoal.getX() + randXPos, blockposGoal.getY() + randYPos + 1D, blockposGoal.getZ() + randZPos, 8F, 8F);
}
} else {
wasClose = false;
entityObj.setSitting(false);
}
if (!isClose) {
entityObj.setDancing(true);
if ((this.entityObj.getNavigation().isDone() || walkingTimeout <= 0) && repathPentalty <= 0) {
int i = blockposGoal.getX();
int j = blockposGoal.getY();
int k = blockposGoal.getZ();
boolean success = false;
if (this.entityObj.distanceToSqr(Vec3.atCenterOf(blockposGoal)) > 256.0) {
Vec3 Vector3d = DefaultRandomPos.getPosTowards(this.entityObj, 14, 3, new Vec3((double) i + 0.5D, (double) j, (double) k + 0.5D), (float) Math.PI / 2F);
if (Vector3d != null) {
success = this.entityObj.getNavigation().moveTo(Vector3d.x, Vector3d.y, Vector3d.z, 1.0D);
} else {
success = Util.tryMoveToXYZLongDist(this.entityObj, new BlockPos(i, j, k), 1);
// System.out.println("success? " + success);
}
} else {
success = this.entityObj.getNavigation().moveTo((double) i + 0.5D, j, (double) k + 0.5D, 1.0D);
}
if (!success) {
repathPentalty = 40;
} else {
walkingTimeout = walkingTimeoutMax;
}
} else {
if (walkingTimeout > 0) {
walkingTimeout--;
} else {
}
}
}
if (repathPentalty > 0) {
repathPentalty--;
}
if (lookUpdateTimer > 0) {
lookUpdateTimer--;
}
}
use of net.minecraft.world.level.block.state.BlockState in project Tropicraft by Tropicraft.
the class HummingbirdEntity method tryGrowPlant.
private void tryGrowPlant(BlockPos pos) {
BlockState state = level.getBlockState(pos);
IntegerProperty age = getPlantAgeProperty(state);
if (age != null) {
int nextAge = state.getValue(age) + 1;
if (age.getPossibleValues().contains(nextAge)) {
level.levelEvent(LevelEvent.PARTICLES_PLANT_GROWTH, pos, 0);
level.setBlockAndUpdate(pos, state.setValue(age, nextAge));
}
}
}
use of net.minecraft.world.level.block.state.BlockState in project Tropicraft by Tropicraft.
the class FireArmorItem method clientTick.
// @Override
// public void damageArmor(LivingEntity player, ItemStack stack, DamageSource source, int damage, int slot) {
// if (source == DamageSource.IN_FIRE || source == DamageSource.LAVA) {
// //cheap way to slow the damage
// //if (player.worldObj.getWorldTime() % 2 == 0) {
// stack.damageItem(damage, player);
// }
// }
//
@OnlyIn(Dist.CLIENT)
public void clientTick(Player player) {
// Don't show fire particles underwater
if (player.isInWater())
return;
float range = 0.2F;
float speed = 0.08F;
Random rand = new Random();
Level worldRef = player.level;
int extraRand = 0;
final Vec3 motion = player.getDeltaMovement();
double plSpeed = Math.sqrt(motion.x * motion.x + motion.z * motion.z);
if (plSpeed < 0.1F) {
extraRand = 7;
}
/**
* 0 for all, 1 for minimal, 2 for off
*/
ParticleStatus particles = Minecraft.getInstance().options.particles;
if (particles == ParticleStatus.MINIMAL)
return;
if (this == TropicraftItems.FIRE_BOOTS.get()) {
boolean onLava = false;
boolean inLava = false;
// for (int x = -1; x < 2; x++) {
// for (int z = -1; z < 2; z++) {
int x = 0;
int z = 0;
if (motion.y < 0) {
BlockState state = player.level.getBlockState(new BlockPos(Mth.floor(player.getX() + x), Mth.floor(player.getY() - 2), Mth.floor(player.getZ() + z)));
if (state.getMaterial() == Material.LAVA) {
onLava = true;
}
}
BlockState block2 = player.level.getBlockState(new BlockPos(Mth.floor(player.getX() + x), Mth.floor(player.getY() - 1), Mth.floor(player.getZ() + z)));
if (block2.getMaterial() == Material.LAVA) {
inLava = true;
}
// why do we do this on the client?
if (onLava && !inLava) {
player.setDeltaMovement(motion.multiply(1, 0, 1));
player.setOnGround(true);
}
// why do we do this on the client???????
if (inLava) {
if (plSpeed < 0.4D) {
player.setDeltaMovement(motion.multiply(1.5D, 1.5D, 1.5D));
}
}
float look = player.level.getGameTime() * (10 + (onLava ? 10 : 0));
double dist = 1F;
double gatherX = player.getX();
double gatherY = player.getBoundingBox().minY;
double gatherZ = player.getZ();
double motionX = ((rand.nextFloat() * speed) - (speed / 2));
double motionZ = ((rand.nextFloat() * speed) - (speed / 2));
final int numFeetParticles = particles == ParticleStatus.DECREASED ? 2 : 11;
for (int i = 0; i < numFeetParticles + (onLava ? 5 : 0); i++) {
motionX = (-Math.sin((look) / 180.0F * 3.1415927F) * Math.cos(0 / 180.0F * 3.1415927F) * (speed + (0.1 * rand.nextDouble())));
motionZ = (Math.cos((look) / 180.0F * 3.1415927F) * Math.cos(0 / 180.0F * 3.1415927F) * (speed + (0.1 * rand.nextDouble())));
SimpleParticleType particle = ParticleTypes.FLAME;
if (rand.nextInt(22) == 0)
particle = ParticleTypes.LARGE_SMOKE;
if (onLava || rand.nextInt(1 + extraRand) == 0) {
Vec3 motion1 = player.getDeltaMovement();
player.level.addParticle(particle, gatherX + ((rand.nextFloat() * range) - (range / 2)), gatherY + ((rand.nextFloat() * range) - (range / 2)), gatherZ + ((rand.nextFloat() * range) - (range / 2)), motion1.x + motionX, 0.01F, motion1.z + motionZ);
player.level.addParticle(particle, (double) gatherX + ((rand.nextFloat() * range) - (range / 2)), (double) gatherY + ((rand.nextFloat() * range) - (range / 2)), (double) gatherZ + ((rand.nextFloat() * range) - (range / 2)), motion1.x - motionX, 0.01F, motion1.z - motionZ);
}
}
} else if (this == TropicraftItems.FIRE_LEGGINGS.get()) {
SimpleParticleType particle = ParticleTypes.FLAME;
if (rand.nextInt(2) == 0)
particle = ParticleTypes.LARGE_SMOKE;
if (rand.nextInt(3 + extraRand) == 0) {
player.level.addParticle(particle, player.getX() + ((rand.nextFloat() * range) - (range / 2)), player.getY() - 0.8F + ((rand.nextFloat() * range) - (range / 2)), player.getZ() + ((rand.nextFloat() * range) - (range / 2)), ((rand.nextFloat() * speed) - (speed / 2)), -0.05F, ((rand.nextFloat() * speed) - (speed / 2)));
}
} else if (this == TropicraftItems.FIRE_CHESTPLATE.get()) {
float look = -180F;
double dist = 0.5F;
double gatherX = player.getX() + (-Math.sin((player.getYRot() + look) / 180.0F * 3.1415927F) * Math.cos(player.getXRot() / 180.0F * 3.1415927F) * dist);
double gatherZ = player.getZ() + (Math.cos((player.getYRot() + look) / 180.0F * 3.1415927F) * Math.cos(player.getXRot() / 180.0F * 3.1415927F) * dist);
SimpleParticleType particle = ParticleTypes.FLAME;
if (rand.nextInt(2) == 0)
particle = ParticleTypes.LARGE_SMOKE;
if (rand.nextInt(1 + extraRand) == 0) {
player.level.addParticle(particle, gatherX + ((rand.nextFloat() * range) - (range / 2)), player.getY() - 0.4F + ((rand.nextFloat() * range) - (range / 2)), gatherZ + ((rand.nextFloat() * range) - (range / 2)), ((rand.nextFloat() * speed) - (speed / 2)), -0.01F, ((rand.nextFloat() * speed) - (speed / 2)));
}
} else if (this == TropicraftItems.FIRE_HELMET.get()) {
float look = -180F;
double dist = 0.5F;
range = 2F;
double gatherX = player.getX() + (-Math.sin((player.getYRot() + look) / 180.0F * 3.1415927F) * Math.cos(player.getXRot() / 180.0F * 3.1415927F) * dist);
double gatherZ = player.getZ() + (Math.cos((player.getYRot() + look) / 180.0F * 3.1415927F) * Math.cos(player.getXRot() / 180.0F * 3.1415927F) * dist);
SimpleParticleType particle = ParticleTypes.FLAME;
if (rand.nextInt(2) == 0)
particle = ParticleTypes.LARGE_SMOKE;
if (rand.nextInt(2) == 0) {
player.level.addParticle(particle, gatherX + ((rand.nextFloat() * range) - (range / 2)), player.getY() + 0.7F, gatherZ + ((rand.nextFloat() * range) - (range / 2)), ((rand.nextFloat() * speed) - (speed / 2)), -0.01F, ((rand.nextFloat() * speed) - (speed / 2)));
}
}
}
use of net.minecraft.world.level.block.state.BlockState in project Tropicraft by Tropicraft.
the class TropicalFertilizerItem method useOn.
@Override
public InteractionResult useOn(UseOnContext context) {
BlockState state = context.getLevel().getBlockState(context.getClickedPos());
if (state.getBlock() == Blocks.GRASS_BLOCK) {
if (!context.getLevel().isClientSide) {
// Logic from GrassBlock#grow, with probability for grass significantly reduced
BlockPos blockpos = context.getClickedPos().above();
BlockState blockstate = Blocks.GRASS.defaultBlockState();
Level world = context.getLevel();
Random rand = world.getRandom();
for (int i = 0; i < 128; ++i) {
BlockPos blockpos1 = blockpos;
int j = 0;
while (true) {
if (j >= i / 16) {
BlockState blockstate2 = world.getBlockState(blockpos1);
if (blockstate2.getBlock() == blockstate.getBlock() && rand.nextInt(10) == 0) {
if (world instanceof ServerLevel) {
((BonemealableBlock) blockstate.getBlock()).performBonemeal((ServerLevel) world, rand, blockpos1, blockstate2);
}
}
if (!blockstate2.isAir()) {
break;
}
BlockState blockstate1;
if (rand.nextInt(8) > 0) {
// Modification here, == changed to > to invert chances
List<ConfiguredFeature<?, ?>> list = world.getBiome(blockpos1).getGenerationSettings().getFlowerFeatures();
if (list.isEmpty()) {
break;
}
// TODO this is so ugly and hacky, pls
ConfiguredFeature<?, ?> pFlowerFeature = list.get(0);
AbstractFlowerFeature<FeatureConfiguration> abstractflowerfeature = (AbstractFlowerFeature) pFlowerFeature.feature;
blockstate1 = abstractflowerfeature.getRandomFlower(rand, blockpos1, pFlowerFeature.config());
} else {
blockstate1 = blockstate;
}
if (blockstate1.canSurvive(world, blockpos1)) {
world.setBlockAndUpdate(blockpos1, blockstate1);
}
break;
}
blockpos1 = blockpos1.offset(rand.nextInt(3) - 1, (rand.nextInt(3) - 1) * rand.nextInt(3) / 2, rand.nextInt(3) - 1);
if (world.getBlockState(blockpos1.below()).getBlock() != Blocks.GRASS_BLOCK || world.getBlockState(blockpos1).isCollisionShapeFullBlock(world, blockpos1)) {
break;
}
++j;
}
}
}
return InteractionResult.SUCCESS;
}
return super.useOn(context);
}
Aggregations