Java Code Examples for net.minecraft.world.World#getTotalWorldTime()

The following examples show how to use net.minecraft.world.World#getTotalWorldTime() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SafeTimeTracker.java    From Framez with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Return true if a given delay has passed since last time marked was called
 * successfully.
 *
 * @deprecated should use the constructor with a delay instead, and call
 * this function without a parameter
 */
public boolean markTimeIfDelay(World world, long delay) {
	if (world == null) {
		return false;
	}

	long currentTime = world.getTotalWorldTime();

	if (currentTime < lastMark) {
		lastMark = currentTime;
		return false;
	} else if (lastMark + delay + lastRandomDelay <= currentTime) {
		duration = currentTime - lastMark;
		lastMark = currentTime;
		lastRandomDelay = (int) (Math.random() * randomRange);

		return true;
	} else {
		return false;
	}
}
 
Example 2
Source File: ItemRuler.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos,
        EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
    if (world.isRemote)
    {
        return EnumActionResult.SUCCESS;
    }

    // Hack to work around the fact that when the NBT changes, the left click event will fire again the next tick,
    // so it would easily result in the state toggling multiple times per left click
    Long last = this.lastLeftClick.get(player.getUniqueID());

    if (last == null || (world.getTotalWorldTime() - last) >= 6)
    {
        // When not sneaking, adjust the position to be the adjacent block and not the targeted block itself
        this.setOrRemovePosition(player.getHeldItem(hand), new BlockPosEU(pos, player.getEntityWorld().provider.getDimension(), side),
                POS_END, player.isSneaking() == false);
    }

    this.lastLeftClick.put(player.getUniqueID(), world.getTotalWorldTime());

    return EnumActionResult.SUCCESS;
}
 
Example 3
Source File: ArmorLogicRebreather.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) {
    IElectricItem electricItem = itemStack.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
    if (electricItem.getCharge() >= energyUsagePerTick) {
        if (player.isInsideOfMaterial(Material.WATER) && world.isRemote && world.getTotalWorldTime() % 20 == 0L) {
            Vec3d pos = player.getPositionVector().add(new Vec3d(0.0, player.getEyeHeight(), 0.0));
            Particle particle = new ParticleBubble.Factory().createParticle(0, world, pos.x, pos.y, pos.z, 0.0, 0.0, 0.0);
            particle.setMaxAge(Integer.MAX_VALUE);
            Minecraft.getMinecraft().effectRenderer.addEffect(particle);
        }
        if (player.isInsideOfMaterial(Material.WATER) && !player.isPotionActive(MobEffects.WATER_BREATHING)) {
            if (player.getAir() < 300 && drainActivationEnergy(electricItem)) {
                player.setAir(Math.min(player.getAir() + 1, 300));
            }
        }
    }
}
 
Example 4
Source File: ModuleAirGrate.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
private void coolHeatSinks(World world, int x, int y, int z, int range){
    if(grateRange > 2) {
        int curTeIndex = (int)(world.getTotalWorldTime() % 27);
        x += dir.offsetX * 2;
        y += dir.offsetY * 2;
        z += dir.offsetZ * 2;
        TileEntity te = world.getTileEntity(x - 1 + curTeIndex % 3, y - 1 + curTeIndex / 3 % 3, z - 1 + curTeIndex / 9 % 3);
        if(te instanceof TileEntityHeatSink) heatSinks.add((TileEntityHeatSink)te);

        Iterator<TileEntityHeatSink> iterator = heatSinks.iterator();
        while(iterator.hasNext()) {
            TileEntityHeatSink heatSink = iterator.next();
            if(heatSink.isInvalid()) {
                iterator.remove();
            } else {
                for(int i = 0; i < 4; i++)
                    heatSink.onFannedByAirGrate();
            }
        }
    }
}
 
