net.minecraft.world.dimension.DimensionType Java Examples

The following examples show how to use net.minecraft.world.dimension.DimensionType. 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: HallowCharmItem.java    From the-hallow with MIT License 7 votes vote down vote up
@Override
public ActionResult useOnBlock(ItemUsageContext context) {
	PlayerEntity player = context.getPlayer();
	if (context.getWorld().isClient) return ActionResult.PASS;
	BlockState state = context.getWorld().getBlockState(context.getBlockPos());
	if(state.getBlock() == HallowedBlocks.HALLOWED_GATE) {
		if (context.getWorld().getDimension().getType() == DimensionType.OVERWORLD) {
			if (HallowedGateBlock.isValid(context.getWorld(), context.getBlockPos(), state)) {
				BlockPos pos = player.getBlockPos();
				CompoundTag tag = new CompoundTag();
				tag.putInt("x", pos.getX());
				tag.putInt("y", pos.getY());
				tag.putInt("z", pos.getZ());
				context.getStack().putSubTag("PortalLoc", tag);
				FabricDimensions.teleport(player, HallowedDimensions.THE_HALLOW);
				return ActionResult.SUCCESS;
			} else {
				player.addChatMessage(new TranslatableText("text.thehallow.gate_incomplete"), true);
			}
		} else {
			player.addChatMessage(new TranslatableText("text.thehallow.gate_in_wrong_dimension"), true);
		}
	}
	return ActionResult.PASS;
}
 
Example #2
Source File: SpawnReporter.java    From fabric-carpet with MIT License 6 votes vote down vote up
public static void registerSpawn(DimensionType dim, MobEntity mob, EntityCategory cat, BlockPos pos)
{
    if (lower_spawning_limit != null)
    {
        if (!( (lower_spawning_limit.getX() <= pos.getX() && pos.getX() <= upper_spawning_limit.getX()) &&
             (lower_spawning_limit.getY() <= pos.getY() && pos.getY() <= upper_spawning_limit.getY()) && 
             (lower_spawning_limit.getZ() <= pos.getZ() && pos.getZ() <= upper_spawning_limit.getZ())
           ))
        {
            return;
        }
    }
    Pair<DimensionType, EntityCategory> key = Pair.of(mob.dimension, cat);
    long count = spawn_stats.get(key).getOrDefault(mob.getType(), 0L);
    spawn_stats.get(key).put(mob.getType(), count + 1);
    spawned_mobs.get(key).put(Pair.of(mob.getType(), pos));
    local_spawns.put(cat, local_spawns.get(cat)+1);
}
 
Example #3
Source File: CarpetSettings.java    From fabric-carpet with MIT License 6 votes vote down vote up
@Override public Integer validate(ServerCommandSource source, ParsedRule<Integer> currentRule, Integer newValue, String string) {
    if (source == null) return newValue;
    if (newValue < 0 || newValue > 32)
    {
        Messenger.m(source, "r spawn chunk size has to be between 0 and 32");
        return null;
    }
    if (currentRule.get().intValue() == newValue.intValue())
    {
        //must been some startup thing
        return newValue;
    }
    if (CarpetServer.minecraft_server == null) return newValue;
    ServerWorld currentOverworld = CarpetServer.minecraft_server.getWorld(DimensionType.OVERWORLD);
    if (currentOverworld != null)
    {
        changeSpawnSize(newValue);
    }
    return newValue;
}
 
Example #4
Source File: CarpetEventServer.java    From fabric-carpet with MIT License 6 votes vote down vote up
@Override
public void onDimensionChange(ServerPlayerEntity player, Vec3d from, Vec3d to, DimensionType fromDim, DimensionType dimTo)
{
    // eligibility already checked in mixin
    Value fromValue = ListValue.fromTriple(from.x, from.y, from.z);
    Value toValue = (to == null)?Value.NULL:ListValue.fromTriple(to.x, to.y, to.z);
    Value fromDimStr = new StringValue(NBTSerializableValue.nameFromRegistryId(Registry.DIMENSION_TYPE.getId(fromDim)));
    Value toDimStr = new StringValue(NBTSerializableValue.nameFromRegistryId(Registry.DIMENSION_TYPE.getId(dimTo)));

    handler.call( () -> Arrays.asList(
            ((c, t) -> new EntityValue(player)),
            ((c, t) -> fromValue),
            ((c, t) -> fromDimStr),
            ((c, t) -> toValue),
            ((c, t) -> toDimStr)
    ), player::getCommandSource);
}
 
