Search in sources :

Example 1 with Structure

use of com.minecolonies.structures.helpers.Structure in project minecolonies by Minecolonies.

the class RenderUtils method renderSigns.

/**
 * Render informal signs at the citizen.
 *
 * @param clientWorld     the client world.
 * @param partialTicks    the partial ticks.
 * @param citizenDataView the citizen data.
 * @param player          the player.
 * @param citizen         the citizen position
 */
public static void renderSigns(final WorldClient clientWorld, final float partialTicks, final CitizenDataView citizenDataView, final EntityPlayer player, final BlockPos citizen) {
    final Block block = ModBlocks.blockInfoPoster;
    final BlockPos vector = citizen.subtract(player.getPosition());
    final EnumFacing facing = EnumFacing.getFacingFromVector(vector.getX(), 0, vector.getZ()).getOpposite();
    final BlockPos pos = citizen.up(2).offset(facing);
    final IBlockState iblockstate = block.getDefaultState().withProperty(BlockInfoPoster.FACING, facing);
    final IBlockState iBlockExtendedState = block.getExtendedState(iblockstate, clientWorld, pos);
    final IBakedModel ibakedmodel = Minecraft.getMinecraft().getBlockRendererDispatcher().getModelForState(iblockstate);
    final TileEntityInfoPoster sign = new TileEntityInfoPoster();
    sign.setPos(pos);
    for (int i = 0; i < sign.signText.length; i++) {
        if (i < citizenDataView.getLatestStatus().length) {
            sign.signText[i] = citizenDataView.getLatestStatus()[i];
        }
    }
    final ModelHolder models = new ModelHolder(pos, iblockstate, iBlockExtendedState, sign, ibakedmodel);
    Structure.getQuads(models, models.quads);
    new Structure(Minecraft.getMinecraft().world).renderGhost(clientWorld, models, player, partialTicks, false);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ModelHolder(com.minecolonies.structures.lib.ModelHolder) EnumFacing(net.minecraft.util.EnumFacing) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) Structure(com.minecolonies.structures.helpers.Structure) TileEntityInfoPoster(com.minecolonies.coremod.tileentities.TileEntityInfoPoster)

Example 2 with Structure

use of com.minecolonies.structures.helpers.Structure in project minecolonies by Minecolonies.

the class RenderEventHandler method onRenderWorldLast.

/**
 * Event used to render the schematics. Only render the schematic if there is one in the settings.
 *
 * @param event Object containing event details.
 */