Example 5
Source File: RedstoneEtherServer.java    From WirelessRedstone with MIT License 6 votes vote down vote up
private void entityJamTest(World world)
{
    if(world.getTotalWorldTime() % 10 != 0)
        return;
    
    int dimension = CommonUtils.getDimension(world);
    for(Iterator<BlockCoord> iterator = ethers.get(dimension).jammerset.iterator(); iterator.hasNext();)
    {
        BlockCoord jammer = iterator.next();
        List<Entity> entitiesinrange = world.getEntitiesWithinAABBExcludingEntity(null, AxisAlignedBB.getBoundingBox(jammer.x-9.5, jammer.y-9.5, jammer.z-9.5, jammer.x+10.5, jammer.y+10.5, jammer.z+10.5));
        for(Iterator<Entity> iterator2 = entitiesinrange.iterator(); iterator2.hasNext();)
        {
            Entity entity = iterator2.next();
            if(!(entity instanceof EntityLivingBase))
                continue;
            
            if(entity instanceof EntityPlayer)
                if(isPlayerJammed((EntityPlayer)entity))
                    continue;
            
            jamEntitySometime((EntityLivingBase) entity);
        }
    }
}
 
Example 6
Source File: PerTickLongCounter.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void checkValueState(World world) {
    long currentWorldTime = world.getTotalWorldTime();
    if (currentWorldTime != lastUpdatedWorldTime) {
        if (currentWorldTime == lastUpdatedWorldTime + 1) {
            //last updated time is 1 tick ago, so we can move current value to last
            //before resetting it to default value
            this.lastValue = currentValue;
        } else {
            //otherwise, set last value as default value
            this.lastValue = defaultValue;
        }
        this.lastUpdatedWorldTime = currentWorldTime;
        this.currentValue = defaultValue;
    }
}
 
Example 7
Source File: ServerQuitFromTimeUpImplementation.java    From malmo with MIT License 5 votes vote down vote up
@Override
protected long getWorldTime()
{
   	World world = null;
   	MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
	world = server.getEntityWorld();
	return (world != null) ? world.getTotalWorldTime() : 0;
}
 
Example 8
Source File: OpenClientProxy.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Override
public long getTicks(World worldObj) {
	if (worldObj != null) { return worldObj.getTotalWorldTime(); }
	World cWorld = getClientWorld();
	if (cWorld != null) return cWorld.getTotalWorldTime();
	return 0;
}
 
Example 9
Source File: SatelliteData.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public void setDimensionId(World world) {
	//TODO: send packet on orbit reached
	super.setDimensionId(world);

	lastActionTime = world.getTotalWorldTime();
}
 
Example 10
Source File: ModuleEffectPoisonCloud.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean run(@NotNull World world, ModuleInstanceEffect instance, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
	Vec3d position = spell.getTarget(world);
	BlockPos pos = spell.getTargetPos();

	if (position == null || pos == null) return true;

	if (!spellRing.taxCaster(world, spell, true)) return false;

	double potency = spellRing.getAttributeValue(world, AttributeRegistry.POTENCY, spell);

	double area = spellRing.getAttributeValue(world, AttributeRegistry.AREA, spell);

	if (world.getTotalWorldTime() % 2 == 0)
		world.playSound(null, pos, ModSounds.FIZZING_LOOP, SoundCategory.NEUTRAL, RandUtil.nextFloat(0.6f, 1f), RandUtil.nextFloat(0.1f, 4f));
	for (Entity entity : world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(new BlockPos(position)).grow(area, area, area))) {
		if (entity instanceof EntityLivingBase) {
			EntityLivingBase living = (EntityLivingBase) entity;
			if (potency >= 3) {
				living.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 100));
			}
			living.addPotionEffect(new PotionEffect(MobEffects.POISON, 60, (int) (potency / 3)));
		}
	}

	return true;
}
 
Example 11
Source File: ICooldownSpellCaster.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
default boolean isCoolingDown(World world, ItemStack stack) {
	int lastCooldown = NBTHelper.getInt(stack, NBTConstants.NBT.LAST_COOLDOWN, 0);
	long lastCast = NBTHelper.getLong(stack, NBTConstants.NBT.LAST_CAST, 0);
	long currentCast = world.getTotalWorldTime();

	long sub = currentCast - lastCast;
	return sub <= lastCooldown;
}
 