Example #5
Source File: Protocol_1_15_2.java    From multiconnect with MIT License 5 votes vote down vote up
private static Identifier dimensionIdToName(int dimensionId) {
    switch (dimensionId) {
        case -1:
            return DimensionType.THE_NETHER_REGISTRY_KEY.getValue();
        case 1:
            return DimensionType.THE_END_REGISTRY_KEY.getValue();
        case 0:
        default:
            return DimensionType.OVERWORLD_REGISTRY_KEY.getValue();
    }
}
 
Example #6
Source File: AddBoundingBox.java    From BoundingBoxOutlineReloaded with MIT License 5 votes vote down vote up
private static DimensionId getDimensionId(PayloadReader reader, String name) {
    if (name.equals(NAME)) return reader.readDimensionId();

    int dimensionRawId = reader.readVarInt();
    DimensionType dimensionType = DimensionType.getById(dimensionRawId);
    return DimensionId.from(dimensionType);
}
 
Example #7
Source File: NBTStructureLoader.java    From BoundingBoxOutlineReloaded with MIT License 5 votes vote down vote up
private LegacyStructureDataUtil getLegacyStructureDataUtil() {
    if (this.legacyStructureDataUtil == null) {
        File dataFolder = new File(DimensionType.OVERWORLD.getDirectory(this.saveHandler.getWorldDirectory()), "data");
        this.legacyStructureDataUtil = LegacyStructureDataUtil.func_215130_a(dimensionId.getDimensionType(),
                new DimensionSavedDataManager(dataFolder, this.saveHandler.getFixer()));
    }
    return this.legacyStructureDataUtil;
}
 
Example #8
Source File: ServerPlayerEntity_scarpetEventMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "changeDimension", at = @At("RETURN"))
private void atChangeDimension(DimensionType newDimension, CallbackInfoReturnable<Entity> cir)
{
    if (PLAYER_CHANGES_DIMENSION.isNeeded())
    {
        ServerPlayerEntity player = (ServerPlayerEntity) (Object)this;
        Vec3d to = null;
        if (!notInAnyWorld || previousDimension != DimensionType.THE_END || newDimension != DimensionType.OVERWORLD)
        {
            to = getPos();
        }
        PLAYER_CHANGES_DIMENSION.onDimensionChange(player, previousLocation, to, previousDimension, newDimension);
    }
}
 
Example #9
Source File: Entity_portalSuffocationMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "changeDimension", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/entity/Entity;getLastNetherPortalDirection()Lnet/minecraft/util/math/Direction;"
))
private void registerEntityDimensionChange(DimensionType newDimension, CallbackInfoReturnable<Entity> cir)
{
    if (CarpetSettings.portalSuffocationFix)
    {
        CarpetSettings.currentTelepotingEntityBox = getBoundingBox();
        CarpetSettings.fixedPosition = null;
    }
}
 
Example #10
Source File: SpawnReporter.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static void reset_spawn_stats(boolean full)
{

    spawn_stats.clear();
    spawned_mobs.clear();
    for (EntityCategory enumcreaturetype : EntityCategory.values())
    {
        if (full)
        {
            spawn_tries.put(enumcreaturetype, 1);
        }
        for (DimensionType dim : DimensionType.getAll())
        {
            Pair<DimensionType, EntityCategory> key = Pair.of(dim, enumcreaturetype);
            overall_spawn_ticks.put(key, 0L);
            spawn_attempts.put(key, 0L);
            spawn_ticks_full.put(key, 0L);
            spawn_ticks_fail.put(key, 0L);
            spawn_ticks_succ.put(key, 0L);
            spawn_ticks_spawns.put(key, 0L);
            spawn_cap_count.put(key, 0L);
            spawn_stats.put(key, new Object2LongOpenHashMap<>());
            spawned_mobs.put(key, new EvictingQueue<>());
        }
    }
    track_spawns = 0L;
}
 