@SubscribeEvent
public void onRenderWorldLast(final RenderWorldLastEvent event) {
    final Structure structure = Settings.instance.getActiveStructure();
    if (structure != null) {
        BlockPos size = structure.getSize(BlockUtils.getRotation(Settings.instance.getRotation()));
        BlockPos position = Settings.instance.getPosition();
        final int x = size.getX();
        final int z = size.getZ();
        final int y = size.getY();
        if (Settings.instance.getRotation() == 1) {
            size = new BlockPos(-x, y, z);
        }
        if (Settings.instance.getRotation() == 2) {
            size = new BlockPos(-x, y, -z);
        }
        if (Settings.instance.getRotation() == 3) {
            size = new BlockPos(x, y, -z);
        }
        final BlockPos offset = Settings.instance.getOffset(new PlacementSettings().setRotation(BlockUtils.getRotation(Settings.instance.getRotation())).setMirror(Settings.instance.getMirror()));
        if (offset.equals(new BlockPos(0, 0, 0))) {
            position = position.subtract(new BlockPos(size.getX() / 2, 0, size.getZ() / 2));
        } else {
            position = position.subtract(offset);
        }
        structure.renderStructure(position, Minecraft.getMinecraft().world, Minecraft.getMinecraft().player, event.getPartialTicks());
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) Structure(com.minecolonies.structures.helpers.Structure) PlacementSettings(net.minecraft.world.gen.structure.template.PlacementSettings) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with Structure

use of com.minecolonies.structures.helpers.Structure in project minecolonies by Minecolonies.

the class WindowBuildTool method changeSchematic.

/*
     * ---------------- Miscellaneous ----------------
     */
/**
 * Changes the current structure.
 * Set to button position at that time
 */
private void changeSchematic() {
    final String sname;
    if (Settings.instance.isStaticSchematicMode()) {
        sname = Settings.instance.getStaticSchematicName();
    } else {
        sname = schematics.get(schematicsDropDownList.getSelectedIndex());
    }
    final StructureName structureName = new StructureName(sname);
    final Structure structure = new Structure(null, structureName.toString(), new PlacementSettings().setRotation(BlockUtils.getRotation(Settings.instance.getRotation())).setMirror(Settings.instance.getMirror()));
    final String md5 = Structures.getMD5(structureName.toString());
    if (structure.isTemplateMissing() || !structure.isCorrectMD5(md5)) {
        if (structure.isTemplateMissing()) {
            Log.getLogger().info("Template structure " + structureName + " missing");
        } else {
            Log.getLogger().info("structure " + structureName + " md5 error");
        }
        Log.getLogger().info("Request To Server for structure " + structureName);
        if (FMLCommonHandler.instance().getMinecraftServerInstance() == null) {
            MineColonies.getNetwork().sendToServer(new SchematicRequestMessage(structureName.toString()));
            return;
        } else {
            Log.getLogger().error("WindowBuildTool: Need to download schematic on a standalone client/server. This should never happen");
        }
    }
    Settings.instance.setStructureName(structureName.toString());
    Settings.instance.setActiveSchematic(structure);
    if (Settings.instance.getPosition() == null) {
        Settings.instance.setPosition(this.pos);
    }
}
Also used : SchematicRequestMessage(com.minecolonies.coremod.network.messages.SchematicRequestMessage) StructureName(com.minecolonies.coremod.colony.StructureName) Structure(com.minecolonies.structures.helpers.Structure) PlacementSettings(net.minecraft.world.gen.structure.template.PlacementSettings)

Example 4 with Structure

use of com.minecolonies.structures.helpers.Structure in project minecolonies by Minecolonies.

the class ClientEventHandler method renderWorldLastEvent.

/**
 * Used to catch the renderWorldLastEvent in order to draw the debug nodes for pathfinding.
 *
 * @param event the catched event.
 */
@SubscribeEvent
public void renderWorldLastEvent(@NotNull final RenderWorldLastEvent event) {
    Pathfinding.debugDraw(event.getPartialTicks());
    final Structure structure = Settings.instance.getActiveStructure();
    final WorldClient world = Minecraft.getMinecraft().world;
    final EntityPlayer player = Minecraft.getMinecraft().player;
    if (structure != null) {
        final BlockPos position = Settings.instance.getPosition();
        if (Settings.instance.getStructureName().contains(AbstractEntityAIStructure.WAYPOINT_STRING)) {
            RenderUtils.renderWayPoints(position, world, event.getPartialTicks());
        } else {
            RenderUtils.renderColonyBorder(position, world, event.getPartialTicks(), player, colonyBorder);
        }
        return;
    } else {
        if (citizen != null) {
            final Entity entityCitizen = world.getEntityByID(citizen.getEntityId());
            if (entityCitizen instanceof EntityCitizen) {
                RenderUtils.renderSigns(world, event.getPartialTicks(), citizen, player, entityCitizen.getPosition());
                ticksPassed += event.getPartialTicks();
                if (ticksPassed > Constants.TICKS_SECOND * SECONDS_TO_SHOW) {
                    ticksPassed = 0;
                    citizen = null;
                }
            } else {
                citizen = null;
                ticksPassed = 0;
            }
            return;
        }
        final ColonyView colony = ColonyManager.getClosestColonyView(world, player.getPosition());
        if (colony != null && player != null && colony.getPermissions().hasPermission(player, Action.ACCESS_HUTS)) {
            for (final CitizenDataView citizenDataView : new ArrayList<CitizenDataView>(colony.getCitizens().values())) {
                final Entity entityCitizen = world.getEntityByID(citizenDataView.getEntityId());
                if (entityCitizen instanceof EntityCitizen && entityCitizen.getPosition().distanceSq(player.getPosition()) <= 2) {
                    RenderUtils.renderSigns(world, event.getPartialTicks(), citizenDataView, player, entityCitizen.getPosition());
                    citizen = citizenDataView;
                    return;
                }
            }
        }
    }
    colonyBorder.clear();
}
Also used : Entity(net.minecraft.entity.Entity) ColonyView(com.minecolonies.coremod.colony.ColonyView) ArrayList(java.util.ArrayList) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) CitizenDataView(com.minecolonies.coremod.colony.CitizenDataView) Structure(com.minecolonies.structures.helpers.Structure) AbstractEntityAIStructure(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIStructure) EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen) WorldClient(net.minecraft.client.multiplayer.WorldClient) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 5 with Structure