Example 12
Source File: GTItemLightHelmet.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
/** Logic for light helmet block placing with an electric item **/
public void doLightHelmetThings(World world, EntityPlayer player, ItemStack stack) {
	if (world.getTotalWorldTime() % 5 == 0) {
		BlockPos playerPos = player.getPosition();
		boolean canPlaceLightBlock = world.isAirBlock(playerPos) && world.getLightBrightness(playerPos) < 7.0F;
		boolean isLightPresent = world.getBlockState(playerPos) == GTBlocks.lightSource.getDefaultState();
		if (canPlaceLightBlock && !isLightPresent && ElectricItem.manager.getCharge(stack) >= 1.0D) {
			world.setBlockState(player.getPosition(), GTBlocks.lightSource.getDefaultState());
			ElectricItem.manager.use(stack, 10.0D, player);
		}
	}
}
 
Example 13
Source File: GTItemElectromagnet.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int slot, boolean selected) {
	NBTTagCompound nbt = StackUtil.getNbtData((stack));
	if (worldIn.getTotalWorldTime() % 2 == 0) {
		if (!(entityIn instanceof EntityPlayer) || !nbt.getBoolean(ACTIVE)) {
			this.setDamage(stack, 0);
			return;
		}
		double x = entityIn.posX;
		double y = entityIn.posY + 1.5;
		double z = entityIn.posZ;
		int pulled = 0;
		for (EntityItem item : worldIn.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(x, y, z, x + 1, y
				+ 1, z + 1).grow(range))) {
			if (item.getEntityData().getBoolean("PreventRemoteMovement")) {
				continue;
			}
			if (!canPull(stack) || pulled > 200) {
				break;
			}
			item.addVelocity((x - item.posX) * speed, (y - item.posY) * speed, (z - item.posZ) * speed);
			ElectricItem.manager.use(stack, energyCost, (EntityLivingBase) entityIn);
			pulled++;
		}
		this.setDamage(stack, pulled > 0 ? 1 : 0);
	}
}
 
Example 14
Source File: UnicornTrailRenderer.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SideOnly(Side.CLIENT)
@SubscribeEvent
public static void tick(TickEvent.ClientTickEvent event) {
	if (event.phase != TickEvent.Phase.END) return;
	World world = Minecraft.getMinecraft().world;
	if (world == null) return;

	List<EntityUnicorn> unicorns = world.getEntities(EntityUnicorn.class, input -> true);

	for (EntityUnicorn unicorn : unicorns) {
		if (unicorn == null) continue;
		if (unicorn.isDead) {
			positions.remove(unicorn);
			break;
		}

		positions.putIfAbsent(unicorn, new ArrayList<>());

		List<Point> poses = positions.get(unicorn);

		if ((poses.size() >= 1000 || world.getTotalWorldTime() % 20 == 0) && !poses.isEmpty()) {
			poses.remove(0);
		}

		double mot = 0.05;
		if (poses.size() < 1000) {
			if (unicorn.motionX >= mot || unicorn.motionX <= -mot
					|| unicorn.motionY >= mot || unicorn.motionY <= -mot
					|| unicorn.motionZ >= mot || unicorn.motionZ <= -mot) {

				Vec3d backCenter = unicorn.getPositionVector();
				Vec3d look = new Vec3d(unicorn.motionX, unicorn.motionY, unicorn.motionZ).normalize();
				backCenter = backCenter.add(look.scale(-1));

				Vec3d cross = look.crossProduct(new Vec3d(0, 1, 0)).normalize().scale(0.35f);
				poses.add(new Point(backCenter, cross, world.getTotalWorldTime()));
			} else if (!poses.isEmpty()) {
				poses.remove(0);
			}
		}
	}
}
 
