use of net.minecraft.world.level.Level 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.Level 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);
}
use of net.minecraft.world.level.Level in project Tropicraft by Tropicraft.
the class ScubaData method onPlayerTick.
@SubscribeEvent
public static void onPlayerTick(PlayerTickEvent event) {
Level world = event.player.level;
if (event.phase == Phase.END) {
// TODO support more than chest slot?
ItemStack chestStack = event.player.getItemBySlot(EquipmentSlot.CHEST);
Item chestItem = chestStack.getItem();
if (chestItem instanceof ScubaArmorItem) {
LazyOptional<ScubaData> data = event.player.getCapability(CAPABILITY);
if (!world.isClientSide) {
underwaterPlayers.add((ServerPlayer) event.player);
}
if (isUnderWater(event.player)) {
data.ifPresent(d -> {
d.tick(event.player);
if (!world.isClientSide) {
d.updateClient((ServerPlayer) event.player, false);
}
});
((ScubaArmorItem) chestItem).tickAir(event.player, EquipmentSlot.CHEST, chestStack);
if (!world.isClientSide && world.getGameTime() % 60 == 0) {
// TODO this effect could be better, custom packet?
Vec3 eyePos = event.player.getEyePosition(0);
Vec3 motion = event.player.getDeltaMovement();
Vec3 particlePos = eyePos.add(motion.reverse());
((ServerLevel) world).sendParticles(ParticleTypes.BUBBLE, particlePos.x(), particlePos.y(), particlePos.z(), 4 + world.random.nextInt(3), 0.25, 0.25, 0.25, motion.length());
}
} else if (!world.isClientSide && underwaterPlayers.remove(event.player)) {
// Update client state as they leave the water
data.ifPresent(d -> d.updateClient((ServerPlayer) event.player, false));
}
}
}
}
use of net.minecraft.world.level.Level in project Tropicraft by Tropicraft.
the class TropicraftSpawnEgg method useOn.
public InteractionResult useOn(UseOnContext context) {
Level world = context.getLevel();
if (world.isClientSide) {
return InteractionResult.SUCCESS;
} else {
ItemStack itemStack = context.getItemInHand();
BlockPos pos = context.getClickedPos();
Direction dir = context.getClickedFace();
BlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if (block == Blocks.SPAWNER) {
BlockEntity te = world.getBlockEntity(pos);
if (te instanceof SpawnerBlockEntity) {
BaseSpawner spawner = ((SpawnerBlockEntity) te).getSpawner();
EntityType<?> spawnType = typeIn.get();
spawner.setEntityId(spawnType);
te.setChanged();
world.sendBlockUpdated(pos, state, state, 3);
itemStack.shrink(1);
return InteractionResult.SUCCESS;
}
}
BlockPos spawnPos;
if (state.getCollisionShape(world, pos).isEmpty()) {
spawnPos = pos;
} else {
spawnPos = pos.relative(dir);
}
EntityType<?> type3 = typeIn.get();
if (type3.spawn((ServerLevel) world, itemStack, context.getPlayer(), spawnPos, MobSpawnType.SPAWN_EGG, true, !Objects.equals(pos, spawnPos) && dir == Direction.UP) != null) {
itemStack.shrink(1);
}
return InteractionResult.SUCCESS;
}
}
use of net.minecraft.world.level.Level in project MinecraftForge by MinecraftForge.
the class DispenseFluidContainer method fillContainer.
/**
* Picks up fluid in front of a Dispenser and fills a container with it.
*/
@Nonnull
private ItemStack fillContainer(@Nonnull BlockSource source, @Nonnull ItemStack stack) {
Level world = source.getLevel();
Direction dispenserFacing = source.getBlockState().getValue(DispenserBlock.FACING);
BlockPos blockpos = source.getPos().relative(dispenserFacing);
FluidActionResult actionResult = FluidUtil.tryPickUpFluid(stack, null, world, blockpos, dispenserFacing.getOpposite());
ItemStack resultStack = actionResult.getResult();
if (!actionResult.isSuccess() || resultStack.isEmpty()) {
return super.execute(source, stack);
}
if (stack.getCount() == 1) {
return resultStack;
} else if (((DispenserBlockEntity) source.getEntity()).addItem(resultStack) < 0) {
this.dispenseBehavior.dispense(source, resultStack);
}
ItemStack stackCopy = stack.copy();
stackCopy.shrink(1);
return stackCopy;
}
Aggregations