Skip to content

Commit

Permalink
things re reordered for the polleball logic for random effects redone…
Browse files Browse the repository at this point in the history
… to use switch case inset of if else
  • Loading branch information
rayanfox25 committed Mar 26, 2024
1 parent 16c47c8 commit 0f36dee
Show file tree
Hide file tree
Showing 13 changed files with 247 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.*;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.projectile.thrown.ThrownItemEntity;
import net.minecraft.item.Item;
import net.minecraft.network.listener.ClientPlayPacketListener;
Expand All @@ -16,16 +18,16 @@
import rayan.buzzblocks.BuzzBlocks;
import rayan.buzzblocks.entity.ModEntites;
import rayan.buzzblocks.item.ModItems;
import rayan.buzzblocks.util.CustomMaths;
import rayan.buzzblocks.util.D20.*;
import rayan.buzzblocks.util.PlayerMessageUtility;

import java.util.List;

import static rayan.buzzblocks.util.CustomMaths.preCalculateCumulativeProbabilities;
import static rayan.buzzblocks.util.CustomMaths.weightedRandomSelection;


public class PollenBallProjectialEntity extends ThrownItemEntity {
World world = getEntityWorld();

public PollenBallProjectialEntity(EntityType<? extends ThrownItemEntity> entityType, World world) {
super(entityType, world);
}
Expand All @@ -50,98 +52,96 @@ protected void onEntityHit(EntityHitResult entityHitResult) {
}

@Override
protected void onBlockHit(BlockHitResult blockHitResult ) {
protected void onBlockHit(BlockHitResult blockHitResult) {
super.onBlockHit(blockHitResult);
BlockPos blockPos = blockHitResult.getBlockPos();
World world = getEntityWorld();
Entity owner = this.getOwner();


// Introduce a probability factor for the explosion
List<Double> probabilityFactors = List.of(
0.1, //lightningStrikeProbability
0.1, //explosionProbability
0.1, //hostileMobSpawnProbability
0.1, //foodDropProbability
0.1, //petSpawnProbability
0.1, //flowerDropProbability
0.1, //diamondBlockSpawnProbability
0.1, //sandstonePyramidSpawnProbability
0.1 , //effectProbability
0.1
); // Must add/sum to 1
probabilityFactors = preCalculateCumulativeProbabilities(probabilityFactors);
int switchValue = weightedRandomSelection(probabilityFactors);

switch (switchValue) {
case 0: //lightningStrikeProbability
BuzzBlocks.LOGGER.warn("This is the lightning");
Entity player = getOwner();
if (player instanceof ServerPlayerEntity) {
// Strike the player with lightning
LightningEntity lightning = new LightningEntity(EntityType.LIGHTNING_BOLT, world);
lightning.refreshPositionAndAngles(player.getX(), player.getY(), player.getZ(), player.getYaw(), player.getPitch());
world.spawnEntity(lightning);
}
break;
case 1:
BuzzBlocks.LOGGER.warn("This is the Exploded");
CustomExplosion explosion = new CustomExplosion(world, blockPos, 15);
explosion.explode();
break;
case 2:
BuzzBlocks.LOGGER.warn("This is the Spawning Mobs");
spawnHostileMobs mob = new spawnHostileMobs(world, blockPos, 10);
mob.Mobs();
break;
case 3:
BuzzBlocks.LOGGER.warn("This is the yay food");
dropRandomFood food = new dropRandomFood(world, blockPos, 10);
food.Food();
break;
case 4:
BuzzBlocks.LOGGER.warn("This is the Pets");
spawnRandomPet pet = new spawnRandomPet(world, blockPos, 10);
pet.Pet();
break;
case 5:
BuzzBlocks.LOGGER.warn("This is the Flowers");
dropRandomFlowers flowers = new dropRandomFlowers(world, blockPos, 10);
flowers.flowers();
break;
case 6:
BuzzBlocks.LOGGER.warn("This is the Diamond_Block");
world.setBlockState(blockPos, Blocks.DIAMOND_BLOCK.getDefaultState());
break;
case 7:
// Place a small sandstone pyramid
BuzzBlocks.LOGGER.warn("This is the pyramid");
placeSmallSandstonePyramid pyramid = new placeSmallSandstonePyramid(world, blockPos);
pyramid.Pyramid();
break;
case 8:
BuzzBlocks.LOGGER.warn("Applying random Positive effect");
GivePositiveRandomEffect effect = new GivePositiveRandomEffect(world, (ServerPlayerEntity) owner);
effect.GEffect();
break;
case 9:
BuzzBlocks.LOGGER.warn("Applying random Negative effect");
GiveNegtiveRandomEffect effect1 = new GiveNegtiveRandomEffect(world, (ServerPlayerEntity) owner);
effect1.NEffect();
break;
default:
// nothing
}


BlockState blockState = world.getBlockState(blockPos);
if (!blockState.isAir() && blockState.isReplaceable()) {
world.setBlockState(blockPos, Blocks.AIR.getDefaultState());
this.remove(RemovalReason.DISCARDED);
if (owner instanceof ServerPlayerEntity) { // Added null check for owner
// Introduce a probability factor for the explosion
List<Double> probabilityFactors = List.of(
0.09, //lightningStrikeProbability
0.09,//explosionProbability
0.09, //hostileMobSpawnProbability
0.09, //foodDropProbability
0.09, //petSpawnProbability
0.09, //flowerDropProbability
0.09, //diamondBlockSpawnProbability
0.09, //sandstonePyramidSpawnProbability
0.09, //effectProbability Positive
0.09, //effectProbability Negative
1.09
); // Must add/sum to 1
probabilityFactors = CustomMaths.preCalculateCumulativeProbabilities(probabilityFactors);
int switchValue = CustomMaths.weightedRandomSelection(probabilityFactors);

switch (switchValue) {
case 0: //lightningStrikeProbability
BuzzBlocks.LOGGER.warn("This is the lightning");
PlayerMessageUtility.sendMessageToPlayers(world,"this effect is broken");
break;
case 1:
BuzzBlocks.LOGGER.warn("This is the Exploded");
CustomExplosion explosion = new CustomExplosion(world, blockPos, 15);
explosion.explode();
break;
case 2:
BuzzBlocks.LOGGER.warn("This is the Spawning Mobs");
spawnHostileMobs mob = new spawnHostileMobs(world, blockPos, 10);
mob.Mobs();
break;
case 3:
BuzzBlocks.LOGGER.warn("This is the yay food");
dropRandomFood food = new dropRandomFood(world, blockPos, 10);
food.Food();
break;
case 4:
BuzzBlocks.LOGGER.warn("This is the Pets");
spawnRandomPet pet = new spawnRandomPet(world, blockPos, 10);
pet.Pet();
PlayerMessageUtility.sendMessageToPlayers(world, "DANG ANIMALS ");
break;
case 5:
BuzzBlocks.LOGGER.warn("This is the Flowers");
dropRandomFlowers flowers = new dropRandomFlowers(world, blockPos, 10);
flowers.flowers();
PlayerMessageUtility.sendMessageToPlayers(world, "FLOWERS ALL OF THEM");
break;
case 6:
BuzzBlocks.LOGGER.warn("This is the Diamond_Block");
world.setBlockState(blockPos, Blocks.DIAMOND_BLOCK.getDefaultState());
PlayerMessageUtility.sendMessageToPlayers(world, "OWO A DIAMOND");
break;
case 7:
// Place a small sandstone pyramid
BuzzBlocks.LOGGER.warn("This is the pyramid");
placeSmallSandstonePyramid pyramid = new placeSmallSandstonePyramid(world, blockPos);
pyramid.Pyramid();
break;
case 8:
BuzzBlocks.LOGGER.warn("Applying random Positive effect");
GivePositiveRandomEffect effect = new GivePositiveRandomEffect(world, (ServerPlayerEntity) owner);
effect.GEffect();
break;
case 9:
BuzzBlocks.LOGGER.warn("Applying random Positive effect");
GiveNegtiveRandomEffect effect1 = new GiveNegtiveRandomEffect(world, (ServerPlayerEntity) owner);
effect1.NEffect();
break;
case 10:
TNTTrap.triggerTrap(world, (ServerPlayerEntity) owner);
PlayerMessageUtility.sendMessageToPlayers(world, "GET EXPLODED");
default:
// nothing
}

BlockState blockState = world.getBlockState(blockPos);
if (!blockState.isAir() && blockState.isReplaceable()) {
world.setBlockState(blockPos, Blocks.AIR.getDefaultState());
this.remove(RemovalReason.DISCARDED);
}
}

this.remove(RemovalReason.DISCARDED);

}
}

}
16 changes: 13 additions & 3 deletions src/main/java/rayan/buzzblocks/util/D20/CustomExplosion.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package rayan.buzzblocks.util.D20;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.world.World;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.explosion.Explosion;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

public class CustomExplosion {
private final World world;
Expand All @@ -26,10 +28,18 @@ public void explode() {
explosion.collectBlocksAndDamageEntities();
explosion.affectWorld(true);
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS, 1.0f, 1.0f);
sendMessageToPlayers("You rolled a 3 Better hope your at a safe distance");
}
spawnExplosionParticles();
}