Example #11
Source File: CarpetSettings.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static void changeSpawnSize(int size)
{
    ServerWorld overworld = CarpetServer.minecraft_server.getWorld(DimensionType.OVERWORLD);
    if (overworld != null) {
        ChunkPos centerChunk = new ChunkPos(new BlockPos(
                overworld.getLevelProperties().getSpawnX(),
                overworld.getLevelProperties().getSpawnY(),
                overworld.getLevelProperties().getSpawnZ()
        ));
        SpawnChunks.changeSpawnChunks(overworld.getChunkManager(), centerChunk, size);
    }
}
 
Example #12
Source File: ShapesRenderer.java    From fabric-carpet with MIT License 5 votes vote down vote up
public boolean shouldRender(DimensionType dim)
{
    if (shape.followEntity <=0 ) return true;
    if (client.world == null) return false;
    if (client.world.getEntityById(shape.followEntity) == null) return false;
    return true;
}
 
Example #13
Source File: ShapesRenderer.java    From fabric-carpet with MIT License 5 votes vote down vote up
public void addShape(CompoundTag tag)
{
    ShapeDispatcher.ExpiringShape shape = ShapeDispatcher.fromTag(tag);
    if (shape == null) return;
    BiFunction<MinecraftClient, ShapeDispatcher.ExpiringShape, RenderedShape<? extends ShapeDispatcher.ExpiringShape >> shapeFactory;
    shapeFactory = renderedShapes.get(tag.getString("shape"));
    if (shapeFactory == null)
    {
        CarpetSettings.LOG.info("Unrecognized shape: "+tag.getString("shape"));
    }
    else
    {
        RenderedShape<?> rshape = shapeFactory.apply(client, shape);
        DimensionType dim = shape.shapeDimension;
        long key = rshape.key();
        synchronized (shapes)
        {
            RenderedShape<?> existing = shapes.computeIfAbsent(dim, d -> new Long2ObjectOpenHashMap<>()).get(key);
            if (existing != null)
            {   // promoting previous shape
                existing.expiryTick = rshape.expiryTick;
            }
            else
            {
                shapes.get(dim).put(key, rshape);
            }
        }
    }
}
 
Example #14
Source File: ShapeDispatcher.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Override
public Value validate(Map<String, Value> options, CarpetContext cc, Value value)
{
    String dimStr = value.getString();
    Optional<DimensionType> dimOp = Registry.DIMENSION_TYPE.getOrEmpty(new Identifier(dimStr));
    if (!dimOp.isPresent()) throw new InternalExpressionException("Unknown dimension "+dimStr);
    return value;
}
 
Example #15
Source File: CarpetEventServer.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Override
public void onTick()
{
    handler.call(Collections::emptyList, () ->
            CarpetServer.minecraft_server.getCommandSource().
                    withWorld(CarpetServer.minecraft_server.getWorld(DimensionType.THE_END))
    );
}
 
Example #16
Source File: CarpetEventServer.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Override
public void onTick()
{
    handler.call(Collections::emptyList, () ->
            CarpetServer.minecraft_server.getCommandSource().
                    withWorld(CarpetServer.minecraft_server.getWorld(DimensionType.THE_NETHER))
    );
}
 
Example #17
Source File: HopperCounter.java    From fabric-carpet with MIT License 5 votes vote down vote up
public void reset(MinecraftServer server)
{
    counter.clear();
    startTick = server.getWorld(DimensionType.OVERWORLD).getTime();
    startMillis = System.currentTimeMillis();
    // pubSubProvider.publish();
}
 
Example #18
Source File: CarpetEventServer.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Override
public void onTick()
{
    handler.call(Collections::emptyList, () ->
            CarpetServer.minecraft_server.getCommandSource().
                    withWorld(CarpetServer.minecraft_server.getWorld(DimensionType.OVERWORLD))
    );
}
 