use of com.minecolonies.structures.helpers.Structure in project minecolonies by Minecolonies.

the class WindowBuildTool method init.

private void init(final BlockPos pos) {
    @Nullable final Structure structure = Settings.instance.getActiveStructure();
    if (structure != null) {
        rotation = Settings.instance.getRotation();
    } else if (pos != null) {
        this.pos = pos;
        Settings.instance.setPosition(pos);
        Settings.instance.setRotation(0);
    }
    initBuildingTypeNavigation();
    initStyleNavigation();
    initSchematicNavigation();
    // Register all necessary buttons with the window.
    registerButton(BUTTON_CONFIRM, this::confirmClicked);
    registerButton(BUTTON_CANCEL, this::cancelClicked);
    registerButton(BUTTON_LEFT, this::moveLeftClicked);
    registerButton(BUTTON_MIRROR, WindowBuildTool::mirror);
    registerButton(BUTTON_RIGHT, this::moveRightClicked);
    registerButton(BUTTON_BACKWARD, this::moveBackClicked);
    registerButton(BUTTON_FORWARD, this::moveForwardClicked);
    registerButton(BUTTON_UP, WindowBuildTool::moveUpClicked);
    registerButton(BUTTON_DOWN, WindowBuildTool::moveDownClicked);
    registerButton(BUTTON_ROTATE_RIGHT, this::rotateRightClicked);
    registerButton(BUTTON_ROTATE_LEFT, this::rotateLeftClicked);
    registerButton(BUTTON_PASTE, this::pasteComplete);
    registerButton(BUTTON_PASTE_NICE, this::pasteNice);
    registerButton(BUTTON_RENAME, this::renameClicked);
    registerButton(BUTTON_DELETE, this::deleteClicked);
}
Also used : Structure(com.minecolonies.structures.helpers.Structure) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Structure (com.minecolonies.structures.helpers.Structure)5 BlockPos (net.minecraft.util.math.BlockPos)3 PlacementSettings (net.minecraft.world.gen.structure.template.PlacementSettings)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 CitizenDataView (com.minecolonies.coremod.colony.CitizenDataView)1 ColonyView (com.minecolonies.coremod.colony.ColonyView)1 StructureName (com.minecolonies.coremod.colony.StructureName)1 EntityCitizen (com.minecolonies.coremod.entity.EntityCitizen)1 AbstractEntityAIStructure (com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIStructure)1 SchematicRequestMessage (com.minecolonies.coremod.network.messages.SchematicRequestMessage)1 TileEntityInfoPoster (com.minecolonies.coremod.tileentities.TileEntityInfoPoster)1 ModelHolder (com.minecolonies.structures.lib.ModelHolder)1 ArrayList (java.util.ArrayList)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 WorldClient (net.minecraft.client.multiplayer.WorldClient)1 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)1 Entity (net.minecraft.entity.Entity)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EnumFacing (net.minecraft.util.EnumFacing)1