Example 15
Source File: UnicornTrailRenderer.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
@SideOnly(Side.CLIENT)
public static void render(RenderWorldLastEvent event) {
	World world = Minecraft.getMinecraft().world;
	EntityPlayer player = Minecraft.getMinecraft().player;
	if (player == null || world == null) return;

	GlStateManager.pushMatrix();

	double interpPosX = player.lastTickPosX + (player.posX - player.lastTickPosX) * event.getPartialTicks();
	double interpPosY = player.lastTickPosY + (player.posY - player.lastTickPosY) * event.getPartialTicks();
	double interpPosZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * event.getPartialTicks();

	GlStateManager.translate(-interpPosX, -interpPosY + 0.1, -interpPosZ);

	GlStateManager.disableCull();
	GlStateManager.depthMask(false);
	GlStateManager.enableBlend();
	GlStateManager.disableTexture2D();
	GlStateManager.shadeModel(GL11.GL_SMOOTH);
	GlStateManager.blendFunc(GL_SRC_ALPHA, GL_ONE);
	GlStateManager.enableColorMaterial();
	GlStateManager.disableLighting();

	Tessellator tessellator = Tessellator.getInstance();
	BufferBuilder vb = tessellator.getBuffer();

	Set<EntityUnicorn> corns = new HashSet<>(positions.keySet());
	for (EntityUnicorn corn : corns) {
		if (corn.world.provider.getDimension() != world.provider.getDimension()) continue;

		List<Point> points = new ArrayList<>(positions.getOrDefault(corn, new ArrayList<>()));
		boolean q = false;

		vb.begin(GL11.GL_TRIANGLE_STRIP, DefaultVertexFormats.POSITION_COLOR);
		for (Point pos : points) {
			if (pos == null) continue;

			float sub = (world.getTotalWorldTime() - pos.time);
			Color color = Color.getHSBColor(sub % 360.0f / 360.0f, 1f, 1f);

			int alpha;
			if (sub < 500) {
				alpha = (int) (MathHelper.clamp(Math.log(sub + 1) / 2.0, 0, 1) * 80.0);
			} else {
				alpha = (int) (MathHelper.clamp(1 - (Math.log(sub) / 2.0), 0, 1) * 80.0);
			}

			pos(vb, pos.origin.subtract(pos.normal.scale(1.5))).color(color.getRed(), color.getGreen(), color.getBlue(), alpha).endVertex();
			pos(vb, pos.origin.add(pos.normal.scale(1.5))).color(color.getRed(), color.getGreen(), color.getBlue(), alpha).endVertex();
			q = !q;
		}

		tessellator.draw();
	}

	GlStateManager.enableCull();
	GlStateManager.depthMask(true);
	GlStateManager.disableBlend();
	GlStateManager.enableTexture2D();
	GlStateManager.shadeModel(GL11.GL_FLAT);
	GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);

	GlStateManager.popMatrix();
}
 
Example 16
Source File: PhasedBlockRenderer.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
public PhaseObject(World world, Set<BlockPos> blocks, int expiry) {
	this.surface = SurfaceFace.fromPlaces(blocks);
	this.lastWorldTick = world.getTotalWorldTime();
	this.expiry = expiry;
	this.when = ClientTickHandler.getTicksInGame();
}
 
Example 17
Source File: ItemMetalAxe.java    From BaseMetals with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void onUpdate(final ItemStack item, final World world, final Entity player, final int inventoryIndex, final boolean isHeld) {
	if(regenerates && !world.isRemote && isHeld && item.getItemDamage() > 0 && world.getTotalWorldTime() % regenInterval == 0){
		item.setItemDamage(item.getItemDamage() - 1);
	}
}
 
Example 18
Source File: ItemMetalCrackHammer.java    From BaseMetals with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void onUpdate(final ItemStack item, final World world, final Entity player, final int inventoryIndex, final boolean isHeld) {
	if(regenerates && !world.isRemote && isHeld && item.getItemDamage() > 0 && world.getTotalWorldTime() % regenInterval == 0){
		item.setItemDamage(item.getItemDamage() - 1);
	}
}
 