Example #19
Source File: HopperCounter.java    From fabric-carpet with MIT License 5 votes vote down vote up
public void add(MinecraftServer server, ItemStack stack)
{
    if (startTick == 0)
    {
        startTick = server.getWorld(DimensionType.OVERWORLD).getTime();
        startMillis = System.currentTimeMillis();
    }
    Item item = stack.getItem();
    counter.put(item, counter.getLong(item) + stack.getCount());
    // pubSubProvider.publish();
}
 
Example #20
Source File: PacketDistributor.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * A target point that excludes the provided player entity.
 */
public TargetPoint(final ServerPlayerEntity excluded, final double x, final double y, final double z, final double radius, final DimensionType dim) {
	this.excluded = excluded;
	this.x = x;
	this.y = y;
	this.z = z;
	this.radius = radius;
	this.dim = dim;
}
 
Example #21
Source File: PacketDistributor.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * A target point that does not exclude any entities.
 */
public TargetPoint(final double x, final double y, final double z, final double radius, final DimensionType dim) {
	this.excluded = null;
	this.x = x;
	this.y = y;
	this.z = z;
	this.radius = radius;
	this.dim = dim;
}
 
Example #22
Source File: MixinMinecraftServer.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Redirect(method = "createWorlds", at = @At(value = "INVOKE", target = "java/util/Iterator.next ()Ljava/lang/Object;"))
private Object proxyNextWorldToSpecialCaseOverworld(Iterator<DimensionType> iterator) {
	DimensionType type = iterator.next();

	if (type == DimensionType.OVERWORLD) {
		WorldEvents.onWorldLoad(this.worlds.get(type));
	}

	return type;
}
 
Example #23
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void sendPacketToAllAround(double x, double y, double z, double range, DimensionType dim) {
    sendToAllAround(toPacket(NetworkDirection.PLAY_TO_CLIENT), x, y, z, range, dim);
}
 
Example #24
Source File: ServerWorld_tickMixin.java    From fabric-carpet with MIT License 4 votes vote down vote up
protected ServerWorld_tickMixin(LevelProperties levelProperties_1, DimensionType dimensionType_1, BiFunction<World, Dimension, ChunkManager> biFunction_1, Profiler profiler_1, boolean boolean_1)
{
    super(levelProperties_1, dimensionType_1, biFunction_1, profiler_1, boolean_1);
}
 
Example #25
Source File: ServerPlayerEntity_scarpetEventMixin.java    From fabric-carpet with MIT License 4 votes vote down vote up
@Inject(method = "changeDimension", at = @At("HEAD"))
private void logPreviousCoordinates(DimensionType newDimension, CallbackInfoReturnable<Entity> cir)
{
    previousLocation = getPos();
    previousDimension = dimension;
}
 
Example #26
Source File: PlayerManager_scarpetEventsMixin.java    From fabric-carpet with MIT License 4 votes vote down vote up
@Inject(method = "respawnPlayer", at = @At("HEAD"))
private void onRespawn(ServerPlayerEntity player, DimensionType dimension, boolean alive, CallbackInfoReturnable<ServerPlayerEntity> cir)
{
    PLAYER_RESPAWNS.onPlayerEvent(player);
}
 
Example #27
Source File: WorldMixin_RealTime.java    From Galaxy with GNU Affero General Public License v3.0 4 votes vote down vote up
protected WorldMixin_RealTime(MutableWorldProperties mutableWorldProperties, RegistryKey<World> registryKey, RegistryKey<DimensionType> registryKey2, DimensionType dimensionType, Supplier<Profiler> profiler, boolean bl, boolean bl2, long l) {
    super(mutableWorldProperties, registryKey, registryKey2, dimensionType, profiler, bl, bl2, l);
}
 
Example #28
Source File: ServerUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static File getSaveDirectory() {
    return getSaveDirectory(DimensionType.OVERWORLD);
}
 
Example #29
Source File: ServerUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static File getSaveDirectory(DimensionType dimension) {
    return getServer().getWorld(dimension).getSaveHandler().getWorldDirectory();
}
 
Example #30
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void sendPacketToAllAround(BlockPos pos, double range, DimensionType dim) {
    sendPacketToAllAround(pos.getX(), pos.getY(), pos.getZ(), range, dim);
}