use of net.minecraft.nbt.StringNBT in project xercamods by ercanserteli.
the class ItemGoldenCupcake method onItemUseFinish.
@Override
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, LivingEntity player) {
player.addPotionEffect(new EffectInstance(Effects.REGENERATION, 300, 1));
player.addPotionEffect(new EffectInstance(Effects.WEAKNESS, 200, 0));
if (!worldIn.isRemote) {
int n = worldIn.rand.nextInt(5);
switch(n) {
case 0:
((ServerWorld) worldIn).addLightningBolt(new LightningBoltEntity(worldIn, player.posX, player.posY, player.posZ, true));
worldIn.createExplosion(null, player.posX, player.posY, player.posZ, 1.1F, false, Explosion.Mode.BREAK);
EntityConfettiBall entityball = new EntityConfettiBall(worldIn, player);
entityball.shoot(player, 270, player.rotationYaw + 90, 0.0F, 1.0F, 1.0F);
worldIn.addEntity(entityball);
for (int i = 0; i < 8; i++) {
entityball = new EntityConfettiBall(worldIn, player);
entityball.shoot(player, 300, 45 * i, 0.0F, 1.0F, 1.0F);
worldIn.addEntity(entityball);
}
float multiplier = 0.5f;
float motionX = worldIn.rand.nextFloat() - 0.5f;
float motionY = worldIn.rand.nextFloat() - 0.5f;
float motionZ = worldIn.rand.nextFloat() - 0.5f;
ItemEntity newCupcake = new ItemEntity(worldIn, player.posX + motionX, player.posY + 1 + motionY, player.posZ + motionZ, new ItemStack(Items.ITEM_GOLDEN_CUPCAKE, 2));
newCupcake.setMotion(motionX * multiplier, motionY * multiplier, motionZ * multiplier);
worldIn.addEntity(newCupcake);
break;
case 1:
case 2:
worldIn.playSound(null, player.posX, player.posY + 3, player.posZ, SoundEvents.YAHOO, SoundCategory.PLAYERS, 1.0f, worldIn.rand.nextFloat() * 0.2F + 0.9F);
player.addVelocity(0, 2, 0);
player.velocityChanged = true;
player.addPotionEffect(new EffectInstance(Effects.JUMP_BOOST, 1200, 6));
break;
case 3:
case 4:
worldIn.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.SCARY, SoundCategory.PLAYERS, 1.0f, worldIn.rand.nextFloat() * 0.2F + 0.8F);
player.addPotionEffect(new EffectInstance(Effects.BLINDNESS, 200, 1));
ItemStack head = new ItemStack(net.minecraft.item.Items.PLAYER_HEAD, 1);
head.getOrCreateTag().put("SkullOwner", new StringNBT("MHF_Herobrine"));
Item[] instruments = { Items.ITEM_GAVEL, Items.ITEM_RAW_SAUSAGE, Items.ITEM_STONE_WARHAMMER, Items.ITEM_PROSECUTOR_BADGE };
int i = worldIn.rand.nextInt(4);
Entity e1 = new SkeletonEntity(EntityType.SKELETON, worldIn);
e1.setItemStackToSlot(EquipmentSlotType.MAINHAND, new ItemStack(instruments[i]));
e1.setItemStackToSlot(EquipmentSlotType.HEAD, head);
e1.setLocationAndAngles(player.posX + (double) worldIn.rand.nextInt(3), player.posY + (double) worldIn.rand.nextInt(5), player.posZ + (double) worldIn.rand.nextInt(3), worldIn.rand.nextFloat() * 360.0F, 0.0F);
ItemStack playerHead = new ItemStack(net.minecraft.item.Items.PLAYER_HEAD, 1);
playerHead.getOrCreateTag().put("SkullOwner", new StringNBT(player.getName().getString()));
Entity e2 = new ZombieEntity(worldIn);
e2.setItemStackToSlot(EquipmentSlotType.MAINHAND, new ItemStack(Items.ITEM_KNIFE));
e2.setItemStackToSlot(EquipmentSlotType.OFFHAND, new ItemStack(Items.ITEM_KNIFE));
e2.setItemStackToSlot(EquipmentSlotType.HEAD, playerHead);
e2.setLocationAndAngles(player.posX + (double) worldIn.rand.nextInt(3), player.posY + (double) worldIn.rand.nextInt(5), player.posZ + (double) worldIn.rand.nextInt(3), worldIn.rand.nextFloat() * 360.0F, 0.0F);
worldIn.addEntity(e1);
worldIn.addEntity(e2);
break;
}
}
return super.onItemUseFinish(stack, worldIn, player);
}
use of net.minecraft.nbt.StringNBT in project MCMOD-Industria by M-Marvin.
the class TileEntityJigsaw method generateStructure.
public void generateStructure(boolean keepJigsaws, int levels, Random rand) {
if (!this.level.isClientSide()) {
boolean hasAlreadyGenerated = this.level.getBlockState(worldPosition.relative(this.getFacing())).getBlock() == ModItems.jigsaw;
ServerWorld world = (ServerWorld) this.level;
ListNBT list = JigsawFileManager.getPoolList(world, this.poolFile);
if (list != null && levels > 0 && !hasAlreadyGenerated && !this.targetName.getPath().equals("empty")) {
HashMap<Integer, Integer> structures = new HashMap<Integer, Integer>();
int index = 0;
int structIndex = 0;
for (int i = 0; i < list.size(); i++) {
CompoundNBT entry = list.getCompound(i);
int chance = entry.getInt("chance");
for (int i1 = 0; i1 < chance; i1++) {
structures.put(index++, structIndex);
}
structIndex++;
}
int randomStructureId = structures.size() > 1 ? structures.get(rand.nextInt(index - 1)) : structures.get(0);
CompoundNBT structureNBT = list.getCompound(randomStructureId);
ResourceLocation resourceStructure = ResourceLocation.tryParse(structureNBT.getString("file"));
JigsawReplacement replaceMode = JigsawReplacement.fromName(structureNBT.getString("replaceBlocks"));
ListNBT blockList = structureNBT.contains("blocks") ? structureNBT.getList("blocks", 8) : new ListNBT();
List<BlockState> blocks = new ArrayList<BlockState>();
for (int i = 0; i < blockList.size(); i++) {
StringNBT stringNBT = (StringNBT) blockList.get(i);
BlockStateParser parser = new BlockStateParser(new StringReader(stringNBT.getAsString()), true);
try {
parser.parse(false);
blocks.add(parser.getState());
} catch (CommandSyntaxException e) {
Industria.LOGGER.warn("Cant parse replace-list block " + stringNBT.getAsString() + " in jigsaw metafile " + resourceStructure + "!");
}
}
Template template = JigsawFileManager.getTemplate(world, resourceStructure);
if (template != null) {
JigsawType alowedType = this.getBlockState().getValue(BlockJigsaw.TYPE).getOppesite();
List<BlockInfo> jigsawBlocks = template.filterBlocks(BlockPos.ZERO, new PlacementSettings(), ModItems.jigsaw);
List<BlockInfo> filteredJigsaws = new ArrayList<BlockInfo>();
for (BlockInfo block : jigsawBlocks) {
ResourceLocation jigsawName = ResourceLocation.tryParse(block.nbt.getString("name"));
if (jigsawName.toString().equals(this.targetName.toString()) && block.state.getValue(BlockJigsaw.TYPE) == alowedType)
filteredJigsaws.add(block);
}
if (filteredJigsaws.size() != 0) {
BlockInfo randomJigsaw = filteredJigsaws.size() > 1 ? filteredJigsaws.get(rand.nextInt(filteredJigsaws.size())) : filteredJigsaws.get(0);
Rotation rotation = Rotation.NONE;
if (alowedType != JigsawType.HORIZONTAL && !this.lockOrientation) {
rotation = Rotation.getRandom(rand);
} else {
Direction compare1 = this.getBlockState().getValue(BlockJigsaw.FACING);
Direction compare2 = alowedType == JigsawType.HORIZONTAL ? randomJigsaw.state.getValue(BlockJigsaw.FACING).getOpposite() : randomJigsaw.state.getValue(BlockJigsaw.FACING);
if (compare1 == compare2) {
rotation = Rotation.NONE;
} else if (compare1 == compare2.getOpposite()) {
rotation = Rotation.CLOCKWISE_180;
} else if (compare1.getCounterClockWise() == compare2) {
rotation = Rotation.CLOCKWISE_90;
} else if (compare1.getClockWise() == compare2) {
rotation = Rotation.COUNTERCLOCKWISE_90;
}
}
PlacementSettings placement = (new PlacementSettings()).setMirror(Mirror.NONE).setRotation(rotation).setIgnoreEntities(false).setChunkPos((ChunkPos) null).addProcessor(new JigsawTemplateProcessor(replaceMode, blocks));
BlockPos offset = randomJigsaw.pos;
offset = Template.transform(offset, Mirror.NONE, rotation, BlockPos.ZERO);
offset = offset.relative(this.getFacing().getOpposite());
BlockPos generationPos = this.worldPosition.subtract(offset);
template.placeInWorldChunk(world, generationPos, placement, rand);
for (BlockInfo jigsaw : jigsawBlocks) {
BlockPos transformedPos = Template.transform(jigsaw.pos, Mirror.NONE, rotation, BlockPos.ZERO);
transformedPos = generationPos.offset(transformedPos);
TileEntity tileEntity = world.getBlockEntity(transformedPos);
if (tileEntity instanceof TileEntityJigsaw) {
((TileEntityJigsaw) tileEntity).generateStructure(keepJigsaws, levels - 1, rand);
}
}
}
}
}
if (!keepJigsaws) {
world.setBlock(worldPosition, replaceState, 2);
}
}
}
Aggregations