Jump to content

[1.8]Spawning particles around all entities within a radius around the player


The_Fireplace

Recommended Posts

I want to spawn particles around every living entity within a radius around the player, only if they have a certain headgear equipped. That being said, I don't want them visible to other players not wearing the headgear. I think the simplest way to do this would be to spawn them on the client-side only.

Now to the problem. I tried coding this, and it was a failure. The player couldn't see the particles. Now for my code:

In my FMLEvents.class, which is registered to the FML Event bus:

 

 

@SideOnly(Side.CLIENT)

@SubscribeEvent

public void onRenderTick(RenderTickEvent t){

if(Minecraft.getMinecraft().thePlayer != null)

if(Minecraft.getMinecraft().thePlayer.getEquipmentInSlot(4) != null)

if(MiscTools.areItemStacksEqual(new ItemStack(Minecraft.getMinecraft().thePlayer.getEquipmentInSlot(4).getItem()), new ItemStack(UnLogicII.crystal_eye_headband))){

byte i = 0;

if(i < 40){

i++;

}else{

List entities = Minecraft.getMinecraft().theWorld.getEntitiesWithinAABBExcludingEntity(Minecraft.getMinecraft().thePlayer, Minecraft.getMinecraft().thePlayer.getBoundingBox().expand(8, 8, 8));

for(int j=0;j<entities.size();j++){

Random rand = new Random();

Entity entity = (Entity)entities.get(j);

Minecraft.getMinecraft().theWorld.spawnParticle(EnumParticleTypes.SPELL_MOB, entity.posX, entity.posY, entity.posZ, (rand.nextDouble() - 0.5D) * (double)entity.width, rand.nextDouble() * (double)entity.height, (rand.nextDouble() - 0.5D) * (double)entity.width, null);

}

i = 0;

}

}

}

 

 

 

Am I doing this completely wrong, or have I just messed up a small portion of it? Any help is appreciated.

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Link to comment
Share on other sites

I'm not sure what your MiscTools#areItemStacksEqual implementation is like (or why you would even need one when the ItemStack class itself already offers several ways to check equality), but if your headgear can be damaged, I highly doubt it will ever return true.

 

Not only that, but unless your item requires stack damage or NBT to determine equality, you are wasting a lot of effort.

// this monstrosity:
MiscTools.areItemStacksEqual(new ItemStack(Minecraft.getMinecraft().thePlayer.getEquipmentInSlot(4).getItem()), new ItemStack(UnLogicII.crystal_eye_headband)

// should be rewriten as:
Minecraft.getMinecraft().thePlayer.getEquipmentInSlot(4).getItem() == UnLogicII.crystal_eye_headband

Also, why not store a reference to Minecraft, either in your class or locally in the method, so you don't have such long-winded statements?

 

Finally, this:

byte i = 0;
      if(i < 40){
         i++;
      } else {

What are you expecting to happen there? You initialize i to zero EVERY SINGLE TIME the method is called, so i++ is completely pointless and your 'else' statement is never called.

Link to comment
Share on other sites

I'm not sure what your MiscTools#areItemStacksEqual implementation is like (or why you would even need one when the ItemStack class itself already offers several ways to check equality), but if your headgear can be damaged, I highly doubt it will ever return true.

 

Not only that, but unless your item requires stack damage or NBT to determine equality, you are wasting a lot of effort.

// this monstrosity:
MiscTools.areItemStacksEqual(new ItemStack(Minecraft.getMinecraft().thePlayer.getEquipmentInSlot(4).getItem()), new ItemStack(UnLogicII.crystal_eye_headband)

// should be rewriten as:
Minecraft.getMinecraft().thePlayer.getEquipmentInSlot(4).getItem() == UnLogicII.crystal_eye_headband

Also, why not store a reference to Minecraft, either in your class or locally in the method, so you don't have such long-winded statements?

 

Finally, this:

byte i = 0;
      if(i < 40){
         i++;
      } else {

What are you expecting to happen there? You initialize i to zero EVERY SINGLE TIME the method is called, so i++ is completely pointless and your 'else' statement is never called.

The first part, I figured out in the time I was waiting for a response. The second part, I didn't notice, I put the byte in the wrong spot. Thanks.

 

Now, for anyone else trying to do this, here is my completed, working code:

byte i = 0;
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onRenderTick(RenderTickEvent t){
	Minecraft mc = Minecraft.getMinecraft();
	if(mc.inGameHasFocus){
		if(mc.thePlayer.getHeldItem() != null)
			if(mc.thePlayer.getHeldItem().getItem() == Item.getItemFromBlock(UnLogicII.coal_gun) || mc.thePlayer.getHeldItem().getItem() == Item.getItemFromBlock(UnLogicII.smart_coal_gun)){
				mc.ingameGUI.drawString(Minecraft.getMinecraft().fontRendererObj, StatCollector.translateToLocal("info.coal_type")+": "+StatCollector.translateToLocal(EnumAmmo.getItem(ExtendedPlayer.get(Minecraft.getMinecraft().thePlayer).getAmmoType()).getUnlocalizedName()+".name"), 1, 1, 16777215);
			}
	}
	if(mc.thePlayer != null)
	if(mc.thePlayer.getEquipmentInSlot(4) != null)
	if(mc.thePlayer.getEquipmentInSlot(4).getItem() == UnLogicII.crystal_eye_headband){
	if(i < 40){
		i++;
	}else{
		World world = mc.thePlayer.worldObj;
		AxisAlignedBB aabb = mc.thePlayer.getEntityBoundingBox().expand(8, 8, ;
		List entities = world.getEntitiesWithinAABBExcludingEntity(mc.thePlayer, aabb);
		for(int j=0;j<entities.size();j++){
			Random rand = new Random();
			Entity entity = (Entity)entities.get(j);
			mc.theWorld.spawnParticle(EnumParticleTypes.SPELL_MOB, entity.posX, entity.posY, entity.posZ, (rand.nextDouble() - 0.5D) * (double)entity.width, rand.nextDouble() * (double)entity.height, (rand.nextDouble() - 0.5D) * (double)entity.width, null);
		}
		i = 0;
	}
	}
}

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.