Example 19
Source File: SchematicCreationUtils.java    From litematica with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static void takeBlocksFromWorld(LitematicaSchematic schematic, World world, List<SelectionBox> boxes)
{
    BlockPos.MutableBlockPos posMutable = new BlockPos.MutableBlockPos(0, 0, 0);
    long totalBlocks = 0;

    for (SelectionBox box : boxes)
    {
        String regionName = box.getName();
        ISchematicRegion region = schematic.getSchematicRegion(regionName);
        ILitematicaBlockStateContainer container = region != null ? region.getBlockStateContainer() : null;
        Map<BlockPos, NBTTagCompound> blockEntityMap = region != null ? region.getBlockEntityMap() : null;
        Map<BlockPos, NextTickListEntry> tickMap = region != null ? region.getBlockTickMap() : null;

        if (container == null || blockEntityMap == null || tickMap == null)
        {
            InfoUtils.showGuiOrInGameMessage(MessageType.ERROR, "litematica.message.error.schematic_save.missing_container", regionName);
            continue;
        }

        Vec3i size = box.getSize();
        final int sizeX = Math.abs(size.getX());
        final int sizeY = Math.abs(size.getY());
        final int sizeZ = Math.abs(size.getZ());

        // We want to loop nice & easy from 0 to n here, but the per-sub-region pos1 can be at
        // any corner of the area. Thus we need to offset from the total area origin
        // to the minimum/negative (ie. 0,0 in the loop) corner here.
        final BlockPos minCorner = fi.dy.masa.malilib.util.PositionUtils.getMinCorner(box.getPos1(), box.getPos2());
        final int startX = minCorner.getX();
        final int startY = minCorner.getY();
        final int startZ = minCorner.getZ();

        for (int y = 0; y < sizeY; ++y)
        {
            for (int z = 0; z < sizeZ; ++z)
            {
                for (int x = 0; x < sizeX; ++x)
                {
                    posMutable.setPos(x + startX, y + startY, z + startZ);
                    IBlockState state = world.getBlockState(posMutable).getActualState(world, posMutable);
                    container.setBlockState(x, y, z, state);

                    if (state.getBlock() != Blocks.AIR)
                    {
                        ++totalBlocks;
                    }

                    if (state.getBlock().hasTileEntity())
                    {
                        TileEntity te = world.getTileEntity(posMutable);

                        if (te != null)
                        {
                            // TODO Add a TileEntity NBT cache from the Chunk packets, to get the original synced data (too)
                            BlockPos pos = new BlockPos(x, y, z);
                            NBTTagCompound tag = te.writeToNBT(new NBTTagCompound());
                            NBTUtils.writeBlockPosToTag(pos, tag);
                            blockEntityMap.put(pos, tag);
                        }
                    }
                }
            }
        }

        if (world instanceof WorldServer)
        {
            IntBoundingBox structureBB = IntBoundingBox.createProper(
                    startX,         startY,         startZ,
                    startX + sizeX, startY + sizeY, startZ + sizeZ);
            List<NextTickListEntry> pendingTicks = ((WorldServer) world).getPendingBlockUpdates(structureBB.toVanillaBox(), false);

            if (pendingTicks != null)
            {
                final int listSize = pendingTicks.size();
                final long currentTime = world.getTotalWorldTime();

                // The getPendingBlockUpdates() method doesn't check the y-coordinate... :-<
                for (int i = 0; i < listSize; ++i)
                {
                    NextTickListEntry entry = pendingTicks.get(i);

                    if (entry.position.getY() >= startY && entry.position.getY() < structureBB.maxY)
                    {
                        // Store the delay, ie. relative time
                        BlockPos posRelative = new BlockPos(
                                entry.position.getX() - minCorner.getX(),
                                entry.position.getY() - minCorner.getY(),
                                entry.position.getZ() - minCorner.getZ());
                        NextTickListEntry newEntry = new NextTickListEntry(posRelative, entry.getBlock());
                        newEntry.setPriority(entry.priority);
                        newEntry.setScheduledTime(entry.scheduledTime - currentTime);

                        tickMap.put(posRelative, newEntry);
                    }
                }
            }
        }
    }

    schematic.setTotalBlocksReadFromWorld(totalBlocks);
}
 
Example 20
Source File: ItemMetalHoe.java    From BaseMetals with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void onUpdate(final ItemStack item, final World world, final Entity player, final int inventoryIndex, final boolean isHeld) {
	if(regenerates && !world.isRemote && isHeld && item.getItemDamage() > 0 && world.getTotalWorldTime() % regenInterval == 0){
		item.setItemDamage(item.getItemDamage() - 1);
	}
}