private void sendMessageToPlayers(String message) {
// Send message to all players in the world
for (PlayerEntity player : world.getPlayers()) {
player.sendMessage(Text.of(message), false);
}
}

@Environment(EnvType.CLIENT)
public void spawnExplosionParticles() {
// Limit the number of particles spawned per explosion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.world.World;
import rayan.buzzblocks.BuzzBlocks;

Expand Down Expand Up @@ -38,6 +40,7 @@ public void NEffect() {
} else {
BuzzBlocks.LOGGER.error("Player is null. Cannot apply status effect.");
}
sendMessageToPlayers("");
}

// Helper method to get all the status effects you want to consider
Expand All @@ -57,4 +60,11 @@ private List<StatusEffect> getAllStatusEffects() {
// Add more negative effects as needed
return effects;
}

private void sendMessageToPlayers(String message) {
// Send message to all players in the world
for (PlayerEntity player : world.getPlayers()) {
player.sendMessage(Text.of(message), false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.world.World;
import rayan.buzzblocks.BuzzBlocks;

Expand Down Expand Up @@ -38,6 +40,7 @@ public void GEffect() {
} else {
BuzzBlocks.LOGGER.error("Player is null. Cannot apply status effect.");
}
sendMessageToPlayers("rolled a 5");
}

// Helper method to get all the status effects you want to consider
Expand All @@ -57,4 +60,10 @@ private List<StatusEffect> getAllStatusEffects() {
effects.add(StatusEffects.LUCK);
return effects;
}
private void sendMessageToPlayers(String message) {
// Send message to all players in the world
for (PlayerEntity player : world.getPlayers()) {
player.sendMessage(Text.of(message), false);
}
}
}
15 changes: 15 additions & 0 deletions src/main/java/rayan/buzzblocks/util/D20/LightningStriker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package rayan.buzzblocks.util.D20;

import net.minecraft.entity.EntityType;
import net.minecraft.entity.LightningEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.world.World;

public class LightningStriker {
public static void strikePlayer(PlayerEntity player, World world) {
// Strike the player with lightning
LightningEntity lightning = new LightningEntity(EntityType.LIGHTNING_BOLT, world);
lightning.refreshPositionAndAngles(player.getX(), player.getY(), player.getZ(), player.getYaw(), player.getPitch());
world.spawnEntity(lightning);
}
}
Loading

0 comments on commit 0f36dee

Please sign in to comment.