Last active
December 1, 2017 23:23
-
-
Save pollend/49d213ab0f3d057d4d84aed90758c0d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2017 MovingBlocks | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
package org.terasology.railnetwork; | |
import org.terasology.math.ChunkMath; | |
import org.terasology.math.Side; | |
import org.terasology.math.SideBitFlag; | |
import org.terasology.math.geom.Vector3i; | |
import org.terasology.minecarts.blocks.RailsUpdateFamily; | |
import org.terasology.registry.CoreRegistry; | |
import org.terasology.registry.In; | |
import org.terasology.segmentedpaths.blocks.PathFamily; | |
import org.terasology.world.block.Block; | |
import org.terasology.world.block.BlockManager; | |
import org.terasology.world.block.BlockUri; | |
import org.terasology.world.block.family.BlockFamily; | |
import org.terasology.world.chunks.CoreChunk; | |
import org.terasology.world.generation.Region; | |
import org.terasology.world.generation.WorldRasterizerPlugin; | |
import org.terasology.world.generation.facets.SeaLevelFacet; | |
import org.terasology.world.generation.facets.SurfaceHeightFacet; | |
import org.terasology.world.generator.plugin.RegisterPlugin; | |
@RegisterPlugin | |
public class RailNetworkRasterizer implements WorldRasterizerPlugin { | |
@In | |
private BlockManager blockManager; | |
private RailsUpdateFamily railFamily; | |
@Override | |
public void initialize() { | |
railFamily = (RailsUpdateFamily) blockManager.getBlockFamily("Rails:rails"); | |
} | |
@Override | |
public void generateChunk(CoreChunk chunk, Region chunkRegion) { | |
SurfaceHeightFacet surfaceHeightFacet = chunkRegion.getFacet(SurfaceHeightFacet.class); | |
SeaLevelFacet seaLevelFacet = chunkRegion.getFacet(SeaLevelFacet.class); | |
int seaLevel = seaLevelFacet.getSeaLevel(); | |
for (Vector3i position : chunkRegion.getRegion()) { | |
if (position.y > seaLevel) { | |
chunk.setBlock(ChunkMath.calcBlockPos(position), railFamily.getBlockByConnection(SideBitFlag.getSides(Side.LEFT, Side.RIGHT))); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment